📜 ⬆️ ⬇️

Asterisk Callback, or how to make cheap calls

There is a situation when employees on business trips call from cellular over long distance to the head office, although there is a PBX in the office which will be provided by an excellent cheap telecom operator with tasty prices, or simply call an internal number of the subscriber, through an external number, and you can think of a total number of situations the problem of which is a call back. It is for these purposes that I implemented another scenario in which an employee just needs to call the number, and then the PBX will call him back and the already called subscriber will be able to do through the PBX what he needs not at the expense of his balance on the cellular, city operator or any another operator providing telecommunications services, and, for example, due to cheaper services connected to the PBX.

A special case of this situation is implemented in today's example dialplan:

Calling to an external number -> PBX calls back -> dial the internal number of the subscriber -> communicate over the outgoing from the trunk to the PBX.

what we need:
A pair of dialplan lines that will handle the incoming connection and outgoing connection
Script generating .call file.
')
So. The first step we need ... to finish the call:

[callback-context]
exten => _7XXXXX.,1,Hangup


Further, all processing (what word is loud processing ... So ... Processing) will take place in the “h” event of the same context, since we already put the phone down.
Run the script to create a .call file.

exten => h,1,System(/usr/local/scripts/callback.sh ${CALLERID(num)})


The script itself looks like this:

 #!/bin/bash callee=$1 Channel="SIP/"$callee MaxRetries=10 RetryTime=10 WaitTime=20 Context="call-to" Extension="callback" Priority=1 DATA=`date` echo "Channel: $Channel CallerId: EXTERNAL_PBX_NUM <EXTERNAL_PBX_NUM> MaxRetries: $MaxRetries RetryTime: $RetryTime WaitTime: $WaitTime Context: $Context Extension: $Extension Priority: $Priority" > /var/spool/asterisk/outgoing/$callee.call 


The script will call back the one who called the PBX and after he picks up the phone switches the channel to the context call-to on the extension callback for processing:
In this context, we will play the greeting file and invitation to enter the number (for those who will deal with kapipasta - the custom file name. By default, Asterisk does not have this file. Write your own or use the standard one), we will wait for entering the number to which you need to call, which should consist of - Maximum 4, we will wait 5 seconds and give only 1 attempt to enter.

After entering the number, call it and connect 2 channels to the bridge using the Dial function.

[call-to]
exten => callback, 1, Read (NUM, input-number, 4, n, 1.5)
exten => callback, n, DIAL (PJSIP / $ {NUM})


Thus, we call the internal number not at our own expense, but at the expense of the PBX.

PS
1. For perfectionists: Yes, I did not set the pincode input. do it yourself if you need to (I will tell you - It is necessary to use the Read function once more).
1. Yes, the PBX will not reach the subscriber if he called from the trunk to which the number is not assigned (which is given a dynamic number).

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


All Articles