Skip to main content

Documentation Index

Fetch the complete documentation index at: https://cometchat-22654f5b-docs-android-v6-beta2.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

FieldValue
Key ClassesTransientMessage
Key MethodsCometChat.sendTransientMessage()
Receiver TypesCometChatReceiverType.user, CometChatReceiverType.group
Listener EventsonTransientMessageReceived
PrerequisitesSDK initialized, user logged in
// Send transient message (not stored on server)
Map<String, dynamic> data = {"LIVE_REACTION": "heart"};
TransientMessage transientMessage = TransientMessage(
  receiverId: "UID",
  receiverType: CometChatReceiverType.user,
  data: data,
);
CometChat.sendTransientMessage(transientMessage,
  onSuccess: () => debugPrint("Sent"),
  onError: (e) => debugPrint("Error: ${e.message}"),
);

// Receive transient messages
CometChat.addMessageListener("LISTENER_ID", MessageListener(
  onTransientMessageReceived: (TransientMessage message) {
    debugPrint("Received: ${message.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 | 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";
Map<String, dynamic> data = {};
data["LIVE_REACTION"] = "heart";

TransientMessage transientMessage = TransientMessage(
  receiverId: receiverId,
  receiverType: CometChatReceiverType.user,
  data: data,
);

CometChat.sendTransientMessage(transientMessage, onSuccess: () {
  debugPrint("Transient Message Sent");
}, onError: (CometChatException e) {
  debugPrint("Transient message sending failed with exception: ${e.message}");
});
TransientMessage Parameters:
ParameterTypeDescriptionRequired
receiverIdStringThe UID of the user or GUID of the group to send the transient message toYes
receiverTypeStringThe type of the receiver — CometChatReceiverType.user or CometChatReceiverType.groupYes
dataMap<String, dynamic>A map to provide custom data with the transient messageYes
senderUser?The sender of the transient message (set automatically by the SDK)No
ParameterTypeDescriptionSample Value
codeStringError code identifier"ERR_CHAT_API_FAILURE"
messageStringHuman-readable error message"Failed to send the transient message."
detailsStringAdditional technical details"An unexpected error occurred while sending the transient message."

Real-time Transient Messages

In other words, as a recipient, how do I know when someone sends a transient message?
Always remove listeners when they’re no longer needed (e.g., in the dispose() method). Failing to remove listeners can cause memory leaks and duplicate event handling.
CometChat.removeMessageListener("listenerId");
You will receive the transient message in the onTransientMessageReceived() method of the registered MessageListener class.
class Class_Name  with MessageListener {

//CometChat.addMessageListener("listenerId", this);
@override
void onTransientMessageReceived(TransientMessage message) {
  // TODO: implement onTransientMessageReceived
}


}
The received object is a TransientMessage with the following fields:
ParameterTypeDescription
senderUser?An object of the User class holding all the information related to the sender of the transient message.
receiverIdStringUnique ID of the receiver. This can be the UID of the user or GUID of the group the transient message is sent to.
receiverTypeStringThe type of the receiver — CometChatReceiverType.user or CometChatReceiverType.group.
dataMap<String, dynamic>A map containing the custom data sent with the transient message.

Next Steps

Send Messages

Learn how to send persistent text and media messages

Typing Indicators

Show real-time typing status to users