Quick Reference
Quick Reference
| Component | Description |
|---|---|
InteractiveMessage | Message containing interactive UI elements (forms, buttons, etc.) |
InteractionGoal | Defines the desired outcome of user interactions |
Interaction | Represents a single user action on an interactive element |
InteractiveMessage
TheInteractiveMessage class represents a message with embedded interactive content.
| Parameter | Type | Description | Required |
|---|---|---|---|
receiverId | string | UID of user or GUID of group | Yes |
receiverType | string | CometChat.RECEIVER_TYPE.USER or GROUP | Yes |
messageType | string | Type identifier (e.g., "form", "card") | Yes |
interactiveData | Object | JSON structure defining the interactive elements | Yes |
allowSenderInteraction | boolean | Whether sender can interact with the message | No (default: false) |
interactionGoal | InteractionGoal | Defines when the interaction is considered complete | No (default: none) |
Send an Interactive Message
UsesendInteractiveMessage() to send an interactive message.
- JavaScript
- TypeScript
sendInteractiveMessage() returns an InteractiveMessage object.
| Field | Getter | Return Type | Description |
|---|---|---|---|
| interactiveData | getInteractiveData() | Object | The structured JSON data for the interactive element |
| interactionGoal | getInteractionGoal() | InteractionGoal | The intended outcome of interacting with the message |
| interactions | getInteractions() | Interaction[] | List of user interactions performed on the message |
| allowSenderInteraction | getIsSenderInteractionAllowed() | boolean | Whether the sender can interact with the message |
Interactive Elements
TheinteractiveData object defines the UI elements. Common element types:
| Element Type | Description |
|---|---|
textInput | Single or multi-line text field |
dropdown | Single-select dropdown menu |
Select | Multi-select checkbox group |
button | Clickable button with action |
Text Input
Dropdown (Single Select)
Checkbox (Multi Select)
Submit Button
Interaction Goals
AnInteractionGoal defines when the user’s interaction with the message is considered complete. Use this to track engagement and trigger follow-up actions.
| Goal Type | Constant | Description |
|---|---|---|
| Any Interaction | CometChat.GoalType.ANY_ACTION | Complete when any element is interacted with |
| Any of Specific | CometChat.GoalType.ANY_OF | Complete when any of the specified elements is interacted with |
| All of Specific | CometChat.GoalType.ALL_OF | Complete when all specified elements are interacted with |
| None | CometChat.GoalType.NONE | Never considered complete (default) |
Set an Interaction Goal
- JavaScript
- TypeScript
Interactions
AnInteraction represents a single user action on an interactive element.
| Property | Type | Description |
|---|---|---|
elementId | string | Identifier of the interacted element |
interactedAt | number | Unix timestamp of the interaction |
Mark as Interacted
UsemarkAsInteracted() to record when a user interacts with an element.
- JavaScript
- TypeScript
Real-Time Events
Register aMessageListener to receive interactive message events.
Receive Interactive Messages
- JavaScript
- TypeScript
Interaction Goal Completed
Triggered when a user’s interactions satisfy the definedInteractionGoal.
- JavaScript
- TypeScript
Allow Sender Interaction
By default, the sender cannot interact with their own interactive message. Enable sender interaction:- JavaScript
- TypeScript
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