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.
AI Integration Quick Reference
// Text message
val textMessage = TextMessage ( "UID" , "Hello!" , CometChatConstants.RECEIVER_TYPE_USER)
CometChat. sendMessage (textMessage, object : CallbackListener < TextMessage >() {
override fun onSuccess (msg: TextMessage ) { }
override fun onError (e: CometChatException ) { }
})
// Media message (file upload)
val mediaMessage = MediaMessage ( "UID" , File ( "/path/to/file.jpg" ),
CometChatConstants.MESSAGE_TYPE_IMAGE, CometChatConstants.RECEIVER_TYPE_USER)
CometChat. sendMediaMessage (mediaMessage, object : CallbackListener < MediaMessage >() {
override fun onSuccess (msg: MediaMessage ) { }
override fun onError (e: CometChatException ) { }
})
// Custom message
val customData = JSONObject (). apply { put ( "latitude" , "19.07" ); put ( "longitude" , "72.87" ) }
val customMessage = CustomMessage ( "UID" , CometChatConstants.RECEIVER_TYPE_USER, "LOCATION" , customData)
CometChat. sendCustomMessage (customMessage, object : CallbackListener < CustomMessage >() {
override fun onSuccess (msg: CustomMessage ) { }
override fun onError (e: CometChatException ) { }
})
Type Method Receiver Types Text sendMessage()RECEIVER_TYPE_USER, RECEIVER_TYPE_GROUPMedia sendMediaMessage()RECEIVER_TYPE_USER, RECEIVER_TYPE_GROUPCustom sendCustomMessage()RECEIVER_TYPE_USER, RECEIVER_TYPE_GROUP
CometChat supports three types of messages:
Type Method Use Case Text sendMessage()Plain text messages Media sendMediaMessage()Images, videos, audio, files Custom sendCustomMessage()Location, polls, or any JSON data
You can also send Interactive Messages for forms, cards, and custom UI elements.
Text Message
Send a text message using sendMessage() with a TextMessage object.
Java (User)
Kotlin (User)
Java (Group)
Kotlin (Group)
private String receiverID = "UID" ;
private String messageText = "Hello CometChat!" ;
private String receiverType = CometChatConstants . RECEIVER_TYPE_USER ;
TextMessage textMessage = new TextMessage (receiverID, messageText, receiverType);
CometChat . sendMessage (textMessage, new CometChat . CallbackListener < TextMessage >() {
@ Override
public void onSuccess ( TextMessage textMessage ) {
Log . d (TAG, "Message sent successfully: " + textMessage . toString ());
}
@ Override
public void onError ( CometChatException e ) {
Log . d (TAG, "Message sending failed with exception: " + e . getMessage ());
}
});
private val receiverID = "UID"
private val messageText = "Hello CometChat!"
private val receiverType = CometChatConstants.RECEIVER_TYPE_USER
val textMessage = TextMessage (receiverID, messageText, receiverType)
CometChat. sendMessage (textMessage, object : CallbackListener < TextMessage >() {
override fun onSuccess (textMessage: TextMessage ) {
Log. d (TAG, "Message sent successfully: $textMessage " )
}
override fun onError (e: CometChatException ) {
Log. d (TAG, "Message sending failed with exception: " + e.message)
}
})
private String receiverID = "GUID" ;
private String messageText = "Hello CometChat!" ;
private String receiverType = CometChatConstants . RECEIVER_TYPE_GROUP ;
TextMessage textMessage = new TextMessage (receiverID, messageText, receiverType);
CometChat . sendMessage (textMessage, new CometChat . CallbackListener < TextMessage >() {
@ Override
public void onSuccess ( TextMessage textMessage ) {
Log . d (TAG, "Message sent successfully: " + textMessage . toString ());
}
@ Override
public void onError ( CometChatException e ) {
Log . d (TAG, "Message sending failed with exception: " + e . getMessage ());
}
});
private val receiverID = "GUID"
private val messageText = "Hello CometChat!"
private val receiverType = CometChatConstants.RECEIVER_TYPE_GROUP
val textMessage = TextMessage (receiverID, messageText, receiverType)
CometChat. sendMessage (textMessage, object : CallbackListener < TextMessage >() {
override fun onSuccess (textMessage: TextMessage ) {
Log. d (TAG, "Message sent successfully: $textMessage " )
}
override fun onError (e: CometChatException ) {
Log. d (TAG, "Message sending failed with exception: " + e.message)
}
})
The TextMessage class constructor takes the following parameters:
Parameter Description Required receiverIDUID of the user or GUID of the group receiving the messageYes messageTextThe text message content Yes receiverTypeCometChatConstants.RECEIVER_TYPE_USER or RECEIVER_TYPE_GROUPYes
On success, sendMessage() returns a TextMessage object containing all information about the sent message.
Attach custom JSON data to the message:
JSONObject metadata = new JSONObject ();
metadata . put ( "latitude" , "50.6192171633316" );
metadata . put ( "longitude" , "-72.68182268750002" );
textMessage . setMetadata (metadata);
val metadata = JSONObject ()
metadata. put ( "latitude" , "50.6192171633316" )
metadata. put ( "longitude" , "-72.68182268750002" )
textMessage. setMetadata (metadata)
Tag messages for easy filtering later:
List < String > tags = new ArrayList <>();
tags . add ( "pinned" );
textMessage . setTags (tags);
val tags: MutableList < String > = ArrayList ()
tags. add ( "pinned" )
textMessage. setTags (tags)
Quote a Message
Reply to a specific message by setting its ID:
textMessage . setQuotedMessageId ( 10 );
textMessage.quotedMessageId = 10
Send images, videos, audio, or files using sendMediaMessage().
There are two ways to send media messages:
Upload a file — Pass a File object and CometChat uploads it automatically
Send a URL — Provide a URL to media hosted on your server or cloud storage
JSONObject metadata = new JSONObject ();
metadata . put ( "latitude" , "50.6192171633316" );
metadata . put ( "longitude" , "-72.68182268750002" );
mediaMessage . setMetadata (metadata);
val metadata = JSONObject ()
metadata. put ( "latitude" , "50.6192171633316" )
metadata. put ( "longitude" , "-72.68182268750002" )
mediaMessage. setMetadata (metadata)
Add Caption
Add text along with the media:
mediaMessage . setCaption ( "Message Caption" );
mediaMessage. setCaption ( "Message Caption" )
List < String > tags = new ArrayList <>();
tags . add ( "pinned" );
mediaMessage . setTags (tags);
val tags: MutableList < String > = ArrayList ()
tags. add ( "pinned" )
mediaMessage. setTags (tags)
Upload a File
Pass a File object directly. CometChat uploads it to its servers and returns the URL in the success response.
Java (User)
Kotlin (User)
Java (Group)
Kotlin (Group)
private String receiverID = "UID" ;
private String messageType = CometChatConstants . MESSAGE_TYPE_IMAGE ;
private String receiverType = CometChatConstants . RECEIVER_TYPE_USER ;
private String filePath = "/storage/emulated/0/Download/CometChat.jpg" ;
MediaMessage mediaMessage = new MediaMessage (receiverID, new File (filePath), messageType, receiverType);
CometChat . sendMediaMessage (mediaMessage, new CometChat . CallbackListener < MediaMessage >() {
@ Override
public void onSuccess ( MediaMessage mediaMessage ) {
Log . d (TAG, "Media message sent successfully: " + mediaMessage . toString ());
}
@ Override
public void onError ( CometChatException e ) {
Log . d (TAG, "Media message sending failed with exception: " + e . getMessage ());
}
});
private val receiverID = "UID"
private val messageType = CometChatConstants.MESSAGE_TYPE_IMAGE
private val receiverType = CometChatConstants.RECEIVER_TYPE_USER
private val filePath = "/storage/emulated/0/Download/CometChat.jpg"
val mediaMessage = MediaMessage (receiverID, File (filePath), messageType, receiverType)
CometChat. sendMediaMessage (mediaMessage, object : CallbackListener < MediaMessage >() {
override fun onSuccess (mediaMessage: MediaMessage ) {
Log. d (TAG, "Media message sent successfully: " + mediaMessage. toString ())
}
override fun onError (e: CometChatException ) {
Log. d (TAG, "Media message sending failed with exception: " + e.message)
}
})
private String receiverID = "GUID" ;
private String messageType = CometChatConstants . MESSAGE_TYPE_IMAGE ;
private String receiverType = CometChatConstants . RECEIVER_TYPE_GROUP ;
private String filePath = "/storage/emulated/0/Download/CometChat.jpg" ;
MediaMessage mediaMessage = new MediaMessage (receiverID, new File (filePath), messageType, receiverType);
CometChat . sendMediaMessage (mediaMessage, new CometChat . CallbackListener < MediaMessage >() {
@ Override
public void onSuccess ( MediaMessage mediaMessage ) {
Log . d (TAG, "Media message sent successfully: " + mediaMessage . toString ());
}
@ Override
public void onError ( CometChatException e ) {
Log . d (TAG, "Media message sending failed with exception: " + e . getMessage ());
}
});
private val receiverID = "GUID"
private val messageType = CometChatConstants.MESSAGE_TYPE_IMAGE
private val receiverType = CometChatConstants.RECEIVER_TYPE_GROUP
private val filePath = "/storage/emulated/0/Download/CometChat.jpg"
val mediaMessage = MediaMessage (receiverID, File (filePath), messageType, receiverType)
CometChat. sendMediaMessage (mediaMessage, object : CallbackListener < MediaMessage >() {
override fun onSuccess (mediaMessage: MediaMessage ) {
Log. d (TAG, "Media message sent successfully: " + mediaMessage. toString ())
}
override fun onError (e: CometChatException ) {
Log. d (TAG, "Media message sending failed with exception: " + e.message)
}
})
The MediaMessage class constructor takes the following parameters:
Parameter Description Required receiverIdThe UID or GUID of the recipient Yes fileThe File object to upload Yes messageTypeMESSAGE_TYPE_IMAGE, MESSAGE_TYPE_VIDEO, MESSAGE_TYPE_AUDIO, or MESSAGE_TYPE_FILEYes receiverTypeRECEIVER_TYPE_USER or RECEIVER_TYPE_GROUPYes
Send a URL
Send media hosted on your server or cloud storage using the Attachment class:
Java (User)
Kotlin (User)
Java (Group)
Kotlin (Group)
String receiverId = "recipient_UID" ;
MediaMessage mediaMessage = new MediaMessage (receiverId, CometChatConstants . MESSAGE_TYPE_IMAGE , CometChatConstants . RECEIVER_TYPE_USER );
Attachment attachment = new Attachment ();
attachment . setFileName ( "test" );
attachment . setFileExtension ( "png" );
attachment . setFileUrl ( "https://pngimg.com/uploads/mario/mario_PNG125.png" );
mediaMessage . setAttachment (attachment);
CometChat . sendMediaMessage (mediaMessage, new CometChat . CallbackListener < MediaMessage >() {
@ Override
public void onSuccess ( MediaMessage mediaMessage1 ) {
Log . i (TAG, "onSuccess" );
}
@ Override
public void onError ( CometChatException e ) {
Log . e (TAG, e . getMessage ());
}
});
val receiverId = "recipient_UID"
val mediaMessage = MediaMessage (receiverId, CometChatConstants.MESSAGE_TYPE_IMAGE, CometChatConstants.RECEIVER_TYPE_USER)
val attachment = Attachment ()
attachment.fileName = "test"
attachment.fileExtension = "png"
attachment.fileUrl = "https://pngimg.com/uploads/mario/mario_PNG125.png"
mediaMessage.attachment = attachment
CometChat. sendMediaMessage (mediaMessage, object : CallbackListener < MediaMessage ?>() {
override fun onSuccess (mediaMessage1: MediaMessage ?) {
Log. i (TAG, "onSuccess" )
}
override fun onError (e: CometChatException ) {
Log. e (TAG, e.message !! )
}
})
String receiverId = "recipient_GUID" ;
MediaMessage mediaMessage = new MediaMessage (receiverId, CometChatConstants . MESSAGE_TYPE_IMAGE , CometChatConstants . RECEIVER_TYPE_GROUP );
Attachment attachment = new Attachment ();
attachment . setFileName ( "test" );
attachment . setFileExtension ( "png" );
attachment . setFileUrl ( "https://pngimg.com/uploads/mario/mario_PNG125.png" );
mediaMessage . setAttachment (attachment);
CometChat . sendMediaMessage (mediaMessage, new CometChat . CallbackListener < MediaMessage >() {
@ Override
public void onSuccess ( MediaMessage mediaMessage1 ) {
Log . i (TAG, "onSuccess" );
}
@ Override
public void onError ( CometChatException e ) {
Log . e (TAG, e . getMessage ());
}
});
val receiverId = "recipient_GUID"
val mediaMessage = MediaMessage (receiverId, CometChatConstants.MESSAGE_TYPE_IMAGE, CometChatConstants.RECEIVER_TYPE_GROUP)
val attachment = Attachment ()
attachment.fileName = "test"
attachment.fileExtension = "png"
attachment.fileUrl = "https://pngimg.com/uploads/mario/mario_PNG125.png"
mediaMessage.attachment = attachment
CometChat. sendMediaMessage (mediaMessage, object : CallbackListener < MediaMessage ?>() {
override fun onSuccess (mediaMessage1: MediaMessage ?) {
Log. i (TAG, "onSuccess" )
}
override fun onError (e: CometChatException ) {
Log. e (TAG, e.message !! )
}
})
On success, sendMediaMessage() returns a MediaMessage object.
Multiple Attachments
Starting version 3.0.9, the SDK supports sending multiple attachments in a single media message.
Upload Multiple Files
Java (User)
Kotlin (User)
Java (Group)
Kotlin (Group)
String receiverId = "cometchat-uid-1" ;
List < File > files = new ArrayList < File >();
files . add ( new File ( "/storage/emulated/0/Download/1.jpg" ));
files . add ( new File ( "/storage/emulated/0/Download/2.jpg" ));
files . add ( new File ( "/storage/emulated/0/Download/3.jpg" ));
MediaMessage mediaMessage = new MediaMessage (receiverId, files, fileType, CometChatConstants . RECEIVER_TYPE_USER );
CometChat . sendMediaMessage (mediaMessage, new CometChat . CallbackListener < MediaMessage >() {
@ Override
public void onSuccess ( MediaMessage mediaMessage ) {
Log . d (TAG, "Message Sent Successfully" )
}
@ Override
public void onError ( CometChatException e ) {
Log . d (TAG, "Message Sending Failed with exception : " + e . getMessage ());
}
});
val receiverId = "cometchat-uid-1"
val files: MutableList < File > = ArrayList ()
files. add ( File ( "/storage/emulated/0/Download/1.jpg" ))
files. add ( File ( "/storage/emulated/0/Download/2.jpg" ))
files. add ( File ( "/storage/emulated/0/Download/3.jpg" ))
val mediaMessage = MediaMessage (receiverId, files, fileType, CometChatConstants.RECEIVER_TYPE_USER)
CometChat. sendMediaMessage (mediaMessage, object : CallbackListener < MediaMessage ?>() {
override fun onSuccess (mediaMessage: MediaMessage ?) {
Log. d (TAG, "Message Sent Successfully" )
}
override fun onError (e: CometChatException ) {
Log. d (TAG, "Message Sending Failed with exception : " + e.message)
}
})
String groupId = "cometchat-guid-1" ;
List < File > files = new ArrayList < File >();
files . add ( new File ( "/storage/emulated/0/Download/1.jpg" ));
files . add ( new File ( "/storage/emulated/0/Download/2.jpg" ));
files . add ( new File ( "/storage/emulated/0/Download/3.jpg" ));
MediaMessage mediaMessage = new MediaMessage (groupId, files, fileType, CometChatConstants . RECEIVER_TYPE_GROUP );
CometChat . sendMediaMessage (mediaMessage, new CometChat . CallbackListener < MediaMessage >() {
@ Override
public void onSuccess ( MediaMessage mediaMessage ) {
Log . d (TAG, "Message Sent Successfully" )
}
@ Override
public void onError ( CometChatException e ) {
Log . d (TAG, "Message Sending Failed with exception : " + e . getMessage ());
}
});
val groupId = "cometchat-guid-1"
val files: MutableList < File > = ArrayList ()
files. add ( File ( "/storage/emulated/0/Download/1.jpg" ))
files. add ( File ( "/storage/emulated/0/Download/2.jpg" ))
files. add ( File ( "/storage/emulated/0/Download/3.jpg" ))
val mediaMessage = MediaMessage (groupId, files, fileType, CometChatConstants.RECEIVER_TYPE_GROUP)
CometChat. sendMediaMessage (mediaMessage, object : CallbackListener < MediaMessage ?>() {
override fun onSuccess (mediaMessage: MediaMessage ?) {
Log. d (TAG, "Message Sent Successfully" )
}
override fun onError (e: CometChatException ) {
Log. d (TAG, "Message Sending Failed with exception : " + e.message)
}
})
The MediaMessage class constructor takes the following parameters:
Parameter Description Required receiverIdThe UID or GUID of the recipient Yes filesA List<File> of files to upload Yes messageTypeMESSAGE_TYPE_IMAGE, MESSAGE_TYPE_VIDEO, MESSAGE_TYPE_AUDIO, or MESSAGE_TYPE_FILEYes receiverTypeRECEIVER_TYPE_USER or RECEIVER_TYPE_GROUPYes
Send Multiple URLs
Java (User)
Kotlin (User)
Java (Group)
Kotlin (Group)
String receiverId = "cometchat-uid-1" ;
MediaMessage mediaMessage = new MediaMessage (receiverId, CometChatConstants . MESSAGE_TYPE_IMAGE , CometChatConstants . RECEIVER_TYPE_USER );
List < Attachment > attachments = new ArrayList <>();
for ( int i = 0 ; i < 5 ; i ++ ) {
Attachment attachment = new Attachment ();
attachment . setFileName ( "test" );
attachment . setFileExtension ( "png" );
attachment . setFileUrl ( "https://pngimg.com/uploads/mario/mario_PNG125.png" );
attachment . setFileMimeType ( "image/png" );
attachments . add (attachment);
}
mediaMessage . setAttachments (attachments);
CometChat . sendMediaMessage (mediaMessage, new CometChat . CallbackListener < MediaMessage >() {
@ Override
public void onSuccess ( MediaMessage mediaMessage ) {
Log . d (TAG, "Message Sent Successfully" )
}
@ Override
public void onError ( CometChatException e ) {
Log . d (TAG, "Message Sending Failed with exception : " + e . getMessage ());
}
});
val receiverId = "cometchat-uid-1"
val mediaMessage = MediaMessage (receiverId, CometChatConstants.MESSAGE_TYPE_IMAGE, CometChatConstants.RECEIVER_TYPE_USER)
val attachments: MutableList < Attachment > = ArrayList ()
for (i in 0 .. 4 ) {
val attachment = Attachment ()
attachment.fileName = "test"
attachment.fileExtension = "png"
attachment.fileUrl = "https://pngimg.com/uploads/mario/mario_PNG125.png"
attachment.fileMimeType = "image/png"
attachments. add (attachment)
}
mediaMessage.attachments = attachments
CometChat. sendMediaMessage (mediaMessage, object : CallbackListener < MediaMessage ?>() {
override fun onSuccess (mediaMessage: MediaMessage ?) {
Log. d (TAG, "Message Sent Successfully" )
}
override fun onError (e: CometChatException ) {
Log. d (TAG, "Message Sending Failed with exception : " + e.message)
}
})
String groupId = "cometchat-guid-1" ;
MediaMessage mediaMessage = new MediaMessage (groupId, CometChatConstants . MESSAGE_TYPE_IMAGE , CometChatConstants . RECEIVER_TYPE_GROUP );
List < Attachment > attachments = new ArrayList <>();
for ( int i = 0 ; i < 5 ; i ++ ) {
Attachment attachment = new Attachment ();
attachment . setFileName ( "test" );
attachment . setFileExtension ( "png" );
attachment . setFileUrl ( "https://pngimg.com/uploads/mario/mario_PNG125.png" );
attachment . setFileMimeType ( "image/png" );
attachments . add (attachment);
}
mediaMessage . setAttachments (attachments);
CometChat . sendMediaMessage (mediaMessage, new CometChat . CallbackListener < MediaMessage >() {
@ Override
public void onSuccess ( MediaMessage mediaMessage ) {
Log . d (TAG, "Message Sent Successfully" )
}
@ Override
public void onError ( CometChatException e ) {
Log . d (TAG, "Message Sending Failed with exception : " + e . getMessage ());
}
});
val groupId = "cometchat-guid-1"
val mediaMessage = MediaMessage (groupId, CometChatConstants.MESSAGE_TYPE_IMAGE, CometChatConstants.RECEIVER_TYPE_GROUP)
val attachments: MutableList < Attachment > = ArrayList ()
for (i in 0 .. 4 ) {
val attachment = Attachment ()
attachment.fileName = "test"
attachment.fileExtension = "png"
attachment.fileUrl = "https://pngimg.com/uploads/mario/mario_PNG125.png"
attachment.fileMimeType = "image/png"
attachments. add (attachment)
}
mediaMessage.attachments = attachments
CometChat. sendMediaMessage (mediaMessage, object : CallbackListener < MediaMessage ?>() {
override fun onSuccess (mediaMessage: MediaMessage ?) {
Log. d (TAG, "Message Sent Successfully" )
}
override fun onError (e: CometChatException ) {
Log. d (TAG, "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.
You can use the setMetadata(), setCaption() & setTags() methods to add metadata, caption and tags in the same way as a single attachment.
Custom Message
Send custom data that doesn’t fit text or media using sendCustomMessage().
CustomMessage customMessage = new CustomMessage (receiverId, receiverType, customType, customData)
val customMessage = CustomMessage (receiverId, receiverType, customType, customData)
Parameter Description Required receiverIdUID of the user or GUID of the group Yes receiverTypeRECEIVER_TYPE_USER or RECEIVER_TYPE_GROUPYes customTypeDeveloper-defined type string (e.g., "LOCATION", "POLL") Yes customDataThe payload as a JSONObject Yes
You can also set a subtype using setSubtype() to further classify the custom message.
List < String > tags = new ArrayList <>();
tags . add ( "pinned" );
customMessage . setTags (tags);
val tags: MutableList < String > = ArrayList ()
tags. add ( "pinned" )
customMessage. setTags (tags)
Once the message object is ready, call sendCustomMessage().
Java (User)
Kotlin (User)
Java (Group)
Kotlin (Group)
private String UID = "UID" ;
private String customType = "LOCATION" ;
JSONObject customData = new JSONObject ();
customData . put ( "latitude" , "19.0760" );
customData . put ( "longitude" , "72.8777" );
CustomMessage customMessage = new CustomMessage (UID, CometChatConstants . RECEIVER_TYPE_USER , customType, customData);
CometChat . sendCustomMessage (customMessage, new CometChat . CallbackListener < CustomMessage >() {
@ Override
public void onSuccess ( CustomMessage customMessage ) {
Log . d (TAG, customMessage . toString ());
}
@ Override
public void onError ( CometChatException e ) {
Log . d (TAG, e . getMessage ());
}
});
private val UID = "UID"
private val customType = "LOCATION"
val customData = JSONObject ()
customData. put ( "latitude" , "19.0760" )
customData. put ( "longitude" , "72.8777" )
val customMessage = CustomMessage (UID, CometChatConstants.RECEIVER_TYPE_USER, customType, customData)
CometChat. sendCustomMessage (customMessage, object : CallbackListener < CustomMessage >() {
override fun onSuccess (customMessage: CustomMessage ) {
Log. d (TAG, customMessage. toString ())
}
override fun onError (e: CometChatException ) {
Log. d (TAG, e.message !! )
}
})
private String GUID = "GUID" ;
private String customType = "LOCATION" ;
JSONObject customData = new JSONObject ();
customData . put ( "latitude" , "19.0760" );
customData . put ( "longitude" , "72.8777" );
CustomMessage customMessage = new CustomMessage (GUID, CometChatConstants . RECEIVER_TYPE_GROUP , customType, customData);
CometChat . sendCustomMessage (customMessage, new CometChat . CallbackListener < CustomMessage >() {
@ Override
public void onSuccess ( CustomMessage customMessage ) {
Log . d (TAG, customMessage . toString ());
}
@ Override
public void onError ( CometChatException e ) {
Log . d (TAG, e . getMessage ());
}
});
private val GUID = "GUID"
private val customType = "LOCATION"
val customData = JSONObject ()
customData. put ( "latitude" , "19.0760" )
customData. put ( "longitude" , "72.8777" )
val customMessage = CustomMessage (GUID, CometChatConstants.RECEIVER_TYPE_GROUP, customType, customData)
CometChat. sendCustomMessage (customMessage, object : CallbackListener < CustomMessage >() {
override fun onSuccess (customMessage: CustomMessage ) {
Log. d (TAG, customMessage. toString ())
}
override fun onError (e: CometChatException ) {
Log. d (TAG, e.message !! )
}
})
On success, sendCustomMessage() returns a CustomMessage object.
Control Conversation Update
By default, a custom message updates the conversation’s last message. To prevent this:
Java (User)
Kotlin (User)
Java (Group)
Kotlin (Group)
private String UID = "UID" ;
private String customType = "LOCATION" ;
JSONObject customData = new JSONObject ();
customData . put ( "latitude" , "19.0760" );
customData . put ( "longitude" , "72.8777" );
CustomMessage customMessage = new CustomMessage (UID, CometChatConstants . RECEIVER_TYPE_USER , customType, customData);
customMessage . shouldUpdateConversation ( false );
CometChat . sendCustomMessage (customMessage, new CometChat . CallbackListener < CustomMessage >() {
@ Override
public void onSuccess ( CustomMessage customMessage ) {
Log . d (TAG, customMessage . toString ());
}
@ Override
public void onError ( CometChatException e ) {
Log . d (TAG, e . getMessage ());
}
});
private val UID = "UID"
private val customType = "LOCATION"
val customData = JSONObject ()
customData. put ( "latitude" , "19.0760" )
customData. put ( "longitude" , "72.8777" )
val customMessage = CustomMessage (UID, CometChatConstants.RECEIVER_TYPE_USER, customType, customData)
customMessage. shouldUpdateConversation ( false )
CometChat. sendCustomMessage (customMessage, object : CallbackListener < CustomMessage >() {
override fun onSuccess (customMessage: CustomMessage ) {
Log. d (TAG, customMessage. toString ())
}
override fun onError (e: CometChatException ) {
Log. d (TAG, e.message !! )
}
})
private String GUID = "GUID" ;
private String customType = "LOCATION" ;
JSONObject customData = new JSONObject ();
customData . put ( "latitude" , "19.0760" );
customData . put ( "longitude" , "72.8777" );
CustomMessage customMessage = new CustomMessage (GUID, CometChatConstants . RECEIVER_TYPE_GROUP , customType, customData);
customMessage . shouldUpdateConversation ( false );
CometChat . sendCustomMessage (customMessage, new CometChat . CallbackListener < CustomMessage >() {
@ Override
public void onSuccess ( CustomMessage customMessage ) {
Log . d (TAG, customMessage . toString ());
}
@ Override
public void onError ( CometChatException e ) {
Log . d (TAG, e . getMessage ());
}
});
private val GUID = "GUID"
private val customType = "LOCATION"
val customData = JSONObject ()
customData. put ( "latitude" , "19.0760" )
customData. put ( "longitude" , "72.8777" )
val customMessage = CustomMessage (GUID, CometChatConstants.RECEIVER_TYPE_GROUP, customType, customData)
customMessage. shouldUpdateConversation ( false )
CometChat. sendCustomMessage (customMessage, object : CallbackListener < CustomMessage >() {
override fun onSuccess (customMessage: CustomMessage ) {
Log. d (TAG, customMessage. toString ())
}
override fun onError (e: CometChatException ) {
Log. d (TAG, e.message !! )
}
})
Custom Notification Text
Set custom text for push, email, and SMS notifications:
Java (User)
Kotlin (User)
Java (Group)
Kotlin (Group)
private String UID = "UID" ;
private String customType = "LOCATION" ;
JSONObject customData = new JSONObject ();
customData . put ( "latitude" , "19.0760" );
customData . put ( "longitude" , "72.8777" );
CustomMessage customMessage = new CustomMessage (UID, CometChatConstants . RECEIVER_TYPE_USER , customType, customData);
customMessage . setConversationText ( "Custom Notification Body" );
CometChat . sendCustomMessage (customMessage, new CometChat . CallbackListener < CustomMessage >() {
@ Override
public void onSuccess ( CustomMessage customMessage ) {
Log . d (TAG, customMessage . toString ());
}
@ Override
public void onError ( CometChatException e ) {
Log . d (TAG, e . getMessage ());
}
});
private val UID = "UID"
private val customType = "LOCATION"
val customData = JSONObject ()
customData. put ( "latitude" , "19.0760" )
customData. put ( "longitude" , "72.8777" )
val customMessage = CustomMessage (UID, CometChatConstants.RECEIVER_TYPE_USER, customType, customData)
customMessage. setConversationText ( "Custom Notification Body" )
CometChat. sendCustomMessage (customMessage, object : CallbackListener < CustomMessage >() {
override fun onSuccess (customMessage: CustomMessage ) {
Log. d (TAG, customMessage. toString ())
}
override fun onError (e: CometChatException ) {
Log. d (TAG, e.message !! )
}
})
private String GUID = "GUID" ;
private String customType = "LOCATION" ;
JSONObject customData = new JSONObject ();
customData . put ( "latitude" , "19.0760" );
customData . put ( "longitude" , "72.8777" );
CustomMessage customMessage = new CustomMessage (GUID, CometChatConstants . RECEIVER_TYPE_GROUP , customType, customData);
customMessage . setConversationText ( "Custom Notification Body" );
CometChat . sendCustomMessage (customMessage, new CometChat . CallbackListener < CustomMessage >() {
@ Override
public void onSuccess ( CustomMessage customMessage ) {
Log . d (TAG, customMessage . toString ());
}
@ Override
public void onError ( CometChatException e ) {
Log . d (TAG, e . getMessage ());
}
});
private val GUID = "GUID"
private val customType = "LOCATION"
val customData = JSONObject ()
customData. put ( "latitude" , "19.0760" )
customData. put ( "longitude" , "72.8777" )
val customMessage = CustomMessage (GUID, CometChatConstants.RECEIVER_TYPE_GROUP, customType, customData)
customMessage. setConversationText ( "Custom Notification Body" )
CometChat. sendCustomMessage (customMessage, object : CallbackListener < CustomMessage >() {
override fun onSuccess (customMessage: CustomMessage ) {
Log. d (TAG, customMessage. toString ())
}
override fun onError (e: CometChatException ) {
Log. d (TAG, e.message !! )
}
})
It is also possible to send interactive messages from CometChat, to know more click here
Next Steps
Receive Messages Listen for incoming messages in real time
Edit Message Modify sent messages after delivery
Delete Message Remove messages from conversations
Interactive Messages Send messages with embedded forms and buttons
Message Payload Structure
The BaseMessage object returned by SDK methods contains the following fields. TextMessage, MediaMessage, and CustomMessage extend this base structure with additional type-specific fields. Parameter Type Description idlong Unique message identifier muidString Developer-defined message ID for deduplication senderUser User who sent the message receiverAppEntity Message receiver (User or Group ) receiverUidString Receiver’s unique identifier typeString Message type. Values: "text", "image", "video", "audio", "file", "custom" receiverTypeString Type of receiver. Values: "user", "group" categoryString Message category. Values: "message", "action", "call", "custom" sentAtlong Unix timestamp when message was sent deliveredAtlong Unix timestamp when message was delivered readAtlong Unix timestamp when message was read metadataJSONObject Custom message metadata set by developer readByMeAtlong Unix timestamp when logged-in user read the message deliveredToMeAtlong Unix timestamp when message was delivered to logged-in user deletedAtlong Unix timestamp when message was deleted (0 if not deleted) editedAtlong Unix timestamp when message was edited (0 if not edited) deletedByString UID of user who deleted the message (null if not deleted) editedByString UID of user who edited the message (null if not edited) updatedAtlong Unix timestamp of last message update conversationIdString Associated conversation identifier parentMessageIdlong Parent message ID for threaded messages (0 if not a reply) replyCountint Number of replies in thread unreadRepliesCountint Number of unread replies in thread mentionedUsersArray<User > List of users mentioned in the message hasMentionedMeboolean Whether the logged-in user is mentioned reactionsArray<ReactionCount > List of reaction counts on the message rawMessageJSONObject Raw JSON message data quotedMessageIdlong ID of the quoted message (0 if not quoting) quotedMessageBaseMessage The quoted message object (null if not quoting)
Sample BaseMessage Object: {
"id" : 12345 ,
"muid" : "msg_abc123" ,
"sender" : {
"uid" : "user_123" ,
"name" : "John Doe" ,
"avatar" : "https://example.com/avatar.png" ,
"status" : "online" ,
"role" : "default" ,
"lastActiveAt" : 1699900000
},
"receiver" : {
"uid" : "user_456" ,
"name" : "Jane Smith" ,
"avatar" : "https://example.com/avatar2.png"
},
"receiverUid" : "user_456" ,
"type" : "text" ,
"receiverType" : "user" ,
"category" : "message" ,
"sentAt" : 1699900000 ,
"deliveredAt" : 1699900001 ,
"readAt" : 1699900002 ,
"metadata" : {
"priority" : "high" ,
"customField" : "value"
},
"readByMeAt" : 1699900002 ,
"deliveredToMeAt" : 1699900001 ,
"deletedAt" : 0 ,
"editedAt" : 0 ,
"deletedBy" : null ,
"editedBy" : null ,
"updatedAt" : 1699900000 ,
"conversationId" : "user_123_user_456" ,
"parentMessageId" : 0 ,
"replyCount" : 5 ,
"unreadRepliesCount" : 2 ,
"mentionedUsers" : [],
"hasMentionedMe" : false ,
"reactions" : [
{
"reaction" : "👍" ,
"count" : 3 ,
"reactedByMe" : true
}
],
"rawMessage" : {},
"quotedMessageId" : 0 ,
"quotedMessage" : null
}
The nested User object (used in sender, receiver, mentionedUsers) contains: Parameter Type Description uidString Unique identifier of the user nameString Display name of the user avatarString URL to user’s profile picture linkString URL to user’s profile page roleString User role for access control metadataJSONObject Custom data set by developer statusString User online status. Values: "online", "offline" statusMessageString Custom status message lastActiveAtlong Unix timestamp of last activity hasBlockedMeboolean Whether this user has blocked the logged-in user blockedByMeboolean Whether the logged-in user has blocked this user tagsArray<String> List of tags for user identification deactivatedAtlong Unix timestamp when user was deactivated (0 if active)
The nested Group object (used in receiver for group messages) contains: Parameter Type Description guidString Unique identifier of the group nameString Display name of the group typeString Group type. Values: "public", "private", "password" iconString URL to group icon descriptionString Group description ownerString UID of group owner metadataJSONObject Custom data set by developer membersCountint Number of group members tagsArray<String> List of tags for group identification hasJoinedboolean Whether logged-in user has joined scopeString User’s scope in group. Values: "admin", "moderator", "participant"
The nested ReactionCount object (used in reactions array) contains: Parameter Type Description reactionString The reaction emoji countint Total count of this reaction reactedByMeboolean Whether the logged-in user has reacted with this emoji