Simple in principle, and the Perl code was a breeze. However, it needed to retrieve a variable from the dial plan at the beginning and then set another at the end. Could I get that variable's value? Could I buggery. I scoured the forums and Google for information but all anyone had to say on the matter was "don't use AGI->Verbose() with a \n before get_ or set_variable" which was of absolutely no use to me. I couldn't actually retrieve any variable with agi->get_variable().
A few hours of trial and error later, and my script is running like a dream. What did I do? Well, it goes like this ...
- My kit : Centos5.1 server on a quad core running Asterisk 1.4.18.1.
- Install the Asterisk::AGI module by typing :
perl -MCPAN -e 'install Asterisk::AGI' - Start your AGI program like this :
#!/usr/bin/perl
use strict; # Not essential, but always adviseable.
use Asterisk::AGI;
my $agi = new Asterisk::AGI;
my %dummyvar = $agi->ReadParse(); - That last line is the key. Without that there was no way any calls to $agi->get_variable() were going to work. Why? Who knows, certainly no one on the forums seemed to. What it does is load the hash dummyvar with all the environment & call information passed when the agi call was made. You don't need to do anything with it.