What is an IF Condition on Botnation?

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

It is an instruction which takes the form: IF there is X (condition) THEN do A (consequence) ELSE do B (alternative).

We find the conditions, generally in the form "If ... Then ... Else ... ", in all the main programming languages like Javascript, C, Python, Perl, PHP etc…

What's the point?

The If Conditions are essential in order 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 during their responses. The If Conditions will also provide logic for your chatbot to make the right decisions.

Here are some examples :

  • To personalize a discussion: Depending on the time of day, the chatbot can say "Good evening" instead of "Hello" or, depending on the gender of the user, say "Madam" or "Mr."
  • To direct a user to a particular sequence according to his actions. After a quiz according to the results of the user, he will be directed towards different answers according to his points.
  • To calculate reductions according to his order, if the order is over 40 € the chatbot can apply a 10% reduction
  • etc...

How it works ?

The "If ..." Condition is found in the "Variables {...}" tools tab

First, we determine the variable to which the condition will apply. We choose it from the list of chatbot variables in the drop-down menu or we create it for the occasion.


Then we 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:

  • Redirect: launch a chatbot sequencet
  • Set: assign a value to a variable
  • Increment: increase the value of a variable
  • Decrement: decrease the value of a variable
  • Text: display text

Tip: You can trigger multiple 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 perform the functions located under the conditions block..

Example of a classic condition:

In this example, we use the “IF Condition” functionality to guide the user according to the availability of an advisor: IF an advisor is not available (when the “Disponibility” variable takes the value “NO”) THEN we redirect the user to a sequence on which he can leave a message, ELSE he is redirected to a live chat sequence.


You can also make Multiple Conditions:

  • IF A and B happen THEN…
  • IF A or B happen 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 an advisor 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 advisor n 'is not available (the “disponibility” variable will take the value “NO”).

Example of Multiple Condition AND:

In this example, we use the "IF Condition" feature to determine the availability of an advisor knowing that he is not available between 12 p.m. and 2 p.m. This results in: IF the date variable “bn_date_hour” ≥12 AND IF the variable “bn_date_hour” <14 THEN the advisor is not available (the “disponibility” variable will take the value “NO”).


We can, of course, add the Multiple Conditions:

  • IF A AND B AND C AND D, etc. happens THEN…
  • IF A OR B OR C OR D, etc. happens THEN…

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

CAUTION: Remember that the chatbot follows the instructions in the order they are in the sequence. So if you stack IF conditions, make sure that one does not override the other. Also, don't forget to cover the case where no conditions are met. If a condition is valid and then performs a redirection to another sequence, all other conditions or functions below it will not be performed.

Example of cumulative conditions:

In this example, we use the “IF Condition” feature to display different text depending on the user's score (between 1 and 10). The first condition displays “😳 I didn't believe it was possible. Did you do it on purpose?” when the score is equal to 0. The second condition displays “Hum 🤔 ... Did you answer at random?” if the score is between 1 and 4. And so on...


With a good knowledge of variables, IF Conditions become a very powerful tool and are quickly essential when we want to best personalize the user experience


Related articles :


Back to Online Help

Did this answer your question?