If-Else conditions

If-Else conditions

With the condition function you can define rules for the Bot answers. In this way you can create different messages for different messenger types.

By clicking on the button +Condition you can set up new conditions for bot answers. With the condition function you can define rules for the Bot answers, for instance by comparing current value of a variable with another value. For instance, in this way you can create different messages for different messenger types. The first condition in our example here compared current value of a system variable $profile_messenger$ to an abbreviation “WB” to check whether profile messenger of a user is WhatsApp. If not true, the bot will check the second condition which does a similar comparison for Facebook Messenger.


Conditions in details

1) Variables are often user to create conditions. 

Variables are typed with the dollar symbol before and after the variable name, for example: $profile_messenger$. A few variables have already been pre-set, and will appear when you type in a dollar sign. If you set your own variables, they will also appear in this selection.

2) The rules for Bot answers are defined through operators and functions.

Possible operators are:

Mathematic operators: * (plus), - (mins), * (multiplied by), / (divided by)

Comparative operators: == (the same), != (not the same), >= (bigger or the same), > (bigger), <= (smaller or the same), < (smaller)

Logical Operators: and (use when you want two or more conditions to be fulfilled), or (use when you want one condition be fulfilled), not (use when something should not be fulfilled).

3) You can structure conditions with parentheses ().

You may need to create a structure when there are a variety of conditions with logical operators.

for instance: ($profile_messenger$=="FB" or $profile_messenger$=="TG") and $customernummer$!=""

–>  if a profile messeger is telegram or facebook messenger and a variable constomer number is not empty

 

4) There is a variety of possible functions that you can use to create different conditions (see also the complete function reference):

  • Modulo-Operator: gives you the result of a division x%y === Rest (x, y, and Rest are numbers)
  • Recognition of relative dates like yesterday(), today(), tomorrow()
  • Recognition of weekdays: weekday()
  • Recognition of relative dates that refer to specific day of the month, like first_day_of(“Name of the Month”)
  • Calculation and comparison of values in conjunction with mathematic and comparative operators
  • Listing of times (in seconds) on a date value
  • Recognition of the length of a chain of numbers

Examples:
  • Combinationed condition: $profile_messenger$ == WB and $Interest$ == Sport
  • No preferences have been set yet: $Interest$ != “”
  • Several combined conditions: $profile_messenger$ == “WB” and ($interest$ == “mountainbike” or $interest$ == “racebike”)
  • Compare today’s date with a specific date: today() == 01.01.2018
  • Compare the current time to the set time of a user property: (now()-today()) < to_seconds(“12:00”) (is it forenoon?) 
  • It is X-weekday: weekday() == 1 checks if today is Monday; weekday() == 2 checks if today is Tuesday; etc.
  • Modulus: variables with number values will be calculated and the remaining value will be checked: ($Variable1$ + $variable2$) % 2 == 1
  • Message should be sent if the password is the incorrect length: length($PW$)!08
  • See the complete function reference for more examples.