Events
This section describes the events available on WebChat via the SDK
WebChat emits a number of events that you can listen to within your own application.
Adding an event listener
To add an event listener, use:
webchat.on('event_name':string, callback: Function)Each listener will return a CustomEvent object with specific data nested in the event.detail object:
/**
* Add an event listener to the chat widget
* @function on
* @param {string} eventName - the event to listen for
* @param {Function} callback - the function to call when the event is triggered
* @returns {CustomEvent} - the event object with specific data in the event.detail object
*/
.on('loaded', (e: CustomEvent) => {
console.log(e.detail) // the event data specific to WebChat
})For convenience, all events return the element upon which the event was fired within the detail object. For additional return values, see the descriptions below.
Supported events
'loaded' - fired when the WebChat widget has initialised.
Returns a 'loaded' property with a Boolean value:
loaded: true
'openStateChanged' - fired when the WebChat widget is opened or closed.
Returns a String value:
'messageSent' - fired when the user sends a message.
Returns a message object:
'messageReceived' - fired when WebChat receives a message from the server.
Returns a message object:
'chatEnded' - fired when the user selects 'end chat' from the menu in the WebChat application
Last updated