Rate this page:

Using helpers

Helpers are action templates that allow you to transform variables, for example, convert a string into an array, or perform additional data validation, for example, check business hours.

A helper needs to be configured in the Data modification block. For that, create a variable or modify an existing one. As a variable value, you can write both variables and plain values. Use single quotes for plain values.

Available helpers:

Copy URL

CEIL

Copy URL

Rounds up to a whole number.

Note

Numbers greater than 20 digits, exponential numbers, and strings cause an error.

Format: {{CEIL variable}}

Example, where variable test = 2.344:

{{CEIL 5.344}} >>> 6
{{CEIL test}} >>> 3
{{CEIL -1.1}} >>> -1

FLOOR

Copy URL

Rounds down to a whole number.

Note

Numbers greater than 20 digits, exponential numbers, and strings cause an error.

Format: {{FLOOR variable}}

Example, where variable test = 2.344:

{{FLOOR 5.344}} >>> 5
{{FLOOR test}} >>> 2
{{FLOOR -1.1}} >>> -2

CHECK_HOURS

Copy URL

Checks if the current time falls within the specified range. You can use this helper to control the time of placing/forwarding calls, etc. For the helper to work correctly, use it in combination with the Data verification block.

Note

Numbers greater than 20 digits, exponential numbers, and strings cause an error.

Format: {{CHECK_HOURS from to timezone type}}, where:

  • From – date range start time (lower threshold)

  • To – date range end time (upper threshold)

  • Timezone – timezone

  • Type – day of the week (the options are all, weekdays, weekends)

A variable with the CHECK_HOURS helper can take the value of 1 or 0.

Example:

{{CHECK_HOURS '09:30''19:30''+3''weekdays'}} >>> 1 or 0

In the example, the variable will take the value of 1 on weekdays from 9:30 am to 7:30 pm (timezone +3). In other cases, it will take the value of 0.

COMPARE

Copy URL

Compares two values/variables:

  • '==' – equal to

  • '!=' – not equal to

  • '>' – greater than

  • '<' – less than

  • '<=' – less than or equal to

  • '>=' – greater than or equal to

  • '&&' – or

  • '||' – and

Important

The helper can only perform one comparison at a time.

Format: {{#COMPARE v1 operator v2}} if_true {{else}} if_false {{/COMPARE}}, where:

  • V1 – what is compared

  • Operator – agent

  • V2 – what is V1 compared to

  • If_true – what if the condition is met

  • If_false – what if the condition is not met

It is required to explicitly define values returned during comparison (e.g., 'yes' if the condition is met and 'no' in other cases).

Example:

{{#COMPAREorder_found\'==\'\'yes\'}} order found {{else}} order not found {{/COMPARE}} >>> order found

CALC

Copy URL

Performs math operations: addition, subtraction, multiplication, division ('/'), exponentiation ('^'), remainder of division ('%'), and trigonometric functions (sin, cos, and tan).

Format: {{#CALC}} equations {{/CALC}}

Variables inside CALC must be in double curly brackets.

Important

The helper cannot perform multiple operations in one variable. Break down the operations into different variables.

Example, where variable price=10:

{{#CALC}} '+'{{price}} * 5'+'{{/CALC}} >>> 50

DATE_CONVERT

Copy URL

Converts a date from one format to another.

Note

There are no predefined variables in Voximplant Kit that contain the date in any format. You need to manually create a variable or use external resources.

Format: {{DATE_CONVERT date old_format new_format}}

Available date formats and how they display:

New format

Result

MM/DD/YY

01/23/18

MM/DD/YYYY

01/23/2018

YY.MM.DD

18.01.23

DD/MM/YY

23/01/18

DD/MM/YYYY

23/01/2018

DD.MM.YY

23.01.18

DD.MM.YYYY

23.01.2018

DD-MM-YY

23-01-18

DD-MM-YYYY

23-01-2018

HH:mm:SS

12:00:00

MM-DD-YY

01-23-18

MM-DD-YYYY

01-23-2018

YY/MM/DD

18/01/23

YYYY/MM/DD

2018/01/23

YYMMDD

180123

YYYYMMDD

20180123

DD MMM

23 Mar

DD MMMM

23 March

DD MMMM YYYY

23 March 2018

DD MMMM YY

23 March 18

dddd, MMMM D, YYYY

Friday, March 23, 2018

HH:mm:ss.SSS

13:20:00.000

M/D/YY

3/23/18

MMM D, YYYY

Mar 23, 2018

MMMM D, YYYY

March 23, 2018

HH:mm:ss YY/MM/DD

12:00:00 18/03/23

Example, where the original date is 12:00 23.01.2018 and the original format is HH:mm DD.MM.YYYY:

{{DATE_CONVERTorder_data\'HH:mm DD.MM.YYYY\'\'DD/MM/YYY\'}} >>> 25/12/2019

PLUCK

Copy URL

Creates a new array using the values of an old array based on a certain key.

Format: {{PLUCK array key value}}

Example, where variable array_sample = [{"id": 1, "value": "q"}, {"id": 2, "value": "w"}, {"id": 3, "value": "e"}]:

{{PLUCK array_sample 'id'}} >>> [1,2,3]

FILTERBY

Copy URL

Filters data by a specific parameter and its value. Returns a new array; the initial data does not change.

Format: {{FILTERBY array key value}}

Example, where variable array_sample = [{"id": 1, "value": "q"}, {"id": 2, "value": "w"}, {"id": 1, "value": "e"}]:

{{FILTERBY array_sample 'id' 1}} >>> [{"id":1,"value":"q"},{"id":1,"value":"e"}]

FINDBY

Copy URL

Finds the first array element that satisfies the provided key value.

Format: {{FINDBY array key value}}

Example, where variable array_sample = [{"id": 1, "value": "q"}, {"id": 2, "value": "w"}, {"id": 3, "value": "e"}]:

{{FINDBY array_sample 'id' 1}} >>> {"id": 1, "value": "q"}

JOIN

Copy URL

Converts an array to a string with a delimiter.

Format: {{JOIN array separator}}

Example, where variable test = ["summer","autumn","winter","spring"]:

{{JOIN test '|'}} >>> summer|autumn|winter|spring

LENGTH

Copy URL

Displays the length of a string/array.

Format: {{LENGTH str}}

Information

An array with single quotes ['1', '2', '3'] is treated as a string.

Example, where variable test_str = 'text example'; variable test_array = ["apple", "banana", "carrot", "coconut"]; variable test_obj = {"key1": 1, "key2": 2, "key3": 3}:

{{LENGTH test_str}} >>> 12
{{LENGTH test_array}} >>> 4
{{LENGTH test_obj}} >>> 3 (number of keys)

LOWERCASE

Copy URL

Converts a string to lowercase.

Format: {{LOWERCASE str}}

Example, where variable test = 'WONDERFUL order':

{{LOWERCASE test}} >>> wonderful order

UPPERCASE

Copy URL

Converts a string to uppercase.

Format: {{UPPERCASE str}}

Example, where variable test = 'WONDERFUL order':

{{UPPERCASE test}} >>> WONDERFUL ORDER

PHONE_FORMAT

Copy URL

Removes all non-digits from a string.

Format: {{PHONE_FORMAT str}}

Example, where variable test = '+1-474 000 00-00':

{{PHONE_FORMAT test}} >>> 14740000000

REPLACE

Copy URL

Replaces one string value with another.

Format: {{REPLACE str A B}}

Note

If the value you want to replace appears in a string multiple times, it will be replaced everywhere. For example, when you replace 'John' with 'Jack' in a variable that contains 'John Johnson', the result will be 'Jack Jackson'.

Example, where variable test = 'John':

{{REPLACE 'Hello, my name is NAME''NAME'test}} >>> Hello, my name is John

REVERSE

Copy URL

Reverses a string/array.

Format: {{REVERSE variable}}

Example, where variable test_str = 'Some text'; variable test_arr = [1,2,3,4,5]:

{{REVERSE test_str}} >>> txet emoS
{{REVERSE test_arr}} >>> [5,4,3,2,1]

SORT

Copy URL

Sorts array values in ascending order. The system first sorts numbers, then letters.

Format: {{SORT array}}

Information

For descending order, use {{SORT array reverse=1}}.

Example, where variable test_array = ['banana', 'apple', 'coconut', 'carrot']:

{{SORT test_array}} >>> ["apple","banana","carrot","coconut"]
{{SORT test_array reverse=1}} >>> ["coconut","carrot","banana","apple"]

SORTBY

Copy URL

Sorts an array by a specific argument in ascending order. Similarly to SORT, use the option reverse = 1 for descending order.

Format: {{SORTBY array key}}

Example, where variable array_sample = [{"id": 1, "value": "z"}, {"id": 2, "value": "a"}, {"id": 1, "value": "x"}]:

{{SORTBY array_sample 'value'}} >>> [{"id":2,"value":"a"},{"id":1,"value":"x"},{"id":1,"value":"z"}]

SPLIT

Copy URL

Converts a string to an array specifying a delimiter.

Format: {{SPLIT str separator}}

Example, where variable test = 'summer;autumn;winter;spring':

{{SPLIT test';'}} >>> ["summer","autumn","winter","spring"]