Skip to main content
// Fetch conversations list
const request = new CometChat.ConversationsRequestBuilder()
  .setLimit(30).build();
const conversations = await request.fetchNext();

// Get a specific conversation
const conversation = await CometChat.getConversation("UID", "user");

// Tag a conversation
await CometChat.tagConversation("UID", "user", ["archived"]);

// Convert message to conversation
const conversation = await CometChat.CometChatHelper.getConversationFromMessage(message);
Conversations provide the last message for every one-on-one and group conversation the logged-in user is part of. Use this to build a Recent Chats list.

Retrieve List of Conversations

Use ConversationsRequestBuilder to fetch conversations with various filters.

Set Limit

Set the number of conversations to fetch per request.
let limit = 30;
let conversationRequest = 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 = 30;
let conversationType = "group";
let conversationRequest = new CometChat.ConversationsRequestBuilder()
  .setLimit(limit)
  .setConversationType(conversationType)
  .build();
Default limit is 30, maximum is 50.
When conversations are fetched successfully, the response includes an array of Conversation objects filtered by the specified type.

With User and Group Tags

Use withUserAndGroupTags(true) to include user/group tags in the response. Default is false.
let limit = 30;
let conversationRequest = new CometChat.ConversationsRequestBuilder()
  .setLimit(limit)
  .withUserAndGroupTags(true)
  .build();
When conversations are fetched successfully, the response includes tags arrays on the conversationWith objects.

Set User Tags

Fetch user conversations where the user has specific tags.
let limit = 30;
let userTags = ["tag1"];
let conversationRequest = new CometChat.ConversationsRequestBuilder()
  .setLimit(limit)
  .setUserTags(userTags)
  .build();   
When conversations are fetched successfully, the response includes only user conversations where the user has the specified tags.

Set Group Tags

Fetch group conversations where the group has specific tags.
let limit = 30;
let groupTags = ["tag1"];
let conversationRequest = new CometChat.ConversationsRequestBuilder()
  .setLimit(limit)
  .setGroupTags(groupTags)
  .build();
When conversations are fetched successfully, the response includes only group conversations where the group has the specified tags.

With Tags

Use withTags(true) to include conversation tags in the response. Default is false.
let limit = 30;
let conversationRequest = new CometChat.ConversationsRequestBuilder()
  .setLimit(limit)
  .withTags(true)
  .build();

Set Tags

Fetch conversations that have specific tags.
let limit = 30;
let tags = ["archivedChat"];
let conversationRequest = new CometChat.ConversationsRequestBuilder()
  .setLimit(limit)
  .setTags(tags)
  .build();

Include Blocked Users

Use setIncludeBlockedUsers(true) to include conversations with users you’ve blocked.
let limit = 30;
let conversationRequest = new CometChat.ConversationsRequestBuilder()
  .setLimit(limit)
  .setIncludeBlockedUsers(true)
  .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 = 30;
let conversationRequest = new CometChat.ConversationsRequestBuilder()
  .setLimit(limit)
  .setWithBlockedInfo(true)
  .build();

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 = 30;
let conversationRequest = 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 = 30;
let conversationRequest = 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 = 30;
let conversationRequest = new CometChat.ConversationsRequestBuilder()
  .setLimit(limit)
  .setHideAgentic(true)
  .build();

Only Agentic Conversations

Use setOnlyAgentic(true) to fetch only AI agent conversations.
let limit = 30;
let conversationRequest = new CometChat.ConversationsRequestBuilder()
  .setLimit(limit)
  .setOnlyAgentic(true)
  .build();
setHideAgentic() and setOnlyAgentic() are mutually exclusive — use only one per request.
When conversations are fetched successfully, the response includes only AI agent conversations. Agent users have role: "@agentic".

Fetch Conversations

Call build() to create the request, then fetchNext() to retrieve conversations. Maximum 50 per request.
let limit = 30;
let conversationsRequest = new CometChat.ConversationsRequestBuilder()
  .setLimit(limit)
  .build();

conversationsRequest.fetchNext().then(
  (conversationList) => {
    console.log("Conversations list received:", conversationList);
  },
  (error) => {
    console.log("Conversations list fetching failed with error:", error);
  }
);
The Conversation object contains:
FieldDescription
conversationIdID of the conversation
conversationTypeType of conversation (user/group)
lastMessageLast message in the conversation
conversationWithUser or Group object
unreadMessageCountUnread message count
unreadMentionsCountCount of unread mentions
lastReadMessageIdID of the last read message
latestMessageIdID of the latest message
tagsTags associated with the conversation (when using withTags)
The fetchNext() method returns an array of Conversation objects. Access the response data using getter methods:
FieldGetterReturn TypeDescription
conversationIdgetConversationId()stringUnique conversation ID
conversationTypegetConversationType()stringType of conversation ("user" or "group")
lastMessagegetLastMessage()BaseMessageThe last message in the conversation
conversationWithgetConversationWith()User | GroupThe user or group this conversation is with
unreadMessageCountgetUnreadMessageCount()numberNumber of unread messages
unreadMentionsCountgetUnreadMentionsCount()numberCount of unread mentions
lastReadMessageIdgetLastReadMessageId()stringID of the last read message
latestMessageIdgetLatestMessageId()stringID of the latest message
tagsgetTags()string[]Tags associated with the conversation (when using withTags)

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 tags = ["archivedChat"];

CometChat.tagConversation("conversationWith", "conversationType", tags).then(
  (conversation) => {
    console.log("conversation", conversation);
  },
  (error) => {
    console.log("error while fetching a conversation", error);
  }
);
Conversation tags are one-way. If user A tags a conversation with user B, that tag only applies for user A.
When the conversation is tagged successfully, the response returns a Conversation object with the tags field.

Retrieve Single Conversation

Use getConversation() to fetch a specific conversation.
ParameterDescription
conversationWithUID or GUID of the user/group
conversationTypeuser or group
CometChat.getConversation("conversationWith", "conversationType").then(
  (conversation) => {
    console.log("conversation", conversation);
  },
  (error) => {
    console.log("error while fetching a conversation", error);
  }
);
When the conversation is fetched successfully, the response 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.
CometChat.CometChatHelper.getConversationFromMessage(message).then(
  (conversation) => {
    console.log("Conversation Object", conversation);
  }, (error) => {
    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.

Next Steps

Delete Conversation

Remove conversations from the logged-in user’s list

Typing Indicators

Show real-time typing status in conversations