Asterisk Dialplan Askozia 6. Outgoing Calls
The article will talk about the free PBX Askozia version 6 . When developing a telephone exchange, one of the first tasks was the organization of outgoing calls.
In the old version of Askozia, standard “dialplan ” templates were used.
An example of a context can be described schematically:
This approach seemed to us not flexible enough. There is no way to describe the following rule:
Under the cut, our approach and the outcome of the development are described.
We decided to implement this functionality differently, using REGEX .
Template example:
The syntax of the REGEX function is:
An example of use in Askozia 6:
For outgoing calls, one entry point is organized - the “ outgoing ” context , the “ ExecIf ” function is called in it :
If the phone number specified in the variable “ $ {EXTEN} ” matches the pattern, then the call is routed to the sub-context using the “ Gosub ” function .
If the call was not interrupted in the sub-context , the set will go according to the following appropriate rule.
This way we solved the problem with single-channel lines. If the line is busy, the call goes through the next one until it is answered.
Context examples:
Mandatory in “ sub ” - the context checks “ DIALSTATUS ”. If the call is answered, then after the conversation the channel will be terminated using the “ Hangup () ” function . If this is not done, then at the end of the call by the client, re-dialing of the client number may occur.
One important subtlety, when using “ Gosub ” or “ Goto ”, we intentionally do not change $ {EXTEN} . Even if you need to modify the phone number (add / remove prefix).
The fact is that when modifying EXTEN, Asterisk will modify the value of the variable CDR (dst), which will lead to a poorly predicted result in the CDR call history table. I think it’s important in history to keep the number that was dialed by an employee.
Be careful when describing a regular expression. Use the characters “ ^ ”, the beginning of the line and “ $ ” - the end of the line, otherwise you may get unexpected results.
For example, the pattern “ [0-9] {6} ” will correspond to all numbers where there are 6 or more digits. The pattern “ ^ [0-9] {6} $ ” matches only 6-digit numbers.
We got a flexible subsystem for describing outbound routing to the PBX.
The list of rules is displayed as follows:
Example of a card of a specific “Rules”:
How it was
In the old version of Askozia, standard “dialplan ” templates were used.
- X! - all phone numbers
- XXX - three digit numbers
- .! - absolutely all phone numbers
An example of a context can be described schematically:
[outgoing]
exten => _XXXXXX!,1,NoOp(Start outgoing calling...)
same => n,Dial…
This approach seemed to us not flexible enough. There is no way to describe the following rule:
- Number starts at 79
- It follows either 35 or 26
- The rest of the number is 7 digits
Under the cut, our approach and the outcome of the development are described.
Current implementation
We decided to implement this functionality differently, using REGEX .
Template example:
79(25|26)[1-9]{7}
- (25 | 26) is 25 OR 26
- [0-9] - a digit from 0 to 9, occurrence from the 1st or more times
- {7} - number of occurrences of the previous character
The syntax of the REGEX function is:
REGEX("regular expression" string)
Return '1' on regular expression match or '0' otherwise
An example of use in Askozia 6:
[outgoing]
exten => _X!,1,NoOp(Start outgoing calling...)
same => n,Ringing()
same => n,ExecIf($["${REGEX("^[0-9]{6}$" ${EXTEN})}" == "1"]?Gosub(SIP-PR-1-out,${EXTEN},1))
same => n,ExecIf($["${REGEX("^(7|8)[0-9]{10}$" ${EXTEN})}" == "1"]?Gosub(SIP-PR-2-out,${EXTEN},1))
same => n,Hangup()
For outgoing calls, one entry point is organized - the “ outgoing ” context , the “ ExecIf ” function is called in it :
ExecIf($["${REGEX("^[0-9]{6}$" ${EXTEN})}" == "1"]
If the phone number specified in the variable “ $ {EXTEN} ” matches the pattern, then the call is routed to the sub-context using the “ Gosub ” function .
If the call was not interrupted in the sub-context , the set will go according to the following appropriate rule.
This way we solved the problem with single-channel lines. If the line is busy, the call goes through the next one until it is answered.
Context examples:
[SIP-PR-1]
exten => _X!,1,ExecIf($["${number}x" == "x"]?Hangup())
same => n,Dial(SIP/PR-1/${EXTEN},600,TeK))
same => n,ExecIf($["${DIALSTATUS}" = "ANSWER"]?Hangup())
same => n,return
[SIP-PR-2]
exten => _X!,1,ExecIf($["${number}x" == "x"]?Hangup())
same => n,Dial(SIP/PR-2/${EXTEN},600,TeK))
same => n,ExecIf($["${DIALSTATUS}" = "ANSWER"]?Hangup())
same => n,return
Mandatory in “ sub ” - the context checks “ DIALSTATUS ”. If the call is answered, then after the conversation the channel will be terminated using the “ Hangup () ” function . If this is not done, then at the end of the call by the client, re-dialing of the client number may occur.
One important subtlety, when using “ Gosub ” or “ Goto ”, we intentionally do not change $ {EXTEN} . Even if you need to modify the phone number (add / remove prefix).
The fact is that when modifying EXTEN, Asterisk will modify the value of the variable CDR (dst), which will lead to a poorly predicted result in the CDR call history table. I think it’s important in history to keep the number that was dialed by an employee.
Be careful when describing a regular expression. Use the characters “ ^ ”, the beginning of the line and “ $ ” - the end of the line, otherwise you may get unexpected results.
For example, the pattern “ [0-9] {6} ” will correspond to all numbers where there are 6 or more digits. The pattern “ ^ [0-9] {6} $ ” matches only 6-digit numbers.
Summary
We got a flexible subsystem for describing outbound routing to the PBX.
The list of rules is displayed as follows:
Example of a card of a specific “Rules”: