<div dir="ltr"><div><br>On Sun, Jun 29, 2014 at 9:27 PM, Nick Horelik <<a href="mailto:nhorelik@mit.edu">nhorelik@mit.edu</a>> wrote:<br>> Hello,<br>><br>> I am a bit new to Asterisk in general, so I apologize if this is a very<br>
> basic question. After scouring the internet for a few days I seem to be<br>> unable to find a good description of what an 'external Stasis application'<br>> is at a high level. The 'Getting Started with ARI' article has been very<br>
> helpful getting me going on ARI in general, but beyond mentioning that 'my<br>> application' needs to be connected with Stasis there isn't much guidance on<br>> where I should look next for how to write that application and where I would<br>
> install it.<br>><br>> In particular I'm hoping to use ari-py [1], which has been useful in helping<br>> me learn. However, all the provided examples still try to point to the same<br>> 'hello' app mentioned in the getting started guide, which of course will<br>
> fail for me since I don't know how to create or where to put this 'hello'<br>> app.<br>><br>> I can successfully use ari-py to do things like:<br>><br>> client.channels.originate(endpoint="PJSIP/<mynumber>@mytrunk",extension="hello-world",<br>
> context="default")<br>><br>> to call my cell phone and play a message hardcoded into a hello-world<br>> extension, for instance, but I'm not sure how to do anything more<br>> complicated than that. The next thing I would like to learn how to do is use<br>
> ARI to specify an audio file to play (perhaps using<br>> /channel/{channelID}/play), but it's my understanding at this point that I<br>> need my channels inside a stasis application before I can do that.<br>
><br>> Again, I'm sorry if my confusion arises from a failure to understand<br>> something basic about Asterisk in general. I would greatly appreciate any<br>> hints for where I should be looking for references that can help me learn<br>
> more.<br>><br>> Thanks,<br>><br>> Nick Horelik<br><br>Hi Nick -<br><br>ARI is all about controlling things in the context of a dialplan application. Just as, say, the 'Queue' dialplan application has multiple channels that go into it (and under the hood, has bridges, and device state, and all sorts of other things), channels need to be passed into something in the dialplan to hand it off to a connected ARI client. While you can do some things outside of that - such as originating a channel to another location in the dialplan - things are a lot more interesting when you have them in a dialplan application that you control externally.<br>
<br>That dialplan application is the "Stasis" dialplan application [1]. Using your originate example, you could do something like the following:<br><br><span style="font-family:courier new,monospace">exten => hello-world,1,NoOp()<br>
same => n,Stasis(hello-world)<br> same => n,Hangup()<br></span><br></div>When the channel enters into the dialplan application Stasis, that's Asterisk's signal that it is handing control of the channel off to a connected ARI client. In this case, your WebSocket establishes the connection for your ARI application, and informs Asterisk which Stasis dialplan application it wants to control [2]. In this case, the Stasis dialplan application was passed the name 'hello-world' as the name of the application - so a WebSocket that had connected to that application would see that a channel had entered into it.<br>
<br>When a channel does enter into the Stasis dialplan application, the connected WebSocket gets a 'StasisStart' event [3]. That's the application's sign that it can now freely manipulate the channel - such as issuing a play operation through the ARI channels resource. When the channel leaves, the WebSocket gets a 'StasisEnd' event [4]. That's the applications sign that it no longer has control over the channel, and will stop receiving information about it.<br>
<br>If the application wants to continue seeing information about the channel, it can subscribe to the channel via the applications resource [5].<br><br>Hope this helps - if you run into an issue, please don't hesitate to contact this list.<br>
<br>Matt<br><div><br>[1] <a href="https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Application_Stasis">https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Application_Stasis</a><br>[2] <a href="https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Events+REST+API#Asterisk12EventsRESTAPI-eventWebsocket">https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Events+REST+API#Asterisk12EventsRESTAPI-eventWebsocket</a><br>
[3] <a href="https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+REST+Data+Models#Asterisk12RESTDataModels-StasisStart">https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+REST+Data+Models#Asterisk12RESTDataModels-StasisStart</a><br>
[4] <a href="https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+REST+Data+Models#Asterisk12RESTDataModels-StasisEnd">https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+REST+Data+Models#Asterisk12RESTDataModels-StasisEnd</a><br>
[5] <a href="https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Applications+REST+API#Asterisk12ApplicationsRESTAPI-subscribe">https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Applications+REST+API#Asterisk12ApplicationsRESTAPI-subscribe</a><br>
<br>-- <br>Matthew Jordan<br>Digium, Inc. | Engineering Manager<br>445 Jan Davis Drive NW - Huntsville, AL 35806 - USA<br>Check us out at: <a href="http://digium.com">http://digium.com</a> & <a href="http://asterisk.org">http://asterisk.org</a><br>
</div></div>