[asterisk-users] AGI Script
Gustavo Salvador
gustavo.salvador.69 at gmail.com
Wed Mar 6 13:26:45 CST 2013
Thanks Steve,
That was just a snippet, the complete script is as follow:
#!/usr/bin/perl
use strict;
$|=1;
# Setup some variables
my %AGI; my $tests = 0; my $fail = 0; my $pass = 0;
my $key; my $value;
while(<STDIN>) {
chomp;
last unless length($_);
if (/^agi_(\w+)\:\s+(.*)$/) {
$AGI{$1} = $2;
}
}
print STDERR "AGI Environment Dump:\n";
foreach my $i (sort keys %AGI) {
print STDERR " -- $i = $AGI{$i}\n";
}
sub checkresult {
my ($res) = @_;
my $retval;
$tests++;
chomp $res;
if ($res =~ /^200/) {
$res =~ /result=(-?\d+)/;
if (!length($1)) {
print STDERR "FAIL ($res)\n";
$fail++;
} else {
print STDERR "PASS ($1)\n";
$pass++;
}
} else {
print STDERR "FAIL (unexpected result '$res')\n";
$fail++;
}
}
my $count = keys(%AGI);
print "EXEC Dial('DAHDI/g2/$AGI{dnid},,W');
my $result = <STDIN>;
&checkresult($result);
There I'm not using the AGI class because as test not works ( seems to me because it is not there within this asterisk version) . I have tested the Script communication with asterisk works making it to execute a voice prompt.
I have run asterisk in verbose mode, and also set on the debug, but the only clue I have is just this error.
Regards,
Gustavo
On 06/03/2013, at 13:24, Steve Edwards <asterisk.org at sedwards.com> wrote:
> On Wed, 6 Mar 2013, Gustavo Salvador wrote:
>
>>> I'm writing an AGI Perl Script...
>
>>> =============================
>>> #!/usr/bin/perl
>>> use strict;
>>>
>>> my %AGI;
>>> :
>>> print "EXEC Dial(DAHDI/g2/$AGI{dnid},,W)";
>>> =============================
>
> Is this your entire script or just a snippet? If this is all, this is not an AGI.
>
> An AGI is an executable that follows the AGI protocol. At a minimum, this means:
>
> 1) Read the AGI variables from STDIN.
>
> 2) Write an AGI request to STDOUT.
>
> 3) Read the AGI response from STDIN.
>
> 4) Repeat steps 2 & 3 as needed.
>
> Asterisk creates the process executing your AGI and sends a bunch of cruft to it via the process's STDIN. If you don't read this, even if you don't need to use the variables, your AGI will not execute correctly and reliably.
>
> If you do not read the response after every request, your AGI will not execute correctly and reliably.
>
> Most people use an established AGI library since nobody understands the implications of the protocol correctly the first time.
>
> Can you enable AGI debugging on the Asterisk console and see if that yields any clues?
>
>>> When dialplan executes the AGI, asterisk throw the following error: "Dropping incompatible voice fraile on SIP/INCONCERT-00004796 of formar ulaw since our native format has changed to 0x8 (alaw)."
>
> (Actual 'cut-n-paste' is better than 'retyping' console output.)
>
> I think if you take another look, this is a warning, not an error. No big deal, it means just what it says, just ignore it.
>
> --
> Thanks in advance,
> -------------------------------------------------------------------------
> Steve Edwards sedwards at sedwards.com Voice: +1-760-468-3867 PST
> Newline Fax: +1-760-731-3000
>
> --
> _____________________________________________________________________
> -- Bandwidth and Colocation Provided by http://www.api-digital.com --
> New to Asterisk? Join us for a live introductory webinar every Thurs:
> http://www.asterisk.org/hello
>
> asterisk-users mailing list
> To UNSUBSCRIBE or update options visit:
> http://lists.digium.com/mailman/listinfo/asterisk-users
More information about the asterisk-users
mailing list