Callbacks

Markdown

View as Markdown

You can register callback functions for certain events on the chat widget using the following method.

collectchat.on(event, function)

This method uses the parameter event, which can monitor the following events:

EventDescription
openWhen a user opens the chat widget.
closeWhen a user closes the chat widget.
completeWhen a user completes the conversation in the chat widget.
messageEvery time a user responds to a message.

Sample code to register a callback when a user opens the chat widget:

var collectchat = window.collectchat || {};
collectchat.ready = function() {
  collectchat.on('open', function() {
    console.log('User just opened the chat widget');
  });
}

Sample code to register a callback when a user closes the chat widget:

var collectchat = window.collectchat || {};
collectchat.ready = function() {
  collectchat.on('close', function() {
    console.log('User just closed the chat widget');
  });
}

Sample code to register a callback when a user completes the conversation:

var collectchat = window.collectchat || {};
collectchat.ready = function() {
  collectchat.on('complete', function(list) {
    console.log('User just completed the conversation', list);
  });
}

Here, the parameter list is an array with details of all the questions and answers in the conversation.

Sample code to register a callback when a user responds to a message:

var collectchat = window.collectchat || {};
collectchat.ready = function() {
  collectchat.on('message', function(details, list) {
    console.log('User responded to question', details.question, details.answer);
    console.log('All questions answered so far are', list);
  });
}

Here, the parameter details is an object with information about the current question: details.question holds the question posed to the user, and details.answer holds the user's reply.

Related Articles

Was this article helpful?