Forward phone call to first available Stasis-based extension

I have a set of extensions all configured at the moment as follows:

exten => 200X,1,NoOp()
 same => n,Stasis(myAppX)
 same => n,Hangup()

where X is a number in {1, …10}. For example, when one calls 2005, the app ‘myApp5’ will take care of that call. That app interacts with the caller in an automated way (no human interaction).

On the other hand, I have successfully configured a SIP trunk and an inbound route so that I can have a call from that phone number being routed to one of these extensions, but only one.

My goal would be to implement the following scheme when someone calls that phone number:

- call routed to 2001 -> myApp1 starts. If 2001 is busy then:
- call routed to 2002 -> myApp2 starts. If 2002 is busy then:
- call routed to 2010 -> myApp1 starts. If 2010 is busy then return busy tone.

I was wondering what is the best way to achieve this? Eventually I want to be able to scale this to hundreds of extensions. I’ve been reading a bit and I have sketched this solution:

  • I set the inbound route from that phone call to 2001. In the configuration of 2001 (Advanced → Optional Destinations → Busy) set 2002 when 2001 is busy. Repeat: set 2003 when 2002 is busy, …, set 2010 when 2009 is busy.

I have read some solutions based on ring groups, but I think it would not work for me, because of the Stasis nature (since all extensions can automatically start).

However, I am not entirely convinced of my solution, since it is hard to scale to more extensions.

I appreciate any hints or ideas.
Thank you.

I’m not sure why you are using FreePBX, as you seem to have effectively completely bypassed it.

Also what do you mean by by Busy. I’m guessing you mean your stasis app is only serially reusable, not re-entrant, in which case I think you could do this using group counts

Well, I needed to forward the audio stream to a different server and the only solution I found for that was the Asterisk RESTful Interface (ARI) and the concept of External Media Server (External Media and ARI - Asterisk Documentation).

Is there a way how this can be done with FreePBX? I don’t think so, right?

On the other hand I need to rely on FreePBX functionalities such as the bulk handler.

By busy I mean that a call has been already established between two parties.

How does this differ from a normal intracompany trunk?

Nothing in your original question indicated that this had actually happened, and the normal time to treat a callee as busy, is just before making the initial setup request, not on answer.

At the moment, I think my original answer is correct, assuming the ARI is needed.

For anyone reading this: after trying a few solutions I realized I started with a completly wrong assumption. When using Statis, there is no “busy state”. One call reaches the Stasis App and it gets assigned a channel. If a second call reaches the Stasis App (and the first call is still ongoing) it simply gets another channel assigned.

So, any concurrency must be implemented at the level of the Stasis App.
One needs to ensure the (automated) answers are simply sent to the right channel back.
I hope that helps anyone in the future.