Skip to main content
Quick Reference - Mention a user in a message:
// Use the format <@uid:UID> to mention users
let messageText = "Hello, <@uid:cometchat-uid-1>";
let textMessage = new CometChat.TextMessage("RECEIVER_ID", messageText, CometChat.RECEIVER_TYPE.USER);
CometChat.sendMessage(textMessage);
Available via: SDK | REST API | UI Kits
Mentions in messages enable users to refer to specific individual 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.

Send Mentioned Messages

To send a message with a mentioned user, you must follow a specific format: <@uid:UID>. For example, to mention the user with UID cometchat-uid-1 with the message “Hello,” your text would be “Hello, <@uid:cometchat-uid-1>
let receiverID = "UID";
let messageText = "Hello, <@uid:cometchat-uid-1>";
let receiverType = CometChat.RECEIVER_TYPE.USER;
let textMessage = new CometChat.TextMessage(
  receiverID,
  messageText,
  receiverType
);

CometChat.sendMessage(textMessage).then(
  (message) => {
    console.log("Message sent successfully:", message);
  },
  (error) => {
    console.log("Message sending failed with error:", error);
  }
);
On SuccesssendMessage() with mentions returns the sent message object with mentionedUsers populated:Message Object:
ParameterTypeDescriptionSample Value
idstringUnique message identifier"25326"
conversationIdstringConversation identifier"cometchat-uid-6_user_cometchat-uid-7"
receiverIdstringReceiver’s UID"cometchat-uid-7"
receiverTypestringType of receiver"user"
typestringMessage type"text"
categorystringMessage category"message"
textstringMessage text with mention format"Hello <@uid:cometchat-uid-7>, this is a test mention!"
sentAtnumberUnix timestamp when sent1772006074
updatedAtnumberUnix timestamp when updated1772006074
mentionedMebooleanWhether current user is mentionedfalse
mentionedUsersarrayUsers mentioned in messageSee below ↓
senderobjectSender user detailsSee below ↓
receiverobjectReceiver user detailsSee below ↓
dataobjectAdditional message dataSee below ↓
reactionsarrayMessage reactions[]

mentionedUsers Array (per item):
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-7"
namestringUser’s display name"Henry Marino"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-7.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1772005334
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0

sender Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-6"
namestringUser’s display name"Ronald Jerry"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-6.webp"
statusstringUser’s online status"offline"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1772004288
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-7"
namestringUser’s display name"Henry Marino"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-7.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1772005334
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

data Object:
ParameterTypeDescriptionSample Value
textstringMessage text"Hello <@uid:cometchat-uid-7>, this is a test mention!"
entitiesobjectSender and receiver entitiesSee below ↓
mentionsobjectMentioned users mapSee below ↓

data.entities Object:
ParameterTypeDescriptionSample Value
senderobjectSender entity wrapperSee below ↓
receiverobjectReceiver entity wrapperSee below ↓

data.entities.sender Object:
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectUser entity detailsSee below ↓

data.entities.sender.entity Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-6"
namestringUser’s display name"Ronald Jerry"
avatarstringUser’s avatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-6.webp"
statusstringUser’s online status"offline"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1772004288
tagsarrayUser tags[]

data.entities.receiver Object:
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectUser entity detailsSee below ↓

data.entities.receiver.entity Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-7"
namestringUser’s display name"Henry Marino"
avatarstringUser’s avatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-7.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1772005334
conversationIdstringConversation identifier"cometchat-uid-6_user_cometchat-uid-7"
tagsarrayUser tags[]

data.mentions Object:
ParameterTypeDescriptionSample Value
cometchat-uid-7objectMentioned user details keyed by UIDSee below ↓

data.mentions["cometchat-uid-7"] Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-7"
namestringUser’s display name"Henry Marino"
avatarstringUser’s avatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-7.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1772005334
conversationIdstringConversation identifier"cometchat-uid-6_user_cometchat-uid-7"
You can mention user in text message and media messages captions
Push Notifications & UI Rendering: While the message format uses <@uid:UID>, push notifications are sent with the parsed body containing the actual username — not the raw <@uid:> format. For UI rendering with the SDK, use message.getMentionedUsers() to get the mentioned user objects (which include both uid and name) and replace the <@uid:> tags in your message bubble accordingly. If you’re using a UI Kit, this is handled automatically.

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 tags and blocked relationships.
SettingDescription
mentionsWithTagInfo(boolean 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. Default value = false
mentionsWithBlockedInfo(boolean 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. Default value = false

Mentions With Tag Info

To get a list of messages in a conversation where users are mentioned along with the user tags of the mentioned users.
let UID = "UID";
let limit = 30;

var messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setLimit(limit)
  .mentionsWithTagInfo(true)
  .build();

messagesRequest.fetchPrevious().then(
  (messages) => {
    messages.forEach((eachMessage) => {
      eachMessage.getMentionedUsers().forEach((eachMentionedUser) => {
        console.log(eachMentionedUser.getTags());
      });
    });
  },
  (error) => {
    console.log("Message fetching failed with error:", error);
  }
);
On SuccessmentionsWithTagInfo(true) returns mentioned users with their tags:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-7"
namestringUser’s display name"Henry Marino"
tagsarrayUser’s tags["vip"]

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.
let UID = "UID";
let limit = 30;
var messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setLimit(limit)
  .mentionsWithBlockedInfo(true)
  .build();

messagesRequest.fetchPrevious().then(
  (messages) => {
    messages.forEach((eachMessage) => {
      eachMessage.getMentionedUsers().forEach((eachMentionedUser) => {
        console.log("blockedByMe: " + eachMentionedUser.getBlockedByMe());
        console.log("hasBlockedMe: " + eachMentionedUser.getHasBlockedMe());
      });
    });
  },
  (error) => {
    console.log("Message fetching failed with error:", error);
  }
);
On SuccessmentionsWithBlockedInfo(true) returns mentioned users with blocked relationship info:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-7"
namestringUser’s display name"Henry Marino"
blockedByMebooleanWhether current user blocked this userfalse
hasBlockedMebooleanWhether user has blocked current userfalse

Get Users Mentioned In a Particular Message

To retrieve the list of users mentioned in the particular message, you can use the message.getMentionedUsers() method. This method will return an array containing the mentioned users, or an empty array if no users were mentioned in the message.
message.getMentionedUsers();
On SuccessgetMentionedUsers() returns an array of mentioned user objects:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-7"
namestringUser’s display name"Henry Marino"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-7.webp"
statusstringUser’s online status"online"
blockedByMebooleanWhether current user blocked this userfalse
hasBlockedMebooleanWhether user has blocked current userfalse

Best Practices

Always use the <@uid:UID> format when mentioning users. The UID must exactly match the user’s unique identifier in CometChat. Incorrect UIDs will not resolve to a valid mention.
Before sending a message with mentions, verify that the UIDs you are referencing exist in your CometChat app. Mentioning non-existent UIDs will not throw an error, but the mention will not resolve to a user on the recipient’s end.
Use mentionsWithTagInfo(true) and mentionsWithBlockedInfo(true) on your MessagesRequestBuilder when you need to display additional context about mentioned users, such as their roles (via tags) or blocked status. Avoid enabling these filters unnecessarily to reduce payload size.
Mentions are supported in text messages and media message captions. Ensure your UI handles rendering mentions consistently across both message types.

Troubleshooting

Ensure you are using the correct <@uid:UID> format. The UID must be wrapped exactly as <@uid:your-uid-here>. Also verify that the mentioned user exists in your CometChat app. Use message.getMentionedUsers() to confirm the SDK parsed the mentions correctly.
This typically means the mention format in the message text is incorrect or the UID does not match any registered user. Double-check the message text for proper <@uid:UID> syntax and ensure there are no extra spaces or typos in the UID.
Make sure you have set mentionsWithTagInfo(true) or mentionsWithBlockedInfo(true) on your MessagesRequestBuilder before calling fetchPrevious(). These filters are disabled by default.
Verify that you are setting the caption text with the <@uid:UID> format on the media message object. Mentions in captions follow the same format as text messages.

Next Steps