Added CLI dtmf variable option for agi-dtmf.agi script
git-svn-id: svn://192.168.202.10@2125 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
+69
-50
@@ -1,11 +1,11 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# agi-dtmf.agi - script for playing DTMF tones received as the callerid field
|
||||
# agi-dtmf.agi - script for playing DTMF tones or signals received as the callerid field or in the command CLI
|
||||
#
|
||||
# DTMF sound files must be in /var/lib/asterisk/sounds for this to work
|
||||
#
|
||||
# Accepted values are: 1 2 3 4 5 6 7 8 9 0 # * ,
|
||||
# comma means pause for 1 second
|
||||
# comma means pause for 1 second (use 'S' for pause in CLI mode)
|
||||
#
|
||||
# exten => 8500998,1,Answer
|
||||
# exten => 8500998,2,Playback(silence)
|
||||
@@ -13,13 +13,17 @@
|
||||
#; exten => 8500998,3,AGI(agi-dtmf.agi,signalonly) ; optional signal only DTMF
|
||||
# exten => 8500998,4,Hangup
|
||||
#
|
||||
# Copyright (C) 2009 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
|
||||
# Can also be used in a Call Menu: agi-dtmf.agi,signalonly---12345 # optional signal only DTMF with CLI-defined DTMF values
|
||||
#
|
||||
# Copyright (C) 2014 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
|
||||
#
|
||||
# CHANGES
|
||||
# 90312-1534 - Added signalonly option
|
||||
# 140611-1330 - Added CLI dtmf variable option
|
||||
#
|
||||
|
||||
$signalonly=0;
|
||||
$cli_vars_set=0;
|
||||
### begin parsing run-time options ###
|
||||
if (length($ARGV[0])>1)
|
||||
{
|
||||
@@ -29,10 +33,17 @@ if (length($ARGV[0])>1)
|
||||
$args = "$args $ARGV[$i]";
|
||||
$i++;
|
||||
}
|
||||
|
||||
if ($ARGV[0] =~ /signalonly/)
|
||||
{$signalonly=1;}
|
||||
### list of command-line array arguments:
|
||||
@ARGV_vars = split(/---/, $ARGV[0]);
|
||||
|
||||
$signalonly = $ARGV_vars[0];
|
||||
$cli_vars = $ARGV_vars[1];
|
||||
}
|
||||
if ($signalonly =~ /signalonly/)
|
||||
{$signalonly=1;}
|
||||
if (length($cli_vars) > 0)
|
||||
{$cli_vars_set=1;}
|
||||
|
||||
|
||||
$|=1;
|
||||
while(<STDIN>)
|
||||
@@ -58,7 +69,7 @@ my $agi = new Asterisk::AGI;
|
||||
my $clid = $agi->get_variable('CALLERID');
|
||||
my $clidname = $agi->get_variable('CALLERIDNAME');
|
||||
|
||||
print STDERR "X. |$clid|$caller_id|$clidname|\n";
|
||||
print STDERR "X. |$clid|$caller_id|$clidname| |$signalonly|$cli_vars_set|$cli_vars|\n";
|
||||
|
||||
|
||||
### sleep for 5 tenths of a second
|
||||
@@ -68,49 +79,51 @@ print "STREAM FILE silence \"\"\n";
|
||||
|
||||
$caller_id = "$caller_id$caller_idname";
|
||||
|
||||
if ($cli_vars_set > 0)
|
||||
{$caller_id = $cli_vars;}
|
||||
|
||||
@CALLERID_DIGITS = split(//, $caller_id);
|
||||
|
||||
foreach (@CALLERID_DIGITS)
|
||||
{
|
||||
|
||||
if ($CALLERID_DIGITS[$g] =~ /\d/)
|
||||
{
|
||||
if ($signalonly > 0)
|
||||
{print "EXEC SendDTMF $CALLERID_DIGITS[$g] \"\"\n";}
|
||||
if ($CALLERID_DIGITS[$g] =~ /\d/)
|
||||
{
|
||||
if ($signalonly > 0)
|
||||
{print "EXEC SendDTMF $CALLERID_DIGITS[$g] \"\"\n";}
|
||||
else
|
||||
{print "STREAM FILE $CALLERID_DIGITS[$g] \"\"\n";}
|
||||
print STDERR "DIGIT: $CALLERID_DIGITS[$g]\n";
|
||||
}
|
||||
else
|
||||
{print "STREAM FILE $CALLERID_DIGITS[$g] \"\"\n";}
|
||||
print STDERR "DIGIT: $CALLERID_DIGITS[$g]\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($CALLERID_DIGITS[$g] =~ /\#/)
|
||||
{
|
||||
if ($signalonly > 0)
|
||||
{print "EXEC SendDTMF \# \"\"\n";}
|
||||
else
|
||||
{print "STREAM FILE hash \"\"\n";}
|
||||
if ($CALLERID_DIGITS[$g] =~ /\#/)
|
||||
{
|
||||
if ($signalonly > 0)
|
||||
{print "EXEC SendDTMF \# \"\"\n";}
|
||||
else
|
||||
{print "STREAM FILE hash \"\"\n";}
|
||||
}
|
||||
if ($CALLERID_DIGITS[$g] =~ /\*/)
|
||||
{
|
||||
if ($signalonly > 0)
|
||||
{print "EXEC SendDTMF \* \"\"\n";}
|
||||
else
|
||||
{print "STREAM FILE star \"\"\n";}
|
||||
}
|
||||
if ($CALLERID_DIGITS[$g] =~ /\,|S/)
|
||||
{sleep(1);}
|
||||
print STDERR "NON-DIGIT: $CALLERID_DIGITS[$g]\n";
|
||||
}
|
||||
if ($CALLERID_DIGITS[$g] =~ /\*/)
|
||||
{
|
||||
if ($signalonly > 0)
|
||||
{print "EXEC SendDTMF \* \"\"\n";}
|
||||
else
|
||||
{print "STREAM FILE star \"\"\n";}
|
||||
}
|
||||
if ($CALLERID_DIGITS[$g] =~ /\,/)
|
||||
{sleep(1);}
|
||||
print STDERR "NON-DIGIT: $CALLERID_DIGITS[$g]\n";
|
||||
$g++;
|
||||
|
||||
### sleep for 20 hundredths of a second
|
||||
usleep(1*150*1000);
|
||||
|
||||
print "STREAM FILE silence \"\"\n";
|
||||
|
||||
### sleep for 10 hundredths of a second
|
||||
usleep(1*100*1000);
|
||||
}
|
||||
$g++;
|
||||
|
||||
### sleep for 20 hundredths of a second
|
||||
usleep(1*150*1000);
|
||||
|
||||
print "STREAM FILE silence \"\"\n";
|
||||
|
||||
### sleep for 10 hundredths of a second
|
||||
usleep(1*100*1000);
|
||||
}
|
||||
|
||||
print "STREAM FILE silence \"\"\n";
|
||||
$result = <STDIN>;
|
||||
@@ -118,23 +131,29 @@ checkresult($result);
|
||||
|
||||
exit;
|
||||
|
||||
sub checkresult {
|
||||
sub checkresult
|
||||
{
|
||||
my ($res) = @_;
|
||||
my $retval;
|
||||
$tests++;
|
||||
chomp $res;
|
||||
if ($res =~ /^200/) {
|
||||
if ($res =~ /^200/)
|
||||
{
|
||||
$res =~ /result=(-?\d+)/;
|
||||
if (!length($1)) {
|
||||
if (!length($1))
|
||||
{
|
||||
print STDERR "FAIL ($res)\n";
|
||||
$fail++;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
print STDERR "PASS ($1)\n";
|
||||
$pass++;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print STDERR "FAIL (unexpected result '$res')\n";
|
||||
$fail++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user