changed agi-VDADautoREMINDER scripts to use AGI_output setting

git-svn-id: svn://192.168.202.10@189 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
mattf
2006-08-18 16:47:59 +00:00
parent 7be64d8a23
commit 3f9228edf1
2 changed files with 234 additions and 190 deletions
+114 -92
View File
@@ -1,6 +1,6 @@
#!/usr/bin/perl
#
# agi-VDADautoREMINDER.agi version 0.3 *DBI-version*
# agi-VDADautoREMINDER.agi version 0.4 *DBI-version*
#
# runs when a call comes in from the VICIDIAL auto_dialer. This script will
# send the calls out to specified voicemail boxes in if called person presses key.
@@ -28,10 +28,10 @@
# 60313-1626 - First build
# 60810-1729 - Changed to DBI
# - changed to use /etc/astguiclient.conf for configs
# 60818-1144 - added output options check from database
#
$V = 1; # set to 1 for verbose mode
$M = 1; # set to 1 for 2 line messages mode
$script = 'agi-VDADautoREMINDER.agi';
##### AUDIO FILES IN THIS PROGRAM #####
$message_audio_file = 'US_reminder_message';
@@ -41,6 +41,33 @@ $callback_audio_file = 'US_reminder_callback';
$goodbye_audio_file = 'US_reminder_goodbye';
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = ($year + 1900);
$mon++;
if ($mon < 10) {$mon = "0$mon";}
if ($mday < 10) {$mday = "0$mday";}
if ($hour < 10) {$Fhour = "0$hour";}
if ($min < 10) {$min = "0$min";}
if ($sec < 10) {$sec = "0$sec";}
$now_date_epoch = time();
$now_date = "$year-$mon-$mday $hour:$min:$sec";
$start_time=$now_date;
$CIDdate = "$mon$mday$hour$min$sec";
$tsSQLdate = "$year$mon$mday$hour$min$sec"; #20060310100402
$SQLdate = "$year-$mon-$mday $hour:$min:$sec";
$SQLdateBEGIN = $SQLdate;
$BDtarget = ($secX - 5);
($Bsec,$Bmin,$Bhour,$Bmday,$Bmon,$Byear,$Bwday,$Byday,$Bisdst) = localtime($BDtarget);
$Byear = ($Byear + 1900);
$Bmon++;
if ($Bmon < 10) {$Bmon = "0$Bmon";}
if ($Bmday < 10) {$Bmday = "0$Bmday";}
if ($Bhour < 10) {$Bhour = "0$Bhour";}
if ($Bmin < 10) {$Bmin = "0$Bmin";}
if ($Bsec < 10) {$Bsec = "0$Bsec";}
$BDtsSQLdate = "$Byear$Bmon$Bmday$Bhour$Bmin$Bsec";
# default path to astguiclient configuration file:
$PATHconf = '/etc/astguiclient.conf';
@@ -80,55 +107,45 @@ foreach(@conf)
$i++;
}
# Customized Variables
$server_ip = $VARserver_ip; # Asterisk server IP
if (!$VARDB_port) {$VARDB_port='3306';}
if (!$AGILOGfile) {$AGILOGfile = "$PATHlogs/agiout.$year-$mon-$mday";}
use DBI;
use Time::HiRes ('gettimeofday','usleep','sleep'); # necessary to have perl sleep command of less than one second
use Asterisk::AGI;
$AGI = new Asterisk::AGI;
$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
or die "Couldn't connect to database: " . DBI->errstr;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = ($year + 1900);
$mon++;
if ($mon < 10) {$mon = "0$mon";}
if ($mday < 10) {$mday = "0$mday";}
if ($hour < 10) {$Fhour = "0$hour";}
if ($min < 10) {$min = "0$min";}
if ($sec < 10) {$sec = "0$sec";}
$now_date_epoch = time();
$now_date = "$year-$mon-$mday $hour:$min:$sec";
$start_time=$now_date;
$CIDdate = "$mon$mday$hour$min$sec";
$tsSQLdate = "$year$mon$mday$hour$min$sec"; #20060310100402
$SQLdate = "$year-$mon-$mday $hour:$min:$sec";
$SQLdateBEGIN = $SQLdate;
$BDtarget = ($secX - 5);
($Bsec,$Bmin,$Bhour,$Bmday,$Bmon,$Byear,$Bwday,$Byday,$Bisdst) = localtime($BDtarget);
$Byear = ($Byear + 1900);
$Bmon++;
if ($Bmon < 10) {$Bmon = "0$Bmon";}
if ($Bmday < 10) {$Bmday = "0$Bmday";}
if ($Bhour < 10) {$Bhour = "0$Bhour";}
if ($Bmin < 10) {$Bmin = "0$Bmin";}
if ($Bsec < 10) {$Bsec = "0$Bsec";}
$BDtsSQLdate = "$Byear$Bmon$Bmday$Bhour$Bmin$Bsec";
### Grab Server values from the database
$stmtA = "SELECT agi_output FROM servers where server_ip = '$VARserver_ip';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$rec_count=0;
while ($sthArows > $rec_count)
{
$AGILOG = '0';
@aryA = $sthA->fetchrow_array;
$DBagi_output = "$aryA[0]";
if ($DBagi_output =~ /STDERR/) {$AGILOG = '1';}
if ($DBagi_output =~ /FILE/) {$AGILOG = '2';}
if ($DBagi_output =~ /BOTH/) {$AGILOG = '3';}
$rec_count++;
}
$sthA->finish();
### begin parsing run-time options ###
if (length($ARGV[0])>1)
{
if ($V) {print STDERR "Perl Environment Dump:\n";}
if ($AGILOG) {$agi_string = "Perl Environment Dump:"; &agi_output;}
$i=0;
while ($#ARGV >= $i)
{
$args = "$args $ARGV[$i]";
if ($V) {print STDERR "$i|$ARGV[$i]|\n";}
if ($AGILOG) {$agi_string = "$i|$ARGV[$i]"; &agi_output;}
$i++;
}
@@ -162,16 +179,12 @@ if ($V) {print STDERR "Perl Environment Dump:\n";}
}
}
}
else
{
if ($V) {print "no command line options set\n";}
}
$|=1;
while(<STDIN>) {
chomp;
last unless length($_);
if ($V)
if ($AGILOG)
{
if (/^agi_(\w+)\:\s+(.*)$/)
{
@@ -195,8 +208,7 @@ if ( (length($callerid)>20) && ($callerid =~ /\"\S\S\S\S\S\S\S\S\S\S\S\S\S\S\S\S
### set the callerid to the ACQS value(calleridname)
print "SET CALLERID $callerid\n";
checkresult($result);
print STDERR "callerID changed: $callerid\n";
if ($AGILOG) {$agi_string = "callerID changed: $callerid"; &agi_output;}
}
if ( (
(length($calleridname)>5) && ( (!$callerid) or ($callerid =~ /unknown|private|00000000/i) or ($callerid =~ /5551212/) )
@@ -206,37 +218,34 @@ if ( (
### set the callerid to the ACQS value(calleridname)
print "SET CALLERID $callerid\n";
checkresult($result);
print STDERR "callerID changed: $callerid\n";
if ($AGILOG) {$agi_string = "callerID changed: $callerid"; &agi_output;}
}
if ($V)
{
if ($AGILOG) {$agi_string = "AGI Environment Dump:"; &agi_output;}
if ($V) {print STDERR "AGI Environment Dump:\n";}
foreach $i (sort keys %AGI) {
if ($V) {print STDERR " -- $i = $AGI{$i}\n";}
}
foreach $i (sort keys %AGI)
{
if ($AGILOG) {$agi_string = " -- $i = $AGI{$i}"; &agi_output;}
}
if ($AGILOG) {$agi_string = "AGI Variables: |$unique_id|$channel|$extension|$type|$callerid|"; &agi_output;}
$VDADcampaign='';
$VDADphone='';
$VDADphone_code='';
if ($V) {print STDERR "AGI Environment Dump: |$unique_id|$channel|$extension|$type|$callerid|$priority|\n";}
$callerid =~ s/\"//gi;
$CIDlead_id = $callerid;
$CIDlead_id = substr($CIDlead_id, 11, 9);
$CIDlead_id = ($CIDlead_id + 0);
if ($V) {print STDERR "\nCALL RECEIVED IN FROM VDAD: $callerid $channel $priority\n";}
if ($M) {print STDERR "+++++ VDAD START : |$unique_id|$channel|$extension|$type|$callerid|$CIDlead_id|$now_date|$priority|\n";}
if ($AGILOG) {$agi_string = ""+++++ VDAD START : |$CIDlead_id|$now_date|"; &agi_output;}
if ( ($channel =~ /Local/i) && ($AST_ver !~ /^1\.0\.8|^1\.0\.9/) )
{
if ($M) {print STDERR "+++++ VDAD START LOCAL CHANNEL: EXITING- $priority\n";}
if ($AGILOG) {$agi_string = ""+++++ VDAD START LOCAL CHANNEL: EXITING- $priority"; &agi_output;}
if ($priority > 2) {sleep(1);}
exit;
}
@@ -247,11 +256,9 @@ sleep(1);
$AGI->stream_file('beep');
$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
or die "Couldn't connect to database: " . DBI->errstr;
### Grab Server values from the database
$stmtA = "SELECT voicemail_dump_exten,ext_context,answer_transfer_agent,local_gmt,asterisk_version,max_vicidial_trunks FROM servers where server_ip = '$server_ip';";
$stmtA = "SELECT voicemail_dump_exten,ext_context,answer_transfer_agent,local_gmt,asterisk_version,max_vicidial_trunks FROM servers where server_ip = '$VARserver_ip';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
@@ -278,7 +285,7 @@ $sthA->finish();
### Grab call parameters from vicidial_auto_calls table
$stmtA = "UPDATE vicidial_auto_calls set uniqueid='$unique_id', channel='$channel',status='LIVE' where callerid='$callerid' order by call_time desc limit 1;";
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD : |$affected_rows|update of vac table: $callerid\n|$stmtA|\n";}
if ($AGILOG) {$agi_string = "-- VDAD : |$affected_rows|update of vac table: $callerid\n|$stmtA|"; &agi_output;}
if ($affected_rows > 0)
{
$stmtA = "SELECT campaign_id,phone_number,phone_code,lead_id,call_time FROM vicidial_auto_calls where callerid='$callerid' order by call_time desc limit 1;";
@@ -299,11 +306,10 @@ if ($affected_rows > 0)
$sthA->finish();
$stmtA = "INSERT INTO vicidial_log (uniqueid,lead_id,campaign_id,call_date,start_epoch,status,phone_code,phone_number,user,processed) values('$uniqueid','$CIDlead_id','$VDADcampaign','$SQLdate','$now_date_epoch','N','$VDADphone_code','$VDADphone','VDAD','N')";
if($M){print STDERR "\n|$stmtA|\n";}
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD : |$VDADlead_id|$CIDlead_id|insert to vicidial_log: $uniqueid\n";}
if ($AGILOG) {$agi_string = "-- VDAD : |$VDADlead_id|$CIDlead_id|insert to vicidial_log: $uniqueid"; &agi_output;}
}
@@ -322,20 +328,20 @@ if ($pin < 1)
$stmtA = "DELETE FROM vicidial_auto_calls where callerid='$callerid' order by call_time desc limit 1;";
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD vac record deleted: |$affected_rows| $VDADcampaign|$server_ip\n";}
if ($AGILOG) {$agi_string = "-- VDAD vac record deleted: |$affected_rows|$VDADcampaign|"; &agi_output;}
$end_date_epoch = time();
$length_in_sec = ($end_date_epoch - $now_date_epoch);
$stmtA = "UPDATE vicidial_log set end_epoch='$end_date_epoch', length_in_sec='$length_in_sec' where uniqueid='$uniqueid' and lead_id='$CIDlead_id';";
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD vac record deleted: |$affected_rows| $VDADcampaign|$server_ip|$end_date_epoch|$now_date_epoch|$length_in_sec|\n";}
if ($AGILOG) {$agi_string = "-- VDAD vac record deleted: |$affected_rows|$VDADcampaign|$end_date_epoch|$now_date_epoch|$length_in_sec|"; &agi_output;}
$VHqueryCID = "VHNGUP$tsSQLdate";
### insert a NEW record to the vicidial_manager table to be processed
$stmtA = "INSERT INTO vicidial_manager values('','','$SQLdate','NEW','N','$server_ip','','Hangup','$VHqueryCID','Channel: $channel','','','','','','','','','')";
$stmtA = "INSERT INTO vicidial_manager values('','','$SQLdate','NEW','N','$VARserver_ip','','Hangup','$VHqueryCID','Channel: $channel','','','','','','','','','')";
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD call_hungup timout: |$VHqueryCID|$VDADconf_exten|$channel|insert to vicidial_manager\n";}
if ($AGILOG) {$agi_string = "-- VDAD call_hungup timout: |$VHqueryCID|$VDADconf_exten|$channel|insert to vicidial_manager"; &agi_output;}
sleep(1);
@@ -343,7 +349,7 @@ if ($pin < 1)
}
}
if ($V) {print STDERR "+++++ VDAD STATUS : pressed $pin|$unique_id|$channel|$extension|$type|$callerid|$CIDlead_id|$now_date\n";}
if ($AGILOG) {$agi_string = "+++++ VDAD STATUS : pressed $pin|$unique_id|$channel|$extension|$type|$callerid|$CIDlead_id|$now_date"; &agi_output;}
if ($pin !~ /^1|^2/) {exit;}
@@ -364,12 +370,12 @@ if ($pin == "1") ### send call to voicemail
$stmtA = "UPDATE vicidial_auto_calls set status='XFER' where callerid='$callerid';";
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD XFER : |$affected_rows|update of vac table: $callerid\n|$stmtA|\n";}
if ($AGILOG) {$agi_string = "-- VDAD XFER : |$affected_rows|update of vac table: $callerid\n|$stmtA|"; &agi_output;}
$stmtA = "UPDATE vicidial_list set status='VM' where lead_id = '$CIDlead_id';";
if($M){print STDERR "\n\n|$stmtA|\n";}
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD vicidial_list update: |$affected_rows|$CIDlead_id|XFER\n";}
if ($AGILOG) {$agi_string = "-- VDAD vicidial_list update: |$affected_rows|$CIDlead_id|XFER"; &agi_output;}
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = ($year + 1900);
@@ -383,11 +389,11 @@ if ($pin == "1") ### send call to voicemail
$end_date_epoch = time();
$length_in_sec = ($end_date_epoch - $now_date_epoch);
$now_date = "$year-$mon-$mday $hour:$min:$sec";
print STDERR "\nXXXXXXXXXX VDAD transferred: start|stop $start_time|$now_date\n";
if ($AGILOG) {$agi_string = "XXXXXXXXXX VDAD transferred: start|stop $start_time|$now_date"; &agi_output;}
$stmtA = "UPDATE vicidial_log set status='VM', end_epoch='$end_date_epoch', length_in_sec='$length_in_sec' where uniqueid='$uniqueid' and lead_id='$CIDlead_id';";
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD vac record updated: |$affected_rows| $VDADcampaign|$server_ip\n";}
if ($AGILOG) {$agi_string = "-- VDAD vac record updated: |$affected_rows|$VDADcampaign|"; &agi_output;}
$VMAIL_box=0;
### Grab Server values from the database
@@ -405,7 +411,7 @@ if ($pin == "1") ### send call to voicemail
$sthA->finish();
### SEND CALL TO VOICEMAIL BOX ###
print STDERR "\nexiting the VDAD app, transferring call to $voicemail_dump_exten$VMAIL_box\n";
if ($AGILOG) {$agi_string = "exiting the VDAD app, transferring call to $voicemail_dump_exten$VMAIL_box"; &agi_output;}
print "SET CONTEXT $ext_context\n";
checkresult($result);
print "SET EXTENSION $voicemail_dump_exten$VMAIL_box\n";
@@ -422,12 +428,12 @@ if ($pin == "2") ### mark call as a CALLBK
# Thank you for your response, your agent will be contacting you shortly.
$stmtA = "DELETE from vicidial_auto_calls where callerid='$callerid';";
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD DONE : |$affected_rows|delete of vac table: $callerid\n|$stmtA|\n";}
if ($AGILOG) {$agi_string = "-- VDAD DONE : |$affected_rows|delete of vac table: $callerid\n|$stmtA|"; &agi_output;}
$stmtA = "UPDATE vicidial_list set status='CALLBK' where lead_id = '$CIDlead_id';";
if($M){print STDERR "\n\n|$stmtA|\n";}
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD vicidial_list update: |$affected_rows|$CIDlead_id|XFER\n";}
if ($AGILOG) {$agi_string = "-- VDAD vicidial_list update: |$affected_rows|$CIDlead_id|XFER"; &agi_output;}
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = ($year + 1900);
@@ -441,19 +447,19 @@ if ($pin == "2") ### mark call as a CALLBK
$end_date_epoch = time();
$length_in_sec = ($end_date_epoch - $now_date_epoch);
$now_date = "$year-$mon-$mday $hour:$min:$sec";
print STDERR "\nXXXXXXXXXX VDAD transferred: start|stop $start_time|$now_date\n";
if ($AGILOG) {$agi_string = "XXXXXXXXXX VDAD transferred: start|stop $start_time|$now_date"; &agi_output;}
$stmtA = "UPDATE vicidial_log set status='CALLBK', end_epoch='$end_date_epoch', length_in_sec='$length_in_sec' where uniqueid='$uniqueid' and lead_id='$CIDlead_id';";
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD vac record updated: |$affected_rows| $VDADcampaign|$server_ip\n";}
if ($AGILOG) {$agi_string = "-- VDAD vac record updated: |$affected_rows|$VDADcampaign|"; &agi_output;}
$AGI->stream_file("$callback_audio_file");
$VHqueryCID = "VHNGUP$tsSQLdate";
### insert a NEW record to the vicidial_manager table to be processed
$stmtA = "INSERT INTO vicidial_manager values('','','$SQLdate','NEW','N','$server_ip','','Hangup','$VHqueryCID','Channel: $channel','','','','','','','','','')";
$stmtA = "INSERT INTO vicidial_manager values('','','$SQLdate','NEW','N','$VARserver_ip','','Hangup','$VHqueryCID','Channel: $channel','','','','','','','','','')";
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD call_hungup timout: |$VHqueryCID|$VDADconf_exten|$channel|insert to vicidial_manager\n";}
if ($AGILOG) {$agi_string = "-- VDAD call_hungup timout: |$VHqueryCID|$VDADconf_exten|$channel|insert to vicidial_manager"; &agi_output;}
sleep(1);
@@ -505,7 +511,7 @@ undef $interrupt_digit;
######### PLAY THE MESSAGE FILE THEN WAIT 2 SECONDS FOR DIGITS ############
$interrupt_digit = $AGI->stream_file("$message_audio_file",'12');
print STDERR "interrupt_digit |$interrupt_digit|\n";
if ($AGILOG) {$agi_string = "interrupt_digit |$interrupt_digit|"; &agi_output;}
$digits_being_entered=1;
$digit_loop_counter=0;
$totalDTMF='';
@@ -526,19 +532,19 @@ if ($interrupt_digit > 1)
}
$channel_status = $AGI->channel_status("$channel");
if ($V) {print STDERR "SSSSSSSSSS Channel Status: $channel_status\n";}
if ($AGILOG) {$agi_string = "SSSSSSSSSS Channel Status: $channel_status"; &agi_output;}
if ($channel_status == 6)
{
$stmtA = "UPDATE vicidial_log set status='MP' where uniqueid = '$uniqueid' and lead_id='$CIDlead_id';";
if($M){print STDERR "\n\n|$stmtA|\n";}
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD vicidial_log update: N|$affected_rows|$uniqueid\n";}
if ($AGILOG) {$agi_string = "-- VDAD vicidial_log update: N|$affected_rows|$uniqueid"; &agi_output;}
$stmtA = "UPDATE vicidial_list set status='MP' where lead_id = '$CIDlead_id';";
if($M){print STDERR "\n\n|$stmtA|\n";}
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD vicidial_list update: N|$affected_rows|$CIDlead_id\n";}
if ($AGILOG) {$agi_string = "-- VDAD vicidial_list update: N|$affected_rows|$CIDlead_id"; &agi_output;}
}
while ($digit_loop_counter < 1)
@@ -547,7 +553,7 @@ while ($digit_loop_counter < 1)
if ($digit =~ /\d/)
{
$totalDTMF = "$totalDTMF$digit";
print STDERR "digit |$digit| TotalDTMF |$totalDTMF|\n";
if ($AGILOG) {$agi_string = "digit |$digit| TotalDTMF |$totalDTMF|"; &agi_output;}
# $AGI->say_digits("$digit");
undef $digit;
}
@@ -563,7 +569,7 @@ $totalDTMF =~ s/\D//gi;
$pin = $totalDTMF;
if ($totalDTMF)
{
print STDERR "digit |$digit| TotalDTMF |$totalDTMF|\n";
if ($AGILOG) {$agi_string = "digit |$digit| TotalDTMF |$totalDTMF|"; &agi_output;}
return;
}
@@ -571,7 +577,7 @@ if ($totalDTMF)
######### PLAY THE OPTIONS FILE THEN WAIT 5 SECONDS FOR DIGITS ############
$interrupt_digit = $AGI->stream_file("$options_audio_file",'12');
print STDERR "interrupt_digit |$interrupt_digit|\n";
if ($AGILOG) {$agi_string = "interrupt_digit |$interrupt_digit|"; &agi_output;}
$digits_being_entered=1;
$digit_loop_counter=0;
$totalDTMF='';
@@ -597,7 +603,7 @@ while ($digit_loop_counter < 1)
if ($digit =~ /\d/)
{
$totalDTMF = "$totalDTMF$digit";
print STDERR "digit |$digit| TotalDTMF |$totalDTMF|\n";
if ($AGILOG) {$agi_string = "digit |$digit| TotalDTMF |$totalDTMF|"; &agi_output;}
# $AGI->say_digits("$digit");
undef $digit;
}
@@ -613,7 +619,7 @@ $totalDTMF =~ s/\D//gi;
$pin = $totalDTMF;
if ($totalDTMF)
{
print STDERR "digit |$digit| TotalDTMF |$totalDTMF|\n";
if ($AGILOG) {$agi_string = "digit |$digit| TotalDTMF |$totalDTMF|"; &agi_output;}
return;
}
}
@@ -636,10 +642,26 @@ sub checkresult {
$pass++;
}
} else {
print STDERR "FAIL (unexpected result '$res')\n";
# print STDERR "FAIL (unexpected result '$res')\n";
$fail++;
}
}
sub agi_output
{
if ($AGILOG >=2)
{
### open the log file for writing ###
open(Lout, ">>$AGILOGfile")
|| die "Can't open $AGILOGfile: $!\n";
print Lout "$now_date|$script|$agi_string\n";
close(Lout);
}
### send to STDERR writing ###
if ( ($AGILOG == '1') || ($AGILOG == '3') )
{print STDERR "$now_date|$script|$agi_string\n";}
$agi_string='';
}
+120 -98
View File
@@ -1,6 +1,6 @@
#!/usr/bin/perl
#
# agi-VDADautoREMINDERxfer.agi version 0.2 *DBI-version*
# agi-VDADautoREMINDERxfer.agi version 0.3 *DBI-version*
#
# runs when a call comes in from the VICIDIAL auto_dialer. This script will
# send the calls out to specified voicemail boxes or specified extensions if
@@ -30,10 +30,10 @@
# 60511-1214 - First build
# 60810-1729 - Changed to DBI
# - changed to use /etc/astguiclient.conf for configs
# 60818-1144 - added output options check from database
#
$V = 1; # set to 1 for verbose mode
$M = 1; # set to 1 for 2 line messages mode
$script = 'agi-VDADautoREMINDERxfer.agi';
##### AUDIO FILES IN THIS PROGRAM #####
$message_audio_file = 'US_reminder_message';
@@ -43,6 +43,33 @@ $callback_audio_file = 'US_reminder_callback';
$goodbye_audio_file = 'US_reminder_goodbye';
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = ($year + 1900);
$mon++;
if ($mon < 10) {$mon = "0$mon";}
if ($mday < 10) {$mday = "0$mday";}
if ($hour < 10) {$Fhour = "0$hour";}
if ($min < 10) {$min = "0$min";}
if ($sec < 10) {$sec = "0$sec";}
$now_date_epoch = time();
$now_date = "$year-$mon-$mday $hour:$min:$sec";
$start_time=$now_date;
$CIDdate = "$mon$mday$hour$min$sec";
$tsSQLdate = "$year$mon$mday$hour$min$sec"; #20060310100402
$SQLdate = "$year-$mon-$mday $hour:$min:$sec";
$SQLdateBEGIN = $SQLdate;
$BDtarget = ($secX - 5);
($Bsec,$Bmin,$Bhour,$Bmday,$Bmon,$Byear,$Bwday,$Byday,$Bisdst) = localtime($BDtarget);
$Byear = ($Byear + 1900);
$Bmon++;
if ($Bmon < 10) {$Bmon = "0$Bmon";}
if ($Bmday < 10) {$Bmday = "0$Bmday";}
if ($Bhour < 10) {$Bhour = "0$Bhour";}
if ($Bmin < 10) {$Bmin = "0$Bmin";}
if ($Bsec < 10) {$Bsec = "0$Bsec";}
$BDtsSQLdate = "$Byear$Bmon$Bmday$Bhour$Bmin$Bsec";
# default path to astguiclient configuration file:
$PATHconf = '/etc/astguiclient.conf';
@@ -82,55 +109,45 @@ foreach(@conf)
$i++;
}
# Customized Variables
$server_ip = $VARserver_ip; # Asterisk server IP
if (!$VARDB_port) {$VARDB_port='3306';}
if (!$AGILOGfile) {$AGILOGfile = "$PATHlogs/agiout.$year-$mon-$mday";}
use DBI;
use Time::HiRes ('gettimeofday','usleep','sleep'); # necessary to have perl sleep command of less than one second
use Asterisk::AGI;
$AGI = new Asterisk::AGI;
$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
or die "Couldn't connect to database: " . DBI->errstr;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = ($year + 1900);
$mon++;
if ($mon < 10) {$mon = "0$mon";}
if ($mday < 10) {$mday = "0$mday";}
if ($hour < 10) {$Fhour = "0$hour";}
if ($min < 10) {$min = "0$min";}
if ($sec < 10) {$sec = "0$sec";}
$now_date_epoch = time();
$now_date = "$year-$mon-$mday $hour:$min:$sec";
$start_time=$now_date;
$CIDdate = "$mon$mday$hour$min$sec";
$tsSQLdate = "$year$mon$mday$hour$min$sec"; #20060310100402
$SQLdate = "$year-$mon-$mday $hour:$min:$sec";
$SQLdateBEGIN = $SQLdate;
$BDtarget = ($secX - 5);
($Bsec,$Bmin,$Bhour,$Bmday,$Bmon,$Byear,$Bwday,$Byday,$Bisdst) = localtime($BDtarget);
$Byear = ($Byear + 1900);
$Bmon++;
if ($Bmon < 10) {$Bmon = "0$Bmon";}
if ($Bmday < 10) {$Bmday = "0$Bmday";}
if ($Bhour < 10) {$Bhour = "0$Bhour";}
if ($Bmin < 10) {$Bmin = "0$Bmin";}
if ($Bsec < 10) {$Bsec = "0$Bsec";}
$BDtsSQLdate = "$Byear$Bmon$Bmday$Bhour$Bmin$Bsec";
### Grab Server values from the database
$stmtA = "SELECT agi_output FROM servers where server_ip = '$VARserver_ip';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$rec_count=0;
while ($sthArows > $rec_count)
{
$AGILOG = '0';
@aryA = $sthA->fetchrow_array;
$DBagi_output = "$aryA[0]";
if ($DBagi_output =~ /STDERR/) {$AGILOG = '1';}
if ($DBagi_output =~ /FILE/) {$AGILOG = '2';}
if ($DBagi_output =~ /BOTH/) {$AGILOG = '3';}
$rec_count++;
}
$sthA->finish();
### begin parsing run-time options ###
if (length($ARGV[0])>1)
{
if ($V) {print STDERR "Perl Environment Dump:\n";}
if ($AGILOG) {$agi_string = "Perl Environment Dump:"; &agi_output;}
$i=0;
while ($#ARGV >= $i)
{
$args = "$args $ARGV[$i]";
if ($V) {print STDERR "$i|$ARGV[$i]|\n";}
if ($AGILOG) {$agi_string = "$i|$ARGV[$i]"; &agi_output;}
$i++;
}
@@ -164,16 +181,12 @@ if ($V) {print STDERR "Perl Environment Dump:\n";}
}
}
}
else
{
if ($V) {print "no command line options set\n";}
}
$|=1;
while(<STDIN>) {
chomp;
last unless length($_);
if ($V)
if ($AGILOG)
{
if (/^agi_(\w+)\:\s+(.*)$/)
{
@@ -197,8 +210,7 @@ if ( (length($callerid)>20) && ($callerid =~ /\"\S\S\S\S\S\S\S\S\S\S\S\S\S\S\S\S
### set the callerid to the ACQS value(calleridname)
print "SET CALLERID $callerid\n";
checkresult($result);
print STDERR "callerID changed: $callerid\n";
if ($AGILOG) {$agi_string = "callerID changed: $callerid"; &agi_output;}
}
if ( (
(length($calleridname)>5) && ( (!$callerid) or ($callerid =~ /unknown|private|00000000/i) or ($callerid =~ /5551212/) )
@@ -208,37 +220,34 @@ if ( (
### set the callerid to the ACQS value(calleridname)
print "SET CALLERID $callerid\n";
checkresult($result);
print STDERR "callerID changed: $callerid\n";
if ($AGILOG) {$agi_string = "callerID changed: $callerid"; &agi_output;}
}
if ($V)
{
if ($AGILOG) {$agi_string = "AGI Environment Dump:"; &agi_output;}
if ($V) {print STDERR "AGI Environment Dump:\n";}
foreach $i (sort keys %AGI) {
if ($V) {print STDERR " -- $i = $AGI{$i}\n";}
}
foreach $i (sort keys %AGI)
{
if ($AGILOG) {$agi_string = " -- $i = $AGI{$i}"; &agi_output;}
}
if ($AGILOG) {$agi_string = "AGI Variables: |$unique_id|$channel|$extension|$type|$callerid|"; &agi_output;}
$VDADcampaign='';
$VDADphone='';
$VDADphone_code='';
if ($V) {print STDERR "AGI Environment Dump: |$unique_id|$channel|$extension|$type|$callerid|$priority|\n";}
$callerid =~ s/\"//gi;
$CIDlead_id = $callerid;
$CIDlead_id = substr($CIDlead_id, 11, 9);
$CIDlead_id = ($CIDlead_id + 0);
if ($V) {print STDERR "\nCALL RECEIVED IN FROM VDAD: $callerid $channel $priority\n";}
if ($M) {print STDERR "+++++ VDAD START : |$unique_id|$channel|$extension|$type|$callerid|$CIDlead_id|$now_date|$priority|\n";}
if ($AGILOG) {$agi_string = ""+++++ VDAD START : |$CIDlead_id|$now_date|"; &agi_output;}
if ( ($channel =~ /Local/i) && ($AST_ver !~ /^1\.0\.8|^1\.0\.9/) )
{
if ($M) {print STDERR "+++++ VDAD START LOCAL CHANNEL: EXITING- $priority\n";}
if ($AGILOG) {$agi_string = ""+++++ VDAD START LOCAL CHANNEL: EXITING- $priority"; &agi_output;}
if ($priority > 2) {sleep(1);}
exit;
}
@@ -249,11 +258,9 @@ sleep(1);
$AGI->stream_file('beep');
$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
or die "Couldn't connect to database: " . DBI->errstr;
### Grab Server values from the database
$stmtA = "SELECT voicemail_dump_exten,ext_context,answer_transfer_agent,local_gmt,asterisk_version,max_vicidial_trunks FROM servers where server_ip = '$server_ip';";
$stmtA = "SELECT voicemail_dump_exten,ext_context,answer_transfer_agent,local_gmt,asterisk_version,max_vicidial_trunks FROM servers where server_ip = '$VARserver_ip';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
@@ -280,7 +287,7 @@ $sthA->finish();
### Grab call parameters from vicidial_auto_calls table
$stmtA = "UPDATE vicidial_auto_calls set uniqueid='$unique_id', channel='$channel',status='LIVE' where callerid='$callerid' order by call_time desc limit 1;";
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD : |$affected_rows|update of vac table: $callerid\n|$stmtA|\n";}
if ($AGILOG) {$agi_string = "-- VDAD : |$affected_rows|update of vac table: $callerid\n|$stmtA|"; &agi_output;}
if ($affected_rows > 0)
{
$stmtA = "SELECT campaign_id,phone_number,phone_code,lead_id,call_time FROM vicidial_auto_calls where callerid='$callerid' order by call_time desc limit 1;";
@@ -301,11 +308,10 @@ if ($affected_rows > 0)
$sthA->finish();
$stmtA = "INSERT INTO vicidial_log (uniqueid,lead_id,campaign_id,call_date,start_epoch,status,phone_code,phone_number,user,processed) values('$uniqueid','$CIDlead_id','$VDADcampaign','$SQLdate','$now_date_epoch','N','$VDADphone_code','$VDADphone','VDAD','N')";
if($M){print STDERR "\n|$stmtA|\n";}
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD : |$VDADlead_id|$CIDlead_id|insert to vicidial_log: $uniqueid\n";}
if ($AGILOG) {$agi_string = "-- VDAD : |$VDADlead_id|$CIDlead_id|insert to vicidial_log: $uniqueid"; &agi_output;}
}
@@ -324,20 +330,20 @@ if ($pin < 1)
$stmtA = "DELETE FROM vicidial_auto_calls where callerid='$callerid' order by call_time desc limit 1;";
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD vac record deleted: |$affected_rows| $VDADcampaign|$server_ip\n";}
if ($AGILOG) {$agi_string = "-- VDAD vac record deleted: |$affected_rows|$VDADcampaign|"; &agi_output;}
$end_date_epoch = time();
$length_in_sec = ($end_date_epoch - $now_date_epoch);
$stmtA = "UPDATE vicidial_log set end_epoch='$end_date_epoch', length_in_sec='$length_in_sec' where uniqueid='$uniqueid' and lead_id='$CIDlead_id';";
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD vac record deleted: |$affected_rows| $VDADcampaign|$server_ip|$end_date_epoch|$now_date_epoch|$length_in_sec|\n";}
if ($AGILOG) {$agi_string = "-- VDAD vac record deleted: |$affected_rows|$VDADcampaign|$end_date_epoch|$now_date_epoch|$length_in_sec|"; &agi_output;}
$VHqueryCID = "VHNGUP$tsSQLdate";
### insert a NEW record to the vicidial_manager table to be processed
$stmtA = "INSERT INTO vicidial_manager values('','','$SQLdate','NEW','N','$server_ip','','Hangup','$VHqueryCID','Channel: $channel','','','','','','','','','')";
$stmtA = "INSERT INTO vicidial_manager values('','','$SQLdate','NEW','N','$VARserver_ip','','Hangup','$VHqueryCID','Channel: $channel','','','','','','','','','')";
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD call_hungup timout: |$VHqueryCID|$VDADconf_exten|$channel|insert to vicidial_manager\n";}
if ($AGILOG) {$agi_string = "-- VDAD call_hungup timout: |$VHqueryCID|$VDADconf_exten|$channel|insert to vicidial_manager"; &agi_output;}
sleep(1);
@@ -345,7 +351,7 @@ if ($pin < 1)
}
}
if ($V) {print STDERR "+++++ VDAD STATUS : pressed $pin|$unique_id|$channel|$extension|$type|$callerid|$CIDlead_id|$now_date\n";}
if ($AGILOG) {$agi_string = "+++++ VDAD STATUS : pressed $pin|$unique_id|$channel|$extension|$type|$callerid|$CIDlead_id|$now_date"; &agi_output;}
if ($pin !~ /^1|^2|^3/) {exit;}
@@ -366,12 +372,12 @@ if ($pin == "1") ### send call to voicemail
$stmtA = "UPDATE vicidial_auto_calls set status='XFER' where callerid='$callerid';";
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD XFER : |$affected_rows|update of vac table: $callerid\n|$stmtA|\n";}
if ($AGILOG) {$agi_string = "-- VDAD XFER : |$affected_rows|update of vac table: $callerid\n|$stmtA|"; &agi_output;}
$stmtA = "UPDATE vicidial_list set status='VM' where lead_id = '$CIDlead_id';";
if($M){print STDERR "\n\n|$stmtA|\n";}
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD vicidial_list update: |$affected_rows|$CIDlead_id|XFER\n";}
if ($AGILOG) {$agi_string = "-- VDAD vicidial_list update: |$affected_rows|$CIDlead_id|XFER"; &agi_output;}
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = ($year + 1900);
@@ -385,11 +391,11 @@ if ($pin == "1") ### send call to voicemail
$end_date_epoch = time();
$length_in_sec = ($end_date_epoch - $now_date_epoch);
$now_date = "$year-$mon-$mday $hour:$min:$sec";
print STDERR "\nXXXXXXXXXX VDAD transferred: start|stop $start_time|$now_date\n";
if ($AGILOG) {$agi_string = "XXXXXXXXXX VDAD transferred: start|stop $start_time|$now_date"; &agi_output;}
$stmtA = "UPDATE vicidial_log set status='VM', end_epoch='$end_date_epoch', length_in_sec='$length_in_sec' where uniqueid='$uniqueid' and lead_id='$CIDlead_id';";
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD vac record updated: |$affected_rows| $VDADcampaign|$server_ip\n";}
if ($AGILOG) {$agi_string = "-- VDAD vac record updated: |$affected_rows|$VDADcampaign|"; &agi_output;}
$VMAIL_box=0;
### Grab Server values from the database
@@ -407,7 +413,7 @@ if ($pin == "1") ### send call to voicemail
$sthA->finish();
### SEND CALL TO VOICEMAIL BOX ###
print STDERR "\nexiting the VDAD app, transferring call to $voicemail_dump_exten$VMAIL_box\n";
if ($AGILOG) {$agi_string = "exiting the VDAD app, transferring call to $voicemail_dump_exten$VMAIL_box"; &agi_output;}
print "SET CONTEXT $ext_context\n";
checkresult($result);
print "SET EXTENSION $voicemail_dump_exten$VMAIL_box\n";
@@ -424,12 +430,12 @@ if ($pin == "2") ### mark call as a CALLBK
# Thank you for your response, your agent will be contacting you shortly.
$stmtA = "DELETE from vicidial_auto_calls where callerid='$callerid';";
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD DONE : |$affected_rows|delete of vac table: $callerid\n|$stmtA|\n";}
if ($AGILOG) {$agi_string = "-- VDAD DONE : |$affected_rows|delete of vac table: $callerid\n|$stmtA|"; &agi_output;}
$stmtA = "UPDATE vicidial_list set status='CALLBK' where lead_id = '$CIDlead_id';";
if($M){print STDERR "\n\n|$stmtA|\n";}
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD vicidial_list update: |$affected_rows|$CIDlead_id|XFER\n";}
if ($AGILOG) {$agi_string = "-- VDAD vicidial_list update: |$affected_rows|$CIDlead_id|XFER"; &agi_output;}
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = ($year + 1900);
@@ -443,19 +449,19 @@ if ($pin == "2") ### mark call as a CALLBK
$end_date_epoch = time();
$length_in_sec = ($end_date_epoch - $now_date_epoch);
$now_date = "$year-$mon-$mday $hour:$min:$sec";
print STDERR "\nXXXXXXXXXX VDAD transferred: start|stop $start_time|$now_date\n";
if ($AGILOG) {$agi_string = "XXXXXXXXXX VDAD transferred: start|stop $start_time|$now_date"; &agi_output;}
$stmtA = "UPDATE vicidial_log set status='CALLBK', end_epoch='$end_date_epoch', length_in_sec='$length_in_sec' where uniqueid='$uniqueid' and lead_id='$CIDlead_id';";
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD vac record updated: |$affected_rows| $VDADcampaign|$server_ip\n";}
if ($AGILOG) {$agi_string = "-- VDAD vac record updated: |$affected_rows|$VDADcampaign|"; &agi_output;}
$AGI->stream_file("$callback_audio_file");
$VHqueryCID = "VHNGUP$tsSQLdate";
### insert a NEW record to the vicidial_manager table to be processed
$stmtA = "INSERT INTO vicidial_manager values('','','$SQLdate','NEW','N','$server_ip','','Hangup','$VHqueryCID','Channel: $channel','','','','','','','','','')";
$stmtA = "INSERT INTO vicidial_manager values('','','$SQLdate','NEW','N','$VARserver_ip','','Hangup','$VHqueryCID','Channel: $channel','','','','','','','','','')";
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD call_hungup timout: |$VHqueryCID|$VDADconf_exten|$channel|insert to vicidial_manager\n";}
if ($AGILOG) {$agi_string = "-- VDAD call_hungup timout: |$VHqueryCID|$VDADconf_exten|$channel|insert to vicidial_manager"; &agi_output;}
sleep(1);
@@ -470,12 +476,12 @@ if ($pin == "3") ### send call to extension
$stmtA = "UPDATE vicidial_auto_calls set status='XFER' where callerid='$callerid';";
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD XFER : |$affected_rows|update of vac table: $callerid\n|$stmtA|\n";}
if ($AGILOG) {$agi_string = "-- VDAD XFER : |$affected_rows|update of vac table: $callerid\n|$stmtA|"; &agi_output;}
$stmtA = "UPDATE vicidial_list set status='XFER' where lead_id = '$CIDlead_id';";
if($M){print STDERR "\n\n|$stmtA|\n";}
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD vicidial_list update: |$affected_rows|$CIDlead_id|XFER\n";}
if ($AGILOG) {$agi_string = "-- VDAD vicidial_list update: |$affected_rows|$CIDlead_id|XFER"; &agi_output;}
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = ($year + 1900);
@@ -489,11 +495,11 @@ if ($pin == "3") ### send call to extension
$end_date_epoch = time();
$length_in_sec = ($end_date_epoch - $now_date_epoch);
$now_date = "$year-$mon-$mday $hour:$min:$sec";
print STDERR "\nXXXXXXXXXX VDAD transferred: start|stop $start_time|$now_date\n";
if ($AGILOG) {$agi_string = "XXXXXXXXXX VDAD transferred: start|stop $start_time|$now_date"; &agi_output;}
$stmtA = "UPDATE vicidial_log set status='XFER', end_epoch='$end_date_epoch', length_in_sec='$length_in_sec' where uniqueid='$uniqueid' and lead_id='$CIDlead_id';";
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD vac record updated: |$affected_rows| $VDADcampaign|$server_ip\n";}
if ($AGILOG) {$agi_string = "-- VDAD vac record updated: |$affected_rows|$VDADcampaign|"; &agi_output;}
$VMAIL_box=0;
### Grab Server values from the database
@@ -511,7 +517,7 @@ if ($pin == "3") ### send call to extension
$sthA->finish();
### SEND CALL TO VOICEMAIL BOX ###
print STDERR "\nexiting the VDAD app, transferring call to $XFER_exten\n";
if ($AGILOG) {$agi_string = "exiting the VDAD app, transferring call to $XFER_exten"; &agi_output;}
print "SET CONTEXT $ext_context\n";
checkresult($result);
print "SET EXTENSION $XFER_exten\n";
@@ -567,7 +573,7 @@ undef $interrupt_digit;
######### PLAY THE MESSAGE FILE THEN WAIT 2 SECONDS FOR DIGITS ############
$interrupt_digit = $AGI->stream_file("$message_audio_file",'123');
print STDERR "interrupt_digit |$interrupt_digit|\n";
if ($AGILOG) {$agi_string = "interrupt_digit |$interrupt_digit|"; &agi_output;}
$digits_being_entered=1;
$digit_loop_counter=0;
$totalDTMF='';
@@ -588,19 +594,19 @@ if ($interrupt_digit > 1)
}
$channel_status = $AGI->channel_status("$channel");
if ($V) {print STDERR "SSSSSSSSSS Channel Status: $channel_status\n";}
if ($AGILOG) {$agi_string = "SSSSSSSSSS Channel Status: $channel_status"; &agi_output;}
if ($channel_status == 6)
{
$stmtA = "UPDATE vicidial_log set status='MP' where uniqueid = '$uniqueid' and lead_id='$CIDlead_id';";
if($M){print STDERR "\n\n|$stmtA|\n";}
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD vicidial_log update: N|$affected_rows|$uniqueid\n";}
if ($AGILOG) {$agi_string = "-- VDAD vicidial_log update: N|$affected_rows|$uniqueid"; &agi_output;}
$stmtA = "UPDATE vicidial_list set status='MP' where lead_id = '$CIDlead_id';";
if($M){print STDERR "\n\n|$stmtA|\n";}
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD vicidial_list update: N|$affected_rows|$CIDlead_id\n";}
if ($AGILOG) {$agi_string = "-- VDAD vicidial_list update: N|$affected_rows|$CIDlead_id"; &agi_output;}
}
while ($digit_loop_counter < 1)
@@ -609,7 +615,7 @@ while ($digit_loop_counter < 1)
if ($digit =~ /\d/)
{
$totalDTMF = "$totalDTMF$digit";
print STDERR "digit |$digit| TotalDTMF |$totalDTMF|\n";
if ($AGILOG) {$agi_string = "digit |$digit| TotalDTMF |$totalDTMF|"; &agi_output;}
# $AGI->say_digits("$digit");
undef $digit;
}
@@ -625,7 +631,7 @@ $totalDTMF =~ s/\D//gi;
$pin = $totalDTMF;
if ($totalDTMF)
{
print STDERR "digit |$digit| TotalDTMF |$totalDTMF|\n";
if ($AGILOG) {$agi_string = "digit |$digit| TotalDTMF |$totalDTMF|"; &agi_output;}
return;
}
@@ -633,7 +639,7 @@ if ($totalDTMF)
######### PLAY THE OPTIONS FILE THEN WAIT 5 SECONDS FOR DIGITS ############
$interrupt_digit = $AGI->stream_file("$options_audio_file",'123');
print STDERR "interrupt_digit |$interrupt_digit|\n";
if ($AGILOG) {$agi_string = "interrupt_digit |$interrupt_digit|"; &agi_output;}
$digits_being_entered=1;
$digit_loop_counter=0;
$totalDTMF='';
@@ -659,7 +665,7 @@ while ($digit_loop_counter < 1)
if ($digit =~ /\d/)
{
$totalDTMF = "$totalDTMF$digit";
print STDERR "digit |$digit| TotalDTMF |$totalDTMF|\n";
if ($AGILOG) {$agi_string = "digit |$digit| TotalDTMF |$totalDTMF|"; &agi_output;}
# $AGI->say_digits("$digit");
undef $digit;
}
@@ -675,7 +681,7 @@ $totalDTMF =~ s/\D//gi;
$pin = $totalDTMF;
if ($totalDTMF)
{
print STDERR "digit |$digit| TotalDTMF |$totalDTMF|\n";
if ($AGILOG) {$agi_string = "digit |$digit| TotalDTMF |$totalDTMF|"; &agi_output;}
return;
}
}
@@ -698,10 +704,26 @@ sub checkresult {
$pass++;
}
} else {
print STDERR "FAIL (unexpected result '$res')\n";
# print STDERR "FAIL (unexpected result '$res')\n";
$fail++;
}
}
sub agi_output
{
if ($AGILOG >=2)
{
### open the log file for writing ###
open(Lout, ">>$AGILOGfile")
|| die "Can't open $AGILOGfile: $!\n";
print Lout "$now_date|$script|$agi_string\n";
close(Lout);
}
### send to STDERR writing ###
if ( ($AGILOG == '1') || ($AGILOG == '3') )
{print STDERR "$now_date|$script|$agi_string\n";}
$agi_string='';
}