我正在尝试开发一个提醒系统,该系统将自动拨打电话提醒某人特定事件。为此,我使用 Asterisk 进行调用,并使用 PHP 为 Asterisk 创建调用文件。我希望调用文件在添加后 30 秒执行。为此,我在 PHP 脚本中设置了修改后的时间戳。一切都很好,除了我想再次检查 Web 服务以确定它是否仍然与调用用户相关。
这是我的 PHP 脚本
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$request = json_decode(file_get_contents("php://input"));
$tmpcallfile = tempnam("/tmp", "call");
$callfile = tempnam("/var/spool/asterisk/outgoing/", "call");
$fh = fopen($tmpcallfile, "w");
fwrite($fh, "Channel: SIP/voxbeam_outbound/" . $request->{'ToPhoneNumber'} . "\n");
fwrite($fh, "CallerID: " . $request->{'FromPhoneNumber'} . "\n");
fwrite($fh, "MaxRetries: 3\n");
fwrite($fh, "RetryTime: 5\n");
fwrite($fh, "Context: remind_event\n");
fwrite($fh, "Extension: 111\n");
fwrite($fh, "Priority: 1\n");
fwrite($fh, "Archive: Yes\n");
fclose($fh);
touch($tmpcallfile, time()+30);
rename($tmpcallfile, $callfile);
}
?>
我的想法是在 extensions.conf 中使用 curl 简单地调用 Web 服务。
[voxbeam_outbound]
exten => _X.,1,NoOp()
same => n,Answer
same => n,Dial(SIP/voxbeam_outbound/${EXTEN})
[remind_event]
exten => _X.,1,Answer
same => n,Set(status=${CURL(http://localhost/ShouldRemindEvent)})
same => n,GotoIf($["${status:0:1}" != "1"]?10)
same => n,Dial(SIP/voxbeam_outbound/${EXTEN})
same => n,Playback(remind_event)
same => n,Hangup
same => 10,Hangup
我想,如果我会检查网络服务,然后转到 10 挂断,如果网络服务回复 1 以外的任何内容。但由于某种原因,它确实会调用。
为了完整起见,这里还在 sip.conf 中添加了几行,尽管我猜这些实际上并不相关:
[voxbeam_outbound]
type=peer
insecure=invite,port
nat=no
canreinvite=no
username=<hidden>
secret=<hidden>
host=<hidden>
context=voxbeam_outbound
所以问题是,我可以像这样简单地做到这一点,还是需要编写一个 AGI 脚本才能实现我想要的?
我意识到这是编程和配置之间的混合,我相信这最适合 stackoverflow 而不是超级用户,因为它是我正在构建的应用程序,并且因为涉及编程。
萧十郎
潇潇雨雨
九州编程