Should ARI originate make the phone ring?

When does the ARI command to originate a call actually make the phone ring?

I’m learning some basic ARI commands and want Asterisk to call a phone. I have created a bridge (step 1), and created a channel (step 2) as shown below. Before I go to adding the call to the bridge (step 3), should Asterisk have already called the phone?

curl -X POST "http://<asterisk-server>:8088/ari/channels" \
-u <username>:<password> \
-d "endpoint=SIP/<device>" \
-d "extension=<extension>" \
-d "context=<context>" \
-d "priority=1"

Also, the above command succeeds and in the response JSON there is an ‘id’ key. Is this the new channel ID? (I can’t find documentation on the response values). There’s also JSON info about a bridge which is blank…I assume because it hasn’t been added to a bridge yet…

There are a bunch of steps involved with making a call with ARI. To start with:

  • Create a bridge.
  • Create the two channels for the ends of the call, specifying a suitable “endpoint” for each.

An “endpoint” can take a form like PJSIP/number@endpoint for dialling what we might call the “outbound” end of a call (through a SIP provider), or PJSIP/endpoint for the “inbound” end, terminating directly on one of your own SIP phones. Another option might be Local/exten@context to terminate in your dialplan.

And then start monitoring events to control what to do next:

  • You will get ChannelCreated, ChannelStateChanged and Dial events for each channel (plus a third one that PJSIP creates!)
  • You wll get StasisStart for each channel; at this point, you should answer the channel and attach it to your bridge.

Now you have established the call, wait for ChannelDestroyed events when the call finishes, after which you can tear down your bridge.

If you want to see a worked example in detail, have a look at the track_call_ari_bridged_async script in my seaskirt_examples repo.

Thanks for the steps - makes the next piece easier.

As I’m building this in small steps, I’m trying to understand from your response when exactly the endpoint will ring. (I’m connecting 2 internal endpoints). You don’t add the channels into the bridge above (maybe that’s implied).

When does the phone ring (and the dial happen)?

  1. Once the channel is created?
  2. Once the channel is added to the bridge?
  3. Once two channels are added to the bridge?

I’m trying

If using the originate functionality (as your original curl does), then upon invoking the ARI route it should be dialed.

You mean you want to know when the phone rings on the remote side? You can’t know that cause you are not on the remote side :slight_smile: You can get some events like when the call was answered and when the call failed. Having said that, if you are reading the SIP packets you can capture a 180-ringing and that’s how you are going to know the remote side is ringing, though not through Asterisk afaik… Perhaps AMI somehow gives you a call status of 180-ringing from the SIP?..but I will certainly be lying if I tell you I know AMI can do that… by the way, even if SIP tells you there is ringing doesn’t mean the remote phone is ringing, it just means the receiving carrier is sending a ringing signal to his customer.

Even that isn’t generally true, e.g. many Asterisk systems are configured to end a RINGING status before the B leg has been requested. Also, the ISDN name for this, Alerting, is more accurate, although that still doesn’t really allow for phones set to silent, no vibrate mode, except in as much as the display may change.

I think the OP is really asking when is the call actually placed.

Totally agree with you. However, there are case scenarios where the client requires to literally hear the call progress on the remote line. They want the calling party literally hear the callee party ringing. Example: some government entities. Not that they can have what they want, lol.

Asterisk will send you “Progress” events. You can report those back to the user in whatever form, e.g. claim that they indicate the other end is “ringing”, or play some sound to that effect, if that’s what makes them happy.

My original post mentioned “originate” a channel (and I meant causing Asterisk to call an endpoint) by calling the “/ari/channels” method

But I’m starting to wonder if that’s correct. The doc says the above will create and originate a channel, yet “/ari/channel/create” also creates a channel which I can then “dial”.

Since my attempts to use just /ari/channels is failing, I’m wondering if I’m doing this incorrectly? Do I have to create the channel with /ari/channel/create and then call /ari/channels/x/dial to originate? The doc isn’t really clear on the difference between these two approaches (or at least I’m not getting it)…

Making some assumptions, I think he means that the A side channel will not be allocated to the stasis application unless and until it has been answered.

The non-ARI way of getting early media ringback from an Originate would probably (I haven’t tested it) be to originate to a local channel, which answered the A side call before dialling the real A sid.

The create and dial method allows the channel to be bridged early to a caller before dialing it, allowing early media to flow amongst other things such as ringing.

Which to use depends on what exactly the use case is and what is trying to be achieved.