Skip to main content
FieldValue
Key ClassesTextMessage, MediaMessage, CustomMessage
Key MethodssendMessage(), sendMediaMessage(), sendCustomMessage()
Receiver TypesCometChat.RECEIVER_TYPE.USER, CometChat.RECEIVER_TYPE.GROUP
Message TypesTEXT, IMAGE, VIDEO, AUDIO, FILE, CUSTOM
PrerequisitesSDK initialized, user logged in
CometChat supports three types of messages:
TypeMethodUse Case
TextsendMessage()Plain text messages
MediasendMediaMessage()Images, videos, audio, files
CustomsendCustomMessage()Location, polls, or any JSON data

Text Message

Send a text message using CometChat.sendMessage() with a TextMessage object.
let receiverID: string = "UID",
  messageText: string = "Hello world!",
  receiverType: string = CometChat.RECEIVER_TYPE.USER,
  textMessage: CometChat.TextMessage = new CometChat.TextMessage(
    receiverID,
    messageText,
    receiverType
  );

CometChat.sendMessage(textMessage).then(
  (message: CometChat.TextMessage) => {
    console.log("Message sent successfully:", message);
  },
  (error: CometChat.CometChatException) => {
    console.log("Message sending failed with error:", error);
  }
);
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() returns a TextMessage | MediaMessage | CustomMessage | BaseMessage object containing all information related to the sent 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 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 using a React Native image picker and pass it to MediaMessage:
ImagePicker.showImagePicker(options, (response) => {
  if (response.didCancel || response.error) return;

  const file = {
    name: Platform.OS === "android" ? response.fileName : response.fileName || "Camera_001.jpeg",
    type: response.type,
    uri: Platform.OS === "android" ? response.uri : response.uri.replace("file://", ""),
  };
  // Use this file object in MediaMessage
});
let receiverID: string = "UID",
  messageType: string = CometChat.MESSAGE_TYPE.IMAGE,
  receiverType: string = CometChat.RECEIVER_TYPE.USER,
  mediaMessage: CometChat.MediaMessage = new CometChat.MediaMessage(
    receiverID,
    file,
    messageType,
    receiverType
  );

CometChat.sendMediaMessage(mediaMessage).then(
  (message: CometChat.MediaMessage) => {
    console.log("Media message sent successfully", message);
  },
  (error: CometChat.CometChatException) => {
    console.log("Media message sending failed with error", error);
  }
);

Send a URL

Send media hosted on your server or cloud storage using the Attachment class:
let receiverID: string = "UID",
  messageType: string = CometChat.MESSAGE_TYPE.IMAGE,
  receiverType: string = CometChat.RECEIVER_TYPE.USER,
  mediaMessage: CometChat.MediaMessage = new CometChat.MediaMessage(
    receiverID,
    "",
    messageType,
    receiverType
  );

let file: Object = {
  name: "mario",
  extension: "png",
  mimeType: "image/png",
  url: "https://pngimg.com/uploads/mario/mario_PNG125.png",
};

let attachment: CometChat.Attachment = new CometChat.Attachment(file);
mediaMessage.setAttachment(attachment);

CometChat.sendMediaMessage(mediaMessage).then(
  (message: CometChat.MediaMessage) => {
    console.log("Media message sent successfully", message);
  },
  (error: CometChat.CometChatException) => {
    console.log("Media message sending failed with error", error);
  }
);
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:
mediaMessage.setCaption("Check out this photo!");

Add Metadata and Tags

mediaMessage.setMetadata({ location: "Paris" });
mediaMessage.setTags(["vacation"]);
mediaMessage.setQuotedMessageId(10);

Multiple Attachments in a Media Message

Starting version 3.0.9 & above, the SDK supports sending multiple attachments in a single media message. There are two ways:
  1. By providing an array of files — Pass an array of file objects and CometChat uploads them automatically.
  2. By providing URLs — Use the Attachment class with multiple URLs.

Upload Multiple Files

let receiverID: string = "UID",
  messageType: string = CometChat.MESSAGE_TYPE.FILE,
  receiverType: string = CometChat.RECEIVER_TYPE.USER,
  mediaMessage: CometChat.MediaMessage = new CometChat.MediaMessage(
    receiverID,
    files,
    messageType,
    receiverType
  );

CometChat.sendMediaMessage(mediaMessage).then(
  (message: CometChat.MediaMessage) => {
    console.log("Media message sent successfully", message);
  },
  (error: CometChat.CometChatException) => {
    console.log("Media message sending failed with error", error);
  }
);

Send Multiple URLs

let receiverID: string = "UID",
  messageType: string = CometChat.MESSAGE_TYPE.IMAGE,
  receiverType: string = CometChat.RECEIVER_TYPE.USER,
  mediaMessage: CometChat.MediaMessage = new CometChat.MediaMessage(
    receiverID,
    "",
    messageType,
    receiverType
  );

let attachment1: Object = {
  name: "mario",
  extension: "png",
  mimeType: "image/png",
  url: "https://pngimg.com/uploads/mario/mario_PNG125.png",
};

let attachment2: Object = {
  name: "jaguar",
  extension: "png",
  mimeType: "image/png",
  url: "https://pngimg.com/uploads/jaguar/jaguar_PNG20759.png",
};

let attachments: Array<CometChat.Attachment> = [];
attachments.push(new CometChat.Attachment(attachment1));
attachments.push(new CometChat.Attachment(attachment2));

mediaMessage.setAttachments(attachments);

CometChat.sendMediaMessage(mediaMessage).then(
  (message: CometChat.MediaMessage) => {
    console.log("Media message sent successfully", message);
  },
  (error: CometChat.CometChatException) => {
    console.log("Media message sending failed with error", error);
  }
);

Custom Message

Send structured data that doesn’t fit text or media categories — like location coordinates, polls, or game moves.
let receiverID: string = "UID",
  customData: Object = {
    latitude: "50.6192171633316",
    longitude: "-72.68182268750002",
  },
  customType: string = "location",
  receiverType: string = CometChat.RECEIVER_TYPE.USER,
  customMessage: CometChat.CustomMessage = new CometChat.CustomMessage(
    receiverID,
    receiverType,
    customType,
    customData
  );

CometChat.sendCustomMessage(customMessage).then(
  (message: CometChat.CustomMessage) => {
    console.log("Custom message sent successfully", message);
  },
  (error: CometChat.CometChatException) => {
    console.log("Custom message sending failed with error", error);
  }
);
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

customMessage.setTags(["starredMessage"]);

Quote a Message

customMessage.setQuotedMessageId(10);

Control Conversation Update

By default, custom messages update the conversation’s last message. To prevent this:
customMessage.shouldUpdateConversation(false);

Custom Notification Text

Set custom text for push, email, and SMS notifications:
customMessage.setConversationText("Shared a location");

Card Message

A CardMessage 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, through the onCardMessageReceived callback of the MessageListener.To create and send a Card Message, use the REST API. See the Send Message REST API reference for the message creation flow.
On the receiving end, the CardMessage object gives you access to the card payload and its related fields.
const card: object = cardMessage.getCard();             // raw card schema/payload
const text: string = cardMessage.getText();             // preview text for notifications and the conversation list
const fallbackText: string = cardMessage.getFallbackText(); // shown when the card cannot be rendered
const tags: Array<string> = cardMessage.getTags();      // tags associated with the message
The CardMessage class provides the following methods:
MethodReturnsDescription
getCard()objectThe raw card schema/payload passed to the Cards renderer.
getText()stringPreview text for notifications and the conversation list.
getFallbackText()stringText displayed when the card payload cannot be rendered.
getTags()Array<string>Tags associated with the message.
CardMessage extends BaseMessage, so it also exposes the standard message fields (getId(), getSender(), getReceiverId(), getSentAt(), getCategory() = card, etc.). To handle incoming Card Messages on the client, implement onCardMessageReceived on your MessageListener.

Render a Card Message

A CardMessage carries raw Card Schema JSON in getCard(). To draw it natively, pass it to the CometChat Cards renderer (@cometchat/cards-react-native) via the CometChatCardView component. It is a pure renderer: you hand it the card JSON and an action callback, and you own all action behavior (opening URLs, navigating to chats, API calls, etc.). See Campaigns → Rendering Cards for the dependency setup, the CometChatCardView example, and the supported card actions. If the card JSON is empty or invalid, fall back to getFallbackText() (then getText()).

Next Steps

Receive Messages

Listen for incoming messages in real-time

Edit Message

Edit previously sent messages

Delete Message

Delete sent messages