text
stringlengths
0
152
enabled = yes
pretty = yes
[asterisk]
type = user
read_only = no
password = whateveryoudodontusethispassword
OK, let’s load the ari module now:
$ sudo asterisk -rx 'module load res_ari.so'
Loaded res_ari.so => (Asterisk RESTful Interface)
Then, into our /etc/asterisk/extensions.conf file we need an extension to trigger the
Stasis() dialplan app:2
exten => 242,1,Noop()
same => n,Stasis(zarniwoop)
same => n,Hangup()
1 Although, to be honest, there’s really nothing more to the configuration unless you’re implementing one of
the frameworks, which is strongly recommended if you’re going to put this into a production environment,
and which we will explore later.
2 We named the app “zarniwoop” because “hello-world” was used in the Digium wiki on ARI, and it seemed
best to avoid overlap. You can of course name it anything you wish.
332
|
Chapter 19: Asterisk REST Interface
Reload your dialplan with
$ sudo asterisk -rx 'dialplan reload'
Dialplan reloaded.
At this point it might be worthwhile to simply reload Asterisk:
$ sudo service asterisk restart
There are just a few steps left, and you’re ready to test your ARI environment.
Testing Your Basic ARI Environment
Since ARI depends on WebSockets, we’ll need a tool to allow us to test from the com‐
mand line. The Node.js package manager (npm) will allow us to find and install the
wscat tool we’ll use for our tests.
$ sudo yum -y install npm
$ sudo npm install -g wscat
/usr/bin/wscat -> /usr/lib/node_modules/wscat/bin/wscat
/usr/lib
+-- wscat@2.2.1
+-- commander@2.15.1
+-- read@1.0.7
¦ +-- mute-stream@0.0.8
+-- ws@5.2.2
+-- async-limiter@1.0.0
Now let’s light it up and see what we get!
$ wscat -c "ws://localhost:8088/ari/events?api_key= \
asterisk:whateveryoudodontusethispassword&app=zarniwoop"
connected (press CTRL+C to quit)
>
So far, so good. Let’s place a call to our Stasis() app and see what happens.
Open up a new SSH window (leave the other one as is so you can see what happens in
the wscat session). Connect to the Asterisk CLI in that new shell session:
$ sudo asterisk -rvvvv
Using one of your lab telephones, place a call to 242.
On the Asterisk CLI, you should see this:
*CLI>
== Setting global variable 'SIPDOMAIN' to '172.29.1.57'
-- Executing [242@sets:1] NoOp("PJSIP/SOFTPHONE_A-00000001", "") in new stack
-- Executing [242@sets:2] Stasis("PJSIP/SOFTPHONE_A-00000001", "zarniwoop") in new stack
ARI Quick Start
|
333
And on the wscat session, you should see this:
>
< {
"type": "StasisStart",
"timestamp": "2019-01-27T21:43:43.720-0500",
"args": [],
"channel": {