{"id":473,"date":"2022-09-05T13:56:19","date_gmt":"2022-09-05T11:56:19","guid":{"rendered":"https:\/\/support.botnation.ai\/the-if-condition-feature\/"},"modified":"2026-02-25T12:45:14","modified_gmt":"2026-02-25T11:45:14","slug":"the-if-condition-feature","status":"publish","type":"support","link":"https:\/\/botnation.ai\/en\/support\/the-if-condition-feature\/","title":{"rendered":"The IF Condition feature"},"content":{"rendered":"<p>Launch an action in your chatbot based on a condition on a variable<\/p>\n\n\n\n\n\n<h2 class=\"wp-block-heading\">1. What is an IF Condition on Botnation?<\/h2>\n\n\n\n<p>In a word, this is what will allow your chatbot to act in a LOGICAL way.<\/p>\n\n\n\n<p>It is an instruction that takes the form: <strong>IF<\/strong> X happens (condition) <strong>THEN<\/strong> do A (consequence) <strong>OR<\/strong> do B (alternative).<br><br><em>The conditions are usually in the form \u201cIf\u2026 Then\u2026 Else\u2026\u201d in all the main programming languages like Javascript, C, Python, Perl, PHP etc\u2026<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. What is it for?<\/h2>\n\n\n\n<p>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.<\/p>\n\n\n\n<p><strong>Here are some examples:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>To personalize a chat: Depending on the time of day the chatbot can say \u201cGood evening\u201d instead of \u201cGood morning\u201d or depending on the gender of the user say \u201cMrs\u201d or \u201cMr\u201d.<\/li><li>To direct a user to a particular sequence based on his actions. After a quiz, depending on the user \u201cs results, he will be directed to different answers according to his points.<\/li><li>Calculate discounts according to the order, if the order is over 40\u20ac the chatbot can apply a 10% discount<\/li><li>etc\u2026<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">3. How does it work?<\/h2>\n\n\n\n<p>The \u201cIf\u2026\u201d Conditions are found in the \u201cVariables {\u2026}\u201d tool tab.  <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/botnation.ai\/wp-content\/uploads\/2022\/09\/image-60.png.webp\" alt=\"\" class=\"wp-image-481\"><\/figure>\n\n\n\n<p>First we determine the variable on which the condition will be applied. You can choose it from the list of <a href=\"https:\/\/botnation.ai\/en\/support\/all-about-variables\/\">chatbot variables<\/a> in the drop-down menu or create it for the occasion.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/botnation.ai\/wp-content\/uploads\/2022\/09\/image-61.png.webp\" alt=\"\" class=\"wp-image-483\"><\/figure>\n\n\n\n<p>Then you choose the operator (equal to, greater than, different from, etc.) and finally the value of the variable.<br><br>We then choose the action that will be triggered if the condition is met.  <\/p>\n\n\n\n<p><strong>The possible types of actions are:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Redirection : launches a chatbot sequence<\/li><li>Assign: <a href=\"https:\/\/botnation.ai\/en\/assign-a-value-to-a-variable\/\">assign a value to a variable<\/a><\/li><li>Increment : increase the value of a variable<\/li><li>Decrement : decrease the value of a variable<\/li><li>Text: Display a text<\/li><\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>TIP<\/strong><br>You can trigger several actions at the same time.<\/p><\/blockquote>\n\n\n\n<p>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.<\/p>\n\n\n\n<p><strong>Example of a classic condition:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/botnation.ai\/wp-content\/uploads\/2022\/09\/image-62.png.webp\" alt=\"\" class=\"wp-image-485\"><\/figure>\n\n\n\n<p><em>In this example, the \u201cIF Condition\u201d feature is used to guide the user based on the availability of a consultant:  <strong>IF <\/strong>a consultant is free (CAD when the variable \u201cexpert_advisor\u201d is set to \u201cavailable\u201d)  <strong>THEN<\/strong> it is redirected to a live chat sequence,  <strong>OR<\/strong> we redirect him to a sequence on which he can leave a message<\/em>.<\/p>\n\n\n\n<p>You can also make Multiple Conditions like :  <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>If it happens A <strong>AND<\/strong> B then\u2026<\/li><li>If it happens A <strong>OR<\/strong> B then\u2026<\/li><\/ul>\n\n\n\n<p>It is the equivalent of \u201cAND\u201d and \u201cOR\u201d in classical programming.<\/p>\n\n\n\n<p><strong>Example of Multiple OR Condition:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/botnation.ai\/wp-content\/uploads\/2022\/09\/image-63.png.webp\" alt=\"\" class=\"wp-image-487\"><\/figure>\n\n\n\n<p><em>In this example, we use the \u201cIF Condition\u201d feature to determine the availability of a consultant based on the day of the week:  <strong>IF<\/strong>  we are Saturday (bn_date_Wday = 7)  <strong>OR IF<\/strong>  we are Sunday bn_date_Wday = 1)  <strong>THEN<\/strong>  the advisor is not available (the variable \u201cexpert_advisor\u201d will have the value \u201cBusy\u201d).<\/em><\/p>\n\n\n\n<p><strong>Example of Multiple AND Condition:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/botnation.ai\/wp-content\/uploads\/2022\/09\/image-64.png.webp\" alt=\"\" class=\"wp-image-490\"><\/figure>\n\n\n\n<p><em>In this example, we use the \u201cIF Condition\u201d feature to determine the availability of a consultant knowing that he is not free between 12:00 and 14:00. This translates into:  <\/em><strong>IF <\/strong>the <a href=\"https:\/\/botnation.ai\/en\/support\/date-variables-and-functions\/\">date variable<\/a> \u201cbn_date_hour\u201d \u226512 <strong>AND<\/strong> <strong>IF <\/strong>the variable \u201cbn_date_hour\u201d &lt;14 <strong>\n  <em>THEN<\/em>\n<\/strong><em> the advisor is not available (the variable \u201cexpert_advisor\u201d will take the value \u201cBusy\u201d).<\/em><\/p>\n\n\n\n<p><strong>We can, of course, add up the Multiple Conditions:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>If it happens A <strong>AND<\/strong> B <strong>AND<\/strong> C <strong>AND<\/strong> D, etc then\u2026<\/li><li>If it happens A <strong>OR<\/strong> B <strong>OR<\/strong> C <strong>OR<\/strong> D, etc then\u2026<\/li><\/ul>\n\n\n\n<p>The <strong>SINON<\/strong> part is optional. You can therefore create a sequence of IF Conditions on <a href=\"https:\/\/botnation.ai\/en\/change-the-case-of-a-variable\/\">the same variable to cover different cases<\/a>.  <\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>ATTENTION  <\/strong><br>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\u2019t forget to include the case where no conditions are met.  <strong>If a condition is valid and then executes a redirection to another sequence, all other conditions or functions underneath it will not be executed.<\/strong><\/p><\/blockquote>\n\n\n\n<p><strong>Example of cumulative conditions:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/botnation.ai\/wp-content\/uploads\/2022\/09\/cumulative-421x1024.png.webp\" alt=\"\" class=\"wp-image-494\" width=\"723\" height=\"1759\"><\/figure>\n\n\n\n<p><em>In this example, we use the \u201cIF Condition\u201d feature to display a different text depending on the user\u2019s score (between 1 and 5).<\/em><br><em>The first condition displays \u201cThere are days without.\u201d when the score is less than or equal to 2.<\/em><br><em>The second condition displays \u201cNot bad but can do better\u201d if the score is 3.<\/em><br><em>The last condition displays \u201cBravo!\u201d when the score is greater than or equal to 4.<\/em><\/p>\n\n\n\n<p><strong>With a good knowledge of <a href=\"https:\/\/botnation.ai\/en\/support\/date-variables-and-functions\/\">the variables<\/a>, IF Conditions become a very powerful tool and are quickly indispensable when you want to personalize the user experience.<\/strong><\/p>\n\n\n","protected":false},"featured_media":0,"template":"","meta":{"_acf_changed":false},"categorie-support":[194,222,221],"class_list":["post-473","support","type-support","status-publish","hentry","categorie-support-features","categorie-support-variables-en","categorie-support-web-chatbot-en"],"acf":[],"_links":{"self":[{"href":"https:\/\/botnation.ai\/en\/wp-json\/wp\/v2\/support\/473","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/botnation.ai\/en\/wp-json\/wp\/v2\/support"}],"about":[{"href":"https:\/\/botnation.ai\/en\/wp-json\/wp\/v2\/types\/support"}],"wp:attachment":[{"href":"https:\/\/botnation.ai\/en\/wp-json\/wp\/v2\/media?parent=473"}],"wp:term":[{"taxonomy":"categorie-support","embeddable":true,"href":"https:\/\/botnation.ai\/en\/wp-json\/wp\/v2\/categorie-support?post=473"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}