Asterisk Callback, or how to make cheap calls

    There is a situation when employees on business trips call from cellular over the long distance to the head office, although there is a telephone exchange in the office that will be run by an excellent cheap telecom operator with tasty prices, or they just call the subscriber’s internal number through an external number, and you can think of a whole bunch of situations whose problem is a call back. It was 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 called subscriber will be able to do through the PBX what he needs not at the expense of his balance on the mobile, city operator or any another telecommunications service provider, and, for example, due to cheaper services connected to the PBX.

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

    Calls to an external number -> ATS calls back -> we dial an internal number of the subscriber -> we communicate for outgoing from a trunk to a PBX.

    what we need:
    A couple of lines of the dialplan that will process the incoming connection and the outgoing connection.
    Script to generate the .call file.

    So. The first step we need ... to end the call: Next, all processing (which word is loud- processing ... So ... Processing) will occur in the “h” extension of the same context, since we already hung up the phone. Run the script to create the .call file. The script itself looks like this:

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





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




    #!/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 
    MaxRetries: $MaxRetries
    RetryTime: $RetryTime
    WaitTime: $WaitTime
    Context: $Context
    Extension: $Extension
    Priority: $Priority"  > /var/spool/asterisk/outgoing/$callee.call
    


    The script will call the person who called the PBX and after it picks up the phone, transfers the channel to the call-to context on extension callback for processing:
    In this context, we will play the welcome file and invitation to enter the number (for those who will do kapipasta, the file name is custom. By default, this file does not exist in Asterisk. Write your own or use the standard one) we will wait for the number to be dialed which should consist of - Maximum 4, we will wait 5 seconds and give only 1 attempt to enter.

    After entering the number, we call him and connect 2 channels to the bridge with 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 telephone exchange.

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

    Also popular now: