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 ClassesTextMessage, MediaMessage, CustomMessage
Key MethodsCometChat.sendMessage(), CometChat.sendMediaMessage(), CometChat.sendCustomMessage()
Receiver TypesCometChatReceiverType.user, CometChatReceiverType.group
Message TypesCometChatMessageType.text, CometChatMessageType.image, CometChatMessageType.video, CometChatMessageType.audio, CometChatMessageType.file, CometChatMessageType.custom
PrerequisitesSDK initialized, user logged in
// Send text message to user
TextMessage textMessage = TextMessage(
  text: "Hello!",
  receiverUid: "UID",
  receiverType: CometChatReceiverType.user,
  type: CometChatMessageType.text,
);
CometChat.sendMessage(textMessage, onSuccess: (msg) {}, onError: (e) {});

// Send text message to group
TextMessage groupMessage = TextMessage(
  text: "Hello group!",
  receiverUid: "GUID",
  receiverType: CometChatReceiverType.group,
  type: CometChatMessageType.text,
);
CometChat.sendMessage(groupMessage, onSuccess: (msg) {}, onError: (e) {});

// Send media message (image)
MediaMessage mediaMessage = MediaMessage(
  receiverUid: "UID",
  receiverType: CometChatReceiverType.user,
  type: CometChatMessageType.image,
  file: "path/to/image.jpg",
);
CometChat.sendMediaMessage(mediaMessage, onSuccess: (msg) {}, onError: (e) {});

// Send custom message
CustomMessage customMessage = CustomMessage(
  receiverUid: "UID",
  receiverType: CometChatReceiverType.user,
  type: "location",
  customData: {"latitude": "50.6192", "longitude": "-72.6818"},
);
CometChat.sendCustomMessage(customMessage, onSuccess: (msg) {}, onError: (e) {});
CometChat supports three types of messages:
TypeMethodUse Case
TextCometChat.sendMessage()Plain text messages
MediaCometChat.sendMediaMessage()Images, videos, audio, files
CustomCometChat.sendCustomMessage()Location, polls, or any structured data
You can also send Interactive Messages for forms, cards, and custom UI elements.
Available via: SDK | REST API | UI Kits
You can also send metadata along with a text or media message. Think, for example, if you’d want to share the user’s location with every message, you can use the metadata field.

Text Message

In other words, as a sender, how do I send a text message? To send a text message to a single user or group, you need to use the sendMessage() method and pass a TextMessage object to it.

Add Metadata

To send custom data along with a text message, you can use the setMetadata method and pass a Map to it.
Map<String,String> metadata = {};
metadata["lattitude"] =  "50.6192171633316" ;
metadata["longitude"]  = "-72.68182268750002" ;
textMessage.metadata = metadata;

Add Tags

To add a tag to a message you can assign value in .tags variable of the TextMessage Class. tags accepts a list of tags.
List<String> tags = [];
tags.add("pinned");
textMessage.tags = tags;
Once the text message object is ready, you need to use the sendMessage() method to send the text message to the recipient.
String receiverID = "cometchat-uid-1";
String messageText = "messageText";
String receiverType = CometChatConversationType.user;
String type = CometChatMessageType.text;

TextMessage textMessage = TextMessage(text: messageText,
                                    receiverUid: receiverID,
          													receiverType: receiverType,
           													type: type);
CometChat.sendMessage(textMessage, 
  onSuccess: (TextMessage message) {
	debugPrint("Message sent successfully:  $message");
  }, onError: (CometChatException e) {
	debugPrint("Message sending failed with exception:  ${e.message}");
  }
);
The TextMessage class constructor takes the following parameters:
ParameterDescription
receiverIDUID of the user or GUID of the group receiving the messageRequired
messageTextThe text messageRequired
receiverTypeThe type of the receiver- CometChatReceiverType.user (user) or CometChatReceiverType.group (group)Required
typeThe type of the message that needs to be sent which in this case can be: CometChatMessageType.text__(text)
When a text message is sent successfully, the response will include a TextMessage object which includes all information related to the sent message.
On Success — A TextMessage object containing all details of the sent message:TextMessage Object:
ParameterTypeDescriptionSample Value
idnumberUnique message ID401
metadataobjectCustom metadata attached to the message{}
receiverobjectReceiver user objectSee below ↓
editedBystringUID of the user who edited the messagenull
conversationIdstringUnique conversation identifier"cometchat-uid-1_user_cometchat-uid-2"
sentAtnumberEpoch timestamp when the message was sent1745554729
receiverUidstringUID of the receiver"cometchat-uid-2"
typestringType of the message"text"
readAtnumberEpoch timestamp when the message was read0
deletedBystringUID of the user who deleted the messagenull
deliveredAtnumberEpoch timestamp when the message was delivered0
deletedAtnumberEpoch timestamp when the message was deleted0
replyCountnumberNumber of replies to this message0
senderobjectSender user objectSee below ↓
receiverTypestringType of the receiver"user"
editedAtnumberEpoch timestamp when the message was edited0
parentMessageIdnumberID of the parent message (for threads)-1
readByMeAtnumberEpoch timestamp when read by the current user0
categorystringMessage category"message"
deliveredToMeAtnumberEpoch timestamp when delivered to the current user0
updatedAtnumberEpoch timestamp when the message was last updated1745554729
textstringThe text content of the message"messageText"
tagsarrayList of tags associated with the message[]
unreadRepliesCountnumberCount of unread replies0
mentionedUsersarrayList of mentioned users[]
hasMentionedMebooleanWhether the current user is mentionedfalse
reactionsarrayList of reactions on the message[]
moderationStatusstringModeration status of the messagenull
quotedMessageIdnumberID of the quoted messagenull

sender Object:
ParameterTypeDescriptionSample Value
uidstringUnique identifier of the sender"cometchat-uid-1"
namestringDisplay name of the sender"Andrew Joseph"
linkstringProfile linknull
avatarstringAvatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-1.webp"
metadataobjectCustom metadata{}
statusstringOnline status"online"
rolestringUser role"default"
statusMessagestringStatus messagenull
tagsarrayUser tags[]
hasBlockedMebooleanWhether this user has blocked the current userfalse
blockedByMebooleanWhether the current user has blocked this userfalse
lastActiveAtnumberEpoch timestamp of last activity1745554700

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUnique identifier of the receiver"cometchat-uid-2"
namestringDisplay name of the receiver"George Alan"
linkstringProfile linknull
avatarstringAvatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
metadataobjectCustom metadata{}
statusstringOnline status"offline"
rolestringUser role"default"
statusMessagestringStatus messagenull
tagsarrayUser tags[]
hasBlockedMebooleanWhether this user has blocked the current userfalse
blockedByMebooleanWhether the current user has blocked this userfalse
lastActiveAtnumberEpoch timestamp of last activity1745550000
ParameterTypeDescriptionSample Value
codestringError code identifier"ERR_EMPTY_MESSAGE_TEXT"
messagestringHuman-readable error message"The text message body is empty."
detailsstringAdditional technical details"Please provide a non-empty text for the message."

Set Quoted Message

To set a quoted message for a message, use the setQuotedMessageId and setQuotedMessage method of the TextMessage class. This method accepts the ID of the message to be quoted.
textMessage.quotedMessageId = 0
textMessage.quotedMessage =  // Pass base message object here that you want to quote.
Once the text message object is ready, you need to use the sendMessage() method to send the text message to the recipient.
String receiverID = "UID";
String messageText = "Hello CometChat!";
String receiverType = CometChatReceiverType.user;
String type = CometChatMessageType.text;

TextMessage textMessage = TextMessage(
  text: messageText,
  receiverUid: receiverID,
  receiverType: receiverType,
  type: type,
);
textMessage.quotedMessageId = 10;

CometChat.sendMessage(textMessage,
  onSuccess: (TextMessage message) {
    debugPrint("Message sent successfully: ${message.toString()}");
  },
  onError: (CometChatException e) {
    debugPrint("Message sending failed with exception: ${e.message}");
  },
);
The TextMessage class constructor takes the following parameters:
ParameterDescription
receiverIDUID of the user or GUID of the group receiving the messageRequired
messageTextThe text messageRequired
receiverTypeThe type of the receiver- CometChatReceiverType.user (user) or CometChatReceiverType.group (group)Required
When a text message is sent successfully, the response will include a TextMessage object which includes all information related to the sent message.
On Success — A TextMessage object containing all details of the sent quoted message:TextMessage Object:
ParameterTypeDescriptionSample Value
idnumberUnique message ID402
metadataobjectCustom metadata attached to the message{}
receiverobjectReceiver user objectSee below ↓
editedBystringUID of the user who edited the messagenull
conversationIdstringUnique conversation identifier"cometchat-uid-1_user_cometchat-uid-2"
sentAtnumberEpoch timestamp when the message was sent1745554800
receiverUidstringUID of the receiver"cometchat-uid-2"
typestringType of the message"text"
readAtnumberEpoch timestamp when the message was read0
deletedBystringUID of the user who deleted the messagenull
deliveredAtnumberEpoch timestamp when the message was delivered0
deletedAtnumberEpoch timestamp when the message was deleted0
replyCountnumberNumber of replies to this message0
senderobjectSender user objectSee below ↓
receiverTypestringType of the receiver"user"
editedAtnumberEpoch timestamp when the message was edited0
parentMessageIdnumberID of the parent message (for threads)-1
readByMeAtnumberEpoch timestamp when read by the current user0
categorystringMessage category"message"
deliveredToMeAtnumberEpoch timestamp when delivered to the current user0
updatedAtnumberEpoch timestamp when the message was last updated1745554800
textstringThe text content of the message"Hello CometChat!"
tagsarrayList of tags associated with the message[]
unreadRepliesCountnumberCount of unread replies0
mentionedUsersarrayList of mentioned users[]
hasMentionedMebooleanWhether the current user is mentionedfalse
reactionsarrayList of reactions on the message[]
moderationStatusstringModeration status of the messagenull
quotedMessageIdnumberID of the quoted message401

sender Object:
ParameterTypeDescriptionSample Value
uidstringUnique identifier of the sender"cometchat-uid-1"
namestringDisplay name of the sender"Andrew Joseph"
linkstringProfile linknull
avatarstringAvatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-1.webp"
metadataobjectCustom metadata{}
statusstringOnline status"online"
rolestringUser role"default"
statusMessagestringStatus messagenull
tagsarrayUser tags[]
hasBlockedMebooleanWhether this user has blocked the current userfalse
blockedByMebooleanWhether the current user has blocked this userfalse
lastActiveAtnumberEpoch timestamp of last activity1745554700

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUnique identifier of the receiver"cometchat-uid-2"
namestringDisplay name of the receiver"George Alan"
linkstringProfile linknull
avatarstringAvatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
metadataobjectCustom metadata{}
statusstringOnline status"offline"
rolestringUser role"default"
statusMessagestringStatus messagenull
tagsarrayUser tags[]
hasBlockedMebooleanWhether this user has blocked the current userfalse
blockedByMebooleanWhether the current user has blocked this userfalse
lastActiveAtnumberEpoch timestamp of last activity1745550000
ParameterTypeDescriptionSample Value
codestringError code identifier"ERR_EMPTY_MESSAGE_TEXT"
messagestringHuman-readable error message"The text message body is empty."
detailsstringAdditional technical details"Please provide a non-empty text for the message."

Media Message

In other words, as a sender, how do I send a media message like photos, videos & files? To send a media message to any user or group, you need to use the sendMediaMessage() method and pass a MediaMessage object to it.

Add Metadata

To send custom data along with a media message, you can use the setMetadata method and pass a Map to it.
Map<String,dynamic> metadata = {};
metadata["lattitude"] =  "50.6192171633316" ;
metadata["longitude"]  = "-72.68182268750002" ;
mediaMessage.metadata = metadata;

Add Caption(Text along with Media Message)

mediaMessage.caption = "Message Caption";

Add Tags

To add a tag to a message you can use the setTags() method of the MediaMessage Class. The setTags() method accepts a list of tags.
List<String> tags = [];
tags.add("pinned");
mediaMessage.tags = tags;

Set Quoted Message

To quote a message in a media message, use the quotedMessageId property of the MediaMessage class.
mediaMessage.quotedMessageId = 10;
There are 2 ways you can send Media Messages using the CometChat SDK:
  1. By providing the File : You can directly share the file object while creating an object of the MediaMessage class. When the media message is sent using the sendMediaMessage() method, this file is then uploaded to CometChat servers and the URL of the file is sent in the success response of the sendMediaMessage() function.
String receiverID = "cometchat-uid-1";
String messageType = CometChatMessageType.image;
String receiverType = CometChatConversationType.user;
String filePath = "storage/emulated/0/Download/46.jpg";
MediaMessage mediaMessage = MediaMessage(
  receiverType: receiverType,
  type: messageType,
  receiverUid: receiverID,
  file: filePath,
);

await CometChat.sendMediaMessage(mediaMessage, 
  onSuccess: (MediaMessage message) {
  	debugPrint("Media message sent successfully: ${mediaMessage.metadata}");
  }, onError: (e) {
  	debugPrint("Media message sending failed with exception: ${e.message}");
  }
); 
The MediaMessage class constructor takes the following parameters:
ParameterDescription
receiverIdThe UID or GUID of the recipientRequired
fileThe file object to be sentRequired
messageTypeThe type of the message that needs to be sent which, in this case, can be:
1. CometChatMessageType.image (image)
2. CometChatMessageType.video (video)
3. CometChatMessageType.audio (audio)
4. CometChatMessageType.file (file)
Required
receiverTypeThe type of the receiver to whom the message is to be sent, i.e., CometChatReceiverType.user (user) or CometChatReceiverType.group (group)Required
On Success — A MediaMessage object containing all details of the sent media message:MediaMessage Object:
ParameterTypeDescriptionSample Value
idnumberUnique message ID403
metadataobjectCustom metadata attached to the message{}
receiverobjectReceiver user objectSee below ↓
editedBystringUID of the user who edited the messagenull
conversationIdstringUnique conversation identifier"cometchat-uid-1_user_cometchat-uid-2"
sentAtnumberEpoch timestamp when the message was sent1745554900
receiverUidstringUID of the receiver"cometchat-uid-2"
typestringType of the message"image"
readAtnumberEpoch timestamp when the message was read0
deletedBystringUID of the user who deleted the messagenull
deliveredAtnumberEpoch timestamp when the message was delivered0
deletedAtnumberEpoch timestamp when the message was deleted0
replyCountnumberNumber of replies to this message0
senderobjectSender user objectSee below ↓
receiverTypestringType of the receiver"user"
editedAtnumberEpoch timestamp when the message was edited0
parentMessageIdnumberID of the parent message (for threads)0
readByMeAtnumberEpoch timestamp when read by the current user0
categorystringMessage category"message"
deliveredToMeAtnumberEpoch timestamp when delivered to the current user0
updatedAtnumberEpoch timestamp when the message was last updated1745554900
tagsarrayList of tags associated with the message[]
unreadRepliesCountnumberCount of unread replies0
mentionedUsersarrayList of mentioned users[]
hasMentionedMebooleanWhether the current user is mentionedfalse
reactionsarrayList of reactions on the message[]
captionstringCaption text for the media messagenull
attachmentobjectFile attachment detailsSee below ↓
filestringLocal file path"storage/emulated/0/Download/46.jpg"
filesarrayList of additional file pathsnull
attachmentsarrayList of additional attachmentsnull
moderationStatusstringModeration status of the messagenull
quotedMessageIdnumberID of the quoted messagenull

sender Object:
ParameterTypeDescriptionSample Value
uidstringUnique identifier of the sender"cometchat-uid-1"
namestringDisplay name of the sender"Andrew Joseph"
linkstringProfile linknull
avatarstringAvatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-1.webp"
metadataobjectCustom metadata{}
statusstringOnline status"online"
rolestringUser role"default"
statusMessagestringStatus messagenull
tagsarrayUser tags[]
hasBlockedMebooleanWhether this user has blocked the current userfalse
blockedByMebooleanWhether the current user has blocked this userfalse
lastActiveAtnumberEpoch timestamp of last activity1745554700

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUnique identifier of the receiver"cometchat-uid-2"
namestringDisplay name of the receiver"George Alan"
linkstringProfile linknull
avatarstringAvatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
metadataobjectCustom metadata{}
statusstringOnline status"offline"
rolestringUser role"default"
statusMessagestringStatus messagenull
tagsarrayUser tags[]
hasBlockedMebooleanWhether this user has blocked the current userfalse
blockedByMebooleanWhether the current user has blocked this userfalse
lastActiveAtnumberEpoch timestamp of last activity1745550000

attachment Object:
ParameterTypeDescriptionSample Value
fileUrlstringURL of the uploaded file"https://data-us.cometchat.io/assets/images/46.jpg"
fileNamestringName of the file"46.jpg"
fileExtensionstringFile extension"jpg"
fileMimeTypestringMIME type of the file"image/jpeg"
fileSizenumberFile size in bytes24576
ParameterTypeDescriptionSample Value
codestringError code identifier"ERR_FILE_TOO_LARGE"
messagestringHuman-readable error message"The file size exceeds the allowed limit."
detailsstringAdditional technical details"Maximum allowed file size is 25 MB."
  1. By providing the URL of the File: The second way to send media messages using the CometChat SDK is to provide the SDK with the URL of any file that is hosted on your servers or any cloud storage. To achieve this you will have to make use of the Attachment class that is available in the MediaMessage class. For more information, you can refer to the below code snippet:
String receiverID = "cometchat-uid-1";
String messageType = CometChatMessageType.image;
String receiverType = CometChatConversationType.user;

MediaMessage mediaMessage = MediaMessage(
                          receiverType: receiverType,
                          type: messageType,
                          receiverUid: receiverID,
                          file: null);

String fileUrl  = "https://pngimg.com/uploads/mario/mario_PNG125.png";
String fileName   = "test";
String fileExtension = "png";
String fileMimeType = "image/png";

Attachment attach = Attachment(fileUrl, fileName, fileExtension, fileMimeType, null);
mediaMessage.attachment = attach;

await CometChat.sendMediaMessage(mediaMessage,
  onSuccess: (MediaMessage message) {
  	debugPrint("Media message sent successfully: ${mediaMessage}");                            
  }, onError: (CometChatException e) {
  	debugPrint("Media message sending failed with exception: ${e.message}");
  }
);   
When a media message is sent successfully, the response will include a MediaMessage object which includes all information related to the sent message.
On Success — A MediaMessage object containing all details of the sent media message (via URL):MediaMessage Object:
ParameterTypeDescriptionSample Value
idnumberUnique message ID404
metadataobjectCustom metadata attached to the message{}
receiverobjectReceiver user objectSee below ↓
editedBystringUID of the user who edited the messagenull
conversationIdstringUnique conversation identifier"cometchat-uid-1_user_cometchat-uid-2"
sentAtnumberEpoch timestamp when the message was sent1745555000
receiverUidstringUID of the receiver"cometchat-uid-2"
typestringType of the message"image"
readAtnumberEpoch timestamp when the message was read0
deletedBystringUID of the user who deleted the messagenull
deliveredAtnumberEpoch timestamp when the message was delivered0
deletedAtnumberEpoch timestamp when the message was deleted0
replyCountnumberNumber of replies to this message0
senderobjectSender user objectSee below ↓
receiverTypestringType of the receiver"user"
editedAtnumberEpoch timestamp when the message was edited0
parentMessageIdnumberID of the parent message (for threads)0
readByMeAtnumberEpoch timestamp when read by the current user0
categorystringMessage category"message"
deliveredToMeAtnumberEpoch timestamp when delivered to the current user0
updatedAtnumberEpoch timestamp when the message was last updated1745555000
tagsarrayList of tags associated with the message[]
unreadRepliesCountnumberCount of unread replies0
mentionedUsersarrayList of mentioned users[]
hasMentionedMebooleanWhether the current user is mentionedfalse
reactionsarrayList of reactions on the message[]
captionstringCaption text for the media messagenull
attachmentobjectFile attachment detailsSee below ↓
filestringLocal file pathnull
filesarrayList of additional file pathsnull
attachmentsarrayList of additional attachmentsnull
moderationStatusstringModeration status of the messagenull
quotedMessageIdnumberID of the quoted messagenull

sender Object:
ParameterTypeDescriptionSample Value
uidstringUnique identifier of the sender"cometchat-uid-1"
namestringDisplay name of the sender"Andrew Joseph"
linkstringProfile linknull
avatarstringAvatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-1.webp"
metadataobjectCustom metadata{}
statusstringOnline status"online"
rolestringUser role"default"
statusMessagestringStatus messagenull
tagsarrayUser tags[]
hasBlockedMebooleanWhether this user has blocked the current userfalse
blockedByMebooleanWhether the current user has blocked this userfalse
lastActiveAtnumberEpoch timestamp of last activity1745554700

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUnique identifier of the receiver"cometchat-uid-2"
namestringDisplay name of the receiver"George Alan"
linkstringProfile linknull
avatarstringAvatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
metadataobjectCustom metadata{}
statusstringOnline status"offline"
rolestringUser role"default"
statusMessagestringStatus messagenull
tagsarrayUser tags[]
hasBlockedMebooleanWhether this user has blocked the current userfalse
blockedByMebooleanWhether the current user has blocked this userfalse
lastActiveAtnumberEpoch timestamp of last activity1745550000

attachment Object:
ParameterTypeDescriptionSample Value
fileUrlstringURL of the file"https://pngimg.com/uploads/mario/mario_PNG125.png"
fileNamestringName of the file"test"
fileExtensionstringFile extension"png"
fileMimeTypestringMIME type of the file"image/png"
fileSizenumberFile size in bytesnull
ParameterTypeDescriptionSample Value
codestringError code identifier"ERR_INVALID_MESSAGE_TYPE"
messagestringHuman-readable error message"The message type provided is not supported."
detailsstringAdditional technical details"Supported types are image, video, audio, and file."
If you wish to send a caption or some text along with the Media Message, you can use the caption field provided by the MediaMessage class. To get and set the caption you can use the .caption variable . As with text messages, the metadata field can be used with media messages as well. Any additional information can be passed along with the media message as a Map.

Custom Message

In other words, as a sender, how do I send a custom message like location co-ordinates? CometChat allows you to send custom messages which are neither text nor media messages. In order to send a custom message, you need to use the sendCustomMessage() method. The sendCustomMessage() methods takes an object of the CustomMessage which can be obtained using the below constructor.
CustomMessage customMessage = CustomMessage( receiverUid: UID,
    type: type,
    customData: customData,
    receiverType: receiverType,
    subType: subType,
  );
The above constructor, helps you create a custom message with the message type set to whatever is passed to the constructor and the category set to custom. The CustomMessage class constructor takes the following parameters:
ParameterDescriptionRequired
receiverUidUID of the user or GUID of the group to which the message is to be sentYes
receiverTypeType of the receiver — CometChatConversationType.user or CometChatConversationType.groupYes
typeCustom message type string (e.g., "location", "poll")Yes
customDataThe data to be passed as the message in the form of a MapYes
subTypeOptional sub-type for the custom messageNo
You can also use the subType field of the CustomMessage class to set a specific type for the custom message. This can be achieved using the subtype field.

Add Metadata

To send custom data along with a custom message, you can use the metadata property and pass a Map to it.
Map<String, dynamic> metadata = {};
metadata["priority"] = "high";
metadata["source"] = "mobile";
customMessage.metadata = metadata;

Add Tags

To add a tag to a message you can assign value in .tags variable of the CustomMessage Class. tags accepts a list of tags.
List<String> tags = [];
tags.add("pinned");
textMessage.tags = tags;

Set Quoted Message

To quote a message in a custom message, use the quotedMessageId property of the CustomMessage class.
customMessage.quotedMessageId = 10;
Once the object of CustomMessage class is ready you can send the custom message using the sendCustomMessage() method.
String UID = "UID";
String subType = "LOCATION";
String receiverType = CometChatConversationType.user;
String type = CometChatMessageType.custom;

Map<String, String> customData = {};
customData["latitude"] = "19.0760";
customData["longitude"] = "72.8777";

CustomMessage customMessage = CustomMessage(
  receiverUid: UID,
  type: type,
  customData: customData,
  receiverType: receiverType,
  subType: subType,
);

CometChat.sendCustomMessage(customMessage, onSuccess: (CustomMessage message) {
  debugPrint("Custom Message Sent Successfully : $message");
}, onError: (CometChatException e) {
  debugPrint("Custom message sending failed with exception: ${e.message}");
});
The above sample explains how custom messages can be used to share the location with a user. Similarly, you can send custom messages to groups. On success, you will receive an object of CustomMessage class.
On Success — A CustomMessage object containing all details of the sent custom message:CustomMessage Object:
ParameterTypeDescriptionSample Value
idnumberUnique message ID405
metadataobjectCustom metadata attached to the message{}
receiverobjectReceiver user objectSee below ↓
editedBystringUID of the user who edited the messagenull
conversationIdstringUnique conversation identifier"cometchat-uid-1_user_cometchat-uid-2"
sentAtnumberEpoch timestamp when the message was sent1745555100
receiverUidstringUID of the receiver"cometchat-uid-2"
typestringType of the message"custom"
readAtnumberEpoch timestamp when the message was read0
deletedBystringUID of the user who deleted the messagenull
deliveredAtnumberEpoch timestamp when the message was delivered0
deletedAtnumberEpoch timestamp when the message was deleted0
replyCountnumberNumber of replies to this message0
senderobjectSender user objectSee below ↓
receiverTypestringType of the receiver"user"
editedAtnumberEpoch timestamp when the message was edited0
parentMessageIdnumberID of the parent message (for threads)0
readByMeAtnumberEpoch timestamp when read by the current user0
categorystringMessage category"custom"
deliveredToMeAtnumberEpoch timestamp when delivered to the current user0
updatedAtnumberEpoch timestamp when the message was last updated1745555100
customDataobjectCustom data payload{"latitude": "19.0760", "longitude": "72.8777"}
tagsarrayList of tags associated with the message[]
unreadRepliesCountnumberCount of unread replies0
mentionedUsersarrayList of mentioned users[]
hasMentionedMebooleanWhether the current user is mentionedfalse
reactionsarrayList of reactions on the message[]
textstringConversation text for notificationsnull
updateConversationbooleanWhether to update the conversation’s last messagefalse
sendNotificationbooleanWhether to send a push notificationfalse
quotedMessageIdnumberID of the quoted messagenull

sender Object:
ParameterTypeDescriptionSample Value
uidstringUnique identifier of the sender"cometchat-uid-1"
namestringDisplay name of the sender"Andrew Joseph"
linkstringProfile linknull
avatarstringAvatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-1.webp"
metadataobjectCustom metadata{}
statusstringOnline status"online"
rolestringUser role"default"
statusMessagestringStatus messagenull
tagsarrayUser tags[]
hasBlockedMebooleanWhether this user has blocked the current userfalse
blockedByMebooleanWhether the current user has blocked this userfalse
lastActiveAtnumberEpoch timestamp of last activity1745554700

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUnique identifier of the receiver"cometchat-uid-2"
namestringDisplay name of the receiver"George Alan"
linkstringProfile linknull
avatarstringAvatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
metadataobjectCustom metadata{}
statusstringOnline status"offline"
rolestringUser role"default"
statusMessagestringStatus messagenull
tagsarrayUser tags[]
hasBlockedMebooleanWhether this user has blocked the current userfalse
blockedByMebooleanWhether the current user has blocked this userfalse
lastActiveAtnumberEpoch timestamp of last activity1745550000
ParameterTypeDescriptionSample Value
codestringError code identifier"ERR_CHAT_API_FAILURE"
messagestringHuman-readable error message"Failed to send the custom message."
detailsstringAdditional technical details"An unexpected error occurred while processing the request."

Update Conversation

How can I decide whether the custom message should update the last message of a conversation? By default, a custom message will update the last message of a conversation. If you wish to not update the last message of the conversation when a custom message is sent, please use updateConversation (boolean value) method of the Custom Message.
String UID = "UID";
String subType = "LOCATION";
String receiverType = CometChatConversationType.user;
String type = CometChatMessageType.custom;

Map<String, String> customData = {};
customData["latitude"] = "19.0760";
customData["longitude"] = "72.8777";

CustomMessage customMessage = CustomMessage(
  receiverUid: UID,
  type: type,
  customData: customData,
  receiverType: receiverType,
  subType: subType,
);
customMessage.updateConversation = false;

CometChat.sendCustomMessage(customMessage, onSuccess: (CustomMessage message) {
  debugPrint("Custom Message Sent Successfully : $message");
}, onError: (CometChatException e) {
  debugPrint("Custom message sending failed with exception: ${e.message}");
});

Custom Notification Body

How can i customise the notification body of custom message? To add a custom notification body for Push, Email & SMS notification of a custom message you can use the conversationText method of Custom Message class.
String UID = "UID";
String subType = "LOCATION";
String receiverType = CometChatConversationType.user;
String type = CometChatMessageType.custom;

Map<String, String> customData = {};
customData["latitude"] = "19.0760";
customData["longitude"] = "72.8777";

CustomMessage customMessage = CustomMessage(
  receiverUid: UID,
  type: type,
  customData: customData,
  receiverType: receiverType,
  subType: subType,
);
customMessage.conversationText = "Custom Notification Body";

CometChat.sendCustomMessage(customMessage, onSuccess: (CustomMessage message) {
  debugPrint("Custom Message Sent Successfully : $message");
}, onError: (CometChatException e) {
  debugPrint("Custom message sending failed with exception: ${e.message}");
});
It is also possible to send interactive messages from CometChat , to know more click here

Next Steps

Receive Messages

Handle incoming messages in real-time

Edit Message

Modify sent messages after delivery

Interactive Messages

Send forms, cards, and interactive elements

Delete Message

Remove messages from conversations