[asterisk-users] Trouble Playing message file via Perl AGI

David Van Ginneken davevg at gmail.com
Wed Jul 23 14:48:14 CDT 2008


Mike Diehl wrote:
> Hi all,
>
> I'm trying to build an IVR using the Perl AGI module at 
> http://search.cpan.org/~jamesgol/asterisk-perl-0.10/lib/Asterisk/AGI.pm
>
> But, I'm having trouble getting my program to play a message and wait for a 
> keystroke.
>
> I am able to use this code to play the file, so I know that the $msg variable 
> points to a valid sound file:
>
> $result = $agi->exec("background $msg");
>
> But of course, this doesn't allow me to capture any keypresses.  So I tried 
> this:
>
> $agi->stream_file($msg, "0123456789", 0);
>
> The console indicates that it's playing the message, but it then skips to the 
> next AGI instruction and nothing gets played.
>
> Then I tried to use the get_data() method.  It turns out that I had to put two 
> of them in my code, but then the timeout doesn't work and it doesn't capture 
> any keypresses:
>
> $result = $agi->get_data($msg, 120000, 1);
> $result = $agi->get_data($msg, 120000, 1);
>
> Finally, I tried to use the get_option() method that was documented in the 
> module POD file; Perl complains that the method isn't defined:
>
> $result = $agi->get_option($msg, "12345", 10000);
>
> So, what am I missing?  I know this works; too many people are doing it.  Any 
> ideas?
>
> TIA,
>   
$agi->get_data is likely what you are looking for. I'm using it
successfully in both standard and FastAGI scripts.

With this sample script:
#!/usr/bin/perl
use Asterisk::AGI;
use strict;
my $AGI = new Asterisk::AGI;
my %input = $AGI->ReadParse();
my $digits = $AGI->get_data('tt-monkeys', 10000, 1);
$AGI->verbose("We Received $digits",3);
exit;

The CLI outputs:
**
-- Executing [agi-test at default:1] AGI("SIP/1223-090046a8", "test.agi")
in new stack
-- Launched AGI Script /var/lib/asterisk/agi-bin/test.agi
-- <SIP/1223-090046a8> Playing 'tt-monkeys' (language 'en')
-- test.agi: We Received 4
-- AGI Script test.agi completed, returning 0

When I press 4 when listening to tt-monkeys.


Hope this helps.

- Dave





More information about the asterisk-users mailing list