Quick Reference — Send a transient message:
Available via: SDK
Send a Transient Message
You can use thesendTransientMessage() method to send a transient message to a user or in a group. The receiver will receive this information in the onTransientMessageReceived() method of the MessageListener class. In order to send the transient message, you need to use the TransientMessage class.
- To User
- To Group
- TypeScript (User)
- TypeScript (Group)
Response
Response
On Success —
sendTransientMessage() does not return a value, but the transient message object sent looks like:TransientMessage Object:| Parameter | Type | Description | Sample Value |
|---|---|---|---|
receiverId | string | Receiver’s unique identifier | "cometchat-uid-7" |
receiverType | string | Type of receiver | "user" |
data | object | Custom data payload | See below ↓ |
data Object:| Parameter | Type | Description | Sample Value |
|---|---|---|---|
LIVE_REACTION | string | Live reaction type | "heart" |
Real-time Transient Messages
In other words, as a recipient, how do I know when someone sends a transient message? You will receive the transient message in theonTransientMessageReceived() method of the registered MessageListener class.
- JavaScript
- TypeScript
Response
Response
On Event —
onTransientMessageReceived returns the transient message object with sender info:TransientMessage Object:| Parameter | Type | Description | Sample Value |
|---|---|---|---|
receiverId | string | Receiver’s unique identifier | "cometchat-uid-7" |
receiverType | string | Type of receiver | "user" |
data | object | Custom data payload | See below ↓ |
sender | object | User who sent the transient message | See below ↓ |
data Object:| Parameter | Type | Description | Sample Value |
|---|---|---|---|
LIVE_REACTION | string | Live reaction type | "heart" |
sender Object:| Parameter | Type | Description | Sample Value |
|---|---|---|---|
uid | string | User’s unique identifier | "cometchat-uid-6" |
name | string | User’s display name | "Ronald Jerry" |
avatar | string | URL to user’s avatar | "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-6.webp" |
status | string | User’s online status | "online" |
role | string | User’s role | "default" |
hasBlockedMe | boolean | Whether user has blocked current user | false |
blockedByMe | boolean | Whether current user blocked this user | false |
deactivatedAt | number | Deactivation timestamp (0 if active) | 0 |
tags | array | User tags | [] |
TransientMessage class consists of the below parameters:
| Parameter | Information |
|---|---|
| sender | An object of the User class holding all the information. related to the sender of the transient message. |
| receiverId | Unique Id of the receiver. This can be the Id of the group or the user the transient message is sent to. |
| receiverType | The type of the receiver - CometChat.RECEIVER_TYPE.USER or CometChat.RECEIVER_TYPE.GROUP |
| data | A JSONObject to provide data. |
Best Practices
Best Practices
- Use transient messages for ephemeral interactions only — Since transient messages are not stored, they are ideal for features like live reactions, presence pings, or real-time indicators that don’t need to persist.
- Keep the data payload small — Transient messages are designed for lightweight, real-time signals. Avoid sending large JSON objects in the
datafield. - Use unique listener IDs — Each screen or component that registers a
MessageListenershould use a distinctlistenerIdto avoid conflicts with other listeners. - Confirm the receiver is online — Transient messages are only delivered to online users. If guaranteed delivery is required, use a regular message instead.
- Pair with typing indicators for richer UX — Combine transient messages with typing indicators to build expressive, real-time chat experiences.
Troubleshooting
Troubleshooting
- Recipient not receiving transient messages — Verify that the recipient is online and has registered a
MessageListenerwith theonTransientMessageReceivedcallback before the sender dispatches the message. - Listener not firing — Confirm that the
listenerIdused inaddMessageListeneris unique and that the listener has not been removed prematurely. - Messages not arriving in groups — Make sure you are using
CometChat.RECEIVER_TYPE.GROUPwith the correct group ID (GUID), not a user ID. - Cannot retrieve transient messages later — This is expected behavior. Transient messages are never stored. If you need message persistence, use send a message instead.
- Data field appears empty on the receiver side — Ensure you are passing a valid JSON object to the
dataparameter when constructing theTransientMessageinstance.