简体   繁体   English

Asterisk AMI AGI通知PHP脚本

[英]Asterisk AMI AGI Notification PHP Script

I am new to Asterisk. 我是Asterisk的新手。 My requirement is when I receive a call I need to identify caller id and pop up that id when answer the call. 我的要求是当我接到电话时,我需要识别来电显示并在接听电话时弹出该ID。 I have some knowledge in AMI and AGI. 我对AMI和AGI有一些了解。 I want to know how can I do this using php script. 我想知道如何使用php脚本执行此操作。

Any example or something that i can used to do this, please attach here. 我可以用来做任何这样的例子或事情,请在这里附上。

A lot of this depends on the version of Asterisk you're using. 这很大程度上取决于您使用的Asterisk的版本。 I'd recommend using Asterisk 13, as it is both an LTS and has nicer AMI events than other versions. 我建议使用Asterisk 13,因为它既是LTS又比其他版本有更好的AMI事件。

There are two approaches you could take here. 你可以在这里采取两种方法。 The first is to use AMI, which will spill events back to you over a TCP socket. 第一种是使用AMI,它会通过TCP套接字将事件泄露给您。 The second is to use AGI, specifically FastAGI, which will give your remote application control of a channel. 第二种是使用AGI,特别是FastAGI,它将为您的远程应用程序控制一个通道。 In that application, you can then extract the Caller ID yourself. 在该应用程序中,您可以自己提取来电显示。

If you choose to use AMI, you should generally listen for two events: Newchannel - which is raised when a channel is created - and Newcallerid - which is raised when the party identification of the channel is changed. 如果您选择使用AMI,则通常应该监听两个事件: Newchannel (在创建频道时引发)和Newcallerid - 在更改频道的参与方标识时引发。 That should cover the vast majority of the time the party identification changes, and should give you both the Caller ID of the channel, as well as the Connected Line information, which is the party identification of the party that channel is talking to. 这应该涵盖了聚会标识发生变化的绝大多数时间,并且应该为您提供频道的来电显示,以及连接线路信息,这是该频道正在与之通话的一方的一方标识。

You shouldn't need the Link subevent in the Bridge event (which doesn't exist in 13, and is replaced by the BridgeEnter / BridgeLeave events) - which is what I think Arheops was referring to. 您不应该在Bridge事件中使用Link子事件(13中不存在,并且由BridgeEnter / BridgeLeave事件替换) - 这就是我认为Arheops所指的。 Link is only raised when a channel is 'linked' to another channel in a bridge, and has no bearing on Caller ID. 仅当通道“链接”到桥中的另一个通道时才会引发链接,并且与呼叫者ID无关。 Party identification can change in that situation, but that would be conveyed in the NewcallerId event, so it's pointless listening for it. 在这种情况下,党的身份识别可能会发生变化,但这会在NewcallerId事件中传达,因此毫无意义地倾听它。

Alternatively, you can use FastAGI . 或者,您可以使用FastAGI If you go down that route, you'll want to have in your dialplan something that calls your FastAGI server: 如果你沿着这条路走下去,你会想要在你的拨号方案中有一些叫做FastAGI服务器的东西:

exten => _X.,1,NoOp()
 same => n,AGI(agi://127.0.0.1)
 same => n,...

In your script - which can be written in a large variety of languages, given the number of AGI libraries are available - you can then extract the CallerID using the get variable command and the CALLERID function. 在您的脚本中 - 可以使用多种语言编写,只要AGI库的数量可用 - 您可以使用get variable命令和CALLERID函数提取CallerID。 The following is an example in node.js: 以下是node.js中的示例:

return agi.getFullVariable('${CALLERID(NUMBER)}').then(function (number) {
    callerId.number = number;

    return agi.getFullVariable('${CALLERID(NAME)}');
}).then(function (name) {
    callerId.name = name;

As an aside, none of this is "expert" level Asterisk manipulation. 顺便说一句,这些都不是“专家”级别的星号操纵。 It just requires some programming and a basic understanding of Asterisk APIs. 它只需要一些编程和对Asterisk API的基本了解。 Good luck! 祝好运!

If you new to asterisk, you can use already developed soft like asternic fop/fop2. 如果您是星号的新手,您可以使用已开发的软件,如asternic fop / fop2。 It allow do splash with callerid on incoming call and i am sure it will be simpler to got that working. 它允许在来电时使用callerid进行启动,我相信它会更简单。

If you still want do it via asterisk, you should watch for "link" event. 如果你仍然希望通过星号来做,你应该注意“链接”事件。 However there will be no callerid in that event, so you have also look for "NewChannel" events and for "set" extensions with CALLERID(num)=something, which will alter callerid. 但是在该事件中将没有调用者,因此您还要查找“NewChannel”事件以及使用CALLERID(num)= something的“set”扩展,这将改变调用者。

You can connect events using channel uniqueid. 您可以使用channel uniqueid连接事件。

This task is NOT trivial and require be expert in php. 这项任务并不简单,需要专家的PHP。

Also you can change asterisk dialplan to trigger UserEvent action with info you need on call answer, after that just collect UserEvents. 此外,您可以更改星号拨号方案以使用呼叫应答所需的信息触发UserEvent操作,之后只需收集UserEvents。 That require high expertise in asterisk dialplan and low in php. 这需要在星号拨号方案和低PHP的高专业知识。

If a popup on a browser is ok for you I suggest to use websocket to notify a webpage about a new call (with all the parameters). 如果浏览器上的弹出窗口适合您,我建议使用websocket通知网页有关新呼叫(包含所有参数)。 You can do it by listening on AMI events and send data to browsers with nodejs, with this you can avoid polling to Asterisk server to check if a call is answered. 您可以通过侦听AMI事件并使用nodejs将数据发送到浏览器来实现此目的,这样您就可以避免轮询到Asterisk服务器以检查呼叫是否已应答。

Take a look on this code: https://www.backloop.biz/en/products/asterisk-call-notifier-en 看看这段代码: https//www.backloop.biz/en/products/asterisk-call-notifier-en

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

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