The ARI protocol is a robust interface for controlling Asterisk and reacting to Asterisk events. It has been thoroughly tested with Asterisk versions 15 and 16.
ARI stands for Asterisk REST Interface. Through the REST interface it is possible to control just about every aspect of an Asterisk server. ARI also provides a Websocket interface for consuming events from the Asterisk Server. This library has full support for both the REST and Websocket protocols.
If you’re not to familiar with Asterisk, there’s an example repo that will get you up and running with a custom Asterisk IVR in a few minutes, https://github.com/citybaseinc/ex_ari_example .
The documentation is pretty thorough, but it definitely helps to understand Asterisk and ARI.
So I wanted to try the ex_ari_example out last night, but I had some trouble with the Asterisk part. I haven’t played with Asterisk before so I’m not really sure what’s going wrong.
The docker run ... command uses --net host, which doesn’t work on Mac unfortunately. So I ran it like this instead: docker run -p 8088:8088 -p 8089:8089 -p 5062:5062/tcp -p 5062:5062/udp -p 10000-10099:10000-10099/udp --name asterisk -v $PWD/asterisk_local_config/pjsip.conf:/etc/asterisk/pjsip.conf ex-ari-asterisk (I googled around a bit and guessed at the ports). After this, I could start the project with iex -S mix and it connected!
However, I was unable to connect to Asterisk with Zoiper. On the accounts page it says Request Timeout (code: 408) and there is nothing in the Asterisk logs.
I then tried running the Asterisk container inside an Ubuntu virtual machine, using --net host, and running it on a bridged network (VM had IP 192.168.33.10). I changed all the references to 127.0.0.1 to 192.168.33.10 in dev.env, so the Elixir project works fine. But Zoiper gives me a new error now. Instead of Request Timeout (code: 408) error, I now get Unauthorized (code: 401) and I see this in the Asterisk logs:
[Feb 14 07:29:30] NOTICE[37]: res_pjsip/pjsip_distributor.c:676 log_failed_request: Request 'REGISTER' from '<sip:ex_ari@192.168.33.10>' failed for '192.168.33.1:5063' (callid: _R51m7KNwSEepDSdZ6NrSA..) - No matching endpoint found
[Feb 14 07:29:30] NOTICE[37]: res_pjsip/pjsip_distributor.c:676 log_failed_request: Request 'REGISTER' from '<sip:ex_ari@192.168.33.10>' failed for '192.168.33.1:5063' (callid: _R51m7KNwSEepDSdZ6NrSA..) - Failed to authenticate
<--- Transmitting SIP response (505 bytes) to UDP:192.168.33.1:5063 --->
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 192.168.33.1:5063;rport=5063;received=192.168.33.1;branch=z9hG4bK-524287-1---339444ffe79eb675
Call-ID: _R51m7KNwSEepDSdZ6NrSA..
From: <sip:ex_ari@192.168.33.10>;tag=5292835a
To: <sip:ex_ari@192.168.33.10>;tag=z9hG4bK-524287-1---339444ffe79eb675
CSeq: 2 REGISTER
WWW-Authenticate: Digest realm="ex_ari",nonce="1581665370/39d4d6299126e965bb54cf6033f8eca3",opaque="389d044662fe0ad8",algorithm=md5,qop="auth"
Server: Asterisk PBX 16.3.0
Content-Length: 0
I wonder if I am using the wrong username/password?
I run Linux so haven’t had the Mac issues. It looks like you got really really close! I should probably be explicit about the demo only working on Linux as of now.
I’ll dig in a bit more in a few hours. Asterisk is NOT simple to setup. If we get it working would be great if you could write-up some notes for Mac dev.
No worries. Thank you so much for putting this out. I’ll dig into it, and see if I can get it working. And if I do I’ll be happy to add contribute it back
Just want to ask, if there is any work done this library, stands still for a few years, latest version from GitHub isn’t compilable (just little code inconsistencies) ?
thx, that’s great! I’ve already forked it and found an issue related to the stasis state implementation, the :type attribute is mentioned in the json encode, but not available in the defstruct (part of stasis.ex):
defmodule State do
@moduledoc false
@type t :: %__MODULE__{}
@derive {Jason.Encoder, only: [:connected, :url, :status, :type]}
defstruct [
:connected,
:url,
:status,
:channel_supervisor,
reconnection_attempts: 0,
app: %{}
]
end
without going deep into ARI, do you have a quick solution for this issue ?