Skip to main content
An InteractiveMessage is a specialized object that encapsulates an interactive unit within a chat message, such as an embedded form that users can fill out directly within the chat interface. This enhances user engagement by making the chat experience more interactive and responsive to user input.

InteractiveMessage

InteractiveMessage is a chat message with embedded interactive content. It can contain various properties:

Interaction

An Interaction represents a user action involved with an InteractiveMessage. It includes:
  • elementId: An identifier for a specific interactive element.
  • interactedAt: A timestamp indicating when the interaction occurred.

Mark as Interacted

This method marks a message as interacted by identifying it with the provided Id. it also logs the interactive element associated with the interaction.

Goal Completion

A key feature of InteractiveMessage is checking whether a user’s interactions with the message meet the defined InteractionGoal 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:

InteractionGoal

The InteractionGoal represents the desired outcome of an interaction with an InteractiveMessage. It includes:
  • elementIds: A list of identifiers for the interactive elements.
  • type: The type of interaction goal from the CometChatConstants.

Send an Interactive Message

The InteractiveMessage can be sent using the sendInteractiveMessage method of the CometChat class. The method requires an InteractiveMessage object and a CallbackListener for handling the response. Before sending interactive messages, ensure you have initialized the SDK and logged in a user. Here is an example of how to use it:

Real-time Events

CometChat SDK provides event listeners to handle real-time events related to InteractiveMessage. For more details on listener management, see Real-Time Listeners. On InteractiveMessage Received The onInteractiveMessageReceived event listener is triggered when an InteractiveMessage is received. Here is an example:
Always remove listeners when they’re no longer needed (e.g., in onDestroy() or when navigating away). Failing to remove listeners can cause memory leaks and duplicate event handling.

On Interaction Goal Completed

The onInteractionGoalCompleted event listener is invoked when an interaction goal is achieved. Here is an example:
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.

InteractiveMessage Payload Structure

The InteractiveMessage object contains interactive content like forms and buttons:Sample InteractiveMessage Object:
The InteractionGoal object defines the desired outcome of interactions:Sample InteractionGoal Object:
The Interaction object represents a user action on an interactive element:Sample Interaction Object:
The nested User object in sender contains:Sample User Object:

Next Steps

Send Messages

Learn how to send text, media, and custom messages

Mentions

Mention specific users in messages for better engagement

Receive Messages

Handle incoming messages with real-time listeners

Real-Time Listeners

Manage event listeners for real-time updates