Skip to main content

Documentation Index

Fetch the complete documentation index at: https://cometchat-22654f5b-docs-android-v6-beta2.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

FieldValue
Key ClassesInteractiveMessage, InteractionGoal, Interaction, InteractionReceipt
Key MethodsCometChat.sendInteractiveMessage(), CometChat.markAsInteracted()
Key ConstantsInteractionGoalType.anyAction, InteractionGoalType.anyOf, InteractionGoalType.allOf, InteractionGoalType.none
Listener EventsonInteractiveMessageReceived, onInteractionGoalCompleted
PrerequisitesSDK initialized, user logged in
// Create and send an interactive form message
InteractiveMessage interactiveMessage = InteractiveMessage(
  interactiveData: interactiveData,  // Map<String, dynamic> with form fields
  receiverUid: "UID",
  type: "form",
  receiverType: CometChatReceiverType.user,
  allowSenderInteraction: true,
  interactionGoal: InteractionGoal(type: InteractionGoalType.none),
);
CometChat.sendInteractiveMessage(interactiveMessage,
  onSuccess: (InteractiveMessage message) {},
  onError: (CometChatException e) {},
);

// Mark as interacted
CometChat.markAsInteracted(messageId, elementId,
  onSuccess: (String message) {},
  onError: (CometChatException e) {},
);

// Listen for interactive messages
CometChat.addMessageListener("LISTENER_ID", this);
// onInteractiveMessageReceived(InteractiveMessage message) { }
// onInteractionGoalCompleted(InteractionReceipt receipt) { }
Interactive messages embed UI elements like forms, buttons, and dropdowns directly within chat messages. Users can interact with these elements without leaving the conversation, enabling surveys, quick actions, and data collection.
Available via: SDK | REST API | UI Kits

InteractiveMessage

The InteractiveMessage class extends BaseMessage and represents a message with embedded interactive content.
ParameterTypeDescriptionRequired
receiverUidStringThe UID of the user or GUID of the groupYes
receiverTypeStringCometChatReceiverType.user or CometChatReceiverType.groupYes
typeStringType identifier (e.g., "form", "card")Yes
interactiveDataMap<String, dynamic>JSON structure defining the interactive elementsYes
allowSenderInteractionboolWhether sender can interact with the messageNo (default: false)
interactionGoalInteractionGoalDefines when the interaction is considered completeNo (default: none)
tagsList<String>Tags associated with the messageNo
muidStringUnique message identifier for deduplicationNo
parentMessageIdintID of the parent message (for threads)No
metadataMap<String, dynamic>Custom metadata attached to the messageNo

Send an Interactive Message

Use CometChat.sendInteractiveMessage() to send an interactive message.
final Map<String, dynamic> interactiveData = {
  "title": "Survey",
  "formFields": [
    {
      "elementType":  "textInput" ,
      "elementId": "name",
      "optional": false,
      "label": "Name",
      "placeholder": {
        "text": "Enter text here"
        }
    },
    {
      "elementType":  "textInput",
      "elementId": "age",
      "optional": true,
      "label": "Age",
      "maxLines": 1,
      "placeholder": {
        "text": "Enter text here"
        }
    },
    {
      "elementType":  "Select",
      "elementId": "checkBox1",
      "optional": true,
      "label": "Check box element",
      "defaultValue":["chk_option_2"],
      "options" : [
        {
          "label": "Option 1",
          "value": "chk_option_1",
        },
        {
          "label": "Option 2",
          "value": "chk_option_2",
        }

      ]
    },
    {
      "elementType": "dropdown",
      "elementId": "gender",
      "optional": false,
      "label": "Gender",
      "defaultValue":"male",
      "options" : [
        {
          "label": "Male",
          "value": "male",
        },
        {
          "label": "Female",
          "value": "female",
        }

      ]
    },
  ],
  "submitElement": {
    "elementType": "button",
    "elementId": "submitButton",
    "buttonText": "Submit",
    "disableAfterInteracted": false,
    "action": {
      "actionType": "urlNavigation",
      "url": "https://www.cometchat.com/",
    }
  },
};



InteractiveMessage interactiveMessage =
InteractiveMessage(interactiveData: interactiveData,
                   receiverUid: "cometchat-uid-3", //Replace this with receiver id
                   type: "form",
                   receiverType: "user",//replace this with receiver type
                   allowSenderInteraction: true,
                   muid: DateTime.now().millisecondsSinceEpoch.toString(),
                   interactionGoal: InteractionGoal(
                     type: InteractionGoalType.none
                   )
                  );


CometChat.sendInteractiveMessage(interactiveMessage, onSuccess: (InteractiveMessage message){

print(interactiveMessage);

}, onError: (CometChatException excep){
print(excep);
});
The sendInteractiveMessage() method returns an InteractiveMessage object on success.
On Success — An InteractiveMessage object containing all details of the sent interactive message:InteractiveMessage Object:
ParameterTypeDescriptionSample Value
idnumberUnique message ID501
metadataobjectCustom metadata attached to the message{}
receiverobjectReceiver user objectSee below ↓
editedBystringUID of the user who edited the messagenull
conversationIdstringUnique conversation identifier"cometchat-uid-1_user_cometchat-uid-3"
sentAtnumberEpoch timestamp when the message was sent1745554729
receiverUidstringUID of the receiver"cometchat-uid-3"
typestringType of the message"form"
readAtnumberEpoch timestamp when the message was read0
deletedBystringUID of the user who deleted the messagenull
deliveredAtnumberEpoch timestamp when the message was delivered0
deletedAtnumberEpoch timestamp when the message was deleted0
replyCountnumberNumber of replies to this message0
senderobjectSender user objectSee below ↓
receiverTypestringType of the receiver"user"
editedAtnumberEpoch timestamp when the message was edited0
parentMessageIdnumberID of the parent message (for threads)0
readByMeAtnumberEpoch timestamp when read by the current user0
categorystringMessage category"interactive"
deliveredToMeAtnumberEpoch timestamp when delivered to the current user0
updatedAtnumberEpoch timestamp when the message was last updated1745554729
interactiveDataobjectStructured data for the interactive element{"title": "Survey", "formFields": [...]}
interactionsarrayList of user interactions with the message[]
interactionGoalobjectIntended outcome of interacting with the message{"type": "none", "elementIds": []}
tagsarrayList of tags associated with the message[]
allowSenderInteractionbooleanWhether the sender can interact with the messagetrue
unreadRepliesCountnumberCount of unread replies0
quotedMessageIdnumberID of the quoted messagenull

sender Object:
ParameterTypeDescriptionSample Value
uidstringUnique identifier of the sender"cometchat-uid-1"
namestringDisplay name of the sender"Andrew Joseph"
linkstringProfile linknull
avatarstringAvatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-1.webp"
metadataobjectCustom metadata{}
statusstringOnline status"online"
rolestringUser role"default"
statusMessagestringStatus messagenull
tagsarrayUser tags[]
hasBlockedMebooleanWhether this user has blocked the current userfalse
blockedByMebooleanWhether the current user has blocked this userfalse
lastActiveAtnumberEpoch timestamp of last activity1745554700

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUnique identifier of the receiver"cometchat-uid-3"
namestringDisplay name of the receiver"Kevin Hart"
linkstringProfile linknull
avatarstringAvatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
metadataobjectCustom metadata{}
statusstringOnline status"offline"
rolestringUser role"default"
statusMessagestringStatus messagenull
tagsarrayUser tags[]
hasBlockedMebooleanWhether this user has blocked the current userfalse
blockedByMebooleanWhether the current user has blocked this userfalse
lastActiveAtnumberEpoch timestamp of last activity1745550000
ParameterTypeDescriptionSample Value
codestringError code identifier"ERR_CHAT_API_FAILURE"
messagestringHuman-readable error message"Failed to send the interactive message."
detailsstringAdditional technical details"An unexpected error occurred while processing the request."

Interactive Elements

The interactiveData map defines the UI elements. Common element types:
Element TypeDescription
textInputSingle or multi-line text field
dropdownSingle-select dropdown menu
SelectMulti-select checkbox group
buttonClickable button with action

Text Input

{
  "elementType": "textInput",
  "elementId": "name",
  "optional": false,
  "label": "Name",
  "maxLines": 1,  // Optional: limit to single line
  "placeholder": {"text": "Enter text here"}
}
{
  "elementType": "dropdown",
  "elementId": "country",
  "optional": false,
  "label": "Country",
  "defaultValue": "us",
  "options": [
    {"label": "United States", "value": "us"},
    {"label": "United Kingdom", "value": "uk"},
    {"label": "Canada", "value": "ca"}
  ]
}

Checkbox (Multi Select)

{
  "elementType": "Select",
  "elementId": "preferences",
  "optional": true,
  "label": "Preferences",
  "defaultValue": ["email"],
  "options": [
    {"label": "Email notifications", "value": "email"},
    {"label": "SMS notifications", "value": "sms"},
    {"label": "Push notifications", "value": "push"}
  ]
}

Submit Button

{
  "elementType": "button",
  "elementId": "submitBtn",
  "buttonText": "Submit",
  "disableAfterInteracted": true,
  "action": {
    "actionType": "urlNavigation",
    "url": "https://example.com/submit"
  }
}

Interaction Goals

An InteractionGoal defines when the user’s interaction with the message is considered complete. Use this to track engagement and trigger follow-up actions. InteractionGoal Parameters:
ParameterTypeDescriptionRequired
typeStringThe type of interaction goal (see goal types below)Yes
elementIdsList<String>List of element IDs associated with this goalNo (default: [])
Goal TypeConstantDescription
Any InteractionInteractionGoalType.anyActionComplete when any element is interacted with
Any of SpecificInteractionGoalType.anyOfComplete when any of the specified elements is interacted with
All of SpecificInteractionGoalType.allOfComplete when all specified elements are interacted with
NoneInteractionGoalType.noneNever considered complete (default)

Set an Interaction Goal

List<String> elementIds = ["name", "gender", "submitButton"];
InteractionGoal interactionGoal = InteractionGoal(
  type: InteractionGoalType.allOf,
  elementIds: elementIds,
);

InteractiveMessage interactiveMessage = InteractiveMessage(
  interactiveData: interactiveData,
  receiverUid: "cometchat-uid-3",
  type: "form",
  receiverType: "user",
  interactionGoal: interactionGoal,
);

CometChat.sendInteractiveMessage(interactiveMessage,
  onSuccess: (InteractiveMessage message) {
    debugPrint("Interactive message sent successfully: $message");
  },
  onError: (CometChatException excep) {
    debugPrint("Interactive message sending failed with error: ${excep.message}");
  },
);
You would be tracking every interaction users perform on an InteractiveMessage (captured as Interaction objects) and comparing those with the defined InteractionGoal. The completion of a goal can vary depending on the goal type. This user interaction tracking mechanism provides a flexible and efficient way to monitor user engagement within an interactive chat session. By defining clear interaction goals and checking user interactions against these goals, you can manage user engagement and improve the overall chat experience in your CometChat-enabled application.

Interactions

An Interaction represents a single user action on an interactive element.
PropertyTypeDescription
elementIdStringIdentifier of the interacted element
interactedAtDateTimeTimestamp indicating when the interaction occurred

Mark as Interacted

Use CometChat.markAsInteracted() to record when a user interacts with an element. This method marks a message as interacted by identifying it with the provided ID and logs the interactive element associated with the interaction.
Future<void> recordInteraction() async {
  int messageId = 0; // set to your interactive message id
  String interactedElementId = ""; // set to the element id

  await CometChat.markAsInteracted(
    messageId,
    interactedElementId,
    onSuccess: (String message) {
      // after success
    },
    onError: (CometChatException excep) {
      // after error
    },
  );
}
ParameterTypeDescriptionRequired
messageIdintThe ID of the interactive messageYes
interactedElementIdStringThe element ID that was interacted withYes
On Success — A String message confirming the interaction was recorded:
ParameterTypeDescriptionSample Value
messagestringSuccess confirmation message"Message marked as interacted successfully."
ParameterTypeDescriptionSample Value
codestringError code identifier"ERR_CHAT_API_FAILURE"
messagestringHuman-readable error message"Failed to mark the message as interacted."
detailsstringAdditional technical details"An unexpected error occurred while processing the request."

Real-Time Events

Register a MessageListener to receive interactive message events.

Receive Interactive Messages

The onInteractiveMessageReceived event listener is triggered when an InteractiveMessage is received.
class DemoClass with MessageListener{

String listenerId = "UNIQUE_LISTENER_ID"; //Replace with unique listener id


CometChat.addMessageListener(_listenerId, this);



  @override
void onInteractiveMessageReceived(InteractiveMessage message){

  //TODO  implement onInteractiveMessageReceived event 
}

}

Interaction Goal Completed

The onInteractionGoalCompleted event listener is invoked when an interaction goal is achieved. InteractionReceipt Properties:
PropertyTypeDescription
messageIdintThe ID of the interactive message
senderUserThe user who completed the interaction
receiverTypeStringType of the receiver ("user" or "group")
receiverIdStringUID or GUID of the receiver
interactionsList<Interaction>List of interactions that satisfied the goal
class DemoClass with MessageListener{

String listenerId = "UNIQUE_LISTENER_ID"; //Replace with unique listener id


CometChat.addMessageListener(_listenerId, this);



@override
void onInteractionGoalCompleted(InteractionReceipt receipt) {
  //TODO implement onInteractionGoalCompleted
}

}
These event listeners offer your application a way to provide real-time updates in response to incoming interactive messages and goal completions, contributing to a more dynamic and responsive user chat experience.
Always remove listeners when they’re no longer needed to prevent memory leaks.
CometChat.removeMessageListener("UNIQUE_LISTENER_ID");

Allow Sender Interaction

By default, the sender cannot interact with their own interactive message. Set allowSenderInteraction to true to enable sender interaction:
InteractiveMessage interactiveMessage = InteractiveMessage(
  interactiveData: interactiveData,
  receiverUid: "cometchat-uid-3",
  type: "form",
  receiverType: "user",
  allowSenderInteraction: true,
);

CometChat.sendInteractiveMessage(interactiveMessage,
  onSuccess: (InteractiveMessage message) {
    debugPrint("Interactive message sent successfully: $message");
  },
  onError: (CometChatException excep) {
    debugPrint("Interactive message sending failed with error: ${excep.message}");
  },
);

Next Steps

Send Messages

Send text, media, and custom messages

Receive Messages

Listen for incoming messages in real time

Transient Messages

Send ephemeral messages that aren’t stored

Message Structure

Understand message types and hierarchy