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.

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.

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

Starting version 3.0.9 & above the SDK supports sending multiple attachments in a single media message. As in the case of a single attachment in a media message, there are two ways you can send Media Messages using the CometChat SDK:
  1. By providing an array of files: You can now 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.
Getting files:

Send Multiple URLs

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

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.

Next Steps

Receive Messages

Listen for incoming messages in real-time

Edit Message

Edit previously sent messages

Delete Message

Delete sent messages