Asterisk / AMI / Perform actions based on the status of "Originate" action

Posted on 2013-12-05
Medium Priority
Last Modified: 2014-02-28
I'm brand new to Asterisk. I'm using Asterisk AMI over http, and the "Originate" command to dial and connect two external phone numbers. Is it possible to add some additional logic (to the dialplan?) that would

a) do something when the calls are successfully connected (like make an http call, or log something in a db table)
b) do something else when the calls are NOT connected successfully (Say one of the parties accidentally hung up before the call could even get started).

I know I could repeated "poll" the server and check the events, but that seems inefficent if it could be done at a lower level. From what I've read so far in Asterisk: The Definitve Guide, I think it's possible ... I'm just not sure how yet :)

Any suggestions pointing in the right direction would be greatly appreciated!
Question by:_agx_
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
LVL 25

Expert Comment

ID: 39719599
This can be done strictly through the AMI interface by monitoring the activity through events.  It means watching all the traffic and sorting out those relevant to your originate but it works.

Here's a list of events in Asterisk 11 for example,

You will see the individual channel setup,  connection of those channels, and the shutdown.

The big benefit is that you don't have to modify the dialplan this way.  The drawback is there are a fair number of events to sift through.  I use this method for a status panel through AMI over TCP.  I would suggest logging all the call activity generated from one of your originate commands and you will have a example of the events you need to be monitoring for.

A second option would be to use the UserEvent in the dialplan which will send a event to the AMI with whatever information you want to send.  It is fairly simple but will require you to do some logic in your dialplan.  

You can also use the curl command to do a http request from the dialplan,  basically the same work as using a UserEvent in that you need to do the dialplan modifcations.

You can also post data to a database but then you would have to poll the database.  It is better to stay with something event driven.
LVL 52

Author Comment

ID: 39720278
> The drawback is there are a fair number of events to sift through.

Yeah, I was hoping to avoid monitoring and use something a little more direct, like trigger a curl call at the end of the call, and pass the final status ie connected, no answer, etc..  I'm just not sure where to add that to the dialplan.
LVL 25

Accepted Solution

kode99 earned 2000 total points
ID: 39726396
I had to hook up my Asterisk lab setup.  With originate it is slightly different than a normal call.

So when you start the call it rings into the extension, then when that extension is answered the dialout occurs.  The portion where the extension rings is not really in the dialplan.  So if you reject that call nothing happens BUT you will get a even on the AMI telling you that the call was rejected etc.

This will be like this,  where ActionID matches the value you set when you made the call.
Event: OriginateResponse
Privilege: call,all
ActionID: ABC123456
Response: Failure
Channel: SIP/2223
Context: Polycom6701
Exten: 2231
Reason: 5
Uniqueid: <null>

What the Reason number means is seen here.

This even also fires a success after the call has been completed.

If you were watching the events you would also get Hangup event with a cause value and text info.  I think you need to be monitoring for call activity to see this event though.

Once you have picked up the extension the call will proceed normally in the dialplan from the point the originate specified.  So this is fairly simple in that you just need to add a bit of logic following the Dial line that checks the DIALSTATUS variable and do what you need to accordingly.

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

LVL 52

Author Comment

ID: 39727212
> The portion where the extension rings is not really in the dialplan ...
>  So if you reject that call nothing happens BUT you will get a even on
>  the AMI telling you that the call was rejected etc.

Interesting.. I didn't know that.  In my case I'm connecting two external numbers using the "Local" channel. Is the same true for the "Local" channel as well, since it's not an "extension" per se (at least not as I understand them)

My originate action between the two numbers looks something like this

Action: Originate
Channel:  Local/1NPANXX1111/@existing-internal-context
Context:  external-to-external-calls-context
Exten:  1NPANXX3333

BTW: Thanks for the good descriptions. It gives me a better picture of what's happening with the call flow.  I'm tied up on another task, but will set up monitoring and check the events you mentioned later.
LVL 25

Expert Comment

ID: 39757105
Have you looked at the AMI traffic?

The local channel is likely going to change where you need to do the dialplan modifications and may add a few more events to the AMI traffic.

I have not used local channels with my AMI apps so not sure how it will show up. I imagine you will see the setup for the local channel,  much the same as the setup for a direct sip to sip call,  then possibly a 2nd round for the connection of the two calls.

If I get the time this week I'll take a look at how the local channels showup in the AMI for connecting up calls.
LVL 52

Author Comment

ID: 39769202
Sorry, its my turn to be caught up with a deadline. I'll try and get back to this on the w/e

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

So you think no one can listen in on your VOIP conversations, eh? Well... if you haven't setup Secure Real Time Transport (SRTP), your voice communications can be hacked into by just about anyone! First, let's talk about the intended audience for…
Implementing Avaya's One-X portal is pretty painless, until you want to deploy this to the Android and iPhone clients when these clients are outside of your network. The clients will also work within your local network. Here is our experience and so…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question