Skip to main content
Quick Reference - Core messaging methods:
// Send a text message
const textMessage = new CometChat.TextMessage("UID", "Hello!", CometChat.RECEIVER_TYPE.USER);
await CometChat.sendMessage(textMessage);

// Listen for incoming messages
CometChat.addMessageListener("listener-id", new CometChat.MessageListener({
  onTextMessageReceived: (msg) => console.log("Text:", msg),
  onMediaMessageReceived: (msg) => console.log("Media:", msg),
  onCustomMessageReceived: (msg) => console.log("Custom:", msg),
}));
Available via: SDK | REST API | UI Kits
Messaging is one of the core features of CometChat. We’ve thoughtfully created methods to help you send, receive and fetch message history. At the minimum, you must add code for sending messages and receiving messages. Once you’ve implemented that, you can proceed to more advanced features like typing indicators and delivery & read receipts.

Send a Message

Use CometChat.sendMessage() to send a text message to a user or group. The method returns a TextMessage object on success.
On Success — Returns a TextMessage object:TextMessage Object:
ParameterTypeDescriptionSample Value
idstringUnique message identifier"25182"
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
textstringMessage text content"Hello"
typestringMessage type"text"
categorystringMessage category"message"
receiverIdstringUID of the receiver"cometchat-uid-3"
receiverTypestringType of receiver"user"
sentAtnumberUnix timestamp when sent1771320772
updatedAtnumberUnix timestamp of last update1771320772
senderobjectSender user detailsSee below ↓
receiverobjectReceiver user detailsSee below ↓
dataobjectAdditional message dataSee below ↓
reactionsarrayMessage reactions[]
mentionedUsersarrayUsers mentioned in message[]
mentionedMebooleanWhether logged-in user is mentionedfalse
metadataobjectCustom metadata{"@injected": {"extensions": {"link-preview": {"links": []}}}}

sender Object:
ParameterTypeDescriptionSample Value
uidstringUnique identifier of the sender"cometchat-uid-2"
namestringDisplay name"George Alan"
avatarstringURL to avatar image"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringOnline status"online"
rolestringUser role"default"
lastActiveAtnumberUnix timestamp of last activity1771320632
hasBlockedMebooleanWhether sender has blocked logged-in userfalse
blockedByMebooleanWhether logged-in user has blocked senderfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUnique identifier of the receiver"cometchat-uid-3"
namestringDisplay name"Nancy Grace"
avatarstringURL to avatar image"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringOnline status"online"
rolestringUser role"default"
lastActiveAtnumberUnix timestamp of last activity1771320647
hasBlockedMebooleanWhether receiver has blocked logged-in userfalse
blockedByMebooleanWhether logged-in user has blocked receiverfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

data Object:
ParameterTypeDescriptionSample Value
textstringMessage text"Hello"
resourcestringSDK resource identifier"REACT_NATIVE-4_0_13-..."
entitiesobjectSender and receiver entitiesSee below ↓
metadataobjectInjected metadata from extensions{"@injected": {"extensions": {"link-preview": {"links": []}}}}
moderationobjectModeration statusSee below ↓

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

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

data.entities.sender.entity Object:
ParameterTypeDescriptionSample Value
uidstringUnique identifier"cometchat-uid-2"
namestringDisplay name"George Alan"
avatarstringURL to avatar image"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringOnline status"online"
rolestringUser role"default"
lastActiveAtnumberUnix timestamp of last activity1771320632
tagsarrayUser tags[]

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

data.entities.receiver.entity Object:
ParameterTypeDescriptionSample Value
uidstringUnique identifier"cometchat-uid-3"
namestringDisplay name"Nancy Grace"
avatarstringURL to avatar image"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringOnline status"online"
rolestringUser role"default"
lastActiveAtnumberUnix timestamp of last activity1771320647
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
tagsarrayUser tags[]

data.moderation Object:
ParameterTypeDescriptionSample Value
statusstringModeration status"pending"

Receive Messages in Real Time

Use CometChat.addMessageListener() to listen for incoming text, media, and custom messages while your app is running.
onTextMessageReceived — Returns a TextMessage object:TextMessage Object:
ParameterTypeDescriptionSample Value
idstringUnique message identifier"25180"
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
textstringMessage text content"Hello"
typestringMessage type"text"
categorystringMessage category"message"
receiverIdstringUID of the receiver"cometchat-uid-2"
receiverTypestringType of receiver"user"
sentAtnumberUnix timestamp when sent1771320657
updatedAtnumberUnix timestamp of last update1771320657
senderobjectSender user detailsSee below ↓
receiverobjectReceiver user detailsSee below ↓
dataobjectAdditional message dataSee below ↓
reactionsarrayMessage reactions[]
mentionedUsersarrayUsers mentioned in message[]
mentionedMebooleanWhether logged-in user is mentionedfalse
metadataobjectCustom metadata{"@injected": {"extensions": {"link-preview": {"links": []}}}}

sender Object (TextMessage):
ParameterTypeDescriptionSample Value
uidstringUnique identifier of the sender"cometchat-uid-3"
namestringDisplay name"Nancy Grace"
avatarstringURL to avatar image"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringOnline status"online"
rolestringUser role"default"
lastActiveAtnumberUnix timestamp of last activity1771320647
hasBlockedMebooleanWhether sender has blocked logged-in userfalse
blockedByMebooleanWhether logged-in user has blocked senderfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

receiver Object (TextMessage):
ParameterTypeDescriptionSample Value
uidstringUnique identifier of the receiver"cometchat-uid-2"
namestringDisplay name"George Alan"
avatarstringURL to avatar image"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringOnline status"online"
rolestringUser role"default"
lastActiveAtnumberUnix timestamp of last activity1771320632
hasBlockedMebooleanWhether receiver has blocked logged-in userfalse
blockedByMebooleanWhether logged-in user has blocked receiverfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

data Object (TextMessage):
ParameterTypeDescriptionSample Value
textstringMessage text"Hello"
resourcestringSDK resource identifier"REACT_NATIVE-4_0_13-..."
entitiesobjectSender and receiver entitiesSee below ↓
metadataobjectInjected metadata from extensions{"@injected": {"extensions": {"link-preview": {"links": []}}}}
moderationobjectModeration status{"status": "approved"}

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

data.entities.sender Object (TextMessage):
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectSender user detailsSee below ↓

data.entities.sender.entity Object (TextMessage):
ParameterTypeDescriptionSample Value
uidstringUnique identifier"cometchat-uid-3"
namestringDisplay name"Nancy Grace"
avatarstringURL to avatar image"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringOnline status"online"
rolestringUser role"default"
lastActiveAtnumberUnix timestamp of last activity1771320647
tagsarrayUser tags[]

data.entities.receiver Object (TextMessage):
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectReceiver user detailsSee below ↓

data.entities.receiver.entity Object (TextMessage):
ParameterTypeDescriptionSample Value
uidstringUnique identifier"cometchat-uid-2"
namestringDisplay name"George Alan"
avatarstringURL to avatar image"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringOnline status"online"
rolestringUser role"default"
lastActiveAtnumberUnix timestamp of last activity1771320632
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
tagsarrayUser tags[]

onMediaMessageReceived — Returns a MediaMessage object:MediaMessage Object:
ParameterTypeDescriptionSample Value
idstringUnique message identifier"25183"
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
typestringMedia type"image"
categorystringMessage category"message"
receiverIdstringUID of the receiver"cometchat-uid-2"
receiverTypestringType of receiver"user"
sentAtnumberUnix timestamp when sent1771320862
updatedAtnumberUnix timestamp of last update1771320862
senderobjectSender user detailsSee below ↓
receiverobjectReceiver user detailsSee below ↓
dataobjectAdditional message dataSee below ↓
reactionsarrayMessage reactions[]
mentionedUsersarrayUsers mentioned in message[]
mentionedMebooleanWhether logged-in user is mentionedfalse

sender Object (MediaMessage):
ParameterTypeDescriptionSample Value
uidstringUnique identifier of the sender"cometchat-uid-3"
namestringDisplay name"Nancy Grace"
avatarstringURL to avatar image"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringOnline status"offline"
rolestringUser role"default"
lastActiveAtnumberUnix timestamp of last activity1771320859
hasBlockedMebooleanWhether sender has blocked logged-in userfalse
blockedByMebooleanWhether logged-in user has blocked senderfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

receiver Object (MediaMessage):
ParameterTypeDescriptionSample Value
uidstringUnique identifier of the receiver"cometchat-uid-2"
namestringDisplay name"George Alan"
avatarstringURL to avatar image"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringOnline status"online"
rolestringUser role"default"
lastActiveAtnumberUnix timestamp of last activity1771320632
hasBlockedMebooleanWhether receiver has blocked logged-in userfalse
blockedByMebooleanWhether logged-in user has blocked receiverfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

data Object (MediaMessage):
ParameterTypeDescriptionSample Value
typestringMedia type"image"
categorystringMessage category"message"
urlstringURL to the media file"https://data-in.cometchat.io/.../1771320861_514214897_9876c9a3f300f29c8ee619765c1ad768.jpg"
resourcestringSDK resource identifier"REACT_NATIVE-4_0_13-..."
attachmentsarrayMedia attachmentsSee below ↓
entitiesobjectSender and receiver entitiesSee below ↓
moderationobjectModeration status{"status": "approved"}

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

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

data.entities.sender Object (MediaMessage):
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectSender user detailsSee below ↓

data.entities.sender.entity Object (MediaMessage):
ParameterTypeDescriptionSample Value
uidstringUnique identifier"cometchat-uid-3"
namestringDisplay name"Nancy Grace"
avatarstringURL to avatar image"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringOnline status"offline"
rolestringUser role"default"
lastActiveAtnumberUnix timestamp of last activity1771320859
tagsarrayUser tags[]

data.entities.receiver Object (MediaMessage):
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectReceiver user detailsSee below ↓

data.entities.receiver.entity Object (MediaMessage):
ParameterTypeDescriptionSample Value
uidstringUnique identifier"cometchat-uid-2"
namestringDisplay name"George Alan"
avatarstringURL to avatar image"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringOnline status"online"
rolestringUser role"default"
lastActiveAtnumberUnix timestamp of last activity1771320632
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
tagsarrayUser tags[]

onCustomMessageReceived — Returns a CustomMessage object:CustomMessage Object:
ParameterTypeDescriptionSample Value
idstringUnique message identifier"25191"
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
typestringCustom message type"test-custom"
categorystringMessage category"custom"
receiverIdstringUID of the receiver"cometchat-uid-2"
receiverTypestringType of receiver"user"
sentAtnumberUnix timestamp when sent1771324025
updatedAtnumberUnix timestamp of last update1771324025
customDataobjectCustom payload dataSee below ↓
senderobjectSender user detailsSee below ↓
receiverobjectReceiver user detailsSee below ↓
dataobjectAdditional message dataSee below ↓
reactionsarrayMessage reactions[]
mentionedUsersarrayUsers mentioned in message[]
mentionedMebooleanWhether logged-in user is mentionedfalse
metadataobjectCustom metadata{"@injected": {"extensions": {"link-preview": {"links": []}}}}

customData Object:
ParameterTypeDescriptionSample Value
greetingstringCustom greeting message"Hello from custom message!"
timestampnumberCustom timestamp1771324022864

sender Object (CustomMessage):
ParameterTypeDescriptionSample Value
uidstringUnique identifier of the sender"cometchat-uid-3"
namestringDisplay name"Nancy Grace"
avatarstringURL to avatar image"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringOnline status"offline"
rolestringUser role"default"
lastActiveAtnumberUnix timestamp of last activity1771323567
hasBlockedMebooleanWhether sender has blocked logged-in userfalse
blockedByMebooleanWhether logged-in user has blocked senderfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

receiver Object (CustomMessage):
ParameterTypeDescriptionSample Value
uidstringUnique identifier of the receiver"cometchat-uid-2"
namestringDisplay name"George Alan"
avatarstringURL to avatar image"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringOnline status"online"
rolestringUser role"default"
lastActiveAtnumberUnix timestamp of last activity1771323089
hasBlockedMebooleanWhether receiver has blocked logged-in userfalse
blockedByMebooleanWhether logged-in user has blocked receiverfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

data Object (CustomMessage):
ParameterTypeDescriptionSample Value
textstringFallback text"Sent a custom message"
resourcestringSDK resource identifier"REACT_NATIVE-4_0_14-..."
customDataobjectCustom payload data{"greeting": "Hello from custom message!", "timestamp": 1771324022864}
entitiesobjectSender and receiver entitiesSee below ↓
metadataobjectInjected metadata from extensions{"@injected": {"extensions": {"link-preview": {"links": []}}}}
moderationobjectModeration status{"status": "approved"}

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

data.entities.sender Object (CustomMessage):
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectSender user detailsSee below ↓

data.entities.sender.entity Object (CustomMessage):
ParameterTypeDescriptionSample Value
uidstringUnique identifier"cometchat-uid-3"
namestringDisplay name"Nancy Grace"
avatarstringURL to avatar image"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
statusstringOnline status"offline"
rolestringUser role"default"
lastActiveAtnumberUnix timestamp of last activity1771323567
tagsarrayUser tags[]

data.entities.receiver Object (CustomMessage):
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectReceiver user detailsSee below ↓

data.entities.receiver.entity Object (CustomMessage):
ParameterTypeDescriptionSample Value
uidstringUnique identifier"cometchat-uid-2"
namestringDisplay name"George Alan"
avatarstringURL to avatar image"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
statusstringOnline status"online"
rolestringUser role"default"
lastActiveAtnumberUnix timestamp of last activity1771323089
conversationIdstringConversation identifier"cometchat-uid-2_user_cometchat-uid-3"
tagsarrayUser tags[]

Next Steps