Quick Reference for AI Agents & Developers
- Send text:
CometChat.sendTextMessage(message:onSuccess:onError:) - Send media:
CometChat.sendMediaMessage(message:onSuccess:onError:) - Receive messages:
CometChat.addMessageListener("UNIQUE_ID", self) - Fetch history:
MessagesRequest.MessageRequestBuilder().build()→messagesRequest.fetchPrevious(onSuccess:onError:) - Message types:
TextMessage,MediaMessage,CustomMessage,InteractiveMessage(all extendBaseMessage) - Related: Send Message · Receive Message · Typing Indicators
Message Data Models
All message types in CometChat inherit from theBaseMessage class. Understanding these data models is essential for working with messages.
BaseMessage Properties
TheBaseMessage class contains properties common to all message types:
| Property | Type | Description |
|---|---|---|
id | Int | Server-assigned unique message identifier |
muid | String | Client-generated unique identifier |
senderUid | String | UID of the message sender |
receiverUid | String | UID of the receiver (user or group) |
messageType | MessageType | Type: .text, .image, .video, .audio, .file, .custom |
receiverType | ReceiverType | .user or .group |
sentAt | Int | Unix timestamp (seconds) when sent |
deliveredAt | Double | Unix timestamp when delivered |
readAt | Double | Unix timestamp when read |
deliveredToMeAt | Double | When delivered to current user |
readByMeAt | Double | When read by current user |
sender | User? | User object of the sender |
receiver | AppEntity? | User or Group object |
metaData | [String: Any]? | Custom metadata dictionary |
conversationId | String | Unique conversation identifier |
parentMessageId | Int | Parent message ID (for threads) |
replyCount | Int | Number of replies |
mentionedUsers | [User] | Array of mentioned users |
mentionedMe | Bool | Whether current user is mentioned |
reactions | [ReactionCount] | Reaction counts |
editedAt | Double | When edited |
deletedAt | Double | When deleted |
TextMessage
ExtendsBaseMessage with:
| Property | Type | Description |
|---|---|---|
text | String | The text content |
tags | [String]? | Message tags |
MediaMessage
ExtendsBaseMessage with:
| Property | Type | Description |
|---|---|---|
attachment | Attachment? | Single attachment |
attachments | [Attachment]? | Multiple attachments |
caption | String? | Caption text |
tags | [String]? | Message tags |
CustomMessage
ExtendsBaseMessage with:
| Property | Type | Description |
|---|---|---|
customData | [String: Any]? | Custom JSON data |
type | String? | Custom type identifier |
subType | String? | Custom subtype |
Attachment
| Property | Type | Description |
|---|---|---|
fileName | String | File name |
fileExtension | String | File extension |
fileSize | Double | Size in bytes |
fileMimeType | String | MIME type |
fileUrl | String | URL of the file |
Success & Failure Responses
Send Message Success
When a message is sent successfully, you receive the complete message object with server-assigned properties:- Swift
Common Error Codes
| Error Code | Description |
|---|---|
ERR_NOT_LOGGED_IN | User is not logged in |
ERR_UID_NOT_FOUND | Receiver UID not found |
ERR_GUID_NOT_FOUND | Group GUID not found |
ERR_BLOCKED_BY_RECEIVER | Blocked by receiver |
ERR_NOT_A_MEMBER | Not a member of the group |