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

# Send A Message

> Send text, media, and custom messages to users and groups using the CometChat React Native SDK.

<Info>
  **Quick Reference** - Send a text message:

  ```javascript theme={null}
  // Send text to a user
  const textMessage = new CometChat.TextMessage("UID", "Hello!", CometChat.RECEIVER_TYPE.USER);
  const sent = await CometChat.sendMessage(textMessage);

  // Send media to a group
  const mediaMessage = new CometChat.MediaMessage("GUID", file, CometChat.MESSAGE_TYPE.IMAGE, CometChat.RECEIVER_TYPE.GROUP);
  const sentMedia = await CometChat.sendMediaMessage(mediaMessage);
  ```
</Info>

<Note>
  **Available via:** [SDK](/sdk/react-native/send-message) | [REST API](/rest-api/messages/send-message) | [UI Kits](/ui-kit/react-native/core-features#instant-messaging)
</Note>

Using CometChat, you can send three types of messages:

1. [Text Message](#text-message) is the most common and standard message type.
2. [Media Message](#media-message), for sending photos, videos and files.
3. [Custom Message](#custom-message), for sending completely custom data using JSON structures.
4. [Interactive Message](/sdk/react-native/interactive-messages) for sending end-user interactive messages of type form, card and custom interactive.

You can also send metadata along with a text, media or custom message. Think, for example, if you want to share the user's location with every message, you can use the metadata field.

## Text Message

*In other words, as a sender, how do I send a text message?*

To send a text message to a single user or group, you need to use the `sendMessage()` method and pass a `TextMessage` object to it.

### Add Metadata

To send custom data along with a text message, you can use the `setMetadata` method and pass a `JSON Object` to it.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    let metadata = {
      latitude: "50.6192171633316",
      longitude: "-72.68182268750002",
    };

    textMessage.setMetadata(metadata);
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    let metadata: Object = {
      latitude: "50.6192171633316",
      longitude: "-72.68182268750002",
    };

    textMessage.setMetadata(metadata);
    ```
  </Tab>
</Tabs>

### Add Tags

To add a tag to a message you can use the `setTags()` method of the TextMessage Class. The `setTags()` method accepts a list of tags.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    let tags = ["starredMessage"];

    textMessage.setTags(tags);
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    let tags: Array<String> = ["starredMessage"];

    textMessage.setTags(tags);
    ```
  </Tab>
</Tabs>

Once the text message object is ready, you need to use the `sendMessage()` method to send the text message to the recipient.

<Tabs>
  <Tab title="To User">
    ```javascript theme={null}
    let receiverID = "UID";
    let messageText = "Hello world!";
    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="To Group">
    ```javascript theme={null}
    let receiverID = "GUID";
    let messageText = "Hello world!";
    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>

  <Tab title="TypeScript (User)">
    ```typescript theme={null}
    let receiverID: string = "UID",
      messageText: string = "Hello world!",
      receiverType: string = CometChat.RECEIVER_TYPE.USER,
      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="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>
</Tabs>

The `TextMessage` class constructor takes the following parameters:

| Parameter        | Description                                                                                 | Required |
| ---------------- | ------------------------------------------------------------------------------------------- | -------- |
| **receiverID**   | `UID` of the user or `GUID` of the group receiving the message                              | YES      |
| **messageText**  | The text message                                                                            | YES      |
| **receiverType** | The type of the receiver- `CometChat.RECEIVER_TYPE.USER` or `CometChat.RECEIVER_TYPE.GROUP` | YES      |

When a text message is sent successfully, the response will include a `TextMessage` object which includes all information related to the sent message.

<Accordion title="Response">
  **On Success** — Returns a TextMessage object:

  <span id="send-text-message-object" style={{scrollMarginTop: '100px'}} />

  **TextMessage Object:**

  | Parameter        | Type    | Description                         | Sample Value                                                     |
  | ---------------- | ------- | ----------------------------------- | ---------------------------------------------------------------- |
  | `id`             | string  | Unique message identifier           | `"25182"`                                                        |
  | `conversationId` | string  | Conversation identifier             | `"cometchat-uid-2_user_cometchat-uid-3"`                         |
  | `text`           | string  | Message text content                | `"Hello world!"`                                                 |
  | `type`           | string  | Message type                        | `"text"`                                                         |
  | `category`       | string  | Message category                    | `"message"`                                                      |
  | `receiverId`     | string  | UID of the receiver                 | `"cometchat-uid-3"`                                              |
  | `receiverType`   | string  | Type of receiver                    | `"user"`                                                         |
  | `sentAt`         | number  | Unix timestamp when sent            | `1771320772`                                                     |
  | `updatedAt`      | number  | Unix timestamp of last update       | `1771320772`                                                     |
  | `sender`         | object  | Sender user details                 | [See below ↓](#send-text-sender-object)                          |
  | `receiver`       | object  | Receiver user details               | [See below ↓](#send-text-receiver-object)                        |
  | `data`           | object  | Additional message data             | [See below ↓](#send-text-data-object)                            |
  | `reactions`      | array   | Message reactions                   | `[]`                                                             |
  | `mentionedUsers` | array   | Users mentioned in message          | `[]`                                                             |
  | `mentionedMe`    | boolean | Whether logged-in user is mentioned | `false`                                                          |
  | `metadata`       | object  | Custom metadata                     | `{"@injected": {"extensions": {"link-preview": {"links": []}}}}` |

  ***

  <span id="send-text-sender-object" style={{scrollMarginTop: '100px'}} />

  **`sender` Object:**

  | Parameter       | Type    | Description                               | Sample Value                                                            |
  | --------------- | ------- | ----------------------------------------- | ----------------------------------------------------------------------- |
  | `uid`           | string  | Unique identifier of the sender           | `"cometchat-uid-2"`                                                     |
  | `name`          | string  | Display name                              | `"George Alan"`                                                         |
  | `avatar`        | string  | URL to avatar image                       | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"` |
  | `status`        | string  | Online status                             | `"online"`                                                              |
  | `role`          | string  | User role                                 | `"default"`                                                             |
  | `lastActiveAt`  | number  | Unix timestamp of last activity           | `1771320632`                                                            |
  | `hasBlockedMe`  | boolean | Whether sender has blocked logged-in user | `false`                                                                 |
  | `blockedByMe`   | boolean | Whether logged-in user has blocked sender | `false`                                                                 |
  | `deactivatedAt` | number  | Deactivation timestamp (0 if active)      | `0`                                                                     |
  | `tags`          | array   | User tags                                 | `[]`                                                                    |

  ***

  <span id="send-text-receiver-object" style={{scrollMarginTop: '100px'}} />

  **`receiver` Object:**

  | Parameter       | Type    | Description                                 | Sample Value                                                            |
  | --------------- | ------- | ------------------------------------------- | ----------------------------------------------------------------------- |
  | `uid`           | string  | Unique identifier of the receiver           | `"cometchat-uid-3"`                                                     |
  | `name`          | string  | Display name                                | `"Nancy Grace"`                                                         |
  | `avatar`        | string  | URL to avatar image                         | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"` |
  | `status`        | string  | Online status                               | `"online"`                                                              |
  | `role`          | string  | User role                                   | `"default"`                                                             |
  | `lastActiveAt`  | number  | Unix timestamp of last activity             | `1771320647`                                                            |
  | `hasBlockedMe`  | boolean | Whether receiver has blocked logged-in user | `false`                                                                 |
  | `blockedByMe`   | boolean | Whether logged-in user has blocked receiver | `false`                                                                 |
  | `deactivatedAt` | number  | Deactivation timestamp (0 if active)        | `0`                                                                     |
  | `tags`          | array   | User tags                                   | `[]`                                                                    |

  ***

  <span id="send-text-data-object" style={{scrollMarginTop: '100px'}} />

  **`data` Object:**

  | Parameter    | Type   | Description                       | Sample Value                                                     |
  | ------------ | ------ | --------------------------------- | ---------------------------------------------------------------- |
  | `text`       | string | Message text                      | `"Hello world!"`                                                 |
  | `resource`   | string | SDK resource identifier           | `"REACT_NATIVE-4_0_13-..."`                                      |
  | `entities`   | object | Sender and receiver entities      | [See below ↓](#send-text-data-entities-object)                   |
  | `metadata`   | object | Injected metadata from extensions | `{"@injected": {"extensions": {"link-preview": {"links": []}}}}` |
  | `moderation` | object | Moderation status                 | [See below ↓](#send-text-data-moderation-object)                 |

  ***

  <span id="send-text-data-entities-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities` Object:**

  | Parameter  | Type   | Description             | Sample Value                                            |
  | ---------- | ------ | ----------------------- | ------------------------------------------------------- |
  | `sender`   | object | Sender entity wrapper   | [See below ↓](#send-text-data-entities-sender-object)   |
  | `receiver` | object | Receiver entity wrapper | [See below ↓](#send-text-data-entities-receiver-object) |

  ***

  <span id="send-text-data-entities-sender-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.sender` Object:**

  | Parameter    | Type   | Description         | Sample Value                                                 |
  | ------------ | ------ | ------------------- | ------------------------------------------------------------ |
  | `entityType` | string | Type of entity      | `"user"`                                                     |
  | `entity`     | object | Sender user details | [See below ↓](#send-text-data-entities-sender-entity-object) |

  ***

  <span id="send-text-data-entities-sender-entity-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.sender.entity` Object:**

  | Parameter      | Type   | Description                     | Sample Value                                                            |
  | -------------- | ------ | ------------------------------- | ----------------------------------------------------------------------- |
  | `uid`          | string | Unique identifier               | `"cometchat-uid-2"`                                                     |
  | `name`         | string | Display name                    | `"George Alan"`                                                         |
  | `avatar`       | string | URL to avatar image             | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"` |
  | `status`       | string | Online status                   | `"online"`                                                              |
  | `role`         | string | User role                       | `"default"`                                                             |
  | `lastActiveAt` | number | Unix timestamp of last activity | `1771320632`                                                            |
  | `tags`         | array  | User tags                       | `[]`                                                                    |

  ***

  <span id="send-text-data-entities-receiver-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.receiver` Object:**

  | Parameter    | Type   | Description           | Sample Value                                                   |
  | ------------ | ------ | --------------------- | -------------------------------------------------------------- |
  | `entityType` | string | Type of entity        | `"user"`                                                       |
  | `entity`     | object | Receiver user details | [See below ↓](#send-text-data-entities-receiver-entity-object) |

  ***

  <span id="send-text-data-entities-receiver-entity-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.receiver.entity` Object:**

  | Parameter        | Type   | Description                     | Sample Value                                                            |
  | ---------------- | ------ | ------------------------------- | ----------------------------------------------------------------------- |
  | `uid`            | string | Unique identifier               | `"cometchat-uid-3"`                                                     |
  | `name`           | string | Display name                    | `"Nancy Grace"`                                                         |
  | `avatar`         | string | URL to avatar image             | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"` |
  | `status`         | string | Online status                   | `"online"`                                                              |
  | `role`           | string | User role                       | `"default"`                                                             |
  | `lastActiveAt`   | number | Unix timestamp of last activity | `1771320647`                                                            |
  | `conversationId` | string | Conversation identifier         | `"cometchat-uid-2_user_cometchat-uid-3"`                                |
  | `tags`           | array  | User tags                       | `[]`                                                                    |

  ***

  <span id="send-text-data-moderation-object" style={{scrollMarginTop: '100px'}} />

  **`data.moderation` Object:**

  | Parameter | Type   | Description       | Sample Value |
  | --------- | ------ | ----------------- | ------------ |
  | `status`  | string | Moderation status | `"pending"`  |
</Accordion>

### Set Quoted Message Id

To set a quoted message ID for a message, use the `setQuotedMessageId()` method of the TextMessage class. This method accepts the ID of the message to be quoted.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    textMessage.setQuotedMessageId(10);
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    textMessage.setQuotedMessageId(10);
    ```
  </Tab>
</Tabs>

Once the text message object is ready, you need to use the `sendMessage()` method to send the text message to the recipient.

<Tabs>
  <Tab title="To User">
    ```javascript theme={null}
    let receiverID = "UID";
    let messageText = "Hello world!";
    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="To Group">
    ```javascript theme={null}
    let receiverID = "GUID";
    let messageText = "Hello world!";
    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>

  <Tab title="TypeScript (User)">
    ```typescript theme={null}
    let receiverID: string = "UID",
      messageText: string = "Hello world!",
      receiverType: string = CometChat.RECEIVER_TYPE.USER,
      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="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>
</Tabs>

The `TextMessage` class constructor takes the following parameters:

| Parameter        | Description                                                                                  | Required |
| ---------------- | -------------------------------------------------------------------------------------------- | -------- |
| **receiverID**   | `UID` of the user or `GUID` of the group receiving the message                               | Required |
| **messageText**  | The text message                                                                             | Required |
| **receiverType** | The type of the receiver - `CometChat.RECEIVER_TYPE.USER` or `CometChat.RECEIVER_TYPE.GROUP` | Required |

When a text message is sent successfully, the response will include a `TextMessage` object which includes all information related to the sent message.

## Media Message

*In other words, as a sender, how do I send a media message like photos, videos & files?*

To send a media message to any user or group, you need to use the `sendMediaMessage()` method and pass a `MediaMessage` object to it.

### Add Metadata

To send custom data along with a media message, you can use the `setMetadata` method and pass a `JSON Object` to it.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    let metadata = {
      latitude: "50.6192171633316",
      longitude: "-72.68182268750002",
    };

    mediaMessage.setMetadata(metadata);
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    let metadata: Object = {
      latitude: "50.6192171633316",
      longitude: "-72.68182268750002",
    };

    mediaMessage.setMetadata(metadata);
    ```
  </Tab>
</Tabs>

### Add Caption (Text along with Media Message)

To send a caption with a media message, you can use the `setCaption` method and pass text to it.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    let caption = "Random Caption";

    mediaMessage.setCaption(caption);
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    let caption: string = "Random Caption";

    mediaMessage.setCaption(caption);
    ```
  </Tab>
</Tabs>

### Add Tags

To add a tag to a message you can use the `setTags()` method of the MediaMessage Class. The `setTags()` method accepts a list of tags.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    let tags = ["starredMessage"];

    mediaMessage.setTags(tags);
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    let tags: Array<String> = ["starredMessage"];

    mediaMessage.setTags(tags);
    ```
  </Tab>
</Tabs>

There are 2 ways you can send Media Messages using the CometChat SDK:

### 1. By Providing the File

You can directly share the file object while creating an object of the MediaMessage class. When the media message is sent using the `sendMediaMessage()` method, this file is then uploaded to CometChat servers and the URL of the file is sent in the success response of the `sendMediaMessage()` function.

**Getting the file Object:** You can use different React Native packages for sending media messages. We demonstrate how to send images using CometChat.

```javascript theme={null}
ImagePicker.showImagePicker(options, (response) => {
if (response.didCancel) {
  console.log('User cancelled photo picker');
} else if (response.error) {
  console.log('ImagePicker Error: ', response.error);
} else if (response.customButton) {
  console.log('User tapped custom button: ', response.customButton);
} else {
  console.log('ImagePicker Response: ', response);
  if (Platform.OS === 'ios' && response.fileName != undefined) {
    var ext = response.fileName.split('.')[1].toLowerCase();
    var type = this.getMimeType(ext);
    var name = response.fileName;
  } else {
    var type = response.type;
    var name = 'Camera_001.jpeg';
  }
  var file = {
    name: Platform.OS === "android" ? response.fileName : name,
    type: Platform.OS === "android" ? response.type : type,
    uri: Platform.OS === "android" ? response.uri : response.uri.replace("file://", ""),
  }
  console.log('file: ', file);
  this.setState({ mediaMsg: file })
}
});
}
```

<Tabs>
  <Tab title="To User">
    ```javascript theme={null}
    let receiverID = "UID";
    let messageType = CometChat.MESSAGE_TYPE.FILE;
    let receiverType = CometChat.RECEIVER_TYPE.USER;
    let mediaMessage = new CometChat.MediaMessage(
      receiverID,
      this.state.mediaMsg,
      messageType,
      receiverType
    );

    CometChat.sendMediaMessage(mediaMessage).then(
      (message) => {
        console.log("Media message sent successfully", message);
      },
      (error) => {
        console.log("Media message sending failed with error", error);
      }
    );
    ```
  </Tab>

  <Tab title="To Group">
    ```javascript theme={null}
    let receiverID = "GUID";
    let messageType = CometChat.MESSAGE_TYPE.FILE;
    let receiverType = CometChat.RECEIVER_TYPE.GROUP;
    let mediaMessage = new CometChat.MediaMessage(
      receiverID,
      this.state.mediaMsg,
      messageType,
      receiverType
    );

    CometChat.sendMediaMessage(mediaMessage).then(
      (message) => {
        console.log("Media message sent successfully", message);
      },
      (error) => {
        console.log("Media message sending failed with error", error);
      }
    );
    ```
  </Tab>

  <Tab title="TypeScript (User)">
    ```typescript theme={null}
    let receiverID: string = "UID",
      messageType: string = CometChat.MESSAGE_TYPE.FILE,
      receiverType: string = CometChat.RECEIVER_TYPE.USER,
      mediaMessage: CometChat.MediaMessage = new CometChat.MediaMessage(
        receiverID,
        this.state.mediaMsg,
        messageType,
        receiverType
      );

    CometChat.sendMediaMessage(mediaMessage).then(
      (message: CometChat.MediaMessage) => {
        console.log("Media message sent successfully", message);
      },
      (error: CometChat.CometChatException) => {
        console.log("Media message sending failed with error", error);
      }
    );
    ```
  </Tab>

  <Tab title="TypeScript (Group)">
    ```typescript theme={null}
    let receiverID: string = "GUID",
      messageType: string = CometChat.MESSAGE_TYPE.FILE,
      receiverType: string = CometChat.RECEIVER_TYPE.GROUP,
      mediaMessage: CometChat.MediaMessage = new CometChat.MediaMessage(
        receiverID,
        this.state.mediaMsg,
        messageType,
        receiverType
      );

    CometChat.sendMediaMessage(mediaMessage).then(
      (message: CometChat.MediaMessage) => {
        console.log("Media message sent successfully", message);
      },
      (error: CometChat.CometChatException) => {
        console.log("Media message sending failed with error", error);
      }
    );
    ```
  </Tab>
</Tabs>

The `MediaMessage` class constructor takes the following parameters:

| Parameter        | Description                                                                                                                                                                                                                         | Required |
| ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
| **receiverId**   | The `UID` or `GUID` of the recipient.                                                                                                                                                                                               | YES      |
| **file**         | The file object to be sent                                                                                                                                                                                                          | YES      |
| **messageType**  | The type of the message that needs to be sent which in this case can be: <br />1.`CometChat.MESSAGE_TYPE.IMAGE` <br />2.`CometChat.MESSAGE_TYPE.VIDEO` <br />3.`CometChat.MESSAGE_TYPE.AUDIO` <br />4.`CometChat.MESSAGE_TYPE.FILE` | YES      |
| **receiverType** | The type of the receiver to whom the message is to be sent. <br />`1. CometChat.RECEIVER_TYPE.USER` <br />`2. CometChat.RECEIVER_TYPE.GROUP`                                                                                        | YES      |

<Accordion title="Response">
  **On Success** — Returns a MediaMessage object:

  <span id="send-media-file-message-object" style={{scrollMarginTop: '100px'}} />

  **MediaMessage Object:**

  | Parameter        | Type    | Description                         | Sample Value                                    |
  | ---------------- | ------- | ----------------------------------- | ----------------------------------------------- |
  | `id`             | string  | Unique message identifier           | `"25189"`                                       |
  | `conversationId` | string  | Conversation identifier             | `"cometchat-uid-2_user_cometchat-uid-3"`        |
  | `type`           | string  | Media type                          | `"image"`                                       |
  | `category`       | string  | Message category                    | `"message"`                                     |
  | `receiverId`     | string  | UID of the receiver                 | `"cometchat-uid-3"`                             |
  | `receiverType`   | string  | Type of receiver                    | `"user"`                                        |
  | `sentAt`         | number  | Unix timestamp when sent            | `1771323061`                                    |
  | `updatedAt`      | number  | Unix timestamp of last update       | `1771323061`                                    |
  | `sender`         | object  | Sender user details                 | [See below ↓](#send-media-file-sender-object)   |
  | `receiver`       | object  | Receiver user details               | [See below ↓](#send-media-file-receiver-object) |
  | `data`           | object  | Additional message data             | [See below ↓](#send-media-file-data-object)     |
  | `reactions`      | array   | Message reactions                   | `[]`                                            |
  | `mentionedUsers` | array   | Users mentioned in message          | `[]`                                            |
  | `mentionedMe`    | boolean | Whether logged-in user is mentioned | `false`                                         |

  ***

  <span id="send-media-file-sender-object" style={{scrollMarginTop: '100px'}} />

  **`sender` Object:**

  | Parameter       | Type    | Description                               | Sample Value                                                            |
  | --------------- | ------- | ----------------------------------------- | ----------------------------------------------------------------------- |
  | `uid`           | string  | Unique identifier of the sender           | `"cometchat-uid-2"`                                                     |
  | `name`          | string  | Display name                              | `"George Alan"`                                                         |
  | `avatar`        | string  | URL to avatar image                       | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"` |
  | `status`        | string  | Online status                             | `"online"`                                                              |
  | `role`          | string  | User role                                 | `"default"`                                                             |
  | `lastActiveAt`  | number  | Unix timestamp of last activity           | `1771323060`                                                            |
  | `hasBlockedMe`  | boolean | Whether sender has blocked logged-in user | `false`                                                                 |
  | `blockedByMe`   | boolean | Whether logged-in user has blocked sender | `false`                                                                 |
  | `deactivatedAt` | number  | Deactivation timestamp (0 if active)      | `0`                                                                     |
  | `tags`          | array   | User tags                                 | `[]`                                                                    |

  ***

  <span id="send-media-file-receiver-object" style={{scrollMarginTop: '100px'}} />

  **`receiver` Object:**

  | Parameter       | Type    | Description                                 | Sample Value                                                            |
  | --------------- | ------- | ------------------------------------------- | ----------------------------------------------------------------------- |
  | `uid`           | string  | Unique identifier of the receiver           | `"cometchat-uid-3"`                                                     |
  | `name`          | string  | Display name                                | `"Nancy Grace"`                                                         |
  | `avatar`        | string  | URL to avatar image                         | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"` |
  | `status`        | string  | Online status                               | `"offline"`                                                             |
  | `role`          | string  | User role                                   | `"default"`                                                             |
  | `lastActiveAt`  | number  | Unix timestamp of last activity             | `1771322968`                                                            |
  | `hasBlockedMe`  | boolean | Whether receiver has blocked logged-in user | `false`                                                                 |
  | `blockedByMe`   | boolean | Whether logged-in user has blocked receiver | `false`                                                                 |
  | `deactivatedAt` | number  | Deactivation timestamp (0 if active)        | `0`                                                                     |
  | `tags`          | array   | User tags                                   | `[]`                                                                    |

  ***

  <span id="send-media-file-data-object" style={{scrollMarginTop: '100px'}} />

  **`data` Object:**

  | Parameter     | Type   | Description                    | Sample Value                                                              |
  | ------------- | ------ | ------------------------------ | ------------------------------------------------------------------------- |
  | `type`        | string | Media type                     | `"image"`                                                                 |
  | `category`    | string | Message category               | `"message"`                                                               |
  | `url`         | string | URL to the uploaded media file | `"https://data-in.cometchat.io/.../c35f9734fc20947b7456bbea68126f99.png"` |
  | `resource`    | string | SDK resource identifier        | `"REACT_NATIVE-4_0_14-..."`                                               |
  | `attachments` | array  | Media attachments              | [See below ↓](#send-media-file-data-attachments-array)                    |
  | `entities`    | object | Sender and receiver entities   | [See below ↓](#send-media-file-data-entities-object)                      |
  | `moderation`  | object | Moderation status              | `{"status": "pending"}`                                                   |

  ***

  <span id="send-media-file-data-attachments-array" style={{scrollMarginTop: '100px'}} />

  **`data.attachments` Array (per item):**

  | Parameter   | Type   | Description           | Sample Value                                                              |
  | ----------- | ------ | --------------------- | ------------------------------------------------------------------------- |
  | `url`       | string | URL to the attachment | `"https://data-in.cometchat.io/.../c35f9734fc20947b7456bbea68126f99.png"` |
  | `name`      | string | File name             | `"1770616246_260562078_3832605b5c8a337ac672b0c60933d208.png"`             |
  | `mimeType`  | string | MIME type             | `"image/png"`                                                             |
  | `extension` | string | File extension        | `"png"`                                                                   |
  | `size`      | number | File size in bytes    | `2295572`                                                                 |

  ***

  <span id="send-media-file-data-entities-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities` Object:**

  | Parameter  | Type   | Description             | Sample Value                                                  |
  | ---------- | ------ | ----------------------- | ------------------------------------------------------------- |
  | `sender`   | object | Sender entity wrapper   | [See below ↓](#send-media-file-data-entities-sender-object)   |
  | `receiver` | object | Receiver entity wrapper | [See below ↓](#send-media-file-data-entities-receiver-object) |

  ***

  <span id="send-media-file-data-entities-sender-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.sender` Object:**

  | Parameter    | Type   | Description         | Sample Value                                                       |
  | ------------ | ------ | ------------------- | ------------------------------------------------------------------ |
  | `entityType` | string | Type of entity      | `"user"`                                                           |
  | `entity`     | object | Sender user details | [See below ↓](#send-media-file-data-entities-sender-entity-object) |

  ***

  <span id="send-media-file-data-entities-sender-entity-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.sender.entity` Object:**

  | Parameter      | Type   | Description                     | Sample Value                                                            |
  | -------------- | ------ | ------------------------------- | ----------------------------------------------------------------------- |
  | `uid`          | string | Unique identifier               | `"cometchat-uid-2"`                                                     |
  | `name`         | string | Display name                    | `"George Alan"`                                                         |
  | `avatar`       | string | URL to avatar image             | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"` |
  | `status`       | string | Online status                   | `"online"`                                                              |
  | `role`         | string | User role                       | `"default"`                                                             |
  | `lastActiveAt` | number | Unix timestamp of last activity | `1771323060`                                                            |
  | `tags`         | array  | User tags                       | `[]`                                                                    |

  ***

  <span id="send-media-file-data-entities-receiver-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.receiver` Object:**

  | Parameter    | Type   | Description           | Sample Value                                                         |
  | ------------ | ------ | --------------------- | -------------------------------------------------------------------- |
  | `entityType` | string | Type of entity        | `"user"`                                                             |
  | `entity`     | object | Receiver user details | [See below ↓](#send-media-file-data-entities-receiver-entity-object) |

  ***

  <span id="send-media-file-data-entities-receiver-entity-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.receiver.entity` Object:**

  | Parameter        | Type   | Description                     | Sample Value                                                            |
  | ---------------- | ------ | ------------------------------- | ----------------------------------------------------------------------- |
  | `uid`            | string | Unique identifier               | `"cometchat-uid-3"`                                                     |
  | `name`           | string | Display name                    | `"Nancy Grace"`                                                         |
  | `avatar`         | string | URL to avatar image             | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"` |
  | `status`         | string | Online status                   | `"offline"`                                                             |
  | `role`           | string | User role                       | `"default"`                                                             |
  | `lastActiveAt`   | number | Unix timestamp of last activity | `1771322968`                                                            |
  | `conversationId` | string | Conversation identifier         | `"cometchat-uid-2_user_cometchat-uid-3"`                                |
  | `tags`           | array  | User tags                       | `[]`                                                                    |
</Accordion>

### 2. By Providing the URL of the File

The second way to send media messages using the CometChat SDK is to provide the SDK with the URL of any file that is hosted on your servers or any cloud storage. To achieve this you will have to make use of the Attachment class. For more information, you can refer to the below code snippet:

<Tabs>
  <Tab title="To User">
    ```javascript theme={null}
    let receiverID = "cometchat-uid-2";
    let messageType = CometChat.MESSAGE_TYPE.IMAGE;
    let receiverType = CometChat.RECEIVER_TYPE.USER;
    let mediaMessage = new CometChat.MediaMessage(
      receiverID,
      "",
      messageType,
      receiverType
    );

    let file = {
      name: "mario",
      extension: "png",
      mimeType: "image/png",
      url: "https://pngimg.com/uploads/mario/mario_PNG125.png",
    };

    let attachment = new CometChat.Attachment(file);
    mediaMessage.setAttachment(attachment);

    CometChat.sendMediaMessage(mediaMessage).then(
      (mediaMessage) => {
        console.log("message", mediaMessage);
      },
      (error) => {
        console.log("error in sending message", error);
      }
    );
    ```
  </Tab>

  <Tab title="To Group">
    ```javascript theme={null}
    let receiverID = "cometchat-guid-1";
    let messageType = CometChat.MESSAGE_TYPE.IMAGE;
    let receiverType = CometChat.RECEIVER_TYPE.GROUP;
    let mediaMessage = new CometChat.MediaMessage(
      receiverID,
      "",
      messageType,
      receiverType
    );

    let file = {
      name: "mario",
      extension: "png",
      mimeType: "image/png",
      url: "https://pngimg.com/uploads/mario/mario_PNG125.png",
    };

    let attachment = new CometChat.Attachment(file);
    mediaMessage.setAttachment(attachment);

    CometChat.sendMediaMessage(mediaMessage).then(
      (mediaMessage) => {
        console.log("message", mediaMessage);
      },
      (error) => {
        console.log("error in sending message", error);
      }
    );
    ```
  </Tab>

  <Tab title="TypeScript (User)">
    ```typescript theme={null}
    let receiverID: string = "cometchat-uid-2",
      messageType: string = CometChat.MESSAGE_TYPE.IMAGE,
      receiverType: string = CometChat.RECEIVER_TYPE.USER,
      mediaMessage: CometChat.MediaMessage = new CometChat.MediaMessage(
        receiverID,
        "",
        messageType,
        receiverType
      );

    let file: Object = {
      name: "mario",
      extension: "png",
      mimeType: "image/png",
      url: "https://pngimg.com/uploads/mario/mario_PNG125.png",
    };

    let attachment: CometChat.Attachment = new CometChat.Attachment(file);
    mediaMessage.setAttachment(attachment);

    CometChat.sendMediaMessage(mediaMessage).then(
      (mediaMessage: CometChat.MediaMessage) => {
        console.log("message", mediaMessage);
      },
      (error: CometChat.CometChatException) => {
        console.log("error in sending message", error);
      }
    );
    ```
  </Tab>

  <Tab title="TypeScript (Group)">
    ```typescript theme={null}
    let receiverID: string = "cometchat-guid-1",
      messageType: string = CometChat.MESSAGE_TYPE.IMAGE,
      receiverType: string = CometChat.RECEIVER_TYPE.GROUP,
      mediaMessage: CometChat.MediaMessage = new CometChat.MediaMessage(
        receiverID,
        "",
        messageType,
        receiverType
      );

    let file: Object = {
      name: "mario",
      extension: "png",
      mimeType: "image/png",
      url: "https://pngimg.com/uploads/mario/mario_PNG125.png",
    };

    let attachment: CometChat.Attachment = new CometChat.Attachment(file);
    mediaMessage.setAttachment(attachment);

    CometChat.sendMediaMessage(mediaMessage).then(
      (mediaMessage: CometChat.MediaMessage) => {
        console.log("message", mediaMessage);
      },
      (error: CometChat.CometChatException) => {
        console.log("error in sending message", error);
      }
    );
    ```
  </Tab>
</Tabs>

When a media message is sent successfully, the response will include a `MediaMessage` object which includes all information related to the sent message.

<Accordion title="Response">
  **On Success** — Returns a MediaMessage object:

  <span id="send-media-url-message-object" style={{scrollMarginTop: '100px'}} />

  **MediaMessage Object:**

  | Parameter        | Type    | Description                         | Sample Value                                   |
  | ---------------- | ------- | ----------------------------------- | ---------------------------------------------- |
  | `id`             | string  | Unique message identifier           | `"25189"`                                      |
  | `conversationId` | string  | Conversation identifier             | `"cometchat-uid-2_user_cometchat-uid-3"`       |
  | `type`           | string  | Media type                          | `"image"`                                      |
  | `category`       | string  | Message category                    | `"message"`                                    |
  | `receiverId`     | string  | UID of the receiver                 | `"cometchat-uid-3"`                            |
  | `receiverType`   | string  | Type of receiver                    | `"user"`                                       |
  | `sentAt`         | number  | Unix timestamp when sent            | `1771323061`                                   |
  | `updatedAt`      | number  | Unix timestamp of last update       | `1771323061`                                   |
  | `sender`         | object  | Sender user details                 | [See below ↓](#send-media-url-sender-object)   |
  | `receiver`       | object  | Receiver user details               | [See below ↓](#send-media-url-receiver-object) |
  | `data`           | object  | Additional message data             | [See below ↓](#send-media-url-data-object)     |
  | `reactions`      | array   | Message reactions                   | `[]`                                           |
  | `mentionedUsers` | array   | Users mentioned in message          | `[]`                                           |
  | `mentionedMe`    | boolean | Whether logged-in user is mentioned | `false`                                        |

  ***

  <span id="send-media-url-sender-object" style={{scrollMarginTop: '100px'}} />

  **`sender` Object:**

  | Parameter       | Type    | Description                               | Sample Value                                                            |
  | --------------- | ------- | ----------------------------------------- | ----------------------------------------------------------------------- |
  | `uid`           | string  | Unique identifier of the sender           | `"cometchat-uid-2"`                                                     |
  | `name`          | string  | Display name                              | `"George Alan"`                                                         |
  | `avatar`        | string  | URL to avatar image                       | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"` |
  | `status`        | string  | Online status                             | `"online"`                                                              |
  | `role`          | string  | User role                                 | `"default"`                                                             |
  | `lastActiveAt`  | number  | Unix timestamp of last activity           | `1771323060`                                                            |
  | `hasBlockedMe`  | boolean | Whether sender has blocked logged-in user | `false`                                                                 |
  | `blockedByMe`   | boolean | Whether logged-in user has blocked sender | `false`                                                                 |
  | `deactivatedAt` | number  | Deactivation timestamp (0 if active)      | `0`                                                                     |
  | `tags`          | array   | User tags                                 | `[]`                                                                    |

  ***

  <span id="send-media-url-receiver-object" style={{scrollMarginTop: '100px'}} />

  **`receiver` Object:**

  | Parameter       | Type    | Description                                 | Sample Value                                                            |
  | --------------- | ------- | ------------------------------------------- | ----------------------------------------------------------------------- |
  | `uid`           | string  | Unique identifier of the receiver           | `"cometchat-uid-3"`                                                     |
  | `name`          | string  | Display name                                | `"Nancy Grace"`                                                         |
  | `avatar`        | string  | URL to avatar image                         | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"` |
  | `status`        | string  | Online status                               | `"offline"`                                                             |
  | `role`          | string  | User role                                   | `"default"`                                                             |
  | `lastActiveAt`  | number  | Unix timestamp of last activity             | `1771322968`                                                            |
  | `hasBlockedMe`  | boolean | Whether receiver has blocked logged-in user | `false`                                                                 |
  | `blockedByMe`   | boolean | Whether logged-in user has blocked receiver | `false`                                                                 |
  | `deactivatedAt` | number  | Deactivation timestamp (0 if active)        | `0`                                                                     |
  | `tags`          | array   | User tags                                   | `[]`                                                                    |

  ***

  <span id="send-media-url-data-object" style={{scrollMarginTop: '100px'}} />

  **`data` Object:**

  | Parameter     | Type   | Description                  | Sample Value                                                              |
  | ------------- | ------ | ---------------------------- | ------------------------------------------------------------------------- |
  | `type`        | string | Media type                   | `"image"`                                                                 |
  | `category`    | string | Message category             | `"message"`                                                               |
  | `url`         | string | URL to the media file        | `"https://data-in.cometchat.io/.../c35f9734fc20947b7456bbea68126f99.png"` |
  | `resource`    | string | SDK resource identifier      | `"REACT_NATIVE-4_0_14-..."`                                               |
  | `attachments` | array  | Media attachments            | [See below ↓](#send-media-url-data-attachments-array)                     |
  | `entities`    | object | Sender and receiver entities | [See below ↓](#send-media-url-data-entities-object)                       |
  | `moderation`  | object | Moderation status            | `{"status": "pending"}`                                                   |

  ***

  <span id="send-media-url-data-attachments-array" style={{scrollMarginTop: '100px'}} />

  **`data.attachments` Array (per item):**

  | Parameter   | Type   | Description           | Sample Value                                          |
  | ----------- | ------ | --------------------- | ----------------------------------------------------- |
  | `url`       | string | URL to the attachment | `"https://pngimg.com/uploads/mario/mario_PNG125.png"` |
  | `name`      | string | File name             | `"mario"`                                             |
  | `mimeType`  | string | MIME type             | `"image/png"`                                         |
  | `extension` | string | File extension        | `"png"`                                               |

  ***

  <span id="send-media-url-data-entities-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities` Object:**

  | Parameter  | Type   | Description             | Sample Value                                                 |
  | ---------- | ------ | ----------------------- | ------------------------------------------------------------ |
  | `sender`   | object | Sender entity wrapper   | [See below ↓](#send-media-url-data-entities-sender-object)   |
  | `receiver` | object | Receiver entity wrapper | [See below ↓](#send-media-url-data-entities-receiver-object) |

  ***

  <span id="send-media-url-data-entities-sender-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.sender` Object:**

  | Parameter    | Type   | Description         | Sample Value                                                      |
  | ------------ | ------ | ------------------- | ----------------------------------------------------------------- |
  | `entityType` | string | Type of entity      | `"user"`                                                          |
  | `entity`     | object | Sender user details | [See below ↓](#send-media-url-data-entities-sender-entity-object) |

  ***

  <span id="send-media-url-data-entities-sender-entity-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.sender.entity` Object:**

  | Parameter      | Type   | Description                     | Sample Value                                                            |
  | -------------- | ------ | ------------------------------- | ----------------------------------------------------------------------- |
  | `uid`          | string | Unique identifier               | `"cometchat-uid-2"`                                                     |
  | `name`         | string | Display name                    | `"George Alan"`                                                         |
  | `avatar`       | string | URL to avatar image             | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"` |
  | `status`       | string | Online status                   | `"online"`                                                              |
  | `role`         | string | User role                       | `"default"`                                                             |
  | `lastActiveAt` | number | Unix timestamp of last activity | `1771323060`                                                            |
  | `tags`         | array  | User tags                       | `[]`                                                                    |

  ***

  <span id="send-media-url-data-entities-receiver-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.receiver` Object:**

  | Parameter    | Type   | Description           | Sample Value                                                        |
  | ------------ | ------ | --------------------- | ------------------------------------------------------------------- |
  | `entityType` | string | Type of entity        | `"user"`                                                            |
  | `entity`     | object | Receiver user details | [See below ↓](#send-media-url-data-entities-receiver-entity-object) |

  ***

  <span id="send-media-url-data-entities-receiver-entity-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.receiver.entity` Object:**

  | Parameter        | Type   | Description                     | Sample Value                                                            |
  | ---------------- | ------ | ------------------------------- | ----------------------------------------------------------------------- |
  | `uid`            | string | Unique identifier               | `"cometchat-uid-3"`                                                     |
  | `name`           | string | Display name                    | `"Nancy Grace"`                                                         |
  | `avatar`         | string | URL to avatar image             | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"` |
  | `status`         | string | Online status                   | `"offline"`                                                             |
  | `role`           | string | User role                       | `"default"`                                                             |
  | `lastActiveAt`   | number | Unix timestamp of last activity | `1771322968`                                                            |
  | `conversationId` | string | Conversation identifier         | `"cometchat-uid-2_user_cometchat-uid-3"`                                |
  | `tags`           | array  | User tags                       | `[]`                                                                    |
</Accordion>

## Multiple Attachments in a Media Message

Starting version 3.0.9 & above the SDK supports sending multiple attachments in a single media message. As in the case of a single attachment in a media message, there are two ways you can send Media Messages using the CometChat SDK:

### 1. By Providing an Array of Files

You can now share an array of files while creating an object of the MediaMessage class. When the media message is sent using the `sendMediaMessage()` method, the files are uploaded to the CometChat servers & the URL of the files is sent in the success response of the `sendMediaMessage()` method.

**Getting the file Object:** You can use different React Native packages for sending media messages. We demonstrate how to send images using CometChat.

```javascript theme={null}
let options = {
    selectionLimit: 0
};
ImagePicker.showImagePicker(options, (response) => {
if (response.didCancel) {
  console.log('User cancelled photo picker');
} else if (response.error) {
  console.log('ImagePicker Error: ', response.error);
} else if (response.customButton) {
  console.log('User tapped custom button: ', response.customButton);
} else {
  console.log('ImagePicker Response: ', response);
  let files = response.assets;
  let allFiles = [];
  if (files && files.length > 0) {
      console.log("files", files);
      files.forEach(file => {
          if (Platform.OS === 'ios' && file.fileName !== undefined) {
              name = file.fileName;
              type = file.type;
          } else {
              type = file.type;
              name = 'Camera_001.jpeg';
          }
          if (mediaType == 'video') {
              type = 'video/quicktime';
              name = 'Camera_002.mov';
          }
          let tempFile = {
              name: name,
              type:
                  Platform.OS === 'android' && mediaType != 'video'
                      ? file.type
                      : type,
              uri:
                  Platform.OS === 'android'
                      ? file.uri
                      : file.uri.replace('file://', ''),
              size: file.fileSize
          };
          allFiles.push(tempFile);
      });
      this.props.sendMediaMessage(
          allFiles,
          mediaType === 'photo'
              ? CometChat.MESSAGE_TYPE.IMAGE
              : CometChat.MESSAGE_TYPE.VIDEO,
      );
  }
}
});
}
```

<Tabs>
  <Tab title="To User">
    ```javascript theme={null}
    let receiverID = "UID";
    let messageType = CometChat.MESSAGE_TYPE.FILE;
    let receiverType = CometChat.RECEIVER_TYPE.USER;
    let mediaMessage = new CometChat.MediaMessage(
      receiverID,
      files,
      messageType,
      receiverType
    );

    CometChat.sendMediaMessage(mediaMessage).then(
      (message) => {
        console.log("Media message sent successfully", message);
      },
      (error) => {
        console.log("Media message sending failed with error", error);
      }
    );
    ```
  </Tab>

  <Tab title="To Group">
    ```javascript theme={null}
    let receiverID = "GUID";
    let messageType = CometChat.MESSAGE_TYPE.FILE;
    let receiverType = CometChat.RECEIVER_TYPE.GROUP;
    let mediaMessage = new CometChat.MediaMessage(
      receiverID,
      this.state.mediaMsg,
      messageType,
      receiverType
    );

    CometChat.sendMediaMessage(mediaMessage).then(
      (message) => {
        console.log("Media message sent successfully", message);
      },
      (error) => {
        console.log("Media message sending failed with error", error);
      }
    );
    ```
  </Tab>

  <Tab title="TypeScript (User)">
    ```typescript theme={null}
    let receiverID: string = "UID",
      messageType: string = CometChat.MESSAGE_TYPE.FILE,
      receiverType: string = CometChat.RECEIVER_TYPE.USER,
      mediaMessage: CometChat.MediaMessage = new CometChat.MediaMessage(
        receiverID,
        this.state.mediaMsg,
        messageType,
        receiverType
      );

    CometChat.sendMediaMessage(mediaMessage).then(
      (message: CometChat.MediaMessage) => {
        console.log("Media message sent successfully", message);
      },
      (error: CometChat.CometChatException) => {
        console.log("Media message sending failed with error", error);
      }
    );
    ```
  </Tab>

  <Tab title="TypeScript (Group)">
    ```typescript theme={null}
    let receiverID: string = "GUID",
      messageType: string = CometChat.MESSAGE_TYPE.FILE,
      receiverType: string = CometChat.RECEIVER_TYPE.GROUP,
      mediaMessage: CometChat.MediaMessage = new CometChat.MediaMessage(
        receiverID,
        this.state.mediaMsg,
        messageType,
        receiverType
      );

    CometChat.sendMediaMessage(mediaMessage).then(
      (message: CometChat.MediaMessage) => {
        console.log("Media message sent successfully", message);
      },
      (error: CometChat.CometChatException) => {
        console.log("Media message sending failed with error", error);
      }
    );
    ```
  </Tab>
</Tabs>

The `MediaMessage` class constructor takes the following parameters:

| Parameter        | Description                                                                                                                                                                                                                         |
| ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **receiverId**   | The `UID` or `GUID` of the recipient.                                                                                                                                                                                               |
| **files**        | An array of files.                                                                                                                                                                                                                  |
| **messageType**  | The type of the message that needs to be sent which in this case can be: <br />1.`CometChat.MESSAGE_TYPE.IMAGE` <br />2.`CometChat.MESSAGE_TYPE.VIDEO` <br />3.`CometChat.MESSAGE_TYPE.AUDIO` <br />4.`CometChat.MESSAGE_TYPE.FILE` |
| **receiverType** | The type of the receiver to whom the message is to be sent. <br />`1. CometChat.RECEIVER_TYPE.USER`<br />`2. CometChat.RECEIVER_TYPE.GROUP`                                                                                         |

### 2. By Providing the URL of Multiple Files

The second way to send multiple attachments in a single media message using the CometChat SDK is to provide the SDK with the URL of multiple files that are hosted on your servers or any cloud storage. To achieve this you will have to make use of the Attachment class. For more information, you can refer to the below code snippet:

<Tabs>
  <Tab title="To User">
    ```javascript theme={null}
    let receiverID = "cometchat-uid-2";
    let messageType = CometChat.MESSAGE_TYPE.IMAGE;
    let receiverType = CometChat.RECEIVER_TYPE.USER;
    let mediaMessage = new CometChat.MediaMessage(
      receiverID,
      "",
      messageType,
      receiverType
    );

    let attachment1 = {
      name: "mario",
      extension: "png",
      mimeType: "image/png",
      url: "https://pngimg.com/uploads/mario/mario_PNG125.png",
    };

    let attachment2 = {
      name: "jaguar",
      extension: "png",
      mimeType: "image/png",
      url: "https://pngimg.com/uploads/jaguar/jaguar_PNG20759.png",
    };

    let attachments = [];
    attachments.push(new CometChat.Attachment(attachment1));
    attachments.push(new CometChat.Attachment(attachment2));

    mediaMessage.setAttachments(attachments);

    CometChat.sendMediaMessage(mediaMessage).then(
      (mediaMessage) => {
        console.log("message", mediaMessage);
      },
      (error) => {
        console.log("error in sending message", error);
      }
    );
    ```
  </Tab>

  <Tab title="To Group">
    ```javascript theme={null}
    let receiverID = "cometchat-guid-1";
    let messageType = CometChat.MESSAGE_TYPE.IMAGE;
    let receiverType = CometChat.RECEIVER_TYPE.GROUP;
    let mediaMessage = new CometChat.MediaMessage(
      receiverID,
      "",
      messageType,
      receiverType
    );

    let attachment1 = {
      name: "mario",
      extension: "png",
      mimeType: "image/png",
      url: "https://pngimg.com/uploads/mario/mario_PNG125.png",
    };

    let attachment2 = {
      name: "jaguar",
      extension: "png",
      mimeType: "image/png",
      url: "https://pngimg.com/uploads/jaguar/jaguar_PNG20759.png",
    };

    let attachments = [];
    attachments.push(new CometChat.Attachment(attachment1));
    attachments.push(new CometChat.Attachment(attachment2));

    mediaMessage.setAttachments(attachments);

    CometChat.sendMediaMessage(mediaMessage).then(
      (mediaMessage) => {
        console.log("message", mediaMessage);
      },
      (error) => {
        console.log("error in sending message", error);
      }
    );
    ```
  </Tab>

  <Tab title="TypeScript (User)">
    ```typescript theme={null}
    let receiverID: string = "cometchat-uid-2",
      messageType: string = CometChat.MESSAGE_TYPE.IMAGE,
      receiverType: string = CometChat.RECEIVER_TYPE.USER,
      mediaMessage: CometChat.MediaMessage = new CometChat.MediaMessage(
        receiverID,
        "",
        messageType,
        receiverType
      );

    let attachment1: Object = {
      name: "mario",
      extension: "png",
      mimeType: "image/png",
      url: "https://pngimg.com/uploads/mario/mario_PNG125.png",
    };

    let attachment2: Object = {
      name: "jaguar",
      extension: "png",
      mimeType: "image/png",
      url: "https://pngimg.com/uploads/jaguar/jaguar_PNG20759.png",
    };

    let attachments: Array<CometChat.Attachment> = [];
    attachments.push(new CometChat.Attachment(attachment1));
    attachments.push(new CometChat.Attachment(attachment2));

    mediaMessage.setAttachments(attachments);

    CometChat.sendMediaMessage(mediaMessage).then(
      (mediaMessage: CometChat.MediaMessage) => {
        console.log("message", mediaMessage);
      },
      (error: CometChat.CometChatException) => {
        console.log("error in sending message", error);
      }
    );
    ```
  </Tab>

  <Tab title="TypeScript (Group)">
    ```typescript theme={null}
    let receiverID: string = "cometchat-guid-1",
      messageType: string = CometChat.MESSAGE_TYPE.IMAGE,
      receiverType: string = CometChat.RECEIVER_TYPE.GROUP,
      mediaMessage: CometChat.MediaMessage = new CometChat.MediaMessage(
        receiverID,
        "",
        messageType,
        receiverType
      );

    let attachment1: Object = {
      name: "mario",
      extension: "png",
      mimeType: "image/png",
      url: "https://pngimg.com/uploads/mario/mario_PNG125.png",
    };

    let attachment2: Object = {
      name: "jaguar",
      extension: "png",
      mimeType: "image/png",
      url: "https://pngimg.com/uploads/jaguar/jaguar_PNG20759.png",
    };

    let attachments: Array<CometChat.Attachment> = [];
    attachments.push(new CometChat.Attachment(attachment1));
    attachments.push(new CometChat.Attachment(attachment2));

    mediaMessage.setAttachments(attachments);

    CometChat.sendMediaMessage(mediaMessage).then(
      (mediaMessage: CometChat.MediaMessage) => {
        console.log("message", mediaMessage);
      },
      (error: CometChat.CometChatException) => {
        console.log("error in sending message", error);
      }
    );
    ```
  </Tab>
</Tabs>

When a media message is sent successfully, the response will include a `MediaMessage` object which includes all information related to the sent message.

You can use the `setMetadata()`, `setCaption()` & `setTags()` methods to add metadata, caption and tags respectively in exactly the same way as it is done while sending a single file or attachment in a Media Message.

<Accordion title="Response">
  **On Success** — Returns a MediaMessage object with multiple attachments:

  <span id="send-multi-attach-message-object" style={{scrollMarginTop: '100px'}} />

  **MediaMessage Object:**

  | Parameter        | Type    | Description                         | Sample Value                                      |
  | ---------------- | ------- | ----------------------------------- | ------------------------------------------------- |
  | `id`             | string  | Unique message identifier           | `"25189"`                                         |
  | `conversationId` | string  | Conversation identifier             | `"cometchat-uid-2_user_cometchat-uid-3"`          |
  | `type`           | string  | Media type                          | `"image"`                                         |
  | `category`       | string  | Message category                    | `"message"`                                       |
  | `receiverId`     | string  | UID of the receiver                 | `"cometchat-uid-3"`                               |
  | `receiverType`   | string  | Type of receiver                    | `"user"`                                          |
  | `sentAt`         | number  | Unix timestamp when sent            | `1771323061`                                      |
  | `updatedAt`      | number  | Unix timestamp of last update       | `1771323061`                                      |
  | `sender`         | object  | Sender user details                 | [See below ↓](#send-multi-attach-sender-object)   |
  | `receiver`       | object  | Receiver user details               | [See below ↓](#send-multi-attach-receiver-object) |
  | `data`           | object  | Additional message data             | [See below ↓](#send-multi-attach-data-object)     |
  | `reactions`      | array   | Message reactions                   | `[]`                                              |
  | `mentionedUsers` | array   | Users mentioned in message          | `[]`                                              |
  | `mentionedMe`    | boolean | Whether logged-in user is mentioned | `false`                                           |

  ***

  <span id="send-multi-attach-sender-object" style={{scrollMarginTop: '100px'}} />

  **`sender` Object:**

  | Parameter       | Type    | Description                               | Sample Value                                                            |
  | --------------- | ------- | ----------------------------------------- | ----------------------------------------------------------------------- |
  | `uid`           | string  | Unique identifier of the sender           | `"cometchat-uid-2"`                                                     |
  | `name`          | string  | Display name                              | `"George Alan"`                                                         |
  | `avatar`        | string  | URL to avatar image                       | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"` |
  | `status`        | string  | Online status                             | `"online"`                                                              |
  | `role`          | string  | User role                                 | `"default"`                                                             |
  | `lastActiveAt`  | number  | Unix timestamp of last activity           | `1771323060`                                                            |
  | `hasBlockedMe`  | boolean | Whether sender has blocked logged-in user | `false`                                                                 |
  | `blockedByMe`   | boolean | Whether logged-in user has blocked sender | `false`                                                                 |
  | `deactivatedAt` | number  | Deactivation timestamp (0 if active)      | `0`                                                                     |
  | `tags`          | array   | User tags                                 | `[]`                                                                    |

  ***

  <span id="send-multi-attach-receiver-object" style={{scrollMarginTop: '100px'}} />

  **`receiver` Object:**

  | Parameter       | Type    | Description                                 | Sample Value                                                            |
  | --------------- | ------- | ------------------------------------------- | ----------------------------------------------------------------------- |
  | `uid`           | string  | Unique identifier of the receiver           | `"cometchat-uid-3"`                                                     |
  | `name`          | string  | Display name                                | `"Nancy Grace"`                                                         |
  | `avatar`        | string  | URL to avatar image                         | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"` |
  | `status`        | string  | Online status                               | `"offline"`                                                             |
  | `role`          | string  | User role                                   | `"default"`                                                             |
  | `lastActiveAt`  | number  | Unix timestamp of last activity             | `1771322968`                                                            |
  | `hasBlockedMe`  | boolean | Whether receiver has blocked logged-in user | `false`                                                                 |
  | `blockedByMe`   | boolean | Whether logged-in user has blocked receiver | `false`                                                                 |
  | `deactivatedAt` | number  | Deactivation timestamp (0 if active)        | `0`                                                                     |
  | `tags`          | array   | User tags                                   | `[]`                                                                    |

  ***

  <span id="send-multi-attach-data-object" style={{scrollMarginTop: '100px'}} />

  **`data` Object:**

  | Parameter     | Type   | Description                   | Sample Value                                                              |
  | ------------- | ------ | ----------------------------- | ------------------------------------------------------------------------- |
  | `type`        | string | Media type                    | `"image"`                                                                 |
  | `category`    | string | Message category              | `"message"`                                                               |
  | `url`         | string | URL to the primary media file | `"https://data-in.cometchat.io/.../c35f9734fc20947b7456bbea68126f99.png"` |
  | `resource`    | string | SDK resource identifier       | `"REACT_NATIVE-4_0_14-..."`                                               |
  | `attachments` | array  | Media attachments             | [See below ↓](#send-multi-attach-data-attachments-array)                  |
  | `entities`    | object | Sender and receiver entities  | [See below ↓](#send-multi-attach-data-entities-object)                    |
  | `moderation`  | object | Moderation status             | `{"status": "pending"}`                                                   |

  ***

  <span id="send-multi-attach-data-attachments-array" style={{scrollMarginTop: '100px'}} />

  **`data.attachments` Array (per item):**

  | Parameter   | Type   | Description           | Sample Value                                          |
  | ----------- | ------ | --------------------- | ----------------------------------------------------- |
  | `url`       | string | URL to the attachment | `"https://pngimg.com/uploads/mario/mario_PNG125.png"` |
  | `name`      | string | File name             | `"mario"`                                             |
  | `mimeType`  | string | MIME type             | `"image/png"`                                         |
  | `extension` | string | File extension        | `"png"`                                               |

  Example with multiple attachments:

  * Attachment 1: `{"name": "mario", "extension": "png", "mimeType": "image/png", "url": "https://pngimg.com/uploads/mario/mario_PNG125.png"}`
  * Attachment 2: `{"name": "jaguar", "extension": "png", "mimeType": "image/png", "url": "https://pngimg.com/uploads/jaguar/jaguar_PNG20759.png"}`

  ***

  <span id="send-multi-attach-data-entities-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities` Object:**

  | Parameter  | Type   | Description             | Sample Value                                                    |
  | ---------- | ------ | ----------------------- | --------------------------------------------------------------- |
  | `sender`   | object | Sender entity wrapper   | [See below ↓](#send-multi-attach-data-entities-sender-object)   |
  | `receiver` | object | Receiver entity wrapper | [See below ↓](#send-multi-attach-data-entities-receiver-object) |

  ***

  <span id="send-multi-attach-data-entities-sender-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.sender` Object:**

  | Parameter    | Type   | Description         | Sample Value                                                         |
  | ------------ | ------ | ------------------- | -------------------------------------------------------------------- |
  | `entityType` | string | Type of entity      | `"user"`                                                             |
  | `entity`     | object | Sender user details | [See below ↓](#send-multi-attach-data-entities-sender-entity-object) |

  ***

  <span id="send-multi-attach-data-entities-sender-entity-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.sender.entity` Object:**

  | Parameter      | Type   | Description                     | Sample Value                                                            |
  | -------------- | ------ | ------------------------------- | ----------------------------------------------------------------------- |
  | `uid`          | string | Unique identifier               | `"cometchat-uid-2"`                                                     |
  | `name`         | string | Display name                    | `"George Alan"`                                                         |
  | `avatar`       | string | URL to avatar image             | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"` |
  | `status`       | string | Online status                   | `"online"`                                                              |
  | `role`         | string | User role                       | `"default"`                                                             |
  | `lastActiveAt` | number | Unix timestamp of last activity | `1771323060`                                                            |
  | `tags`         | array  | User tags                       | `[]`                                                                    |

  ***

  <span id="send-multi-attach-data-entities-receiver-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.receiver` Object:**

  | Parameter    | Type   | Description           | Sample Value                                                           |
  | ------------ | ------ | --------------------- | ---------------------------------------------------------------------- |
  | `entityType` | string | Type of entity        | `"user"`                                                               |
  | `entity`     | object | Receiver user details | [See below ↓](#send-multi-attach-data-entities-receiver-entity-object) |

  ***

  <span id="send-multi-attach-data-entities-receiver-entity-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.receiver.entity` Object:**

  | Parameter        | Type   | Description                     | Sample Value                                                            |
  | ---------------- | ------ | ------------------------------- | ----------------------------------------------------------------------- |
  | `uid`            | string | Unique identifier               | `"cometchat-uid-3"`                                                     |
  | `name`           | string | Display name                    | `"Nancy Grace"`                                                         |
  | `avatar`         | string | URL to avatar image             | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"` |
  | `status`         | string | Online status                   | `"offline"`                                                             |
  | `role`           | string | User role                       | `"default"`                                                             |
  | `lastActiveAt`   | number | Unix timestamp of last activity | `1771322968`                                                            |
  | `conversationId` | string | Conversation identifier         | `"cometchat-uid-2_user_cometchat-uid-3"`                                |
  | `tags`           | array  | User tags                       | `[]`                                                                    |
</Accordion>

## Custom Message

*In other words, as a sender, how do I send a custom message like location coordinates?*

CometChat allows you to send custom messages which are neither text nor media messages.

In order to send a custom message, you need to use the `sendCustomMessage()` method. The `sendCustomMessage()` method takes an object of the `CustomMessage` which can be obtained using the below constructor.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    let customMessage = new CometChat.CustomMessage(
      receiverID,
      receiverType,
      customType,
      customData
    );
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    let customMessage: CometChat.CustomMessage = new CometChat.CustomMessage(
      receiverID,
      receiverType,
      customType,
      customData
    );
    ```
  </Tab>
</Tabs>

The above constructor helps you create a custom message with the message type set to whatever is passed to the constructor and the category set to `custom`.

The parameters involved are:

| Parameter      | Description                                                           |
| -------------- | --------------------------------------------------------------------- |
| `receiverId`   | The unique ID of the user or group to which the message is to be sent |
| `receiverType` | Type of the receiver i.e user or group                                |
| `customType`   | Custom message type that you need to set                              |
| `customData`   | The data to be passed as the message in the form of a JSON Object     |

You can also use the subType field of the `CustomMessage` class to set a specific type for the custom message. This can be achieved using the `setSubtype()` method.

### Add Tags

To add a tag to a message you can use the `setTags()` method of the CustomMessage Class. The `setTags()` method accepts a list of tags.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    let tags = ["starredMessage"];

    customMessage.setTags(tags);
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    let tags: Array<String> = ["starredMessage"];

    customMessage.setTags(tags);
    ```
  </Tab>
</Tabs>

Once the object of `CustomMessage` class is ready you can send the custom message using the `sendCustomMessage()` method.

<Tabs>
  <Tab title="To User">
    ```javascript theme={null}
    let receiverID = "UID";
    let customData = {
      latitude: "50.6192171633316",
      longitude: "-72.68182268750002",
    };
    let customType = "location";
    let receiverType = CometChat.RECEIVER_TYPE.USER;
    let customMessage = new CometChat.CustomMessage(
      receiverID,
      receiverType,
      customType,
      customData
    );

    CometChat.sendCustomMessage(customMessage).then(
      (message) => {
        console.log("custom message sent successfully", message);
      },
      (error) => {
        console.log("custom message sending failed with error", error);
      }
    );
    ```
  </Tab>

  <Tab title="To Group">
    ```javascript theme={null}
    let receiverID = "GUID";
    let customData = {
      latitude: "50.6192171633316",
      longitude: "-72.68182268750002",
    };
    let customType = "location";
    let receiverType = CometChat.RECEIVER_TYPE.GROUP;
    let customMessage = new CometChat.CustomMessage(
      receiverID,
      receiverType,
      customType,
      customData
    );

    CometChat.sendCustomMessage(customMessage).then(
      (message) => {
        console.log("custom message sent successfully", message);
      },
      (error) => {
        console.log("custom message sending failed with error", error);
      }
    );
    ```
  </Tab>

  <Tab title="TypeScript (User)">
    ```typescript theme={null}
    let receiverID: string = "UID",
      customData: Object = {
        latitude: "50.6192171633316",
        longitude: "-72.68182268750002",
      },
      customType: string = "location",
      receiverType: string = CometChat.RECEIVER_TYPE.USER,
      customMessage: CometChat.CustomMessage = new CometChat.CustomMessage(
        receiverID,
        receiverType,
        customType,
        customData
      );

    CometChat.sendCustomMessage(customMessage).then(
      (message: CometChat.CustomMessage) => {
        console.log("custom message sent successfully", message);
      },
      (error: CometChat.CometChatException) => {
        console.log("custom message sending failed with error", error);
      }
    );
    ```
  </Tab>

  <Tab title="TypeScript (Group)">
    ```typescript theme={null}
    let receiverID: string = "GUID",
      customData: Object = {
        latitude: "50.6192171633316",
        longitude: "-72.68182268750002",
      },
      customType: string = "location",
      receiverType: string = CometChat.RECEIVER_TYPE.GROUP,
      customMessage: CometChat.CustomMessage = new CometChat.CustomMessage(
        receiverID,
        receiverType,
        customType,
        customData
      );

    CometChat.sendCustomMessage(customMessage).then(
      (message: CometChat.CustomMessage) => {
        console.log("custom message sent successfully", message);
      },
      (error: CometChat.CometChatException) => {
        console.log("custom message sending failed with error", error);
      }
    );
    ```
  </Tab>
</Tabs>

The above sample explains how custom messages can be used to share the location with a user. The same can be achieved for groups.

On success, you will receive an object of the `CustomMessage` class.

<Accordion title="Response">
  **On Success** — Returns a CustomMessage object:

  <span id="send-custom-message-object" style={{scrollMarginTop: '100px'}} />

  **CustomMessage Object:**

  | Parameter        | Type    | Description                         | Sample Value                                                     |
  | ---------------- | ------- | ----------------------------------- | ---------------------------------------------------------------- |
  | `id`             | string  | Unique message identifier           | `"25190"`                                                        |
  | `conversationId` | string  | Conversation identifier             | `"cometchat-uid-2_user_cometchat-uid-3"`                         |
  | `type`           | string  | Custom message type                 | `"location"`                                                     |
  | `category`       | string  | Message category                    | `"custom"`                                                       |
  | `receiverId`     | string  | UID of the receiver                 | `"cometchat-uid-3"`                                              |
  | `receiverType`   | string  | Type of receiver                    | `"user"`                                                         |
  | `sentAt`         | number  | Unix timestamp when sent            | `1771323234`                                                     |
  | `updatedAt`      | number  | Unix timestamp of last update       | `1771323234`                                                     |
  | `customData`     | object  | Custom payload data                 | [See below ↓](#send-custom-customdata-object)                    |
  | `sender`         | object  | Sender user details                 | [See below ↓](#send-custom-sender-object)                        |
  | `receiver`       | object  | Receiver user details               | [See below ↓](#send-custom-receiver-object)                      |
  | `data`           | object  | Additional message data             | [See below ↓](#send-custom-data-object)                          |
  | `reactions`      | array   | Message reactions                   | `[]`                                                             |
  | `mentionedUsers` | array   | Users mentioned in message          | `[]`                                                             |
  | `mentionedMe`    | boolean | Whether logged-in user is mentioned | `false`                                                          |
  | `metadata`       | object  | Custom metadata                     | `{"@injected": {"extensions": {"link-preview": {"links": []}}}}` |

  ***

  <span id="send-custom-customdata-object" style={{scrollMarginTop: '100px'}} />

  **`customData` Object:**

  | Parameter   | Type   | Description          | Sample Value           |
  | ----------- | ------ | -------------------- | ---------------------- |
  | `latitude`  | string | Latitude coordinate  | `"50.6192171633316"`   |
  | `longitude` | string | Longitude coordinate | `"-72.68182268750002"` |

  ***

  <span id="send-custom-sender-object" style={{scrollMarginTop: '100px'}} />

  **`sender` Object:**

  | Parameter       | Type    | Description                               | Sample Value                                                            |
  | --------------- | ------- | ----------------------------------------- | ----------------------------------------------------------------------- |
  | `uid`           | string  | Unique identifier of the sender           | `"cometchat-uid-2"`                                                     |
  | `name`          | string  | Display name                              | `"George Alan"`                                                         |
  | `avatar`        | string  | URL to avatar image                       | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"` |
  | `status`        | string  | Online status                             | `"online"`                                                              |
  | `role`          | string  | User role                                 | `"default"`                                                             |
  | `lastActiveAt`  | number  | Unix timestamp of last activity           | `1771323089`                                                            |
  | `hasBlockedMe`  | boolean | Whether sender has blocked logged-in user | `false`                                                                 |
  | `blockedByMe`   | boolean | Whether logged-in user has blocked sender | `false`                                                                 |
  | `deactivatedAt` | number  | Deactivation timestamp (0 if active)      | `0`                                                                     |
  | `tags`          | array   | User tags                                 | `[]`                                                                    |

  ***

  <span id="send-custom-receiver-object" style={{scrollMarginTop: '100px'}} />

  **`receiver` Object:**

  | Parameter       | Type    | Description                                 | Sample Value                                                            |
  | --------------- | ------- | ------------------------------------------- | ----------------------------------------------------------------------- |
  | `uid`           | string  | Unique identifier of the receiver           | `"cometchat-uid-3"`                                                     |
  | `name`          | string  | Display name                                | `"Nancy Grace"`                                                         |
  | `avatar`        | string  | URL to avatar image                         | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"` |
  | `status`        | string  | Online status                               | `"offline"`                                                             |
  | `role`          | string  | User role                                   | `"default"`                                                             |
  | `lastActiveAt`  | number  | Unix timestamp of last activity             | `1771322968`                                                            |
  | `hasBlockedMe`  | boolean | Whether receiver has blocked logged-in user | `false`                                                                 |
  | `blockedByMe`   | boolean | Whether logged-in user has blocked receiver | `false`                                                                 |
  | `deactivatedAt` | number  | Deactivation timestamp (0 if active)        | `0`                                                                     |
  | `tags`          | array   | User tags                                   | `[]`                                                                    |

  ***

  <span id="send-custom-data-object" style={{scrollMarginTop: '100px'}} />

  **`data` Object:**

  | Parameter    | Type   | Description                       | Sample Value                                                          |
  | ------------ | ------ | --------------------------------- | --------------------------------------------------------------------- |
  | `text`       | string | Fallback text                     | `"Sent a custom message"`                                             |
  | `resource`   | string | SDK resource identifier           | `"REACT_NATIVE-4_0_14-..."`                                           |
  | `customData` | object | Custom payload data               | `{"latitude": "50.6192171633316", "longitude": "-72.68182268750002"}` |
  | `entities`   | object | Sender and receiver entities      | [See below ↓](#send-custom-data-entities-object)                      |
  | `metadata`   | object | Injected metadata from extensions | `{"@injected": {"extensions": {"link-preview": {"links": []}}}}`      |
  | `moderation` | object | Moderation status                 | `{"status": "pending"}`                                               |

  ***

  <span id="send-custom-data-entities-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities` Object:**

  | Parameter  | Type   | Description             | Sample Value                                              |
  | ---------- | ------ | ----------------------- | --------------------------------------------------------- |
  | `sender`   | object | Sender entity wrapper   | [See below ↓](#send-custom-data-entities-sender-object)   |
  | `receiver` | object | Receiver entity wrapper | [See below ↓](#send-custom-data-entities-receiver-object) |

  ***

  <span id="send-custom-data-entities-sender-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.sender` Object:**

  | Parameter    | Type   | Description         | Sample Value                                                   |
  | ------------ | ------ | ------------------- | -------------------------------------------------------------- |
  | `entityType` | string | Type of entity      | `"user"`                                                       |
  | `entity`     | object | Sender user details | [See below ↓](#send-custom-data-entities-sender-entity-object) |

  ***

  <span id="send-custom-data-entities-sender-entity-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.sender.entity` Object:**

  | Parameter      | Type   | Description                     | Sample Value                                                            |
  | -------------- | ------ | ------------------------------- | ----------------------------------------------------------------------- |
  | `uid`          | string | Unique identifier               | `"cometchat-uid-2"`                                                     |
  | `name`         | string | Display name                    | `"George Alan"`                                                         |
  | `avatar`       | string | URL to avatar image             | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"` |
  | `status`       | string | Online status                   | `"online"`                                                              |
  | `role`         | string | User role                       | `"default"`                                                             |
  | `lastActiveAt` | number | Unix timestamp of last activity | `1771323089`                                                            |
  | `tags`         | array  | User tags                       | `[]`                                                                    |

  ***

  <span id="send-custom-data-entities-receiver-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.receiver` Object:**

  | Parameter    | Type   | Description           | Sample Value                                                     |
  | ------------ | ------ | --------------------- | ---------------------------------------------------------------- |
  | `entityType` | string | Type of entity        | `"user"`                                                         |
  | `entity`     | object | Receiver user details | [See below ↓](#send-custom-data-entities-receiver-entity-object) |

  ***

  <span id="send-custom-data-entities-receiver-entity-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.receiver.entity` Object:**

  | Parameter        | Type   | Description                     | Sample Value                                                            |
  | ---------------- | ------ | ------------------------------- | ----------------------------------------------------------------------- |
  | `uid`            | string | Unique identifier               | `"cometchat-uid-3"`                                                     |
  | `name`           | string | Display name                    | `"Nancy Grace"`                                                         |
  | `avatar`         | string | URL to avatar image             | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"` |
  | `status`         | string | Online status                   | `"offline"`                                                             |
  | `role`           | string | User role                       | `"default"`                                                             |
  | `lastActiveAt`   | number | Unix timestamp of last activity | `1771322968`                                                            |
  | `conversationId` | string | Conversation identifier         | `"cometchat-uid-2_user_cometchat-uid-3"`                                |
  | `tags`           | array  | User tags                       | `[]`                                                                    |
</Accordion>

### Update Conversation

*How can I decide whether the custom message should update the last message of a conversation?*

By default, a custom message will update the last message of a conversation. If you wish to not update the last message of the conversation when a custom message is sent, please use `shouldUpdateConversation(value: boolean)` method of the Custom Message.

<Tabs>
  <Tab title="To User">
    ```javascript theme={null}
    let receiverID = "UID";
    let customData = {
      latitude: "50.6192171633316",
      longitude: "-72.68182268750002",
    };
    let customType = "location";
    let receiverType = CometChat.RECEIVER_TYPE.USER;
    let customMessage = new CometChat.CustomMessage(
      receiverID,
      receiverType,
      customType,
      customData
    );

    customMessage.shouldUpdateConversation(false);
    CometChat.sendCustomMessage(customMessage).then(
      (message) => {
        console.log("custom message sent successfully", message);
      },
      (error) => {
        console.log("custom message sending failed with error", error);
      }
    );
    ```
  </Tab>

  <Tab title="To Group">
    ```javascript theme={null}
    let receiverID = "GUID";
    let customData = {
      latitude: "50.6192171633316",
      longitude: "-72.68182268750002",
    };
    let customType = "location";
    let receiverType = CometChat.RECEIVER_TYPE.GROUP;
    let customMessage = new CometChat.CustomMessage(
      receiverID,
      receiverType,
      customType,
      customData
    );

    customMessage.shouldUpdateConversation(false);
    CometChat.sendCustomMessage(customMessage).then(
      (message) => {
        console.log("custom message sent successfully", message);
      },
      (error) => {
        console.log("custom message sending failed with error", error);
      }
    );
    ```
  </Tab>

  <Tab title="TypeScript (User)">
    ```typescript theme={null}
    let receiverID: string = "UID",
      customData: Object = {
        latitude: "50.6192171633316",
        longitude: "-72.68182268750002",
      },
      customType: string = "location",
      receiverType: string = CometChat.RECEIVER_TYPE.USER,
      customMessage: CometChat.CustomMessage = new CometChat.CustomMessage(
        receiverID,
        receiverType,
        customType,
        customData
      );

    customMessage.shouldUpdateConversation(false);
    CometChat.sendCustomMessage(customMessage).then(
      (message: CometChat.CustomMessage) => {
        console.log("custom message sent successfully", message);
      },
      (error: CometChat.CometChatException) => {
        console.log("custom message sending failed with error", error);
      }
    );
    ```
  </Tab>

  <Tab title="TypeScript (Group)">
    ```typescript theme={null}
    let receiverID: string = "GUID",
      customData: Object = {
        latitude: "50.6192171633316",
        longitude: "-72.68182268750002",
      },
      customType: string = "location",
      receiverType: string = CometChat.RECEIVER_TYPE.GROUP,
      customMessage: CometChat.CustomMessage = new CometChat.CustomMessage(
        receiverID,
        receiverType,
        customType,
        customData
      );

    customMessage.shouldUpdateConversation(false);
    CometChat.sendCustomMessage(customMessage).then(
      (message: CometChat.CustomMessage) => {
        console.log("custom message sent successfully", message);
      },
      (error: CometChat.CometChatException) => {
        console.log("custom message sending failed with error", error);
      }
    );
    ```
  </Tab>
</Tabs>

### Custom Notification Body

*How can I customize the notification body of a custom message?*

To add a custom notification body for `Push, Email & SMS` notification of a custom message you can use the `setConversationText(text: string)` method of the CustomMessage class.

<Tabs>
  <Tab title="To User">
    ```javascript theme={null}
    let receiverID = "UID";
    let customData = {
      latitude: "50.6192171633316",
      longitude: "-72.68182268750002",
    };
    let customType = "location";
    let receiverType = CometChat.RECEIVER_TYPE.USER;
    let customMessage = new CometChat.CustomMessage(
      receiverID,
      receiverType,
      customType,
      customData
    );

    customMessage.setConversationText("Custom notification body");
    CometChat.sendCustomMessage(customMessage).then(
      (message) => {
        console.log("custom message sent successfully", message);
      },
      (error) => {
        console.log("custom message sending failed with error", error);
      }
    );
    ```
  </Tab>

  <Tab title="To Group">
    ```javascript theme={null}
    let receiverID = "GUID";
    let customData = {
      latitude: "50.6192171633316",
      longitude: "-72.68182268750002",
    };
    let customType = "location";
    let receiverType = CometChat.RECEIVER_TYPE.GROUP;
    let customMessage = new CometChat.CustomMessage(
      receiverID,
      receiverType,
      customType,
      customData
    );

    customMessage.setConversationText("Custom notification body");
    CometChat.sendCustomMessage(customMessage).then(
      (message) => {
        console.log("custom message sent successfully", message);
      },
      (error) => {
        console.log("custom message sending failed with error", error);
      }
    );
    ```
  </Tab>

  <Tab title="TypeScript (User)">
    ```typescript theme={null}
    let receiverID: string = "UID",
      customData: Object = {
        latitude: "50.6192171633316",
        longitude: "-72.68182268750002",
      },
      customType: string = "location",
      receiverType: string = CometChat.RECEIVER_TYPE.USER,
      customMessage: CometChat.CustomMessage = new CometChat.CustomMessage(
        receiverID,
        receiverType,
        customType,
        customData
      );

    customMessage.setConversationText("Custom notification body");
    CometChat.sendCustomMessage(customMessage).then(
      (message: CometChat.CustomMessage) => {
        console.log("custom message sent successfully", message);
      },
      (error: CometChat.CometChatException) => {
        console.log("custom message sending failed with error", error);
      }
    );
    ```
  </Tab>

  <Tab title="TypeScript (Group)">
    ```typescript theme={null}
    let receiverID: string = "GUID",
      customData: Object = {
        latitude: "50.6192171633316",
        longitude: "-72.68182268750002",
      },
      customType: string = "location",
      receiverType: string = CometChat.RECEIVER_TYPE.GROUP,
      customMessage: CometChat.CustomMessage = new CometChat.CustomMessage(
        receiverID,
        receiverType,
        customType,
        customData
      );

    customMessage.setConversationText("Custom notification body");
    CometChat.sendCustomMessage(customMessage).then(
      (message: CometChat.CustomMessage) => {
        console.log("custom message sent successfully", message);
      },
      (error: CometChat.CometChatException) => {
        console.log("custom message sending failed with error", error);
      }
    );
    ```
  </Tab>
</Tabs>

<Note>
  It is also possible to send interactive messages from CometChat. To learn more, see [Interactive Messages](/sdk/react-native/interactive-messages).
</Note>

<AccordionGroup>
  <Accordion title="Best Practices">
    * Use appropriate message types (`TEXT`, `IMAGE`, `VIDEO`, `AUDIO`, `FILE`) for media messages
    * Add metadata to messages when you need to pass additional context (e.g., location, user preferences)
    * Use tags to categorize messages for easier filtering and retrieval
    * Set `shouldUpdateConversation(false)` for background or system-level custom messages that shouldn't appear in conversation lists
    * Use `setConversationText()` to provide meaningful notification text for custom messages
  </Accordion>

  <Accordion title="Troubleshooting">
    * **Message not sending:** Ensure the user is logged in and CometChat is initialized
    * **Media upload fails:** Check file size limits and ensure the file object has correct `name`, `type`, and `uri` properties
    * **Custom message not appearing:** Verify the receiver UID/GUID is correct and the receiver type matches
    * **Notifications not showing custom text:** Make sure `setConversationText()` is called before sending the message
  </Accordion>
</AccordionGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Receive Messages" icon="inbox" href="/sdk/react-native/receive-messages">
    Listen for real-time messages and fetch missed messages
  </Card>

  <Card title="Edit a Message" icon="pen" href="/sdk/react-native/edit-message">
    Edit previously sent messages
  </Card>

  <Card title="Interactive Messages" icon="hand-pointer" href="/sdk/react-native/interactive-messages">
    Send forms, cards, and custom interactive messages
  </Card>

  <Card title="Typing Indicators" icon="keyboard" href="/sdk/react-native/typing-indicators">
    Show real-time typing status in conversations
  </Card>
</CardGroup>
