AI Integration Quick Reference
AI Integration Quick Reference
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:
On success,
sendMessage() returns a TextMessage | MediaMessage | CustomMessage | BaseMessage object containing all information related to the sent message.
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.Media Message
Send images, videos, audio, or files usingCometChat.sendMediaMessage().
sendMediaMessage() accepts the same optional MessageSentListener as sendMessage(). Without a listener, a media message is not queued while offline. See Send While Offline.- 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:
On success,
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. A media message can carry up to a configurable maximum number of attachments (default 10, controlled by thefile.count.max app setting). sendMediaMessage() rejects with ERR_FILE_COUNT_EXCEEDED if you exceed it — read the current limit at runtime with CometChat.getMaxAttachmentCount().
There are two ways:
- 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.
- By providing URLs — Use the
Attachmentclass with multiple URLs. This is also the path the upload-then-send flow uses — theAttachments from anUploadFileRequestare ready to pass straight tosetAttachments().
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.sendCustomMessage() accepts the same optional MessageSentListener as sendMessage(). Without a listener, a custom message is not queued while offline. See Send While Offline.- TypeScript (User)
- JavaScript (User)
- TypeScript (Group)
- JavaScript (Group)
CustomMessage class constructor takes the following parameters:
On success,
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:Control Notifications
By default, custom messages don’t trigger notifications (push, email, or SMS). To enable them, callshouldSendNotification(true) before sending. See Custom message templates for how notifications are handled for custom messages.
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). It is also shown as the conversation-list preview.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:
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