How can I call an AGI command via AMI?

Hy everyone!

How can I call an AGI command via AMI?!
Iwould like to stream a .gsm file but I can’t.

I find the way, but i can’t figure out how could I use it well.

Action: AGI ActionID: 123456 Channel: SIP/1003-0000003b Command: EXEC Playback agent-alreadyon CommandID: asd123

I always get an error message like this:

[quote]Response: Error
ActionID: xyz
Message: Permission denied[/quote]

What do I wrong?
Which is the correct form in the Command part? :question:


You have got the error permisison denied. Whilst I can’t say whether or not the function you want exists, the rejection is not for that reason, is is because your manager user doesn’t have the right login permissions.

Thanks for your reply!

You have right. This permission needed.

But now this message come fom the AMI:

[quote]Response: Error
Message: Failed to add AGI command to channel SIP/1003-0000000b queue[/quote]

Any suggestion? :question: :confused:


I found the way. :smile:

Async agi.

i have the same error with you.

could you help me to solve it?
how can i set agi async in my dialplan?

please help me, thanks.

For example:


exten => 6600,1,NoOp(Async AGI)
 same => n,AGI(agi:async)

Set these permisions for the AMI user:

read = agi write = agi

Use the usual AMI form like this:

Action: AGI ActionID: <value> Channel: <value> Command: <value> CommandID: <value> … Action_AGI

Action: AGI ActionID: 123456789 Channel: SIP/1003-00000024 Command: ANSWER CommandID: Test

Action: AGI ActionID: 123456789 Channel: SIP/1003-00000024 Command: ASYNCAGI BREAK CommandID: Test

I hope it could be helpful!. :smile:
Good Luck!

Thank tomaszcool. but i configure your instruction into extensions_custom.conf, something like that:
; This file contains the contexts the agents login for the module call center.
; and contains the context conferences for module conferences of elastix 1.0.

exten => 1234,1,Playback(demo-congrats) ; extensions can dial 1234
exten => 1234,2,Hangup()
exten => h,1,Hangup()
include => agentlogin
include => conferences
include => calendar-event
include => weather-wakeup
include => async-agi

exten => _*8888.,1,Set(AGENTNUMBER=${EXTEN:5})
exten => _*8888.,n,NoOp(AgentNumber is ${AGENTNUMBER})
exten => _*8888.,n,AgentLogin(${AGENTNUMBER})
exten => _*8888.,n,Hangup()

exten => 9999,1,Set(CALLERID(name)=“MMGETOUT”)
exten => 9999,n,Answer
exten => 9999,n,Playback(conf-will-end-in)
exten => 9999,n,Playback(digits/5)
exten => 9999,n,Playback(minutes)
exten => 9999,n,Hangup

;Used by cbEnd script to play end of conference warning
exten => 5555,1,Answer
exten => 5555,n,Wait(3)
exten => 5555,n,CBMysql()
exten => 5555,n,Hangup

exten => _*7899,1,Answer
exten => _*7899,2,Playback(${FILE_CALL})
exten => _*7899,3,Wait(2)
exten => _*7899,4,Hangup()

exten => *61,1,Answer
exten => *61,2,AGI(nv-weather.php)
exten => *61,3,Hangup
exten => *62,1,Answer
exten => *62,2,AGI(wakeup.php)
exten => *62,3,Hangup

exten => _X.,1,NoOp(Async AGI)
same => n,AGI(agi:async)

after confiugure, i use the linphone (configure extension 101) make a call to x-lite(configure extension 102).

if i send action like your sugguest:
Action: AGI
ActionID: 123456789
Channel: SIP/102-0000005b
Command: ANSWER
CommandID: Test

Response: Error
Message: Failed to add AGI command to channel SIP/102-0000005b queue

could you explain to me?
thanks & best regards.


I get this error message when I don’t use the async agi and I want to add an agi command for the channel. So Did you surely call the “same => n,AGI(agi:async)” part of the dialplan? Check the asterisk CLI.

i check in CLI with command: dialplan show
and the result contain:
[ Context ‘async-agi’ created by ‘pbx_config’ ]
’_X.’ => 1. NoOp(Async AGI) [pbx_config]
2. AGI(agi:async) [pbx_config]

please help me!
could you send me the dialplam that you config?

thanks and best regards.

Here is my extensions.conf:

exten => 6600,1,NoOp(Async AGI)
same => n,AGI(agi:async)

I use the 1005 SIP Client (with Twinkle or Jitsi) and login to the Asterisk and call the 6600 number.
I get these responses from the Asterisk CLI.

Aftret this I loging into the AMI via telnet and send commands.

Action: AGI
ActionID: 123456789
Channel: SIP/1005-00000003
Command: ANSWER
CommandID: Test

The key is the right channel (“SIP/1005-00000003”).

I can offer you a great book: Asterisk: The Definitive Guide, 4th Edition, page 587.

Thats all.

to your opinion, you make the call from extension 1005 to 6600.
so, you can send command with channel is SIP/1005.
but how can you send action answer from extension 6600?

my question is : "how can answer the incoming call ?"
could you help me, please?

thanks and best regards.

You can’t send actions from 6600 extension.
If you wan to manage this (6600) extension you have to do it with Asterisk Manager Interface (AMI). Of course in this case the aim is the caller channel (SIP/1005-00000003) instead of the extension (6600).

The async agi provide a dynamic realtime managing via AMI.

thank tomaszcool so much.

one more question please.
how can send action answer for incoming call (pick up a call) by AMI and AGI ?

thanks and best regards!

telnet to AMI: … r-api.html

AST11 AMI actions: … MI+Actions

AST11 AMI events: … AMI+Events

Good Luck! :wink: