AI Integration Quick Reference
AI Integration Quick Reference
| Field | Value |
|---|---|
| Key Classes | TextMessage, MediaMessage, CustomMessage |
| Key Methods | sendTextMessage(), sendMediaMessage(), sendCustomMessage() |
| Receiver Types | .user, .group |
| Message Types | .text, .image, .video, .audio, .file, custom |
| Prerequisites | SDK initialized, user logged in |
You can also send metadata along with a text, media or custom message. Think, for example, if you’d want to share the user’s location with every message, you can use the metadata field.
Text Message
Send a text message usingCometChat.sendTextMessage() with a TextMessage object.
- Swift (User)
- Objective-C (User)
- Swift (Group)
- Objective-C (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 |
text | The text message content | Yes |
receiverType | .user or .group | Yes |
sendTextMessage() returns a TextMessage object containing all information about the sent message.
Add Metadata
Send custom data along with a text message using themetaData property:
- Swift
- Objective-C
Add Tags
Quote a 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 path and CometChat uploads it automatically
- Send a URL — Provide a URL to media hosted on your server or cloud storage
Upload a File
- Swift
- Objective-C
Send a URL
Use theAttachment class to send media hosted on your server or cloud storage:
MediaMessage class constructor takes the following parameters:
| Parameter | Description | Required |
|---|---|---|
receiverID | UID of the user or GUID of the group | Yes |
fileurl | File path or empty string if using URL | Yes |
messageType | .image, .video, .audio, or .file | Yes |
receiverType | .user or .group | Yes |
sendMediaMessage() returns a MediaMessage object.
Add Caption
Add Metadata and Tags
Same as text messages:Multiple Attachments in a Media Message
Starting version 3.0.906 & above, the SDK supports sending multiple attachments in a single media message.Custom Message
Send structured data that doesn’t fit text or media categories — like location coordinates, polls, or game moves.- Swift (User)
- Swift (Group)
CustomMessage class constructor takes the following parameters:
| Parameter | Description | Required |
|---|---|---|
receiverID | UID of the user or GUID of the group | Yes |
receiverType | .user or .group | Yes |
customData | Dictionary with your custom data | Yes |
type | Your custom type string (e.g., "location", "poll") | Yes |
sendCustomMessage() returns a CustomMessage object.
Add Tags
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:It is also possible to send interactive messages from CometChat. To learn more, see Interactive Messages.
Next Steps
Receive Messages
Listen for incoming messages in real-time
Edit Message
Edit previously sent messages
Delete Message
Delete sent messages