Skip to main content
Quick Reference for AI Agents & Developers
// Fetch messages for a user conversation
let request = new CometChat.MessagesRequestBuilder().setUID("UID").setLimit(50).build();

// Fetch messages for a group conversation
let request = new CometChat.MessagesRequestBuilder().setGUID("GUID").setLimit(50).build();

// Fetch only unread messages
let request = new CometChat.MessagesRequestBuilder().setUID("UID").setUnread(true).setLimit(30).build();

// Fetch only media messages
let request = new CometChat.MessagesRequestBuilder().setUID("UID").setCategories(["message"]).setTypes(["image", "video", "audio", "file"]).setLimit(30).build();

// Fetch messages, then paginate
let messages = await request.fetchPrevious();
The MessagesRequest class as you must be familiar with helps you to fetch messages based on the various parameters provided to it. This document will help you understand better the various options that are available using the MessagesRequest class.
Available via: SDK | REST API | UI Kits
The MessagesRequest class is designed using the Builder design pattern. In order to obtain an object of the MessagesRequest class, you will have to make use of the MessagesRequestBuilder class in the MessagesRequest class. The MessagesRequestBuilder class allows you to set various parameters to the MessagesRequest class based on which the messages are fetched. Steps to generate an object of the MessagesRequest class:
  1. Create an object of the MessagesRequestBuilder class.
  2. Set all the parameters you wish to set.
  3. Call the build() method of the MessagesRequestBuilder class to get an object of the MessagesRequest class.
Once you have an object of the MessagesRequest class, you can call either the fetchNext() method or the fetchPrevious() method using the object.
  1. fetchNext() - Calling this method will return the messages after the specified parameters.
  2. fetchPrevious() - Calling this method will give you messages before the specified parameters.
Since messages are obtained in a paginated manner, a maximum of 100 messages can be pulled in a single iteration. Calling the fetchPrevious()/fetchNext() method on the same MessagesRequest object will get you the next set of messages. Now that you are clear how to use the MessagesRequest class, below are the various options available:

Number of messages fetched

In other words, how do I set the number of messages fetched in a single iteration To achieve this, you can use the setLimit() method. This method takes an integer value as the input and informs the SDK to fetch the specified number of messages in one iteration. The maximum number of messages that can be fetched in one go is 100.
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setLimit(50)
  .build();
On SuccessfetchPrevious() returns an array of Message objects:Message Object (per item in array):
ParameterTypeDescriptionSample Value
idstringUnique message identifier"25234"
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
receiverIdstringReceiver’s UID or GUID"cometchat-uid-2"
receiverTypestringType of receiver"user"
typestringMessage type"text"
categorystringMessage category"message"
textstringMessage text content"Nice"
sentAtnumberUnix timestamp when sent1771398092
deliveredAtnumberUnix timestamp when delivered1771398092
readAtnumberUnix timestamp when read1771404705
updatedAtnumberUnix timestamp when updated1771404705
senderobjectSender user detailsSee below ↓
receiverobjectReceiver user detailsSee below ↓
dataobjectAdditional message dataSee below ↓
metadataobjectMessage metadataSee below ↓
reactionsarrayMessage reactions[]
mentionedUsersarrayUsers mentioned in message[]
mentionedMebooleanWhether current user is mentionedfalse

sender Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-3"
namestringUser’s display name"Nancy Grace"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771397739
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-2"
namestringUser’s display name"George Alan"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771397762
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

data Object:
ParameterTypeDescriptionSample Value
textstringMessage text"Nice"
resourcestringSDK resource identifier"REACT_NATIVE-4_0_14-..."
entitiesobjectSender and receiver entitiesSee below ↓
metadataobjectInjected metadataSee below ↓

data.entities Object:
ParameterTypeDescriptionSample Value
senderobjectSender entity wrapperSee below ↓
receiverobjectReceiver entity wrapperSee below ↓

data.entities.sender Object:
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectUser entity detailsSee below ↓

data.entities.sender.entity Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-3"
namestringUser’s display name"Nancy Grace"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771397739
tagsarrayUser tags[]

data.entities.receiver Object:
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectUser entity detailsSee below ↓

data.entities.receiver.entity Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-2"
namestringUser’s display name"George Alan"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771397762
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
tagsarrayUser tags[]

data.metadata Object:
ParameterTypeDescriptionSample Value
@injectedobjectInjected extensions dataSee below ↓

data.metadata.@injected Object:
ParameterTypeDescriptionSample Value
extensionsobjectExtensions dataSee below ↓

data.metadata.@injected.extensions Object:
ParameterTypeDescriptionSample Value
link-previewobjectLink preview extension dataSee below ↓

data.metadata.@injected.extensions.link-preview Object:
ParameterTypeDescriptionSample Value
linksarrayArray of link previews[]

metadata Object:
ParameterTypeDescriptionSample Value
@injectedobjectInjected extensions dataSee below ↓

metadata.@injected Object:
ParameterTypeDescriptionSample Value
extensionsobjectExtensions dataSee below ↓

metadata.@injected.extensions Object:
ParameterTypeDescriptionSample Value
link-previewobjectLink preview extension dataSee below ↓

metadata.@injected.extensions.link-preview Object:
ParameterTypeDescriptionSample Value
linksarrayArray of link previews[]

Messages for a user conversation

In other words, how do I fetch messages between me and any user This can be achieved using the setUID() method. This method takes the UID of the user with whom the conversation is to be fetched. When a valid UID is passed, the SDK will return all the messages that are a part of the conversation between the logged-in user and the UID that has been specified.
let UID = "UID";
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setLimit(50)
  .build();
On SuccessfetchPrevious() returns an array of Message objects:Message Object (per item in array):
ParameterTypeDescriptionSample Value
idstringUnique message identifier"25234"
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
receiverIdstringReceiver’s UID"cometchat-uid-2"
receiverTypestringType of receiver"user"
typestringMessage type"text"
categorystringMessage category"message"
textstringMessage text content"Nice"
sentAtnumberUnix timestamp when sent1771398092
deliveredAtnumberUnix timestamp when delivered1771398092
readAtnumberUnix timestamp when read1771404705
updatedAtnumberUnix timestamp when updated1771404705
senderobjectSender user detailsSee below ↓
receiverobjectReceiver user detailsSee below ↓
dataobjectAdditional message dataSee below ↓
metadataobjectMessage metadataSee below ↓
reactionsarrayMessage reactions[]
mentionedUsersarrayUsers mentioned in message[]
mentionedMebooleanWhether current user is mentionedfalse

sender Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-3"
namestringUser’s display name"Nancy Grace"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771397739
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-2"
namestringUser’s display name"George Alan"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771397762
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

data Object:
ParameterTypeDescriptionSample Value
textstringMessage text"Nice"
resourcestringSDK resource identifier"REACT_NATIVE-4_0_14-..."
entitiesobjectSender and receiver entitiesSee below ↓
metadataobjectInjected metadataSee below ↓

data.entities Object:
ParameterTypeDescriptionSample Value
senderobjectSender entity wrapperSee below ↓
receiverobjectReceiver entity wrapperSee below ↓

data.entities.sender Object:
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectUser entity detailsSee below ↓

data.entities.sender.entity Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-3"
namestringUser’s display name"Nancy Grace"
avatarstringUser’s avatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
rolestringUser’s role"default"
statusstringUser’s online status"online"
lastActiveAtnumberLast active timestamp1771397739
tagsarrayUser tags[]

data.entities.receiver Object:
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectUser entity detailsSee below ↓

data.entities.receiver.entity Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-2"
namestringUser’s display name"George Alan"
avatarstringUser’s avatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
rolestringUser’s role"default"
statusstringUser’s online status"online"
lastActiveAtnumberLast active timestamp1771397762
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
tagsarrayUser tags[]

data.metadata Object:
ParameterTypeDescriptionSample Value
@injectedobjectInjected extensions dataSee below ↓

data.metadata.@injected Object:
ParameterTypeDescriptionSample Value
extensionsobjectExtensions dataSee below ↓

data.metadata.@injected.extensions Object:
ParameterTypeDescriptionSample Value
link-previewobjectLink preview extensionSee below ↓

data.metadata.@injected.extensions.link-preview Object:
ParameterTypeDescriptionSample Value
linksarrayExtracted links[]

metadata Object:
ParameterTypeDescriptionSample Value
@injectedobjectInjected extensions dataSee below ↓

metadata.@injected Object:
ParameterTypeDescriptionSample Value
extensionsobjectExtensions dataSee below ↓

metadata.@injected.extensions Object:
ParameterTypeDescriptionSample Value
link-previewobjectLink preview extensionSee below ↓

metadata.@injected.extensions.link-preview Object:
ParameterTypeDescriptionSample Value
linksarrayExtracted links[]

Messages for a group conversation

In other words, how do I fetch messages for any group conversation You can achieve this using the setGUID() method. This method takes the GUID of a group for which the conversations are to be fetched. Passing a valid GUID to this method will return all the messages that are a part of the group conversation. Please note that the logged-in user must be a member of the group to fetch the messages for that group.
let GUID = "GUID";
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setGUID(GUID)
  .setLimit(50)
  .build();
On SuccessfetchPrevious() returns an array of Message objects for the group:Message Object (per item in array):
ParameterTypeDescriptionSample Value
idstringUnique message identifier"25237"
conversationIdstringConversation identifier"group_group_1748415903905"
receiverIdstringGroup’s GUID"group_1748415903905"
receiverTypestringType of receiver"group"
typestringMessage type"text"
categorystringMessage category"message"
textstringMessage text content"Nice"
sentAtnumberUnix timestamp when sent1771400683
updatedAtnumberUnix timestamp when updated1771400683
senderobjectSender user detailsSee below ↓
receiverobjectReceiver group detailsSee below ↓
dataobjectAdditional message dataSee below ↓
metadataobjectMessage metadataContains @injected.extensions.link-preview
reactionsarrayMessage reactions[]
mentionedUsersarrayUsers mentioned in message[]
mentionedMebooleanWhether current user is mentionedfalse

sender Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-3"
namestringUser’s display name"Nancy Grace"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771397739
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

receiver Object (Group):
ParameterTypeDescriptionSample Value
guidstringGroup’s unique identifier"group_1748415903905"
namestringGroup’s display name"3 People Group"
typestringGroup type"public"
conversationIdstringConversation identifier"group_group_1748415903905"
ownerstringGroup owner’s UID"123456"
scopestringCurrent user’s scope in group"admin"
membersCountnumberTotal members in group12
onlineMembersCountnumberOnline members count2
hasJoinedbooleanWhether current user has joinedtrue
isBannedbooleanWhether current user is bannedfalse
joinedAtnumberTimestamp when user joined1749203133
createdAtnumberGroup creation timestamp1748415957
updatedAtnumberGroup update timestamp1771245340

data Object:
ParameterTypeDescriptionSample Value
textstringMessage text"Nice"
resourcestringSDK resource identifier"REACT_NATIVE-4_0_14-..."
entitiesobjectSender and receiver entitiesSee below ↓
metadataobjectInjected metadataContains @injected.extensions.link-preview

data.entities Object:
ParameterTypeDescriptionSample Value
senderobjectSender entity wrapperSee below ↓
receiverobjectReceiver entity wrapperSee below ↓

data.entities.sender Object:
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectUser entity detailsContains uid, name, avatar, status, role, lastActiveAt, tags

data.entities.receiver Object:
ParameterTypeDescriptionSample Value
entityTypestringType of entity"group"
entityobjectGroup entity detailsSee below ↓

data.entities.receiver.entity Object (Group):
ParameterTypeDescriptionSample Value
guidstringGroup’s unique identifier"group_1748415903905"
namestringGroup’s display name"3 People Group"
typestringGroup type"public"
conversationIdstringConversation identifier"group_group_1748415903905"
ownerstringGroup owner’s UID"123456"
scopestringCurrent user’s scope in group"admin"
membersCountnumberTotal members in group12
onlineMembersCountnumberOnline members count2
hasJoinedbooleanWhether current user has joinedtrue
joinedAtnumberTimestamp when user joined1749203133
createdAtnumberGroup creation timestamp1748415957
updatedAtnumberGroup update timestamp1771245340
If none of the above two methods setUID() and setGUID() is used, all the messages for the logged-in user will be fetched. This means that messages from all the one-on-one and group conversations which the logged-in user is a part of will be returned.> All the parameters discussed below can be used along with the setUID() or setGUID() or without any of the two to fetch all the messages that the logged-in user is a part of.

Messages before/after a message

In other words, how do I fetch messages before or after a particular message This can be achieved using the setMessageId() method. This method takes the message-id as input and provides messages only after/before the message-id based on if the fetchNext() or fetchPrevious() method is triggered.
let UID = "UID";
let messageId = 1;
let limit = 30;
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setMessageId(messageId)
  .setLimit(limit)
  .build();
On SuccessfetchPrevious() returns messages before the specified message ID:Message Object (per item in array):
ParameterTypeDescriptionSample Value
idstringUnique message identifier"25233"
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
receiverIdstringReceiver’s UID"cometchat-uid-2"
receiverTypestringType of receiver"user"
typestringMessage type"text"
categorystringMessage category"message"
textstringMessage text content"UnreadHey"
sentAtnumberUnix timestamp when sent1771398088
deliveredAtnumberUnix timestamp when delivered1771398088
readAtnumberUnix timestamp when read1771404705
updatedAtnumberUnix timestamp when updated1771398088
senderobjectSender user detailsSee below ↓
receiverobjectReceiver user detailsSee below ↓
dataobjectAdditional message dataSee below ↓
metadataobjectMessage metadataContains @injected.extensions.link-preview
reactionsarrayMessage reactions[]
mentionedUsersarrayUsers mentioned in message[]
mentionedMebooleanWhether current user is mentionedfalse

sender Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-3"
namestringUser’s display name"Nancy Grace"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771397739
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-2"
namestringUser’s display name"George Alan"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771397762
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

data Object:
ParameterTypeDescriptionSample Value
textstringMessage text"UnreadHey"
resourcestringSDK resource identifier"REACT_NATIVE-4_0_14-..."
entitiesobjectSender and receiver entitiesContains sender and receiver wrappers
metadataobjectInjected metadataContains @injected.extensions.link-preview
This method can be used along with setUID() or setGUID() methods to fetch messages after/before any specific message-id for a particular user/group conversation.

Messages before/after a given time

In other words, how do I fetch messages before or after a particular date or time You can easily achieve this using the setTimestamp() method. This method takes the Unix timestamp as input and provides messages only after/before the timestamp based on if fetchNext() or fetchPrevious() method is triggered.
let UID = "UID";
let timestamp = 1602221371;
let limit = 30;
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setTimestamp(timestamp)
  .setLimit(limit)
  .build();
On SuccessfetchPrevious() returns messages before the specified timestamp (includes custom message types):Message Object (per item in array):
ParameterTypeDescriptionSample Value
idstringUnique message identifier"25191"
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
receiverIdstringReceiver’s UID"cometchat-uid-2"
receiverTypestringType of receiver"user"
typestringMessage type"test-custom"
categorystringMessage category"custom"
customDataobjectCustom message dataSee below ↓
sentAtnumberUnix timestamp when sent1771324025
deliveredAtnumberUnix timestamp when delivered1771328175
readAtnumberUnix timestamp when read1771328175
updatedAtnumberUnix timestamp when updated1771328175
senderobjectSender user detailsSee below ↓
receiverobjectReceiver user detailsSee below ↓
dataobjectAdditional message dataSee below ↓
metadataobjectMessage metadataContains @injected.extensions.link-preview
reactionsarrayMessage reactions[]
mentionedUsersarrayUsers mentioned in message[]
mentionedMebooleanWhether current user is mentionedfalse

customData Object (for custom messages):
ParameterTypeDescriptionSample Value
greetingstringCustom greeting text"Hello from custom message!"
timestampnumberCustom timestamp1771324022864

sender Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-3"
namestringUser’s display name"Nancy Grace"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringUser’s online status"offline"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771323567
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-2"
namestringUser’s display name"George Alan"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771323089
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

data Object:
ParameterTypeDescriptionSample Value
customDataobjectCustom message dataSame as top-level customData
resourcestringSDK resource identifier"REACT_NATIVE-4_0_14-..."
entitiesobjectSender and receiver entitiesContains sender and receiver wrappers
metadataobjectInjected metadataContains @injected.extensions.link-preview
This method can be used along with setUID() or setGUID() methods to fetch messages after/before any specific date or time for a particular user/group conversation.

Unread messages

In other words, how do I fetch unread messages This can easily be achieved using setting the unread flag to true. For this, you need to use the setUnread() method. This method takes a boolean value as input. If the value is set to true, the SDK will return just the unread messages.
let UID = "UID";
let limit = 30;
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setUnread(true)
  .setLimit(limit)
  .build();
On SuccessfetchPrevious() returns only unread messages:Message Object (per item in array):
ParameterTypeDescriptionSample Value
idstringUnique message identifier"25241"
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
receiverIdstringReceiver’s UID"cometchat-uid-2"
receiverTypestringType of receiver"user"
typestringMessage type"text"
categorystringMessage category"message"
textstringMessage text content"You there?"
sentAtnumberUnix timestamp when sent1771413707
deliveredAtnumberUnix timestamp when delivered1771413707
updatedAtnumberUnix timestamp when updated1771413707
senderobjectSender user detailsSee below ↓
receiverobjectReceiver user detailsSee below ↓
dataobjectAdditional message dataSee below ↓
metadataobjectMessage metadataContains @injected.extensions.link-preview
reactionsarrayMessage reactions[]
mentionedUsersarrayUsers mentioned in message[]
mentionedMebooleanWhether current user is mentionedfalse

sender Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-3"
namestringUser’s display name"Nancy Grace"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771413285
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-2"
namestringUser’s display name"George Alan"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771413280
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

data Object:
ParameterTypeDescriptionSample Value
textstringMessage text"You there?"
resourcestringSDK resource identifier"REACT_NATIVE-4_0_14-..."
entitiesobjectSender and receiver entitiesContains sender and receiver wrappers
metadataobjectInjected metadataContains @injected.extensions.link-preview
This method along with setGUID() or setUID() can be used to fetch unread messages for a particular group or user conversation respectively.

Exclude messages from blocked users

In other words, how do I fetch messages excluding the messages from the users I have blocked This can be easily achieved using the hideMessagesFromBlockedUsers() method. This method accepts a boolean value which determines if the messages from users blocked by the logged-in user need to be a part if the fetched messages. If the value is set to true, the messages will be hidden and won’t be a part of the messages fetched. The default value is false i.e if this method is not used, the messages from blocked users will be included in the fetched messages.
let UID = "UID";
let limit = 30;
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .hideMessagesFromBlockedUsers(true)
  .setLimit(limit)
  .build();
On SuccessfetchPrevious() returns messages excluding those from blocked users (includes group-call custom messages):Message Object (per item in array):
ParameterTypeDescriptionSample Value
idstringUnique message identifier"25239"
conversationIdstringConversation identifier"group_group_1748415903905"
receiverIdstringGroup’s GUID"group_1748415903905"
receiverTypestringType of receiver"group"
typestringMessage type"group-call"
categorystringMessage category"custom"
customDataobjectCustom message dataSee below ↓
sentAtnumberUnix timestamp when sent1771413265
updatedAtnumberUnix timestamp when updated1771413265
senderobjectSender user detailsSee below ↓
receiverobjectReceiver group detailsSee below ↓
dataobjectAdditional message dataSee below ↓
metadataobjectMessage metadataContains @injected.extensions.link-preview
reactionsarrayMessage reactions[]
mentionedUsersarrayUsers mentioned in message[]
mentionedMebooleanWhether current user is mentionedfalse

customData Object (for group-call):
ParameterTypeDescriptionSample Value
callTypestringType of call"audio"
isCallerbooleanWhether current user initiated calltrue
sessionIdstringCall session identifier"v1.in.2748663902141719..."

sender Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-2"
namestringUser’s display name"George Alan"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771412068
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

receiver Object (Group):
ParameterTypeDescriptionSample Value
guidstringGroup’s unique identifier"group_1748415903905"
namestringGroup’s display name"3 People Group"
typestringGroup type"public"
conversationIdstringConversation identifier"group_group_1748415903905"
ownerstringGroup owner’s UID"123456"
scopestringCurrent user’s scope in group"admin"
membersCountnumberTotal members in group12
onlineMembersCountnumberOnline members count1
hasJoinedbooleanWhether current user has joinedtrue
isBannedbooleanWhether current user is bannedfalse
joinedAtnumberTimestamp when user joined1748437105
createdAtnumberGroup creation timestamp1748415957
updatedAtnumberGroup update timestamp1771245340

data Object:
ParameterTypeDescriptionSample Value
customDataobjectCustom message dataSame as top-level customData
textstringDisplay text"Group video call started. Tap to join!"
resourcestringSDK resource identifier"REACT_NATIVE-4_0_14-..."
entitiesobjectSender and receiver entitiesContains sender and receiver wrappers
metadataobjectInjected metadataContains @injected.extensions.link-preview
moderationobjectModeration statusSee below ↓

data.moderation Object:
ParameterTypeDescriptionSample Value
statusstringModeration status"approved"
This method can be used to hide the messages by users blocked by logged in user in groups that both the members are a part of.

Updated and received messages

In other words, how do I fetch messages that have been received or updated after a particular date or time This method accepts a Unix timestamp value and will return all the messages that have been updated and the ones that have been sent/received after the specified time. The messages updated could mean the messages that have been marked as read/delivered or if the messages are edited or deleted.
let UID = "UID";
let limit = 30;
let timestamp = 1602221371;
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setUpdatedAfter(timestamp)
  .setLimit(limit)
  .build();
On SuccessfetchNext() returns messages received or updated after the specified timestamp:Message Object (per item in array):
ParameterTypeDescriptionSample Value
idstringUnique message identifier"25234"
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
receiverIdstringReceiver’s UID"cometchat-uid-2"
receiverTypestringType of receiver"user"
typestringMessage type"text"
categorystringMessage category"message"
textstringMessage text content"Nice"
sentAtnumberUnix timestamp when sent1771398092
deliveredAtnumberUnix timestamp when delivered1771398092
readAtnumberUnix timestamp when read1771404705
updatedAtnumberUnix timestamp when updated1771404705
senderobjectSender user detailsSee below ↓
receiverobjectReceiver user detailsSee below ↓
dataobjectAdditional message dataContains text, resource, entities, metadata
metadataobjectMessage metadataContains @injected.extensions.link-preview
reactionsarrayMessage reactions[]
mentionedUsersarrayUsers mentioned in message[]
mentionedMebooleanWhether current user is mentionedfalse

sender Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-3"
namestringUser’s display name"Nancy Grace"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771397739
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-2"
namestringUser’s display name"George Alan"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771397762
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]
This can be useful in finding the messages that have been received or updated after a certain time. Can prove very useful if you are saving the messages locally and would like to know the messages that have been updated or received after the last message available in your local databases.

Updated messages only

In other words, how do I fetch messages that have been updated after a particular date or time This can be achieved easily by setting the updatesOnly parameter to true. To do so, you can use the updatesOnly() method. This method takes a boolean input and can be used with the setUpdatedAfter() method to get just the updated messages and not the messages sent/received after the specified time. This method cannot be used independently and always needs to be used with the setUpdatedAfter() method.
let UID = "UID";
let limit = 30;
let timestamp = 1602221371;
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setUpdatedAfter(timestamp)
  .updatesOnly(true)
  .setLimit(limit)
  .build();
On SuccessfetchNext() returns only updated messages (e.g., read receipt changes, edits, deletions):Message Object (per item in array):
ParameterTypeDescriptionSample Value
idstringUnique message identifier"25189"
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
receiverIdstringReceiver’s UID"cometchat-uid-3"
receiverTypestringType of receiver"user"
typestringMessage type"image"
categorystringMessage category"message"
sentAtnumberUnix timestamp when sent1771323061
deliveredAtnumberUnix timestamp when delivered1771323062
readAtnumberUnix timestamp when read1771323227
updatedAtnumberUnix timestamp when updated1771323227
senderobjectSender user detailsSee below ↓
receiverobjectReceiver user detailsSee below ↓
dataobjectAdditional message dataSee below ↓
reactionsarrayMessage reactions[]
mentionedUsersarrayUsers mentioned in message[]
mentionedMebooleanWhether current user is mentionedfalse

sender Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-2"
namestringUser’s display name"George Alan"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771323060
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-3"
namestringUser’s display name"Nancy Grace"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringUser’s online status"offline"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771322968
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

data Object (for image message):
ParameterTypeDescriptionSample Value
typestringMedia type"image"
categorystringMessage category"message"
urlstringMedia URL"https://data-in.cometchat.io/..."
resourcestringSDK resource identifier"REACT_NATIVE-4_0_14-..."
attachmentsarrayFile attachmentsSee below ↓
entitiesobjectSender and receiver entitiesContains sender and receiver wrappers
moderationobjectModeration statusContains status: "approved"

data.attachments Array (per item):
ParameterTypeDescriptionSample Value
extensionstringFile extension"png"
mimeTypestringMIME type"image/png"
namestringFile name"photo.png"
sizenumberFile size in bytes2295572
urlstringFile URL"https://data-in.cometchat.io/..."

Messages for multiple categories

In other words, how do I fetch messages belonging to multiple categories We recommend before trying this, you refer to the Message structure and hierarchy guide to get familiar with the various categories of messages. For this, you will have to use the setCategories() method. This method accepts a list of categories. This tells the SDK to fetch messages only belonging to these categories.
let UID = "UID";
let limit = 30;
let categories = ["message", "custom"];
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setCategories(categories)
  .setLimit(limit)
  .build();
On SuccessfetchPrevious() returns messages from the specified categories (includes both custom and message categories):Message Object (per item in array):
ParameterTypeDescriptionSample Value
idstringUnique message identifier"25251"
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
receiverIdstringReceiver’s UID"cometchat-uid-2"
receiverTypestringType of receiver"user"
typestringMessage type"extension_poll" or "text"
categorystringMessage category"custom" or "message"
customDataobjectCustom message data (for custom category)See below ↓
textstringMessage text (for text type)"Hello Message"
sentAtnumberUnix timestamp when sent1771474256
deliveredAtnumberUnix timestamp when delivered1771474256
readAtnumberUnix timestamp when read1771474256
updatedAtnumberUnix timestamp when updated1771474256
senderobjectSender user detailsSee below ↓
receiverobjectReceiver user detailsSee below ↓
dataobjectAdditional message dataSee below ↓
metadataobjectMessage metadataSee below ↓
reactionsarrayMessage reactions[]
mentionedUsersarrayUsers mentioned in message[]
mentionedMebooleanWhether current user is mentionedfalse

customData Object (for poll extension):
ParameterTypeDescriptionSample Value
idstringPoll unique identifier"fde49a5e-baa8-4e04-95e9-c2c09557caa0"
questionstringPoll question"Custom"
optionsobjectPoll options{"1": "Yes", "2": "No"}

sender Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-3"
namestringUser’s display name"Nancy Grace"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771474104
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-2"
namestringUser’s display name"George Alan"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringUser’s online status"offline"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771474191
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

data Object:
ParameterTypeDescriptionSample Value
textstringDisplay text"Custom" or "Hello Message"
customDataobjectCustom data (for custom messages)Same as top-level customData
updateConversationbooleanWhether to update conversationtrue
resourcestringSDK resource identifier"REACT_NATIVE-4_0_14-..."
entitiesobjectSender and receiver entitiesContains sender and receiver wrappers
metadataobjectInjected metadataContains extensions data

metadata Object (for poll extension):
ParameterTypeDescriptionSample Value
@injectedobjectInjected extensions dataSee below ↓
incrementUnreadCountbooleanWhether to increment unread counttrue
pushNotificationstringPush notification text"Poll: Custom"

metadata.@injected.extensions Object:
ParameterTypeDescriptionSample Value
link-previewobjectLink preview data{"links": []}
pollsobjectPoll extension dataSee below ↓

metadata.@injected.extensions.polls Object:
ParameterTypeDescriptionSample Value
idstringPoll unique identifier"fde49a5e-baa8-4e04-95e9-c2c09557caa0"
questionstringPoll question"Custom"
optionsobjectPoll options{"1": "Yes", "2": "No"}
resultsobjectPoll resultsContains options and total
The above snippet will help you get only the messages belonging to the message and custom category. This can also be used to disable certain categories of messages like call and action. This along with setGUID() and setUID() can help display only the messages you wish to display avoiding the other category of messages.

Messages for multiple types

In other words, how do I fetch messages belonging to multiple types We recommend before trying this, you refer to the Message structure and hierarchy guide to get familiar with the various types of messages. This can be easily achieved using the setTypes() method. This method accepts a list of types. This tells the SDK to fetch messages only belonging to these types.
let UID = "UID";
let limit = 30;
let categories = ["message"];
let types = ["image", "video", "audio", "file"];
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setCategories(categories)
  .setTypes(types)
  .setLimit(limit)
  .build();
On SuccessfetchPrevious() returns only media messages (image, video, audio, file types):Message Object (per item in array):
ParameterTypeDescriptionSample Value
idstringUnique message identifier"25253"
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
receiverIdstringReceiver’s UID"cometchat-uid-2"
receiverTypestringType of receiver"user"
typestringMessage type"image" or "audio"
categorystringMessage category"message"
sentAtnumberUnix timestamp when sent1771474540
deliveredAtnumberUnix timestamp when delivered1771474540
readAtnumberUnix timestamp when read1771474540
updatedAtnumberUnix timestamp when updated1771474540
senderobjectSender user detailsSee below ↓
receiverobjectReceiver user detailsSee below ↓
dataobjectAdditional message dataSee below ↓
reactionsarrayMessage reactions[]
mentionedUsersarrayUsers mentioned in message[]
mentionedMebooleanWhether current user is mentionedfalse

sender Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-3"
namestringUser’s display name"Nancy Grace"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringUser’s online status"offline"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771474535
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-2"
namestringUser’s display name"George Alan"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringUser’s online status"offline"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771474191
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

data Object (for media messages):
ParameterTypeDescriptionSample Value
typestringMedia type"image" or "audio"
categorystringMessage category"message"
urlstringMedia URL"https://data-in.cometchat.io/..."
resourcestringSDK resource identifier"REACT_NATIVE-4_0_14-..."
attachmentsarrayFile attachmentsSee below ↓
entitiesobjectSender and receiver entitiesContains sender and receiver wrappers

data.attachments Array (per item):
ParameterTypeDescriptionSample Value
extensionstringFile extension"jpg" or "ogg"
mimeTypestringMIME type"image/jpeg" or "application/ogg"
namestringFile name"photo.jpg" or "audio.ogg"
sizenumberFile size in bytes142099
urlstringFile URL"https://data-in.cometchat.io/..."
Using the above code snippet, you can fetch all the media messages. This along with setUID() or setGUID() can be used to fetch media messages for any particular conversation. This can be useful in many other scenarios as well.

Messages for a specific thread

In other words, how do I fetch messages that are a part of a thread and not directly a user/group conversation This can be done using the setParentMessageId() method. This method needs to be used when you have implemented threaded conversations in your app. This method will return the messages only belonging to the thread with the specified parent Id.
let UID = "UID";
let messageId = 1; // Use msg.getId() on a message where msg.getReplyCount() > 0
let limit = 30;
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setLimit(limit)
  .setParentMessageId(messageId)
  .build();
On SuccessfetchPrevious() returns messages belonging to the specified thread:Message Object (per item in array):
ParameterTypeDescriptionSample Value
idstringUnique message identifier"25257"
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
receiverIdstringReceiver’s UID"cometchat-uid-2"
receiverTypestringType of receiver"user"
typestringMessage type"text"
categorystringMessage category"message"
textstringMessage text content"Thread Message"
parentMessageIdstringParent message ID (thread root)"25256"
sentAtnumberUnix timestamp when sent1771476403
deliveredAtnumberUnix timestamp when delivered1771476404
readAtnumberUnix timestamp when read1771476404
updatedAtnumberUnix timestamp when updated1771476404
senderobjectSender user detailsSee below ↓
receiverobjectReceiver user detailsSee below ↓
dataobjectAdditional message dataContains text, resource, entities, metadata
metadataobjectMessage metadataContains @injected.extensions.link-preview
reactionsarrayMessage reactions[]
mentionedUsersarrayUsers mentioned in message[]
mentionedMebooleanWhether current user is mentionedfalse

sender Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-3"
namestringUser’s display name"Nancy Grace"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771475038
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-2"
namestringUser’s display name"George Alan"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771475047
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]
The above code snippet returns the messages that belong to the thread with parent id 100.

Hide threaded messages in user/group conversations

In other words, how do I exclude threaded messages from the normal user/group conversations In order to do this, you can use the hideReplies() method. This method is also related to threaded conversations. This method takes boolean as input. This boolean when set to true will make sure that the messages that belong to threads are not fetched. If set to false, which is also the default value, the messages belong to the threads will also be fetched along with other messages.
let UID = "UID";
let limit = 30;
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setLimit(limit)
  .hideReplies(true)
  .build();
On SuccessfetchPrevious() returns messages excluding threaded replies (parent messages with threads still appear):Message Object (per item in array):
ParameterTypeDescriptionSample Value
idstringUnique message identifier"25256"
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
receiverIdstringReceiver’s UID"cometchat-uid-2"
receiverTypestringType of receiver"user"
typestringMessage type"text" or "audio"
categorystringMessage category"message"
textstringMessage text content"New Message for Thread"
replyCountnumberNumber of replies (for parent messages)1
sentAtnumberUnix timestamp when sent1771476391
deliveredAtnumberUnix timestamp when delivered1771476392
readAtnumberUnix timestamp when read1771476392
updatedAtnumberUnix timestamp when updated1771476392
senderobjectSender user detailsSee below ↓
receiverobjectReceiver user detailsSee below ↓
dataobjectAdditional message dataContains text, resource, entities, metadata or attachments
metadataobjectMessage metadataContains @injected.extensions.link-preview
reactionsarrayMessage reactions[]
mentionedUsersarrayUsers mentioned in message[]
mentionedMebooleanWhether current user is mentionedfalse

sender Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-3"
namestringUser’s display name"Nancy Grace"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771475038
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-2"
namestringUser’s display name"George Alan"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771475047
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

Hide deleted messages in user/group conversations

In other words, how do I exclude deleted messages from a user/group conversation In order to do this, you can use the hideDeletedMessages() method. This method takes boolean as input. This boolean when set to true will make sure that the deleted messages are not fetched. If set to false, which is also the default value, the deleted messages will also be fetched along with other messages.
let UID = "UID";
let limit = 30;
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setLimit(limit)
  .hideDeletedMessages(true)
  .build();
On SuccessfetchPrevious() returns messages excluding deleted messages:Message Object (per item in array):
ParameterTypeDescriptionSample Value
idstringUnique message identifier"25256"
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
receiverIdstringReceiver’s UID"cometchat-uid-2"
receiverTypestringType of receiver"user"
typestringMessage type"text"
categorystringMessage category"message"
textstringMessage text content"New Message for Thread"
replyCountnumberNumber of replies (if parent message)1
parentMessageIdstringParent message ID (if threaded reply)"25256"
sentAtnumberUnix timestamp when sent1771476391
deliveredAtnumberUnix timestamp when delivered1771476392
readAtnumberUnix timestamp when read1771476392
updatedAtnumberUnix timestamp when updated1771476392
senderobjectSender user detailsSee below ↓
receiverobjectReceiver user detailsSee below ↓
dataobjectAdditional message dataContains text, resource, entities, metadata
metadataobjectMessage metadataContains @injected.extensions.link-preview
reactionsarrayMessage reactions[]
mentionedUsersarrayUsers mentioned in message[]
mentionedMebooleanWhether current user is mentionedfalse

sender Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-3"
namestringUser’s display name"Nancy Grace"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771475038
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-2"
namestringUser’s display name"George Alan"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771475047
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

Messages by tags

In other words, how do I fetch messages by tags In order to do this, you can use the setTags() method. This method accepts a list of tags. This tells the SDK to fetch messages only belonging to these tags.
let UID = "UID";
let limit = 30;
let tags = ["starredMessage"];
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setLimit(limit)
  .setTags(tags)
  .build();
On SuccessfetchPrevious() returns only messages matching the specified tags:Message Object (per item in array):
ParameterTypeDescriptionSample Value
idstringUnique message identifier"25259"
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
receiverIdstringReceiver’s UID"cometchat-uid-2"
receiverTypestringType of receiver"user"
typestringMessage type"text"
categorystringMessage category"message"
textstringMessage text content"Tagged message for docs"
sentAtnumberUnix timestamp when sent1771478898
deliveredAtnumberUnix timestamp when delivered1771478900
readAtnumberUnix timestamp when read1771478900
updatedAtnumberUnix timestamp when updated1771478900
senderobjectSender user detailsSee below ↓
receiverobjectReceiver user detailsSee below ↓
dataobjectAdditional message dataContains text, resource, entities, metadata
metadataobjectMessage metadataContains @injected.extensions.link-preview
reactionsarrayMessage reactions[]
mentionedUsersarrayUsers mentioned in message[]
mentionedMebooleanWhether current user is mentionedfalse

sender Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-3"
namestringUser’s display name"Nancy Grace"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771478591
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-2"
namestringUser’s display name"George Alan"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringUser’s online status"offline"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771477541
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

Messages with tags

In other words, how do I fetch messages with the tags information In order to do this, you can use the withTags() method. This method accepts boolean as input. When set to true , the SDK will fetch messages along with the tags. When set to false , the SDK will not fetch tags associated with messages. The default value for this parameter is false .
let UID = "UID";
let limit = 30;
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setLimit(limit)
  .withTags(true)
  .build();
On SuccessfetchPrevious() returns messages with the tags field included:Message Object (per item in array):
ParameterTypeDescriptionSample Value
idstringUnique message identifier"25265"
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
receiverIdstringReceiver’s UID"cometchat-uid-3"
receiverTypestringType of receiver"user"
typestringMessage type"text"
categorystringMessage category"message"
textstringMessage text content"Tagged message for docs"
tagsarrayMessage tags["starredMessage"]
sentAtnumberUnix timestamp when sent1771481257
updatedAtnumberUnix timestamp when updated1771481257
senderobjectSender user detailsSee below ↓
receiverobjectReceiver user detailsSee below ↓
dataobjectAdditional message dataContains text, resource, entities, metadata, moderation
metadataobjectMessage metadataContains @injected.extensions.link-preview
reactionsarrayMessage reactions[]
mentionedUsersarrayUsers mentioned in message[]
mentionedMebooleanWhether current user is mentionedfalse

sender Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-2"
namestringUser’s display name"George Alan"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771480243
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-3"
namestringUser’s display name"Nancy Grace"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771480251
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]
In other words, as a logged-in user, how do I fetch messages that contain links? In order to do this, you can use the hasLinks() method. This method accepts boolean as input. When set to true , the SDK will fetch messages which have links in the text. The default value for this parameter is false.
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 UID = "UID";
let limit = 30;
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setLimit(limit)
  .hasLinks(true)
  .build();
On SuccessfetchPrevious() returns an array of Message objects containing links:Message Object (per item in array):
ParameterTypeDescriptionSample Value
idstringUnique message identifier"25269"
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
receiverIdstringReceiver’s UID"cometchat-uid-2"
receiverTypestringType of receiver"user"
typestringMessage type"text"
categorystringMessage category"message"
textstringMessage text content"Please checkout our website https://cometchat.com"
sentAtnumberUnix timestamp when sent1771481824
deliveredAtnumberUnix timestamp when delivered1771481825
readAtnumberUnix timestamp when read1771481825
updatedAtnumberUnix timestamp when updated1771481825
senderobjectSender user detailsSee below ↓
receiverobjectReceiver user detailsSee below ↓
dataobjectAdditional message dataSee below ↓
metadataobjectMessage metadataSee below ↓
reactionsarrayMessage reactions[]
mentionedUsersarrayUsers mentioned in message[]
mentionedMebooleanWhether current user is mentionedfalse

sender Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-3"
namestringUser’s display name"Nancy Grace"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771480251
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-2"
namestringUser’s display name"George Alan"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771480243
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

data Object:
ParameterTypeDescriptionSample Value
textstringMessage text"Please checkout our website https://cometchat.com"
resourcestringSDK resource identifier"REACT_NATIVE-4_0_14-..."
entitiesobjectSender and receiver entitiesSee below ↓
metadataobjectInjected metadataSee below ↓

data.entities Object:
ParameterTypeDescriptionSample Value
senderobjectSender entity wrapperSee below ↓
receiverobjectReceiver entity wrapperSee below ↓

data.entities.sender Object:
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectUser entity detailsSee below ↓

data.entities.sender.entity Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-3"
namestringUser’s display name"Nancy Grace"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771480251
tagsarrayUser tags[]

data.entities.receiver Object:
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectUser entity detailsSee below ↓

data.entities.receiver.entity Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-2"
namestringUser’s display name"George Alan"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771480243
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
tagsarrayUser tags[]

data.metadata Object:
ParameterTypeDescriptionSample Value
@injectedobjectInjected extensions dataSee below ↓

data.metadata.@injected Object:
ParameterTypeDescriptionSample Value
extensionsobjectExtensions dataSee below ↓

data.metadata.@injected.extensions Object:
ParameterTypeDescriptionSample Value
link-previewobjectLink preview extension dataSee below ↓

data.metadata.@injected.extensions.link-preview Object:
ParameterTypeDescriptionSample Value
linksarrayArray of link previewsSee below ↓

data.metadata.@injected.extensions.link-preview.links Array (per item):
ParameterTypeDescriptionSample Value
urlstringThe URL found in the message"https://cometchat.com"
titlestringPage title"In-app Chat SDK & API For Messaging And Calling - CometChat"
descriptionstringPage description"Build real time chat, voice and video calling experience..."
faviconstringURL to site favicon"https://cometchat.com/_static/favicon.png"
imagestringURL to preview image"https://a.storyblok.com/f/231922/1200x630/d639d0748b/open-graph-image.png/m/1200x630/"

metadata Object:
ParameterTypeDescriptionSample Value
@injectedobjectInjected extensions dataSee below ↓

metadata.@injected Object:
ParameterTypeDescriptionSample Value
extensionsobjectExtensions dataSee below ↓

metadata.@injected.extensions Object:
ParameterTypeDescriptionSample Value
link-previewobjectLink preview extensionSee below ↓

metadata.@injected.extensions.link-preview Object:
ParameterTypeDescriptionSample Value
linksarrayArray of link previewsSee below ↓

metadata.@injected.extensions.link-preview.links Array (per item):
ParameterTypeDescriptionSample Value
urlstringThe URL found in the message"https://cometchat.com"
titlestringPage title"In-app Chat SDK & API For Messaging And Calling - CometChat"
descriptionstringPage description"Build real time chat, voice and video calling experience..."
faviconstringURL to site favicon"https://cometchat.com/_static/favicon.png"
imagestringURL to preview image"https://a.storyblok.com/f/231922/1200x630/d639d0748b/open-graph-image.png/m/1200x630/"

Messages with attachments

In other words, as a logged-in user, how do I fetch messages that contain attachments? In order to do this, you can use the hasAttachments() method. This method accepts boolean as input. When set to true , the SDK will fetch messages which have attachments (image, audio, video or file). The default value for this parameter is false.
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 UID = "UID";
let limit = 30;
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setLimit(limit)
  .hasAttachments(true)
  .build();
On SuccessfetchPrevious() returns an array of Message objects with attachments:Message Object (per item in array):
ParameterTypeDescriptionSample Value
idstringUnique message identifier"25253"
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
receiverIdstringReceiver’s UID"cometchat-uid-2"
receiverTypestringType of receiver"user"
typestringMessage type"image"
categorystringMessage category"message"
sentAtnumberUnix timestamp when sent1771474540
deliveredAtnumberUnix timestamp when delivered1771474540
readAtnumberUnix timestamp when read1771474540
updatedAtnumberUnix timestamp when updated1771474540
senderobjectSender user detailsSee below ↓
receiverobjectReceiver user detailsSee below ↓
dataobjectAdditional message dataSee below ↓
reactionsarrayMessage reactions[]
mentionedUsersarrayUsers mentioned in message[]
mentionedMebooleanWhether current user is mentionedfalse

sender Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-3"
namestringUser’s display name"Nancy Grace"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringUser’s online status"offline"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771474535
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-2"
namestringUser’s display name"George Alan"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringUser’s online status"offline"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771474191
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

data Object:
ParameterTypeDescriptionSample Value
typestringAttachment type"image"
categorystringMessage category"message"
urlstringURL to the attachment"https://data-in.cometchat.io/2748663902141719/media/..."
resourcestringSDK resource identifier"REACT_NATIVE-4_0_14-..."
attachmentsarrayArray of attachment objectsSee below ↓
entitiesobjectSender and receiver entitiesSee below ↓

data.attachments Array (per item):
ParameterTypeDescriptionSample Value
extensionstringFile extension"jpg"
mimeTypestringMIME type of the file"image/jpeg"
namestringFile name"IMG_20260217_150412.jpg"
sizenumberFile size in bytes142099
urlstringURL to the attachment"https://data-in.cometchat.io/2748663902141719/media/..."

data.entities Object:
ParameterTypeDescriptionSample Value
senderobjectSender entity wrapperSee below ↓
receiverobjectReceiver entity wrapperSee below ↓

data.entities.sender Object:
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectUser entity detailsSee below ↓

data.entities.sender.entity Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-3"
namestringUser’s display name"Nancy Grace"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringUser’s online status"offline"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771474535
tagsarrayUser tags[]

data.entities.receiver Object:
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectUser entity detailsSee below ↓

data.entities.receiver.entity Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-2"
namestringUser’s display name"George Alan"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringUser’s online status"offline"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771474191
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
tagsarrayUser tags[]

Messages with reactions

In other words, as a logged-in user, how do I fetch messages that contain reactions? In order to do this, you can use the hasReactions() method. This method accepts boolean as input. When set to true , the SDK will fetch messages which have reactions. The default value for this parameter is false.
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 UID = "UID";
let limit = 30;
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setLimit(limit)
  .hasReactions(true)
  .build();
On SuccessfetchPrevious() returns an array of Message objects with reactions:Message Object (per item in array):
ParameterTypeDescriptionSample Value
idstringUnique message identifier"25275"
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
receiverIdstringReceiver’s UID"cometchat-uid-2"
receiverTypestringType of receiver"user"
typestringMessage type"text"
categorystringMessage category"message"
textstringMessage text content"Message with reactions"
sentAtnumberUnix timestamp when sent1771495045
deliveredAtnumberUnix timestamp when delivered1771495045
readAtnumberUnix timestamp when read1771495045
updatedAtnumberUnix timestamp when updated1771495045
senderobjectSender user detailsSee below ↓
receiverobjectReceiver user detailsSee below ↓
dataobjectAdditional message dataSee below ↓
metadataobjectMessage metadataSee below ↓
reactionsarrayMessage reactions[]
mentionedUsersarrayUsers mentioned in message[]
mentionedMebooleanWhether current user is mentionedfalse

sender Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-3"
namestringUser’s display name"Nancy Grace"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771495034
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-2"
namestringUser’s display name"George Alan"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771494233
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

data Object:
ParameterTypeDescriptionSample Value
textstringMessage text"Message with reactions"
resourcestringSDK resource identifier"REACT_NATIVE-4_0_14-..."
reactionsarrayReactions on the messageSee below ↓
entitiesobjectSender and receiver entitiesSee below ↓
metadataobjectInjected metadataSee below ↓

data.reactions Array (per item):
ParameterTypeDescriptionSample Value
reactionstringThe reaction emoji"❤️"
countnumberNumber of users who reacted1
reactedByMebooleanWhether current user reacted (optional)true

data.entities Object:
ParameterTypeDescriptionSample Value
senderobjectSender entity wrapperSee below ↓
receiverobjectReceiver entity wrapperSee below ↓

data.entities.sender Object:
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectUser entity detailsSee below ↓

data.entities.sender.entity Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-3"
namestringUser’s display name"Nancy Grace"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771495034
tagsarrayUser tags[]

data.entities.receiver Object:
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectUser entity detailsSee below ↓

data.entities.receiver.entity Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-2"
namestringUser’s display name"George Alan"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771494233
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
tagsarrayUser tags[]

data.metadata Object:
ParameterTypeDescriptionSample Value
@injectedobjectInjected extensions dataSee below ↓

data.metadata.@injected Object:
ParameterTypeDescriptionSample Value
extensionsobjectExtensions dataSee below ↓

data.metadata.@injected.extensions Object:
ParameterTypeDescriptionSample Value
link-previewobjectLink preview extension dataSee below ↓

data.metadata.@injected.extensions.link-preview Object:
ParameterTypeDescriptionSample Value
linksarrayExtracted links[]

metadata Object:
ParameterTypeDescriptionSample Value
@injectedobjectInjected extensions dataSee below ↓

metadata.@injected Object:
ParameterTypeDescriptionSample Value
extensionsobjectExtensions dataSee below ↓

metadata.@injected.extensions Object:
ParameterTypeDescriptionSample Value
link-previewobjectLink preview extension dataSee below ↓

metadata.@injected.extensions.link-preview Object:
ParameterTypeDescriptionSample Value
linksarrayExtracted links[]

Messages with mentions

In other words, as a logged-in user, how do I fetch messages that contain mentions? In order to do this, you can use the hasMentions() method. This method accepts boolean as input. When set to true , the SDK will fetch messages which have mentions. The default value for this parameter is false.
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 UID = "UID";
let limit = 30;
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setLimit(limit)
  .hasMentions(true)
  .build();
On SuccessfetchPrevious() returns an array of Message objects containing mentions:Message Object (per item in array):
ParameterTypeDescriptionSample Value
idstringUnique message identifier"25271"
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
receiverIdstringReceiver’s UID"cometchat-uid-2"
receiverTypestringType of receiver"user"
typestringMessage type"text"
categorystringMessage category"message"
textstringMessage text content"<@uid:cometchat-uid-2> Hello"
sentAtnumberUnix timestamp when sent1771482742
deliveredAtnumberUnix timestamp when delivered1771482743
readAtnumberUnix timestamp when read1771482743
updatedAtnumberUnix timestamp when updated1771482743
senderobjectSender user detailsSee below ↓
receiverobjectReceiver user detailsSee below ↓
dataobjectAdditional message dataSee below ↓
metadataobjectMessage metadataSee below ↓
reactionsarrayMessage reactions[]
mentionedUsersarrayUsers mentioned in messageSee below ↓
mentionedMebooleanWhether current user is mentionedtrue

mentionedUsers Array (per item):
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-2"
namestringUser’s display name"George Alan"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771494233
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0

sender Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-3"
namestringUser’s display name"Nancy Grace"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771482552
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-2"
namestringUser’s display name"George Alan"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771482544
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

data Object:
ParameterTypeDescriptionSample Value
textstringMessage text"<@uid:cometchat-uid-2> Hello"
resourcestringSDK resource identifier"REACT_NATIVE-4_0_14-..."
mentionsobjectMap of mentioned users by UIDSee below ↓
entitiesobjectSender and receiver entitiesSee below ↓
metadataobjectInjected metadataSee below ↓

data.mentions Object (keyed by UID):
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-2"
namestringUser’s display name"George Alan"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771494233

data.entities Object:
ParameterTypeDescriptionSample Value
senderobjectSender entity wrapperSee below ↓
receiverobjectReceiver entity wrapperSee below ↓

data.entities.sender Object:
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectUser entity detailsSee below ↓

data.entities.sender.entity Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-3"
namestringUser’s display name"Nancy Grace"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771482552
tagsarrayUser tags[]

data.entities.receiver Object:
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectUser entity detailsSee below ↓

data.entities.receiver.entity Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-2"
namestringUser’s display name"George Alan"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771482544
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
tagsarrayUser tags[]

data.metadata Object:
ParameterTypeDescriptionSample Value
@injectedobjectInjected extensions dataSee below ↓

data.metadata.@injected Object:
ParameterTypeDescriptionSample Value
extensionsobjectExtensions dataSee below ↓

data.metadata.@injected.extensions Object:
ParameterTypeDescriptionSample Value
link-previewobjectLink preview extensionSee below ↓

data.metadata.@injected.extensions.link-preview Object:
ParameterTypeDescriptionSample Value
linksarrayExtracted links[]

metadata Object:
ParameterTypeDescriptionSample Value
@injectedobjectInjected extensions dataSee below ↓

metadata.@injected Object:
ParameterTypeDescriptionSample Value
extensionsobjectExtensions dataSee below ↓

metadata.@injected.extensions Object:
ParameterTypeDescriptionSample Value
link-previewobjectLink preview extensionSee below ↓

metadata.@injected.extensions.link-preview Object:
ParameterTypeDescriptionSample Value
linksarrayExtracted links[]

Messages with particular user mentions

In other words, as a logged-in user, how do I fetch messages that mention specific users? In order to do this, you can use the setMentionedUIDs() method. This method accepts an array of UIDs as input. When set, the SDK will fetch messages which have the mentions of the UIDs passed.
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 UID = "UID";
let limit = 30;
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setLimit(limit)
  .setMentionedUIDs(["UID"])
  .build();
On SuccessfetchPrevious() returns an array of Message objects mentioning the specified UIDs:Message Object (per item in array):
ParameterTypeDescriptionSample Value
idstringUnique message identifier"25271"
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
receiverIdstringReceiver’s UID"cometchat-uid-2"
receiverTypestringType of receiver"user"
typestringMessage type"text"
categorystringMessage category"message"
textstringMessage text content"<@uid:cometchat-uid-2> Hello"
sentAtnumberUnix timestamp when sent1771482742
deliveredAtnumberUnix timestamp when delivered1771482743
readAtnumberUnix timestamp when read1771482743
updatedAtnumberUnix timestamp when updated1771482743
senderobjectSender user detailsSee below ↓
receiverobjectReceiver user detailsSee below ↓
dataobjectAdditional message dataSee below ↓
metadataobjectMessage metadataSee below ↓
reactionsarrayMessage reactions[]
mentionedUsersarrayUsers mentioned in messageSee below ↓
mentionedMebooleanWhether current user is mentionedtrue

mentionedUsers Array (per item):
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-2"
namestringUser’s display name"George Alan"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771494233
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0

sender Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-3"
namestringUser’s display name"Nancy Grace"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771482552
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-2"
namestringUser’s display name"George Alan"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771482544
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

data Object:
ParameterTypeDescriptionSample Value
textstringMessage text"<@uid:cometchat-uid-2> Hello"
resourcestringSDK resource identifier"REACT_NATIVE-4_0_14-..."
mentionsobjectMap of mentioned users by UIDSee below ↓
entitiesobjectSender and receiver entitiesSee below ↓
metadataobjectInjected metadataSee below ↓

data.mentions Object (keyed by UID):
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-2"
namestringUser’s display name"George Alan"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771494233

data.entities Object:
ParameterTypeDescriptionSample Value
senderobjectSender entity wrapperSee below ↓
receiverobjectReceiver entity wrapperSee below ↓

data.entities.sender Object:
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectUser entity detailsSee below ↓

data.entities.sender.entity Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-3"
namestringUser’s display name"Nancy Grace"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771482552
tagsarrayUser tags[]

data.entities.receiver Object:
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectUser entity detailsSee below ↓

data.entities.receiver.entity Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-2"
namestringUser’s display name"George Alan"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771482544
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
tagsarrayUser tags[]

data.metadata Object:
ParameterTypeDescriptionSample Value
@injectedobjectInjected extensions dataSee below ↓

data.metadata.@injected Object:
ParameterTypeDescriptionSample Value
extensionsobjectExtensions dataSee below ↓

data.metadata.@injected.extensions Object:
ParameterTypeDescriptionSample Value
link-previewobjectLink preview extensionSee below ↓

data.metadata.@injected.extensions.link-preview Object:
ParameterTypeDescriptionSample Value
linksarrayExtracted links[]

metadata Object:
ParameterTypeDescriptionSample Value
@injectedobjectInjected extensions dataSee below ↓

metadata.@injected Object:
ParameterTypeDescriptionSample Value
extensionsobjectExtensions dataSee below ↓

metadata.@injected.extensions Object:
ParameterTypeDescriptionSample Value
link-previewobjectLink preview extensionSee below ↓

metadata.@injected.extensions.link-preview Object:
ParameterTypeDescriptionSample Value
linksarrayExtracted links[]

Messages with specific attachment types

In other words, as a logged-in user, how do I fetch messages that contain specific types of attachments? In order to do this, you can use the setAttachmentTypes() method. This method accepts an array of CometChat.AttachmentType ENUM values as input. When provided, the SDK will fetch only those messages that include attachments of the specified types (such as image, audio, video, or file).
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 UID = "UID";
let limit = 30;
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setLimit(limit)
  .setAttachmentTypes([CometChat.AttachmentType.IMAGE, CometChat.AttachmentType.VIDEO])
  .build();
On SuccessfetchPrevious() returns an array of Message objects with the specified attachment types:Message Object (per item in array):
ParameterTypeDescriptionSample Value
idstringUnique message identifier"25196"
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
receiverIdstringReceiver’s UID"cometchat-uid-2"
receiverTypestringType of receiver"user"
typestringMessage type"image"
categorystringMessage category"message"
sentAtnumberUnix timestamp when sent1771386517
deliveredAtnumberUnix timestamp when delivered1771386517
readAtnumberUnix timestamp when read1771483750
updatedAtnumberUnix timestamp when updated1771483750
senderobjectSender user detailsSee below ↓
receiverobjectReceiver user detailsSee below ↓
dataobjectAdditional message dataSee below ↓
reactionsarrayMessage reactions[]
mentionedUsersarrayUsers mentioned in message[]
mentionedMebooleanWhether current user is mentionedfalse

sender Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-3"
namestringUser’s display name"Nancy Grace"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringUser’s online status"offline"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771386507
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-2"
namestringUser’s display name"George Alan"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringUser’s online status"offline"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771386436
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

data Object:
ParameterTypeDescriptionSample Value
typestringAttachment type"image"
categorystringMessage category"message"
urlstringURL to the attachment"https://data-in.cometchat.io/2748663902141719/media/..."
resourcestringSDK resource identifier"REACT_NATIVE-4_0_14-..."
attachmentsarrayArray of attachment objectsSee below ↓
entitiesobjectSender and receiver entitiesSee below ↓

data.attachments Array (per item):
ParameterTypeDescriptionSample Value
extensionstringFile extension"jpg"
mimeTypestringMIME type of the file"image/jpeg"
namestringFile name"IMG_20260217_150412.jpg"
sizenumberFile size in bytes142099
urlstringURL to the attachment"https://data-in.cometchat.io/2748663902141719/media/..."

data.entities Object:
ParameterTypeDescriptionSample Value
senderobjectSender entity wrapperSee below ↓
receiverobjectReceiver entity wrapperSee below ↓

data.entities.sender Object:
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectUser entity detailsSee below ↓

data.entities.sender.entity Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-3"
namestringUser’s display name"Nancy Grace"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringUser’s online status"offline"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771386507
tagsarrayUser tags[]

data.entities.receiver Object:
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectUser entity detailsSee below ↓

data.entities.receiver.entity Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-2"
namestringUser’s display name"George Alan"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringUser’s online status"offline"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771386436
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
tagsarrayUser tags[]

Best Practices & Troubleshooting

Always call fetchNext() or fetchPrevious() on the same MessagesRequest object to paginate through results. Creating a new MessagesRequest object will reset pagination and start from the beginning.
You can chain multiple builder methods together (e.g., setCategories() + setTypes() + setUID()) to narrow down results. This is more efficient than fetching all messages and filtering client-side.
If you store messages locally, use setUpdatedAfter() with the timestamp of your last synced message to fetch only new or updated messages. Combine with updatesOnly(true) if you only need edits, deletions, and read/delivery status changes.
The maximum limit per fetch is 100. For most UI use cases, a limit of 30–50 provides a good balance between performance and user experience. Smaller limits mean faster responses and less memory usage.
If fetchNext() or fetchPrevious() returns an empty array, verify that: the logged-in user is a member of the group (for group conversations), the UID/GUID is correct, and the applied filters aren’t too restrictive. Try removing filters one at a time to isolate the issue.
Methods like hasLinks(), hasAttachments(), hasReactions(), hasMentions(), setMentionedUIDs(), and setAttachmentTypes() require the Conversation & Advanced Search feature to be enabled. Ensure you are on an Advanced or Custom plan and have enabled the feature from the CometChat Dashboard (Chats → Settings → General Configuration).

Next Steps