<div dir="ltr"><div><div><div><div>Thank you so much for your help. I think I mostly understand now, I just want to confirm that I'm thinking of this properly. Basically, in the dialplan you can pass an arbitrary string to Stasis, which serves as the application name and handle by which a websocket client refers to that application. I need to dial that extension to get a channel into it from a phone or e.g. something like, <br>
<br>client.channels.originate(endpoint="Local/hello-world@default", extension="hello-world", context="default")<br><br></div>using ari-py from anywhere if I have the extension you mentioned. I also noticed that I need an active websocket at /ari/events?app=<appname>&api_key=<user:password> in order for the channel to remain open (for example, leaving open the wscat example in the getting started guide), otherwise it hangs up immediately.<br>
<br></div>I think one thing that led me astray before was that when I ran originate_example.py I got the no-json error indicated in this air-py github issue [1] and immediately assumed that I was just doing something wrong. In fact, that example shouldn't raise an exception regardless of the appname - it just won't do anything until a phone dials an extension that triggers a Stasis command with that appname.<br>
<br></div>Does all this sound correct? If so it sounds like I should try to debug ari-py or look into other abstraction layers.<br><br></div>Thanks again,<br><br>Nick<br><div><div><br>[1] <a href="https://github.com/asterisk/ari-py/issues/3">https://github.com/asterisk/ari-py/issues/3</a><br>
<div><br></div></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Jun 29, 2014 at 10:56 PM, Matthew Jordan <span dir="ltr"><<a href="mailto:mjordan@digium.com" target="_blank">mjordan@digium.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div class="h5"><br>On Sun, Jun 29, 2014 at 9:27 PM, Nick Horelik <<a href="mailto:nhorelik@mit.edu" target="_blank">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></div></div>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" target="_blank">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" target="_blank">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" target="_blank">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" target="_blank">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" target="_blank">https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Applications+REST+API#Asterisk12ApplicationsRESTAPI-subscribe</a><span class="HOEnZb"><font color="#888888"><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" target="_blank">http://digium.com</a> & <a href="http://asterisk.org" target="_blank">http://asterisk.org</a><br>
</font></span></div></div>
<br>_______________________________________________<br>
asterisk-app-dev mailing list<br>
<a href="mailto:asterisk-app-dev@lists.digium.com">asterisk-app-dev@lists.digium.com</a><br>
<a href="http://lists.digium.com/cgi-bin/mailman/listinfo/asterisk-app-dev" target="_blank">http://lists.digium.com/cgi-bin/mailman/listinfo/asterisk-app-dev</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>774.208.2168
</div>