> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-mintlify-715169f7.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Message class reference for CometChat SDKs

> Class reference for message objects returned by CometChat SDK methods, covering BaseMessage and subclasses like TextMessage, MediaMessage, and CardMessage.

This page documents the message classes used across all CometChat SDKs. All message objects share the same structure regardless of platform.

All properties are accessed via getter methods.

## Class Hierarchy

```
BaseMessage
├── TextMessage
├── MediaMessage
├── CustomMessage
├── CardMessage
└── Action
```

***

## BaseMessage

`BaseMessage` is the base class for all message types. Every message object — whether it's a text message, media message, or custom message — extends this class.

### Properties

| Property           | Getter                    | Return Type       | Description                                                            |
| ------------------ | ------------------------- | ----------------- | ---------------------------------------------------------------------- |
| id                 | `getId()`                 | `number`          | Unique message ID                                                      |
| conversationId     | `getConversationId()`     | `string`          | ID of the conversation this message belongs to                         |
| parentMessageId    | `getParentMessageId()`    | `number`          | ID of the parent message (for threaded messages)                       |
| muid               | `getMuid()`               | `string`          | Client-generated unique message ID                                     |
| sender             | `getSender()`             | `User`            | Sender of the message                                                  |
| receiver           | `getReceiver()`           | `User` \| `Group` | Receiver of the message                                                |
| receiverId         | `getReceiverId()`         | `string`          | UID/GUID of the receiver                                               |
| type               | `getType()`               | `string`          | Message type (e.g., `"text"`, `"image"`, `"file"`, `"custom"`)         |
| receiverType       | `getReceiverType()`       | `string`          | Receiver type (`"user"` or `"group"`)                                  |
| category           | `getCategory()`           | `MessageCategory` | Message category (e.g., `"message"`, `"action"`, `"call"`, `"custom"`) |
| sentAt             | `getSentAt()`             | `number`          | Timestamp when the message was sent (epoch seconds)                    |
| deliveredAt        | `getDeliveredAt()`        | `number`          | Timestamp when the message was delivered                               |
| readAt             | `getReadAt()`             | `number`          | Timestamp when the message was read                                    |
| deliveredToMeAt    | `getDeliveredToMeAt()`    | `number`          | Timestamp when the message was delivered to the logged-in user         |
| readByMeAt         | `getReadByMeAt()`         | `number`          | Timestamp when the message was read by the logged-in user              |
| editedAt           | `getEditedAt()`           | `number`          | Timestamp when the message was edited                                  |
| editedBy           | `getEditedBy()`           | `string`          | UID of the user who edited the message                                 |
| deletedAt          | `getDeletedAt()`          | `number`          | Timestamp when the message was deleted                                 |
| deletedBy          | `getDeletedBy()`          | `string`          | UID of the user who deleted the message                                |
| replyCount         | `getReplyCount()`         | `number`          | Number of replies to this message                                      |
| unreadRepliesCount | `getUnreadRepliesCount()` | `number`          | Number of unread replies                                               |
| data               | `getData()`               | `Object`          | Raw data payload of the message                                        |
| metadata           | `getMetadata()`           | `Object`          | Custom metadata attached to the message                                |
| rawMessage         | `getRawMessage()`         | `Object`          | Raw JSON of the message as received from the server                    |

### Conditional Properties

These properties may or may not be populated depending on the method or request configuration used to fetch the message.

| Property        | Getter                 | Return Type       | Description                                             |
| --------------- | ---------------------- | ----------------- | ------------------------------------------------------- |
| reactions       | `getReactions()`       | `ReactionCount[]` | Array of reaction counts on the message                 |
| mentionedUsers  | `getMentionedUsers()`  | `User[]`          | Array of users mentioned in the message                 |
| hasMentionedMe  | `hasMentionedMe()`     | `boolean`         | Whether the logged-in user was mentioned in the message |
| quotedMessageId | `getQuotedMessageId()` | `number`          | ID of the quoted message (if this is a reply)           |
| quotedMessage   | `getQuotedMessage()`   | `BaseMessage`     | The quoted message object (if this is a reply)          |

***

## TextMessage

`TextMessage` extends [BaseMessage](#basemessage) and represents a text-based chat message.

It inherits all properties from `BaseMessage` and adds the following.

### Properties

| Property         | Getter                  | Return Type        | Description                                                                                             |
| ---------------- | ----------------------- | ------------------ | ------------------------------------------------------------------------------------------------------- |
| text             | `getText()`             | `string`           | The text content of the message                                                                         |
| metadata         | `getMetadata()`         | `Object`           | Custom metadata attached to the message (includes extension data like data masking, link preview, etc.) |
| data             | `getData()`             | `Object`           | Raw data payload including `text`, `resource`, `metadata`, `moderation`, and `entities`                 |
| moderationStatus | `getModerationStatus()` | `ModerationStatus` | Moderation status of the message. Returns `"unmoderated"` if not moderated.                             |

### Conditional Properties

These properties may or may not be populated depending on the method or request configuration used to fetch the message.

| Property | Getter      | Return Type | Description                      |
| -------- | ----------- | ----------- | -------------------------------- |
| tags     | `getTags()` | `string[]`  | Tags associated with the message |

***

## MediaMessage

`MediaMessage` extends [BaseMessage](#basemessage) and represents a message with media attachments such as images, videos, audio files, or documents.

It inherits all properties from `BaseMessage` and adds the following.

### Properties

| Property         | Getter                  | Return Type        | Description                                                                 |
| ---------------- | ----------------------- | ------------------ | --------------------------------------------------------------------------- |
| caption          | `getCaption()`          | `string`           | Caption text for the media message                                          |
| attachment       | `getAttachment()`       | `Attachment`       | The primary attachment of the media message                                 |
| attachments      | `getAttachments()`      | `Attachment[]`     | All attachments of the media message                                        |
| url              | `getURL()`              | `string`           | URL of the media file                                                       |
| metadata         | `getMetadata()`         | `Object`           | Custom metadata attached to the message                                     |
| data             | `getData()`             | `Object`           | Raw data payload of the message                                             |
| moderationStatus | `getModerationStatus()` | `ModerationStatus` | Moderation status of the message. Returns `"unmoderated"` if not moderated. |

### Conditional Properties

These properties may or may not be populated depending on the method or request configuration used to fetch the message.

| Property | Getter      | Return Type | Description                      |
| -------- | ----------- | ----------- | -------------------------------- |
| tags     | `getTags()` | `string[]`  | Tags associated with the message |

***

## CustomMessage

`CustomMessage` extends [BaseMessage](#basemessage) and represents a developer-defined message with a custom data payload.

It inherits all properties from `BaseMessage` and adds the following.

### Properties

| Property           | Getter                     | Return Type | Description                                                  |
| ------------------ | -------------------------- | ----------- | ------------------------------------------------------------ |
| customData         | `getCustomData()`          | `Object`    | The custom data payload set by the developer                 |
| subType            | `getSubType()`             | `string`    | Sub type of the custom message                               |
| conversationText   | `getConversationText()`    | `string`    | Preview text displayed in the conversation list              |
| updateConversation | `willUpdateConversation()` | `boolean`   | Whether this message updates the conversation's last message |
| sendNotification   | `willSendNotification()`   | `boolean`   | Whether a push notification is sent for this message         |
| metadata           | `getMetadata()`            | `Object`    | Custom metadata attached to the message                      |
| data               | `getData()`                | `Object`    | Raw data payload of the message                              |

### Conditional Properties

These properties may or may not be populated depending on the method or request configuration used to fetch the message.

| Property | Getter      | Return Type | Description                      |
| -------- | ----------- | ----------- | -------------------------------- |
| tags     | `getTags()` | `string[]`  | Tags associated with the message |

***

## Action

`Action` extends [BaseMessage](#basemessage) and represents a system-generated action message such as a member joining, leaving, or being banned from a group.

It inherits all properties from `BaseMessage` and adds the following.

### Properties

| Property  | Getter           | Return Type                        | Description                                                                     |
| --------- | ---------------- | ---------------------------------- | ------------------------------------------------------------------------------- |
| action    | `getAction()`    | `string`                           | The action being performed (e.g., `"joined"`, `"left"`, `"kicked"`, `"banned"`) |
| message   | `getMessage()`   | `string`                           | The default human-readable action message                                       |
| actionBy  | `getActionBy()`  | `User` \| `Group` \| `BaseMessage` | The entity that performed the action                                            |
| actionOn  | `getActionOn()`  | `User` \| `Group` \| `BaseMessage` | The entity on which the action was performed                                    |
| actionFor | `getActionFor()` | `User` \| `Group` \| `BaseMessage` | The entity for whom the action was performed                                    |
| oldScope  | `getOldScope()`  | `string`                           | Previous scope of the member (for scope change actions)                         |
| newScope  | `getNewScope()`  | `string`                           | New scope of the member (for scope change actions)                              |
| rawData   | `getRawData()`   | `Object`                           | Raw JSON data of the action message                                             |
| metadata  | `getMetadata()`  | `Object`                           | Custom metadata attached to the action message                                  |

***

## Call

`Call` extends [BaseMessage](#basemessage) and represents a voice or video call message.

It inherits all properties from `BaseMessage` and adds the following.

### Properties

| Property      | Getter               | Return Type                                                                        | Description                                                                                |
| ------------- | -------------------- | ---------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
| sessionId     | `getSessionId()`     | `string`                                                                           | Unique session ID of the call                                                              |
| callInitiator | `getCallInitiator()` | [`User`](/sdk/reference/entities#user)                                             | The user who initiated the call                                                            |
| callReceiver  | `getCallReceiver()`  | [`User`](/sdk/reference/entities#user) \| [`Group`](/sdk/reference/entities#group) | The user or group receiving the call                                                       |
| action        | `getAction()`        | `string`                                                                           | The call action (e.g., `"initiated"`, `"ongoing"`, `"ended"`, `"cancelled"`, `"rejected"`) |
| initiatedAt   | `getInitiatedAt()`   | `number`                                                                           | Timestamp when the call was initiated                                                      |
| joinedAt      | `getJoinedAt()`      | `number`                                                                           | Timestamp when the call was joined                                                         |
| rawData       | `getRawData()`       | `Object`                                                                           | Raw JSON data of the call message                                                          |
| metadata      | `getMetadata()`      | `Object`                                                                           | Custom metadata attached to the call message                                               |

***

## AIAssistantMessage

`AIAssistantMessage` extends [BaseMessage](#basemessage) and represents the full assistant reply persisted after an AI Agent run completes. It is received via the `onAIAssistantMessageReceived` callback of the [MessageListener](/sdk/javascript/all-real-time-listeners#message-listener).

It inherits all properties from `BaseMessage` and adds the following.

### Properties

| Property             | Getter                      | Return Type              | Description                                                                      |
| -------------------- | --------------------------- | ------------------------ | -------------------------------------------------------------------------------- |
| assistantMessageData | `getAssistantMessageData()` | `AIAssistantMessageData` | The assistant message data containing runId, threadId, and text                  |
| elements             | `getElements()`             | `AIAssistantElement[]`   | Ordered content blocks of the reply (text, cards, etc.). Empty array when absent |

### AIAssistantMessageData

| Property | Getter          | Return Type | Description                            |
| -------- | --------------- | ----------- | -------------------------------------- |
| runId    | `getRunId()`    | `string`    | The run ID of the agent execution      |
| threadId | `getThreadId()` | `string`    | The thread ID of the conversation      |
| text     | `getText()`     | `string`    | The full text of the assistant's reply |

***

## AIAssistantElement

`AIAssistantElement` is a single ordered content block returned by `AIAssistantMessage.getElements()`. Each element is a `{ type, value }` envelope; the SDK returns the `value` raw and never interprets it — branch on `getType()` to decide how to read `getData()`.

| Property | Getter      | Return Type | Description                                                                                |
| -------- | ----------- | ----------- | ------------------------------------------------------------------------------------------ |
| type     | `getType()` | `string`    | The element type — `"text"`, `"card"`, or another platform-defined type                    |
| data     | `getData()` | `any`       | The element's raw body. For `"text"` it is a string; for `"card"` it is `{ card, cardId }` |

***

## CardMessage

`CardMessage` extends [BaseMessage](#basemessage) and represents a standalone card message (category `card`). It is received via the `onCardMessageReceived` callback of the [MessageListener](/sdk/javascript/all-real-time-listeners#message-listener). The SDK returns the card payload raw; your app renders it. See the [Card Messages guide](/sdk/javascript/card-messages).

It inherits all properties from `BaseMessage` and adds the following.

### Properties

| Property     | Getter              | Return Type             | Description                                                                      |
| ------------ | ------------------- | ----------------------- | -------------------------------------------------------------------------------- |
| card         | `getCard()`         | `Object` \| `undefined` | The raw Card Schema JSON object (`data.card`); `undefined` when absent           |
| text         | `getText()`         | `string`                | The plain-text content accompanying the card (`data.text`); used as preview text |
| fallbackText | `getFallbackText()` | `string`                | Text to display when the card cannot be rendered (`card.fallbackText`)           |
| tags         | `getTags()`         | `string[]`              | Tags associated with the message                                                 |

***

## AIToolResultMessage

`AIToolResultMessage` extends [BaseMessage](#basemessage) and represents the output of a tool call made during an AI Agent run. It is received via the `onAIToolResultReceived` callback of the [MessageListener](/sdk/javascript/all-real-time-listeners#message-listener).

It inherits all properties from `BaseMessage` and adds the following.

### Properties

| Property              | Getter                       | Return Type               | Description                                                           |
| --------------------- | ---------------------------- | ------------------------- | --------------------------------------------------------------------- |
| toolResultMessageData | `getToolResultMessageData()` | `AIToolResultMessageData` | The tool result data containing runId, threadId, text, and toolCallId |

### AIToolResultMessageData

| Property   | Getter            | Return Type | Description                                    |
| ---------- | ----------------- | ----------- | ---------------------------------------------- |
| runId      | `getRunId()`      | `string`    | The run ID of the agent execution              |
| threadId   | `getThreadId()`   | `string`    | The thread ID of the conversation              |
| text       | `getText()`       | `string`    | The text output of the tool                    |
| toolCallId | `getToolCallId()` | `string`    | The ID of the tool call this result belongs to |

***

## AIToolArgumentMessage

`AIToolArgumentMessage` extends [BaseMessage](#basemessage) and represents the arguments passed to a tool during an AI Agent run. It is received via the `onAIToolArgumentsReceived` callback of the [MessageListener](/sdk/javascript/all-real-time-listeners#message-listener).

It inherits all properties from `BaseMessage` and adds the following.

### Properties

| Property                | Getter                         | Return Type                 | Description                                                      |
| ----------------------- | ------------------------------ | --------------------------- | ---------------------------------------------------------------- |
| toolArgumentMessageData | `getToolArgumentMessageData()` | `AIToolArgumentMessageData` | The tool argument data containing runId, threadId, and toolCalls |

### AIToolArgumentMessageData

| Property  | Getter           | Return Type    | Description                              |
| --------- | ---------------- | -------------- | ---------------------------------------- |
| runId     | `getRunId()`     | `string`       | The run ID of the agent execution        |
| threadId  | `getThreadId()`  | `string`       | The thread ID of the conversation        |
| toolCalls | `getToolCalls()` | `AIToolCall[]` | Array of tool calls with their arguments |

### AIToolCall

| Property      | Getter               | Return Type          | Description                               |
| ------------- | -------------------- | -------------------- | ----------------------------------------- |
| id            | `getId()`            | `string`             | Unique tool call ID                       |
| type          | `getType()`          | `string`             | Type of the tool call                     |
| displayName   | `getDisplayName()`   | `string`             | Display name of the tool                  |
| executionText | `getExecutionText()` | `string`             | Execution text for the tool               |
| function      | `getFunction()`      | `AIToolCallFunction` | The function details (name and arguments) |

### AIToolCallFunction

| Property  | Getter           | Return Type | Description                                         |
| --------- | ---------------- | ----------- | --------------------------------------------------- |
| name      | `getName()`      | `string`    | Name of the function being called                   |
| arguments | `getArguments()` | `string`    | JSON string of the arguments passed to the function |

***

## AIAssistantBaseEvent

`AIAssistantBaseEvent` is the base class for all real-time streaming events from an AI Agent run. It is received via the `onAIAssistantEventReceived` callback of the [AIAssistantListener](/sdk/javascript/all-real-time-listeners#ai-assistant-listener).

The `type` field identifies the specific event (e.g., `"run_started"`, `"tool_call_started"`, `"text_message_content"`, `"run_finished"`).

### Properties

| Property        | Getter                 | Return Type | Description                                   |
| --------------- | ---------------------- | ----------- | --------------------------------------------- |
| type            | `getType()`            | `string`    | The event type identifier                     |
| conversationId  | `getConversationId()`  | `string`    | The conversation ID associated with the event |
| messageId       | `getMessageId()`       | `string`    | The message ID associated with the event      |
| parentMessageId | `getParentMessageId()` | `string`    | The parent message ID (if in a thread)        |
| data            | `getData()`            | `object`    | Additional event-specific data                |
| data.timestamp  | `getTimestamp()`       | `number`    | Timestamp of the event                        |
| data.runId      | `getRunId()`           | `string`    | The run ID of the agent execution             |
| data.threadId   | `getThreadId()`        | `string`    | The thread ID of the conversation             |

***

## AIAssistantCardStartedEvent

`AIAssistantCardStartedEvent` extends [AIAssistantBaseEvent](#aiassistantbaseevent) and is emitted (event type `card_start`) when an AI Agent begins generating a card during a streaming run. See the [Card Messages guide](/sdk/javascript/card-messages#real-time-card-streaming-events).

It inherits all properties from `AIAssistantBaseEvent` and adds the following.

### Properties

| Property        | Getter                 | Return Type | Description                                    |
| --------------- | ---------------------- | ----------- | ---------------------------------------------- |
| streamMessageId | `getStreamMessageId()` | `string`    | ID correlating the stream events for this card |
| cardId          | `getCardId()`          | `string`    | ID of the card being generated                 |
| executionText   | `getExecutionText()`   | `string`    | Text shown while the card is being generated   |

***

## AIAssistantCardReceivedEvent

`AIAssistantCardReceivedEvent` extends [AIAssistantBaseEvent](#aiassistantbaseevent) and is emitted (event type `card`) when the full card payload is delivered during a streaming run.

It inherits all properties from `AIAssistantBaseEvent` and adds the following.

### Properties

| Property        | Getter                 | Return Type | Description                                             |
| --------------- | ---------------------- | ----------- | ------------------------------------------------------- |
| streamMessageId | `getStreamMessageId()` | `string`    | ID correlating the stream events for this card          |
| cardId          | `getCardId()`          | `string`    | ID of the card                                          |
| card            | `getCard()`            | `any`       | The raw card payload to render; `undefined` when absent |

***

## AIAssistantCardEndedEvent

`AIAssistantCardEndedEvent` extends [AIAssistantBaseEvent](#aiassistantbaseevent) and is emitted (event type `card_end`) when card generation finishes during a streaming run.

It inherits all properties from `AIAssistantBaseEvent` and adds the following.

### Properties

| Property        | Getter                 | Return Type | Description                                    |
| --------------- | ---------------------- | ----------- | ---------------------------------------------- |
| streamMessageId | `getStreamMessageId()` | `string`    | ID correlating the stream events for this card |
| cardId          | `getCardId()`          | `string`    | ID of the card that finished generating        |
