Problem with a PERL AGI script

Good morning,

I am in the midst of writing a script that will accept input from a cell phone and populate a MySQL database table. I’ve started with getting data captured from a soft phone and repeating the data back via the AGI->say_digits directive.

My system configuration is:

  • Running Asterisk Version : Asterisk 1.4.21.2
  • Asterisk Source Version : 1.4.21.2
  • Zaptel Source Version : 1.4.12.1
  • Libpri Source Version : 1.4.7
  • Addons Source Version : 1.4.7

FreePBX 2.6.0.0 as installed from the PBX in a Flash ISO with all the updates installed. Hence the system is CentOS 5.4.

As for hardware, I’m running on a Dell desktop with one each Sangoma A102 and A200 for communication with the world, though I have not yet tried to move the T1 incoming line to the Asterisk system for external access.

The problem is simple: AGI->stream_file and AGI->get_data don’t seem to be working as advertised in the Asterisk::AGI man page or as documented in the second edition of the O’Reilly Asterisk book.

The source code follows. I don’t think there is a syntax problem on the stream_file command, but the man page isn’t the best in the world, so I am not certain. In this iteration of the code I am not using get_data.

Thanks for any suggestions.

==================================================

#!/usr/bin/perl -w
###############################################################################

ivr.pl

12/21/2009

Initial cut at interactive time recording

###############################################################################

somewhat from:

http://www.mail-archive.com/[email protected]/msg21137.html

###############################################################################

open(FOO,">/tmp/fooout.txt");
use Asterisk::AGI;

$now = time;

$AGI = new Asterisk::AGI;

@words = (‘a’,‘1’);

$AGI->answer();

this seems to work - the line is aswered

$AGI->say_datetime($now);

this seems to work - the date and time are transmitted

$AGI->noop(“stream file should be next”);

this does not place a message in /var/log/asterisk/full as suggested by

the documentation

$AGI->stream_file(‘room-service’,‘1234’);

this does not play the file, but if this is missing nothing else

works

grab five digits from the phone and translate them from ASCII decimal

representation back to integer equivalents

$rep = 0;
$AGI->noop(“wait_for_digits next”);

this does not place a message in /var/log/asterisk/full as suggested by

the documentation

while ($rep < 5) {
$foo_in = $AGI->wait_for_digit(15000);
$foo[$rep] = $foo_in;
$AGI->noop(“digit $rep = $foo_in”);
$rep++;
}

this reads the values of foo and converts from decimal ascii value to digit

$foo1 = ‘’;
foreach $foo_out (@foo) {
if ($foo_out == 48) {
$foo1 = “$foo1” . ‘0’;
} elsif ($foo_out == 49) {
$foo1 = “$foo1” . ‘1’;
} elsif ($foo_out == 50) {
$foo1 = “$foo1” . ‘2’;
} elsif ($foo_out == 51) {
$foo1 = “$foo1” . ‘3’;
} elsif ($foo_out == 52) {
$foo1 = “$foo1” . ‘4’;
} elsif ($foo_out == 53) {
$foo1 = “$foo1” . ‘5’;
} elsif ($foo_out == 54) {
$foo1 = “$foo1” . ‘6’;
} elsif ($foo_out == 55) {
$foo1 = “$foo1” . ‘7’;
} elsif ($foo_out == 56) {
$foo1 = “$foo1” . ‘8’;
} elsif ($foo_out == 57) {
$foo1 = “$foo1” . ‘9’;
}
}

this works as advertised

print FOO “the digits entered are: $foo1\n”;

this works as advertised

$AGI->say_digits($foo1);

this works as advertised

foreach $word (@words) {
$AGI->say_alpha($word);
}

this works as advertised