How to use variables in Cally Square

How to use variables in Cally Square

Overview

In this page you will learn how to use variables in the Cally Square IVR projects.

Remember all the variables can be defined in two ways:

  • in the Tools section (see Variables)

  • inside the Cally Square IVR project designer (File → Variable)

image-20251007-081919.png

 

Syntax

The variable format that you need to use in Cally Square is {VARIABLENAME}

DO NOT use the $ character before the {}.

Asterisk channel variables list

The variable format in Cally Square is slightly different from the Asterisk one. See here for Asterisk Standard Channel Variables.

Set a Variable

A common operation is assigning a value to a variable. The value can be a string, a number, or another variable, such as Asterisk variables or custom variables.

Example: the Asterisk variable ${CALLERID(num)} must be defined as {CALLERID(num)} in the Cally Square environment.

image-20250227-150916.png

You can configure the Set block in the Cally Square IVR Designer as below:

  • Label: enter a short description of the block

  • Variable: select the variable from the list

  • Value: insert the value of the variable you need

    • in this example: {CALLERID(num)}

As result, The variable CALLER_NUMBER will contain the caller number.

DB Query Result

Using the Database block you need to specify the variable where the query result will be saved.

For example, we want to retrieve the customer name from the orders table where the order number is previously inserted by the caller.

image-20250227-152243.png

You can configure the Database block in the Cally Square IVR Designer as below:

  • Label: enter a short description of the block

  • ODBC Connection: select the connection to the DB

  • Query: insert the query

    • in this example: SELECT customer_name FROM orders WHERE order_num={ORDERNUM}

  • Variable: select the variable from the list

The result set is stored into a matrix as:

{VARIABLENAME[row][column name]}

that is

{DBRESULT[0][customer_name]}

The first row has the index 0 (zero).

Built-in variables

We provide the following Asterisk channels variables named:

variable name + _ROWS_COUNT: shows the number of affected rows (only for SELECT statements).

Example: {RESULT_ROWS_COUNT}

 

 

Asterisk Dialplan Functions

Using Asterisk dialplan functions can be helpful to gather information about agents or the queue status before routing calls to a queue.

Example:

In the GotoIf block we run a function to get the number of the current waiting calls in the queue.

If there are more than 5 waiting calls, the new callers will hear a message (playback block) that invite them to call later.

Here is the function we used into the GotoIf block:

{QUEUE_WAITING_COUNT(queuename)} >= 5

** replace "queuename" with the name of the queue you want to check.

Asterisk dialplan functions list

See here  for Standard Asterisk Dialplan Functions.

Javascript Methods

Cally Square is able to manage also the javascript methods.

For example, we need to check the caller prefix in order to send the call to the correct queue (local or UK callers).

The GotoIf condition is: ‘{PRODUCT_TYPE}’ == ‘option’

Javascript string methods

See here for JavaScript String Methods

Array Handler

With the Math block we are able to execute mathematical operations, javascript methods (as described in the previous section) and handle an array of values.

Example:

There is a variable called INPUT_DATA that contains a separated string:

John,Doe,998,john.doe@xcally.com

We want to set each value to a different variable ({FIRST_NAME}, {LAST_NAME},{EXTENSION},{EMAIL})

image-20250227-154720.png
image-20250227-154909.png

You can configure the Math block in the Cally Square IVR Designer as below:

  • Label: enter a short description of the block

  • Operation: enter the operation you need

    • in this example: '{INPUT_DATA}'.split(",")

  • Variable: select the variable from the list

 

After that you need to configure Set blocks as below:

  • Label: enter a short description of the block

  • Variable: select the variable from the list

    • in this example: EMAIL

  • Value: enter the value of the variable

    • in this example: EMAIL = {RESULT[3]}

 

As result, The variable EMAIL will contain the email extracted from the INPUT_DATA string.

In the same way, you can set also the other variables:

FIRST_NAME = {RESULT[0]} (John)

LAST_NAME = {RESULT[1]} (Doe)

EXTENSION = {RESULT[2]} (998)