How to use variables to change chatbot messages

Now that we’ve learned how to use variables and tags in our chatbot we’re ready to see how we can use them not just to alter the flow but to change what our chatbot says.

Using Xenioo we can use three different approaches: flow redirection, conditional texts and full variable text. Let’s see all of them.

Flow Redirection

This is by far the easiest way to change your chatbot message based on a variable value: you use a Variable Switch Action to detect your variable value and redirect your user to another section of your flow accordingly. So, for example, assuming we want to show our user a different message depending on the “customer_level” variable being “vip” or not, we could do something like this:

As our conversation naturally progresses, this approach, while easier, may prove more difficult to manage as branching texts are also branching paths. Adding more text to our initial bubbles for all users will force us to do something like this:

Again, this is perfectly fine but may prove difficult to handle as the conversation becomes more and more complex.

Conditional Text

The Conditional Text approach puts the text right after the switch as a unique operation. This approach will not produce a different result from the previous one but in this case, the flow won’t be affected by our extra text.

As our conversation becomes more complex we can keep our flow in a single branch and this makes it easier to later do some more editing. On the downside, not every action can be encapsulated as an operation and only one text can be set as child so keep in mind these limits when choosing this path.

Full Variable Text

Using the Full Variable Text approach means using a full variable as a text placeholder and filling it with the desired message. In this case, we basically prepare our messages beforehand and use them wherever necessary. Our flow would look similar to this:

This approach shares some similarities with the Conditional Text one but fixes its single text operation limitation. An additional plus of this approach is that you can have a single initialization of different text variables that you can then reuse wherever necessary. On the other hand it may become a little more difficult to read all of the placeholders instead of the actual text while designing your bot.

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