Methods
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 users 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>
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 can only be sent after a conversation has been initiated.
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>
Updated about 1 month ago