AGI:解析 SIP Header

    內容表格
    沒有標頭

    版本為 15:18, 20 Nov 2024

    到這個版本。

    返回到 版本存檔.

    查閱目前版本

    解析 SIP Header 的 Diversion 欄位內容

    Dialplan:

    [my-sip-header-filter]
    exten => s,1,NoOp( Incoming calls from internet )
    exten => s,n,NoOp(SIP_HEADER From field: ${SIP_HEADER(From,1)})
    exten => s,n,NoOp(SIP_HEADER To field: ${SIP_HEADER(To,1)})
    ; for debug only
    exten => s,n,GotoIf($[${LEN(${SIP_HEADER(Diversion,1)})} > 0]?next:next)
    ;exten => s,n,GotoIf($[${LEN(${SIP_HEADER(Diversion,1)})} > 0]?next)
    exten => s,n,NoOp(SIP_HEADER Diversion field: <Data Not Found>)
    exten => s,n,Hangup
    exten => s,n(next),NoOp(SIP_HEADER Diversion field: ${SIP_HEADER(Diversion,1)})
    exten => s,n,Set(STR=${SIP_HEADER(Diversion,1)})
    exten => s,n,NoOp(STR: ${STR})
    exten => s,n,AGI(get_diverter.php,${STR})
    exten => s,n,NoOp(Diverter: ${DIVERTER})
    exten => s,n,Hangup
    

    get_diverter.php:

    #!/usr/bin/php -q
    <?php
    include(dirname(__FILE__)."/phpagi.php");
    
    $AGI = new AGI();
    
    // for debug only
    $argv[1] = '<sip:358505735791@voxbone.com>;counter=1;reason=unknown';
    
    if (!isset($argv[1])) {
            $AGI->verbose('Missing STR info');
            exit(1);
    }
    
    $STRING = $argv[1];
    
    preg_match('#<sip:(?P<number>[0-9]+)@(.*)>#',$STRING,$MATCHES);
    
    //print_r($MATCHES);
    $NUMBER = $MATCHES["number"];
    $AGI->verbose("DIVERTER: $NUMBER");
    
    // Return to Dialplan
    $AGI->set_variable("DIVERTER",$NUMBER);
    
    ?>
    
    Powered by MindTouch Core