On initialisation the widget makes an api available on the window.dgchat.methods object. The functions in the methods object allow widget actions to be performed programmatically.

SendMessage

The sendMessage method allows the customer to programmatically send a message on the user behalf. This method is not available once the user is handed over to a crm.

<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>

launchWidget

The launchWidget method allows the customer to programmatically launch the widget. If the generalSettings.executeWidgetOnChatLaunch option is enabled and the chat has not been started yet then the widget executes the chat flow and maximises the widget dialog. On subsequent clicks (or if executeWidgetOnChatLaunch is not enabled) the launchWidget method will only have the effect of maximising the widget dialog.

<script>
   const element = document.querySelector('.some element');
   element.addEventListener("click", () => {
     window.dgchat.methods.launchWidget();
   }, false);
</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>