简体   繁体   English

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

[英]How to set Asterisk call log CDR database fields from AMI ORIGINATE

I'm using the Asterisk Management Interface (AMI) in PHP to originate outbound calls.我在 PHP 中使用星号管理接口 (AMI) 来发起出站调用。 Below is a snippet of the code I'm using:下面是我正在使用的代码片段:

// 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: Originate\r\n" );
fputs($socket, "Channel: SIP/$ext\r\n" );
fputs($socket, "Exten: $num\r\n" );
fputs($socket, "Context: from-internal\r\n");
fputs($socket, "Priority: 1\r\n" );
fputs($socket, "CallerID: \"".$name."\" <".$num.">\r\n" );
fputs($socket, "Async: yes\r\n\r\n" );

How do I set the caller name ( $name ) or other details written to the asteriskcdrdb for outbound calls within the originate script?如何为原始脚本中的出站呼叫设置呼叫者姓名 ( $name ) 或写入asteriskcdrdb其他详细信息? Ideally I want to set the dst fields in the same way the inbound call fields are set.理想情况下,我想以与设置入站呼叫字段相同的方式设置dst字段。

After the originate you can parse the output to look for the channel id and then you can use Setvar to set CDR(userfield) or CDR(accouncode) ... etc.originate之后,您可以解析输出以查找通道 id,然后您可以使用 Setvar 来设置 CDR(userfield) 或 CDR(accouncode) ...等。

My example:我的例子:

fputs($socket, "Action: Originate\r\n");
fputs($socket, "Channel: $userExt\r\n");
fputs($socket, "Context: $AMIcntx\r\n");
fputs($socket, "Exten: $phoneNum\r\n");
fputs($socket, "Priority: 1\r\n");

$chan=true;
$channelID=0;

while (!feof($socket))
{
    if ($chan && preg_match("#Channel: ([a-zA-Z0-9\\/-]+)#", $wrets, $cm))
    {
        $channelID = $cm[1];        
        fputs($socket, "Action: Setvar\r\n");
        fputs($socket, "Channel: $channelID\r\n");
        fputs($socket, "Variable: CDR(userfield)\r\n");
        fputs($socket, "Value: FOOBAR\r\n\r\n");        
        fputs($socket, "Action: Logoff\r\n\r\n");
        $chan = false; //There are various Channel response, not overwrite.
    }
    //Further parsing of the AMI response go heres
}

SetVar sets the variable for the specified channel only. SetVar仅为指定通道设置变量。 You have to send the setvar command early as possible, before the call ends.您必须在呼叫结束之前尽早发送 setvar 命令。

Another way if you could edit your dialplan (i can't, because i use freepbx) is to make a specific context for the ami call, pass some variables from the originate to the context, a set this vars to the CDR in the dialplan.如果你可以编辑你的拨号计划(我不能,因为我使用 freepbx)的另一种方法是为 ami 调用创建一个特定的上下文,将一些变量从源传递到上下文,将这个变量设置为拨号计划中的 CDR .

you don't need to use Action: Setvar to set the CDR(accountcode) , all what you need is to add the below line during call origination您不需要使用 Action: Setvar 来设置 CDR(accountcode) ,您只需要在呼叫发起期间添加以下行

           fputs($socket, "Account: FOOBAR\r\n" );

and below is full example下面是完整的例子

       fputs($socket, "Action: Originate\r\n" );
        fputs($socket, "Channel: SIP/201\r\n" );
        fputs($socket, "Exten: 1234\r\n" );
        fputs($socket, "Account: FOOBAR\r\n" );
        fputs($socket, "Context: from-internal\r\n" );
        fputs($socket, "Priority: 1\r\n" );
        fputs($socket, "WaitTime: 15\r\n" );
        fputs($socket, "Callerid: 123456\r\n\r\n" );
        $wrets=fgets($socket,128);
        echo $wrets;

You can put any variable in action originate:您可以将任何变量放入操作中:

    fputs($socket, "Action: Originate\r\n" );
    fputs($socket, "Channel: SIP/201\r\n" );
    fputs($socket, "Exten: 1234\r\n" );
    fputs($socket, "Account: FOOBAR\r\n" );
    fputs($socket, "Context: from-internal\r\n" );
    fputs($socket, "Priority: 1\r\n" );
    fputs($socket, "WaitTime: 15\r\n" );
    fputs($socket, "Callerid: 123456\r\n" );
    fputs($socket, "Variable: CDR(userfield)=AnyData\r\n\r\n" );
    $wrets=fgets($socket,128);
    echo $wrets;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM