问题
I am little new to Asterisk AGI. I am using perl with asterisk agi.
I need to design an IVR solution using Perl asterisk agi.
I have write a little code and it is executing fine.
Perl Code:-
#!/usr/bin/perl -w
use strict;
use warnings;
use Asterisk::AGI;
my $agi = new Asterisk::AGI;
my $option1 = "";
my $option2 = "";
$agi->exec("Read","option1,recording-201503252343,1,,,");
$option2 = $agi->get_variable("$option1");
$agi->exec("NoOp","$option1");
if($option2 == 1)
{
$agi->exec("Playback","hello-world");
$agi->exec("Goto","English,s,1");
}
Asterisk Dialplan:-
exten => 12345,1,Answer()
exten => 12345,2,AGI(agi_new-new.pl)
exten => 12345,n,NoOP(${AGISTATUS})
exten => 12345,n,Hangup()
Actually what i did in the code is that i want a user to dial the extension lead by the IVR in which 2 options are prompted and he has to choose between 2 options when he/she enter the options i want to store that digit into a variable so that i use condition on that variable. I use get_variable to get the variable but when i press the desired option it gets that dtmf input but it is not storing in the variable via the command get_variable.
please i need little help on this.
if anyone could help it will be highly appreciated.
回答1:
$AGI->get_variable() gets variable stored in channel data. Catched DTMF digits don't stored in the data of current channel. For your case you need use $AGI->get_data().
# Wait 3 seconds for press button
my $option1 = $agi->get_data('recording-201503252343',3000,1);
if ($option1 == 1) {
# do something
}
And in your example you have errors. Defined $option1 is empty. You executing command Read with catching DTMF in option1 and next you want get value of $option1 (empty). Either it's a typo in the example in the Read command (option1 instead of $option1) or it is a wrong code, which works as expected.
来源:https://stackoverflow.com/questions/29509316/asterisk-get-variable-in-perl-agi