Callbacks
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>
Callback | Description |
---|---|
onChatMinimizeClick | Called when the user clicks on the chat minimize button |
onChatLauncherClick | Called when the user clicks on the chat launcher |
onChatEndClick | Called when the user ends the chat |
onChatProactiveButtonClick | Called when the user clicks on a proactive button |
analytics | Called when Flow sends an Analytics event |
onChatInitialised | Called once the chat dialog is displayed |
onBotMessage | Called when the bot sends a message. The message text is sent as a parameter to the function |
onMessageFeedbackButtonClick | Called when the user provides feedback to a bot message. Called with the feedback the user gave |
iframeDimensions | Called when a DG iframe is injected into the page. Called with an object with a key of either dg-chat-widget |
onCarouselSelection | Called when the user makes a selection in the carousel. See the Carousel section below for more details |
onCarouselDisplay | Called when a carousel is displayed. See the carousel section below for more details |
onCSATPopoverCloseClicked | Called when the CSAT close button is clicked |
onChatConversationStarted | Called when the conversation is started. The session id of the chat is passed to the callback |
onCSATPopoverSubmitClicked | Called when the user clicks on the submit button in the csat feedback popover |
onWidgetEmbedded | Called when the widget is embedded and the launchWidget method is available |
onChatInitialisedError | Called when the widget fails to initialise |
newConversationStarted | Called 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 |
customCallback | Can 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"
}
}
Updated about 1 month ago