> ## Documentation Index
> Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Message Structure and Hierarchy

> Understand CometChat Android SDK message categories, message types, base messages, and message hierarchy for chat apps.

> [accordion] AI Integration Quick Reference
>
> **Message Categories:**
>
> * **Message**: text, image, video, audio, file
> * **Custom**: Developer-defined types (e.g., location)
> * **Interactive**: form, card, customInteractive
> * **Action**: groupMember, message (system-generated)
> * **Call**: audio, video (with status: initiated, ongoing, ended, etc.)
>
> **Check message type:**
>
> ```kotlin theme={null}
> when (message.category) {
>     CometChatConstants.CATEGORY_MESSAGE -> { /* Handle message */ }
>     CometChatConstants.CATEGORY_CUSTOM -> { /* Handle custom */ }
>     CometChatConstants.CATEGORY_ACTION -> { /* Handle action */ }
>     CometChatConstants.CATEGORY_CALL -> { /* Handle call */ }
> }
> ```

Every message in CometChat belongs to a category and has a specific type within that category. Understanding this hierarchy helps you handle different message types correctly.

## Message Hierarchy

![](https://mintcdn.com/cometchat-22654f5b/dDWpooIQ48haNjyU/images/76f2cb7e-bvoxc4srq8tenc66v5dsah0sxmup8mbhqae59irsfboesbs98fexfs1ouqvw6218-b163973e26cc92682c683dfc90dbd452.png?fit=max\&auto=format\&n=dDWpooIQ48haNjyU\&q=85\&s=78753cb64971efe8929449ccf564a29b)

## Categories Overview

| Category | Types | Description |
| - | - | - |
| `message` | `text`, `image`, `video`, `audio`, `file` | Standard user messages |
| `custom` | Developer-defined | Custom data (location, polls, etc.) |
| `interactive` | `form`, `card`, `customInteractive` | Messages with actionable UI elements |
| `action` | `groupMember`, `message` | System-generated events |
| `call` | `audio`, `video` | Call-related messages |

## Checking Message Category and Type

Use `getCategory()` and `getType()` on a [`BaseMessage`](https://www.cometchat.com/docs/sdk/reference/messages#basemessage) to determine how to handle a received message:

> [tab] Java
>
> ```java theme={null}
> String category = message.getCategory();
> String type = message.getType();
>
> switch (category) {
>     case CometChatConstants.CATEGORY_MESSAGE:
>         if (type.equals(CometChatConstants.MESSAGE_TYPE_TEXT)) {
>             TextMessage textMsg = (TextMessage) message;
>             Log.d(TAG, "Text: " + textMsg.getText());
>         } else if (type.equals(CometChatConstants.MESSAGE_TYPE_IMAGE)) {
>             MediaMessage mediaMsg = (MediaMessage) message;
>             Log.d(TAG, "Image URL: " + mediaMsg.getAttachment().getFileUrl());
>         }
>         break;
>     case CometChatConstants.CATEGORY_CUSTOM:
>         CustomMessage customMsg = (CustomMessage) message;
>         Log.d(TAG, "Custom type: " + type + ", data: " + customMsg.getCustomData());
>         break;
>     case CometChatConstants.CATEGORY_ACTION:
>         Action actionMsg = (Action) message;
>         Log.d(TAG, "Action: " + actionMsg.getAction());
>         break;
>     case CometChatConstants.CATEGORY_CALL:
>         Call callMsg = (Call) message;
>         Log.d(TAG, "Call status: " + callMsg.getCallStatus());
>         break;
> }
> ```

> [tab] Kotlin
>
> ```kotlin theme={null}
> val category = message.category
> val type = message.type
>
> when (category) {
>     CometChatConstants.CATEGORY_MESSAGE -> {
>         if (type == CometChatConstants.MESSAGE_TYPE_TEXT) {
>             val textMsg = message as TextMessage
>             Log.d(TAG, "Text: ${textMsg.text}")
>         } else if (type == CometChatConstants.MESSAGE_TYPE_IMAGE) {
>             val mediaMsg = message as MediaMessage
>             Log.d(TAG, "Image URL: ${mediaMsg.attachment?.fileUrl}")
>         }
>     }
>     CometChatConstants.CATEGORY_CUSTOM -> {
>         val customMsg = message as CustomMessage
>         Log.d(TAG, "Custom type: $type, data: ${customMsg.customData}")
>     }
>     CometChatConstants.CATEGORY_ACTION -> {
>         val actionMsg = message as Action
>         Log.d(TAG, "Action: ${actionMsg.action}")
>     }
>     CometChatConstants.CATEGORY_CALL -> {
>         val callMsg = message as Call
>         Log.d(TAG, "Call status: ${callMsg.callStatus}")
>     }
> }
> ```

## Message

Standard user messages. Types: `text`, `image`, `video`, `audio`, `file`.

## Custom

Developer-defined messages for content that doesn't fit standard categories (e.g., location sharing, polls). Set your own `type` string to identify the custom message.

## Interactive

Messages with embedded UI elements users can interact with directly in chat.

Types: `form`, `card`, `customInteractive`.

> [!NOTE]
>
> See [Interactive Messages](https://www.cometchat.com/docs/sdk/android/v4/interactive-messages.md) for full details.

## Action

System-generated messages triggered by actions on group members or messages. Represented as [`Action`](https://www.cometchat.com/docs/sdk/reference/messages#action) objects.

Types: `groupMember`, `message`.

The `action` property specifies what happened:

**For `groupMember`:** `joined`, `left`, `kicked`, `banned`, `unbanned`, `added`, `scopeChanged`

**For `message`:** `edited`, `deleted`

## Call

Call-related messages. Types: `audio`, `video`. Represented as [`Call`](https://www.cometchat.com/docs/sdk/reference/messages#call) objects.

The `status` property indicates the call state: `initiated`, `ongoing`, `canceled`, `rejected`, `unanswered`, `busy`, `ended`.

***

## Next Steps

> [card] [Send Message](https://www.cometchat.com/docs/sdk/android/v4/send-message.md)
>
> Send text, media, and custom messages

> [card] [Receive Messages](https://www.cometchat.com/docs/sdk/android/v4/receive-messages.md)
>
> Handle incoming messages of all types

> [card] [Additional Message Filtering](https://www.cometchat.com/docs/sdk/android/v4/additional-message-filtering.md)
>
> Filter messages by category, type, and other parameters

> [card] [Interactive Messages](https://www.cometchat.com/docs/sdk/android/v4/interactive-messages.md)
>
> Create and handle interactive form and card messages


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.