Skip to main content
Quick Reference for AI Agents & Developers
// Send interactive message (form, card, buttons)
const interactiveData = {
  title: "Quick Survey",
  formFields: [
    { elementType: "textInput", elementId: "name", label: "Your Name" },
    { elementType: "dropdown", elementId: "rating", label: "Rating",
      options: [{ label: "Good", value: "4" }, { label: "Great", value: "5" }] }
  ],
  submitElement: { elementType: "button", elementId: "submit", buttonText: "Submit" }
};

const message = new CometChat.InteractiveMessage(
  receiverID,
  CometChat.RECEIVER_TYPE.GROUP,
  "form",  // type: form, card, etc.
  interactiveData
);
await CometChat.sendInteractiveMessage(message);

// Listen for interactive messages
CometChat.addMessageListener("LISTENER", new CometChat.MessageListener({
  onInteractiveMessageReceived: (msg) => {
    const data = msg.getInteractiveData();
  }
}));

// Set interaction goal
message.setInteractionGoal(new CometChat.InteractionGoal(
  ["submitBtn"], CometChat.INTERACTION_TYPE.ANY_OF
));
Interactive messages contain embedded interactive elements like forms, buttons, and inputs that users can interact with directly in the chat interface.
Available via: SDK | REST API | UI Kits

Use Cases

TypeDescription
FormsSurveys, feedback forms, data collection
ButtonsQuick actions, confirmations, navigation
CardsProduct cards, booking confirmations
PollsVoting, decision making

InteractiveMessage Properties

PropertyDescriptionRequired
receiverIdUID or GUID of recipientYes
receiverTypeUSER or GROUPYes
messageTypeType of interactive message (e.g., “form”)Yes
interactiveDataJSON object with interactive contentYes
allowSenderInteractionCan sender interact (default: false)No
interactionGoalDefines completion criteriaNo

Send an Interactive Message

const interactiveData = {
  title: "Quick Survey",
  formFields: [
    {
      elementType: "textInput",
      elementId: "name",
      label: "Your Name",
      placeholder: { text: "Enter your name" }
    },
    {
      elementType: "dropdown",
      elementId: "rating",
      label: "How would you rate us?",
      options: [
        { label: "Excellent", value: "5" },
        { label: "Good", value: "4" },
        { label: "Average", value: "3" }
      ]
    }
  ],
  submitElement: {
    elementType: "button",
    elementId: "submitBtn",
    buttonText: "Submit",
    action: {
      actionType: "urlNavigation",
      url: "https://example.com/thanks"
    }
  }
};

const message = new CometChat.InteractiveMessage(
  "group-123",
  CometChat.RECEIVER_TYPE.GROUP,
  "form",
  interactiveData
);

CometChat.sendInteractiveMessage(message).then(
  (msg) => console.log("Interactive message sent:", msg),
  (error) => console.log("Failed:", error)
);

Receive Interactive Messages

Listen for incoming interactive messages:
const listenerID = "INTERACTIVE_LISTENER";

CometChat.addMessageListener(
  listenerID,
  new CometChat.MessageListener({
    onInteractiveMessageReceived: (message) => {
      console.log("Interactive message received:", message);
      
      const data = message.getInteractiveData();
      const type = message.getType();
      
      // Render based on type
      renderInteractiveMessage(type, data);
    }
  })
);

// Remove listener when done
CometChat.removeMessageListener(listenerID);

Interaction Goals

Track when users complete interactions with your message.

Goal Types

GoalDescription
ANYCompleted with any interaction
ANY_OFCompleted when any specified element is interacted with
ALL_OFCompleted when all specified elements are interacted with
NONENever marked as completed

Set an Interaction Goal

const interactionGoal = new CometChat.InteractionGoal(
  ["submitBtn", "ratingInput"],  // Element IDs
  CometChat.INTERACTION_TYPE.ALL_OF  // All must be interacted with
);

const message = new CometChat.InteractiveMessage(
  "group-123",
  CometChat.RECEIVER_TYPE.GROUP,
  "form",
  interactiveData
);

message.setInteractionGoal(interactionGoal);

CometChat.sendInteractiveMessage(message);

Listen for Goal Completion

CometChat.addMessageListener(
  "GOAL_LISTENER",
  new CometChat.MessageListener({
    onInteractionGoalCompleted: (receipt) => {
      console.log("Interaction goal completed:", receipt);
      // User has completed the required interactions
    }
  })
);

Form Field Types

TypeDescription
textInputSingle or multi-line text input
dropdownSelect from options
checkboxMultiple selection
radioSingle selection
buttonAction button

Text Input

{
  elementType: "textInput",
  elementId: "feedback",
  label: "Your Feedback",
  optional: false,
  maxLines: 3,
  placeholder: { text: "Enter your feedback" }
}
{
  elementType: "dropdown",
  elementId: "department",
  label: "Select Department",
  defaultValue: "sales",
  options: [
    { label: "Sales", value: "sales" },
    { label: "Support", value: "support" },
    { label: "Billing", value: "billing" }
  ]
}

Checkbox

{
  elementType: "checkbox",
  elementId: "interests",
  label: "Select Interests",
  defaultValue: ["tech"],
  options: [
    { label: "Technology", value: "tech" },
    { label: "Sports", value: "sports" },
    { label: "Music", value: "music" }
  ]
}

Allow Sender Interaction

By default, the sender cannot interact with their own interactive message. Enable it if needed:
const message = new CometChat.InteractiveMessage(
  "group-123",
  CometChat.RECEIVER_TYPE.GROUP,
  "form",
  interactiveData
);

message.setAllowSenderInteraction(true);

CometChat.sendInteractiveMessage(message);

Next Steps