MySQL,星号Dialplans和呼叫转移
题
我怎么星转发来的电话基础上的匹配的呼入号码有一个数字来着?两个数字都存储在一个MySQL数据库。
解决方案 3
该解决方案我在寻找结束了寻找这样的:
[default]
exten => _X.,1,Set(ARRAY(${EXTEN}_phone)=${DTC_ICF(phone_number,${EXTEN})})
exten => _X.,n(callphone),Dial(SIP/metaswitch/${${EXTEN}_phone},26)
exten => _X.,n(end),Hangup()
其他提示
对不起长代码样本,但是,超过一半的是调试代码,以帮你得到它的设立。
我假设你的服务器已经有一个现代版的PHP(在 /usr/bin/php
)的一项旨在图书馆和你有一个数据库表名为 fwd_table
与列 caller_id
和 destination
.
在/var/lib/星号/agi-bin得到一个副本 PHP AGI 图书馆。然后创建一个文件命名的喜欢的东西 forward_by_callerid.agi
这包括:
#!/usr/bin/php
<?php
ini_set('display_errors','false'); //Supress errors getting sent to the Asterisk process
require('phpagi.php');
$agi = new AGI();
try {
$pdo = new PDO('mysql:host='.$db_hostname.';dbname='.$db_database.';charset=UTF-8', $db_user, $db_pass);
} catch (PDOException $e) {
$agi->conlog("FAIL: Error connecting to the database! " . $e->getMessage());
die();
}
$find_fwd_by_callerid = $pdo->prepare('SELECT destination FROM fwd_table WHERE caller_id=? ');
$caller_id = $agi->request['agi_callerid'];
if($callerid=="unknown" or $callerid=="private" or $callerid==""){
$agi->conlog("Call came in without caller id, I give up");
exit;
}else{
$agi->conlog("Call came in with caller id number $caller_id.");
}
if($find_fwd_by_callerid->execute(array($caller_id)) === false){
$agi->conlog("Database problem searching for forward destination (find_fwd_by_callerid), croaking");
exit;
}
$found_fwds = $find_fwd_by_callerid->fetchAll();
if(count($found_fwds) > 0){
$destination = $found_contacts[0]['destination'];
$agi->set_variable('FWD_TO', $destination);
$agi->conlog("Caller ID matched, setting FWD_TO variable to ''");
}
?>
然后从拨的计划你可以叫它是这样的:
AGI(forward_by_callerid.agi)
如果你的数据库匹配,它将设置变量 FWD_TO
与善良。请编辑问题,如果你需要更多的帮助,得到这种集成到你拨号的计划。
这篇文章 应该做的伎俩。这是关于3行代码和一些简单的查询,以增加和删除转发的规则。
不隶属于 StackOverflow