📜 ⬆️ ⬇️

Nontrivial task with callback + DID in Asterisk

Hello, dear habravchane and lovers of asterisk!
I want to share an interesting task and a version of its solution. So, here are the conditions of the problem.
We have:
- modified Elastix 2.3 distribution
- asterisk 1.8.13.1
- FreePBX 2.8.1
- 24 numbers connected by sip and 30 channels
- ~ 40 different LLC in the holding
Current task:
- make callback service for each DID number (and, accordingly, from each LLC)

It would seem that "this is freePBX - everything is done with a mouse." This is not entirely true.

Step one. Awareness of the problem.


I use the elastix web interface for configuration. I like him very much.
Go to PBX-> PBX Configuration-> Callback and fill in the data for the callback.
Go to the IVR section, select the desired menu and set up, for example, on “9” our callback.
I check - everything works. Called from 28-xx-yy - the call returned from 28-xx-yy
Did the same for IVR on number 28-xx-xx - the call returned from 28-xx-yy
Agree, as it is illogical, when you call to order products, and they call you back from the number of the plant. And I have quite a lot of such organizations.
From here the current problem emerged: you need to call 28-xx-xx - the call returns from the number 28-xx-xx

Step two. Finding a solution from the elastix / FreePBX web interface


I will say right away. Maybe it is, but I did not find it.
')

Step three. Exploring configuration files directly


The context for callback is in the extensions_additional.conf file.
[callback] include => callback-custom exten => 1,1,Set(CALL=${CALLERID(number)}) exten => 1,n,Set(DESTINATION=ivr-5.s.1) exten => 1,n,Set(SLEEP=1) exten => 1,n,System(/var/lib/asterisk/bin/callback ${CALL} ${DESTINATION} ${SLEEP} &) exten => 1,n,Hangup 

We see that the call is made from the php script / var / lib / asterisk / bin / callback
Having looked through it, we learn that the call is made from the Local channel, and leaves according to the rules of outgoing routes (Outbound Routes)
And after a working day of passing thoughts, I got an idea to make the necessary DID based on prefixes when dialing from callback.

Step Four. The solution of the problem


For clarity, here is the logic:


The technical side turned out to be very "difficult." As you know, FreePBX overwrites extensions_additional.conf for any of its conservation. Added a new user through the web - apply your contexts.
The solution to this is to use the file extensions_override_freepbx.conf - but I did not succeed. I didn’t spend more than an hour studying, because the solution of the main task had already flown somewhere in the air. I instinctively realized that the reason most likely was that there was already a lot of rewritten on the server.

We look context [callback]
We need to pass the DID to the CALL variable. Through callback-custom, it is useless to do this - anyway, the variable is reassigned below the main context. And then, I remembered a useful article .
Add the [callback-az] context to the extensions_custom.conf made by copying [callback] and add FROM_DID to the CALL variable
 [callback-az] exten => 1,1,Set(CALL=${FROM_DID}${CALLERID(number)}) exten => 1,n,Set(DESTINATION=ivr-5.s.1) exten => 1,n,Set(SLEEP=1) exten => 1,n,Set(DESC='callb_CRT') exten => 1,n,System(/var/lib/asterisk/bin/callback ${CALL} ${DESTINATION} ${SLEEP} ${DESC} &) 

I note that my operators on the phone displayed the caller simply - " Callback "
Looking ahead, it caused a panic - because they serve a bunch of organizations, and they want to see where the call came from. Logical, you can not argue.
Therefore, in the context above, I added the DESC variable, with the text, and sent it to the callback script. That suited everyone.

Next we modify the script itself / var / lib / asterisk / bin / callback - as already mentioned, this is a simple php script.
I think everyone already understood what will happen next.
Are looking for
 $callback_number = $args[0]; $callback_destination = $args[1]; $pause_seconds = $args[2]; 

Paste below
 $callback_desc = $args[3]; 

Are looking for
 $callerid = "Callback" 

replace with
 $callerid = $callback_desc; 

Is done. Next you need to correctly make a call to context.
Remember the above useful article and pictures to it.
There is no Custom Destinations module in Elastix, therefore we climb directly into FreePBX. It is located at:
ip-add/admin
login and password are standard, easy to googling.

Do this like this:

I will explain. The first “1” in the callback-az string , 1.1 is the callback number from the context of [callback-az] - we will have several callbacks in the context (1 for each DID). The second “1” is the priority number.

Well, the final touch - we indicate in IVR at our DID the number 9 - our Custom Destination

And this is done for each DID and Callback.

Do not forget to add the prefix to outgoing routes! I will not talk about this, that's what you can easily do with the mouse.

Conclusion


I do not consider myself a guru asterisk. I am sure that someone knows a way to do better and more correctly. I found my way and want to share it with the community.
Thanks to all.

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


All Articles