Skip to main content
Quick Reference for AI Agents & Developers
// Message categories
CometChat.CATEGORY_MESSAGE      // text, image, video, audio, file
CometChat.CATEGORY_CUSTOM       // custom types you define
CometChat.CATEGORY_ACTION       // system events (join, leave, kick)
CometChat.CATEGORY_CALL         // audio, video calls
CometChat.CATEGORY_INTERACTIVE  // form, card, customInteractive

// Check message type
const category = message.getCategory();
const type = message.getType();

if (category === CometChat.CATEGORY_MESSAGE) {
  if (type === CometChat.MESSAGE_TYPE.TEXT) {
    console.log(message.getText());
  }
}
Every CometChat message belongs to a category and type. Understanding this hierarchy helps you handle messages correctly in your application.

Message Hierarchy

Categories Overview

CategoryDescriptionTypes
messageStandard chat messagestext, image, video, audio, file
customDeveloper-defined messagesAny custom type
interactiveInteractive UI elementsform, card, customInteractive
actionSystem-generated eventsgroupMember, message
callCall-related messagesaudio, video

Message Category

Standard messages for text and media content.
TypeDescriptionUse Case
textPlain text messageChat messages
imageImage attachmentPhoto sharing
videoVideo attachmentVideo sharing
audioAudio attachmentVoice messages
fileFile attachmentDocument sharing
// Check message category and type
if (message.getCategory() === CometChat.CATEGORY_MESSAGE) {
  switch (message.getType()) {
    case CometChat.MESSAGE_TYPE.TEXT:
      console.log("Text:", message.getText());
      break;
    case CometChat.MESSAGE_TYPE.IMAGE:
    case CometChat.MESSAGE_TYPE.VIDEO:
    case CometChat.MESSAGE_TYPE.AUDIO:
    case CometChat.MESSAGE_TYPE.FILE:
      console.log("Media:", message.getAttachment());
      break;
  }
}

Custom Category

Custom messages allow you to send any data structure that doesn’t fit standard message types.
Custom messages have no predefined types. You define your own type string to identify different custom message formats.
Common Use Cases:
  • Location sharing (type: "location")
  • Polls (type: "poll")
  • Product cards (type: "product")
  • Meeting invites (type: "meeting")
// Send custom location message
const customMessage = new CometChat.CustomMessage(
  receiverID,
  CometChat.RECEIVER_TYPE.USER,
  "location",  // Your custom type
  {
    latitude: 37.7749,
    longitude: -122.4194,
    address: "San Francisco, CA"
  }
);

await CometChat.sendCustomMessage(customMessage);

// Handle received custom message
if (message.getCategory() === CometChat.CATEGORY_CUSTOM) {
  const type = message.getType();
  const data = message.getCustomData();
  
  if (type === "location") {
    console.log("Location:", data.latitude, data.longitude);
  }
}

Interactive Category

Interactive messages contain UI elements users can interact with directly in the chat.
TypeDescriptionUse Case
formEmbedded formSurveys, data collection
cardInteractive cardProduct displays, previews
customInteractiveCustom interactive elementAny custom UI
For detailed implementation, see Interactive Messages.

Action Category

System-generated messages for group and message events.

Group Member Actions

ActionDescription
joinedMember joined the group
leftMember left the group
kickedMember was kicked
bannedMember was banned
unbannedMember was unbanned
addedMember was added
scopeChangedMember scope was changed

Message Actions

ActionDescription
editedMessage was edited
deletedMessage was deleted
// Handle action messages
if (message.getCategory() === CometChat.CATEGORY_ACTION) {
  const action = message.getAction();
  const actionBy = message.getActionBy();
  const actionOn = message.getActionOn();
  
  switch (action) {
    case CometChat.ACTION_TYPE.MEMBER_JOINED:
      console.log(`${actionOn.getName()} joined the group`);
      break;
    case CometChat.ACTION_TYPE.MEMBER_KICKED:
      console.log(`${actionOn.getName()} was kicked by ${actionBy.getName()}`);
      break;
    case CometChat.ACTION_TYPE.MEMBER_SCOPE_CHANGED:
      console.log(`${actionOn.getName()} scope changed to ${message.getNewScope()}`);
      break;
  }
}

Call Category

Call-related messages with status tracking.
TypeDescription
audioVoice call
videoVideo call

Call Status Values

StatusDescription
initiatedCall started
ongoingCall in progress
canceledCaller cancelled
rejectedReceiver rejected
unansweredNo answer
busyReceiver busy
endedCall completed
// Handle call messages
if (message.getCategory() === CometChat.CATEGORY_CALL) {
  const callType = message.getType(); // "audio" or "video"
  const status = message.getStatus();
  
  switch (status) {
    case CometChat.CALL_STATUS.INITIATED:
      console.log(`${callType} call initiated`);
      break;
    case CometChat.CALL_STATUS.ONGOING:
      console.log("Call in progress");
      break;
    case CometChat.CALL_STATUS.ENDED:
      console.log("Call ended");
      break;
    case CometChat.CALL_STATUS.CANCELLED:
      console.log("Call cancelled");
      break;
    case CometChat.CALL_STATUS.REJECTED:
      console.log("Call rejected");
      break;
    case CometChat.CALL_STATUS.UNANSWERED:
      console.log("Call unanswered");
      break;
    case CometChat.CALL_STATUS.BUSY:
      console.log("User busy");
      break;
  }
}

Complete Message Handler

function handleMessage(message) {
  const category = message.getCategory();
  
  switch (category) {
    case CometChat.CATEGORY_MESSAGE:
      handleStandardMessage(message);
      break;
    case CometChat.CATEGORY_CUSTOM:
      handleCustomMessage(message);
      break;
    case CometChat.CATEGORY_ACTION:
      handleActionMessage(message);
      break;
    case CometChat.CATEGORY_CALL:
      handleCallMessage(message);
      break;
    case CometChat.CATEGORY_INTERACTIVE:
      handleInteractiveMessage(message);
      break;
  }
}

Next Steps