Fetch, filter, tag, and search conversations using the CometChat JavaScript SDK.
AI Integration Quick Reference
// Fetch conversations listconst request = new CometChat.ConversationsRequestBuilder() .setLimit(30).build();const conversations = await request.fetchNext();// Get a specific conversationconst conversation = await CometChat.getConversation("UID", "user");// Tag a conversationawait CometChat.tagConversation("UID", "user", ["archived"]);// Convert message to conversationconst 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. Each Conversation object includes the other participant (user or group), the last message, unread counts, and optional tags. Use this to build a Recent Chats list.
Use withUserAndGroupTags(true) to include user/group tags in the response. Default is false.
TypeScript
JavaScript
let limit: number = 30, conversationRequest: CometChat.ConversationsRequest = new CometChat.ConversationsRequestBuilder() .setLimit(limit) .withUserAndGroupTags(true) .build();
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.
Use withTags(true) to include conversation tags in the response. Default is false.
TypeScript
JavaScript
let limit: number = 30,conversationRequest: CometChat.ConversationsRequest = new CometChat.ConversationsRequestBuilder() .setLimit(limit) .withTags(true) .build();
let limit = 30;let conversationRequest = new CometChat.ConversationsRequestBuilder() .setLimit(limit) .withTags(true) .build();
Use setIncludeBlockedUsers(true) to include conversations with users you’ve blocked.
TypeScript
JavaScript
let limit: number = 30, conversationRequest: CometChat.ConversationsRequest = new CometChat.ConversationsRequestBuilder() .setLimit(limit) .setIncludeBlockedUsers(true) .build();
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.
Use setWithBlockedInfo(true) to include blocked user information in the response.
TypeScript
JavaScript
let limit: number = 30, conversationRequest: CometChat.ConversationsRequest = new CometChat.ConversationsRequestBuilder() .setLimit(limit) .setWithBlockedInfo(true) .build();
let limit = 30;let conversationRequest = new CometChat.ConversationsRequestBuilder() .setLimit(limit) .setWithBlockedInfo(true) .build();
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 & Customplans. 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)
TypeScript
JavaScript
let limit: number = 30, conversationRequest: CometChat.ConversationsRequest = new CometChat.ConversationsRequestBuilder() .setLimit(limit) .setSearchKeyword("Hiking") .build();
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.
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 & Customplans. 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)
TypeScript
JavaScript
let limit: number = 30, conversationRequest: CometChat.ConversationsRequest = new CometChat.ConversationsRequestBuilder() .setLimit(limit) .setUnread(true) .build();
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).
Use setHideAgentic(true) to exclude AI agent conversations from the list.
TypeScript
JavaScript
let limit: number = 30, conversationRequest: CometChat.ConversationsRequest = new CometChat.ConversationsRequestBuilder() .setLimit(limit) .setHideAgentic(true) .build();
let limit = 30;let conversationRequest = new CometChat.ConversationsRequestBuilder() .setLimit(limit) .setHideAgentic(true) .build();
Use setOnlyAgentic(true) to fetch only AI agent conversations.
TypeScript
JavaScript
let limit: number = 30, conversationRequest: CometChat.ConversationsRequest = new CometChat.ConversationsRequestBuilder() .setLimit(limit) .setOnlyAgentic(true) .build();
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".
After configuring the builder, call build() to create the request, then fetchNext() to retrieve conversations. Maximum 50 per request. Call fetchNext() repeatedly on the same object to paginate.
TypeScript
JavaScript
let limit: number = 30, conversationsRequest: CometChat.ConversationsRequest = new CometChat.ConversationsRequestBuilder() .setLimit(limit) .build();conversationsRequest.fetchNext().then( (conversationList: CometChat.Conversation[]) => { console.log("Conversations list received:", conversationList); }, (error: CometChat.CometChatException) => { console.log("Conversations list fetching failed with error:", error); });
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 fetchNext() method returns an array of Conversation objects. Access the response data using getter methods:
Use CometChatHelper.getConversationFromMessage() to convert a received message into a Conversation object. Useful for updating your Recent Chats list when receiving real-time messages.