1
votes

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
I know nothing about asterisk, but Perl interpolates variables in double quotes. Hence, "$option" is the same '' . $option - maybe you want '$option' instead? Single quotes don't interpolate. - choroba
dear still having same output. it not work for me. - Faisal

1 Answers

1
votes

$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.