Skip to main content
Triggered for custom events such as button clicks within the chat. This event provides a generic pattern for handling custom interactions.

Event properties

type
string
required
Always 'customEvent'.
customEventName
string
required
The name of the custom event, for example. 'buttonItemClicked'.
contentItem
object
required
The message item that triggered the event.
message
object
required
The complete message containing the item.

Custom event names

  • buttonItemClicked
    Triggered when a button in a response is clicked.

Example

instance.on('customEvent', (event, instance) => {
    console.log('Custom event triggered:', event.customEventName);
    
    if (event.customEventName === 'buttonItemClicked') {
        console.log('Button clicked:', event.contentItem);
        
        // Handle button click
        const buttonId = event.contentItem.id;
        const buttonLabel = event.contentItem.label;
        
        // Perform action based on button
        handleButtonAction(buttonId, buttonLabel);
        
        // Track analytics
        analytics.track('button_clicked', {
            buttonId,
            buttonLabel,
            messageId: event.message.id
        });
    }
});

Do you need practical examples?

Learn how to apply the features available for embedded chat into your implementation with guidance and examples.