Skip to main content
Quick Reference for AI Agents & Developers
  • Mention format: <@uid:USER_UID> in message text (e.g., "Hello <@uid:cometchat-uid-1>")
  • Get mentioned users: message.mentionedUsers returns array of mentioned User objects
  • Check if mentioned: message.mentionedMe returns Bool
  • Fetch with tag info: MessagesRequest.MessageRequestBuilder().mentionsWithTagInfo(true).build()
  • Related: Send Message · Receive Message · Messaging Overview
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.

Mention Format

FormatExample
<@uid:USER_UID><@uid:cometchat-uid-1>
Example message text with mention:
"Hello <@uid:cometchat-uid-1>, how are you?"

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>.
let messageText = "Hello <@uid:cometchat-uid-1>, how are you?"
let textMessage = TextMessage(receiverUid: "cometchat-uid-2", text: messageText, receiverType: .user)

CometChat.sendTextMessage(message: textMessage) { message in
    print("Mentioned users: \(message.mentionedUsers)")
} onError: { error in
    print("Error: \(error?.errorDescription)")
}
Method: CometChat.sendTextMessage(message:)
ParameterTypeValue
receiverUidString"cometchat-uid-2"
receiverTypeCometChat.ReceiverType.user
textString"Hello <@uid:cometchat-uid-2>, how are you?"
mentionFormatString<@uid:USER_UID>
Method: CometChat.sendTextMessage(message:)
ParameterTypeValue
receiverUidString"cometchat-guid-1"
receiverTypeCometChat.ReceiverType.group
textString"Hey <@uid:cometchat-uid-2>, check this out!"
You can mention users in text messages and media message captions.

Fetch Mentioned Messages

By default, the SDK will fetch all messages irrespective of whether the logged-in user is mentioned or not. The SDK allows you to fetch messages with additional mention information.
SettingDescription
mentionsWithTagInfo(true)Fetch messages with mentioned users’ tags
mentionsWithBlockedInfo(true)Fetch messages with blocked relationship info

Mentions With Tag Info

let messagesRequest = MessagesRequest(builder: MessagesRequest.MessageRequestBuilder()
    .set(uid: "cometchat-uid-2")
    .set(limit: 50)
    .mentionsWithTagInfo(true))

messagesRequest.fetchPrevious { messages in
    for message in messages ?? [] {
        for user in message.mentionedUsers {
            print("User tags: \(user.tags)")
        }
    }
} onError: { error in
    print("Error: \(error?.errorDescription)")
}
Method: MessagesRequest.fetchPrevious()
ParameterTypeValue
uidString"cometchat-uid-2"
limitInt50
mentionsWithTagInfoBooltrue

Mentions With Blocked Info

let messagesRequest = MessagesRequest(builder: MessagesRequest.MessageRequestBuilder()
    .set(uid: "cometchat-uid-2")
    .set(limit: 50)
    .mentionsWithBlockedInfo(true))

messagesRequest.fetchPrevious { messages in
    for message in messages ?? [] {
        for user in message.mentionedUsers {
            print("Has blocked me: \(user.hasBlockedMe)")
            print("Blocked by me: \(user.blockedByMe)")
        }
    }
} onError: { error in
    print("Error: \(error?.errorDescription)")
}
Method: MessagesRequest.fetchPrevious()
ParameterTypeValue
uidString"cometchat-uid-2"
limitInt50
mentionsWithBlockedInfoBooltrue

Get Users Mentioned In a Message

To retrieve the list of users mentioned in a particular message:
let mentionedUsers = message.mentionedUsers  // Returns [User]
Mentioned Users Array:
IndexUIDName
0"cometchat-uid-1""John Doe"
1"cometchat-uid-3""Jane Smith"

Check if Logged-in User Was Mentioned

To check if the logged-in user has been mentioned in a particular message:
let wasMentioned = message.mentionedMe  // Returns Bool
PropertyTypeDescription
mentionedMeBooltrue if logged-in user was mentioned

Mentioned User Properties

PropertyTypeDescription
uidStringUnique user identifier
nameStringUser’s display name
avatarString?User’s avatar URL
tags[String]User’s tags (with mentionsWithTagInfo)
hasBlockedMeBoolHas user blocked logged-in user (with mentionsWithBlockedInfo)
blockedByMeBoolIs user blocked by logged-in user (with mentionsWithBlockedInfo)