MySQL,Asterisk拨号计划和呼叫转移
时间:2020-03-05 18:55:12 来源:igfitidea点击:
如何通过将来电号码与要转接的号码进行匹配来使Asterisk转发来电?这两个数字都存储在MySQL数据库中。
解决方案
回答
本文应该做到这一点。它包含3行代码和一些用于添加和删除转发规则的简单查询。
回答
很抱歉,很长的代码示例,但其中有一半以上是调试代码,以进行设置。
我假设服务器已经具有带有PDO库的PHP的现代版本(位于/ usr / bin / php),并且我们具有名为fwd_table的数据库表,其中具有caller_id列和destination列。
在/ var / lib / asterisk / 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"正确。如果我们需要更多帮助将其集成到拨号计划中,请编辑问题。
回答
我一直在寻找的解决方案最终看起来像这样:
[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()