[英]MySQL, Asterisk Dialplans and call forwarding
如何根據將來電號碼與要轉發的號碼相匹配,讓Asterisk轉接來電? 這兩個數字都存儲在MySQL數據庫中。
對於長代碼示例感到抱歉,但超過一半的代碼是調試代碼來幫助您進行設置。
我假設您的服務器已經有一個現代版本的PHP(在/usr/bin/php
)和PDO庫,並且您有一個名為fwd_table
的數據庫表, 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
設置為goodness。 如果您需要更多幫助將其集成到撥號計划中,請編輯您的問題。
我正在尋找的解決方案最終看起來像這樣:
[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()
這篇文章應該可以解決問題。 這是大約3行代碼和一些簡單的查詢來添加和刪除轉發規則。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.