มีหลายวิธีที่จะทำ CallBack ได้ อันนี้ก็อีกตัวอย่างหนึ่ง ผมไม่ได้ลองใช้วิธีนี้ดู
เป็นการเล่นกับ outgoing directory ซึ่งผมเคยเขียนถึงใน จะเล่นอะไรกับ /var/spool/asterisk/ ได้บ้าง
อันนี้ไปเจอมาจาก callback.agi modules (http://pastebin.ca/179670) ไม่รู้จะ credit ใคร เพราะไม่รู้ใคร post?
modules.conf
; Asterisk configuration file
;
; Module Loader configuration file
;
[modules]
autoload=yes
;
; If you want, load the GTK console right away.
; Don't load the KDE console since
; it's not as sophisticated right now.
;
noload => pbx_gtkconsole.so
;load => pbx_gtkconsole.so
noload => pbx_kdeconsole.so
;
; Intercom application is obsoleted by
; chan_oss. Don't load it.
;
noload => app_intercom.so
;
; Explicitly load the chan_modem.so early on to be sure
; it loads before any of the chan_modem_* 's afte rit
;
load => chan_modem.so
load => res_musiconhold.so
load => chan_capi.so
;
; Load either OSS or ALSA, not both
; By default, load OSS only (automatically) and do not load ALSA
;
;noload => chan_alsa.so
noload => chan_oss.so
;
; Module names listed in "global" section will have symbols globally
; exported to modules loaded after them.
;
[global]
chan_modem.so=yes
chan_capi.so=yes
callback.agi:
#!/usr/bin/php -q
<?php
ob_implicit_flush(true);
set_time_limit(0);
$err=fopen("php://stderr","w");
$in = fopen("php://stdin","r");
$out = fopen("php://stout","w");
echo("before loop"); /*falls Debug-Ausgaben gewuenscht */
while (!feof($in)) {
echo("in loop"); /*falls Debug-ausgaben gewuenscht*/
$temp = str_replace("\n","",fgets($in,4096));
$s = split(":",$temp);
$agi[str_replace("agi_","",$s[0])] = trim($s[1]);
if(($temp == "") || ($temp == "\n")) {
break;
}
}
$cf =
fopen("/var/spool/asterisk/outgoing/cb".$agi["callerid"],"w+");
fputs($cf,"Channel: CAPI/".$agi["extension"].":da_die_msn_die_asterisk_anrufen_soll\n");
fputs($cf,"Context: capidialtone\n");
fputs($cf,"Extension: s\n");
fputs($cf,"SetVar: CALLERIDNUM=".$agi["extension"]."\n");
fputs($cf,"MaxRetries: 2\n");
fputs($cf,"RetryTime: 10\n");
fclose($cf);
fclose($in);
fclode($out);
fclode($err);
?>
download file นี้ได้ที่ http://pastebin.ca/raw/179670