The article will discuss the free
Askozia PBX
version 6 . When designing a telephone exchange, one of the first tasks was to organize outgoing calls.
How it was
In the old version of Askozia, standard dialplan β
templates β were used.
- X! - all phone numbers
- XXX - three-digit numeric numbers
- .! - absolutely all phone numbers
It is possible to schematically describe an example context:
')
[outgoing] exten => _XXXXXX!,1,NoOp(Start outgoing calling...) same => n,Dialβ¦
We found this approach is not flexible enough. It is not possible to describe the following rule:
- Room starts at 79
- This is followed by either 35 or 26
- The rest of the number consists of 7 digits.
Under the cat we describe the chosen approach and the result of the development.
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] - digit from 0 to 9, entry from one or more times
- {7} - number of occurrences of the previous character
REGEX function syntax:
REGEX("regular expression" string) Return '1' on regular expression match or '0' otherwise
Example usage 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, in which the β
ExecIf β function is
called :
ExecIf($["${REGEX("^[0-9]{6}$" ${EXTEN})}" == "1"]
If the phone number specified in the β
$ {EXTEN} β variable matches the pattern, then the call is routed to the
sub-context by means of the β
Gosub β function.
If the call to the
sub-context was not interrupted, the set will follow the next appropriate rule.
We thus 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 β - context is checked β
DIALSTATUS β. If the call is answered, after the conversation the channel will be terminated by means of the β
Hangup () β function. If this is not done, then at the end of the call by the customer, the customerβs number can be redialled.
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 weakly predictable result in the CDR call history table. I think in history it is important to keep the number that was dialed by the employee.
Be careful when describing a regular expression. Use the characters β
^ β, the beginning of the line and β
$ β - the end of the line, otherwise you can get an unexpected result.
For example, the pattern β
[0-9] {6} β will correspond to all numbers where there are 6 or more digits. The β
^ [0-9] {6} $ β pattern corresponds to only 6-digit numbers.
Results
We received a flexible subsystem to describe the outgoing routing to the PBX.
The list of rules is displayed as follows:

Example of a card of a specific βRuleβ
