将变量从星号拨号方案传递到AGI perl脚本

8xiog9wr  于 2023-02-19  发布在  Perl
关注(0)|答案(2)|浏览(153)

我尝试使用AGI将一个变量从星号拨号计划传递到Perl脚本。我现在对此感到非常困惑,不知道它到底是如何工作的。现在在我的拨号计划中,我有以下内容:

exten=>1122,1,Answer
exten=>1122,n,Read(digit)
exten=>1122,n,agi(/home/steve/Desktop/testperlping.pl,${digit})
exten=>1122,n,Hangup()

我希望用户拨打分机号1122,然后输入一个1 - 10的数字,并使用AGI将输入的数字传递给perl。
我的perl脚本如下所示:

#!/usr/bin/perl -w
$|=1;

use Net::Ping;
use Asterisk::AGI;

$AGI = new Asterisk::AGI;

my %input = $AGI->ReadParse();

***I think I need something here***

$AGI->verbose("$numbertheytypedintophone"); #This will display the entered number back to the CLI.

任何帮助都将不胜感激。

ej83mcc0

ej83mcc01#

我正在使用Asterisk::FastAGI(推荐用于Perl集成),代码如下所示:

my $dst = $self->param('dst');

对于Asterisk::AGI,它已经是(我刚刚阅读AGI.pm源代码):

my $digits=$input{'arg_1'};

我强烈建议你阅读模块的源代码,如果你有任何问题,会快得多。

xwbd5t1u

xwbd5t1u2#

考虑拨号计划的一部分

exten => _X.,1,NoOp(${PJSIP_HEADER(read,To)})
exten => _X.,n,Set(FirstTo=${CUT(PJSIP_HEADER(read,To),:,2)})
exten => _X.,n,Set(TO_DID=${CUT(FirstTo,@,1)})
exten => _X.,n,Set(client_number=${CALLERID(num)})
exten => _X.,n,AGI(check_nr.agi,,${client_number})
exten => _X.,n,Set(First_check=${first_ani})

请注意agi脚本上的双逗号
将使用client_number值的脚本部分

(my $empty_field,  my $data ) = @ARGV;
   my @data_array = split /--/, $data;                  
   my $callerid   = $data_array[0];

如果您有多个参数(如

AGI(check_nr.agi,,${client_number}--${second}--${third})

在这种情况下

(my $empty_field,  my $data ) = @ARGV;
   my @data_array = split /--/, $data;                  
   my $callerid   = $data_array[0]; 
   my $second     = $data_array[1]; 
   my $third      = $data_array[2];

要将变量传递回星号拨号计划,应用途:

print "SET VARIABLE first_ani $first_ani\n";

完整的Perl脚本

#!/usr/bin/perl

# Modules to use
use strict ;
use warnings;
use Config::IniFiles;
use DBI;
use sigtrap;
use sigtrap qw(handler my_handler normal-signals stack-trace error-signals);

                   my $cfg = Config::IniFiles -> new( -file => '/etc/my_file.ini' );
                   my $dbinst = $cfg -> val('AST', 'DBINST');
                   my $dbhost = $cfg -> val('AST', 'DBHOST');
                   my $dbuser = $cfg -> val('AST', 'DBUSER');
                   my $dbpass = $cfg -> val('AST', 'DBPASS');
                   
                   my $dbhA  = DBI->connect( "dbi:mysql:$dbinst:$dbhost",$dbuser,$dbpass, {RaiseError => 0,PrintError => 1,AutoCommit => 0,}) or die $DBI::errstr;     


########################################### Pass data from asterisk channel to perl script ##########################################
  (my $empty_field,  my $data ) = @ARGV;
   my @data_array = split /--/, $data;                  
   my $callerid   = $data_array[0];

########################################### Pass data from asterisk channel to perl script ##########################################

        my $sthA = $dbhA->prepare( "select  ani,
                                            numero,
                                            data_ultima_modifica
                                    from my_table
                                    where numero = ?
                                    ORDER BY data_ultima_modifica DESC "); 
           $sthA->bind_param( 1, $callerid ); 
           $sthA->execute();
        my $sthArows=$sthA->rows;

            if ($sthArows > 0) 
            {
              my @aryA                  = $sthA->fetchrow_array;
              my $ani                   = $aryA[0];
              my $numero                = $aryA[1];
              my $data_ultima_modifica  = $aryA[2];
            
                   print "SET VARIABLE first_ani  $first_ani \n";
             }
            $sthA->finish();    

 
################## Close DB Connection##################
                warn $DBI::errstr if $DBI::err;
                $dbhA->commit(); 
                $dbhA->disconnect();
################## Close DB Connection##################

相关问题