Make your Chatbot interact with your website

Transmit events (javascript events) and actions to your site

➜ Discover Botnation and launch your chatbot easily!

Your Botnation web chatbot can interact with the website on which it is installed by transmitting Javascript events to the browser. The web chatbot can then communicate with your site via these events that you must intercept to, for example, directly add a product to the cart, change page without opening a new site etc…

Warning:
This documentation is not covered by Botnation support. Botnation only sends Javascript events to the browser displaying your site. Any interpretation or action related to these Javascript eventsis no longer relevant to Botnation. Moreover, these “web” developments on your side (site side) certainly interact with other applications (analytics, shopping cart, payment, page loading…) for which we cannot provide support. In case of difficulty, we recommend you to get in touch with a Javascript developer, the writing of this Javascript code concerning your site and not the chatbot on the Botnation side, just like the logo of your site will depend on a graphic designer and not on the Botnation support.

1. How to send informations directly from your chatbot to your website

On the interface of your Botnation chatbot you just have to activate the “Javascript event” feature.

Then indicate the event name, which will be intercepted via this name on your site, and possibly add additional parameters that will be retrieved in the form of key/value on your site. These parameters can be composed of Botnation variables.

These parameters are for example useful to configure an add-to-cart event by communicating a customer ID and an item reference.

You can add as many events from any section of your chatbot as you want and usually only one script is needed on the site to intercept them.

2. How to set up a Javascript event on your side

On the site side, you need to intercept these events by adding an “onEvents” inside – I repeat “inside” – the javascript Botnation tag of your chatbot.

Example:

window.chatboxSettings = {
   onEvents: function(eventName, eventArgs) {
      // votre action 
      // eventName = "name of the event"
      // eventArgs = {arg1: "val1", arg2: "val2"}
   }
}

For example, to have the chatbot communicate a page change to the user’s browser:

onEvents: function (eventName, eventArgs) {
switch (eventName) {
case 'redirection':
// verify that we received an url
if (eventArgs.hasOwnProperty('url')) {
// redirect to the url
window.location.href = eventArgs.url;
}
break;
default:
break;
}
}

You can also redirect the user to an external site by specifying a complete address e.g. https://www.example.com/ma-page-de-redirection or to another page of the current site by specifying a relative url e.g. /my-page-of-redirection.

The addresses of your pages (relative urls) must begin with a slash (‘/’).

Once this configuration is done, you will be able to launch new redirections endlessly from any section of your event chatbot without modifying the script on your page. You just have to repeat the steps, respecting strictly the event name and the parameter name.

3. Make it easier

If you do several actions on the event name only – and not on the event’s values, you’ll have to define a “case” for this one:

window.chatboxSettings = { 

// ensemble du tag Botnation

// Communication Events

  onEvents: function (eventName, eventArgs) {

   switch (eventName) {

    case 'riri':

// votre action javascript 

       break;

    case 'fifi':

// votre action javascript 

        break;

    case 'loulou':

// votre action javascript 

        break;

    default:

      break;

   }

  }

}

This feature is unlimited and therefore allows you to fully control the user’s browser and other Javascript applications included in it.

If you use Google Tag Manager on your site or another Tag Management tool to manage the Botnation tag it should be compatible.

Warning:
Javascript events must be managed on your own website, so they may not be functional on the test page provided by Botnation or on the Chatbotnation hosting because you do not have access to the editing of the code of these sites.

To make the javascript events functional, you must first publish the chatbot on your own site, including during the test phase.

Do not hesitate to send us your best projects so that we can put them forward.

➜ Discover Botnation and launch your chatbot easily!