Logic Operations

How you can carry out Logic Operations with your chatbot.

The logical operations that you can carry out within your chatbot are very useful tools, especially if you want the bot to assess a number or compare two words and make a statement in response to that assessment.

There is a drop-down menu to help you compose the logic statements.

You’ll see they take the form:

These instruct the chatbot to say whatever text is in between the curly brackets if A equals B, A does not equal B, A is greater than B or A is less than B.

If the logical operation is not true, then the chatbot ignores the text.

For example [IF (6!B){well done}] results in the chatbot saying ‘well done’ except when B equals 6.



Do not use the symbols > and < as part of the TEXT response of the chatbot otherwise the logical operation will not work (i.e. do not put them within the curly brackets).

You can give A and B values that are integers, decimals, both positive and negative numbers and also zero.

ExamplesIn each of these three examples, the chatbot will say
[IF(1=1){well done}];‘well done’ because one equals one.
[IF(0<1,185){well done}];‘well done’ because zero is less than one thousand, one hundred and eighty-five.
[IF(1>-5){well done}];‘well done’ because one is greater than minus five.

You can also give A and B values that are letters, combinations of letters and words. The assessment of letters is sensitive to different alphabets. So ‘YES’ in Latin letters is not equal to ‘ΥΕΣ’ in Greek.

ExamplesIn each of these four examples, the chatbot will say
[IF(z=z){well done}]‘well done’ because ‘z’ equals ‘z’.
[IF(word=word){well done}]'well done' because 'word' equals ‘word’.
[IF(word1!word2){well done}]‘well done’ because 'word1' does not equal ‘word2’.
[IF(a!а){well done}]‘well done’ because the first ‘a’ is in Latin, the second, Cyrillic.

Crucially — and this is what makes these tools really powerful — you can compare custom variables and the user’s earlier responses.

Please see the documentation on Custom Variables and Prior Responses.

Suppose you have earlier defined [customVar x=5] [customVar z=8].

To use these logic tools you would follow the structure of these examples:

[IF([showVar=x]=5){well done}]
[IF([showVar=z]!hello){well done}]
[IF(1<[showVar=x]){well done}]
[IF([showVar=x]![showVar=z]){well done}]

In each of these four instances, the chatbot would say, ‘well done’, because x does equal 5, z does not equal, hello, 1 is less than 5 and 5 does not equal 8.

You can compare a user's prior response to extracted data to a variable, to a number, to a word, or to a response or an extracted data from the other interaction:

So, for example:

[IF([responseTo interaction=999 fallback=no]=Yes){well done}]

This will cause the bot to say ‘well done’ if the user’s input at interaction 999 was ‘Yes’, otherwise, the bot will do nothing.

[IF([extractedData interaction=999 fallback=no data]>10){well done}]

This will cause the bot to say ‘well done’ if the user’s input at interaction 999 is a number greater than ten. Otherwise, the bot will do nothing.

You can be really creative with this ability to assess numbers and letters, allowing your chatbot to give sophisticated responses to developments within the conversation.


See our educational chatbots in the bot store for examples of smart ways to use this feature (and also the engagement template here).

Watch this video tutorial to learn ''Using logic operations with your SnatchBot chatbot''

Next Steps

Menu that is always available for the user during the conversation.