There are a few events produced by Laiye Chatbot's widget that should be listened to. These events can be used to implement particular behaviors on the website hosting the widget.

πŸ“˜

Note

The following examples are illustrating the usage of events by using the Jquery library.

destygo_widget_loaded

The destygo_widget_loaded event is emitted at the document level and is triggered when the widget is done with initialization. It's useful to start listening to the other events at the right time.

Data available with this event:

  • detail.client_token : the unique token of the client using the widget

Example:

$(document).on('destygo_widget_loaded', function(event) {
    console.log('Widget for ' + event.detail.client_token + 'is ready');
})

destygo_send_message

The destygo_send_message event is emitted at the widget level (#destygo_widget id) and is triggered when the user sends a message.

Data available with this event:

  • detail.message : the message's text

Example:

$('#destygo_widget').on('destygo_send_message', function(event) {
    console.log('User has sent a message: ' + event.detail.message);
})

destygo_receive_message

The destygo_receive_message event is emitted at the widget level (#destygo_widget id) and is triggered when the user receives a message.

Data available with this event:

  • detail.message : the message's text

Example:

$('#destygo_widget').on('destygo_receive_message', function(event) {
    console.log('User has received a message: ' + event.detail.message);
})

destygo_click_on_toggler

The destygo_click_on_toggler event is emitted at the widget level (#destygo_widget id) and is triggered when the user clicks on the toggler, whether it's to open or close the widget.

Data available with this event:

  • detail.action : value is open if the click is to open the widget, otherwise the value is close

Example:

$('#destygo_widget').on('destygo_click_on_toggler', function(event) {
    console.log('Widget toggled: ' + event.detail.action);
})

destygo_click_on_contact

The destygo_click_on_contact event is emitted at the widget level (#destygo_widget id) and is triggered when the the user clicks on the contact button in the header.

Data available with this event:

  • detail.client_token : the unique token of the client using the widget

Example:

$('#destygo_widget').on('destygo_click_on_contact', function(event) {
    console.log('User ' + event.detail.client_token + ' has clicked on Contact button');
})

destygo_zendesk_triggered

The destygo_zendesk_triggered event is emitted at the widget level (#destygo_widget id) and is triggered when the initialization between the widget and Zendesk is complete.
This event is made for the use of setZendeskUserInfo function.

Example :

$('#destygo_widget').on('destygo_zendesk_triggered', function(event) {
    const payload = {
        email: '[email protected]',
        display_name: 'User name',
        phone: '0600000000'
    };
    DestygoChat.setZendeskUserInfo(payload)
})