Listen to an Event

Listen to events from the bot, and use them on your website.

Listener Function

You will have to update the bot script in order to define the function which will be called when receiving events.

Add an eventListener parameter in the clustaarSettings.

window.clustaarSettings = {
            bot_id: YOUR_BOT_ID,
            bot_token: YOUR_BOT_TOKEN,
            eventListener: clustaarEventsListener
};

Then, define the clustaarEventsListener function on your website so it can react to the events you are interested in.

function clustaarEventsListener(eventName) {
  switch(eventName) {
    case "MY_EVENT_NAME": {
      window.location.href = "https://clustaar.com/";
      break;
    }
    case "REDIRECT_TO_GOOGLE": {
      window.location.href = "https://google.com/";
      break;
    }
  }
}

If you want to use an event with a payload, as the CLSTR_USER_REPLIED event, you must provide the optional payload argument.

function clustaarEventsListener(eventName, payload) {
  switch(eventName) {
    case "CLSTR_USER_REPLIED": {
      alert("User said: " + payload);
      break;
    }
  }
}