The IF Condition feature

Launch an action in your chatbot based on a condition on a variable

1. What is an IF Condition on Botnation?

In a word, this is what will allow your chatbot to act in a LOGICAL way.

It is an instruction that takes the form: IF X happens (condition) THEN do A (consequence) OR do B (alternative).

The conditions are usually in the form “If… Then… Else…” in all the main programming languages like Javascript, C, Python, Perl, PHP etc…

2. What is it for?

If Conditions are essential to make your chatbot dynamic. You will use them regularly to guide users according to their choices and especially according to the data captured in variables when they answer. The If Conditions will also provide logic to your chatbot so that it makes the right decisions.

Here are some examples:

  • To personalize a chat: Depending on the time of day the chatbot can say “Good evening” instead of “Good morning” or depending on the gender of the user say “Mrs” or “Mr”.
  • To direct a user to a particular sequence based on his actions. After a quiz, depending on the user “s results, he will be directed to different answers according to his points.
  • Calculate discounts according to the order, if the order is over 40€ the chatbot can apply a 10% discount
  • etc…

3. How does it work?

The “If…” Conditions are found in the “Variables {…}” tool tab.

First we determine the variable on which the condition will be applied. You can choose it from the list of chatbot variables in the drop-down menu or create it for the occasion.

Then you choose the operator (equal to, greater than, different from, etc.) and finally the value of the variable.

We then choose the action that will be triggered if the condition is met.

The possible types of actions are:

  • Redirection : launches a chatbot sequence
  • Assign: assign a value to a variable
  • Increment : increase the value of a variable
  • Decrement : decrease the value of a variable
  • Text: Display a text

You can trigger several actions at the same time.

Finally, we determine the action that should be triggered when the condition is not met. Otherwise the bot would simply continue to execute the functions under the condition block.

Example of a classic condition:

In this example, the “IF Condition” feature is used to guide the user based on the availability of a consultant: IF a consultant is free (CAD when the variable “expert_advisor” is set to “available”) THEN it is redirected to a live chat sequence, OR we redirect him to a sequence on which he can leave a message.

You can also make Multiple Conditions like :

  • If it happens A AND B then…
  • If it happens A OR B then…

It is the equivalent of “AND” and “OR” in classical programming.

Example of Multiple OR Condition:

In this example, we use the “IF Condition” feature to determine the availability of a consultant based on the day of the week: IF we are Saturday (bn_date_Wday = 7) OR IF we are Sunday bn_date_Wday = 1) THEN the advisor is not available (the variable “expert_advisor” will have the value “Busy”).

Example of Multiple AND Condition:

In this example, we use the “IF Condition” feature to determine the availability of a consultant knowing that he is not free between 12:00 and 14:00. This translates into: IF the date variable “bn_date_hour” ≥12 AND IF the variable “bn_date_hour” <14 THEN the advisor is not available (the variable “expert_advisor” will take the value “Busy”).

We can, of course, add up the Multiple Conditions:

  • If it happens A AND B AND C AND D, etc then…
  • If it happens A OR B OR C OR D, etc then…

The SINON part is optional. You can therefore create a sequence of IF Conditions on the same variable to cover different cases.

Remember that the chatbot follows the instructions in the order they are given in the sequence. So if you are combining IF conditions, make sure that one does not cancel out the other. Also, don’t forget to include the case where no conditions are met. If a condition is valid and then executes a redirection to another sequence, all other conditions or functions underneath it will not be executed.

Example of cumulative conditions:

In this example, we use the “IF Condition” feature to display a different text depending on the user’s score (between 1 and 5).
The first condition displays “There are days without.” when the score is less than or equal to 2.
The second condition displays “Not bad but can do better” if the score is 3.
The last condition displays “Bravo!” when the score is greater than or equal to 4.

With a good knowledge of the variables, IF Conditions become a very powerful tool and are quickly indispensable when you want to personalize the user experience.

Create your Chatbot Easily and for Free!