Q: What are variables? How do I use them?
A: A variable is a storage for data. For example, Voximplant Kit has standard {{phone}} and {{UTC}} variables. The {{phone}} variable is used for storing the phone numbers; the {{UTC}} variable stores the customer’s time zone. You can use standard variables or create your own ones.
Example 1. Using a standard variable in Voximplant Kit.
The minimum set of blocks above performs the following:
Starts a scenarioCalls a customerIf the customer answers the phone, the scenario ends with a successful statusIf the customer couldn’t be reached, the scenario finishes with the unsuccessful status. The Call to Number block covers step 2. Clicking this block will open its settings. It is a simple block with only one parameter: Phone.By default, the parameter value is the {{phone}} variable.
The {{phone}} variable contains the customers’ phone numbers from your Excel file (see New Campaign, step 4, Map).
Using a standard {{phone}} variable based on the example of the speech synthesis block:
Example 2. Creating and using a new variable.
The Data Modification block allows you to change the variables and create new ones. Add this block to your scenario and click it. The block settings have the Variable and Value fields. Click the Variable field to select a variable in the list or type a name for a new variable.
IMPORTANT! The variable name can only contain Latin letters and numbers. You must enclose the name in curly brackets. The variable names are case-sensitive; {{Phone}} and {{phone}} are two different variables
Let's assume that you want to add the VIP status for a customer. To do this, create a variable named {{VIP}}, set it to yes, and click Save. That’s it! Now you can use your new variable in the next blocks.
Q: Is there an “advanced” way to manage variables?
Yes, there are special templates in Voximplant Kit for this purpose; using them, you can add working hours checking, convert the date format, round the retrieved values, etc.
CEIL
Round up to a whole number.
Numbers having more than 20 digits, written in exponential notation, and strings cause the error.
For example, variable test = 2.344
{{CEIL 5.344}} >>> 6
{{CEIL test}} >>> 3
{{CEIL -1.1}} >>> -1
FLOOR
Round down to a whole number.
Numbers having more than 20 digits, written in exponential notation, and strings cause the error.
For example, variable test = 2.344
{{FLOOR 5.344}} >>> 5
{{FLOOR test}} >>> 2
{{FLOOR -1.1}} >>> -2
CHECK_HOURS
Check if the time of a function call matches with the specified range.
{{CHECK_HOURS from to timezone type}}
{{CHECK_HOURS '09:30' '19:30' '+3' 'all'}} >>> 1 или 0
COMPARE
Comparison of two values /variables. The following comparison characters are supported: "==", "!=" (means not equal), ">", "<", "<=", ">=".
{{#COMPARE v1 operator v2}} if_true {{else}} if_false {{/COMPARE}}
It is mandatory to explicitly define values returned during comparison (e.g., “yes” if the condition is met and “NO” otherwise)
{{#COMPARE 'test' '==' 'tust'}} true {{else}} false {{/COMPARE}} >>> false
For example, variable order_found = yes
{{#COMPARE order_found '==' 'yes'}}
order found {{else}}
order not found {{/COMPARE}}
>>> order found
CALC
Mathematical functions: addition, subtraction, multiplication, division.
{{#CALC}} equations {{/CALC}}
Variables inside CALC must be in curly brackets.
For example, variable price = 10
{{#CALC}}
{{price}} * 5{{/CALC}}
>>> 50
DATE_CONVERT
Date format conversion.
{{DATE_CONVERT date old_format new_format}}
For example, variable order_data = 12:00 25.12.2019
{{DATE_CONVERT order_data 'HH:mm DD.MM.YYYY' 'DD/MM/YYY'}}
>>> 25/12/2019
Original date 12:00 23.01.2018
Original format: HH:mm DD.MM.YYYY
New format | Result | MM/DD/YY | 01/23/18 |
MM/DD/YYYY | 01/23/2018 |
YY.MM.DD | 18.01.23 |
YYYY.MM.DD | 2018.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 |
PLUCK
Creating a new array from the values of the old array based on the key.
{{PLUCK array key value}}
For example, variable array_sample = [{"id": 1, "value": "q"}, {"id": 2, "value": "w"}, {"id": 3, "value": "e"}]
{{PLUCK array_sample 'id'}}
>>> [1,2,3]
FILTERBY
Filter data by the specified parameter and its value. A new array is returned since a source array isn’t mutated.
{{FILTERBY array key value}}
For example, 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
Find the first array element that satisfies the provided key value.
{{FINDBY array key value}}
For example, 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
Convert an array to a string with the specified delimiter.
For example, variable test = ["summer","autumn","winter","spring"]
{{JOIN test '|'}}
>>> summer|autumn|winter|spring
LENGTH
The length of the string/array.
An array with single quotes ['1', '2', '3'] вis treated as a string (LENGTH — 15).
For example, 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 (количество ключей)
LOWERCASE
Convert a string to lower case.
For example, variable test = "WONDERFUL order"
{{LOWERCASE test}} >>> wonderful order
UPPERCASE
Convert a string to upper case.
For example, variable test = "WONDERFUL order"
{{UPPERCASE test}} >>> WONDERFUL ORDER
PHONE_FORMAT
Remove all non-digits from the specified string.
For example, variable test = "+7-917 562 02 -34"
{{PHONE_FORMAT test}} >>> 79175620234
REPLACE
Replacing one value by another in the specified string.
For example, variable test = "John"
{{REPLACE 'Hello, my name is NAME' 'NAME' test}}
>>> Hello, my name is John
REVERSE
Reverse the specified string/array.
For example, 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
Sort the array values in ascending order. The numbers are sorted first then followed by the letters.
For descending order use the option reverse = 1.
For example, variable test_array = ["banana", "apple", "coconut", "carrot"]
{{SORT test_array}} >>> ["apple","banana","carrot","coconut"]
{{SORT test_array reverse=1}} >>> ["coconut","carrot","banana","apple"]
SORTBY
Sort an array by a specific argument in ascending order.
For descending order use the option reverse = 1.
For example, 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
Convert a string to an array regarding the specified delimiter.
For example, variable test = "summer;autumn;winter;spring"
{{SPLIT str separator}} >>> ["summer","autumn","winter","spring"]