📜 ⬆️ ⬇️

In Asterisk version 12 appeared REST interface (Asterisk REST Interface - ARI)

In Asterisk version 12 appeared REST interface (Asterisk REST Interface - ARI).

Yes, this is a RESTful API in kind.

While the following resources are available:
')


Or, interfaces to channels, devices, bridges, recordings, sounds. Probably will increase capacity :-)

Well, the main feature is the ability to connect via WebSocket to / ari / events and receive events in the permanent connection mode.
Unlike AMI, objects are walking in JSON format, and working with events is extremely convenient.
Sample ARI script:

import ari client = ari.connect('http://localhost:8088/', 'hey', 'peekaboo') def on_dtmf(channel, event): """Callback for DTMF events. When DTMF is received, play the digit back to the channel. # hangs up, * plays a special message. :param channel: Channel DTMF was received from. :param event: Event. """ digit = event['digit'] if digit == '#': channel.play(media='sound:goodbye') channel.continueInDialplan() elif digit == '*': channel.play(media='sound:asterisk-friend') else: channel.play(media='sound:digits/%s' % digit) def on_start(channel, event): """Callback for StasisStart events. On new channels, register the on_dtmf callback, answer the channel and play "Hello, world" :param channel: Channel DTMF was received from. :param event: Event. """ channel.on_event('ChannelDtmfReceived', on_dtmf) channel.answer() channel.play(media='sound:hello-world') client.on_channel_event('StasisStart', on_start) # Run the WebSocket client.run(apps="hello") 


Events are very different. Including you can generate an event using GET, and get it yourself as a UserEvent via WebSocket. So to say, Asterisk as a data bus: - {P

Connecting a call to the WebSocket application is done from the dialplan by the Stasis team.

This is how dialplan looks like:

 exten => 1,1,Wait(1.5) same => n,Stasis(dialer) ; dialer is the name of the application same => n,Wait(2) same => n,Hangup() 


You can exit WebSocket via the / channels / {channelId} / continue call, and control from WebSocket will be transferred back to Asterisk's dialplan.

It's like AMI and AGI in one bottle.

By the way, there is a delicious bun in the form of a browser by API.

Here is a screenshot:

image

Well, looking carefully at the API, I thought up a pack of UseCases:



Monitor ^ Spy ^ Record ^ Conference ^ Dialer

It looks like going to another level.

Asterisk12, while maintaining the telephone harvester for the admin, gives the developer an interface that is close in convenience and is no worse than FreeSWITCH. IMHO. There is XML, here is JSON.

And if you think about the CURL function, it turns out that soooo hands grow on the dialplan :-)

 *CLI> core show function CURL -= Info about function 'CURL' =- [Synopsis] Retrieves the contents of a URL [Description] url - URL to retrieve post-data - Optional data to send as a POST (GET is default action) [Syntax] CURL(url[,post-data]) 


Well done, what to say :-)

Main links:

Source: https://habr.com/ru/post/225007/


All Articles