It dials an external number -> the PBX calls back -> we dial the subscriber's internal extension -> we communicate via the outgoing trunk to the PBX.
What we need:
A few lines of dialplan that will handle the incoming and outgoing connections
A script to generate a .call file.
So, the first step is to… end the call:
[callback-context]
exten => _7XXXXX.,1,Hangup
Further processing (what a big word—processing… Well, let's call it "handling") will take place in the "h" extension of the same context, since we have already hung up.
Run the script to create the .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 party that called the PBX, and after they pick up the phone, it will transfer the channel to the call-to context, extension callback for processing:
In this context, we will play a greeting and prompt for number input (for those dealing with capipasta—the filename is custom. By default, Asterisk does not have this file. Record your own or use the standard one). We will wait for the input of the number to call, which should consist of a maximum of 4 digits, wait for 5 seconds, and allow only 1 attempt for input.
After the number is entered, we call it and connect the two channels 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 PBX's expense.
