SWITCH

Smart chatbots take decisions and behave differently in different situations. Flexibility is a key factor in creating a bot that will be really useful and engaging.

To achieve this in Activechat you can use the SWITCH block. When executed, it will check specific user attribute for certain conditions and route the flow to different parts or skills of your bot conversation according to these conditions. 

Using SWITCH block to check multiple conditions
Using SWITCH block to check multiple conditions

To set up conditional branching, open SWITCH block editor by clicking the block on the canvas and choose the name of the user attribute to check. In the example above chatbot will check $user_age attribute (acquired somewhere else with the LISTEN block) to branch conversation depending on its value.

Each condition in the SWITCH block has it’s own “button” which can be used to trigger other block flows (just connect it to another block with an arrow).

If none of the conditions are met, the conversation will proceed to the next block that is connected to the bottom of the SWITCH block.

You can build complex conditions with AND/OR – just click the dropdown list on the right. 

Possible checks are:

  • > (greater than)
  • < (less than)
  • >= (greater or equal)
  • <= (less or equal)
  • == (equals)
  • != (not equals)
  • ∈ (contains)
  • ∉ (does not contain)

“Contains” and “does not contain” checks are great for keyword detection. Here is another example of the “default” chatbot skill, checking the value of $_last_user_input system attribute to trigger different chatbot skills when the user is typing specific keywords. Notice the use of SEND blocks to trigger chatbot events and launch skills.

Keyword detection with the SWITCH block
Keyword detection with the SWITCH block

You can add up to 10 different conditions in a single SWITCH block. If you need more, just connect another SWITCH block to the bottom exit of the first one.

Please keep in mind that different conditions are evaluated top to bottom, in the order they appear in the SWITCH block editor. It means that if you want to check for “car” and “cart” separately and use ∈ (contains), put “cart” first. Otherwise, both keywords will trigger the “car” check since “car” is contained within “cart”.

Was this article helpful to you? Yes 2 No 2

How can we help?