AI Integration Quick Reference
AI Integration Quick Reference
| Field | Value |
|---|---|
| Key Classes | TextMessage, MediaMessage, 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 |
Text Message
Send a text message usingCometChat.sendMessage() with a TextMessage object.
- TypeScript (User)
- JavaScript (User)
- TypeScript (Group)
- JavaScript (Group)
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 |
sendMessage() returns a TextMessage | MediaMessage | CustomMessage | BaseMessage object containing all information related to the sent message.
Media Message
Send images, videos, audio, or files usingCometChat.sendMediaMessage().
There are two ways to send media messages:
- Upload a file — Pass a file object and CometChat uploads it automatically
- 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 toMediaMessage:
- TypeScript (User)
- JavaScript (User)
- TypeScript (Group)
- JavaScript (Group)
Send a URL
Send media hosted on your server or cloud storage using theAttachment class:
- TypeScript (User)
- JavaScript (User)
- TypeScript (Group)
- JavaScript (Group)
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 |
sendMediaMessage() returns a MediaMessage object.
Add Caption
Add text along with the media:Add Metadata and Tags
Multiple Attachments in a Media Message
Starting version 3.0.9 & above, the SDK supports sending multiple attachments in a single media message. There are two ways:- By providing an array of files — Pass an array of file objects and CometChat uploads them automatically.
- By providing URLs — Use the
Attachmentclass with multiple URLs.
Upload Multiple Files
- TypeScript (User)
- JavaScript (User)
- TypeScript (Group)
- JavaScript (Group)
Send Multiple URLs
- TypeScript (User)
- JavaScript (User)
- TypeScript (Group)
- JavaScript (Group)
Custom Message
Send structured data that doesn’t fit text or media categories — like location coordinates, polls, or game moves.- TypeScript (User)
- JavaScript (User)
- TypeScript (Group)
- JavaScript (Group)
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 |
sendCustomMessage() returns a CustomMessage object.
Add Tags
Quote a Message
Control Conversation Update
By default, custom messages update the conversation’s last message. To prevent this:Custom Notification Text
Set custom text for push, email, and SMS notifications:Card Message
ACardMessage 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.
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 for the message creation flow.CardMessage object gives you access to the card payload and its related fields.
- TypeScript
- JavaScript
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 on your MessageListener.
Render a Card Message
ACardMessage 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 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 for the dependency setup, the CometChatCardView example, and the supported card actions. If the card JSON is empty or invalid, fall back to getFallbackText() (then getText()).
Next Steps
Receive Messages
Listen for incoming messages in real-time
Edit Message
Edit previously sent messages
Delete Message
Delete sent messages