Skip to main content
// Send transient message to user
const msg = new CometChat.TransientMessage("UID", CometChat.RECEIVER_TYPE.USER, { LIVE_REACTION: "heart" });
CometChat.sendTransientMessage(msg);

// Listen for transient messages
CometChat.addMessageListener("LISTENER_ID", new CometChat.MessageListener({
  onTransientMessageReceived: (msg) => console.log("Transient:", msg)
}));
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.

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.
let receiverId: string = "UID";
let receiverType: string = CometChat.RECEIVER_TYPE.USER;
let data: Object = { "LIVE_REACTION": "heart" };

let transientMessage: CometChat.TransientMessage = new CometChat.TransientMessage(receiverId, receiverType, data);
CometChat.sendTransientMessage(transientMessage);
sendTransientMessage() returns void — the message is sent as a fire-and-forget operation with no response.

Real-time Transient Messages

Always remove listeners when they’re no longer needed (e.g., on component unmount or page navigation). Failing to remove listeners can cause memory leaks and duplicate event handling.
You will receive the transient message in the onTransientMessageReceived() method of the registered MessageListener class.
let listenerId: string = "UNIQUE_LISTENER_ID";

CometChat.addMessageListener(
  listenerId,
  new CometChat.MessageListener({
      onTransientMessageReceived: (transientMessage: CometChat.TransientMessage) => {
          console.log('transient message received', transientMessage);
      },
  })
);
The received object is a TransientMessage.

Next Steps

Typing Indicators

Show real-time typing status in conversations

Send Messages

Send text, media, and custom messages