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:
ParameterDescriptionRequired
receiverIDUID of the user or GUID of the group receiving the messageYes
messageTextThe text message contentYes
receiverTypeCometChat.RECEIVER_TYPE.USER or CometChat.RECEIVER_TYPE.GROUPYes
On success, sendMessage() method returns a TextMessage | MediaMessage | CustomMessage | BaseMessage object depending on the input message type.

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:
ParameterDescriptionRequired
receiverIDUID of the user or GUID of the groupYes
fileFile object to upload, or empty string if using URLYes
messageTypeCometChat.MESSAGE_TYPE.IMAGE, VIDEO, AUDIO, or FILEYes
receiverTypeCometChat.RECEIVER_TYPE.USER or GROUPYes
On success, sendMediaMessage() returns a MediaMessage object.

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 cancel or retry individual files — upload the files with CometChat.uploadFiles(), collect the resulting Attachments, 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 returned by uploadFiles() 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:
ParameterDescriptionRequired
receiverIDUID of the user or GUID of the groupYes
receiverTypeCometChat.RECEIVER_TYPE.USER or GROUPYes
customTypeYour custom type string (e.g., "location", "poll")Yes
customDataJSON object with your custom dataYes
On success, sendCustomMessage() returns a CustomMessage object.

Add Tags

Quote a Message

Control Conversation Update

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

Custom Notification Text

Set custom text for push, email, and SMS notifications:
The sendCustomMessage() method returns a CustomMessage object.

Card Message

A CardMessage (category card) is a rich, structured card rendered from Card Schema JSON.
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