- 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 Map structures.
- A Card Message, a structured, interactive card message created server-side via the REST API and delivered to clients.
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 thesetMetadata method and pass a Map to it.
- Dart
Add Tags
To add a tag to a message you can assign value in.tags variable of the TextMessage Class. tags accepts a list of tags.
- Dart
sendMessage() method to send the text message to the recipient.
- Dart (User)
- Dart (group)
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- CometChatReceiverType.user (user) or CometChatReceiverType.group (group) | Required |
| type | The type of the message that needs to be sent which in this case can be: CometChatMessageType.text__(text) |
TextMessage object which includes all information related to the sent message.
Set Quoted Message
To set a quoted message for a message, use thesetQuotedMessageId and setQuotedMessage method of the TextMessage class. This method accepts the ID of the message to be quoted.
- Dart
sendMessage() method to send the text message to the recipient.
- Dart (User)
- Dart (Group)
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 |
TextMessage object which includes all information related to the sent message.
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 thesetMetadata method and pass a Map to it.
- Dart
Add Caption(Text along with Media Message)
- Dart
Add Tags
To add a tag to a message you can use thesetTags() method of the MediaMessage Class. The setTags() method accepts a list of tags.
- Dart
- 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.
- Dart
MediaMessage class constructor takes the following parameters:
| Parameter | Description | |
|---|---|---|
| receiverId | The UID or GUID of the recipient | Required |
| file | The file object to be sent | Required |
| messageType | The type of the message that needs to be sent which, in this case, can be: 1. CometChatMessageType.image (image) 2. CometChatMessageType.video (video) 3. CometChatMessageType.audio (audio) 4. CometChatMessageType.file (file) | Required |
| receiverType | The type of the receiver to whom the message is to be sent, i.e., CometChatReceiverType.user (user) or CometChatReceiverType.group (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:
- Dart
MediaMessage object which includes all information related to the sent message.
If you wish to send a caption or some text along with the Media Message, you can use the caption field provided by the MediaMessage class. To get and set the caption you can use the .caption variable . 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 Map.
Send Multiple Media Files
You can send multiple media files (images, videos, audio, or documents) in a single message. This enables richer and more efficient conversations.- Dart
File Size and Count Validation
The SDK automatically validates file size and count when sending media messages. You can configure these limits through Settings in the CometChat Dashboard.| Validation | Description |
|---|---|
| File Size | Maximum size per file (configurable in Dashboard) |
| File Count | Maximum number of files per message (configurable in Dashboard) |
onError callback will be triggered with details about the validation error.
- Dart
Custom Message
In other words, as a sender, how do I send a custom message like location co-ordinates? CometChat allows you to send custom messages which are neither text nor media messages. 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 constructor.
- Dart
custom.
The parameters involved are:
receiverUid- Unique id of the user or group to which the message is to be sent.receiverType- Type of the receiver i.e user or groupcustomType- custom message type that you need to setcustomData- The data to be passed as the message in the form of aMap.
CustomMessage class to set a specific type for the custom message. This can be achieved using the subtype field.
Add Tags
To add a tag to a message you can assign value in.tags variable of the CustomMessage Class. tags accepts a list of tags.
- Dart
CustomMessage class is ready you can send the custom message using the sendCustomMessage() method.
- User
- Group
CustomMessage class.
Update Conversation
How can I decide whether the custom message should update the last message of a conversation? By default, a custom message will update the last message of a conversation. If you wish to not update the last message of the conversation when a custom message is sent, please useupdateConversation (boolean value) method of the Custom Message.
- User
- Group
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 method of Custom Message class.
- User
- Group
Card Message
In other words, as a sender, how do I send a card message? ACardMessage is a structured, interactive message rendered as a card bubble. It belongs to the card category and carries a block of card schema JSON that the CometChat Cards library draws.
Card Messages cannot be sent through the SDK. The
CardMessage class is receive-only — it has no public constructor and the SDK exposes no sendCardMessage() method. Card Messages are created server-side via the Platform REST API or the Dashboard Bubble Builder, and delivered to clients like any other message.To create and send a Card Message, use the REST API. See the Send Message REST API reference for the message creation flow.CardMessage object gives you access to the card payload and its related fields.
- Dart
CardMessage class provides the following methods:
| Method | Returns | Description |
|---|---|---|
getCard() | Map<String, dynamic>? | The raw card schema/payload passed to the Cards renderer. |
getText() | String? | Optional text shown alongside the card. |
getFallbackText() | String? | Text displayed when the card payload cannot be rendered. |
getTags() | List<String>? | Tags associated with the message. |
CardMessage extends BaseMessage, so it also exposes the standard message fields (id, sender, receiverUid, sentAt, category = card, etc.).
To handle incoming Card Messages on the client, implement onCardMessageReceived on your MessageListener.
Render a Card Message
ACardMessage carries raw card-schema JSON in getCard(). To draw it natively, use the CometChat Cards renderer package (cometchat_cards) — the same renderer the UI Kit’s card bubble wraps. It is a pure renderer: you hand it the card JSON and an action callback, and you own all action behavior.
Add the Cards dependency
Add the cards package to yourpubspec.yaml:
Render the card
Pass the card JSON (jsonEncode(cardMessage.getCard())) to the renderer and handle actions through the callback.
- Dart
The Cards library is a pure renderer — it never executes actions, it only emits them through the callback. You own all behavior (opening URLs, navigating to chats, API calls, etc.). See Campaigns → Supported Card Actions for the full list of action types.When rendering directly, fallback is your responsibility: if the card JSON is empty or invalid, fall back to
cardMessage.getFallbackText() (then getText()).