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, BaseMessage, User, MessagesRequest, MessagesRequestBuilder
Key PropertiesmentionedUsers, hasMentionedMe
Builder MethodsmentionsWithTagInfo(), mentionsWithBlockedInfo()
Mention Format<@uid:UID>
PrerequisitesSDK initialized, user logged in
// Send a message with a mention (use <@uid:UID> format)
TextMessage textMessage = TextMessage(
  text: "Hello <@uid:cometchat-uid-1>",
  receiverUid: "UID",
  receiverType: CometChatReceiverType.user,
  type: CometChatMessageType.text,
);
CometChat.sendMessage(textMessage, onSuccess: (msg) {
  debugPrint("Mentioned users: ${msg.mentionedUsers}");
}, onError: (e) {});

// Get mentioned users from a message
List<User> mentionedUsers = message.mentionedUsers;

// Check if logged-in user was mentioned
bool wasMentioned = message.hasMentionedMe ?? false;

// Fetch messages with mention tag info
MessagesRequest request = (MessagesRequestBuilder()
  ..uid = "UID"
  ..limit = 30
  ..mentionsWithTagInfo(true)
).build();
request.fetchPrevious(onSuccess: (messages) {}, onError: (e) {});
Mentions in messages enable users to refer to specific individuals within a conversation. This is done by using the <@uid:UID> format, where UID represents the user’s unique identification. Mentions are a powerful tool for enhancing communication in messaging platforms. They streamline interaction by allowing users to easily engage and collaborate with particular individuals, especially in group conversations.
Available via: SDK | REST API | UI Kits

Send Mentioned Messages

Every User object has a String unique identifier associated with them which can be found in a property called uid. To mention a user in a message, the message text should contain the uid in following format: <@uid:UID_OF_THE_USER>. For example, to mention the user with UID cometchat-uid-1 in a text message, your text should be “<@uid:cometchat-uid-1>
String receiverID = "UID";
User sender = User(name: "Sender", uid: "senderUID");
String messageText = "Hello, <@uid:cometchat-uid-1>";
String receiverType = CometChatReceiverType.user;

TextMessage textMessage = TextMessage(
      text: messageText,
      sender: sender,
      receiverUid: receiverID,
      receiverType: receiverType,
			category: CometChatMessageCategory.message,
      type: CometChatMessageType.text);

CometChat.sendMessage(textMessage, onSuccess:(TextMessage textMessage) {
      print("Message sent successfully: ${textMessage.text}, mentioned users: ${textMessage.mentionedUsers}");
  },
   onError:(CometChatException e) {
      print("Message sending failed with exception: $e");
  }
);
On Success — A TextMessage object containing all details of the sent message with mentions:TextMessage Object:
ParameterTypeDescriptionSample Value
idnumberUnique message ID501
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"Hello, <@uid:cometchat-uid-1>"
tagsarrayList of tags associated with the message[]
unreadRepliesCountnumberCount of unread replies0
mentionedUsersarrayList of mentioned usersSee below ↓
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

mentionedUsers Array (per item):
ParameterTypeDescriptionSample Value
uidstringUnique identifier of the mentioned user"cometchat-uid-1"
namestringDisplay name of the mentioned user"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
ParameterTypeDescriptionSample Value
codestringError code identifier"ERR_CHAT_API_FAILURE"
messagestringHuman-readable error message"Failed to send the message."
detailsstringAdditional technical details"An unexpected error occurred while processing the request."
You can mention user in text message and media messages captions

Mentioned Messages

By default, the SDK will fetch all the messages irrespective of the fact that the logged-in user is mentioned or not in the message. The SDK has other optional filters such as tag info and blocked info.
SettingDescriptionDefault Value
mentionsWithTagInfo(bool value)If set to true, SDK will fetch a list of messages where users are mentioned & will also fetch the tags of the mentioned users.false
mentionsWithBlockedInfo(bool value)If set to true, SDK will fetch a list of messages where users are mentioned & will also fetch their blocked relationship with the logged-in user.false

Mentions With Tag Info

To get a list of messages in a conversation where users are mentioned along with the tags of the mentioned users. Relevant fields to access on returned messages and their mentioned users:
FieldPropertyReturn TypeDescription
mentionedUsersmentionedUsersList<User>Array of users mentioned in the message
tags (on each mentioned user)tagsList<String>Tags associated with the mentioned user
String UID = "cometchat-uid-1";

MessagesRequest messagesRequest = (MessagesRequestBuilder()
..limit=50
..uid=UID
..mentionsWithTagInfo(true))
.build();

messagesRequest.fetchPrevious(onSuccess:(List<BaseMessage> messages) {
    for (BaseMessage message in messages){
      for (User user in message.mentionedUsers){
        print("mentioned user tags: ${user.tags}");
      }
    }
  },
		onError: (CometChatException e) {
    print("error: $e");
  }
);
On Success — A List<BaseMessage> containing messages with mentioned users and their tag info (each item is a BaseMessage object):BaseMessage Object:
ParameterTypeDescriptionSample Value
idnumberUnique message ID502
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-1"
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)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 updated1745554729
unreadRepliesCountnumberCount of unread replies0
quotedMessageIdnumberID of the quoted messagenull
quotedMessageobjectThe quoted message objectnull

sender Object:
ParameterTypeDescriptionSample Value
uidstringUnique identifier of the sender"cometchat-uid-2"
namestringDisplay name of the sender"George Alan"
linkstringProfile linknull
avatarstringAvatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.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-1"
namestringDisplay name of the receiver"Andrew Joseph"
linkstringProfile linknull
avatarstringAvatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-1.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 fetch the requested data."
detailsstringAdditional technical details"An unexpected error occurred while processing the request."

Mentions With Blocked Info

To get a list of messages in a conversation where users are mentioned along with the blocked relationship of the mentioned users with the logged-in user. Relevant fields to access on returned messages and their mentioned users:
FieldPropertyReturn TypeDescription
mentionedUsersmentionedUsersList<User>Array of users mentioned in the message
blockedByMe (on each mentioned user)blockedByMeboolWhether the logged-in user has blocked this mentioned user
hasBlockedMe (on each mentioned user)hasBlockedMeboolWhether this mentioned user has blocked the logged-in user
String UID = "cometchat-uid-1";

MessagesRequest messagesRequest = (MessagesRequestBuilder()
..limit=50
..uid=UID
..mentionsWithBlockedInfo(true))
.build();

messagesRequest.fetchPrevious(onSuccess:(List<BaseMessage> messages) {
    for (BaseMessage message in messages){
      for (User user in message.mentionedUsers){
        print("mentioned user has blocked me? ${user.hasBlockedMe}");
        print("mentioned user is blocked by me? ${user.blockedByMe}");
      }
    }
  },
		onError: (CometChatException e) {
    print("error: $e");
  }
);
On Success — A List<BaseMessage> containing messages with mentioned users and their blocked relationship info (each item is a BaseMessage object):BaseMessage Object:
ParameterTypeDescriptionSample Value
idnumberUnique message ID503
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-1"
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)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 updated1745554729
unreadRepliesCountnumberCount of unread replies0
quotedMessageIdnumberID of the quoted messagenull
quotedMessageobjectThe quoted message objectnull

sender Object:
ParameterTypeDescriptionSample Value
uidstringUnique identifier of the sender"cometchat-uid-2"
namestringDisplay name of the sender"George Alan"
linkstringProfile linknull
avatarstringAvatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.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-1"
namestringDisplay name of the receiver"Andrew Joseph"
linkstringProfile linknull
avatarstringAvatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-1.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 fetch the requested data."
detailsstringAdditional technical details"An unexpected error occurred while processing the request."

Get Users Mentioned In a Particular Message

To retrieve the list of users mentioned in the particular message, you can use the mentionedUsers property on any BaseMessage. This property will return an array containing User objects of the mentioned users, or an empty array if no users were mentioned in the message.
message.mentionedUsers
The mentionedUsers property returns a List<User> objects.

Check if Logged-in user has been mentioned

To check if the logged-in user has been mentioned in a particular message we can use the hasMentionedMe property on any BaseMessage. This property will return a boolean value, true if the logged-in user has been mentioned, otherwise false.
message.hasMentionedMe

Next Steps

Send Messages

Send text, media, and custom messages

Receive Messages

Listen for incoming messages in real time

Reactions

Add emoji reactions to messages

Threaded Messages

Organize conversations with message threads