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:Next Steps
Receive Messages
Listen for incoming messages in real-time
Edit Message
Edit previously sent messages
Delete Message
Delete sent messages