login | register
Thu 28 of Aug, 2008 [03:55 UTC]

voip-info.org

Discuss [0] History

Asterisk tips Call Back

Created by: cyrenity,Last modification on Fri 25 of Apr, 2008 [05:30 UTC]

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
<?php

ob_implicit_flush(true);
set_time_limit(0);
$to = $argv1;

$err=fopen("php://stderr","w");
$in = fopen("php://stdin","r");
while (!feof($in)) {
$temp = str_replace("\n","",fgets($in,4096));
$s = split(":",$temp);
$agi[str_replace("agi_","",$s0)] = trim($s1);
if $temp == "") {
break;
}
}
$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");
fclose($cf);
fclose($in);
fclose($err);
?>


Extensions.conf


  • 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/ -
    Image


Comments