Nontrivial task with callback + DID in Asterisk

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

It would seem, "it's freePBX - everything is done with the mouse there." This is not entirely true.

Step one. Awareness of the problem.


I use the elastix web interface to configure. I really like him.
Go to PBX-> PBX Configuration-> Callback and fill in the data for the callback.
We go to the IVR section, select the desired menu and configure, for example, “9” our callback.
I check - everything works. I called from 28-xx-yy - the call returned from 28-xx-yy
I did the same for IVR on the number 28-xx-xx - the call returned from 28-xx-yy
Agree, it’s illogical when you call to order products, but they call you back from the number of some plant. And I have quite a few such organizations.
From here the current task flowed: it is necessary that by calling 28-xx-xx - the call should return 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 the 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 find out that the call is made from the Local channel, and leaves according to the rules of the outbound routes.
And after a working day of thought, I got an idea - to make the desired DID based on prefixes when dialing from callback.

The fourth step. The solution of the problem


For clarity, I will give the following logic:
  • register for number 28-xx-xx in Outbound Routes in the prefix field our number 28-xx-xx
  • the call comes from 55-xy-xx to 28-xx-xx
  • pass 55-xy-xx and 28-xx-xx to the callback script
  • we dial the number in the format 28xxx5555xyxx
  • the asterisk drives the number 28xxxx55xyxx into the Outbound Routes and cuts off 28xxxx by dialing 55xyxx from the number 28xxxx
  • PROFIT!


The technical side turned out to be very "more complicated". As you know, FreePBX rereads extensions_additional.conf any time it is saved. Added a new user via the web - apply your current contexts.
The solution to this is to use the extensions_override_freepbx.conf file - but it didn’t work out for me. I didn’t spend more than an hour studying, because the solution to the main problem was already flying somewhere in the air. I instinctively realized that the reason most likely is that a lot has been rewritten on the server.

We look at the context [callback]
We need to pass the DID to the variable CALL. It is useless to do this through callback-custom - anyway, the variable will be reassigned lower in the main context. And then, I remembered a useful article .
Add the [callback-az] context made by copying [callback] in extensions_custom.conf 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’ll notice that my phone operator simply displays a call on their phones - “ Callback ” I
’ll run ahead, it caused a panic - they serve a bunch of organizations and want to see where the call came from. Logically, you can’t argue.
Therefore, in the context above, I added the DESC variable, text, and sent it to the callback script. It suited everyone.

Next, we modify the script / var / lib / asterisk / bin / callback itself - as already mentioned, this is a simple php script.
I think everyone has 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;

Done. Next, you need to correctly make a call to the context.
I recall the above useful article and pictures to it.
Elastix does not have a Custom Destinations module , so we climb directly into FreePBX. It is located at:
ip-add/admin
login and password are standard, they are easy to google.

We do it like this: I

’ll explain. The first “1” in the line callback-az, 1,1 is the callback number from the context [callback-az] - we get several callbacks in the context (1 for each DID). The second “1” is the priority number.

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

And this is done for each DID and Callback

Remember to add a prefix to your outbound routes! I will not talk about this, this is exactly what you can easily do with the mouse.

Conclusion


I do not consider myself an asterisk guru. 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.

Also popular now: