Asterisk AGI use

Hi there

I need to connect two external numbers with an API call and was thinking of using the Asterisk AGI. Would it be possible using that? If so, where can I start to develop functionality to achieve this?
I am a software developer so I think I would be able to program or achieve what I need but I need to know where to start.
My current setup:

  • Asterisk/Elastix running on VirtualBox.
  • I can make outbound calls so that part is taken care of and tested.


Better use AMI and start here: the switch to the asterisk wiki for more information. There already apis to work with like php, Net and so on.

This could be a simple task using PHP and AMI and Asterisk Originate command

Yes, ambiorixg12
That is the route I am currently trying, will report back if I am successfull :smile:

Okay guys so my logic is as follows:
If I can use an API that allows me to make an Asterisk CLI command remotely (Asterisk Commander) then I can use that to call the originate command.
Now before I go all-out I am testing the originate command in my server’s CLI.
The call

works fine. What I am trying to achieve though is, to connect two outbound/external numbers and not an extension and an outbound number.
Things along the lines of

don’t work.
Any suggestions on how I can achieve this or what I might be doing wrong?

Use Local/mynumber@from_internal, or specify the full SIP dialstring, with both device and outgoing digits fields, as you must be doing in the outgoing extension.

Note that CLI is not the preferred way of doing third party control. At least for older Asterisk’s AMI is preferred, although there may other option in recent ones.

Hi David.
Thanks for your help, it worked.
So I’ve set up a php script, where I call the following AMI command:

I get the following error:

I have tried “@from-internal”, “Local/@from-internal”,"" and “Local/” and none of them work.
It works when I specify a normal extension like "SIP/25"

Unless you provide the context, it will assume @default.

I got it working! Yes, like, just before I read your message :smile: I changed the context to “from-internal” and it worked! Thanks David.
I will report back again when the solution is basically done :smile:

Hi all.
So me, returning to this thread again! :smile:
I can successfully queue originates but my next step is as follows:
I want to send DTMF signals down the originating channel.
So what I have at the moment is (PHP):

fputs($socket, "Action: Originate\r\nChannel: Local/$company_number@from-internal\r\nExten: $user_mobile\r\nPriority: 1\r\nTimeout: 600000\r\nContext: from-internal\r\n\r\n"); (this works)
and I then immediately follow that up with:

fputs($socket, "Action: PlayDTMF\r\nChannel: Local/$company_number@from-internal\r\nDigit: 3\r\n\r\n"); (Unfortunately, this gives the output error: “Channel not found”.
Where am I going wrong here?
My thoughts are something along the lines of: the originating channel is now actually a SIP channel? Question is how do I specify that?

  1. the channel instance has -xxxx appended, where xxxx is a random number to create a unique instance ID.

  2. when the channel is answered, the local channel will optimise out and you will need to know the name of the underlying real channel to use send DTMF.

That channel is the channel that is running the outgoing extension, so the easiest way is to play it from that extension.

Hi David
Thanks for the reply.
Okay so help me out here because I am still new to all this.
Are you saying that I need to use the “Exten” number dialed, in the Originate call, as the Channel to send the DTMF signal on?
If this is the case, what would the syntax look like?
I have tried “$user_mobile”, “SIP/$user_mobile”, “SIP/$user_mobile@from-internal”, “Local/$user_mobile” and “Local/$user_mobile@from-internal”.
Also, when you talk about the Instance ID, is there a way for me to get the value of this assigned number?

No. I’m saying that the easiest way is to use the dialplan code of that extension to send the DTMF.

At the moment, I think you are in too deep. The support forums are not a substitute for reading documentation, going on courses, or paid consultancy. What they can do is hint you to features you may have missed, and correct misunderstandings.

Whilst it is possible that someone has code which does what you need and is willing to let you have it on an unsupported basis, they really need to know what your application is, rather the specific point that you are asking about. The right solution may well be very different from the way you are going at the moment.

Thanks for your help David, I’ll keep in mind what you said.
I have been looking at courses and paid support, but as a young working man, with this as a solo project, I don’t have that kind of money to throw around.
Still, thanks for all your help!

So to add on to what David said about specifying what precisely I need to achieve, I’m gonna post it here and hope someone can help or maybe has a snippet of code to help:
[li]I want to connect two numbers with a PHP call to the Asterisk AMI.[/li]
[li]These numbers will always be external numbers out on the PSTN and will never be an extension on the PBX.[/li]
[li]Sometimes, -one- of these numbers will be a call center, so DTMF signals need to be sent on this line/channel.[/li]
[li]Not only does the solution need to send the DTMF signals, but it also only has to call the -other- extension which is not a call center, when a physical person has picked up the receiver on the call-centers side[/li][/ul]
So the solution waits in the call center queue, and then when a physical person has picked up it calls the other extension then they are connected.

Basically you are building a Dialer and based on your requirements it must be “smart”. What you want to do is possible but you will need a deep understanding of asterisk and dialers. My two cents:

  1. Don´t use Elastix for that, you will end with a messed up configuration files and includes.
  2. Try to switch to asterisk 13 and take a deep deep look into ARI and Stasis.

If none of the above works for you and you decide to keep current version then try to achieve someting with the next logic:

Dialer trigger the call(send it to a local channel), evaluate the type of answer(human or machine, try to tune the AMD command), If it is a machine execute an AGI to retreive the channel(you have already the number so you can use core show channels from AMI or CLI to grep/get the channel), with the channel name pass the DTMF(try to inject it with playdtmf or chanspy as a workaround).

If it was a human then continue the flow as expected, in both cases you can send it to a QUEUE or to another channel. Take a look into the bridge command.

And also take a look into the Elastix´s Call center Dialer(/opt/elastix/dialer) that will help you to build yor dialer.