Skip to main content
Using CometChat, you can send three types of messages:
  1. Text Message is the most common and standard message type.
  2. Media Message for sending photos, videos and files.
  3. Custom Message, for sending completely custom data using JSON structures.
  4. Interactive Messages, for sending end-user interactive messages of type form, card and custom Interactive
You can also send metadata along with a text, media or custom message. Think, for example, if you’d want to share the user’s location with every message, you can use the metadata field

Text Message

Send a text message using CometChat.sendMessage() with a TextMessage object.
The TextMessage class constructor takes the following parameters: On success, sendMessage() method returns a TextMessage | MediaMessage | CustomMessage | BaseMessage object depending on the input message type.

Send While Offline

With offline support enabled, pass a MessageSentListener as the second argument to queue the message when the device has no connection. The same listener works with sendMediaMessage() and sendCustomMessage().
Offline, onMessagePending fires first, then onError with code FAILED_TO_FETCH as a not-connected notice, and onMessageSent follows once the message is sent on reconnect. In onError, look the message up with getPendingMessages() and check its getStatus(): PENDING means queued, FAILED means it failed. A send without a MessageSentListener is never queued; offline, its Promise rejects. See Send While Offline.

Media Message

Send images, videos, audio, or files using CometChat.sendMediaMessage(). There are two ways to send media messages:
  1. Upload a file — Pass a file object and CometChat uploads it automatically
  2. Send a URL — Provide a URL to media hosted on your server or cloud storage

Upload a File

Get the file from an input element and pass it to MediaMessage:

Send a URL

Send media hosted on your server or cloud storage using the Attachment class:
The MediaMessage class constructor takes the following parameters: On success, sendMediaMessage() returns a MediaMessage object.
With offline support enabled, pass a MessageSentListener to sendMediaMessage() to queue the message while offline. onError can then mean “queued”, not “failed”: check the message’s status. See Send While Offline.

Add Caption

Add text along with the media:
typescript mediaMessage.setCaption("Check out this photo!");

Add Metadata and Tags

Same as text messages:
The sendMediaMessage() method returns a MediaMessage object.

Multiple Attachments in a Media Message

The SDK supports sending multiple attachments in a single media message. A media message can carry up to a configurable maximum number of attachments (default 10, controlled by the file.count.max app setting). sendMediaMessage() rejects with ERR_FILE_COUNT_EXCEEDED if you exceed it — read the current limit at runtime with CometChat.getMaxAttachmentCount().
Recommended: upload first, then send. For a real composer — where you want a progress bar per file, and the ability to remove or retry individual files — create an upload request with CometChat.createUploadFileRequest(), upload your files through it, then collect the resulting Attachments (request.getAttachments()) and attach them here with setAttachments(). This decouples the (slow, cancellable) upload from the (instant) send. See Upload Files & Send Attachments for the full flow.
There are two ways to send a multi-attachment media message using the CometChat SDK:
  1. By providing an array of files: You can share an array 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 is sent in the success response of the sendMediaMessage() method. This is the simplest path, but it gives no upload progress and no per-file cancel/retry — for that, upload first.
Getting files:

Send Multiple URLs

Provide an array of Attachment objects that already point at hosted URLs. This is also the path the upload-then-send flow uses — the Attachments from an upload request’s getAttachments() are ready to pass straight to setAttachments().

Custom Message

Send structured data that doesn’t fit text or media categories — like location coordinates, polls, or game moves.
The CustomMessage class constructor takes the following parameters: On success, sendCustomMessage() returns a CustomMessage object.
With offline support enabled, pass a MessageSentListener to sendCustomMessage() to queue the message while offline. onError can then mean “queued”, not “failed”: check the message’s status. See Send While Offline.

Add Tags

Quote a Message

Control Conversation Update

By default, custom messages update the conversation’s last message. To prevent this:

Control Notifications

By default, custom messages don’t trigger notifications (push, email, or SMS). To enable them, call shouldSendNotification(true) before sending. See Custom message templates for how notifications are handled for custom messages.

Custom Notification Text

Set custom text for push, email, and SMS notifications. Notifications use this text only when they’re enabled for the message (see Control Notifications). It is also shown as the conversation-list preview.
The sendCustomMessage() method returns a CustomMessage object.

Card Message

A CardMessage (category card) is a rich, structured card rendered from Card Schema JSON.
Design cards visually with Card Builder. Build your card messages in the CometChat Dashboard and export the Card Schema JSON — instead of writing it by hand.
Card messages cannot be sent through the SDK. CardMessage is receive-only — there is no sendCardMessage() method. Cards are created server-side via the Platform (REST) API or the Dashboard Bubble Builder, and delivered to clients through the onCardMessageReceived callback of the MessageListener.
To receive and render cards, see the Card Messages guide.

Next Steps

Receive Messages

Listen for incoming messages in real-time

Edit Message

Edit previously sent messages

Delete Message

Delete sent messages