[asterisk-users] AGI

Steve Edwards asterisk.org at sedwards.com
Thu Mar 14 17:24:47 CDT 2013


(A more specific subject may yield better answers -- better bait == better 
fish.)

On Thu, 14 Mar 2013, Gustavo Salvador wrote:

> Does any one knows how to place a call from a shell agi? I guess is 
> something like echo Exec Dial(DAHDI/g2/2010,,W).

While you can write an AGI in any language that has reasonable 
STDIN/STDOUT facilities (fortran was a little bit frustrating), a shell 
language like bash would not be my first choice.

Is there any reason you are not open to using a more 'mainstream' 
scripting language like Perl or PHP? You'll find more people with that 
experience willing to help.

My personal favorite is to use C because I know it best and because it is 
a compiled language so your AGIs execute 'instantaneously.'

Whatever language you choose, use an established library for the AGI 
protocol. Nobody gets it right the first time.

> Algo how i get the dnid variable?

This implies that you need to read up a bit on the AGI protocol. The 
second* thing an AGI should to is read the AGI variables -- one of which 
is agi_dnid.

You can pass command line parameters to your AGI when you execute the agi() 
function in your dialplan. For example:

 	exten = *,n,	agi(my-first-agi,${AGENT-ID})

Your AGI can then access the command line arguments as you would
normally expect for a program executed from a shell -- $argv[1],
$argv[2], etc for PHP.

Personally, I dislike 'positional' parameters. I prefer to use the
getopt_long() function so my dialplan is 'self-documenting' and easier
to maintain so for me, the same command would look like:

 	exten = *,n,	agi(my-first-agi,--agent-id=${AGENT-ID})

The difference is not all that apparent with a single parameter, but if 
you have a half-dozen, it is much more obvious and once you've make the 
change, you will always use it for consistency.

*) The first thing an AGI should do is set up a signal handler to catch 
'SIGHUP' if the channel is hung up prematurely.

-- 
Thanks in advance,
-------------------------------------------------------------------------
Steve Edwards       sedwards at sedwards.com      Voice: +1-760-468-3867 PST
Newline                                              Fax: +1-760-731-3000



More information about the asterisk-users mailing list