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 |
You can also send Interactive Messages for forms, cards, and custom UI elements.
Text Message
Send a text message usingCometChat.sendMessage() with a TextMessage object.
- User
- Group
- TypeScript (User)
- TypeScript (Group)
- Async/Await
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 object.
Add Metadata
Attach custom JSON data to the message:- JavaScript
- TypeScript
Add Tags
Tag messages for easy filtering later:- JavaScript
- TypeScript
Quote a Message
Reply to a specific message by setting its ID:- JavaScript
- TypeScript
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:
- User
- Group
- TypeScript (User)
- TypeScript (Group)
Send a URL
Send media hosted on your server or cloud storage using theAttachment class:
- User
- Group
- TypeScript (User)
- TypeScript (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:- JavaScript
- TypeScript
Add Metadata and Tags
Same as text messages:Multiple Attachments
Send multiple files in a single media message.Upload Multiple Files
- User
- Group
- TypeScript (User)
- TypeScript (Group)
Send Multiple URLs
- User
- Group
- TypeScript (User)
- TypeScript (Group)
Custom Message
Send structured data that doesn’t fit text or media categories — like location coordinates, polls, or game moves.- User
- Group
- TypeScript (User)
- TypeScript (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:You can also send interactive messages with forms, cards, and buttons. See Interactive Messages for details.
Next Steps
Receive Messages
Listen for incoming messages in real-time
Edit Message
Edit previously sent messages
Delete Message
Delete sent messages
Interactive Messages
Send forms, cards, and custom UI elements