Asterisk tips Call Back

Callback for Asterisk

Callback script i made, Callback works when called channel is busy, if SIP user is busy it will return user unavailable and send the control to s-NOANSWER.

How it works

  • if called channel or phone is busy, it will ask to press 5 for callback or any other key to leave voicemail,
  • upon pressing 5, it will create a callfile in /var/spool/asterisk/outgoing with a special channel to be called
  • Channel provided in callfile will periodically check if the extension set to callback is busy or available. as soon as it finds the channel available it will try to establish the call.

Php Agi script

#!/usr/bin/php -q

$to = $argv[1];

$in = fopen("php://stdin","r");
while (!feof($in)) {
$temp = str_replace("\n","",fgets($in,4096));
$s = split(":",$temp);
$agi[str_replace("agi_","",$s[0])] = trim($s[1]);
if (($temp == "") || ($temp == "\n")) {
$cf = fopen("/var/spool/asterisk/outgoing/cb" . $agi["callerid"] . $to,"w+"); 
fputs($cf,"Channel: LOCAL/cb".$agi["callerid"].$to."\n");
fputs($cf,"Context: default\n");
fputs($cf,"Extension: ".$to."\n");
fputs($cf,"CallerID: CB ".$agi["callerid"]."<".$agi["callerid"]."> \n");
fputs($cf,"MaxRetries: 100\n");
fputs($cf,"RetryTime: 30\n");


  • in extensions.conf add something like this
exten => s-BUSY,1,ChanIsAvail(SIP/${MACRO_EXTEN}|s)
exten => s-BUSY,2,GotoIf($["${AVAILSTATUS}"<="1"]?s-NOANSWER,1)
exten => s-BUSY,3,Read(digit|callback|1)
exten => s-BUSY,4,Gotoif($[ "${digit}" = "5"]?callback,1:5)
exten => s-BUSY,5,Voicemail(${MACRO_EXTEN},b)
exten => s-BUSY,6,Hangup

exten => callback,1,AGI(callback|${MACRO_EXTEN})
exten => callback,2,Hangup

;in cbXXXXXX first three digits are FROM exten and last ones are TO exten
;this exten is used by CALL FILE, logic for this is to make sure extension we are calling is IDLE or NOT_INUSE state.

exten => _cbXXXXXX,1,Set(FROM=${EXTEN:2:3})
exten => _cbXXXXXX,2,Set(TO=${EXTEN:5:3})
exten => _cbXXXXXX,3,ChanIsAvail(SIP/${TO}|s)
exten => _cbXXXXXX,4,GotoIf($["${AVAILSTATUS}" <= "1"]?5:7)
exten => _cbXXXXXX,5,Set(CALLERID(all)="CB ${TO} <${TO}>")
exten => _cbXXXXXX,6,Dial(SIP/${FROM}|10)
exten => _cbXXXXXX,7,Hangup

  • Copy Callback script in agi-bin directory.
  • Copy callback.gsm in /var/lib/asterisk/sounds/ -

Advanced Callback for Asterisk (Retry-Dial)

While the solution above work fairly good, and implementation is fast and easy, beahavior is inverse to the typical implementation found on traditional PBX (ie, Spanish IBERCOM). One on the caveheats of the above solution is that the retry-dial functions can simulate that callback by placing the callback reversely, starting at the callee phone, and ending at the caller one. This behaviour is inverse to what the user expects, it can be confusing and in the short term can produce multiple problems (ie, when some of the parties receives additional calls between the callback period).

In order to address this, an Asterisk Advanced Retry-Dial (Callback) funtionality can be developed using a daemon, that check if the remote user is still talking, and if not, it address a new call in the correct order. The feauture is copied from traditional retry-dials funtions on PBXs as Spanish IBERCOM, and even has the avaivility to be used on multiple remote sites.

Created by: cyrenity, Last modification: Wed 16 of May, 2012 (13:22) by admin
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+