如何从AMI ORIGINATE设置Asterisk呼叫日志CDR数据库字段



我使用PHP中的Asterisk Management Interface(AMI)来发起出站调用。下面是我正在使用的代码片段:

// snippet
// $num is the number to dial e.g. 0207 121 3456
// $ext is the extension use to make the call e.g. 101
// $name is the name of the caller e.g. Fred Flintstone
//
fputs($socket, "Action: Originatern" );
fputs($socket, "Channel: SIP/$extrn" );
fputs($socket, "Exten: $numrn" );
fputs($socket, "Context: from-internalrn");
fputs($socket, "Priority: 1rn" );
fputs($socket, "CallerID: "".$name."" <".$num.">rn" );
fputs($socket, "Async: yesrnrn" );

如何在始发脚本中为出站呼叫设置呼叫方名称($name)或写入asteriskcdrdb的其他详细信息?理想情况下,我希望以设置入站呼叫字段的方式设置dst字段。

您可以将任何变量放在操作中始发:

    fputs($socket, "Action: Originatern" );
    fputs($socket, "Channel: SIP/201rn" );
    fputs($socket, "Exten: 1234rn" );
    fputs($socket, "Account: FOOBARrn" );
    fputs($socket, "Context: from-internalrn" );
    fputs($socket, "Priority: 1rn" );
    fputs($socket, "WaitTime: 15rn" );
    fputs($socket, "Callerid: 123456rn" );
    fputs($socket, "Variable: CDR(userfield)=AnyDatarnrn" );
    $wrets=fgets($socket,128);
    echo $wrets;

发起后,您可以解析输出以查找通道id,然后可以使用Setvar设置CDR(userfield)或CDR(accuncode)。。。等

我的例子:

fputs($socket, "Action: Originatern");
fputs($socket, "Channel: $userExtrn");
fputs($socket, "Context: $AMIcntxrn");
fputs($socket, "Exten: $phoneNumrn");
fputs($socket, "Priority: 1rn");
$chan=true;
$channelID=0;
while (!feof($socket))
{
    if ($chan && preg_match("#Channel: ([a-zA-Z0-9\/-]+)#", $wrets, $cm))
    {
        $channelID = $cm[1];        
        fputs($socket, "Action: Setvarrn");
        fputs($socket, "Channel: $channelIDrn");
        fputs($socket, "Variable: CDR(userfield)rn");
        fputs($socket, "Value: FOOBARrnrn");        
        fputs($socket, "Action: Logoffrnrn");
        $chan = false; //There are various Channel response, not overwrite.
    }
    //Further parsing of the AMI response go heres
}

SetVar仅为指定通道设置变量。您必须在调用结束之前尽早发送setvar命令。

如果你可以编辑你的拨号计划(我不能,因为我使用freepbx),另一种方法是为ami调用创建一个特定的上下文,将一些变量从始发传递到上下文,并将这些变量设置为拨号计划中的CDR。

您不需要使用Action:Setvar来设置CDR(帐户代码),您只需要在呼叫发起期间添加以下行

           fputs($socket, "Account: FOOBARrn" );

下面是的完整示例

       fputs($socket, "Action: Originatern" );
        fputs($socket, "Channel: SIP/201rn" );
        fputs($socket, "Exten: 1234rn" );
        fputs($socket, "Account: FOOBARrn" );
        fputs($socket, "Context: from-internalrn" );
        fputs($socket, "Priority: 1rn" );
        fputs($socket, "WaitTime: 15rn" );
        fputs($socket, "Callerid: 123456rnrn" );
        $wrets=fgets($socket,128);
        echo $wrets;

相关内容

  • 没有找到相关文章

最新更新