[Asterisk-Users] simple perl-agi - where's the error?

Michael Collins mcollins at fcnetwork.biz
Wed Mar 22 13:01:27 MST 2006


> the DIALSTRING you were given is just an extension, 089324154332.  As
> Lenz pointed out, and it also says in the app_dial.c:773 WARNING, it
> must be technology/number, not just a number.  Not sure perl methods,
> but you might concatenate a technology before the number, something
like
> $res = $AGI->exec("DIAL Local/$dialstring");
> or
> $res = $AGI->exec("DIAL SIP/$dialstring");
> 
> again, I don't know perl, so if that broke something, sorry ;)
> 
> 
> Christian B wrote:
> > Hello!
> >
> > I'm trying to setup a perl-deadagi, but my perl skills lack. can
> > someone tell me why the following code doesn't work:
> >
> > #!/usr/bin/perl
> > use Asterisk::AGI;
> >  $AGI = new Asterisk::AGI;
> >
> > $dialstring = $AGI->get_variable("DIALSTRING");
> > $res = $AGI->exec("DIAL $dialstring");
> >
> >
> > the asterisk output says:
> >
> > AGI Rx << GET VARIABLE DIALSTRING
> > AGI Tx >> 200 result=1 (089324154332)
> > AGI Rx << EXEC DIAL  ""
> >     -- AGI Script Executing Application: (DIAL) Options: ()
> > Mar 20 11:46:02 WARNING[21970]: app_dial.c:773 dial_exec_full: Dial
> > requires an argument (technology/number) AGI Tx >> 200 result=-1
> >     -- AGI Script agirouter/dialscript.pl completed, returning 0
> >
> >
> > so the get_variable-command seems to work, also the exec(with
> > "$dialstring = 089324154332" the call goes out), but not setting the
> > variable. should be so simple :-( astcc-agi seems to use the same
> > syntax, so i have no clue what is wrong in my place...
> > any ideas? thx!
> >
> > kind regards
> > Christian

I believe the problem was that the expected value of $dialstring in the
Perl script wasn't making it back to *.

I would recommend a little debugging:

#!/usr/bin/perl
use Asterisk::AGI;
$AGI = new Asterisk::AGI;

$dialstring = $AGI->get_variable("DIALSTRING");

# Debug here:
print STDERR "\$dialstring contains '$dialstring'\n\n";
# This _should_ print to the console on the Asterisk server

# Note also the minor changes to the arguments for exec method:
$res = $AGI->exec('DIAL', $dialstring);


What you want to do is make absolutely certain that you are getting what
you expect with the $AGI->get_variable("DIALSTRING") call.  If you get
only a phone number then you WILL need to add the technology to the exec
call:

$res = $AGI->exec('DIAL', "ZAP/g1/$dialstring");
-or-
$res = $AGI->exec('DIAL', "SIP/$dialstring");

(Use the technology appropriate for your application.)

Quickie Perl lesson: Putting a variable in double quotes causes
interpolation.  For example, if the variable $dialstring contains a
phone number (e.g. 5595551212) then the command:
$res = $AGI->exec('DIAL', "ZAP/g1/$dialstring");

Becomes the equivalent of:
$res = $AGI->exec('DIAL', "ZAP/g1/5595551212");

HTH,
MC



More information about the asterisk-users mailing list