How to use page variables in your Web Chatbot

When building a web chatbot it may often useful to send additional information to Xenioo based on specific contents of the page. Also, sometimes, you may want to completely change the active flow, depending on the current page or even depending on some page variables.

You could, for example, automatically greet the user with the correct name after logon to a private area or display some kind of information coming from your application and available inside the page.

Let’s see how this is done.

Sending Variables from Web to Xenioo Web Chatbot

Any variable you have in your page can be forwarded to Xenioo by simply declaring it in the Xenioo Widget initialization script. The following example assumes you have two JavaScript variables named varone and vartwo that you want to send to your chatbot startup:

<script src="https://static.xenioo.com/webchat/xenioowebchat.js"></script>
<script>
    xenioowebchat.Start("your chatbot id", {
          variables:[
            { Name:"varone", Value:varone },
            { Name:"vartwo", Value:vartwo }
          ]
        }
    );
</script>

The script above will send to Xenioo varone and vartwo values and your chatbot will start with two additional variables with the very same name.

Of course the variable may be written server-side by your script and injected in your initialization script directly.

Changing your web chatbot flow

To change your chatbot flow at startup, all you have to do is set the behaviour initialization parameter to any valid behaviour api token.

<script src="https://static.xenioo.com/webchat/xenioowebchat.js"></script>
<script>
    xenioowebchat.Start("your chatbot id", {
          behaviour: "one of your chatbot behaviour API Token"
        }
    );
</script>

Instead of starting from the configured Start Behaviour, Xenioo will start the conversation from the behaviour you specified in the above script.

Changing the flow from a script

By default, the Xenioo widget will create a xenioowebchat instance variable that is available on any subsequent JavaScript script. The Xenioo instance variable exposes a number of functions that can be used to interact with the Xenioo widget in multiple ways.

One of these functions let you change the flow of the chatbot dynamically. You could, for example, redirect the user on a completely different flow on the click of a button inside your page.

xenioowebchat.goTo( "My Bot Behaviour Name", "My Bot Interaction Name" );

The above script will send a redirect command to your chatbot and your user will automatically be moved to the desired flow.

[wpsr_share_icons icons="whatsapp,facebook,twitter,linkedin,email,pdf" icon_size="40px" share_counter="no" icon_shape="drop"]