> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-docs-rn-guide-message-privately.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Mentions

> Add user mentions to CometChat messages in one-on-one and group chats using UID-based mention syntax.

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>"`

<Tabs>
  <Tab title="TypeScript (User)">
    ```typescript theme={null}
    let receiverID: string = "UID";
    let messageText: string = "Hello <@uid:cometchat-uid-1>";
    let receiverType: string = CometChat.RECEIVER_TYPE.USER;
    let textMessage: CometChat.TextMessage = new CometChat.TextMessage(receiverID, messageText, receiverType);

    CometChat.sendMessage(textMessage).then(
    (message: CometChat.TextMessage) => {
    console.log("Message sent successfully:", message);
    }, (error: CometChat.CometChatException) => {
    console.log("Message sending failed with error:", error);
    }
    );

    ```
  </Tab>

  <Tab title="JavaScript (User)">
    ```javascript theme={null}
    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);
      }
    );
    ```
  </Tab>

  <Tab title="TypeScript (Group)">
    ```typescript theme={null}
    let receiverID: string = "GUID",
      messageText: string = "Hello world!",
      receiverType: string = CometChat.RECEIVER_TYPE.GROUP,
      textMessage: CometChat.TextMessage = new CometChat.TextMessage(
        receiverID,
        messageText,
        receiverType
      );

    CometChat.sendMessage(textMessage).then(
    (message: CometChat.TextMessage) => {
    console.log("Message sent successfully:", message);
    },
    (error: CometChat.CometChatException) => {
    console.log("Message sending failed with error:", error);
    }
    );

    ```
  </Tab>

  <Tab title="JavaScript (Group)">
    ```javascript theme={null}
    let receiverID = "GUID";
    let messageText = "Hello <@uid:cometchat-uid-1>";
    let receiverType = CometChat.RECEIVER_TYPE.GROUP;
    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);
      }
    );
    ```
  </Tab>
</Tabs>

<Note>
  You can mention user in text message and media messages captions
</Note>

## 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.

| Setting                                | Description                                                                                                                                                                    |
| -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| 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.

<Tabs>
  <Tab title="TypeScript (User)">
    ```typescript theme={null}
    let UID: string = "UID",
      limit: number = 30,
      messagesRequest: CometChat.MessagesRequest =
        new CometChat.MessagesRequestBuilder()
          .setUID(UID)
          .setLimit(limit)
          .mentionsWithTagInfo(true)
          .build();

    messagesRequest.fetchPrevious().then(
    (messages: CometChat.BaseMessage[]) => {
    messages.forEach((eachMessage: CometChat.BaseMessage) => {
    eachMessage
    .getMentionedUsers()
    .forEach((eachMentionedUser: CometChat.User) => {
    console.log(eachMentionedUser.getTags());
    });
    });
    },
    (error) => {
    console.log("Message fetching failed with error:", error);
    }
    );

    ```
  </Tab>

  <Tab title="JavaScript (User)">
    ```javascript theme={null}
    let UID = "UID";
    let limit = 30;

    let 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);
      }
    );
    ```
  </Tab>

  <Tab title="TypeScript (Group)">
    ```typescript theme={null}
    let GUID: string = "GUID",
      limit: number = 30,
      messagesRequest: CometChat.MessagesRequest =
        new CometChat.MessagesRequestBuilder()
          .setGUID(GUID)
          .setLimit(limit)
          .mentionsWithTagInfo(true)
          .build();

    messagesRequest.fetchPrevious().then(
    (messages: CometChat.BaseMessage[]) => {
    messages.forEach((eachMessage: CometChat.BaseMessage) => {
    eachMessage
    .getMentionedUsers()
    .forEach((eachMentionedUser: CometChat.User) => {
    console.log(eachMentionedUser.getTags());
    });
    });
    },
    (error) => {
    console.log("Message fetching failed with error:", error);
    }
    );

    ```
  </Tab>

  <Tab title="JavaScript (Group)">
    ```javascript theme={null}
    let GUID = "GUID";
    let limit = 30;

    let messagesRequest = new CometChat.MessagesRequestBuilder()
      .setGUID(GUID)
      .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);
      }
    );
    ```
  </Tab>
</Tabs>

Relevant fields to access on returned messages and their mentioned users:

| Field                         | Getter                | Return Type                              | Description                             |
| ----------------------------- | --------------------- | ---------------------------------------- | --------------------------------------- |
| mentionedUsers                | `getMentionedUsers()` | [`User[]`](/sdk/reference/entities#user) | Array of users mentioned in the message |
| tags (on each mentioned user) | `getTags()`           | `string[]`                               | Tags associated with the mentioned user |

## 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:

| Field                                 | Getter                | Return Type                              | Description                                                |
| ------------------------------------- | --------------------- | ---------------------------------------- | ---------------------------------------------------------- |
| mentionedUsers                        | `getMentionedUsers()` | [`User[]`](/sdk/reference/entities#user) | Array of users mentioned in the message                    |
| blockedByMe (on each mentioned user)  | `getBlockedByMe()`    | `boolean`                                | Whether the logged-in user has blocked this mentioned user |
| hasBlockedMe (on each mentioned user) | `getHasBlockedMe()`   | `boolean`                                | Whether this mentioned user has blocked the logged-in user |

<Tabs>
  <Tab title="TypeScript (User)">
    ```typescript theme={null}
    let UID: string = "UID",
      limit: number = 30,
      messagesRequest: CometChat.MessagesRequest =
        new CometChat.MessagesRequestBuilder()
          .setUID(UID)
          .setLimit(limit)
          .mentionsWithBlockedInfo(true)
          .build();

    messagesRequest.fetchPrevious().then(
    (messages: CometChat.BaseMessage[]) => {
    messages.forEach((eachMessage: CometChat.BaseMessage) => {
    eachMessage
    .getMentionedUsers()
    .forEach((eachMentionedUser: CometChat.User) => {
    console.log("blockedByMe: " + eachMentionedUser.getBlockedByMe());
    console.log("hasBlockedMe: " + eachMentionedUser.getHasBlockedMe());
    });
    });
    },
    (error) => {
    console.log("Message fetching failed with error:", error);
    }
    );

    ```
  </Tab>

  <Tab title="JavaScript (User)">
    ```javascript theme={null}
    let UID = "UID";
    let limit = 30;

    let 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);
      }
    );
    ```
  </Tab>

  <Tab title="TypeScript (Group)">
    ```typescript theme={null}
    let GUID: string = "GUID",
      limit: number = 30,
      messagesRequest: CometChat.MessagesRequest =
        new CometChat.MessagesRequestBuilder()
          .setGUID(GUID)
          .setLimit(limit)
          .mentionsWithBlockedInfo(true)
          .build();

    messagesRequest.fetchPrevious().then(
    (messages: CometChat.BaseMessage[]) => {
    messages.forEach((eachMessage: CometChat.BaseMessage) => {
    eachMessage
    .getMentionedUsers()
    .forEach((eachMentionedUser: CometChat.User) => {
    console.log("blockedByMe: " + eachMentionedUser.getBlockedByMe());
    console.log("hasBlockedMe: " + eachMentionedUser.getHasBlockedMe());
    });
    });
    },
    (error) => {
    console.log("Message fetching failed with error:", error);
    }
    );

    ```
  </Tab>

  <Tab title="JavaScript (Group)">
    ```javascript theme={null}
    let GUID = "GUID";
    let limit = 30;

    let messagesRequest = new CometChat.MessagesRequestBuilder()
      .setGUID(GUID)
      .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);
      }
    );
    ```
  </Tab>
</Tabs>

## 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.

```javascript theme={null}
message.getMentionedUsers();
```

The getMentionedUsers() method returns an array of [`User`](/sdk/reference/entities#user) objects.

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Send Messages" icon="paper-plane" href="/sdk/javascript/send-message">
    Send text, media, and custom messages
  </Card>

  <Card title="Receive Messages" icon="envelope-open" href="/sdk/javascript/receive-message">
    Listen for incoming messages in real time
  </Card>

  <Card title="Reactions" icon="face-smile" href="/sdk/javascript/reactions">
    Add emoji reactions to messages
  </Card>

  <Card title="Threaded Messages" icon="comments" href="/sdk/javascript/threaded-messages">
    Organize conversations with message threads
  </Card>
</CardGroup>
