Documentation

Callbacks

Callbacks let you add custom behavior when specific events occur in the chat widget. To use them, define your callback functions inside the widget configuration on your page. Note that callbacks cannot be stored on the server-side config.

  <script>
    window.DG_CHAT_WIDGET_CONFIG = {
      widgetId: 'xxxxx-xxxxxx-xxxxxxx-xxxxxx',
      env: 'dev.us|eu|us',
      callbacks: {
        onChatMinimizeClick: () => {
          console.log('user minimized chat');
        }
      }
    }
  </script>
CallbackDescription
onChatMinimizeClickCalled when the user clicks on the chat minimize button
onChatLauncherClickCalled when the user clicks on the chat launcher
onChatEndClickCalled when the user ends the chat
onChatProactiveButtonClickCalled when the user clicks on a proactive button
analyticsCalled when Flow sends an Analytics event
onChatInitialisedCalled once the chat dialog is displayed
onBotMessageCalled when the bot sends a message. The message text is sent as a parameter to the function
onMessageFeedbackButtonClickCalled when the user provides feedback to a bot message. Called with the feedback the user gave
iframeDimensionsCalled when a DG iframe is injected into the page. Called with an object with a key of either dg-chat-widget
onCarouselSelectionCalled when the user makes a selection in the carousel. See the Carousel section below for more details
onCarouselDisplayCalled when a carousel is displayed. See the carousel section below for more details
onCSATPopoverCloseClickedCalled when the CSAT close button is clicked
onChatConversationStartedCalled when the conversation is started. The session id of the chat is passed to the callback
onCSATPopoverSubmitClickedCalled when the user clicks on the submit button in the csat feedback popover
onWidgetEmbeddedCalled when the widget is embedded and the launchWidget method is available
onChatInitialisedErrorCalled when the widget fails to initialise
newConversationStartedCalled when a new conversation is started in the widget. This is triggered when the flow starts, if the flow reaches an end and restarts, or if the user clicks a quick reply which has been assigned the return to main menu function
customCallbackCan be used to trigger a callback at an arbitrary point in the flow and can be used for any purpose as required.

Payloads

Some of the callback functions are triggered from within the flow itself. The following callbacks and their payloads are listed below:

newConversationStarted

The newConversationStarted callback can be triggered via the advanced Chat Activity with the following payload.

{
  "type": "newConversationStarted"
}

customCallback

The customCallback callback can be triggered via the advanced chat activity with the following payload. The value of the payload will be forwarded to the callback:

{
  "type": "customCallback",
  "payload": {
    "someProperty": "some value"
  }
}

What’s Next