> ## Documentation Index
> Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Send Messages

> Send CometChat text, media, and custom messages to users and groups in React Native apps with message types and metadata.

> [accordion] AI Integration Quick Reference
>
> | Field | Value |
> | - | - |
> | Package | `@cometchat/chat-sdk-react-native` |
> | Import | `import { CometChat } from "@cometchat/chat-sdk-react-native";` |
> | Key Classes | [`TextMessage`](https://www.cometchat.com/docs/sdk/reference/messages#textmessage), [`MediaMessage`](https://www.cometchat.com/docs/sdk/reference/messages#mediamessage), [`CustomMessage`](https://www.cometchat.com/docs/sdk/reference/messages#custommessage) |
> | Key Methods | `sendMessage()`, `sendMediaMessage()`, `sendCustomMessage()` |
> | Receiver Types | `CometChat.RECEIVER_TYPE.USER`, `CometChat.RECEIVER_TYPE.GROUP` |
> | Message Types | `TEXT`, `IMAGE`, `VIDEO`, `AUDIO`, `FILE`, `CUSTOM` |
> | Prerequisites | SDK initialized, user logged in |
> | Primary output | `Promise<CometChat.BaseMessage>` — resolves to the sent `TextMessage` / `MediaMessage` / `CustomMessage`; rejects with `CometChatException` |
> | Constraints | There is no `sendCardMessage()` — card messages are **receive-only**. All three send methods are async: an un-`await`ed call returns a Promise, not a message. |
> | Related | [Receive Messages](https://www.cometchat.com/docs/sdk/react-native/receive-messages.md) · [Edit a Message](https://www.cometchat.com/docs/sdk/react-native/edit-message.md) · [Delete a Message](https://www.cometchat.com/docs/sdk/react-native/delete-message.md) · [Threaded Messages](https://www.cometchat.com/docs/sdk/react-native/threaded-messages.md) |
> | Full reference | [`TextMessage`](https://www.cometchat.com/docs/sdk/reference/messages#textmessage) · [`MediaMessage`](https://www.cometchat.com/docs/sdk/reference/messages#mediamessage) · [`CustomMessage`](https://www.cometchat.com/docs/sdk/reference/messages#custommessage) · [`BaseMessage`](https://www.cometchat.com/docs/sdk/reference/messages#basemessage) |

CometChat supports three types of messages:

| Type | Method | Use Case |
| - | - | - |
| [Text](#text-message) | `sendMessage()` | Plain text messages |
| [Media](#media-message) | `sendMediaMessage()` | Images, videos, audio, files |
| [Custom](#custom-message) | `sendCustomMessage()` | Location, polls, or any JSON data |

## Text Message

Send a text message using `CometChat.sendMessage()` with a [`TextMessage`](https://www.cometchat.com/docs/sdk/reference/messages#textmessage) object.

> [tab] 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] JavaScript (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);
>   }
> );
> ```
>
> Alternatively, you can use the `async/await` syntax:
>
> ```javascript theme={null}
> try {
>   const receiverID = "UID";
>   const messageText = "Hello world!";
>   const receiverType = CometChat.RECEIVER_TYPE.USER;
>   const textMessage = new CometChat.TextMessage(
>     receiverID,
>     messageText,
>     receiverType
>   );
>
>   const message = await CometChat.sendMessage(textMessage);
>   console.log("Message sent successfully:", message);
> } catch (error) {
>   console.log("Message sending failed with error:", error);
> }
> ```

> [tab] 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] JavaScript (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);
>   }
> );
> ```

The [`TextMessage`](https://www.cometchat.com/docs/sdk/reference/messages#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 content | Yes |
| `receiverType` | `CometChat.RECEIVER_TYPE.USER` or `CometChat.RECEIVER_TYPE.GROUP` | Yes |

On success, `sendMessage()` returns a [`TextMessage`](https://www.cometchat.com/docs/sdk/reference/messages#textmessage) | [`MediaMessage`](https://www.cometchat.com/docs/sdk/reference/messages#mediamessage) | [`CustomMessage`](https://www.cometchat.com/docs/sdk/reference/messages#custommessage) | [`BaseMessage`](https://www.cometchat.com/docs/sdk/reference/messages#basemessage) object containing all information related to the sent message.

> [!NOTE]
>
> With offline support enabled, pass a `MessageSentListener` as the second argument to queue the message when the device has no connection. `onMessagePending` fires first, on every send. Offline, `onError` can then fire once as a notice that the message is queued, not failed: check the `reason` argument (`null` means queued, a value means a real failure). `onMessageSent` follows when the message is sent on reconnect. A send without a listener is never queued and rejects while offline. See [Send While Offline](https://www.cometchat.com/docs/sdk/react-native/offline-send.md).

## Media Message

Send images, videos, audio, or files using `CometChat.sendMediaMessage()`.

> [!NOTE]
>
> `sendMediaMessage()` accepts the same optional `MessageSentListener` as `sendMessage()`. Without a listener, a media message is not queued while offline. See [Send While Offline](https://www.cometchat.com/docs/sdk/react-native/offline-send.md).

There are two ways to send media messages:

1. **Upload a file** — Pass a file object and CometChat uploads it automatically
2. **Send a URL** — Provide a URL to media hosted on your server or cloud storage

### Upload a File

Get the file using a React Native image picker and pass it to [`MediaMessage`](https://www.cometchat.com/docs/sdk/reference/messages#mediamessage):

```javascript theme={null}
ImagePicker.showImagePicker(options, (response) => {
  if (response.didCancel || response.error) return;

  const file = {
    name: Platform.OS === "android" ? response.fileName : response.fileName || "Camera_001.jpeg",
    type: response.type,
    uri: Platform.OS === "android" ? response.uri : response.uri.replace("file://", ""),
  };
  // Use this file object in MediaMessage
});
```

> [tab] TypeScript (User)
>
> ```typescript theme={null}
> let receiverID: string = "UID",
>   messageType: string = CometChat.MESSAGE_TYPE.IMAGE,
>   receiverType: string = CometChat.RECEIVER_TYPE.USER,
>   mediaMessage: CometChat.MediaMessage = new CometChat.MediaMessage(
>     receiverID,
>     file,
>     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] JavaScript (User)
>
> ```javascript theme={null}
> let receiverID = "UID";
> let messageType = CometChat.MESSAGE_TYPE.IMAGE;
> let receiverType = CometChat.RECEIVER_TYPE.USER;
> let mediaMessage = new CometChat.MediaMessage(
>   receiverID,
>   file,
>   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] TypeScript (Group)
>
> ```typescript theme={null}
> let receiverID: string = "GUID",
>   messageType: string = CometChat.MESSAGE_TYPE.IMAGE,
>   receiverType: string = CometChat.RECEIVER_TYPE.GROUP,
>   mediaMessage: CometChat.MediaMessage = new CometChat.MediaMessage(
>     receiverID,
>     file,
>     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] JavaScript (Group)
>
> ```javascript theme={null}
> let receiverID = "GUID";
> let messageType = CometChat.MESSAGE_TYPE.IMAGE;
> let receiverType = CometChat.RECEIVER_TYPE.GROUP;
> let mediaMessage = new CometChat.MediaMessage(
>   receiverID,
>   file,
>   messageType,
>   receiverType
> );
>
> CometChat.sendMediaMessage(mediaMessage).then(
>   (message) => {
>     console.log("Media message sent successfully", message);
>   },
>   (error) => {
>     console.log("Media message sending failed with error", error);
>   }
> );
> ```

### Send a URL

Send media hosted on your server or cloud storage using the [`Attachment`](https://www.cometchat.com/docs/sdk/reference/auxiliary#attachment) class:

> [tab] TypeScript (User)
>
> ```typescript theme={null}
> let receiverID: string = "UID",
>   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(
>   (message: CometChat.MediaMessage) => {
>     console.log("Media message sent successfully", message);
>   },
>   (error: CometChat.CometChatException) => {
>     console.log("Media message sending failed with error", error);
>   }
> );
> ```

> [tab] JavaScript (User)
>
> ```javascript theme={null}
> let receiverID = "UID";
> 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(
>   (message) => {
>     console.log("Media message sent successfully", message);
>   },
>   (error) => {
>     console.log("Media message sending failed with error", error);
>   }
> );
> ```

> [tab] TypeScript (Group)
>
> ```typescript theme={null}
> let receiverID: string = "GUID",
>   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(
>   (message: CometChat.MediaMessage) => {
>     console.log("Media message sent successfully", message);
>   },
>   (error: CometChat.CometChatException) => {
>     console.log("Media message sending failed with error", error);
>   }
> );
> ```

> [tab] JavaScript (Group)
>
> ```javascript theme={null}
> let receiverID = "GUID";
> 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(
>   (message) => {
>     console.log("Media message sent successfully", message);
>   },
>   (error) => {
>     console.log("Media message sending failed with error", error);
>   }
> );
> ```

The [`MediaMessage`](https://www.cometchat.com/docs/sdk/reference/messages#mediamessage) class constructor takes the following parameters:

| Parameter | Description | Required |
| - | - | - |
| `receiverID` | UID of the user or GUID of the group | Yes |
| `file` | File object to upload, or empty string if using URL | Yes |
| `messageType` | `CometChat.MESSAGE_TYPE.IMAGE`, `VIDEO`, `AUDIO`, or `FILE` | Yes |
| `receiverType` | `CometChat.RECEIVER_TYPE.USER` or `GROUP` | Yes |

On success, `sendMediaMessage()` returns a [`MediaMessage`](https://www.cometchat.com/docs/sdk/reference/messages#mediamessage) object.

### Add Caption

Add text along with the media:

```javascript theme={null}
mediaMessage.setCaption("Check out this photo!");
```

### Add Metadata and Tags

```javascript theme={null}
mediaMessage.setMetadata({ location: "Paris" });
mediaMessage.setTags(["vacation"]);
mediaMessage.setQuotedMessageId(10);
```

## Multiple Attachments in a Media Message

Starting version 3.0.9 & above, the SDK supports sending multiple attachments in a single media message. A media message can carry up to a configurable maximum number of attachments (default **10**, controlled by the `file.count.max` app setting). `sendMediaMessage()` rejects with `ERR_FILE_COUNT_EXCEEDED` if you exceed it — read the current limit at runtime with `CometChat.getMaxAttachmentCount()`.

> [!TIP]
>
> **Recommended: upload first, then send.** For a real composer — where you want a progress bar per file, and the ability to remove or retry individual files — upload the files through an [`UploadFileRequest`](https://www.cometchat.com/docs/sdk/react-native/upload-files), collect the resulting `Attachment`s, and attach them here with `setAttachments()`. This decouples the (slow, cancellable) upload from the (instant) send. See [Upload Files & Send Attachments](https://www.cometchat.com/docs/sdk/react-native/upload-files.md) for the full flow.

There are two ways:

1. **By providing an array of files** — Pass an array of file objects and CometChat uploads them automatically. This is the simplest path, but it gives no upload progress and no per-file cancel/retry — for that, [upload first](https://www.cometchat.com/docs/sdk/react-native/upload-files.md).
2. **By providing URLs** — Use the [`Attachment`](https://www.cometchat.com/docs/sdk/reference/auxiliary#attachment) class with multiple URLs. This is also the path the [upload-then-send flow](https://www.cometchat.com/docs/sdk/react-native/upload-files.md) uses — the `Attachment`s from an `UploadFileRequest` are ready to pass straight to `setAttachments()`.

### Upload Multiple Files

> [tab] 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,
>     files,
>     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] JavaScript (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] 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,
>     files,
>     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] JavaScript (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,
>   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);
>   }
> );
> ```

### Send Multiple URLs

> [tab] TypeScript (User)
>
> ```typescript theme={null}
> let receiverID: string = "UID",
>   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(
>   (message: CometChat.MediaMessage) => {
>     console.log("Media message sent successfully", message);
>   },
>   (error: CometChat.CometChatException) => {
>     console.log("Media message sending failed with error", error);
>   }
> );
> ```

> [tab] JavaScript (User)
>
> ```javascript theme={null}
> let receiverID = "UID";
> 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(
>   (message) => {
>     console.log("Media message sent successfully", message);
>   },
>   (error) => {
>     console.log("Media message sending failed with error", error);
>   }
> );
> ```

> [tab] TypeScript (Group)
>
> ```typescript theme={null}
> let receiverID: string = "GUID",
>   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(
>   (message: CometChat.MediaMessage) => {
>     console.log("Media message sent successfully", message);
>   },
>   (error: CometChat.CometChatException) => {
>     console.log("Media message sending failed with error", error);
>   }
> );
> ```

> [tab] JavaScript (Group)
>
> ```javascript theme={null}
> let receiverID = "GUID";
> 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(
>   (message) => {
>     console.log("Media message sent successfully", message);
>   },
>   (error) => {
>     console.log("Media message sending failed with error", error);
>   }
> );
> ```

## Custom Message

Send structured data that doesn't fit text or media categories — like location coordinates, polls, or game moves.

> [!NOTE]
>
> `sendCustomMessage()` accepts the same optional `MessageSentListener` as `sendMessage()`. Without a listener, a custom message is not queued while offline. See [Send While Offline](https://www.cometchat.com/docs/sdk/react-native/offline-send.md).

> [tab] 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] JavaScript (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] 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] JavaScript (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);
>   }
> );
> ```

The [`CustomMessage`](https://www.cometchat.com/docs/sdk/reference/messages#custommessage) class constructor takes the following parameters:

| Parameter | Description | Required |
| - | - | - |
| `receiverID` | UID of the user or GUID of the group | Yes |
| `receiverType` | `CometChat.RECEIVER_TYPE.USER` or `GROUP` | Yes |
| `customType` | Your custom type string (e.g., `"location"`, `"poll"`) | Yes |
| `customData` | JSON object with your custom data | Yes |

On success, `sendCustomMessage()` returns a [`CustomMessage`](https://www.cometchat.com/docs/sdk/reference/messages#custommessage) object.

### Add Tags

```javascript theme={null}
customMessage.setTags(["starredMessage"]);
```

### Quote a Message

```javascript theme={null}
customMessage.setQuotedMessageId(10);
```

### Control Conversation Update

By default, custom messages update the conversation's last message. To prevent this:

```javascript theme={null}
customMessage.shouldUpdateConversation(false);
```

### Control Notifications

By default, custom messages don't trigger notifications (push, email, or SMS). To enable them, call `shouldSendNotification(true)` before sending. See [Custom message templates](https://www.cometchat.com/docs/notifications/templates-and-sounds.md#5-custom-message-templates) for how notifications are handled for custom messages.

```javascript theme={null}
// Enable notification sending for this custom message
customMessage.shouldSendNotification(true);
```

### Custom Notification Text

Set custom text for push, email, and SMS notifications. Notifications use this text only when they're enabled for the message (see [Control Notifications](#control-notifications)). It is also shown as the conversation-list preview.

```javascript theme={null}
customMessage.setConversationText("Shared a location");
customMessage.shouldSendNotification(true);
```

***

## Card Message

A `CardMessage` is a structured, interactive message rendered as a card bubble. It belongs to the `card` category and carries a block of Card Schema JSON that the CometChat Cards library draws.

> [!TIP]
>
> **Design cards visually with [Card Builder](https://www.cometchat.com/docs/card-builder/overview.md).** Build your card messages in the CometChat Dashboard and export the Card Schema JSON — instead of writing it by hand.

> [!NOTE]
>
> **Card Messages cannot be sent through the SDK.** The `CardMessage` class is **receive-only** — it has no public constructor and the SDK exposes no `sendCardMessage()` method. Card Messages are created server-side via the **Platform (REST) API** or the **Dashboard Bubble Builder**, and delivered to clients like any other message, through the `onCardMessageReceived` callback of the `MessageListener`.
>
> To create and send a Card Message, use the REST API. See the [Send Message REST API reference](https://www.cometchat.com/docs/rest-api/messages/send-message.md) for the message creation flow.

On the receiving end, the `CardMessage` object gives you access to the card payload and its related fields.

> [tab] TypeScript
>
> ```typescript theme={null}
> const card: object = cardMessage.getCard();             // raw card schema/payload
> const text: string = cardMessage.getText();             // preview text for notifications and the conversation list
> const fallbackText: string = cardMessage.getFallbackText(); // shown when the card cannot be rendered
> const tags: Array<string> = cardMessage.getTags();      // tags associated with the message
> ```

> [tab] JavaScript
>
> ```javascript theme={null}
> const card = cardMessage.getCard();             // raw card schema/payload
> const text = cardMessage.getText();             // preview text for notifications and the conversation list
> const fallbackText = cardMessage.getFallbackText(); // shown when the card cannot be rendered
> const tags = cardMessage.getTags();             // tags associated with the message
> ```

The `CardMessage` class provides the following methods:

| Method | Returns | Description |
| - | - | - |
| `getCard()` | `object` | The raw card schema/payload passed to the Cards renderer. |
| `getText()` | `string` | Preview text for notifications and the conversation list. |
| `getFallbackText()` | `string` | Text displayed when the card payload cannot be rendered. |
| `getTags()` | `Array<string>` | Tags associated with the message. |

`CardMessage` extends `BaseMessage`, so it also exposes the standard message fields (`getId()`, `getSender()`, `getReceiverId()`, `getSentAt()`, `getCategory()` = `card`, etc.).

To handle incoming Card Messages on the client, implement [`onCardMessageReceived`](https://www.cometchat.com/docs/sdk/react-native/receive-messages#card-messages) on your `MessageListener`.

### Render a Card Message

A `CardMessage` carries raw Card Schema JSON in `getCard()`. To draw it natively, pass it to the **CometChat Cards** renderer (`@cometchat/cards-react-native`) via the [`CometChatCardView`](https://www.cometchat.com/docs/sdk/react-native/campaigns#rendering-cards) component. It is a pure renderer: you hand it the card JSON and an action callback, and you own all action behavior (opening URLs, navigating to chats, API calls, etc.).

See [Campaigns → Rendering Cards](https://www.cometchat.com/docs/sdk/react-native/campaigns.md#rendering-cards) for the dependency setup, the `CometChatCardView` example, and the [supported card actions](https://www.cometchat.com/docs/sdk/react-native/campaigns.md#supported-card-actions). If the card JSON is empty or invalid, fall back to `getFallbackText()` (then `getText()`).

***

## Next Steps

> [card] [Receive Messages](https://www.cometchat.com/docs/sdk/react-native/receive-messages.md)
>
> Listen for incoming messages in real-time

> [card] [Edit Message](https://www.cometchat.com/docs/sdk/react-native/edit-message.md)
>
> Edit previously sent messages

> [card] [Delete Message](https://www.cometchat.com/docs/sdk/react-native/delete-message.md)
>
> Delete sent messages


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.