Expressions always begin with a dollar sign and an opening square bracket and end with a closing square bracket:
$[expression]
Example:
$[${COUNT}+1]
Example in dialplan
exten => 321,1,Set(COUNT=3)
exten => 321,n,Set(NEWCOUNT=$[${COUNT}+1])
exten => 321,n,SayNumber(${NEWCOUNT})
Operators
Boolean operators
expr1 expr2 (OR)
expr1 & expr2 (AND)
expr1 {=, >, >=, <, <=, !=} expr2
Mathematical operators
expr1 {+, -} expr2
expr1 {*, /, %} expr2
Dialplan Functions
Function_Name(argument)
${FUNCTION_NAME(argument)}
Conditional Branching
The GotoIf() Application evaluates an expression and sends the caller to a specific destination based on whether the expression evaluates to true or false.
GotoIf () uses a special syntax, often called the conditional syntax:
GotoIf(expression?destination1:destination2)
If the expression evaluates to true, the caller is sent to destination1. If the expression evaluates to false, the caller is sent to the second destination. So, what is true and what is false? An empty string and the number 0 evaluate as false. Anthing else evaluates as true.
The destinations can each be one of the following:
- A priority label with the same extension, such as weasels
- An extension and a priority label within the same context, such as 123, weasels
- A context, extension, and priority label, such as incoming, 123, weasels
Example:
exten => 345,1,Set(TEST=1)
exten => 345,n,GotoIf($[${TEST}=1]?weasels:iguanas)
exten => 345,n(weasels), Playback(weasels-eaten-phonesys)
exten => 345,n, Hangup()