Skip to main content
Quick Reference for AI Agents & Developers
// Send transient message to user
val data = JSONObject()
data.put("LIVE_REACTION", "heart")
val transientMessage = TransientMessage("UID", CometChatConstants.RECEIVER_TYPE_USER, data)
CometChat.sendTransientMessage(transientMessage)

// Receive transient messages
CometChat.addMessageListener("LISTENER_ID", object : MessageListener() {
    override fun onTransientMessageReceived(transientMessage: TransientMessage) {
        Log.d(TAG, "Transient message: ${transientMessage.data}")
    }
})
Transient messages are messages that are sent in real-time only and are not saved or tracked anywhere. The receiver of the message will only receive the message if he is online and these messages cannot be retrieved later.
Available via: SDK | REST API | UI Kits

Send a Transient Message

You can use the sendTransientMessage() 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.
String receiverId = "cometchat-uid-2";
String receiverType = CometChatConstants.RECEIVER_TYPE_USER;

JSONObject data = new JSONObject();
data.put("LIVE_REACTION", "heart");
TransientMessage transientMessage = new TransientMessage(uid, CometChatConstants.RECEIVER_TYPE_USER, data);
CometChat.sendTransientMessage(transientMessage);

Real-time Transient Messages

How do I know when someone sends a transient message? You will receive the transient message in the onTransientMessageReceived() method of the registered MessageListener class.
CometChat.addMessageListener("UNIQUE_LISTENER_ID", new CometChat.MessageListener() {
  @Override
  public void onTransientMessageReceived(TransientMessage transientMessage) {
    Log.d(TAG, "Transient message received with data : " + transientMessage.getData());  
  }
});
The TransientMessage class consists of the below parameters:
ParameterInformation
senderAn object of the User class holding all the information. related to the sender of the transient message.
receiverIdUnique Id of the receiver. This can be the Id of the group or the user the transient message is sent to.
receiverTypeThe type of the receiver - CometChat.RECEIVER_TYPE.USER or CometChat.RECEIVER_TYPE.GROUP
dataA JSONObject to provide data.
Always remove listeners when they’re no longer needed (e.g., in onDestroy() or when navigating away). Failing to remove listeners can cause memory leaks and duplicate event handling.

Best Practices

Transient messages are ideal for temporary events like typing indicators, live reactions, or presence updates. For messages that need to be stored or retrieved later, use regular text or custom messages instead.
Since transient messages are sent in real-time, keep the data payload minimal to reduce network overhead and improve delivery speed. Avoid sending large objects or binary data.
Transient messages are only delivered to online users. If delivery confirmation is critical, implement a fallback mechanism using regular messages or check user presence before sending.

Next Steps