Smart Dialplan - use of Custom Applications
Smart Dialplan explains how to use Custom Applications in Wildix Dialplan to interact with external software and databases.
Updated: October 2023
Permalink: https://wildix.atlassian.net/wiki/x/1Q3OAQ
AGI in “Custom Application”
Variables in Dialplan
Variables are needed to store the information necessary to execute the application.
Syntax used to set a variable: set(variablename=value)
Where:
variablename: is the name of the variable, it is insensitive to the variables defined by users
value: is the value attributed to the variable; value can be a function.
Syntax used to call a variable: ${variablename}
Example:
Set a variable: set(foo=123456789)
Call a variable: ${foo:offset:length}
Where:
foo: is the name of the variable
offset: optional offset in starting to read a variable
length: optional number of characters to read
${foo} → 123456789
${foO:1} → 23456789
${Foo:-4:3} → 678
Dialplan example:
- set(FOO=101) - sets the name of the variable as FOO and the value as 101
- Dial(SIP/${FOO}) - dials 101
Here are some useful variables:
${CALLERID(all)}: The current Caller ID name and number
${CALLERID(name)}: The current Caller ID name
${CALLERID(num)}: The current Caller ID number ${ANSWEREDTIME}: Elapsed time since the call has been answered
${EXTEN}: Extension
${CONTEXT}: Name of Dialplan procedure
${CHANNEL}: The channel (the called number present in the Dialplan procedure)
Example:
This Dialplan is assigned to user 102.
NoOp function serves to display the variable value in logs:
Conditions in Dialplan
You can use execute a conditional jump to another Dialplan procedure, based on the boolean result (true or false) of the Gotoif function.
Syntax to execute a jump: GotoIf(condition?label1:label2)
Where:
label1:label2 are the destinations of the jump, consisting of: context, extension, priority
context: name of Dialplan procedure
extension: extension or called number present in this Dialplan procedure
priority: line number, usually 1
condition: the choice of Gotoif depends on the boolean result of this expression: true or false, in Dialplan True = 1 and False = 0.
The condition syntax is the following one: $[expr1 operator expr2], where
expr can be a variable, a value, a function, an expression (expressions can be nested)
operator as a rule it is relational (comparison) operator ( =, <>..); for nested expressions it’s possible to use logical operators AND, OR, NOT (explained below)
Logical operators:
expr1 | expr2 → OR
expr1 & expr2 → AND
!expr → NOT
Relational operators:
expr1 = expr2 → equal
expr1 != expr2 → inequal
expr1 < expr2 → less than
expr1 > expr2 → greater than
expr1 <= expr2 → less than or equal
expr1 >= expr2 → greater than or equal
Example: