Function reference

Function reference

Functions are small autonomous programms that “take in” some data as parameters, process it and return a resulting value. You can use functions to compute values of the variables or to condition bot answers to create complex dialogue flows. Here you can find a reference of currently supported functions with examples for the use in conditions.

 

length($string$)

Returns the length of the  given $string$.

  • Example: length ($pw$) == 8

the condition checks whether $pw$ consists of exactly 8 characters

 

substr ($string$, $start$, $length$)

Returns the part of a string $string$ defined by $start$ (integer) and $length (integer) parameters. $string$ can be of type “text”, “word” oder “number”.

  • Example: substr ($profile_number$, 0, 2) == "49"

checks if a user’s profile number starts with „49“

 

round($number$, $precision$)

Returns the rounded value of $number$ to specified $precision$ (number of digits after the decimal point). $precision$ can also be negative or zero (default). If $precision$ is negative the rounding will occur before the decimal point.

  • Example: round ($age$, 0) >= 18

checks whether rounded $age$ equals or is greater than 18

 

floor($number$)

Returns the next lowest integer value by rounding down $number$ if necessary.

  • Example: $number$ – floor($number$) == 0

the compound condition checks whether $number$ is an integer

 

ceil($number$)

Returns the next highest integer value by rounding up $number$.

  • Example: ceil ($number$) == 1

checks if $number$ rounded up is 1

 

abs($number$)

Returns the absolute value of $number$.

  • Example: abs($number$) < 10

checks if absolute value of $number$ is smaller than 10

 

in_array($string$,$array$)

Checks if $string$ is an element of the collection $array$ and returns 1 if true.

  • Example: in_array ("red", $preferred_colors$)

checks if color “red“ is saved in the collection $favourite_colors$

 

preg_match("/$pattern$/", $string$)

Searches $string$ for a match to the regular expression $pattern$. Returns 1 in case of a match and 0 in case of no match. Please make sure to embed the regular expression in “/ and /”  (“/$pattern$/”).

  • Example: preg_match("/^[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9_\-\.]+\.[a-zA-Z]{2,5}$/", $email$) == 1

checks whether $email$ has a valid format

 


Temporal functions with example usage in conditions

 

now()

Returns current Unix Timestamp (number of seconds from 01. January 1970 00:00:00 UTC)

  • Example:now() <= 1541526600

checks if the timestamp of NOW is smaller than (the timestamp of) 11/06/2018 5:50pm (UTC)

 

today()

Returns Unix timestamp of 0 a.m. of today’s date in the channel time zone (defined in channel settings) in seconds. A comparison with a date in the format DD.MM.YYYY or MM/DD/YYY is allowed in conditions.

  • Example: today() == 01.01.2021

checks if it is 01.01.2021

 

now() – today ()

Returns current time in the channel timezone in seconds.

  • Example: now() – today() < 43200

checks whether it is forenoon (12 hours in seconds = 43200)

 

to_seconds($time$)

transforms $time$ inputted as hh:mm to seconds.

  • Example: now()-today() < to_seconds("12:00")

checks whether it is forenoon

 

yesterday()

Returns timestamp of yesterday at the same time (computed as now() – 24*3600). A comparison with a date in the format DD.MM.YYYY or MM/DD/YYY is allowed in conditions.

  • Example: yesterday() == 31.12.2020

checks whether yesterday’s date was 31.12.2020

 

tomorrow()

Returns timestamp of tomorrow at the same time (computed as now() + 24*3600). A comparison with a date in the format DD.MM.YYYY or MM/DD/YYY is allowed in conditions.

  • Example: tomorrow() == 02.01.2020

checks tomorrow is 02.01.2020

 

weekday()

returns current weekday (1-7 for Monday-Sunday)

  • Example: weekday() == 7

checks it if is Sunday today

 

month()

returns current month

  • Example: month() == 6

checks if it is June

 

day()

Returns current day of the month

  • Example: day() == 20

compound conditions checks if it is 20th June.

unix_timestamp(time)

The function expects to be given a string containing an English date format and will try to parse that format into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 UTC)

 

time_format($format$, $timestamp$)

Returns time formatted according to the string in $format$ using the given integer $timestamp$ or the current time if no timestamp is given.

The followings characters are recognized in the format parameter string:

Format character Description Example returned values
a Lowercase Ante meridiem and Post meridiem am or pm
A Uppercase Ante meridiem and Post meridiem AM or PM
g 12-hour format of an hour without leading zeros 1 through 12
G 24-hour format of an hour without leading zeros 0 through 23
h 12-hour format of an hour with leading zeros 01 through 12
H 24-hour format of an hour with leading zeros 00 through 23
i Minutes with leading zeros 00 to 59
s Seconds with leading zeros 00 through 59
e Timezone identifier Examples: UTC, GMT, Atlantic/Azores
P Difference to Greenwich time (GMT) with colon between hours and minutes Example: +02:00
T Timezone abbreviation Examples: EST, MDT …

 

  • Example: $time=(time_format("H:i“))$ 

here current time is in a format hh:mm is passed to the variable $time$ (type “text”).

Time_format() function is based on the php date() function. Please find its description and a comprehensive list of formatting options here.