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
Field Value Key Classes TextMessage, MediaMessage, CustomMessage, MessagesRequest, MessagesRequestBuilderKey Methods CometChat.sendMessage(), CometChat.sendMediaMessage(), CometChat.sendCustomMessage(), MessagesRequest.fetchPrevious()Key Properties parentMessageId, hideRepliesListener Events onTextMessageReceived, onMediaMessageReceived, onCustomMessageReceivedPrerequisites SDK initialized, user logged in
// Send a message in a thread (attach to parent message)
TextMessage textMessage = TextMessage (
text : "Reply in thread" ,
receiverUid : "UID" ,
receiverType : CometChatReceiverType .user,
type : CometChatMessageType .text,
);
textMessage.parentMessageId = 103 ; // Parent message ID
CometChat . sendMessage (textMessage, onSuccess : (msg) {}, onError : (e) {});
// Fetch messages from a thread
MessagesRequest messageRequest = ( MessagesRequestBuilder ()
..uid = "UID"
..parentMessageId = 103
..limit = 50 ). build ();
messageRequest. fetchPrevious (onSuccess : ( List < BaseMessage > list) {}, onError : (e) {});
// Exclude threaded messages from main conversation
MessagesRequest request = ( MessagesRequestBuilder ()
..uid = "UID"
..hideReplies = true
..limit = 50 ). build ();
Threaded messages (or threads) are messages started from a particular parent message. Each thread is attached to a parent message.
Send Message in a Thread
As mentioned in the Send a Message section, you can send a message to a User or a Group by mentioning the receiver (uid/guid) and receiverType(user/group).
A message can be categorized as:
Text Message
Media Message
Custom Message
Interactive Message
Set the parentMessageId on the message object to indicate which thread the message belongs to. The id specified in the parentMessageId parameter maps the message sent to the particular thread. Any message type — TextMessage , MediaMessage , CustomMessage , or Interactive Message — can be sent in a thread.
String receiverID = "UID" ;
String messagesText = "Hello" ;
String receiverType = CometChatConversationType .user;
String type = CometChatMessageType .text;
TextMessage textMessage = TextMessage (
text : messagesText,
receiverUid : receiverID,
receiverType : receiverType,
type : type);
textMessage.parentMessageId = 103 ;
CometChat . sendMessage (textMessage, onSuccess : ( TextMessage message) {
debugPrint ( "Message sent successfully: $ message " );
}, onError : ( CometChatException e) {
debugPrint ( "Message sending failed with exception: ${ e . message } " );
});
String receiverID = "GUID" ;
String messagesText = "Hello" ;
String receiverType = CometChatConversationType .group;
String type = CometChatMessageType .text;
TextMessage textMessage = TextMessage (
text : messagesText,
receiverUid : receiverID,
receiverType : receiverType,
type : type);
textMessage.parentMessageId = 103 ;
CometChat . sendMessage (textMessage, onSuccess : ( TextMessage message) {
debugPrint ( "Message sent successfully: $ message " );
}, onError : ( CometChatException e) {
debugPrint ( "Message sending failed with exception: ${ e . message } " );
});
TextMessage Parameters:
Parameter Type Description Required textStringThe text content of the message Yes receiverUidStringThe UID of the user or GUID of the group to send the message to Yes receiverTypeStringThe type of the receiver — CometChatConversationType.user or CometChatConversationType.group Yes typeStringThe type of the message — CometChatMessageType.text Yes parentMessageIdintThe ID of the parent message to send this message as a thread reply Yes (for threads)
On Success — A TextMessage object containing all details of the sent threaded message:TextMessage Object: Parameter Type Description Sample Value idnumber Unique message ID 601metadataobject Custom metadata attached to the message {}receiverobject Receiver user object See below ↓ editedBystring UID of the user who edited the message nullconversationIdstring Unique conversation identifier "cometchat-uid-1_user_cometchat-uid-2"sentAtnumber Epoch timestamp when the message was sent 1745554729receiverUidstring UID of the receiver "cometchat-uid-2"typestring Type of the message "text"readAtnumber Epoch timestamp when the message was read 0deletedBystring UID of the user who deleted the message nulldeliveredAtnumber Epoch timestamp when the message was delivered 0deletedAtnumber Epoch timestamp when the message was deleted 0replyCountnumber Number of replies to this message 0senderobject Sender user object See below ↓ receiverTypestring Type of the receiver "user"editedAtnumber Epoch timestamp when the message was edited 0parentMessageIdnumber ID of the parent message (for threads) 103readByMeAtnumber Epoch timestamp when read by the current user 0categorystring Message category "message"deliveredToMeAtnumber Epoch timestamp when delivered to the current user 0updatedAtnumber Epoch timestamp when the message was last updated 1745554729textstring The text content of the message "Hello"tagsarray List of tags associated with the message []unreadRepliesCountnumber Count of unread replies 0mentionedUsersarray List of mentioned users []hasMentionedMeboolean Whether the current user is mentioned falsereactionsarray List of reactions on the message []moderationStatusstring Moderation status of the message nullquotedMessageIdnumber ID of the quoted message null
sender Object:Parameter Type Description Sample Value uidstring Unique identifier of the sender "cometchat-uid-1"namestring Display name of the sender "Andrew Joseph"linkstring Profile link nullavatarstring Avatar URL "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-1.webp"metadataobject Custom metadata {}statusstring Online status "online"rolestring User role "default"statusMessagestring Status message nulltagsarray User tags []hasBlockedMeboolean Whether this user has blocked the current user falseblockedByMeboolean Whether the current user has blocked this user falselastActiveAtnumber Epoch timestamp of last activity 1745554700
receiver Object:Parameter Type Description Sample Value uidstring Unique identifier of the receiver "cometchat-uid-2"namestring Display name of the receiver "George Alan"linkstring Profile link nullavatarstring Avatar URL "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"metadataobject Custom metadata {}statusstring Online status "offline"rolestring User role "default"statusMessagestring Status message nulltagsarray User tags []hasBlockedMeboolean Whether this user has blocked the current user falseblockedByMeboolean Whether the current user has blocked this user falselastActiveAtnumber Epoch timestamp of last activity 1745550000
Parameter Type Description Sample Value codestring Error code identifier "ERR_CHAT_API_FAILURE"messagestring Human-readable error message "Failed to send the message."detailsstring Additional technical details "An unexpected error occurred while processing the request."
The above snippet shows how a message with the text “Hello” can be sent in the thread with parentMessageId 103.
Similarly, using the parentMessageId parameter, Media and Custom Messages can be sent in threads too.
Receiving Real-Time Messages
The procedure to receive real-time messages is exactly the same as mentioned in the Receive Messages section. Use the MessageListener class to listen for incoming thread messages. Check if the received message belongs to the active thread using the parentMessageId field.
Always remove message 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" );
class Class_Name with MessageListener {
int activeParentMessageId = 103 ;
//CometChat.addMessageListener("listenerId", this);
@override
void onTextMessageReceived ( TextMessage textMessage) {
if (textMessage.parentMessageId == activeParentMessageId){
debugPrint ( "Text message received successfully: $ textMessage " );
}
}
@override
void onMediaMessageReceived ( MediaMessage mediaMessage) {
if (mediaMessage.parentMessageId == activeParentMessageId){
debugPrint ( "Media message received successfully: $ mediaMessage " );
}
}
@override
void onCustomMessageReceived ( CustomMessage customMessage) {
if (customMessage.parentMessageId == activeParentMessageId){
debugPrint ( "Custom message received successfully: $ customMessage " );
}
}
}
Fetch all the messages for any particular thread.
Use MessagesRequestBuilder with parentMessageId to fetch messages belonging to a specific thread. Call fetchPrevious() to get messages (max 100 per request), returned as BaseMessage objects. Call fetchPrevious() again on the same object to get the next set.
MessagesRequestBuilder Parameters:
Parameter Type Description Required uidStringThe UID of the user whose conversation thread messages are to be fetched Yes (for user threads) guidStringThe GUID of the group whose conversation thread messages are to be fetched Yes (for group threads) parentMessageIdintThe ID of the parent message whose thread messages are to be fetched Yes limitintNumber of messages to fetch in a single request (max 100) No
String UID = "cometchat-uid-1" ;
MessagesRequest messageRequest = ( MessagesRequestBuilder ()
..uid = UID
..parentMessageId = 103
..limit = 50 ). build ();
messageRequest. fetchPrevious (onSuccess : ( List < BaseMessage > list) {
debugPrint ( "Message fetching Successful" );
}, onError : ( CometChatException e) {
debugPrint ( "Message fetching failed with exception: ${ e . message } " );
});
On Success — A List<BaseMessage> containing the fetched thread messages (each item is a BaseMessage object):BaseMessage Object: Parameter Type Description Sample Value idnumber Unique message ID 602metadataobject Custom metadata attached to the message {}receiverobject Receiver user object See below ↓ editedBystring UID of the user who edited the message nullconversationIdstring Unique conversation identifier "cometchat-uid-1_user_cometchat-uid-2"sentAtnumber Epoch timestamp when the message was sent 1745554729receiverUidstring UID of the receiver "cometchat-uid-1"typestring Type of the message "text"readAtnumber Epoch timestamp when the message was read 0deletedBystring UID of the user who deleted the message nulldeliveredAtnumber Epoch timestamp when the message was delivered 0deletedAtnumber Epoch timestamp when the message was deleted 0replyCountnumber Number of replies to this message 0senderobject Sender user object See below ↓ receiverTypestring Type of the receiver "user"editedAtnumber Epoch timestamp when the message was edited 0parentMessageIdnumber ID of the parent message (for threads) 103readByMeAtnumber Epoch timestamp when read by the current user 0categorystring Message category "message"deliveredToMeAtnumber Epoch timestamp when delivered to the current user 0updatedAtnumber Epoch timestamp when the message was last updated 1745554729unreadRepliesCountnumber Count of unread replies 0quotedMessageIdnumber ID of the quoted message nullquotedMessageobject The quoted message object null
sender Object:Parameter Type Description Sample Value uidstring Unique identifier of the sender "cometchat-uid-2"namestring Display name of the sender "George Alan"linkstring Profile link nullavatarstring Avatar URL "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"metadataobject Custom metadata {}statusstring Online status "online"rolestring User role "default"statusMessagestring Status message nulltagsarray User tags []hasBlockedMeboolean Whether this user has blocked the current user falseblockedByMeboolean Whether the current user has blocked this user falselastActiveAtnumber Epoch timestamp of last activity 1745554700
receiver Object:Parameter Type Description Sample Value uidstring Unique identifier of the receiver "cometchat-uid-1"namestring Display name of the receiver "Andrew Joseph"linkstring Profile link nullavatarstring Avatar URL "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-1.webp"metadataobject Custom metadata {}statusstring Online status "offline"rolestring User role "default"statusMessagestring Status message nulltagsarray User tags []hasBlockedMeboolean Whether this user has blocked the current user falseblockedByMeboolean Whether the current user has blocked this user falselastActiveAtnumber Epoch timestamp of last activity 1745550000
Parameter Type Description Sample Value codestring Error code identifier "ERR_CHAT_API_FAILURE"messagestring Human-readable error message "Failed to fetch the requested data."detailsstring Additional technical details "An unexpected error occurred while processing the request."
Avoid Threaded Messages in User/Group Conversations
While fetching messages for normal user/group conversations using the MessagesRequest, the threaded messages by default will be a part of the list of messages received. Use hideReplies = true on the MessagesRequestBuilder to exclude threaded messages from the list.
String UID = "cometchat-uid-1" ;
MessagesRequest messageRequest = ( MessagesRequestBuilder ()
..uid = UID
..hideReplies = true
..limit = 50 ). build ();
messageRequest. fetchNext (onSuccess : ( List < BaseMessage > list) {
debugPrint ( "Message fetching Successful" );
}, onError : ( CometChatException e) {
debugPrint ( "Message fetching failed with exception: ${ e . message } " );
});
String GUID = "cometchat-guid-1" ;
MessagesRequest messageRequest = ( MessagesRequestBuilder ()
..guid = GUID
..hideReplies = true
..limit = 50 ). build ();
messageRequest. fetchNext (onSuccess : ( List < BaseMessage > list) {
debugPrint ( "Message fetching Successful" );
}, onError : ( CometChatException e) {
debugPrint ( "Message fetching failed with exception: ${ e . message } " );
});
On Success — A List<BaseMessage> containing the fetched messages excluding threaded replies (each item is a BaseMessage object):BaseMessage Object: Parameter Type Description Sample Value idnumber Unique message ID 603metadataobject Custom metadata attached to the message {}receiverobject Receiver user object See below ↓ editedBystring UID of the user who edited the message nullconversationIdstring Unique conversation identifier "cometchat-uid-1_user_cometchat-uid-2"sentAtnumber Epoch timestamp when the message was sent 1745554729receiverUidstring UID of the receiver "cometchat-uid-1"typestring Type of the message "text"readAtnumber Epoch timestamp when the message was read 0deletedBystring UID of the user who deleted the message nulldeliveredAtnumber Epoch timestamp when the message was delivered 0deletedAtnumber Epoch timestamp when the message was deleted 0replyCountnumber Number of replies to this message 0senderobject Sender user object See below ↓ receiverTypestring Type of the receiver "user"editedAtnumber Epoch timestamp when the message was edited 0parentMessageIdnumber ID of the parent message (for threads) 0readByMeAtnumber Epoch timestamp when read by the current user 0categorystring Message category "message"deliveredToMeAtnumber Epoch timestamp when delivered to the current user 0updatedAtnumber Epoch timestamp when the message was last updated 1745554729unreadRepliesCountnumber Count of unread replies 0quotedMessageIdnumber ID of the quoted message nullquotedMessageobject The quoted message object null
sender Object:Parameter Type Description Sample Value uidstring Unique identifier of the sender "cometchat-uid-2"namestring Display name of the sender "George Alan"linkstring Profile link nullavatarstring Avatar URL "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"metadataobject Custom metadata {}statusstring Online status "online"rolestring User role "default"statusMessagestring Status message nulltagsarray User tags []hasBlockedMeboolean Whether this user has blocked the current user falseblockedByMeboolean Whether the current user has blocked this user falselastActiveAtnumber Epoch timestamp of last activity 1745554700
receiver Object:Parameter Type Description Sample Value uidstring Unique identifier of the receiver "cometchat-uid-1"namestring Display name of the receiver "Andrew Joseph"linkstring Profile link nullavatarstring Avatar URL "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-1.webp"metadataobject Custom metadata {}statusstring Online status "offline"rolestring User role "default"statusMessagestring Status message nulltagsarray User tags []hasBlockedMeboolean Whether this user has blocked the current user falseblockedByMeboolean Whether the current user has blocked this user falselastActiveAtnumber Epoch timestamp of last activity 1745550000
Parameter Type Description Sample Value codestring Error code identifier "ERR_CHAT_API_FAILURE"messagestring Human-readable error message "Failed to fetch the requested data."detailsstring Additional technical details "An unexpected error occurred while processing the request."
The response is a list of BaseMessage objects, excluding any messages that are replies within a thread. Only top-level messages in the conversation are returned.
Next Steps
Send Messages Learn how to send text, media, and custom messages
Receive Messages Handle incoming messages in real-time
Reactions Add emoji reactions to messages
Message Structure Understand message types and hierarchy