Quick Reference for AI Agents & Developers
- Text message:
TextMessage(receiverUid:text:receiverType:)→CometChat.sendTextMessage(message:onSuccess:onError:) - Media message:
MediaMessage(receiverUid:fileurl:messageType:receiverType:)→CometChat.sendMediaMessage(message:onSuccess:onError:) - Custom message:
CustomMessage(receiverUid:receiverType:customData:type:)→CometChat.sendCustomMessage(message:onSuccess:onError:) - Receiver types:
.user,.group - Related: Receive Message · Interactive Messages · Messaging Overview
- A text message, the most common and standard message type.
- A media message, for sending photos, videos and files.
- A custom message, for sending completely custom data using JSON structures.
- A Interactive Messages , for sending end-user interactive messages of type form, card and custom Interactive
Object Structures
TextMessage Object
TheTextMessage object represents a text message in CometChat.
| Parameter | Type | Description |
|---|---|---|
| id | Int | Unique message identifier assigned by CometChat |
| muid | String | Message unique identifier (client-generated) |
| conversationId | String | Unique conversation identifier |
| senderUid | String | UID of the message sender |
| receiverUid | String | UID/GUID of the message receiver |
| receiverType | CometChat.ReceiverType | .user (0) or .group (1) |
| messageType | CometChat.MessageType | .text (0) for text messages |
| messageCategory | CometChat.MessageCategory | .message (0) for standard messages |
| sentAt | Int | Unix timestamp when message was sent |
| deliveredAt | Double | Unix timestamp when message was delivered |
| readAt | Double | Unix timestamp when message was read |
| editedAt | Double | Unix timestamp when message was edited |
| deletedAt | Double | Unix timestamp when message was deleted |
| updatedAt | Double | Unix timestamp of last update |
| editedBy | String | UID of user who edited the message |
| deletedBy | String | UID of user who deleted the message |
| parentMessageId | Int | ID of parent message (for threaded replies) |
| replyCount | Int | Number of replies to this message |
| unreadRepliesCount | Int | Number of unread replies |
| metaData | [String: Any] | Custom metadata dictionary |
| mentionedUsers | [User] | Array of mentioned users |
| mentionedMe | Bool | Whether current user is mentioned |
| reactions | [ReactionCount] | Array of reaction counts |
| text | String | The text content of the message |
| tags | [String] | Array of tags associated with the message |
| sender | User | User object of the sender |
| receiver | User or Group | User or Group object of the receiver |
MediaMessage Object
TheMediaMessage object represents a media message (image, video, audio, file) in CometChat.
| Parameter | Type | Description |
|---|---|---|
| id | Int | Unique message identifier assigned by CometChat |
| muid | String | Message unique identifier (client-generated) |
| conversationId | String | Unique conversation identifier |
| senderUid | String | UID of the message sender |
| receiverUid | String | UID/GUID of the message receiver |
| receiverType | CometChat.ReceiverType | .user (0) or .group (1) |
| messageType | CometChat.MessageType | .image (1), .video (2), .audio (3), .file (4) |
| messageCategory | CometChat.MessageCategory | .message (0) for standard messages |
| sentAt | Int | Unix timestamp when message was sent |
| deliveredAt | Double | Unix timestamp when message was delivered |
| readAt | Double | Unix timestamp when message was read |
| editedAt | Double | Unix timestamp when message was edited |
| deletedAt | Double | Unix timestamp when message was deleted |
| updatedAt | Double | Unix timestamp of last update |
| parentMessageId | Int | ID of parent message (for threaded replies) |
| replyCount | Int | Number of replies to this message |
| unreadRepliesCount | Int | Number of unread replies |
| metaData | [String: Any] | Custom metadata dictionary |
| mentionedUsers | [User] | Array of mentioned users |
| mentionedMe | Bool | Whether current user is mentioned |
| reactions | [ReactionCount] | Array of reaction counts |
| attachment | Attachment | Single attachment object |
| attachments | [Attachment]? | Array of attachments (for multiple files) |
| caption | String? | Caption text for the media |
| tags | [String] | Array of tags associated with the message |
| sender | User | User object of the sender |
| receiver | User or Group | User or Group object of the receiver |
CustomMessage Object
TheCustomMessage object represents a custom message with arbitrary data.
| Parameter | Type | Description |
|---|---|---|
| id | Int | Unique message identifier assigned by CometChat |
| muid | String | Message unique identifier (client-generated) |
| conversationId | String | Unique conversation identifier |
| senderUid | String | UID of the message sender |
| receiverUid | String | UID/GUID of the message receiver |
| receiverType | CometChat.ReceiverType | .user (0) or .group (1) |
| messageType | CometChat.MessageType | Custom type string |
| messageCategory | CometChat.MessageCategory | .custom (3) for custom messages |
| sentAt | Int | Unix timestamp when message was sent |
| deliveredAt | Double | Unix timestamp when message was delivered |
| readAt | Double | Unix timestamp when message was read |
| editedAt | Double | Unix timestamp when message was edited |
| deletedAt | Double | Unix timestamp when message was deleted |
| updatedAt | Double | Unix timestamp of last update |
| parentMessageId | Int | ID of parent message (for threaded replies) |
| replyCount | Int | Number of replies to this message |
| unreadRepliesCount | Int | Number of unread replies |
| metaData | [String: Any] | Custom metadata dictionary |
| mentionedUsers | [User] | Array of mentioned users |
| mentionedMe | Bool | Whether current user is mentioned |
| reactions | [ReactionCount] | Array of reaction counts |
| customType | String | Custom type identifier (e.g., “location”, “poll”) |
| customData | [String: Any] | Custom data dictionary |
| subType | String? | Optional sub-type for further categorization |
| updateConversation | Bool | Whether to update conversation’s last message |
| conversationText | String? | Custom text for conversation preview/notifications |
| tags | [String] | Array of tags associated with the message |
| sender | User | User object of the sender |
| receiver | User or Group | User or Group object of the receiver |
User Object
TheUser object represents a CometChat user.
| Parameter | Type | Description |
|---|---|---|
| uid | String | Unique user identifier |
| name | String | Display name of the user |
| avatar | String? | Avatar image URL |
| link | String? | Profile link URL |
| role | String | User role (e.g., “default”, “moderator”, “admin”) |
| status | CometChat.UserStatus | .online (0) or .offline (1) |
| statusMessage | String? | Custom status message |
| lastActiveAt | Double | Unix timestamp of last activity |
| hasBlockedMe | Bool | Whether this user has blocked the logged-in user |
| blockedByMe | Bool | Whether the logged-in user has blocked this user |
| metadata | [String: Any] | Custom metadata dictionary |
| deactivatedAt | Double | Unix timestamp when user was deactivated (0 if active) |
| tags | [String] | Array of tags associated with the user |
Group Object
TheGroup object represents a CometChat group.
| Parameter | Type | Description |
|---|---|---|
| guid | String | Unique group identifier |
| name | String | Display name of the group |
| icon | String? | Group icon image URL |
| description | String? | Group description |
| type | CometChat.GroupType | .public, .private, or .password |
| owner | String | UID of the group owner |
| membersCount | Int | Number of members in the group |
| createdAt | Double | Unix timestamp when group was created |
| updatedAt | Double | Unix timestamp of last update |
| hasJoined | Bool | Whether the logged-in user has joined the group |
| joinedAt | Double | Unix timestamp when user joined the group |
| scope | CometChat.GroupMemberScope | .participant, .moderator, or .admin |
| metadata | [String: Any]? | Custom metadata dictionary |
| tags | [String]? | Array of tags associated with the group |
Attachment Object
TheAttachment object represents a file attachment in a media message.
| Parameter | Type | Description |
|---|---|---|
| fileName | String | Name of the file |
| fileExtension | String | File extension (e.g., “jpg”, “pdf”) |
| fileSize | Int | File size in bytes |
| fileMimeType | String | MIME type (e.g., “image/jpeg”, “application/pdf”) |
| fileUrl | String | URL to access the file |
CometChatException Object
TheCometChatException object represents an error returned by the SDK.
| Parameter | Type | Description |
|---|---|---|
| errorCode | String | Unique error code identifier |
| errorDescription | String | Human-readable error message |
| details | String? | Additional context or troubleshooting information |
Text Message
In other words, as a sender, how do I send a text message? To send a text message to a single user or group, you need to use thesendMessage() method and pass a TextMessage object to it.
Add Metadata
To send custom data along with a text message, you can use the metadata field provided inTextMessage. A metadata field is a dictionary of type [String: Any] which will be received as it was sent without any processing from CometChat. It can be used to send any additional data that needs to be sent along with a message.
- Swift
- Objective C
Add Tags
To add a tag to a message you can useArray of strings that you need to set it to property tags.
- Swift
- Objective C
sendMessage() method to send the text message to the recipient.
- User(Swift)
- User(Objective C)
- Group(Swift)
- Group(Objective C)
TextMessage class constructor takes the following parameters:
| Parameters | Information |
|---|---|
| receiverID | The UID or GUID of the recipient |
| text | The text to be sent |
| receiverType | The type of the receiver to whom the message is to be sent i.e user or group |
login() method returns the TextMessage object containing all the information of the sent message.
Sample Payloads
Sample Payloads
- Request
- Success Response
- Error Response
Method:
CometChat.sendTextMessage(message:)Object Type: TextMessage (before sending)| Parameter | Type | Value |
|---|---|---|
| id | Int | 0 |
| muid | String | "" |
| conversationId | String | "" |
| senderUid | String | "" |
| receiverUid | String | "cometchat-uid-3" |
| receiverType | CometChat.ReceiverType | 0 (.user) |
| messageType | CometChat.MessageType | 0 (.text) |
| messageCategory | CometChat.MessageCategory | 0 (.message) |
| sentAt | Int | 0 |
| deliveredAt | Double | 0.0 |
| readAt | Double | 0.0 |
| editedAt | Double | 0.0 |
| deletedAt | Double | 0.0 |
| updatedAt | Double | 0.0 |
| editedBy | String | "" |
| deletedBy | String | "" |
| parentMessageId | Int | 0 |
| replyCount | Int | 0 |
| unreadRepliesCount | Int | 0 |
| metaData | [String: Any] | [:] (empty dictionary) |
| mentionedUsers | [User] | [] (empty array) |
| mentionedMe | Bool | false |
| reactions | [ReactionCount] | [] (empty array) |
| text | String | "Hello" |
| sender | User? | nil |
| receiver | User? | nil |
More Sample Payloads
More Sample Payloads
- TextMessage to Group
- With Metadata
Object Type: TextMessage
sender (User):
receiver (Group):
| Parameter | Type | Value |
|---|---|---|
| id | Int | 143 |
| muid | String | "1708934500456_user_12345" |
| senderUid | String | "user_12345" |
| receiverUid | String | "group_dev_team" |
| text | String | "Team meeting at 3 PM" |
| messageType | CometChat.MessageType | 0 (.text) |
| receiverType | CometChat.ReceiverType | 1 (.group) |
| messageCategory | CometChat.MessageCategory | 0 (.message) |
| sentAt | Int | 1708934500 |
| deliveredAt | Double? | nil |
| readAt | Double? | nil |
| editedAt | Double? | nil |
| deletedAt | Double? | nil |
| editedBy | String? | nil |
| deletedBy | String? | nil |
| conversationId | String | "group_group_dev_team" |
| metaData | [String: Any]? | nil |
| tags | [String]? | nil |
| parentMessageId | Int | 0 |
| replyCount | Int | 0 |
| unreadRepliesCount | Int | 0 |
| mentionedUsers | [User] | [] (empty array) |
| mentionedMe | Bool | false |
| reactions | [ReactionCount] | [] (empty array) |
| quotedMessageId | Int | 0 |
| quotedMessage | BaseMessage? | nil |
| Parameter | Type | Value |
|---|---|---|
| uid | String | "user_12345" |
| name | String | "John Doe" |
| avatar | String | "https://data-us.cometchat.io/avatars/user_12345.png" |
| link | String? | nil |
| role | String | "default" |
| status | CometChat.UserStatus | 0 (.online) |
| statusMessage | String? | nil |
| lastActiveAt | Double | 1708934500.0 |
| metadata | [String: Any]? | nil |
| tags | [String]? | nil |
| hasBlockedMe | Bool | false |
| blockedByMe | Bool | false |
| Parameter | Type | Value |
|---|---|---|
| guid | String | "group_dev_team" |
| name | String | "Development Team" |
| icon | String | "https://data-us.cometchat.io/groups/dev_team.png" |
| description | String | "Team for development discussions" |
| type | CometChat.GroupType | "public" |
| owner | String | "user_admin" |
| membersCount | Int | 15 |
| createdAt | Double | 1700000000.0 |
| updatedAt | Double | 1708900000.0 |
| hasJoined | Bool | true |
| joinedAt | Double | 1705000000.0 |
| scope | CometChat.GroupMemberScope | "participant" |
| metadata | [String: Any]? | nil |
| tags | [String]? | nil |
Set Quoted Message
To set a quoted message for a message, use thequotedMessageId.
- Swift
sendMessage() method to send the text message to the recipient.
- Swift
TextMessage class constructor takes the following parameters:
| Parameter | Description | |
|---|---|---|
receiverID | UID of the user or GUID of the group receiving the message | Required |
messageText | The text message | Required |
receiverType | The type of the receiver- CometChatConstants.RECEIVER_TYPE_USER (user) or CometChatConstants.RECEIVER_TYPE_GROUP (group) | Required |
Sample Payloads - Quoted Message
Sample Payloads - Quoted Message
- Request
- Success Response
- Error Response
Method:
CometChat.sendTextMessage(message:)| Parameter | Type | Value |
|---|---|---|
| receiverUid | String | "cometchat-uid-2" |
| text | String | "I agree with this!" |
| receiverType | CometChat.ReceiverType | 0 (.user) |
| quotedMessageId | Int | 140 |
Media Message
In other words, as a sender, how do I send a media message like photos, videos & files? To send a media message to any user or group, you need to use thesendMediaMessage() method and pass a MediaMessage object to it.
Add Metadata
To send custom data along with a media message, you can use the metadata field provided inMediaMessage. A metadata field is a dictionary of type [String: Any] which will be received as it was sent without any processing from CometChat. It can be used to send any additional data that needs to be sent along with a message.
- Swift
- Objective C
Add Caption(Text along with Media Message)
To send a caption with a media message, you can usesetCaption method and pass text to it.
- Swift
Add Tags
To add a tag to a message you can useArray of strings that you need to set it to property tags.
- Swift
- Objective C
- By providing the File : You can directly share the file object while creating an object of the MediaMessage class. When the media message is sent using the sendMediaMessage() method, this file is then uploaded to CometChat servers and the URL of the file is sent in the success response of the sendMediaMessage() function.
- Swift
- Objective C
MediaMessage class. The initialize method of the MediaMessage class takes the following mandatory parameters:
| Parameter | Description | |
|---|---|---|
| receiverId | The UID or GUID of the recipient | Required |
| fileurl | The file path object to be sent | Required |
| messageType | The type of the message that needs to be sent which in this case can be: - image - video - audio - file | Required |
| receiverType | The type of the receiver to whom the message is to be sent - user - group | Required |
- By providing the URL of the File: The second way to send media messages using the CometChat SDK is to provide the SDK with the URL of any file that is hosted on your servers or any cloud storage. To achieve this you will have to make use of the Attachment class that is available in the MediaMessage class. For more information, you can refer to the below code snippet:
- Swift
Sample Payloads
Sample Payloads
- Request
- Success Response
- Error Response
Method:
CometChat.sendMediaMessage(message:)| Parameter | Type | Value |
|---|---|---|
| receiverUid | String | "cometchat-uid-2" |
| messageType | CometChat.MessageType | 1 (.image) |
| receiverType | CometChat.ReceiverType | 0 (.user) |
| fileUrl | String | "file:///Library/Developer/CoreSimulator/.../image.jpg" |
More Sample Payloads
More Sample Payloads
- Image to Group
- With Caption
Object Type: MediaMessage
attachment (Attachment):
receiver (Group):
| Parameter | Type | Value |
|---|---|---|
| id | Int | 148 |
| muid | String | "1708937000123_user_12345" |
| senderUid | String | "user_12345" |
| receiverUid | String | "group_dev_team" |
| messageType | CometChat.MessageType | 1 (.image) |
| receiverType | CometChat.ReceiverType | 1 (.group) |
| messageCategory | CometChat.MessageCategory | 0 (.message) |
| sentAt | Int | 1708937000 |
| conversationId | String | "group_group_dev_team" |
| caption | String? | nil |
| parentMessageId | Int | 0 |
| replyCount | Int | 0 |
| Parameter | Type | Value |
|---|---|---|
| fileName | String | "team_photo.png" |
| fileExtension | String | "png" |
| fileSize | Int | 512000 |
| fileMimeType | String | "image/png" |
| fileUrl | String | "https://data-us.cometchat.io/assets/images/team_photo.png" |
| Parameter | Type | Value |
|---|---|---|
| guid | String | "group_dev_team" |
| name | String | "Development Team" |
| icon | String | "https://data-us.cometchat.io/groups/dev_team.png" |
| description | String | "Team for development discussions" |
| type | CometChat.GroupType | "public" |
| owner | String | "user_admin" |
| membersCount | Int | 15 |
caption field provided by the MediaMessage class. To set the caption you can use the setCaption() method and at the receiver end, you can obtain the caption using the getCaption() method. As with text messages, the metadata field can be used with media messages as well. Any additional information can be passed along with the media message as a JSONObject.
Multiple Attachments in a Media Message
Starting version 3.0.906 & above the SDK supports sending of multiple attachments in a single media message. As in case for 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 a List 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 are sent in the success response of thesendMediaMessage()method.
- Swift
Sample Payloads - Multiple Attachments
Sample Payloads - Multiple Attachments
- Request
- Success Response
- Error Response
Method:
files (
CometChat.sendMediaMessage(message:)| Parameter | Type | Value |
|---|---|---|
| receiverUid | String | "cometchat-uid-2" |
| messageType | CometChat.MessageType | 4 (.file) |
| receiverType | CometChat.ReceiverType | 0 (.user) |
[File]):| Index | name | data |
|---|---|---|
| 0 | "FileName 1" | <binary_data> |
| 1 | "FileName 2" | <binary_data> |
| 2 | "FileName 3" | <binary_data> |
Custom Message
CometChat SDK allows you to send a completely custom message across. You can use this feature to send messages that do not fit in any default categories provided. In order to send a custom message, you need to use thesendCustomMessage() method.
The sendCustomMessage() methods takes an object of the CustomMessage which can be obtained using the below two constructor:
- Swift
custom.
The parameters involved are:
- receiverId - Unique id of the user or group to which the message is to be sent.
- receiverType - Type of the receiver i.e user or group
- type - custom message type that you need to set
- customData - The data to be passed as the message in the form of a Dictionary object.
CustomMessage class to set a specific type for the CustomeMessage.
Add Tags
To add a tag to a message you can useArray of strings that you need to set it to property tags.
- Swift
- Objective C
CustomMessage class is ready you can send the custom message using the sendCustomMessage() method.
- User(Swift)
- Group(Swift)
Sample Payloads
Sample Payloads
- Request
- Success Response
- Error Response
Method:
customData (
CometChat.sendCustomMessage(message:)| Parameter | Type | Value |
|---|---|---|
| receiverUid | String | "cometchat-uid-2" |
| receiverType | CometChat.ReceiverType | 0 (.user) |
| type | String | "Custom Type" |
[String: Any]):| Key | Type | Value |
|---|---|---|
| customKey | String | "customData" |
Real-World Examples
Real-World Examples
- Location Sharing
- Poll Message
- Payment Request
Object Type: CustomMessage
customData (
| Parameter | Type | Value |
|---|---|---|
| id | Int | 209 |
| muid | String | "1708944500123_user_12345" |
| senderUid | String | "user_12345" |
| receiverUid | String | "user_67890" |
| customType | String | "location" |
| subType | String? | nil |
| receiverType | CometChat.ReceiverType | 0 (.user) |
| messageCategory | CometChat.MessageCategory | 3 (.custom) |
| sentAt | Int | 1708944500 |
| conversationId | String | "user_12345_user_user_67890" |
| updateConversation | Bool | true |
| conversationText | String | "📍 Shared a location" |
[String: Any]):| Key | Type | Value |
|---|---|---|
| latitude | String | "37.7749" |
| longitude | String | "-122.4194" |
| address | String | "San Francisco, CA" |
| accuracy | Double | 10.5 |
Update Conversation
How can I decide whether the custom message should update last message of a conversation? By default, a custom message will update the last message of a conversation. If you wish to not update last message of conversation when a custom message is sent, please use updateConversation property of the Custom Message.- User(Swift)
Custom Notification Body
How can i customise the notification body of custom message? To add a custom notification body forPush, Email & SMS notification of a custom message you can use the conversationText property of Custom Message class.
- User(Swift)
It is also possible to send interactive messages from CometChat , to know more click here
Common Error Codes
| Error Code | Description | Resolution |
|---|---|---|
ERR_NOT_LOGGED_IN | User is not logged in | Call CometChat.login() first |
ERR_FILE_SIZE_EXCEEDED | File size exceeds maximum limit | Reduce file size to under 100MB |
ERR_INVALID_RECEIVER | Invalid receiver UID/GUID | Verify the receiver exists |
ERR_BLOCKED_BY_USER | Blocked by the receiver | Cannot send messages to users who blocked you |
ERR_SDK_NOT_INITIALIZED | SDK not initialized | Call CometChat.init() first |
ERR_NETWORK_ERROR | Network connectivity issue | Check internet connection and retry |