InteractiveMessage
is a specialised 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
is a chat message with embedded interactive content. It can contain various properties:
Parameter | Description | |
---|---|---|
receiverId | The UID or GUID of the recipient | Required |
receiverType | The type of the receiver to whom the message is to be sent (e.g., CometChatConstants.RECEIVER_TYPE_USER for user or CometChatConstants.RECEIVER_TYPE_GROUP for group) | Required |
messageType | The type of the message that needs to be sent | Required |
interactiveData | A JSONObject holding structured data for the interactive element | Required |
allowSenderInteraction | A boolean determining whether the message sender can interact with the message (default is set to false) | |
interactionGoal | An InteractionGoal object encapsulating the intended outcome of interacting with the InteractiveMessage (default is set to none) |
elementId
: An identifier for a specific interactive element.interactedAt
: A timestamp indicating when the interaction occurred.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:
Goals | Description | Keys |
---|---|---|
Any Interaction | The goal is considered completed if there is at least one interaction. | CometChatConstants.INTERACTION_TYPE_ANY |
Any of Specific Interactions | The goal is achieved if any of the specified interactions occurred. | CometChatConstants.INTERACTION_TYPE_ANY_OF |
All of Specific Interactions | The goal is completed when all specified interactions occur. | CometChatConstants.INTERACTION_TYPE_All_OF |
None | The goal is never completed | CometChatConstants.INTERACTION_TYPE_NONE |
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.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.
Here is an example of how to use it:
InteractiveMessage
.
onInteractiveMessageReceived
event listener is triggered when an InteractiveMessage
is received.
Here is an example:
onInteractionGoalCompleted
event listener is invoked when an interaction goal is achieved.
Here is an example:
InteractiveMessage
is constructed with the receiver’s UID, the receiver type, the interactive type, and interactive data as a JSONObject. Once created, the InteractiveMessage
can be sent using CometChat’s sendInteractiveMessage()
method. Incoming InteractiveMessages
can be received and processed via CometChat’s message listener framework.