How to handle channels into an ARI queue app?

1.2k Views Asked by At

I`m trying to play a little bit with ARI in order to create a queue that would be capable to serve multiple asterisk instances. After some basic documentation, it seems that ARI is the way to do it.

What I have achieved by now it`s a simple dial plan that sends an incoming call to my stasis app. Once the call came into stasis a STASIS_START event is fired, and I consider this as being the entry point to my queue (that is my first problem). After the call was received I put some records into an H2 database and start playing moh on that channel.

Just for the demo, immediately I try to create another channel to a free agent to handle the call.

The problem is that when I create the channel I have to set the app, and if I set the same app, I will get a new STASIS_START event fired(another entry in H2 DB - which is not desired), but in this case, it's a fake one, as I considered that STASIS_START should be fired only when a new call came into my "queue". I was thinking to put some variables on the "true external calls" that enter the stasis app and then check if the arrived calls have these variables... but I'm afraid I`m doing something wrong maybe from an architectural point of view.

What is the best approach here?

Another two bonus questions:

  1. Why would I use a bridge to play MOH for the waiting caller when I can play some moh directly on that channel? Is it because the bridge gave me the ability to record or capture DTMF events?

  2. Is my assumption correct that when Im trying to call for queue agents (in order to match these with the waiting call in the queue) I should usePOST /channels/createcombined with POST /channels/{channelId}/dialinstead of usingPOST /channels` which would use originate?

2

There are 2 best solutions below

0
On

The initial StasisStart should be set to handle only the external calls.

You can do it as you said by setting variable for the incoming calls or the opposite - by setting a variable for your originated agent calls.

The important thing is that you can listen to your own originated calls StatsisStart events, this events will fire only from this specific channel so you can track it easily.

Bonus answers:

  1. When you play MOH "directly" to the channel - asterisk will create a bridge for you internally. No need to create ARI bridge for DTMF too. I think (not sure) that you should create a bridge yourself only when you want to use a single bridge for multiple channels to control it easily.
  2. The benefit of using create and dial is that you can set channel variables and track the channel in all states before the answer event. If yoy trying to build the full queue app in ARI you definitely want it.
2
On

I am not the best ARI programmer in the world, but on the matter of your code calling stasisStart() the second time I believe pretty much you only have the following two options:

  1. Yes, implement your original idea of a global variable to mark the first time stasisStart is called and bypass it every time afterwards. I tried this approach and it is working very well for me.
  2. If you can arrange your scenario in such a way that the first agent to answer is considered one phone call and the transfer to the next agent is considered a new phone call (albeit with the same caller channel) then you might be able to divide your code in two ARI apps, both running registered to stasis at the same time, where agent1 answers the call with app1 and then transfers the call to app2.