Documentation

Methods

When the widget is initalialised it adds a methods object to the global dgchat object (see the How the chat app is embedded for more details). They can be accessed on the global object like so window.dgchat.methods.methodName() This allows you to programmatically perform actions on the widget. The following actions are supported by the methods api:

sendMessage

The sendMessage method allows the customer to programmatically send a message on the users behalf:

<script>
  const element = document.querySelector('.some element');
  element.addEventListener("click", () => {
    window.dgchat.methods.sendMessage('Some custom message to be sent on the customers behalf');
  }, false);
</script>

sendSystemMessage

The sendSystemMessage method allows a system message to be programatically added to the conversation:

window.dgchat.methods.sendSystemMessage('Some system message');

A system message should only be added after a conversation has been initiated.

launchWidget

The launchWidget method allows the customer to programmatically launch the widget.

<script>
  window.dgchat.methods.launchWidget();
</script>

initProactiveButtons

The initProactiveButtons method allows the customer to programmatically trigger the proactive buttons to display. The payload must be as follows:

<script>
  window.dgchat.methods.initProactiveButtons({
    questions: ['list', 'of', 'questions'],
    answers: ['list', 'of', 'answers'],
  });
</script>

debug

The debug method enables raw websocket data to be logged to the console. This command can be run from the console directly:

window.dgchat.methods.debug();

trackNavigation

The trackNavigation method allows the customer to track when a user navigates to a new page, it should be called with the updated url of the page.

window.dgchat.methods.trackNavigation('www.google.com');

This adds a system event in the conversation page, showing the url of the page the user navigated to.

The method is only necessary for single page applications where the browser history does not update as expected. You must also ensure that generalSetting.enableNavigationTracking is set to true.