2008-09-16 34 views

回答

1

我一直在尋找最終看上去像這樣的解決方案:

[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() 
1

This article應該這樣做。這是關於3行代碼和一些簡單的查詢來添加和刪除轉發規則。

+0

非常接近。不包括MySQL問題的一部分,但我認爲它讓我走得很遠。只需要一些例子。謝謝! – afarnham 2008-09-16 14:48:07

3

對不起,對於長代碼示例,但它的一半以上是調試代碼,以幫助您設置它。

我假設你的服務器已經PHP與PDO庫一個現代版(在/usr/bin/php),並有一個名爲fwd_table的列caller_iddestination數據庫表。

在/ 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。如果您需要更多幫助,將其集成到撥號計劃中,請編輯您的問題。