PHP-AGI 開發筆記

    PHP-AGI 開發的心得

    Q: 程式開頭的宣告

    A:

    reference to undefined name 'syntax' Exception of type 'MindTouch.Deki.Script.Runtime.DekiScriptUndefinedNameException' was thrown. (click for details)
    Q: [PHP] 指令模式的參數傳遞
    reference to undefined name 'syntax' Exception of type 'MindTouch.Deki.Script.Runtime.DekiScriptUndefinedNameException' was thrown. (click for details)
    Q: 用 agi 撥出電話,然後檢測撥出的狀態

    agi:

    reference to undefined name 'syntax' Exception of type 'MindTouch.Deki.Script.Runtime.DekiScriptUndefinedNameException' was thrown. (click for details)

    DIALSTATUS 回傳字串:

    ANSWER
    BUSY
    NOANSWER
    CANCEL
    CONGESTIOS
    CHANUNAVAIL
    DONTCALL
    TORTURE
    INVALIDARGS

    Q: [PHP] Array 運用

    A:

    Sample: 簡單的將星期轉成對應的數字

    reference to undefined name 'syntax' Exception of type 'MindTouch.Deki.Script.Runtime.DekiScriptUndefinedNameException' was thrown. (click for details)
    reference to undefined name 'syntax' Exception of type 'MindTouch.Deki.Script.Runtime.DekiScriptUndefinedNameException' was thrown. (click for details)
    Q: 變更語音的語系

    A:

    $AGI->exec('Set','CHANNEL(language)=en');
    

    以 IncrediblePBX 為例
    編輯 /var/lib/asterisk/agi-bin/wakeupphp

    ...
            // added by alang
            execute_agi( "EXEC Set \"CHANNEL(language)=en\" ");
    
    //=========================================================================
    // This is where we interact with the caller.  Answer the phone and so on
    //=========================================================================
    
    
            $rc = execute_agi( "ANSWER ");
    ... 
    
    Q: 範例: 在 AGI 裡取用 FreePBX 的資料庫(asterisk)內容

    A: 需要兩個檔案

    1. class_freepbx.php:包含所有 DB 的函式庫
    2. freepbx_agi.php:應用範例

    使用說明:

    • 這兩個檔案必須用在 FreePBX 環境下
    • DB credential 是透過 AGI 取得以下幾個變數,不需要 PHP 設定檔。
      指令: asterisk -rx "dialplan show globals" | grep AMP
      • AMPDBENGINE
      • AMPDBHOST
      • AMPDBUSER
      • AMPDBPASS
      • AMPDBFILE
      • AMPDBNAME
    • 如果系統沒有安裝 FreePBX,以上變數將無法取得影響 AGI 執行
       

    技巧#1:連結另一個 DB (不同於 DB Name: asterisk)
    注意: 只能指定 DBName,其餘 DB 連線資訊必須與 AGI Global 變數的相同

    $db2 = new AGIDB($AGI);
    $db2->dbname='asteriskcdrdb';
    

    技巧#2:出現錯誤

    SEVERE PROGRAMMING ERROR: For portability, FIELDS must be surrounded by SINGLE QUOTES ('), yet none were found. Continuing.

    檢查 $sql 的內容至少要包含一對的單引號。

    標籤 (Edit tags)
    • No tags
    您必須 登入 才能發佈評論。
    Powered by MindTouch Core