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.mentionedUsersreturns array of mentionedUserobjects - Check if mentioned:
message.mentionedMereturnsBool - Fetch with tag info:
MessagesRequest.MessageRequestBuilder().mentionsWithTagInfo(true).build() - Related: Send Message · Receive Message · Messaging Overview
Mention Format
| Format | Example |
|---|---|
<@uid:USER_UID> | <@uid:cometchat-uid-1> |
Send Mentioned Messages
Every User object has a String unique identifier associated with them which can be found in a property calleduid. To mention a user in a message, the message text should contain the uid in following format: <@uid:UID_OF_THE_USER>.
- Swift (User)
- Swift (Group)
Sample Payloads - Send Mentioned Message (User)
Sample Payloads - Send Mentioned Message (User)
- Request
- Success Response
Method:
CometChat.sendTextMessage(message:)| Parameter | Type | Value |
|---|---|---|
| receiverUid | String | "cometchat-uid-2" |
| receiverType | CometChat.ReceiverType | .user |
| text | String | "Hello <@uid:cometchat-uid-2>, how are you?" |
| mentionFormat | String | <@uid:USER_UID> |
Sample Payloads - Send Mentioned Message (Group)
Sample Payloads - Send Mentioned Message (Group)
- Request
- Success Response
Method:
CometChat.sendTextMessage(message:)| Parameter | Type | Value |
|---|---|---|
| receiverUid | String | "cometchat-guid-1" |
| receiverType | CometChat.ReceiverType | .group |
| text | String | "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.| Setting | Description |
|---|---|
mentionsWithTagInfo(true) | Fetch messages with mentioned users’ tags |
mentionsWithBlockedInfo(true) | Fetch messages with blocked relationship info |
Mentions With Tag Info
- Swift (User)
- Swift (Group)
Sample Payloads - Fetch Mentions with Tag Info
Sample Payloads - Fetch Mentions with Tag Info
- Request
- Success Response
Method:
MessagesRequest.fetchPrevious()| Parameter | Type | Value |
|---|---|---|
| uid | String | "cometchat-uid-2" |
| limit | Int | 50 |
| mentionsWithTagInfo | Bool | true |
Mentions With Blocked Info
- Swift (User)
Sample Payloads - Fetch Mentions with Blocked Info
Sample Payloads - Fetch Mentions with Blocked Info
- Request
- Success Response
Method:
MessagesRequest.fetchPrevious()| Parameter | Type | Value |
|---|---|---|
| uid | String | "cometchat-uid-2" |
| limit | Int | 50 |
| mentionsWithBlockedInfo | Bool | true |
Get Users Mentioned In a Message
To retrieve the list of users mentioned in a particular message:- Swift
| Index | UID | Name |
|---|---|---|
| 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:- Swift
| Property | Type | Description |
|---|---|---|
| mentionedMe | Bool | true if logged-in user was mentioned |
Mentioned User Properties
| Property | Type | Description |
|---|---|---|
| uid | String | Unique user identifier |
| name | String | User’s display name |
| avatar | String? | User’s avatar URL |
| tags | [String] | User’s tags (with mentionsWithTagInfo) |
| hasBlockedMe | Bool | Has user blocked logged-in user (with mentionsWithBlockedInfo) |
| blockedByMe | Bool | Is user blocked by logged-in user (with mentionsWithBlockedInfo) |