AI Integration Quick Reference
AI Integration Quick Reference
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:
On success,
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:
On success,
sendMediaMessage() returns a MediaMessage object.
Add Caption
Add Metadata and Tags
Same as text messages:Multiple Attachments in a Media Message
The SDK supports sending multiple attachments in a single media message. A media message can carry up to a configurable maximum number of attachments (default 10, controlled by thefile.count.max app setting) — read the current limit at runtime with CometChat.getMaxFileCount().
There are two ways to send a multi-attachment media message using the CometChat SDK:
- By providing an array of files: You can share an array of
Fileobjects while creating an object of the MediaMessage class. When the media message is sent using thesendMediaMessage()method, the files are uploaded to the CometChat servers & the URLs of the files are sent in the success response of thesendMediaMessage()method. This is the simplest path, but it gives no upload progress and no per-file cancel/retry — for that, upload first.
MediaMessage class constructor takes the following parameters:
- By providing the URL of the multiple files: The second way to send multiple attachments using the CometChat SDK is to provide the SDK with
Attachmentobjects that already point at files hosted on your servers or any cloud storage. This is also the path the upload-then-send flow uses — theAttachments from an upload request’sgetAttachments()are ready to set straight on the message’sattachmentsproperty. For more information, you can refer to the below code snippet:
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:
On success,
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