AI Integration Quick Reference
AI Integration Quick Reference
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.
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 theConversationsRequest 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.- TypeScript
- JavaScript
Set Conversation Type
Filter by conversation type:user for one-on-one or group for group conversations. If not set, both types are returned.
- TypeScript
- JavaScript
The default value for
setLimit is 30 and the max value is 50.Conversation objects filtered by the specified type.
Relevant fields to access on returned conversations:
| Field | Getter | Return Type | Description |
|---|---|---|---|
| conversationType | getConversationType() | string | Type of conversation ("user" or "group") |
With User and Group Tags
UsewithUserAndGroupTags(true) to include user/group tags in the response. Default is false.
- TypeScript
- JavaScript
tags arrays on the conversationWith objects (user or group).
Relevant fields to access on returned conversations:
| Field | Getter | Return Type | Description |
|---|---|---|---|
| conversationWith tags | getConversationWith().getTags() | string[] | Tags associated with the user or group in the conversation |
Set User Tags
Fetch user conversations where the user has specific tags.- TypeScript
- JavaScript
| Field | Getter | Return Type | Description |
|---|---|---|---|
| conversationWith tags | getConversationWith().getTags() | string[] | Tags associated with the user in the conversation |
Set Group Tags
Fetch group conversations where the group has specific tags.- TypeScript
- JavaScript
| Field | Getter | Return Type | Description |
|---|---|---|---|
| conversationWith tags | getConversationWith().getTags() | string[] | Tags associated with the group in the conversation |
With Tags
UsewithTags(true) to include conversation tags in the response. Default is false.
- TypeScript
- JavaScript
| Field | Getter | Return Type | Description |
|---|---|---|---|
| tags | getTags() | string[] | Tags associated with the conversation |
Set Tags
Fetch conversations that have specific tags.- TypeScript
- JavaScript
| Field | Getter | Return Type | Description |
|---|---|---|---|
| tags | getTags() | string[] | Tags associated with the conversation |
Include Blocked Users
UsesetIncludeBlockedUsers(true) to include conversations with users you’ve blocked.
- TypeScript
- JavaScript
blockedByMe, blockedByMeAt, blockedAt), set withBlockedInfo to true.
With Blocked Info
UsesetWithBlockedInfo(true) to include blocked user information in the response.
- TypeScript
- JavaScript
| Field | Getter | Return Type | Description |
|---|---|---|---|
| blockedByMe | getConversationWith().getBlockedByMe() | boolean | Whether the logged-in user has blocked this user |
| hasBlockedMe | getConversationWith().getHasBlockedMe() | boolean | Whether this user has blocked the logged-in user |
| blockedByMeAt | getConversationWith().blockedByMeAt | number | Timestamp when the logged-in user blocked this user |
| blockedAt | getConversationWith().blockedAt | number | Timestamp when this user was blocked |
Search Conversations
UsesetSearchKeyword() 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)- TypeScript
- JavaScript
Unread Conversations
UsesetUnread(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)- TypeScript
- JavaScript
unreadMessageCount > 0).
Hide Agentic Conversations
UsesetHideAgentic(true) to exclude AI agent conversations from the list.
- TypeScript
- JavaScript
Only Agentic Conversations
UsesetOnlyAgentic(true) to fetch only AI agent conversations.
- TypeScript
- JavaScript
The
setHideAgentic() and setOnlyAgentic() methods are mutually exclusive. You should only use one of them in a single request builder instance.role: "@agentic" and include agent-specific metadata.
Fetch Conversations
After configuring the builder, callbuild() to create the request, then fetchNext() to retrieve conversations. Maximum 50 per request. Call fetchNext() repeatedly on the same object to paginate.
- TypeScript
- JavaScript
fetchNext() method returns an array of Conversation objects.
Tag Conversation
UsetagConversation() to add tags to a conversation.
| Parameter | Description |
|---|---|
conversationWith | UID or GUID of the user/group |
conversationType | user or group |
tags | Array of tags to add |
- TypeScript
- JavaScript
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.
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:
| Field | Getter | Return Type | Description |
|---|---|---|---|
| tags | getTags() | string[] | Tags applied to the conversation |
Retrieve Single Conversation
UsegetConversation() to fetch a specific conversation.
| Parameter | Description |
|---|---|
conversationWith | UID or GUID of the user/group |
conversationType | user or group |
- TypeScript
- JavaScript
Conversation object (not an array).
The getConversation() method returns a single Conversation object.
Convert Messages to Conversations
UseCometChatHelper.getConversationFromMessage() to convert a received message into a Conversation object. Useful for updating your Recent Chats list when receiving real-time messages.
- TypeScript
- JavaScript
When converting a message to a conversation,
unreadMessageCount and tags won’t be available. Manage unread counts in your client-side code.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