<If>
The <If> conditional allows you to implement If/Then style conditionals.
<If> Attributes
<If> supports the following attributes that change its behavior:
| Attribute | Allowed Values | Default Value |
|---|---|---|
| expression | string expression to evaluate | none |
expression
The expression attribute accepts a string of conditionals to evaluate. If the expression evaluates to true, then all verbs nested inside <If> are executed. Otherwise, the nested verbs are ignored and the next VoXML instruction is executed.
<If> Examples
Simple Usage
Welcome the caller, transcribe input, and evaluate response.
<Response>
<Gather input="speech" output="menu">
<Say>Hello. What is the purpose of your call?</Say>
</Gather>
<If expression="${menu.speech}=~'(support|sales)'">
<Say>Transferring you to support or sales.</Say>
</If>
</Response>
Advanced Usage
Welcome the caller, then route them to support or sales based on their response.
<Response>
<Gather input="speech" output="menu">
<Say>Hello. Are you calling for support or sales?</Say>
</Gather>
<If expression="${menu.speech}=~'support'">
<Say>Transferring you to support.</Say>
<Dial timeout="30">
<Number>13003003000</Number>
</Dial>
</If>
<If expression="${menu.speech}=~'sales'">
<Say>Transferring you to sales.</Say>
<Dial timeout="30">
<Number>13003003001</Number>
</Dial>
</If>
</Response>