Want to make your blocks more dynamic? You can include Handlebars expressions in specific blocks like text fields and 'set attribute'. These expressions will be calculated when your application is running.
We've also made your life easier with our own custom Handlebars functions, designed to streamline certain features. Check out the list below for all of them:
- Dynamic Sum
- Conditional Statements
- Literal Strings
- Temporal Functions
- date
- dateTime
- isNowBetweenTimes
- isNowWeekend
- isTodayAnyOf
- Timezones
Dynamic Sum
Related ticket:
Formula: {{ sum ${attr_1} ${attr_2} ${attr_3} }}
Let’s imagine you’re collecting number attributes. number_1
is set to 4, number_2
is set to 5 and number_3
is set to 6. Now you want to create another attribute that is set to the sum of the previous attributes. You can create a new sum_result
attribute whose value would be:
{{ sum ${number_1} ${number_2} ${number_3} }}
Now when a conversation trigger that block, the sum_result
attribute will be set to the sum of the previous attributes (in this case, 15).
Notes:
- Be aware of adding spaces between the attributes
- If one of the attributes is not a valid number, it will be automatically set to 0. So if in the previous example
number_1
is equal tobanana
instead of a number,sum_result
will be set to11
- The
sum
function receives an arbitrarily number of attributes, in this case we’re evaluating 3 but it can be 1, 10, or even 100.
Conditional Statements
We support 6 different conditional statements:
#eq: Equal
#neq: Not Equal
#gt: Greater Than
#gte: Greater Than or Equal
#lt: Less Than
#lte: Less Than or Equal
For example, lets imagine we have two attributes: attr
and threshold
and we want to set a new is_greater_than_threshold
attribute to yes or no depending if value > threshold, we can use the following formula:
{{#gt ${attr} ${threshold} }}
yes
{{else}}
no
{{/gt}}
All of the conditional statements are used in a similar way. If we want to set the attribute a_equal_b
to yes or no depending of the values of attributes a
and b
we would use the following formula:
{{#eq ${a} ${b} }}
yes
{{else}}
no
{{/eq}}
Literal Strings
A comparison against literal values, needs to be quoted.
Example comparing attribute state
with literal string:
{{#eq '${state}' 'Alabama'}}
AL
{{else}}
{{#eq '${state}' 'Alaska'}}
AK
{{else}}
{{#eq '${state}' 'Arizona'}}
AZ
{{else}}
{{#eq '${state}' 'California'}}
CA
{{else}}
None
{{/eq}}
{{/eq}}
{{/eq}}
{{/eq}}
Temporal Functions
date
Evaluates the current date in yyyy-MM-dd
format, e.g. 2023-07-12
for July 7th, 2023.
Parameters:
- (Optional) A timezone context to use for evaluation. Defaults to UTC if unspecified.t
Examples:
// The current date in the UTC timezone
{{ date }}
// The current date in Seoul
{{ date 'Asia/Seoul' }}
In the following screenshot, an attribute named attribute_date
is:
- Set in the first card using the
date
helper - Printed in the second card
dateTime
Evaluates the current date in YYYY-MM-DDTHH:mm:ss.sssZ
format, e.g. 2024-02-29T15:21:33.243
for Feb 29th, 2024 15:21:33.243.
Parameters:
- (Optional) A timezone context to use for evaluation. Defaults to UTC if unspecified.t
Examples:
// The current date in the UTC timezone
{{ dateTime }}
// The current date in La Paz
{{ dateTime 'America/La_Paz' }}
In the following screenshot, an attribute named attribute_date_time
is:
- Set in the first card using the
dateTime
helper - Printed in the second card
isNowBetweenTimes
Evaluates if the current time is between the specified time boundary:
- If true, evaluates to
Yes
- If false, evaluates to
No
Parameters:
- (Required) Minimum and maximum time boundaries expressed in the format
HHmm-HHmm
. If the minimum value exceeds the maximum, e.g.1800-0100
, the maximum value is assumed to fall on the next day. - (Optional) A timezone context to use for evaluation. Defaults to UTC if unspecified.
Examples:
// Is it presently between 5pm (today) and 1am (next day) in the UTC timezone?
{{ isNowBetweenTimes '1700-0100' }}
// Is it presently between 5pm (today) and 1am (next day) in Seoul?
{{ isNowBetweenTimes '1700-0100' 'Asia/Seoul' }}
In the following screenshot, an attribute named attribute_is_now_working_time
is:
- Set in the first card using the
isNowBetweenTimes
helper function - Printed in the second card
- Used for control flow in the third card
isNowWeekend
Evaluates if the current time falls on the weekend.
- If true, evaluates to
Yes
- If false, evaluates to
No
Parameters:
- (Optional) A timezone context to use for evaluation. Defaults to UTC if unspecified.
Examples:
// Is it presently the weekend in the UTC timezone?
{{ isNowWeekend }}
// Is it presently the weekned in Seoul?
{{ isNowWeekend 'Asia/Seoul' }}
In the following screenshot, an attribute named attribute_is_today_weekend
is:
- Set in the first card using the
isNowWeekend
helper function - Printed in the second card
- Used for control flow in the third card
isTodayAnyOf
Evaluates if the current day/time falls on any of the speciifed dates.
- If true, evaluates to
Yes
- If false, evaluates to
No
Parameters:
- (Required) A comma-separated list of dates expressed in the format
yyyy-MM-dd
. Whitespace between dates is optional. - (Optional) A timezone context to use for evaluation. Defaults to UTC if unspecified.
Examples:
// Is it presently Christmas Day or New Year's Day in the UTC timezone?
{{ isTodayAnyOf '2023-12-25, 2024-01-01' }}
// Is it presently Christmas Day or New Year's Day in Seoul?
{{ isTodayAnyOf '2023-12-25, 2024-01-01' 'Asia/Seoul' }}
In the following screenshot, an attribute named attribute_is_today_holiday
is:
- Set in the first card using the
isTodayAnyOf
helper function - Printed in the second card
- Used for control flow in the third card
Timezones
US timezones include:
US/Alaska
US/Arizona
US/Michigan
US/Central
US/Hawaii
US/Mountain
US/Samoa
US/Eastern
US/East-Indiana
US/Indiana-Starke
US/Aleutian
US/Pacific
In the following screenshot, an attribute named attribute_is_today_weekend
is: