Skip to main content
Quick Reference for AI Agents & Developers
  • Create interactive: InteractiveMessage() — set receiverUid, receiverType, type, interactiveData
  • Send interactive: CometChat.sendInteractiveMessage(message:onSuccess:onError:)
  • Types: Form, Card, Scheduler, Custom Interactive
  • Interaction goal: Set interactionGoal to define completion criteria
  • Related: Send Message · Messaging Overview

InteractiveMessage Properties

PropertyTypeDescription
receiverUidStringUID or GUID of recipient
receiverTypeReceiverType.user or .group
typeStringform, card, scheduler, or custom
interactiveData[String: Any]JSON structure for content
allowSenderInteractionBoolCan sender interact (default: false)
interactionGoalInteractionGoalCompletion criteria
messageCategoryMessageCategory.interactive

Interaction Goal Types

TypeDescriptionValue
Any ActionGoal completed if any interaction occurs.anyAction
Any OfGoal achieved if any specified interaction occurs.anyOf
All OfGoal completed when all specified interactions occur.allOf
NoneGoal is never completed.none

Form Element Types

Element TypeDescription
textInputSingle or multi-line text input
dropdownDropdown select with options
checkboxMultiple selection checkboxes
radioSingle selection radio buttons
singleSelectSingle selection list
buttonAction button (submit, navigate)

Button Action Types

Action TypeDescription
urlNavigationOpens a URL in browser
apiActionMakes an API call with specified parameters
customActionCustom action handled by app

Send Form Interactive Message

let interMessage = InteractiveMessage()
interMessage.messageCategory = .interactive
interMessage.type = "form"
interMessage.receiverType = .user
interMessage.receiverUid = "cometchat-uid-2"
interMessage.allowSenderInteraction = true

interMessage.interactiveData = [
    "title": "Contact Form",
    "formFields": [
        [
            "elementId": "name_field",
            "elementType": "textInput",
            "label": "Name",
            "optional": false
        ],
        [
            "elementId": "country_dropdown",
            "elementType": "dropdown",
            "label": "Country",
            "options": [
                ["label": "USA", "value": "usa"],
                ["label": "UK", "value": "uk"],
                ["label": "India", "value": "india"]
            ]
        ]
    ],
    "submitElement": [
        "elementId": "submit_btn",
        "elementType": "button",
        "buttonText": "Submit",
        "disableAfterInteracted": true
    ],
    "goalCompletionText": "Thank you for submitting!"
]

let goal = InteractionGoal()
goal.elementIds = ["submit_btn"]
goal.interactionType = .anyOf
interMessage.interactionGoal = goal

CometChat.sendInteractiveMessage(message: interMessage, onSuccess: { message in
    print("Interactive message sent: \(message)")
}, onError: { error in
    print("Error: \(error?.errorDescription ?? "")")
})
Method: CometChat.sendInteractiveMessage(message:)Message Parameters:
ParameterTypeValue
receiverUidString"cometchat-uid-2"
receiverTypeCometChat.ReceiverType.user
typeString"form"
messageCategoryCometChat.MessageCategory.interactive
allowSenderInteractionBooltrue
Interaction Goal:
ParameterTypeValue
elementIds[String]["submit_btn"]
interactionTypeInteractionGoalType.anyOf

Send Card Interactive Message

let interMessage = InteractiveMessage()
interMessage.messageCategory = .interactive
interMessage.type = "card"
interMessage.receiverType = .user
interMessage.receiverUid = "cometchat-uid-2"
interMessage.allowSenderInteraction = true

interMessage.interactiveData = [
    "title": "Product Card",
    "subtitle": "Special Offer",
    "text": "Check out this amazing product with 20% discount!",
    "imageUrl": "https://example.com/product.png",
    "cardActions": [
        [
            "elementId": "buy_btn",
            "elementType": "button",
            "buttonText": "Buy Now",
            "action": [
                "actionType": "urlNavigation",
                "url": "https://example.com/buy"
            ]
        ],
        [
            "elementId": "details_btn",
            "elementType": "button",
            "buttonText": "View Details",
            "action": [
                "actionType": "urlNavigation",
                "url": "https://example.com/details"
            ]
        ]
    ]
]

let goal = InteractionGoal()
goal.elementIds = ["buy_btn", "details_btn"]
goal.interactionType = .anyOf
interMessage.interactionGoal = goal

CometChat.sendInteractiveMessage(message: interMessage, onSuccess: {...}, onError: {...})
Message Parameters:
ParameterTypeValue
receiverUidString"cometchat-uid-2"
receiverTypeCometChat.ReceiverType.user
typeString"card"
messageCategoryCometChat.MessageCategory.interactive
allowSenderInteractionBooltrue

Send Scheduler Interactive Message

let interMessage = InteractiveMessage()
interMessage.messageCategory = .interactive
interMessage.type = "scheduler"
interMessage.receiverType = .user
interMessage.receiverUid = "cometchat-uid-2"
interMessage.allowSenderInteraction = true

interMessage.interactiveData = [
    "title": "Schedule a Meeting",
    "duration": 30,
    "bufferTime": 5,
    "availability": [
        "monday": ["09:00-12:00", "14:00-17:00"],
        "tuesday": ["09:00-12:00", "14:00-17:00"],
        "wednesday": ["09:00-12:00", "14:00-17:00"]
    ],
    "scheduleElement": [
        "elementId": "schedule_btn",
        "elementType": "button",
        "buttonText": "Schedule",
        "disableAfterInteracted": true
    ],
    "goalCompletionText": "Meeting scheduled successfully!"
]

CometChat.sendInteractiveMessage(message: interMessage, onSuccess: {...}, onError: {...})
Message Parameters:
ParameterTypeValue
receiverUidString"cometchat-uid-2"
receiverTypeCometChat.ReceiverType.user
typeString"scheduler"
messageCategoryCometChat.MessageCategory.interactive
allowSenderInteractionBooltrue
Scheduler Data:
ParameterTypeValue
titleString"Schedule a Meeting"
durationInt30
bufferTimeInt5

Send Form to Group

let interMessage = InteractiveMessage()
interMessage.messageCategory = .interactive
interMessage.type = "form"
interMessage.receiverType = .group
interMessage.receiverUid = "cometchat-guid-1"
interMessage.allowSenderInteraction = true

interMessage.interactiveData = [
    "title": "Group Poll",
    "formFields": [
        [
            "elementId": "poll_radio",
            "elementType": "radio",
            "label": "What's your favorite?",
            "optional": false,
            "options": [
                ["label": "Option A", "value": "a"],
                ["label": "Option B", "value": "b"],
                ["label": "Option C", "value": "c"]
            ]
        ]
    ],
    "submitElement": [
        "elementId": "vote_btn",
        "elementType": "button",
        "buttonText": "Vote",
        "disableAfterInteracted": true
    ]
]

CometChat.sendInteractiveMessage(message: interMessage, onSuccess: {...}, onError: {...})
Message Parameters:
ParameterTypeValue
receiverUidString"cometchat-guid-1"
receiverTypeCometChat.ReceiverType.group
typeString"form"
messageCategoryCometChat.MessageCategory.interactive

Interaction Object Properties

PropertyTypeDescription
elementIdStringID of interacted element
interactedAtDoubleTimestamp of interaction

InteractionGoal Object Properties

PropertyTypeDescription
elementIds[String]IDs of target elements
interactionTypeInteractionGoalType.anyAction, .anyOf, .allOf, .none

Real-time Interactive Message Events

To receive interactive message events, implement CometChatMessageDelegate:
class YourClass: CometChatMessageDelegate {
    
    init() {
        CometChat.addMessageListener("listener-id", self)
    }
    
    func onInteractiveMessageReceived(_ message: InteractiveMessage) {
        print("Interactive message received")
        print("Type: \(message.type ?? "")")
        print("Interactive Data: \(message.interactiveData ?? [:])")
    }
    
    func onInteractionGoalCompleted(_ message: InteractiveMessage) {
        print("Interaction goal completed")
        print("Message ID: \(message.id)")
    }
}
Method: onInteractiveMessageReceived(_ message: InteractiveMessage)
ParameterTypeDescription
messageInteractiveMessageThe interactive message object
message.typeString?form, card, scheduler, or custom
message.interactiveData[String: Any]?JSON structure of content
message.interactionGoalInteractionGoal?Goal definition