Skip to main content

Expressions

Expressions in VoXML allow you to build complex, in-line conditionals for <Do> and <If>.

Variables

As a developer, you have access to any variable stored during the call. Variables can be directly stored and removed via the <Set> and <Unset> verbs. Likewise, variables can be indirectly set via the <Gather> and <Dial> Voice verbs if their respective output attribute is set.

<Gather> sets the following variables:

<output>.digits, for example: menu.digits
<output>.speech, for example: menu.speech

<Dial> sets the following variables:

<output>.status, for example: xfer.status

The <Do> control conditional sets the following variable:

do.n, where the value is the current iteration (base of 0)

To access a variable in an expression, the variable name must be wrapped in ${...}. For example:

${menu.digits}=="123"

Operators

The following operators are supported:

OperatorDescription
==equal
!=not equal
=~regular expression matching
!~regular expression not-matching
&&logical AND
||logical OR

It is best practice to wrap conditional in single or double quotes to avoid parsing errors. For example:

${menu.speech}=~(support|sales)    // bad
${menu.speech}=~'(support|sales)' // good

Examples

The following are valid expressions:

${menu.digits}=="1" || ${menu.speech}=~"(power|outage)"
1 == ${var}
${var}!~"(support|pharmacy)"