Conditional Welcome: Direct the Flow of Your Bot Based on External Parameters

Abby Updated by Abby

There are several instances where we may need a dynamic bot with different flow options.

In this example we'll create two different flows for our user, depending on an external parameter, in this case a parameter in the URL that determines whether they're a new user, or a returning user.

For this workaround we'll add a Javascript function to the container page which we'll then trigger from the welcome message, but don't worry it's just a matter of copying and pasting!

Step One

Let's start with the builder.

In the builder you need first delete the buttons in the Welcome Message block:

Step Two

Then we will add a script to start the execution as soon as the bot is ready:

<script>window.trigger()</script>



Step Three

Now we need to create the Global Keywords to redirect based on the input that we will send:



Step Four

Just in case, connect the Welcome Message block, as it will be the "default" exit if the param that we send is wrong or missing

Step Five

In the Design Section we will "hide" the Welcome Message block with CSS:

[data-block="welcome_0"] .MessageBubble{display:none;}

Step Six

We need now to set up the function that will execute with the loading of the bot in the page where the bot is embedded:

The string 'flow' will be what you change for your particular parameter

let trigger = false

window.trigger= function(){
if (!trigger) {

 let searchParams = new URLSearchParams(window.location.search)
let param = searchParams.get('flow') myLandbot.sendMessage({ type: 'hidden', payload: param })

trigger = true;

}}

The most important part of this script is this:
myLandbot.sendMessage({ type: 'hidden', payload: param })

It will send "a message", that is hidden, and the variable "param" is the one that needs to match with the values in the global keywords.In the example above, we capture a param in the url and use it in the param variable

Obviously, you can adapt the script, to use internal JS values, instead of the url param.

I hope this workaround opens a new set of opportunities for your bots!

Here's where you can test it!

New users: https://landbotredirectionexample.carrd.co/?flow=flow_1

Returning users: https://landbotredirectionexample.carrd.co/?flow=flow_2

How did we do?

Different ways to format numbers with JS

How to not display Proactive Message to repeating Visitors

Contact