Приступая к работе с ARI
http.conf
[general] enabled=yes enablestatic=yes bindaddr=0.0.0.0 bindport=8088 prefix=
ari.conf
[general] enabled = yes pretty = yes [test] type = user read_only = no password = test_password
*CLI> ari show status ARI Status: Enabled: Yes Output format: pretty Auth realm: Asterisk REST Interface Allowed Origins: User count: 1
*CLI> module show like res_http_websocket.so Module Description Use Count Status res_http_websocket.so HTTP WebSocket Support 2 Running 1 modules loaded
extensions.conf
[from-test] exten => 1776,1,NoOp() same => n,Answer() same => n,Stasis(hello-world) same => n,Hangup()
Тестируем ARI Websocket
yum install nodejs npm --enablerepo=epel
npm install -g wscat
npm install -g ws
# wscat -c ws://echo.websocket.org connected (press CTRL+C to quit) >
Подключимся к Asterisk при помощи wscat
wscat -c "ws://localhost:8088/ari/events?api_key=test:test_password&app=hello-world"
[root@localhost ~]# wscat -c "ws://localhost:8088/ari/events?api_key=test:test_password&app=hello-world" connected (press CTRL+C to quit)
Инициируем вызов через созданный контекст
-- Executing [1776@from-test:1] NoOp("SIP/1000-0000023e", "") in new stack -- Executing [1776@from-test:2] Answer("SIP/1000-0000023e", "") in new stack -- Executing [1776@from-test:3] Stasis("SIP/1000-0000023e", "hello-world") in new stack
wscat отобразит событие StasisStart
< { "type": "StasisStart", "timestamp": "2015-04-21T13:27:16.702+0400", "args": [], "channel": { "id": "1429608436.4119", "name": "SIP/1000-0000024a", "state": "Up", "caller": { "name": "1000", "number": "1000" }, "connected": { "name": "", "number": "" }, "accountcode": "", "dialplan": { "context": "from-test", "exten": "1776", "priority": 3 }, "creationtime": "2015-04-21T13:27:16.669+0400" }, "application": "hello-world" }
При помощи curl скажем Asterisk воспроизвести hello-world, где 1429608436.4119 - «id»: «1429608436.4119» - StasisStart
curl -v -u test:test_password -X POST "http://localhost:8088/ari/channels/1429608436.4119/play?media=sound:hello-world"
* About to connect() to localhost port 8088 (#0) * Trying 127.0.0.1... connected * Connected to localhost (127.0.0.1) port 8088 (#0) * Server auth using Basic with user 'test' > POST /ari/channels/1429608436.4119/play?media=sound:hello-world HTTP/1.1 > Authorization: Basic dGVzdGFyaToxMjM0NQ== > User-Agent: curl/7.19.7 (i386-redhat-linux-gnu) libcurl/7.19.7 NSS/3.16.2.3 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2 > Host: localhost:8088 > Accept: */* > < HTTP/1.1 201 Created < Server: Asterisk/12.5.0 < Date: Tue, 21 Apr 2015 09:28:29 GMT < Connection: close < Cache-Control: no-cache, no-store < Location: /playback/1a2a17ae-dc4e-4d47-b4d4-b7c12098551f < Content-type: application/json < Content-Length: 170 < { "id": "1a2a17ae-dc4e-4d47-b4d4-b7c12098551f", "media_uri": "sound:hello-world", "target_uri": "channel:1429608436.4119", "language": "ru", "state": "queued" * Closing connection #0
Asterisk воспроизведет приветствие
-- <SIP/1000--0000023e> Playing 'hello-world.gsm' (language 'ru')
wscat websocket соединение отобразит событие «PlaybackStarted»
< { "type": "PlaybackStarted", "playback": { "id": "1a2a17ae-dc4e-4d47-b4d4-b7c12098551f", "media_uri": "sound:hello-world", "target_uri": "channel:1429608436.4119", "language": "ru", "state": "playing" }, "application": "hello-world" } < { "type": "PlaybackFinished", "playback": { "id": "1a2a17ae-dc4e-4d47-b4d4-b7c12098551f", "media_uri": "sound:hello-world", "target_uri": "channel:1429608436.4119", "language": "ru", "state": "done" }, "application": "hello-world" }
«StasisEnd»
< { "type": "StasisEnd", "timestamp": "2015-04-21T13:34:54.382+0400", "channel": { "id": "1429608436.4119", "name": "SIP/1000-0000024a", "state": "Up", "caller": { "name": "1000", "number": "1000" }, "connected": { "name": "", "number": "" }, "accountcode": "", "dialplan": { "context": "from-test", "exten": "1776", "priority": 3 }, "creationtime": "2015-04-21T13:27:16.669+0400" }, "application": "hello-world" }
https://wiki.asterisk.org/wiki/display/AST/Asterisk+Configuration+for+ARI