Quick Reference for AI Agents & Developers
Retrieve List of Conversations
How do I retrieve the latest conversations that I’ve been a part of? To fetch the list of conversations, use theConversationsRequest class. 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 fetched.
The ConversationsRequestBuilder class allows you to set the following parameters:
Set Limit
This method sets the limit i.e. the number of conversations that should be fetched in a single iteration.- Java (Set Limit)
- Kotlin (Set Limit)
Set Conversation Type
This method can be used to fetch user or group conversations specifically. TheconversationType variable can hold one of the below two values:
- user - Only fetches user conversation.
- group - Only fetches group conversations.
- Java
- Kotlin
With User and Group Tags
This method can be used to fetch the user/group tags in theConversation Object. By default the value is false.
- Java
- Kotlin
Set User Tags
This method fetches user conversations that have the specified tags.- Java
- Kotlin
Set Group Tags
- Java
- Kotlin
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 isfalse
- Java
- Kotlin
Set Tags
This method helps you fetch the conversations based on the specified tags.- Java
- Kotlin
Include Blocked Users
This method helps you fetch the conversations of users whom the logged-in user has blocked.- Java
- Kotlin
With Blocked Info
This method helps you fetch the conversations of users whom the logged-in user has blocked.- Java
- Kotlin
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)- Java
- Kotlin
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)- Java
- Kotlin
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.
- Java
- Kotlin
Conversation object consists of the following fields:
| Field | Information |
|---|---|
conversationId | ID of the conversation |
conversationType | Type of conversation (user/group) |
lastMessage | Last message the conversation |
conversationWith | User or Group object containing the details of the user or group |
unreadMessageCount | Unread message count for the conversation |
Tag Conversation
How do I tag a conversation? To tag a specific conversation, use thetagConversation() method. The tagConversation() method accepts three parameters.
-
conversationWith: UID/GUID of the user/group whose conversation you want to fetch. -
conversationType: TheconversationTypevariable can hold one of the below two values:- user - Only fetches user conversation.
- group - Only fetches group conversations.
-
tags: Thetagsvariable will be a list of tags you want to add to a conversation.
- Java
- Kotlin
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
How do I retrieve a specific conversation? To fetch a specific conversation, use thegetConversation method. The getConversation method accepts two parameters.
conversationWith: UID/GUID of the user/group whose conversation you want to fetch.conversationType: TheconversationTypevariable can hold one of the below two values:
- user - Only fetches user conversation.
- group - Only fetches group conversations.
- Java
- Kotlin
Convert Messages to Conversations
As per our Receive Messages guide, for real-time messages, you will always receiveMessage 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.
- Java
- Kotlin
While converting a
Message object to a 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.Best Practices
Use Pagination for Performance
Use Pagination for Performance
Set a reasonable limit (30-50) and fetch conversations in batches. Maximum limit is 50 conversations per request.
Filter by Conversation Type
Filter by Conversation Type
Use
setConversationType() to fetch only user or group conversations when building separate tabs or views.Implement Search for Large Lists
Implement Search for Large Lists
Enable “Conversation & Advanced Search” in Dashboard and use
setSearchKeyword() for better user experience with many conversations.Use Tags for Organization
Use Tags for Organization
Handle Unread Count Client-Side
Handle Unread Count Client-Side
When converting messages to conversations, manage unread counts in your app since they’re not included in the conversion.
Troubleshooting
Empty Conversations List
Empty Conversations List
Symptom:
fetchNext() returns an empty list even though conversations exist.Cause: User hasn’t sent or received any messages, or filters are too restrictive.Solution: Remove filters temporarily to verify conversations exist. Check if the user has participated in any chats.Search Not Working
Search Not Working
Symptom:
setSearchKeyword() doesn’t filter conversations.Cause: “Conversation & Advanced Search” feature not enabled in Dashboard.Solution: Enable the feature in CometChat Dashboard under Chats → Settings → General Configuration. Available in Advanced & Custom plans only.Unread Filter Not Working
Unread Filter Not Working
Symptom:
setUnread(true) doesn’t filter unread conversations.Cause: “Conversation & Advanced Search” feature not enabled.Solution: Enable the feature in Dashboard. This is a premium feature available in Advanced & Custom plans.