[asterisk-users] How to write a function with a return value in Asterisk

James FitzGibbon james.fitzgibbon at gmail.com
Wed Aug 8 13:03:24 CDT 2007


On 8/8/07, Mike <list at virtutel.ca> wrote:

> So, I wrote (well, plagarized directly from the Web) a simple Perl program
> that prints "Hello World".  I call it using this:
>
> exten => 12345,1,AGI(agi-helloworld.agi)
>
> Seems to work (I'm not expecting anything, really, just no Asterisk
> error).
>
> When I try to use it as part Noop like this:
>  exten => 12345,1,Noop(${AGI(agi-helloworld.agi)})
>
> In the hope of getting to see Noop(Hello World) in my CLI, I get the
> following Asterisk error:
>
> Aug  8 13:40:48 ERROR[5771]: pbx.c:1402 ast_func_read: Function AGI not
> registered
>
> AGI certainly seems registered as it worked in the first case.  Again,
> something obvious I missed?
>

This is calling the AGI application:

exten => something,priority,AGI(program|args)

This is an attempt to call a function called AGI (which doesn't exist) and
pass the results of said non-existent function to the NoOp application:

exten => something,priority,NoOp(${AGI(program|args)})

look at 'core show applications' and 'core show functions' to see what you
can call in each case.  Applications and functions aren't interchangeable.

If you want to use an AGI script to set a variable you can later use as an
arg to Dial(), then you want to call the AGI application from your dialplan,
then from inside the AGI script do your calculations and issue the AGI
command "SET VARIABLE name value".

So if you have a very basic AGI script that just does this:

echo "SET VARIABLE foo bar"

then your dialplan could look something like this:

exten => foo,1,AGI(foo.agi)
exten => foo,n,NoOp(${foo})

And you'd expect to see "NoOp(bar)" on your console when you called that
extension.

Of course, you'd want to use one of the available AGI frameworks to do the
heavy lifting of parsing the input that Asterisk gives an AGI script and
take care of the error handing when you issue a command back to Asterisk
from the AGI script.

-- 
j.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digium.com/pipermail/asterisk-users/attachments/20070808/f2446044/attachment.htm 


More information about the asterisk-users mailing list