Skip to content
Last updated

Events

The Dixa Messenger emits events that you can listen to in order to react to what is happening within the messenger. For example if you want to know when a the widget is opened by the user, or when a conversation is started, you can use the API below to do so.

API

To listen to an event you should use the _dixa_.addListener() API, which receives two arguments, first is the event name and the second is the callback that will be called once the event has happened. In order to remove an event listener you can use the _dixa_.removeListener() API. The signature is exactly the same.

Here's a list of available events:

EventDescriptionpayload
on-api-readycalled when the Dixa Messenger API is fully initialized and ready to receive commandsvoid info
on-widget-open-changedcalled when widget is either opened or closed by the user or programmaticallyboolean info
on-conversation-startedcalled when a conversation is startedobject info
on-conversation-endedcalled when a conversation is endsobject info
on-message-addedcalled when a new message is added to the conversation, by the user, agent or botsReceivableMessages info
on-view-changedcalled when user navigates to different viewing the messengerstring info
on-user-identity-changedcalled when users identify themselvesIdentify info
on-agent-assignedcalled when an agent joins the conversationAgent info
on-agent-unassignedcalled when an agent leaves the conversationAgent info
on-user-purgedcalled when the user identity is removed programmaticallyvoid
on-widget-focus-changedcalled when the widget is focused or loses focusstring info
on-shutdown-completedcalled when the widget has finished the shutdown processvoid info
on-backend-errorcalled when the backend has returned an error in response to an actionBackendError info
user-bannedcalled when user is banned via agent interfacevoid
user-unbannedcalled when user is unbanned via agent interfacevoid

Example:

function handleConversationStarted(data) {
  console.log(data.conversationId);
}

// Listen for when the API is ready
_dixa_.addListener('on-api-ready', function () {
  console.log('Dixa Messenger API is ready!');
  // You can now use the promise-based API
  _dixa_.api.init({ messengerToken: 'your-token' });
});

// start listening to the events
_dixa_.addListener('on-conversation-started', onConversationStarted);

// stop listening to the events:
_dixa_.removeListener('on-conversation-started', onConversationStarted);

Interface: HostNotificationEvents

Events that a host website can listen to. This is kept separate from WidgetEvents definitions in order to avoid any coupling of internal types to what we expose to the host.

To see a complete list of all available events and their corresponding payloads you can see the HostNotificationEvents interface.