AMI - Dial Two Extensions at Same Time, Connect First to Pickup

What I’m trying to do is the following and I want to make sure I go down the right path here…

I have three extensions.101, 102, and 200.

When extension 200 calls extension 101 I want 102 to ring as well. Then which ever extension (101 or 102) picks up first it is then connected to 200.

So far I’ve gotten AMI going and I’ve managed to trigger an Originate to 102 when I detect a call being made to 101 (I’m currently looking for the “Newchannel” event.

The question now is what do I do. The Originate needs an extension to connect to. I thought about creating a Bridge to do this. I could do this with ARI (since I don’t see how to do it with AMI) and then possibly pass this bridge name in to the “exten” of the Originate? Then if I see it actually pick up then send a “Redirect” to the original call from 200 to 101 to bring 200 into the bridge with 102 and hangup the call to 101?

For completeness, if 101 answers before 102 then just let things happen and don’t do anything.

Or is there a better way about going about this? To simplify this, think of the example of when someone phones a house. Every phone in that house rings. When one of the phones is picked up, the rest of the phones stop ringing. In this case each phone is different extension and they are all created dynamically on the fly.

Appreciate any feedback.

Could you use a Queue with a ‘ringall’ strategy?

I was thinking that. But how do I setup a queue in AMI to do that? Also how would I do it so that it happens after the initial call (extension 200 to 101) has already been initiated? I would have to setup the queue before the call was initiated?

That brings up an important requirement. I can’t add 102 and 101 into a queue before the call happens because I need to intercept the call request and then send a command to the SIP client running as extension 102 because it’s running on a mobile device. I need to let it know that a call is coming first so that it then registers, on demand if you will, with the Asterisk server in the background. I can’t keep this connection connected all the time since it would drain the battery of the user’s phone too quickly. Thankfully, I’ve already got all this notification stuff built in my application now.

I don’t think the queue will work unfortunately now that I talk it out. :slight_smile:

call 101 to 102 and extension 200 call **102
you can code it is

exten => _**.,1,PickupChan(PJSIP/${EXTEN:2})
same => n,Hangup

You are confusing yourself by using extension to refer to two different things, an Asterisk extension and and SIP device/end point.

You have three devices. When device 200 calls extension 101, you want Asterisk to ring extensions 101 and 102…

The way to do this is to use the & operator in the Dial application:

exten => 101,1,Dial(SIP/101&SIP/102)

Note also that best security practice is not to name devices based on their primary extension. If you do this the distinction between devices and extensions will be much clearer.

1 Like

Thanks for the reply David and Tom.

For ease I named the extensions/endpoints 101, 102, 200 in this email. In reality I have different values for endpoints and extensions but they were long values that I didn’t want to confuse the question with.

So to do this with AMI I would set the exten value in the the AMI action to 101,1,Dial(SIP/101&SIP/102)?

I assume this would need to be setup before the call to 101 occurs? Which I’m not sure if this will work for my use case based on my reply above. I need 200 to call 101 and then using AMI trigger a call to 102 (this I’ve got working). Then which ever answers first, 101 or 102, connect that to 200 (this is the last piece I need to sort out).

No. This is what you do in the dialplan. I assumed anyone using AMI would be familiar with dialplans. Please explain why you need AMI at all.

1 Like


AMI (and ARI) is being used to dynamically create endpoints (and the users and aors) for mobile sip client devices as they are unknown at the time of setup (see my first reply to this thread above.) The desk phones are known. So in this example 101 is the desk phone and 102 is the dynamically created endpoint. In reality I’m just using a random UUID for the endpoint name but for ease of understanding here I’m calling it 102.

I’m not sure what you mean, “this is what you do in the dialplan”? What is “this”? You mean to use AMI DialPlanExtensionAdd action? I am unclear how to use this action as there is not a lot to go on here and I can not find any examples for this specific function.

Or by “this” do you mean that the dialplan can be used to send an APNS notification to my mobile sip client (again, please read my first response at the top speaking about mobile devices and the need to notify them when a call is about to come in).

To be clear, I can NOT create a dialplan in the configs on the server since some of my endpoints are being created dynamically. The dynamic endpoints get related to the desk phones. Which is why I want to “link” them so that they both ring when the desk phone extension is called.

I appreciate the help and my apologies for not being able to follow you here.

Ok I finally “get it”. I managed to get an entry into the Dialplan that made sense using AMI…

Action: DialplanExtensionAdd
Context: test
Extension: 101
Priority: 1
Application: Dial
ApplicationData: PJSIP/101&PJSIP/102
Replace: yes

This works well and both devices ring. One setup in the extensions.conf (101) and the other using ARI (102). Worked great.

Last issue I have now is that I need to somehow delay the call to 102 as that is on a mobile device. For an Apple device I need to send it a VOIP notification so that the sip client app can connect and register with the Asterisk server in the background in order to receive the INVITE.

Any thoughts on this?

So far I thought about a multi-line dial plan entry that would could delay for a second or two before actually calling the DIAL application. But this seems like a bit of a hack. It would be nice to be able to let the DIAL application know when it’s ok to dial out to 102.

The Dial application itself does not allow that to occur. The way that people implement it is using a Local channel which executes dialplan logic for one of the dialed parties. In there they do the notification, wait, and then Dial.

Thank you J,

Are there any examples you could point me to? I’m not sure I follow the “Local channel”?

Thoughts I had were something like the EXEC or SHELL command. But that seems a bit of a hack. Would be good if I could send some data to a socket and get a response and then act on that…

1, Dial (PJSIP/101)
2, Set (result=$(SHELL (/bin/sendNotificationAndGetResult)))
3, GotoIf ($result = “1” ?dial2)
4, hangup()
5, (dial2),Dial(PJSIP/102)

I’m pretty sure I don’t have the syntax exactly correct above. But you get the idea. The way I have things setup is that I send a notification to the device, the device registers with Asterisk, the device then sends back to my application that it is registered and ready to receive the call. In this case it sends back a 1 which gets put into “result”.

I know many people don’t wait for a response back and just wait a second or two and then call DIAL. This always seemed like a bit of a risky way of doing things. Perhaps I’m making it too complicated. But is this in line with what you were thinking?

If you are calling a single device you can do something like that. If you are calling more than one you can’t, as if one is registered then Dial won’t return. That is why I mentioned the Local channel.


That creates two channels, one dials the PJSIP endpoint named ‘jcolp’. The other executes dialplan logic, extension jcolp in context mobile. In that case you can execute the mobile logic in there, including Dial, at the same time as dialing the normal PJSIP device.

1 Like