Skip to main content

Documentation Index

Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt

Use this file to discover all available pages before exploring further.

Conversations provide the last messages for every one-on-one and group conversation the logged-in user is a part of. This makes it easy for you to build a Recent Chat list.

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. Fetching using this builder will return Conversation objects. The ConversationsRequestBuilder to fetch conversations with various filters.

Set Limit

Set the number of conversations to fetch per request.
let limit: number = 30,
  conversationRequest: CometChat.ConversationsRequest = new CometChat.ConversationsRequestBuilder()
    .setLimit(limit)
    .build();

Set Conversation Type

Filter by conversation type: user for one-on-one or group for group conversations. If not set, both types are returned.
let limit: number = 30,
  conversationType: string = "group",
  conversationRequest: CometChat.ConversationsRequest = new CometChat.ConversationsRequestBuilder()
    .setLimit(limit)
    .setConversationType(conversationType)
    .build();
When conversations are fetched successfully, the response includes conversations with blocked users. To also get blocked info details (blockedByMe, blockedByMeAt, blockedAt), set withBlockedInfo to true.

With Blocked Info

Use setWithBlockedInfo(true) to include blocked user information in the response.
let limit: number = 30,
  conversationRequest: CometChat.ConversationsRequest = new CometChat.ConversationsRequestBuilder()
  .setLimit(limit)
  .setWithBlockedInfo(true)
  .build();     
Relevant fields to access on returned conversations:
FieldGetterReturn TypeDescription
blockedByMegetConversationWith().getBlockedByMe()booleanWhether the logged-in user has blocked this user
hasBlockedMegetConversationWith().getHasBlockedMe()booleanWhether this user has blocked the logged-in user
blockedByMeAtgetConversationWith().blockedByMeAtnumberTimestamp when the logged-in user blocked this user
blockedAtgetConversationWith().blockedAtnumberTimestamp when this user was blocked

Search Conversations

Use setSearchKeyword() to search conversations by 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)
let limit: number = 30,
  conversationRequest: CometChat.ConversationsRequest = new CometChat.ConversationsRequestBuilder()
    .setLimit(limit)
    .setSearchKeyword("Hiking")
    .build();  
When conversations are fetched successfully, the response includes conversations where the user or group name matches the search keyword.

Unread Conversations

Use setUnread(true) to fetch only conversations with unread messages.
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)
let limit: number = 30,
  conversationRequest: CometChat.ConversationsRequest = new CometChat.ConversationsRequestBuilder()
    .setLimit(limit)
    .setUnread(true)
    .build();  
When conversations are fetched successfully, the response includes only conversations with unread messages (unreadMessageCount > 0).

Hide Agentic Conversations

Use setHideAgentic(true) to exclude AI agent conversations from the list.
let limit: number = 30,
  conversationRequest: CometChat.ConversationsRequest = new CometChat.ConversationsRequestBuilder()
    .setLimit(limit)
    .setHideAgentic(true)
    .build();  

Only Agentic Conversations

Use setOnlyAgentic(true) to fetch only AI agent conversations.
let limit: number = 30,
  conversationRequest: CometChat.ConversationsRequest = new CometChat.ConversationsRequestBuilder()
    .setLimit(limit)
    .setOnlyAgentic(true)
    .build();  
The fetchNext() method returns an array of Conversation objects.

Tag Conversation

Use tagConversation() to add tags to a conversation.
ParameterDescription
conversationWithUID or GUID of the user/group
conversationTypeuser or group
tagsArray of tags to add
let conversationWith: string = "UID",
  tags: Array<String> = ["archivedChat"],
  conversationType: string = "user";

CometChat.tagConversation(conversationWith, conversationType, tags).then(
(conversation: CometChat.Conversation) => {
console.log("conversation", conversation);
},
(error: CometChat.CometChatException) => {
console.log("error while fetching a conversation", error);
}
);

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.
When the conversation is tagged successfully, the response will return a single Conversation object (not an array) with the tags field included. The tagConversation() method returns a Conversation object with the tags field populated. Relevant fields to access on returned conversation:
FieldGetterReturn TypeDescription
tagsgetTags()string[]Tags applied to the conversation

Retrieve Single Conversation

Use getConversation() to fetch a specific conversation.
ParameterDescription
conversationWithUID or GUID of the user/group
conversationTypeuser or group
let conversationWith: string = "UID",
  conversationType: string = "user";

CometChat.getConversation(conversationWith, conversationType).then(
(conversation: CometChat.Conversation) => {
console.log("conversation", conversation);
},
(error: CometChat.CometChatException) => {
console.log("error while fetching a conversation", error);
}
);

When the conversation is fetched successfully, the response will return a single Conversation object (not an array). The getConversation() method returns a single Conversation object.

Convert Messages to Conversations

Use CometChatHelper.getConversationFromMessage() to convert a received message into a Conversation object. Useful for updating your Recent Chats list when receiving real-time messages.
let message: CometChat.TextMessage | CometChat.MediaMessage | CometChat.CustomMessage;

CometChat.CometChatHelper.getConversationFromMessage(message).then(
(conversation: CometChat.Conversation) => {
console.log("Conversation Object", conversation);
},(error: CometChat.CometChatException) => {
console.log("Error while converting message object", error);
}
);

When converting a message to a conversation, unreadMessageCount and tags won’t be available. Manage unread counts in your client-side code.
The getConversationFromMessage() method returns a Conversation object.

Next Steps

Delete Conversation

Remove conversations from the logged-in user’s list

Receive Messages

Listen for incoming messages to update conversation lists in real time

Typing Indicators

Show real-time typing status in conversations

Delivery & Read Receipts

Track message delivery and read status per conversation