AI Integration Quick Reference
AI Integration Quick Reference
| Type | Method | Receiver Types |
|---|---|---|
| Text | sendMessage() | RECEIVER_TYPE_USER, RECEIVER_TYPE_GROUP |
| Media | sendMediaMessage() | RECEIVER_TYPE_USER, RECEIVER_TYPE_GROUP |
| Custom | sendCustomMessage() | RECEIVER_TYPE_USER, RECEIVER_TYPE_GROUP |
You can also send Interactive Messages for forms, cards, and custom UI elements.
Text Message
Send a text message usingsendMessage() with a TextMessage object.
- Java (User)
- Kotlin (User)
- Java (Group)
- Kotlin (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 | CometChatConstants.RECEIVER_TYPE_USER or RECEIVER_TYPE_GROUP | Yes |
sendMessage() returns a TextMessage object containing all information about the sent message.
Add Metadata
Attach custom JSON data to the message:- Java
- Kotlin
Add Tags
Tag messages for easy filtering later:- Java
- Kotlin
Quote a Message
Reply to a specific message by setting its ID:- Java
- Kotlin
Media Message
Send images, videos, audio, or files usingsendMediaMessage().
There are two ways to send media messages:
- Upload a file — Pass a
Fileobject and CometChat uploads it automatically - Send a URL — Provide a URL to media hosted on your server or cloud storage
Add Metadata
- Java
- Kotlin
Add Caption
Add text along with the media:- Java
- Kotlin
Add Tags
- Java
- Kotlin
Upload a File
Pass aFile object directly. CometChat uploads it to its servers and returns the URL in the success response.
- Java (User)
- Kotlin (User)
- Java (Group)
- Kotlin (Group)
MediaMessage class constructor takes the following parameters:
| Parameter | Description | Required |
|---|---|---|
receiverId | The UID or GUID of the recipient | Yes |
file | The File object to upload | Yes |
messageType | MESSAGE_TYPE_IMAGE, MESSAGE_TYPE_VIDEO, MESSAGE_TYPE_AUDIO, or MESSAGE_TYPE_FILE | Yes |
receiverType | RECEIVER_TYPE_USER or RECEIVER_TYPE_GROUP | Yes |
Send a URL
Send media hosted on your server or cloud storage using theAttachment class:
- Java (User)
- Kotlin (User)
- Java (Group)
- Kotlin (Group)
sendMediaMessage() returns a MediaMessage object.
Multiple Attachments
Starting version 3.0.9, the SDK supports sending multiple attachments in a single media message.Upload Multiple Files
- Java (User)
- Kotlin (User)
- Java (Group)
- Kotlin (Group)
MediaMessage class constructor takes the following parameters:
| Parameter | Description | Required |
|---|---|---|
receiverId | The UID or GUID of the recipient | Yes |
files | A List<File> of files to upload | Yes |
messageType | MESSAGE_TYPE_IMAGE, MESSAGE_TYPE_VIDEO, MESSAGE_TYPE_AUDIO, or MESSAGE_TYPE_FILE | Yes |
receiverType | RECEIVER_TYPE_USER or RECEIVER_TYPE_GROUP | Yes |
Send Multiple URLs
- Java (User)
- Kotlin (User)
- Java (Group)
- Kotlin (Group)
MediaMessage object which includes all information related to the sent message.
You can use the setMetadata(), setCaption() & setTags() methods to add metadata, caption and tags in the same way as a single attachment.
Custom Message
Send custom data that doesn’t fit text or media usingsendCustomMessage().
- Java
- Kotlin
| Parameter | Description | Required |
|---|---|---|
receiverId | UID of the user or GUID of the group | Yes |
receiverType | RECEIVER_TYPE_USER or RECEIVER_TYPE_GROUP | Yes |
customType | Developer-defined type string (e.g., "LOCATION", "POLL") | Yes |
customData | The payload as a JSONObject | Yes |
setSubtype() to further classify the custom message.
Add Tags
- Java
- Kotlin
sendCustomMessage().
- Java (User)
- Kotlin (User)
- Java (Group)
- Kotlin (Group)
sendCustomMessage() returns a CustomMessage object.
Control Conversation Update
By default, a custom message updates the conversation’s last message. To prevent this:- Java (User)
- Kotlin (User)
- Java (Group)
- Kotlin (Group)
Custom Notification Text
Set custom text for push, email, and SMS notifications:- Java (User)
- Kotlin (User)
- Java (Group)
- Kotlin (Group)
It is also possible to send interactive messages from CometChat, to know more click here
Next Steps
Receive Messages
Listen for incoming messages in real time
Edit Message
Modify sent messages after delivery
Delete Message
Remove messages from conversations
Interactive Messages
Send messages with embedded forms and buttons
Message Payload Structure
BaseMessage Object
BaseMessage Object
The
Sample BaseMessage Object:
BaseMessage object returned by SDK methods contains the following fields. TextMessage, MediaMessage, and CustomMessage extend this base structure with additional type-specific fields.| Parameter | Type | Description |
|---|---|---|
id | long | Unique message identifier |
muid | String | Developer-defined message ID for deduplication |
sender | User | User who sent the message |
receiver | AppEntity | Message receiver (User or Group) |
receiverUid | String | Receiver’s unique identifier |
type | String | Message type. Values: "text", "image", "video", "audio", "file", "custom" |
receiverType | String | Type of receiver. Values: "user", "group" |
category | String | Message category. Values: "message", "action", "call", "custom" |
sentAt | long | Unix timestamp when message was sent |
deliveredAt | long | Unix timestamp when message was delivered |
readAt | long | Unix timestamp when message was read |
metadata | JSONObject | Custom message metadata set by developer |
readByMeAt | long | Unix timestamp when logged-in user read the message |
deliveredToMeAt | long | Unix timestamp when message was delivered to logged-in user |
deletedAt | long | Unix timestamp when message was deleted (0 if not deleted) |
editedAt | long | Unix timestamp when message was edited (0 if not edited) |
deletedBy | String | UID of user who deleted the message (null if not deleted) |
editedBy | String | UID of user who edited the message (null if not edited) |
updatedAt | long | Unix timestamp of last message update |
conversationId | String | Associated conversation identifier |
parentMessageId | long | Parent message ID for threaded messages (0 if not a reply) |
replyCount | int | Number of replies in thread |
unreadRepliesCount | int | Number of unread replies in thread |
mentionedUsers | Array<User> | List of users mentioned in the message |
hasMentionedMe | boolean | Whether the logged-in user is mentioned |
reactions | Array<ReactionCount> | List of reaction counts on the message |
rawMessage | JSONObject | Raw JSON message data |
quotedMessageId | long | ID of the quoted message (0 if not quoting) |
quotedMessage | BaseMessage | The quoted message object (null if not quoting) |
User Object
User Object
The nested
User object (used in sender, receiver, mentionedUsers) contains:| Parameter | Type | Description |
|---|---|---|
uid | String | Unique identifier of the user |
name | String | Display name of the user |
avatar | String | URL to user’s profile picture |
link | String | URL to user’s profile page |
role | String | User role for access control |
metadata | JSONObject | Custom data set by developer |
status | String | User online status. Values: "online", "offline" |
statusMessage | String | Custom status message |
lastActiveAt | long | Unix timestamp of last activity |
hasBlockedMe | boolean | Whether this user has blocked the logged-in user |
blockedByMe | boolean | Whether the logged-in user has blocked this user |
tags | Array<String> | List of tags for user identification |
deactivatedAt | long | Unix timestamp when user was deactivated (0 if active) |
Group Object
Group Object
The nested
Group object (used in receiver for group messages) contains:| Parameter | Type | Description |
|---|---|---|
guid | String | Unique identifier of the group |
name | String | Display name of the group |
type | String | Group type. Values: "public", "private", "password" |
icon | String | URL to group icon |
description | String | Group description |
owner | String | UID of group owner |
metadata | JSONObject | Custom data set by developer |
membersCount | int | Number of group members |
tags | Array<String> | List of tags for group identification |
hasJoined | boolean | Whether logged-in user has joined |
scope | String | User’s scope in group. Values: "admin", "moderator", "participant" |
ReactionCount Object
ReactionCount Object
The nested
ReactionCount object (used in reactions array) contains:| Parameter | Type | Description |
|---|---|---|
reaction | String | The reaction emoji |
count | int | Total count of this reaction |
reactedByMe | boolean | Whether the logged-in user has reacted with this emoji |