Skip to main content

Retrieve List of Conversations

In other words, as a logged-in user, how do I retrieve the latest conversations that I’ve been a part of? To fetch the list of conversations, you can use the ConversationsRequest class. To use this class i.e. to create an object of the ConversationsRequest class, you need to use the ConversationsRequestBuilder class. The ConversationsRequestBuilder class allows you to set the parameters based on which the conversations are to be fetched. The ConversationsRequestBuilder class allows you to set the below parameters:

Set Limit

This method sets the limit i.e. the number of conversations that should be fetched in a single iteration.

Set Conversation Type

This method can be used to fetch user or group conversations specifically. The conversationType variable can hold one of the below two values:
  • user - Only fetches user conversation.
  • group - Only fetches group conversations.
If none is set, the list of conversations will include both user and group conversations.

With User and Group Tags

This method can be used to fetch the user/group tags in the Conversation Object. By default the value is false.

With Tags

This method makes sure that the tags associated with the conversations are returned along with the other details of the conversations. The default value for this parameter is false

Set Tags

This method helps you fetch the conversations based on the specified tags.

Include Blocked Users

This method helps you fetch the conversations of users whom the logged-in user has blocked.

With Blocked Info

This method can be used to fetch the blocked information of the blocked user in the ConversationWith object.

Search Conversations

This method helps you search a conversation based on User or Group name.
This feature is only available with Conversation & Advanced Search. The Conversation & Advanced Search is only available in Advanced & Custom plans. If you’re already on one of these plans, please enable the Conversation & Advanced Search from CometChat Dashboard (Open your app, navigate to Chats -> Settings -> General Configuration)

Unread Conversations

This method helps you fetch unread conversations.
This feature is only available with Conversation & Advanced Search. The Conversation & Advanced Search is only available in Advanced & Custom plans. If you’re already on one of these plans, please enable the Conversation & Advanced Search from CometChat Dashboard (Open your app, navigate to Chats -> Settings -> General Configuration)

Filter by User Tags

This method helps you filter conversations based on specific user tags.

Filter by Group Tags

This method helps you filter conversations based on specific group tags.

Hide Agentic Conversations

This method helps you hide AI-driven (agentic) conversations from the list. Agentic conversations are those involving AI agents.

Only Agentic Conversations

This method helps you fetch only AI-driven (agentic) conversations. This is useful when you want to display a separate list of AI agent conversations.
Finally, once all the parameters are set to the builder class, you need to call the build() method to get the object of the ConversationsRequest class. Once you have the object of the ConversationsRequest class, you need to call the fetchNext() method. Calling this method will return a list of Conversation objects containing X number of conversations depending on the limit set. A Maximum of only 50 Conversations can be fetched at once.
The Conversationobject consists of the below fields:
FieldInformation
conversationIdID of the conversation
conversationTypeType of conversation (user/group)
lastMessageLast message the conversation
conversationWithUser or Group object containing the details of the user or group
unreadMessageCountUnread message count for the conversation
unreadMentionsCountthe count of unread mentions in the conversation.
lastReadMessageIdthe ID of the last read message in the conversation (int type).

Tag Conversation

In other words, as a logged-in user, how do I tag a conversation? In order to tag a specific conversation, you can use the tagConversation() method. The tagConversation() method accepts three parameters.
  1. conversationWith: UID/GUID of the user/group whose conversation you want to fetch.
  2. conversationType: The conversationType variable can hold one of the below two values:
    1. user - Only fetches user conversation.
    2. group - Only fetches group conversations.
  3. tags: The tags variable will be a list of tags you want to add to a conversation.
The tags for conversations are one-way. This means that if user A tags a conversation with user B, that tag will be applied to that conversation only for user A.

Retrieve Single Conversation

In other words, as a logged-in user, how do I retrieve a specific conversation? In order to fetch a specific conversation, you can use the getConversation method. The getConversation method accepts two parameters.
  1. conversationWith: UID/GUID of the user/group whose conversation you want to fetch.
  2. conversationType: The conversationType variable can hold one of the below two values:
  • user - Only fetches user conversation.
  • group - Only fetches group conversations.

Convert Messages to Conversations

As per our Receive Messages guide, for real-time messages, you will always receive Message objects and not Conversation objects. Thus, you will need a mechanism to convert the Message object to a Conversation object. You can use the getConversationFromMessage method for this purpose.
While converting Message object to Conversation object, the unreadMessageCount & tags will not be available in the Conversation object. The unread message count needs to be managed in your client-side code.