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() method returns a TextMessage | MediaMessage | CustomMessage | BaseMessage object depending on the input message type.
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 from an input element 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:- TypeScript
- JavaScript
Add Metadata and Tags
Same as text messages:sendMediaMessage() method returns a MediaMessage object.
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:- 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 thesendMediaMessage()method.
- html
- 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:sendCustomMessage() method returns a CustomMessage object.
Next Steps
Receive Messages
Listen for incoming messages in real-time
Edit Message
Edit previously sent messages
Delete Message
Delete sent messages