Queue + AGI Script

Folks,

I am writing an AGI script that I would like to be executed once the call has been answered. I believe the queue function has this capability. My issue is that when I run this agi script I need to be able to pass variables through, but I do not quite understand how to do that here.

Queue(queuename[|options][|URL][|announceoverride][|timeout][|AGI])

but then in the AGI section I need to call foo.agi|foo,foo1,foo2

The | is making asterisk think that its ending the AGI.

I hope that makes sense?

What variables do you want?

You can use the GET command from AGI to get variables already set in Asterisk.

Basically I want to pass foo, foo2, foo3 along.

So if I use the queue command:

Queue(queuename|||||blah.agi|foo,foo2,foo3)

Where I use the pipe after foo.agi to pass the variables across, asterisk thinks it has ended the command.

I don’t believe you can pass parameters to the AGI directly via the Queue application. wimnat’s solution is the one you will probably need to implement.

so something like this wouldnt work?

Queue(queuename|||||AGI(script.agi|arg1|arg2|…))

No, that likely will not work.

Thank you for your help.

So if I declare all of the values that I want to get before I call the AGI Script - What is the best way to GET them?

eg.

Set(TIMESTAMP=${EPOCH})

Set(FOO=Blah)

How go I GET TIMESTAMP and FOO through AGI?

Depends on which language you are developing it in :smile:

voip-info.org/wiki/view/get+variable

Using Asterisk::AGI in perl you’d do something like this

my $timestamp = $AGI->get_variable(‘TIMESTAMP’);

I was looking at that page - I was not able to find the php equivalent of the above GET. Thank you for your help sop far - i’m almost there :smile:

phpagi.sourceforge.net/phpagi2/d … I/AGI.html

I do not have phpagi installed on the server - is this mandatory to be able to do this?

No phpagi is just an extension to make using php/agi easier. I’ve never used it.

I use…

echo “GET VARIABLE QUEUESTATUS”;

then read stdinput to get the result.

Thank you.

So if I declare:

Set(foo=foo)

and then in my AGI script:

#!/usr/bin/php -q

<?php $blah = "GET VARIABLE foo"; echo "VERBOSE \".$blah." \"; ?>

it should show “foo”

is that correct?

Not quite. You can’t assign the result directly. Here’s an example from my code.

[code]
$stdin = fopen(‘php://stdin’, ‘r’);
$stdout = fopen(‘php://stdout’, ‘w’);
$stdlog = fopen(’/var/log/asterisk/agi’, ‘w’);

// toggle agi log debugging output (more verbose)
$debug = true;

// Functions for variable input / output

function read() {

global $stdin, $stdlog, $debug;

$input = str_replace("\n", "", fgets($stdin, 4096));
if ($debug) {
	fputs($stdlog, "".date("H:i:s")." Read: $input\n");
}

return $input;

}

function write($line) {

global $stdout, $stdlog, $debug;

if ($debug) {
	fputs($stdlog, "".date("H:i:s")." Write: $line\n");
}

echo $line."\n";

}

function errlog($line) {

global $err, $stdlog, $debug;

echo "VERBOSE \"$line\" \n";
if ($debug) {
	fputs($stdlog, "".date("H:i:s")." Msg: $line\n");
}

read();

}

// Get the queue status
write(“GET VARIABLE QUEUESTATUS”);
$qS = read();[/code]

I’m sorry i really hate to sound ignorant, but I could just basically replace QUEUESTATUS with whatever variable i have set earlier?

Yep absolutly. QUEUESTATUS is just what i’m getting in that particular example.

So I copied the code you provided - replaced queuestatus with foo which I declared in extensions.conf

it seems to write a log to agi in /var/log/asterisk/
13:56:42 Write: GET VARIABLE foo
13:56:42 Read: agi_request: test3.agi

what im trying to do now is store this variable instead of doing a write.

$foo = write(“GET VARIABLE QUEUESTATUS”);

…or something like this…How is this accomplished?

The write function performs the operation for you. The read function will get the result.

So, do your write(GET VARIABLE foo);
then $myVar = read();

$myVar should now contain your variable. Make sure you turn on agi debug… ‘agi set debug on’ at the CLI so you can see what’s going on and if you have problems, post some output here.

So the output in the CLI is as follows:

Set(“channelinfo here…”, “foo=foo”) in new stack

-- Launched AGI Script /var/lib/asterisk/agi-bin/test3.agi

test3.agi: Is anything in here?: agi_request: test3.agi

the code in the AGI (not including the above code) is:

// Get the foo!
write(“GET VARIABLE foo”);
$foo = read();

echo "VERBOSE "Is anything in here?: “.$foo.” " ";

I’m pretty sure the issue you are having here is that you need to read in all of the buffered input prior to doing your write. The agi process sends a bunch of variables on startup.
The following link gives an example.
voip-info.org/tiki-index.php … 0AGI%20php