Skip to main content
CometChat supports three types of messages: 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.sendTextMessage() with a TextMessage object.
The TextMessage class constructor takes the following parameters: On success, sendTextMessage() returns a TextMessage object containing all information about the sent message.

Add Metadata

Send custom data along with a text message using the metaData property:

Add Tags

Quote a Message

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 path and CometChat uploads it automatically
  2. Send a URL — Provide a URL to media hosted on your server or cloud storage

Upload a File

Send a URL

Use the Attachment class to send media hosted on your server or cloud storage:
The MediaMessage class constructor takes the following parameters: On success, sendMediaMessage() returns a MediaMessage object.

Add Caption

Add Metadata and Tags

Same as text messages:

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) — read the current limit at runtime with CometChat.getMaxFileCount().
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 set them here on the message’s attachments property. 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 File objects 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 URLs of the files are 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.
The MediaMessage class constructor takes the following parameters:
  1. By providing the URL of the multiple files: The second way to send multiple attachments using the CometChat SDK is to provide the SDK with Attachment objects that already point at files hosted on your servers or any cloud storage. This is also the path the upload-then-send flow uses — the Attachments from an upload request’s getAttachments() are ready to set straight on the message’s attachments property. For more information, you can refer to the below code snippet:
When sending a message built from pre-uploaded or already-hosted attachments, leave the message’s files property nil — build the message with the fileurl: constructor and an empty string. Passing an empty files array causes the send to fail with an invalid-message error, even though attachments is populated.

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.

Add Tags

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:
It is also possible to send interactive messages from CometChat. To learn more, see Interactive Messages.

Next Steps

Receive Messages

Listen for incoming messages in real-time

Edit Message

Edit previously sent messages

Delete Message

Delete sent messages