Search the Asterisk Blog

Asterisk 14 ARI: Create, Bridge, Dial.

By Joshua Colp

Asterisk’s REST Interface (ARI) in both Asterisk 12 and 13 has the ability to originate (create) outgoing channels.  The functionality in ARI mirrors that of the “originate” CLI command, AMI action and dialplan applications.  In its use, it creates, in one operation, a channel that is setup, dialed, and directed to a location upon answer.  The big limiting factor is that all of these things happen in a single operation, and an answer is a required part of the process.

In Asterisk 14, much more flexibility is provided by splitting the operation in two parts: channel creation and channel dialing.

POST /channels/create

As you might imagine, the create operation will create an outgoing channel; but, unlike the regular originate operation, the channel will be immediately placed into your ARI application, without being dialed. While in the ARI application, you can perform operations on it that logically make sense. Any that don’t will respond with an error – don’t try to play a sound file to it, it hasn’t been dialed yet, silly. If your outgoing channel is the result of an incoming channel, you may want to connect the two in a bridge in case the outgoing channel provides progress in the form of media – inband ringing, or a friendly phrase saying the call could not be connected.

The operation takes a very slimmed down list of arguments in comparison to the origination one; just those required to create an outgoing channel and location information, nothing more. In fact, arguments controlling variables or caller ID are not present, as these should be set using the variable operation before dialing. You might also notice that you can not send created channels to the dialplan. This is because the dialplan, and dialplan applications, were not written to take into account created, but un-dialed channels, and thus do not support them. You can only send a created channel to an ARI application.

Early Bridging

The act of placing channels into a bridge before one has answered is referred to as “early bridging”. The bridging functionality in Asterisk has been changed to transparently, without any effort on your part, handle this case and do “the right thing.” You need only use the same operations that you would have used previously on answered channels to add them to the bridge.

A common scenario would be the following:

  1. Create an outgoing channel
  2. Set variables and callerid on the outgoing channel
  3. Create a bridge
  4. Add the calling channel to the bridge
  5. Add the outgoing channel to the bridge
  6. Dial the outgoing channel

This mirrors that of Asterisk’s Dial() application and ensures that any early media is conveyed. Building on this as a base allow you to implement many of the features of app_dial or even create new ones more easily.

POST /channels/{channelId}/dial

Once a channel has been created and you have performed any operations you want on it, you can actually perform the dial operation by calling “dial” on it. Dial places the actual outgoing call and you will receive events as they occur.

Give It A Try

As of this writing Asterisk 14.0.0-beta1 is available which includes this functionality. If you’ve been wanting more control over the dialing process in your ARI application, the future is now. If you experience any issues please submit an issue on the issue tracker so we can squash it before release.

There Are 2 Comments

  • Dovid says:

    Does this mean that I can finally replace AGI’s with ARI?

    • Joshua Colp says:

      That depends! As ARI doesn’t provide access to run arbitrary dialplan applications you have to use the primitives provided to do what you need. If they fit your needs – then yes!

Add to the Discussion

Your email address will not be published. Required fields are marked *

About the Author

Joshua Colp

Joshua Colp is a Senior Software Developer at Digium and a long time Asterisk developer. He originally started in the community submitting simple patches and grew into improving and creating new core components of Asterisk itself. He is a self-taught programmer who believes in finding the balance between doing things the way they should be done and doing what is right for the people using the software. In his spare time he enjoys smashing fax machines.

See All of Joshua's Articles

More From
The Digium Blog

  • No items