如何从 Asterisk REST API (ARI) 获取所有拨号器事件?

How to get all dialer events from Asterisk REST API (ARI)?

我正在制作一个 Web 应用程序,它应该能够监控我的 Asterisk 服务器上的调用。我可以在 URL ws://(host):8088/ari/events?app=dialer 上使用 Javascript WebSocket 连接到 ARI,并且可以正常工作。问题是我只能从通过 ARI 进行的调用中获取事件。从 Zoiper 等其他客户端发出的呼叫未注册。另一方面,Asterisk 有 AJAM,它在 http://(host):8088/rawman?action=waitevent 上使用长轮询并注册来自所有客户端(ARI、Zoiper 和其他)的调用,但只有信息 who 是呼叫(呼叫者),而不是 whom(被呼叫者)。

所以,我的问题是,如何从所有客户端(最好)使用 WebSockets 获取显示谁在呼叫谁的实时呼叫事件。谢谢

ARI 使用基于订阅的事件模型。引用 wiki 上的文档:

Resources in Asterisk do not, by default, send events about themselves to a connected ARI application. In order to get events about resources, one of three things must occur:

  1. The resource must be a channel that entered into a Stasis dialplan application. A subscription is implicitly created in this case. The subscription is implicitly destroyed when the channel leaves the Stasis dialplan application.
  2. While a channel is in a Stasis dialplan application, the channel may interact with other resources - such as a bridge. While channels interact with the resource, a subscription is made to that resource. When no more channels in a Stasis dialplan application are interacting with the resource, the implicit subscription is destroyed.
  3. At any time, an ARI application may make a subscription to a resource in Asterisk through application operations. While that resource exists, the ARI application owns the subscription.

因此,您通过 ARI WebSocket 获取有关通道事件的原因是因为它进入了 Stasis 拨号方案应用程序。然而,这不是获取事件的唯一方法。

如果您对来自其他事件源的事件感兴趣,可以使用 applications 资源订阅这些资源。例如,如果我想接收与 PJSIP 端点 "Alice" 有关的所有事件,我将使用以下订阅:

POST https://localhost:8080/ari/applications/my_app/subscription?eventSource=endpoint:PJSIP%2FAlice

请注意,订阅端点会隐式订阅为该端点创建的所有频道。如果你想订阅某项技术的所有端点,你也可以订阅资源本身:

POST https://localhost:8080/ari/applications/my_app/subscription?eventSource=endpoint:PJSIP

为了更清楚地了解 Matt Jordan 已经提供的内容,这里有一个按照他的建议执行 ari-py 的示例:

import ari
import logging

logging.basicConfig(level=logging.ERROR)
client = ari.connect('http://localhost:8088', 'username', 'password')
postRequest=client.applications.subscribe(applicationName=["NameOfAppThatWillReapThisEvent-ThisAppShouldBeRunning"], eventSource="endpoint:PJSIP/alice")

print postRequest

ws://(主机):8088/ari/events?app=dialer&subscibeAll=true 添加 SubscribeAll=true 做你想要的 =)

可能会帮助某人:

订阅通道、网桥和端点上的所有事件

POST http://localhost:8088/ari/applications/appName/subscription?api_key=user:password&eventSource=channel:,bridge:,endpoint:

退订

DELETE http://localhost:8088/ari/applications/appName/subscription?api_key=user:password&eventSource=channel:__AST_CHANNEL_ALL_TOPIC,bridge:__AST_BRIDGE_ALL_TOPIC,endpoint:__AST_ENDPOINT_ALL_TOPIC