Приступая к работе с 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

http show status

http show status

localhost*CLI> http show status
HTTP Server Status:
Prefix: /test
Server Enabled and Bound to 0.0.0.0:8088

Enabled URI's:
/test/httpstatus => Asterisk HTTP General Status
/test/phoneprov/... => Asterisk HTTP Phone Provisioning Tool
/test/amanager => HTML Manager Event Interface w/Digest authentication
/test/arawman => Raw HTTP Manager Event Interface w/Digest authentication
/test/manager => HTML Manager Event Interface
/test/rawman => Raw HTTP Manager Event Interface
/test/static/... => Asterisk HTTP Static Delivery
/test/amxml => XML Manager Event Interface w/Digest authentication
/test/mxml => XML Manager Event Interface
/test/ari/... => Asterisk RESTful API
/test/ws => Asterisk HTTP WebSocket
*CLI> module show like res_ari
Module                         Description                              Use Count  Status
res_ari.so                     Asterisk RESTful Interface               10         Running
res_ari_applications.so        RESTful API module - Stasis application  0          Running
res_ari_asterisk.so            RESTful API module - Asterisk resources  0          Running
res_ari_bridges.so             RESTful API module - Bridge resources    0          Running
res_ari_channels.so            RESTful API module - Channel resources   0          Running
res_ari_device_states.so       RESTful API module - Device state resour 0          Running
res_ari_endpoints.so           RESTful API module - Endpoint resources  0          Running
res_ari_events.so              RESTful API module - WebSocket resource  0          Running
res_ari_model.so               ARI Model validators                     0          Running
res_ari_playbacks.so           RESTful API module - Playback control re 0          Running
res_ari_recordings.so          RESTful API module - Recording resources 0          Running
res_ari_sounds.so              RESTful API module - Sound resources     0          Running
12 modules loaded
*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"
}

Getting Started with ARI

https://wiki.asterisk.org/wiki/display/AST/Asterisk+Configuration+for+ARI

Только авторизованные участники могут оставлять комментарии.
  • asterisk/ari/ari_start.txt
  • Последние изменения: 2018/03/12