ADZ
December 8, 2008, 5:30pm
1
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?
wimnat
December 8, 2008, 11:51pm
2
What variables do you want?
You can use the GET command from AGI to get variables already set in Asterisk.
ADZ
December 9, 2008, 2:37pm
3
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.
davevg
December 9, 2008, 3:01pm
4
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.
ADZ
December 9, 2008, 3:18pm
5
so something like this wouldnt work?
Queue(queuename|||||AGI(script.agi|arg1|arg2|…))
davevg
December 9, 2008, 4:13pm
6
No, that likely will not work.
ADZ
December 9, 2008, 4:17pm
7
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?
davevg
December 9, 2008, 4:41pm
8
Depends on which language you are developing it in
voip-info.org/wiki/view/get+variable
Using Asterisk::AGI in perl you’d do something like this
my $timestamp = $AGI->get_variable(‘TIMESTAMP’);
ADZ
December 9, 2008, 8:37pm
9
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
davevg
December 9, 2008, 8:48pm
10
ADZ
December 9, 2008, 10:12pm
11
I do not have phpagi installed on the server - is this mandatory to be able to do this?
wimnat
December 9, 2008, 10:14pm
12
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.
ADZ
December 9, 2008, 10:26pm
13
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?
wimnat
December 9, 2008, 10:30pm
14
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]
ADZ
December 9, 2008, 10:35pm
15
I’m sorry i really hate to sound ignorant, but I could just basically replace QUEUESTATUS with whatever variable i have set earlier?
wimnat
December 9, 2008, 11:16pm
16
Yep absolutly. QUEUESTATUS is just what i’m getting in that particular example.
ADZ
December 10, 2008, 7:18pm
17
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?
wimnat
December 10, 2008, 10:08pm
18
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.
ADZ
December 11, 2008, 3:42pm
19
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.” " ";
davevg
December 11, 2008, 4:16pm
20
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