πŸ“œ ⬆️ ⬇️

Asterisk. Dialplan Askozia 6. Outgoing calls

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.


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:


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} 


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:

image

Example of a card of a specific β€œRule”

image

Source: https://habr.com/ru/post/445536/


All Articles