updated agi-VDADcloser scripts to DBI

git-svn-id: svn://192.168.202.10@157 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
mattf
2006-08-11 15:28:21 +00:00
parent d738aefbfb
commit 99d108ad7c
8 changed files with 1033 additions and 937 deletions
+113 -104
View File
@@ -1,6 +1,6 @@
#!/usr/bin/perl
#
# agi-VDADcloser_PHONE.agi version 0.3
# agi-VDADcloser_PHONE.agi version 0.4 *DBI-version*
#
# runs when a call comes in from a VICIDIAL fronter from a foreign location. This script will
# send the calls out to the closers that are logged in. Customer data is not supplied aside from phone number,
@@ -38,6 +38,7 @@
#
# changes:
# 60504-1243 - Added drop second/message/exten options from inbound_group
# 60811-1100 - Changed to DBI
#
$V = 1; # set to 1 for verbose mode
@@ -48,7 +49,7 @@ $DROP_TIME = 360; ### number of seconds to wait until you drop a waiting call
### Make sure this file is in a path or put the absolute path to it
require("/home/cron/AST_SERVER_conf.pl"); # local configuration file
use Net::MySQL;
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;
@@ -211,42 +212,52 @@ if (!$phone_code) {$phone_code = '1';}
if (!$VLcomments) {$VLcomments = '';}
if (!$DB_port) {$DB_port='3306';}
my $dbhA = Net::MySQL->new(hostname=>"$DB_server", database=>"$DB_database", user=>"$DB_user", password=>"$DB_pass", port => "$DB_port") or die "Couldn't connect to database: $DB_server - $DB_database\n";
my $dbhA = DBI->connect("DBI:mysql:$DB_database:$DB_server:$DB_port", "$DB_user", "$DB_pass")
or die "Couldn't connect to database: " . DBI->errstr;
### Grab Server values from the database
$cbc=0;
$stmtA = "SELECT voicemail_dump_exten,ext_context,answer_transfer_agent,local_gmt,asterisk_version,max_vicidial_trunks FROM servers where server_ip = '$server_ip';";
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
while ( $record = $iter->each)
{
$DBvoicemail_dump_exten = "$record->[0]";
$DBext_context = "$record->[1]";
$DBanswer_transfer_agent = "$record->[2]";
$DBSERVER_GMT = "$record->[3]";
$DBasterisk_version = "$record->[4]";
$DBmax_vicidial_trunks = "$record->[5]";
if ($DBvoicemail_dump_exten) {$voicemail_dump_exten = $DBvoicemail_dump_exten;}
if ($DBext_context) {$ext_context = $DBext_context;}
if ($DBanswer_transfer_agent) {$answer_transfer_agent = $DBanswer_transfer_agent;}
if ($DBSERVER_GMT) {$SERVER_GMT = $DBSERVER_GMT;}
if ($DBasterisk_version) {$AST_ver = $DBasterisk_version;}
if ($DBmax_vicidial_trunks) {$max_vicidial_trunks = $DBmax_vicidial_trunks;}
}
@aryA = $sthA->fetchrow_array;
$DBvoicemail_dump_exten = "$aryA[0]";
$DBext_context = "$aryA[1]";
$DBanswer_transfer_agent = "$aryA[2]";
$DBSERVER_GMT = "$aryA[3]";
$DBasterisk_version = "$aryA[4]";
$DBmax_vicidial_trunks = "$aryA[5]";
if ($DBvoicemail_dump_exten) {$voicemail_dump_exten = $DBvoicemail_dump_exten;}
if ($DBext_context) {$ext_context = $DBext_context;}
if ($DBanswer_transfer_agent) {$answer_transfer_agent = $DBanswer_transfer_agent;}
if ($DBSERVER_GMT) {$SERVER_GMT = $DBSERVER_GMT;}
if ($DBasterisk_version) {$AST_ver = $DBasterisk_version;}
if ($DBmax_vicidial_trunks) {$max_vicidial_trunks = $DBmax_vicidial_trunks;}
$cbc++;
}
$sthA->finish();
### insert a record into the vicidial_list table
$stmtA = "INSERT INTO vicidial_list (entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,called_since_last_reset,phone_code,phone_number,security_phrase,called_count,gmt_offset_now,comments) values('$SQLdate','$tsSQLdate','INBND','$ref_agent','$parked_by','VDCL','$list_id','Y','$phone_code','$cust_phone','$channel_group','1','-5.00','$VLcomments');";
$dbhA->query($stmtA);
$dbhA->query("select LAST_INSERT_ID() LIMIT 1;");
if ($dbhA->has_selected_record)
$affected_rows = $dbhA->do($stmtA);
$cbc=0;
$stmtA = "select LAST_INSERT_ID() LIMIT 1;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $cbc)
{
$iterA=$dbhA->create_record_iterator;
while ($recordA = $iterA->each)
{$insert_lead_id = "$recordA->[0]";}
@aryA = $sthA->fetchrow_array;
$insert_lead_id = "$aryA[0]";
$cbc++;
}
$sthA->finish();
$new_lead_id = $insert_lead_id;
$CIDlead_id = $new_lead_id;
if($M){print STDERR "\n|$stmtA|$new_lead_id|\n";}
@@ -267,41 +278,38 @@ if($M){print STDERR "\n|$stmtA|$new_lead_id|\n";}
$VDADfronter = "$ref_agent";
### Grab inbound_group values from the database
$cbc=0;
$stmtA = "SELECT drop_call_seconds,drop_message,drop_exten FROM vicidial_inbound_groups where group_id = '$channel_group';";
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
while ( $record = $iter->each)
{
$DBdrop_call_seconds = "$record->[0]";
$DBdrop_message = "$record->[1]";
$DBdrop_exten = "$record->[2]";
if ($DBdrop_call_seconds) {$DROP_TIME = $DBdrop_call_seconds;}
if ($DBdrop_message) {$drop_message = $DBdrop_message;}
if ($DBdrop_exten) {$drop_exten = $DBdrop_exten;}
}
@aryA = $sthA->fetchrow_array;
$DBdrop_call_seconds = "$aryA[0]";
$DBdrop_message = "$aryA[1]";
$DBdrop_exten = "$aryA[2]";
if ($DBdrop_call_seconds) {$DROP_TIME = $DBdrop_call_seconds;}
if ($DBdrop_message) {$drop_message = $DBdrop_message;}
if ($DBdrop_exten) {$drop_exten = $DBdrop_exten;}
$cbc++;
}
$sthA->finish();
### insert a LIVE record to the vicidial_auto_calls table
$stmtA = "INSERT INTO vicidial_auto_calls values('','$server_ip','$channel_group','LIVE','$CIDlead_id','$uniqueid','$callerid','$channel','$VDADphone_code','$VDADphone','$SQLdate','IN')";
$dbhA->query($stmtA);
# $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','QUEUE','$VDADphone_code','$VDADphone','VDCL','N')";
# if($M){print STDERR "\n|$stmtA|\n";}
# $dbhA->query($stmtA);
# if ($M) {print STDERR "-- VDAD : |$VDADlead_id|$CIDlead_id|insert to vicidial_log: $uniqueid\n";}
$affected_rows = $dbhA->do($stmtA);
$stmtA = "INSERT INTO vicidial_closer_log (lead_id,campaign_id,call_date,start_epoch,status,phone_code,phone_number,user,processed) values('$CIDlead_id','$VDADcampaign','$SQLdate','$now_date_epoch','QUEUE','$VDADphone_code','$VDADphone','VDCL','N')";
if($M){print STDERR "\n|$stmtA|\n";}
$dbhA->query($stmtA);
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL : |$VDADlead_id|$CIDlead_id|insert to vicidial_closer_log\n";}
$stmtA = "INSERT INTO vicidial_xfer_log (lead_id,campaign_id,call_date,phone_code,phone_number,user,closer) values('$CIDlead_id','$VDADcampaign','$SQLdate','$VDADphone_code','$VDADphone','$VDADfronter','VDXL')";
if($M){print STDERR "\n|$stmtA|\n";}
$dbhA->query($stmtA);
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDXL : |$VDADlead_id|$CIDlead_id|insert to vicidial_closer_log\n";}
@@ -329,17 +337,19 @@ if ($channel_status < 1)
}
}
$cbc=0;
$stmtA = "SELECT next_agent_call FROM vicidial_inbound_groups where group_id='$channel_group';";
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$rec_countCUSTDATA=0;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
$rec_countCUSTDATA=0;
while ( $record = $iter->each)
{
$CAMP_callorder = "$record->[0]";
}
@aryA = $sthA->fetchrow_array;
$CAMP_callorder = "$aryA[0]";
$cbc++;
}
$sthA->finish();
$agent_call_order='order by last_call_finish';
if ($CAMP_callorder =~ /overall_user_level/i) {$agent_call_order = 'order by user_level desc,last_call_finish';}
@@ -347,53 +357,58 @@ if ($channel_status < 1)
if ($CAMP_callorder =~ /oldest_call_finish/i) {$agent_call_order = 'order by last_call_finish';}
if ($CAMP_callorder =~ /random/i) {$agent_call_order = 'order by random_id';}
$rec_countWAIT=0;
$rec_countWAIT=0;
$cbc=0;
$stmtA = "SELECT count(*) FROM vicidial_auto_calls where status = 'LIVE' and server_ip='$server_ip' and campaign_id = '$channel_group' and call_time < \"$SQLdateBEGIN\" and lead_id != '$VDADlead_id';";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
while ( $record = $iter->each)
{
$rec_countWAIT = "$record->[0]";
}
@aryA = $sthA->fetchrow_array;
$rec_countWAIT = "$aryA[0]";
$cbc++;
}
$sthA->finish();
if ($rec_countWAIT < 1)
{
$stmtA = "UPDATE vicidial_live_agents set status='QUEUE',lead_id='$CIDlead_id',uniqueid='$unique_id', channel='$channel', callerid='$callerid' where status IN('CLOSER','READY') and server_ip='$server_ip' and campaign_id LIKE \"%CLOSER%\" and closer_campaigns LIKE \"% $VDADcampaign %\" and last_update_time > '$BDtsSQLdate' $agent_call_order limit 1;";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD get agent: |$affected_rows|update of vla table: $VDADcampaign|$server_ip\n|$stmtA|\n";}
if ($affected_rows > 0)
{
$cbc=0;
$stmtA = "SELECT conf_exten,user,extension FROM vicidial_live_agents where status = 'QUEUE' and server_ip='$server_ip' and campaign_id LIKE \"%CLOSER%\" and callerid='$callerid' and channel='$channel' order by last_call_time limit 1;";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$rec_countCUSTDATA=0;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
$rec_countCUSTDATA=0;
while ( $record = $iter->each)
{
$VDADconf_exten = "$record->[0]";
$VDADuser = "$record->[1]";
$VDADextension = "$record->[2]";
}
@aryA = $sthA->fetchrow_array;
$VDADconf_exten = "$aryA[0]";
$VDADuser = "$aryA[1]";
$VDADextension = "$aryA[2]";
$cbc++;
}
$sthA->finish();
$stmtA = "UPDATE vicidial_auto_calls set status='CLOSER' where callerid='$callerid';";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL XFER : |$affected_rows|update of vac table: $callerid\n|$stmtA|\n";}
$stmtA = "UPDATE vicidial_xfer_log set closer='$VDADuser' where lead_id = '$CIDlead_id' order by call_date desc limit 1;";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDXL vicidial_xfer_log update: |$affected_rows|$CIDlead_id|$VDADuser\n";}
$dbhA->close;
$dbhA->disconnect();
print STDERR "\nexiting the VDAD app, transferring call to $VDADconf_exten\n";
print "SET CONTEXT $ext_context\n";
@@ -473,20 +488,23 @@ if ($drop_seconds < 1)
}
else
{
$cbc=0;
$stmtA = "SELECT voicemail_ext FROM vicidial_inbound_groups where group_id = '$channel_group' limit 1;";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
{
$iter=$dbhA->create_record_iterator;
$rec_countCUSTDATA=0;
while ( $record = $iter->each)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$rec_countCUSTDATA=0;
while ($sthArows > $cbc)
{
$VDADvoicemail_ext = "$record->[0]";
$VDADvoicemail_ext = "$aryA[0]";
$VDADvoicemail_ext =~ s/\D//gi;
$DROPexten = "$voicemail_dump_exten$VDADvoicemail_ext";
}
}
$cbc++;
}
$sthA->finish();
}
}
@@ -508,38 +526,29 @@ if ($drop_seconds < 1)
{
### 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','','','','','','','','','')";
$dbhA->query($stmtA) or die "Couldn't execute query:\n";
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL call_hungup timout: |$VHqueryCID|$VDADconf_exten|$channel|insert to vicidial_manager\n";}
}
$stmtA = "DELETE FROM vicidial_auto_calls where callerid='$callerid' and server_ip='$server_ip' order by call_time desc limit 1;";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL vac record deleted: |$affected_rows| $VDADcampaign|$server_ip\n";}
# $stmtA = "UPDATE vicidial_log set status='DROP',end_epoch='$now_date_epoch',length_in_sec='$drop_seconds' where uniqueid = '$uniqueid';";
# if($M){print STDERR "\n\n|$stmtA|\n";}
# $dbhA->query("$stmtA");
# my $affected_rows = $dbhA->get_affected_rows_length;
# if ($M) {print STDERR "-- VDCL vicidial_log update: |$affected_rows|$uniqueid\n";}
$stmtA = "UPDATE vicidial_closer_log set status='DROP',end_epoch='$now_date_epoch',length_in_sec='$drop_seconds' where lead_id = '$CIDlead_id' order by start_epoch desc limit 1;";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL vicidial_closer_log update: |$affected_rows|$CIDlead_id\n";}
$stmtA = "UPDATE vicidial_list set status='XDROP' where lead_id = '$CIDlead_id';";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL vicidial_list update: |$affected_rows|$CIDlead_id\n";}
}
$dbhA->close;
$dbhA->disconnect();
+134 -118
View File
@@ -1,6 +1,6 @@
#!/usr/bin/perl
#
# agi-VDADcloser_inbound.agi version 0.3
# agi-VDADcloser_inbound.agi version 0.4 *DBI-version*
#
# runs when a call comes in from an inbound call. This script will
# send the calls out to the closers that are logged in.
@@ -29,6 +29,7 @@
#
# changes:
# 60504-1224 - Added drop second/message/exten options from inbound_group
# 60811-1003 - Changed to DBI by Marin Blu
#
$V = 1; # set to 1 for verbose mode
@@ -39,7 +40,7 @@ $DROP_TIME = 360; ### number of seconds to wait until you drop a waiting call
### Make sure this file is in a path or put the absolute path to it
require("/home/cron/AST_SERVER_conf.pl"); # local configuration file
use Net::MySQL;
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;
@@ -225,91 +226,103 @@ exit;
if (!$DB_port) {$DB_port='3306';}
my $dbhA = Net::MySQL->new(hostname=>"$DB_server", database=>"$DB_database", user=>"$DB_user", password=>"$DB_pass", port => "$DB_port") or die "Couldn't connect to database: $DB_server - $DB_database\n";
my $dbhA = DBI->connect("DBI:mysql:$DB_database:$DB_server:$DB_port", "$DB_user", "$DB_pass")
or die "Couldn't connect to database: " . DBI->errstr;
### Grab Server values from the database
$cbc=0;
$stmtA = "SELECT voicemail_dump_exten,ext_context,answer_transfer_agent,local_gmt,asterisk_version,max_vicidial_trunks FROM servers where server_ip = '$server_ip';";
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
while ( $record = $iter->each)
{
$DBvoicemail_dump_exten = "$record->[0]";
$DBext_context = "$record->[1]";
$DBanswer_transfer_agent = "$record->[2]";
$DBSERVER_GMT = "$record->[3]";
$DBasterisk_version = "$record->[4]";
$DBmax_vicidial_trunks = "$record->[5]";
if ($DBvoicemail_dump_exten) {$voicemail_dump_exten = $DBvoicemail_dump_exten;}
if ($DBext_context) {$ext_context = $DBext_context;}
if ($DBanswer_transfer_agent) {$answer_transfer_agent = $DBanswer_transfer_agent;}
if ($DBSERVER_GMT) {$SERVER_GMT = $DBSERVER_GMT;}
if ($DBasterisk_version) {$AST_ver = $DBasterisk_version;}
if ($DBmax_vicidial_trunks) {$max_vicidial_trunks = $DBmax_vicidial_trunks;}
}
@aryA = $sthA->fetchrow_array;
$DBvoicemail_dump_exten = "$aryA[0]";
$DBext_context = "$aryA[1]";
$DBanswer_transfer_agent = "$aryA[2]";
$DBSERVER_GMT = "$aryA[3]";
$DBasterisk_version = "$aryA[4]";
$DBmax_vicidial_trunks = "$aryA[5]";
if ($DBvoicemail_dump_exten) {$voicemail_dump_exten = $DBvoicemail_dump_exten;}
if ($DBext_context) {$ext_context = $DBext_context;}
if ($DBanswer_transfer_agent) {$answer_transfer_agent = $DBanswer_transfer_agent;}
if ($DBSERVER_GMT) {$SERVER_GMT = $DBSERVER_GMT;}
if ($DBasterisk_version) {$AST_ver = $DBasterisk_version;}
if ($DBmax_vicidial_trunks) {$max_vicidial_trunks = $DBmax_vicidial_trunks;}
$cbc++;
}
$sthA->finish();
### insert a record into the vicidial_list table
$stmtA = "INSERT INTO vicidial_list (entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,called_since_last_reset,phone_code,phone_number,security_phrase,called_count,gmt_offset_now) values('$SQLdate','$tsSQLdate','INBND','$fronter','$channel_group','VDCL','$list_id','Y','$phone_code','$phone_number','$channel_group','1','-5.00');";
$dbhA->query($stmtA);
$dbhA->query("select LAST_INSERT_ID() LIMIT 1;");
if ($dbhA->has_selected_record)
$affected_rows = $dbhA->do($stmtA);
$cbc=0;
$stmtA = "select LAST_INSERT_ID() LIMIT 1;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $cbc)
{
$iterA=$dbhA->create_record_iterator;
while ($recordA = $iterA->each)
{$insert_lead_id = "$recordA->[0]";}
@aryA = $sthA->fetchrow_array;
$insert_lead_id = "$aryA[0]";
$cbc++;
}
$sthA->finish();
$new_lead_id = $insert_lead_id;
if($M){print STDERR "\n|$stmtA|$new_lead_id|\n";}
$PADlead_id = sprintf("%09s", $new_lead_id); while (length($PADlead_id) > 9) {chop($PADlead_id);}
# YmmddhhmmssLLLLLLLLL
$YqueryCID = "Y$CIDdate$PADlead_id";
$callerid = $YqueryCID;
### set the callerid
print "SET CALLERID $YqueryCID\n";
checkresult($result);
print STDERR "callerID changed: $YqueryCID\n";
$PADlead_id = sprintf("%09s", $new_lead_id); while (length($PADlead_id) > 9) {chop($PADlead_id);}
# YmmddhhmmssLLLLLLLLL
$YqueryCID = "Y$CIDdate$PADlead_id";
$callerid = $YqueryCID;
### set the callerid
print "SET CALLERID $YqueryCID\n";
checkresult($result);
print STDERR "callerID changed: $YqueryCID\n";
### Grab inbound_group values from the database
$cbc=0;
$stmtA = "SELECT drop_call_seconds,drop_message,drop_exten FROM vicidial_inbound_groups where group_id = '$channel_group';";
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
while ( $record = $iter->each)
{
$DBdrop_call_seconds = "$record->[0]";
$DBdrop_message = "$record->[1]";
$DBdrop_exten = "$record->[2]";
if ($DBdrop_call_seconds) {$DROP_TIME = $DBdrop_call_seconds;}
if ($DBdrop_message) {$drop_message = $DBdrop_message;}
if ($DBdrop_exten) {$drop_exten = $DBdrop_exten;}
}
@aryA = $sthA->fetchrow_array;
$DBdrop_call_seconds = "$aryA[0]";
$DBdrop_message = "$aryA[1]";
$DBdrop_exten = "$aryA[2]";
if ($DBdrop_call_seconds) {$DROP_TIME = $DBdrop_call_seconds;}
if ($DBdrop_message) {$drop_message = $DBdrop_message;}
if ($DBdrop_exten) {$drop_exten = $DBdrop_exten;}
$cbc++;
}
$sthA->finish();
### insert a LIVE record to the vicidial_auto_calls table
$stmtA = "INSERT INTO vicidial_auto_calls values('','$server_ip','$channel_group','LIVE','$new_lead_id','$uniqueid','$callerid','$channel','$phone_code','$phone_number','$SQLdate','IN')";
$dbhA->query($stmtA);
$affected_rows = $dbhA->do($stmtA);
if($M){print STDERR "\n|$stmtA|\n";}
$stmtA = "INSERT INTO vicidial_log (uniqueid,lead_id,campaign_id,call_date,start_epoch,status,phone_code,phone_number,user,processed) values('$uniqueid','$new_lead_id','$channel_group','$SQLdate','$now_date_epoch','XFER','$phone_code','$phone_number','$fronter','N')";
if($M){print STDERR "\n|$stmtA|\n";}
$dbhA->query($stmtA);
if ($M) {print STDERR "-- VDAD : |$new_lead_id|$fronter|insert to vicidial_log: $uniqueid\n";}
$stmtA = "INSERT INTO vicidial_log (uniqueid,lead_id,campaign_id,call_date,start_epoch,status,phone_code,phone_number,user,processed) values('$uniqueid','$new_lead_id','$channel_group','$SQLdate','$now_date_epoch','XFER','$phone_code','$phone_number','$fronter','N')";
if($M){print STDERR "\n|$stmtA|\n";}
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD : |$new_lead_id|$fronter|insert to vicidial_log: $uniqueid\n";}
$stmtA = "INSERT INTO vicidial_closer_log (lead_id,campaign_id,call_date,start_epoch,status,phone_code,phone_number,user,processed) values('$new_lead_id','$channel_group','$SQLdate','$now_date_epoch','QUEUE','$phone_code','$phone_number','VDCL','N')";
if($M){print STDERR "\n|$stmtA|\n";}
$dbhA->query($stmtA);
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL : |$new_lead_id|insert to vicidial_closer_log\n";}
$stmtA = "INSERT INTO vicidial_xfer_log (lead_id,campaign_id,call_date,phone_code,phone_number,user,closer) values('$new_lead_id','$channel_group','$SQLdate','$phone_code','$phone_number','$fronter','VDXL')";
if($M){print STDERR "\n|$stmtA|\n";}
$dbhA->query($stmtA);
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDXL : |$new_lead_id|insert to vicidial_closer_log\n";}
$VDADlead_id = $new_lead_id;
@@ -338,17 +351,20 @@ if ($channel_status < 1)
}
}
$cbc=0;
$stmtA = "SELECT next_agent_call FROM vicidial_inbound_groups where group_id='$channel_group';";
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$rec_countCUSTDATA=0;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
$rec_countCUSTDATA=0;
while ( $record = $iter->each)
{
$CAMP_callorder = "$record->[0]";
}
@aryA = $sthA->fetchrow_array;
$CAMP_callorder = "$aryA[0]";
$cbc++;
}
$sthA->finish();
$agent_call_order='order by last_call_finish';
if ($CAMP_callorder =~ /overall_user_level/i) {$agent_call_order = 'order by user_level desc,last_call_finish';}
@@ -356,62 +372,64 @@ if ($channel_status < 1)
if ($CAMP_callorder =~ /oldest_call_finish/i) {$agent_call_order = 'order by last_call_finish';}
if ($CAMP_callorder =~ /random/i) {$agent_call_order = 'order by random_id';}
$rec_countWAIT=0;
$rec_countWAIT=0;
$cbc=0;
$stmtA = "SELECT count(*) FROM vicidial_auto_calls where status = 'LIVE' and server_ip='$server_ip' and campaign_id = '$channel_group' and call_time < \"$SQLdateBEGIN\" and lead_id != '$VDADlead_id';";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
while ( $record = $iter->each)
{
$rec_countWAIT = "$record->[0]";
}
@aryA = $sthA->fetchrow_array;
$rec_countWAIT = "$aryA[0]";
$cbc++;
}
$sthA->finish();
if ($rec_countWAIT < 1)
{
$stmtA = "UPDATE vicidial_live_agents set status='QUEUE',lead_id='$new_lead_id',uniqueid='$unique_id', channel='$channel', callerid='$callerid' where status IN('CLOSER','READY') and server_ip='$server_ip' and campaign_id LIKE \"%CLOSER%\" and closer_campaigns LIKE \"% $channel_group %\" and last_update_time > '$BDtsSQLdate' $agent_call_order limit 1;";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD get agent: |$DROP_TIME|$drop_timer|$affected_rows|update of vla table: $channel_group|$server_ip\n";}
# if ($M) {print STDERR "|$stmtA|\n";}
if ($affected_rows > 0)
{
$cbc=0;
$stmtA = "SELECT conf_exten,user,extension FROM vicidial_live_agents where status = 'QUEUE' and server_ip='$server_ip' and campaign_id LIKE \"%CLOSER%\" and callerid='$callerid' and channel='$channel' order by last_call_time limit 1;";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$rec_countCUSTDATA=0;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
$rec_countCUSTDATA=0;
while ( $record = $iter->each)
{
$VDADconf_exten = "$record->[0]";
$VDADuser = "$record->[1]";
$VDADextension = "$record->[2]";
}
}
else
{
print STDERR "NNNNNNNNNN No agent record found!!!\n";
@aryA = $sthA->fetchrow_array;
$VDADconf_exten = "$aryA[0]";
$VDADuser = "$aryA[1]";
$VDADextension = "$aryA[2]";
$cbc++;
}
$sthA->finish();
$stmtA = "UPDATE vicidial_auto_calls set status='CLOSER' where callerid='$callerid';";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL XFER : |$affected_rows|update of vac table: $callerid\n|$stmtA|\n";}
$stmtA = "UPDATE vicidial_xfer_log set closer='$VDADuser' where lead_id = '$new_lead_id' order by call_date desc limit 1;";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDXL vicidial_xfer_log update: |$affected_rows|$new_lead_id|$VDADuser\n";}
$stmtA = "UPDATE vicidial_closer_log set user='$VDADuser' where lead_id='$new_lead_id' order by call_date desc limit 1;";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- closer log : |$affected_rows|update of vcl table: $new_lead_id\n|$stmtA|\n";}
$dbhA->close;
$dbhA->disconnect();
print STDERR "\nexiting the VDAD app, transferring call to $VDADconf_exten\n";
print "SET CONTEXT $ext_context\n";
@@ -436,6 +454,10 @@ if ($channel_status < 1)
exit;
}
else
{
print STDERR "NNNNNNNNNN No agent record found!!!\n";
}
}
else
{
@@ -491,20 +513,23 @@ if ($drop_seconds < 1)
}
else
{
$cbc=0;
$stmtA = "SELECT voicemail_ext FROM vicidial_inbound_groups where group_id = '$channel_group' limit 1;";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
{
$iter=$dbhA->create_record_iterator;
$rec_countCUSTDATA=0;
while ( $record = $iter->each)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$rec_countCUSTDATA=0;
while ($sthArows > $cbc)
{
$VDADvoicemail_ext = "$record->[0]";
$VDADvoicemail_ext = "$aryA[0]";
$VDADvoicemail_ext =~ s/\D//gi;
$DROPexten = "$voicemail_dump_exten$VDADvoicemail_ext";
}
}
$cbc++;
}
$sthA->finish();
}
}
@@ -526,38 +551,29 @@ if ($drop_seconds < 1)
{
### 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','','','','','','','','','')";
$dbhA->query($stmtA) or die "Couldn't execute query:\n";
$affected_rows = $dbhA->do($stmtA) or die "Couldn't execute query:\n";
if ($M) {print STDERR "-- VDCL call_hungup timout: |$VHqueryCID|$VDADconf_exten|$channel|insert to vicidial_manager\n";}
}
$stmtA = "DELETE FROM vicidial_auto_calls where callerid='$callerid' and server_ip='$server_ip' order by call_time desc limit 1;";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL vac record deleted: |$affected_rows| $channel_group|$server_ip\n";}
# $stmtA = "UPDATE vicidial_log set status='DROP',end_epoch='$now_date_epoch',length_in_sec='$drop_seconds' where uniqueid = '$uniqueid';";
# if($M){print STDERR "\n\n|$stmtA|\n";}
# $dbhA->query("$stmtA");
# my $affected_rows = $dbhA->get_affected_rows_length;
# if ($M) {print STDERR "-- VDCL vicidial_log update: |$affected_rows|$uniqueid\n";}
$stmtA = "UPDATE vicidial_closer_log set status='DROP',end_epoch='$now_date_epoch',length_in_sec='$drop_seconds' where lead_id = '$new_lead_id' order by start_epoch desc limit 1;";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL vicidial_closer_log update: |$affected_rows|$new_lead_id\n";}
$stmtA = "UPDATE vicidial_list set status='XDROP' where lead_id = '$new_lead_id';";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL vicidial_list update: |$affected_rows|$new_lead_id\n";}
}
$dbhA->close;
$dbhA->disconnect();
+126 -117
View File
@@ -1,6 +1,6 @@
#!/usr/bin/perl
#
# agi-VDADcloser_inboundANI.agi version 0.3
# agi-VDADcloser_inboundANI.agi version 0.4 *DBI-version*
#
# runs when a call comes in from an inbound call. This script will
# send the calls out to the closers that are logged in.
@@ -28,6 +28,7 @@
#
# changes:
# 60504-1240 - Added drop second/message/exten options from inbound_group
# 60811-1003 - Changed to DBI by Marin Blu
#
$V = 1; # set to 1 for verbose mode
@@ -38,7 +39,7 @@ $DROP_TIME = 360; ### number of seconds to wait until you drop a waiting call
### Make sure this file is in a path or put the absolute path to it
require("/home/cron/AST_SERVER_conf.pl"); # local configuration file
use Net::MySQL;
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;
@@ -225,86 +226,91 @@ exit;
if (!$DB_port) {$DB_port='3306';}
my $dbhA = Net::MySQL->new(hostname=>"$DB_server", database=>"$DB_database", user=>"$DB_user", password=>"$DB_pass", port => "$DB_port") or die "Couldn't connect to database: $DB_server - $DB_database\n";
my $dbhA = DBI->connect("DBI:mysql:$DB_database:$DB_server:$DB_port", "$DB_user", "$DB_pass")
or die "Couldn't connect to database: " . DBI->errstr;
### Grab Server values from the database
$cbc=0;
$stmtA = "SELECT voicemail_dump_exten,ext_context,answer_transfer_agent,local_gmt,asterisk_version,max_vicidial_trunks FROM servers where server_ip = '$server_ip';";
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
while ( $record = $iter->each)
{
$DBvoicemail_dump_exten = "$record->[0]";
$DBext_context = "$record->[1]";
$DBanswer_transfer_agent = "$record->[2]";
$DBSERVER_GMT = "$record->[3]";
$DBasterisk_version = "$record->[4]";
$DBmax_vicidial_trunks = "$record->[5]";
if ($DBvoicemail_dump_exten) {$voicemail_dump_exten = $DBvoicemail_dump_exten;}
if ($DBext_context) {$ext_context = $DBext_context;}
if ($DBanswer_transfer_agent) {$answer_transfer_agent = $DBanswer_transfer_agent;}
if ($DBSERVER_GMT) {$SERVER_GMT = $DBSERVER_GMT;}
if ($DBasterisk_version) {$AST_ver = $DBasterisk_version;}
if ($DBmax_vicidial_trunks) {$max_vicidial_trunks = $DBmax_vicidial_trunks;}
}
@aryA = $sthA->fetchrow_array;
$DBvoicemail_dump_exten = "$aryA[0]";
$DBext_context = "$aryA[1]";
$DBanswer_transfer_agent = "$aryA[2]";
$DBSERVER_GMT = "$aryA[3]";
$DBasterisk_version = "$aryA[4]";
$DBmax_vicidial_trunks = "$aryA[5]";
if ($DBvoicemail_dump_exten) {$voicemail_dump_exten = $DBvoicemail_dump_exten;}
if ($DBext_context) {$ext_context = $DBext_context;}
if ($DBanswer_transfer_agent) {$answer_transfer_agent = $DBanswer_transfer_agent;}
if ($DBSERVER_GMT) {$SERVER_GMT = $DBSERVER_GMT;}
if ($DBasterisk_version) {$AST_ver = $DBasterisk_version;}
if ($DBmax_vicidial_trunks) {$max_vicidial_trunks = $DBmax_vicidial_trunks;}
$cbc++;
}
$sthA->finish();
### insert a record into the vicidial_list table
$stmtA = "INSERT INTO vicidial_list (entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,called_since_last_reset,phone_code,phone_number,security_phrase,called_count,gmt_offset_now,comments) values('$SQLdate','$tsSQLdate','INBND','$fronter','$channel_group','VDCL','$list_id','Y','$phone_code','$phone_number','$channel_group','1','-5.00','$VLcomments');";
$dbhA->query($stmtA);
$dbhA->query("select LAST_INSERT_ID() LIMIT 1;");
if ($dbhA->has_selected_record)
$affected_rows = $dbhA->do($stmtA);
$cbc=0;
$stmtA = "select LAST_INSERT_ID() LIMIT 1;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $cbc)
{
$iterA=$dbhA->create_record_iterator;
while ($recordA = $iterA->each)
{$insert_lead_id = "$recordA->[0]";}
@aryA = $sthA->fetchrow_array;
$insert_lead_id = "$aryA[0]";
$cbc++;
}
$sthA->finish();
$new_lead_id = $insert_lead_id;
if($M){print STDERR "\n|$stmtA|$new_lead_id|\n";}
$PADlead_id = sprintf("%09s", $new_lead_id); while (length($PADlead_id) > 9) {chop($PADlead_id);}
# YmmddhhmmssLLLLLLLLL
$YqueryCID = "Y$CIDdate$PADlead_id";
$callerid = $YqueryCID;
### set the callerid
print "SET CALLERID $YqueryCID\n";
checkresult($result);
print STDERR "callerID changed: $YqueryCID\n";
$PADlead_id = sprintf("%09s", $new_lead_id); while (length($PADlead_id) > 9) {chop($PADlead_id);}
# YmmddhhmmssLLLLLLLLL
$YqueryCID = "Y$CIDdate$PADlead_id";
$callerid = $YqueryCID;
### set the callerid
print "SET CALLERID $YqueryCID\n";
checkresult($result);
print STDERR "callerID changed: $YqueryCID\n";
### Grab inbound_group values from the database
$cbc=0;
$stmtA = "SELECT drop_call_seconds,drop_message,drop_exten FROM vicidial_inbound_groups where group_id = '$channel_group';";
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
while ( $record = $iter->each)
{
$DBdrop_call_seconds = "$record->[0]";
$DBdrop_message = "$record->[1]";
$DBdrop_exten = "$record->[2]";
if ($DBdrop_call_seconds) {$DROP_TIME = $DBdrop_call_seconds;}
if ($DBdrop_message) {$drop_message = $DBdrop_message;}
if ($DBdrop_exten) {$drop_exten = $DBdrop_exten;}
}
@aryA = $sthA->fetchrow_array;
$DBdrop_call_seconds = "$aryA[0]";
$DBdrop_message = "$aryA[1]";
$DBdrop_exten = "$aryA[2]";
if ($DBdrop_call_seconds) {$DROP_TIME = $DBdrop_call_seconds;}
if ($DBdrop_message) {$drop_message = $DBdrop_message;}
if ($DBdrop_exten) {$drop_exten = $DBdrop_exten;}
$cbc++;
}
$sthA->finish();
### insert a LIVE record to the vicidial_auto_calls table
$stmtA = "INSERT INTO vicidial_auto_calls values('','$server_ip','$channel_group','LIVE','$new_lead_id','$uniqueid','$callerid','$channel','$phone_code','$phone_number','$SQLdate','IN')";
$dbhA->query($stmtA);
$affected_rows = $dbhA->do($stmtA);
if($M){print STDERR "\n|$stmtA|\n";}
# $stmtA = "INSERT INTO vicidial_log (uniqueid,lead_id,campaign_id,call_date,start_epoch,status,phone_code,phone_number,user,processed) values('$uniqueid','$new_lead_id','$channel_group','$SQLdate','$now_date_epoch','QUEUE','$phone_code','$phone_number','VDCL','N')";
# if($M){print STDERR "\n|$stmtA|\n";}
# $dbhA->query($stmtA);
# if ($M) {print STDERR "-- VDAD : |$VDADlead_id|$new_lead_id|insert to vicidial_log: $uniqueid\n";}
$stmtA = "INSERT INTO vicidial_closer_log (lead_id,campaign_id,call_date,start_epoch,status,phone_code,phone_number,user,processed) values('$new_lead_id','$channel_group','$SQLdate','$now_date_epoch','QUEUE','$phone_code','$phone_number','VDCL','N')";
if($M){print STDERR "\n|$stmtA|\n";}
$dbhA->query($stmtA);
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL : |$new_lead_id|insert to vicidial_closer_log\n";}
$VDADlead_id = $new_lead_id;
@@ -332,17 +338,21 @@ if ($channel_status < 1)
$drop_timer = ($drop_timer + 360);
}
}
$cbc=0;
$stmtA = "SELECT next_agent_call FROM vicidial_inbound_groups where group_id='$channel_group';";
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$rec_countCUSTDATA=0;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
$rec_countCUSTDATA=0;
while ( $record = $iter->each)
{
$CAMP_callorder = "$record->[0]";
}
@aryA = $sthA->fetchrow_array;
$CAMP_callorder = "$aryA[0]";
$cbc++;
}
$sthA->finish();
$agent_call_order='order by last_call_finish';
if ($CAMP_callorder =~ /overall_user_level/i) {$agent_call_order = 'order by user_level desc,last_call_finish';}
@@ -350,52 +360,57 @@ if ($channel_status < 1)
if ($CAMP_callorder =~ /oldest_call_finish/i) {$agent_call_order = 'order by last_call_finish';}
if ($CAMP_callorder =~ /random/i) {$agent_call_order = 'order by random_id';}
$rec_countWAIT=0;
$rec_countWAIT=0;
$cbc=0;
$stmtA = "SELECT count(*) FROM vicidial_auto_calls where status = 'LIVE' and server_ip='$server_ip' and campaign_id = '$channel_group' and call_time < \"$SQLdateBEGIN\" and lead_id != '$VDADlead_id';";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
while ( $record = $iter->each)
{
$rec_countWAIT = "$record->[0]";
}
@aryA = $sthA->fetchrow_array;
$rec_countWAIT = "$aryA[0]";
$cbc++;
}
$sthA->finish();
if ($rec_countWAIT < 1)
{
$stmtA = "UPDATE vicidial_live_agents set status='QUEUE',lead_id='$new_lead_id',uniqueid='$unique_id', channel='$channel', callerid='$callerid' where status IN('CLOSER','READY') and server_ip='$server_ip' and campaign_id LIKE \"%CLOSER%\" and closer_campaigns LIKE \"% $channel_group %\" and last_update_time > '$BDtsSQLdate' $agent_call_order limit 1;";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD get agent: |$DROP_TIME|$drop_timer|$affected_rows|update of vla table: $channel_group|$server_ip\n|$stmtA|\n";}
if ($affected_rows > 0)
{
$cbc=0;
$stmtA = "SELECT conf_exten,user,extension FROM vicidial_live_agents where status = 'QUEUE' and server_ip='$server_ip' and campaign_id LIKE \"%CLOSER%\" and callerid='$callerid' and channel='$channel' order by last_call_time limit 1;";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$rec_countCUSTDATA=0;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
$rec_countCUSTDATA=0;
while ( $record = $iter->each)
{
$VDADconf_exten = "$record->[0]";
$VDADuser = "$record->[1]";
$VDADextension = "$record->[2]";
}
@aryA = $sthA->fetchrow_array;
$VDADconf_exten = "$aryA[0]";
$VDADuser = "$aryA[1]";
$VDADextension = "$aryA[2]";
$cbc++;
}
$sthA->finish();
$stmtA = "UPDATE vicidial_auto_calls set status='CLOSER' where callerid='$callerid';";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL XFER : |$affected_rows|update of vac table: $callerid\n|$stmtA|\n";}
$stmtA = "UPDATE vicidial_closer_log set user='$VDADuser' where lead_id='$new_lead_id' order by call_date desc limit 1;";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- closer log : |$affected_rows|update of vcl table: $new_lead_id\n|$stmtA|\n";}
$dbhA->close;
$dbhA->disconnect();
print STDERR "\nexiting the VDAD app, transferring call to $VDADconf_exten\n";
print "SET CONTEXT $ext_context\n";
@@ -420,6 +435,10 @@ if ($channel_status < 1)
exit;
}
else
{
print STDERR "NNNNNNNNNN No agent record found!!!\n";
}
}
else
{
@@ -475,20 +494,23 @@ if ($drop_seconds < 1)
}
else
{
$cbc=0;
$stmtA = "SELECT voicemail_ext FROM vicidial_inbound_groups where group_id = '$channel_group' limit 1;";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
{
$iter=$dbhA->create_record_iterator;
$rec_countCUSTDATA=0;
while ( $record = $iter->each)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$rec_countCUSTDATA=0;
while ($sthArows > $cbc)
{
$VDADvoicemail_ext = "$record->[0]";
$VDADvoicemail_ext = "$aryA[0]";
$VDADvoicemail_ext =~ s/\D//gi;
$DROPexten = "$voicemail_dump_exten$VDADvoicemail_ext";
}
}
$cbc++;
}
$sthA->finish();
}
}
@@ -510,40 +532,27 @@ if ($drop_seconds < 1)
{
### 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','','','','','','','','','')";
$dbhA->query($stmtA) or die "Couldn't execute query:\n";
$affected_rows = $dbhA->do($stmtA) or die "Couldn't execute query:\n";
if ($M) {print STDERR "-- VDCL call_hungup timout: |$VHqueryCID|$VDADconf_exten|$channel|insert to vicidial_manager\n";}
}
$stmtA = "DELETE FROM vicidial_auto_calls where callerid='$callerid' and server_ip='$server_ip' order by call_time desc limit 1;";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL vac record deleted: |$affected_rows| $channel_group|$server_ip\n";}
# $stmtA = "UPDATE vicidial_log set status='DROP',end_epoch='$now_date_epoch',length_in_sec='$drop_seconds' where uniqueid = '$uniqueid';";
# if($M){print STDERR "\n\n|$stmtA|\n";}
# $dbhA->query("$stmtA");
# my $affected_rows = $dbhA->get_affected_rows_length;
# if ($M) {print STDERR "-- VDCL vicidial_log update: |$affected_rows|$uniqueid\n";}
$stmtA = "UPDATE vicidial_closer_log set status='DROP',end_epoch='$now_date_epoch',length_in_sec='$drop_seconds' where lead_id = '$new_lead_id' order by start_epoch desc limit 1;";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL vicidial_closer_log update: |$affected_rows|$new_lead_id\n";}
$stmtA = "UPDATE vicidial_list set status='XDROP' where lead_id = '$new_lead_id';";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL vicidial_list update: |$affected_rows|$new_lead_id\n";}
}
$dbhA->close;
$dbhA->disconnect();
exit;
@@ -1,6 +1,6 @@
#!/usr/bin/perl
#
# agi-VDADcloser_inboundCID.agi version 0.3
# agi-VDADcloser_inboundCID.agi version 0.4 *DBI-version*
#
# runs when a call comes in from an inbound call. This script will
# send the calls out to the closers that are logged in.
@@ -30,6 +30,7 @@
#
# changes:
# 60504-1241 - Added drop second/message/exten options from inbound_group
# 60811-1003 - Changed to DBI by Marin Blu
#
### open the error out file for writing ###
@@ -44,7 +45,7 @@ $DROP_TIME = 360; ### number of seconds to wait until you drop a waiting call
### Make sure this file is in a path or put the absolute path to it
require("/home/cron/AST_SERVER_conf.pl"); # local configuration file
use Net::MySQL;
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;
@@ -246,86 +247,92 @@ exit;
if (!$DB_port) {$DB_port='3306';}
my $dbhA = Net::MySQL->new(hostname=>"$DB_server", database=>"$DB_database", user=>"$DB_user", password=>"$DB_pass", port => "$DB_port") or die "Couldn't connect to database: $DB_server - $DB_database\n";
my $dbhA = DBI->connect("DBI:mysql:$DB_database:$DB_server:$DB_port", "$DB_user", "$DB_pass")
or die "Couldn't connect to database: " . DBI->errstr;
### Grab Server values from the database
$cbc=0;
$stmtA = "SELECT voicemail_dump_exten,ext_context,answer_transfer_agent,local_gmt,asterisk_version,max_vicidial_trunks FROM servers where server_ip = '$server_ip';";
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
while ( $record = $iter->each)
{
$DBvoicemail_dump_exten = "$record->[0]";
$DBext_context = "$record->[1]";
$DBanswer_transfer_agent = "$record->[2]";
$DBSERVER_GMT = "$record->[3]";
$DBasterisk_version = "$record->[4]";
$DBmax_vicidial_trunks = "$record->[5]";
if ($DBvoicemail_dump_exten) {$voicemail_dump_exten = $DBvoicemail_dump_exten;}
if ($DBext_context) {$ext_context = $DBext_context;}
if ($DBanswer_transfer_agent) {$answer_transfer_agent = $DBanswer_transfer_agent;}
if ($DBSERVER_GMT) {$SERVER_GMT = $DBSERVER_GMT;}
if ($DBasterisk_version) {$AST_ver = $DBasterisk_version;}
if ($DBmax_vicidial_trunks) {$max_vicidial_trunks = $DBmax_vicidial_trunks;}
}
@aryA = $sthA->fetchrow_array;
$DBvoicemail_dump_exten = "$aryA[0]";
$DBext_context = "$aryA[1]";
$DBanswer_transfer_agent = "$aryA[2]";
$DBSERVER_GMT = "$aryA[3]";
$DBasterisk_version = "$aryA[4]";
$DBmax_vicidial_trunks = "$aryA[5]";
if ($DBvoicemail_dump_exten) {$voicemail_dump_exten = $DBvoicemail_dump_exten;}
if ($DBext_context) {$ext_context = $DBext_context;}
if ($DBanswer_transfer_agent) {$answer_transfer_agent = $DBanswer_transfer_agent;}
if ($DBSERVER_GMT) {$SERVER_GMT = $DBSERVER_GMT;}
if ($DBasterisk_version) {$AST_ver = $DBasterisk_version;}
if ($DBmax_vicidial_trunks) {$max_vicidial_trunks = $DBmax_vicidial_trunks;}
$cbc++;
}
$sthA->finish();
### insert a record into the vicidial_list table
$stmtA = "INSERT INTO vicidial_list (entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,called_since_last_reset,phone_code,phone_number,security_phrase,called_count,gmt_offset_now,comments) values('$SQLdate','$tsSQLdate','INBND','$fronter','$channel_group','VDCL','$list_id','Y','$phone_code','$phone_number','$channel_group','1','-5.00','$VLcomments');";
$dbhA->query($stmtA);
$dbhA->query("select LAST_INSERT_ID() LIMIT 1;");
if ($dbhA->has_selected_record)
$affected_rows = $dbhA->do($stmtA);
$cbc=0;
$stmtA = "select LAST_INSERT_ID() LIMIT 1;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $cbc)
{
$iterA=$dbhA->create_record_iterator;
while ($recordA = $iterA->each)
{$insert_lead_id = "$recordA->[0]";}
@aryA = $sthA->fetchrow_array;
$insert_lead_id = "$aryA[0]";
$cbc++;
}
$sthA->finish();
$new_lead_id = $insert_lead_id;
if($M){print out "\n|$stmtA|$new_lead_id|\n";}
$PADlead_id = sprintf("%09s", $new_lead_id); while (length($PADlead_id) > 9) {chop($PADlead_id);}
# YmmddhhmmssLLLLLLLLL
$YqueryCID = "Y$CIDdate$PADlead_id";
$callerid = $YqueryCID;
### set the callerid
print "SET CALLERID $YqueryCID\n";
checkresult($result);
print out "callerID changed: $YqueryCID\n";
$PADlead_id = sprintf("%09s", $new_lead_id); while (length($PADlead_id) > 9) {chop($PADlead_id);}
# YmmddhhmmssLLLLLLLLL
$YqueryCID = "Y$CIDdate$PADlead_id";
$callerid = $YqueryCID;
### set the callerid
print "SET CALLERID $YqueryCID\n";
checkresult($result);
print out "callerID changed: $YqueryCID\n";
### Grab inbound_group values from the database
$cbc=0;
$stmtA = "SELECT drop_call_seconds,drop_message,drop_exten FROM vicidial_inbound_groups where group_id = '$channel_group';";
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
while ( $record = $iter->each)
{
$DBdrop_call_seconds = "$record->[0]";
$DBdrop_message = "$record->[1]";
$DBdrop_exten = "$record->[2]";
if ($DBdrop_call_seconds) {$DROP_TIME = $DBdrop_call_seconds;}
if ($DBdrop_message) {$drop_message = $DBdrop_message;}
if ($DBdrop_exten) {$drop_exten = $DBdrop_exten;}
}
@aryA = $sthA->fetchrow_array;
$DBdrop_call_seconds = "$aryA[0]";
$DBdrop_message = "$aryA[1]";
$DBdrop_exten = "$aryA[2]";
if ($DBdrop_call_seconds) {$DROP_TIME = $DBdrop_call_seconds;}
if ($DBdrop_message) {$drop_message = $DBdrop_message;}
if ($DBdrop_exten) {$drop_exten = $DBdrop_exten;}
$cbc++;
}
$sthA->finish();
### insert a LIVE record to the vicidial_auto_calls table
$stmtA = "INSERT INTO vicidial_auto_calls values('','$server_ip','$channel_group','LIVE','$new_lead_id','$uniqueid','$callerid','$channel','$phone_code','$phone_number','$SQLdate','IN')";
$dbhA->query($stmtA);
$affected_rows = $dbhA->do($stmtA);
if($M){print out "\n|$stmtA|\n";}
# $stmtA = "INSERT INTO vicidial_log (uniqueid,lead_id,campaign_id,call_date,start_epoch,status,phone_code,phone_number,user,processed) values('$uniqueid','$new_lead_id','$channel_group','$SQLdate','$now_date_epoch','QUEUE','$phone_code','$phone_number','VDCL','N')";
# if($M){print out "\n|$stmtA|\n";}
# $dbhA->query($stmtA);
# if ($M) {print out "-- VDAD : |$VDADlead_id|$new_lead_id|insert to vicidial_log: $uniqueid\n";}
$stmtA = "INSERT INTO vicidial_closer_log (lead_id,campaign_id,call_date,start_epoch,status,phone_code,phone_number,user,processed) values('$new_lead_id','$channel_group','$SQLdate','$now_date_epoch','QUEUE','$phone_code','$phone_number','VDCL','N')";
if($M){print out "\n|$stmtA|\n";}
$dbhA->query($stmtA);
$affected_rows = $dbhA->do($stmtA);
if ($M) {print out "-- VDCL : |$new_lead_id|insert to vicidial_closer_log\n";}
$VDADlead_id = $new_lead_id;
@@ -353,17 +360,21 @@ if ($channel_status < 1)
$drop_timer = ($drop_timer + 360);
}
}
$cbc=0;
$stmtA = "SELECT next_agent_call FROM vicidial_inbound_groups where group_id='$channel_group';";
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$rec_countCUSTDATA=0;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
$rec_countCUSTDATA=0;
while ( $record = $iter->each)
{
$CAMP_callorder = "$record->[0]";
}
@aryA = $sthA->fetchrow_array;
$CAMP_callorder = "$aryA[0]";
$cbc++;
}
$sthA->finish();
$agent_call_order='order by last_call_finish';
if ($CAMP_callorder =~ /overall_user_level/i) {$agent_call_order = 'order by user_level desc,last_call_finish';}
@@ -371,52 +382,57 @@ if ($channel_status < 1)
if ($CAMP_callorder =~ /oldest_call_finish/i) {$agent_call_order = 'order by last_call_finish';}
if ($CAMP_callorder =~ /random/i) {$agent_call_order = 'order by random_id';}
$rec_countWAIT=0;
$rec_countWAIT=0;
$cbc=0;
$stmtA = "SELECT count(*) FROM vicidial_auto_calls where status = 'LIVE' and server_ip='$server_ip' and campaign_id = '$channel_group' and call_time < \"$SQLdateBEGIN\" and lead_id != '$VDADlead_id';";
if($M){print out "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
if($M){print STDERR "\n\n|$stmtA|\n";}
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
while ( $record = $iter->each)
{
$rec_countWAIT = "$record->[0]";
}
@aryA = $sthA->fetchrow_array;
$rec_countWAIT = "$aryA[0]";
$cbc++;
}
$sthA->finish();
if ($rec_countWAIT < 1)
{
$stmtA = "UPDATE vicidial_live_agents set status='QUEUE',lead_id='$new_lead_id',uniqueid='$unique_id', channel='$channel', callerid='$callerid' where status IN('CLOSER','READY') and server_ip='$server_ip' and campaign_id LIKE \"%CLOSER%\" and closer_campaigns LIKE \"% $channel_group %\" and last_update_time > '$BDtsSQLdate' $agent_call_order limit 1;";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print out "-- VDAD get agent: |$DROP_TIME|$drop_timer|$affected_rows|update of vla table: $channel_group|$server_ip\n|$stmtA|\n";}
if ($affected_rows > 0)
{
$cbc=0;
$stmtA = "SELECT conf_exten,user,extension FROM vicidial_live_agents where status = 'QUEUE' and server_ip='$server_ip' and campaign_id LIKE \"%CLOSER%\" and callerid='$callerid' and channel='$channel' order by last_call_time limit 1;";
if($M){print out "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
if($M){print STDERR "\n\n|$stmtA|\n";}
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$rec_countCUSTDATA=0;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
$rec_countCUSTDATA=0;
while ( $record = $iter->each)
{
$VDADconf_exten = "$record->[0]";
$VDADuser = "$record->[1]";
$VDADextension = "$record->[2]";
}
@aryA = $sthA->fetchrow_array;
$VDADconf_exten = "$aryA[0]";
$VDADuser = "$aryA[1]";
$VDADextension = "$aryA[2]";
$cbc++;
}
$sthA->finish();
$stmtA = "UPDATE vicidial_auto_calls set status='CLOSER' where callerid='$callerid';";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print out "-- VDCL XFER : |$affected_rows|update of vac table: $callerid\n|$stmtA|\n";}
$stmtA = "UPDATE vicidial_closer_log set user='$VDADuser' where lead_id='$new_lead_id' order by call_date desc limit 1;";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print out "-- closer log : |$affected_rows|update of vcl table: $new_lead_id\n|$stmtA|\n";}
$dbhA->close;
$dbhA->disconnect();
print out "\nexiting the VDAD app, transferring call to $VDADconf_exten\n";
print "SET CONTEXT $ext_context\n";
@@ -442,6 +458,10 @@ if ($channel_status < 1)
close(out);
exit;
}
else
{
print STDERR "NNNNNNNNNN No agent record found!!!\n";
}
}
else
{
@@ -497,26 +517,29 @@ if ($drop_seconds < 1)
}
else
{
$cbc=0;
$stmtA = "SELECT voicemail_ext FROM vicidial_inbound_groups where group_id = '$channel_group' limit 1;";
if($M){print out "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
{
$iter=$dbhA->create_record_iterator;
$rec_countCUSTDATA=0;
while ( $record = $iter->each)
if($M){print STDERR "\n\n|$stmtA|\n";}
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$rec_countCUSTDATA=0;
while ($sthArows > $cbc)
{
$VDADvoicemail_ext = "$record->[0]";
$VDADvoicemail_ext = "$aryA[0]";
$VDADvoicemail_ext =~ s/\D//gi;
$DROPexten = "$voicemail_dump_exten$VDADvoicemail_ext";
}
}
$cbc++;
}
$sthA->finish();
}
}
### use STDOUT to send call to proper DROP location
$VHqueryCID = "VH$CIDdate$VDADconf_exten";
$VH{CID = "VH$CIDdate$VDADconf_exten";
if (length($DROPexten)>0)
{ ### if DROP extension is defined then send the dropped call there instead of hangup
@@ -531,39 +554,30 @@ if ($drop_seconds < 1)
else
{
### 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','','','','','','','','','')";
$dbhA->query($stmtA) or die "Couldn't execute query:\n";
if ($M) {print out "-- VDCL call_hungup timout: |$VHqueryCID|$VDADconf_exten|$channel|insert to vicidial_manager\n";}
$stmtA = "INSERT INTO vicidial_manager values('','','$SQLdate','NEW','N','$server_ip','','Hangup','$VH{CID','Channel: $channel','','','','','','','','','')";
$affected_rows = $dbhA->do($stmtA) or die "Couldn't execute {:\n";
if ($M) {print out "-- VDCL call_hungup timout: |$VH{CID|$VDADconf_exten|$channel|insert to vicidial_manager\n";}
}
$stmtA = "DELETE FROM vicidial_auto_calls where callerid='$callerid' and server_ip='$server_ip' order by call_time desc limit 1;";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print out "-- VDCL vac record deleted: |$affected_rows| $channel_group|$server_ip\n";}
# $stmtA = "UPDATE vicidial_log set status='DROP',end_epoch='$now_date_epoch',length_in_sec='$drop_seconds' where uniqueid = '$uniqueid';";
# if($M){print out "\n\n|$stmtA|\n";}
# $dbhA->query("$stmtA");
# my $affected_rows = $dbhA->get_affected_rows_length;
# if ($M) {print out "-- VDCL vicidial_log update: |$affected_rows|$uniqueid\n";}
$stmtA = "UPDATE vicidial_closer_log set status='DROP',end_epoch='$now_date_epoch',length_in_sec='$drop_seconds' where lead_id = '$new_lead_id' order by start_epoch desc limit 1;";
if($M){print out "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print out "-- VDCL vicidial_closer_log update: |$affected_rows|$new_lead_id\n";}
$stmtA = "UPDATE vicidial_list set status='XDROP' where lead_id = '$new_lead_id';";
if($M){print out "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print out "-- VDCL vicidial_list update: |$affected_rows|$new_lead_id\n";}
}
$dbhA->close;
$dbhA->disconnect();
close(out);
+124 -116
View File
@@ -1,6 +1,6 @@
#!/usr/bin/perl
#
# agi-VDADcloser_inboundCID.agi version 0.3
# agi-VDADcloser_inboundCID.agi version 0.4 *DBI-version*
#
# runs when a call comes in from an inbound call. This script will
# send the calls out to the closers that are logged in.
@@ -30,6 +30,7 @@
#
# changes:
# 60504-1241 - Added drop second/message/exten options from inbound_group
# 60811-1003 - Changed to DBI by Marin Blu
#
$V = 1; # set to 1 for verbose mode
@@ -40,7 +41,7 @@ $DROP_TIME = 360; ### number of seconds to wait until you drop a waiting call
### Make sure this file is in a path or put the absolute path to it
require("/home/cron/AST_SERVER_conf.pl"); # local configuration file
use Net::MySQL;
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;
@@ -241,86 +242,91 @@ exit;
if (!$DB_port) {$DB_port='3306';}
my $dbhA = Net::MySQL->new(hostname=>"$DB_server", database=>"$DB_database", user=>"$DB_user", password=>"$DB_pass", port => "$DB_port") or die "Couldn't connect to database: $DB_server - $DB_database\n";
my $dbhA = DBI->connect("DBI:mysql:$DB_database:$DB_server:$DB_port", "$DB_user", "$DB_pass")
or die "Couldn't connect to database: " . DBI->errstr;
### Grab Server values from the database
$cbc=0;
$stmtA = "SELECT voicemail_dump_exten,ext_context,answer_transfer_agent,local_gmt,asterisk_version,max_vicidial_trunks FROM servers where server_ip = '$server_ip';";
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
while ( $record = $iter->each)
{
$DBvoicemail_dump_exten = "$record->[0]";
$DBext_context = "$record->[1]";
$DBanswer_transfer_agent = "$record->[2]";
$DBSERVER_GMT = "$record->[3]";
$DBasterisk_version = "$record->[4]";
$DBmax_vicidial_trunks = "$record->[5]";
if ($DBvoicemail_dump_exten) {$voicemail_dump_exten = $DBvoicemail_dump_exten;}
if ($DBext_context) {$ext_context = $DBext_context;}
if ($DBanswer_transfer_agent) {$answer_transfer_agent = $DBanswer_transfer_agent;}
if ($DBSERVER_GMT) {$SERVER_GMT = $DBSERVER_GMT;}
if ($DBasterisk_version) {$AST_ver = $DBasterisk_version;}
if ($DBmax_vicidial_trunks) {$max_vicidial_trunks = $DBmax_vicidial_trunks;}
}
@aryA = $sthA->fetchrow_array;
$DBvoicemail_dump_exten = "$aryA[0]";
$DBext_context = "$aryA[1]";
$DBanswer_transfer_agent = "$aryA[2]";
$DBSERVER_GMT = "$aryA[3]";
$DBasterisk_version = "$aryA[4]";
$DBmax_vicidial_trunks = "$aryA[5]";
if ($DBvoicemail_dump_exten) {$voicemail_dump_exten = $DBvoicemail_dump_exten;}
if ($DBext_context) {$ext_context = $DBext_context;}
if ($DBanswer_transfer_agent) {$answer_transfer_agent = $DBanswer_transfer_agent;}
if ($DBSERVER_GMT) {$SERVER_GMT = $DBSERVER_GMT;}
if ($DBasterisk_version) {$AST_ver = $DBasterisk_version;}
if ($DBmax_vicidial_trunks) {$max_vicidial_trunks = $DBmax_vicidial_trunks;}
$cbc++;
}
$sthA->finish();
### insert a record into the vicidial_list table
$stmtA = "INSERT INTO vicidial_list (entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,called_since_last_reset,phone_code,phone_number,security_phrase,called_count,gmt_offset_now,comments) values('$SQLdate','$tsSQLdate','INBND','$fronter','$channel_group','VDCL','$list_id','Y','$phone_code','$phone_number','$channel_group','1','-5.00','$VLcomments');";
$dbhA->query($stmtA);
$dbhA->query("select LAST_INSERT_ID() LIMIT 1;");
if ($dbhA->has_selected_record)
$affected_rows = $dbhA->do($stmtA);
$cbc=0;
$stmtA = "select LAST_INSERT_ID() LIMIT 1;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $cbc)
{
$iterA=$dbhA->create_record_iterator;
while ($recordA = $iterA->each)
{$insert_lead_id = "$recordA->[0]";}
@aryA = $sthA->fetchrow_array;
$insert_lead_id = "$aryA[0]";
$cbc++;
}
$sthA->finish();
$new_lead_id = $insert_lead_id;
if($M){print STDERR "\n|$stmtA|$new_lead_id|\n";}
$PADlead_id = sprintf("%09s", $new_lead_id); while (length($PADlead_id) > 9) {chop($PADlead_id);}
# YmmddhhmmssLLLLLLLLL
$YqueryCID = "Y$CIDdate$PADlead_id";
$callerid = $YqueryCID;
### set the callerid
print "SET CALLERID $YqueryCID\n";
checkresult($result);
print STDERR "callerID changed: $YqueryCID\n";
$PADlead_id = sprintf("%09s", $new_lead_id); while (length($PADlead_id) > 9) {chop($PADlead_id);}
# YmmddhhmmssLLLLLLLLL
$YqueryCID = "Y$CIDdate$PADlead_id";
$callerid = $YqueryCID;
### set the callerid
print "SET CALLERID $YqueryCID\n";
checkresult($result);
print STDERR "callerID changed: $YqueryCID\n";
### Grab inbound_group values from the database
$cbc=0;
$stmtA = "SELECT drop_call_seconds,drop_message,drop_exten FROM vicidial_inbound_groups where group_id = '$channel_group';";
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
while ( $record = $iter->each)
{
$DBdrop_call_seconds = "$record->[0]";
$DBdrop_message = "$record->[1]";
$DBdrop_exten = "$record->[2]";
if ($DBdrop_call_seconds) {$DROP_TIME = $DBdrop_call_seconds;}
if ($DBdrop_message) {$drop_message = $DBdrop_message;}
if ($DBdrop_exten) {$drop_exten = $DBdrop_exten;}
}
@aryA = $sthA->fetchrow_array;
$DBdrop_call_seconds = "$aryA[0]";
$DBdrop_message = "$aryA[1]";
$DBdrop_exten = "$aryA[2]";
if ($DBdrop_call_seconds) {$DROP_TIME = $DBdrop_call_seconds;}
if ($DBdrop_message) {$drop_message = $DBdrop_message;}
if ($DBdrop_exten) {$drop_exten = $DBdrop_exten;}
$cbc++;
}
$sthA->finish();
### insert a LIVE record to the vicidial_auto_calls table
$stmtA = "INSERT INTO vicidial_auto_calls values('','$server_ip','$channel_group','LIVE','$new_lead_id','$uniqueid','$callerid','$channel','$phone_code','$phone_number','$SQLdate','IN')";
$dbhA->query($stmtA);
$affected_rows = $dbhA->do($stmtA);
if($M){print STDERR "\n|$stmtA|\n";}
# $stmtA = "INSERT INTO vicidial_log (uniqueid,lead_id,campaign_id,call_date,start_epoch,status,phone_code,phone_number,user,processed) values('$uniqueid','$new_lead_id','$channel_group','$SQLdate','$now_date_epoch','QUEUE','$phone_code','$phone_number','VDCL','N')";
# if($M){print STDERR "\n|$stmtA|\n";}
# $dbhA->query($stmtA);
# if ($M) {print STDERR "-- VDAD : |$VDADlead_id|$new_lead_id|insert to vicidial_log: $uniqueid\n";}
$stmtA = "INSERT INTO vicidial_closer_log (lead_id,campaign_id,call_date,start_epoch,status,phone_code,phone_number,user,processed) values('$new_lead_id','$channel_group','$SQLdate','$now_date_epoch','QUEUE','$phone_code','$phone_number','VDCL','N')";
if($M){print STDERR "\n|$stmtA|\n";}
$dbhA->query($stmtA);
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL : |$new_lead_id|insert to vicidial_closer_log\n";}
$VDADlead_id = $new_lead_id;
@@ -348,17 +354,20 @@ if ($channel_status < 1)
$drop_timer = ($drop_timer + 360);
}
}
$cbc=0;
$stmtA = "SELECT next_agent_call FROM vicidial_inbound_groups where group_id='$channel_group';";
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$rec_countCUSTDATA=0;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
$rec_countCUSTDATA=0;
while ( $record = $iter->each)
{
$CAMP_callorder = "$record->[0]";
}
@aryA = $sthA->fetchrow_array;
$CAMP_callorder = "$aryA[0]";
$cbc++;
}
$sthA->finish();
$agent_call_order='order by last_call_finish';
if ($CAMP_callorder =~ /overall_user_level/i) {$agent_call_order = 'order by user_level desc,last_call_finish';}
@@ -366,52 +375,57 @@ if ($channel_status < 1)
if ($CAMP_callorder =~ /oldest_call_finish/i) {$agent_call_order = 'order by last_call_finish';}
if ($CAMP_callorder =~ /random/i) {$agent_call_order = 'order by random_id';}
$rec_countWAIT=0;
$rec_countWAIT=0;
$cbc=0;
$stmtA = "SELECT count(*) FROM vicidial_auto_calls where status = 'LIVE' and server_ip='$server_ip' and campaign_id = '$channel_group' and call_time < \"$SQLdateBEGIN\" and lead_id != '$VDADlead_id';";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
while ( $record = $iter->each)
{
$rec_countWAIT = "$record->[0]";
}
@aryA = $sthA->fetchrow_array;
$rec_countWAIT = "$aryA[0]";
$cbc++;
}
$sthA->finish();
if ($rec_countWAIT < 1)
{
$stmtA = "UPDATE vicidial_live_agents set status='QUEUE',lead_id='$new_lead_id',uniqueid='$unique_id', channel='$channel', callerid='$callerid' where status IN('CLOSER','READY') and server_ip='$server_ip' and campaign_id LIKE \"%CLOSER%\" and closer_campaigns LIKE \"% $channel_group %\" and last_update_time > '$BDtsSQLdate' $agent_call_order limit 1;";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD get agent: |$DROP_TIME|$drop_timer|$affected_rows|update of vla table: $channel_group|$server_ip\n|$stmtA|\n";}
if ($affected_rows > 0)
{
$cbc=0;
$stmtA = "SELECT conf_exten,user,extension FROM vicidial_live_agents where status = 'QUEUE' and server_ip='$server_ip' and campaign_id LIKE \"%CLOSER%\" and callerid='$callerid' and channel='$channel' order by last_call_time limit 1;";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$rec_countCUSTDATA=0;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
$rec_countCUSTDATA=0;
while ( $record = $iter->each)
{
$VDADconf_exten = "$record->[0]";
$VDADuser = "$record->[1]";
$VDADextension = "$record->[2]";
}
@aryA = $sthA->fetchrow_array;
$VDADconf_exten = "$aryA[0]";
$VDADuser = "$aryA[1]";
$VDADextension = "$aryA[2]";
$cbc++;
}
$sthA->finish();
$stmtA = "UPDATE vicidial_auto_calls set status='CLOSER' where callerid='$callerid';";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL XFER : |$affected_rows|update of vac table: $callerid\n|$stmtA|\n";}
$stmtA = "UPDATE vicidial_closer_log set user='$VDADuser' where lead_id='$new_lead_id' order by call_date desc limit 1;";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- closer log : |$affected_rows|update of vcl table: $new_lead_id\n|$stmtA|\n";}
$dbhA->close;
$dbhA->disconnect();
print STDERR "\nexiting the VDAD app, transferring call to $VDADconf_exten\n";
print "SET CONTEXT $ext_context\n";
@@ -436,6 +450,10 @@ if ($channel_status < 1)
exit;
}
else
{
print STDERR "NNNNNNNNNN No agent record found!!!\n";
}
}
else
{
@@ -491,20 +509,23 @@ if ($drop_seconds < 1)
}
else
{
$cbc=0;
$stmtA = "SELECT voicemail_ext FROM vicidial_inbound_groups where group_id = '$channel_group' limit 1;";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
{
$iter=$dbhA->create_record_iterator;
$rec_countCUSTDATA=0;
while ( $record = $iter->each)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$rec_countCUSTDATA=0;
while ($sthArows > $cbc)
{
$VDADvoicemail_ext = "$record->[0]";
$VDADvoicemail_ext = "$aryA[0]";
$VDADvoicemail_ext =~ s/\D//gi;
$DROPexten = "$voicemail_dump_exten$VDADvoicemail_ext";
}
}
$cbc++;
}
$sthA->finish();
}
}
@@ -526,40 +547,27 @@ if ($drop_seconds < 1)
{
### 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','','','','','','','','','')";
$dbhA->query($stmtA) or die "Couldn't execute query:\n";
$affected_rows = $dbhA->do($stmtA) or die "Couldn't execute query:\n";
if ($M) {print STDERR "-- VDCL call_hungup timout: |$VHqueryCID|$VDADconf_exten|$channel|insert to vicidial_manager\n";}
}
$stmtA = "DELETE FROM vicidial_auto_calls where callerid='$callerid' and server_ip='$server_ip' order by call_time desc limit 1;";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL vac record deleted: |$affected_rows| $channel_group|$server_ip\n";}
# $stmtA = "UPDATE vicidial_log set status='DROP',end_epoch='$now_date_epoch',length_in_sec='$drop_seconds' where uniqueid = '$uniqueid';";
# if($M){print STDERR "\n\n|$stmtA|\n";}
# $dbhA->query("$stmtA");
# my $affected_rows = $dbhA->get_affected_rows_length;
# if ($M) {print STDERR "-- VDCL vicidial_log update: |$affected_rows|$uniqueid\n";}
$stmtA = "UPDATE vicidial_closer_log set status='DROP',end_epoch='$now_date_epoch',length_in_sec='$drop_seconds' where lead_id = '$new_lead_id' order by start_epoch desc limit 1;";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL vicidial_closer_log update: |$affected_rows|$new_lead_id\n";}
$stmtA = "UPDATE vicidial_list set status='XDROP' where lead_id = '$new_lead_id';";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL vicidial_list update: |$affected_rows|$new_lead_id\n";}
}
$dbhA->close;
$dbhA->disconnect();
exit;
@@ -1,6 +1,6 @@
#!/usr/bin/perl
#
# agi-VDADcloser_inboundCID.agi version 0.3
# agi-VDADcloser_inboundCID.agi version 0.4 *DBI-version*
#
# runs when a call comes in from an inbound call. This script will
# send the calls out to the closers that are logged in.
@@ -30,6 +30,7 @@
#
# changes:
# 60504-1242 - Added drop second/message/exten options from inbound_group
# 60811-1003 - Changed to DBI by Marin Blu
#
$V = 1; # set to 1 for verbose mode
@@ -40,7 +41,7 @@ $DROP_TIME = 360; ### number of seconds to wait until you drop a waiting call
### Make sure this file is in a path or put the absolute path to it
require("/home/cron/AST_SERVER_conf.pl"); # local configuration file
use Net::MySQL;
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;
@@ -241,99 +242,115 @@ exit;
if (!$DB_port) {$DB_port='3306';}
my $dbhA = Net::MySQL->new(hostname=>"$DB_server", database=>"$DB_database", user=>"$DB_user", password=>"$DB_pass", port => "$DB_port") or die "Couldn't connect to database: $DB_server - $DB_database\n";
my $dbhA = DBI->connect("DBI:mysql:$DB_database:$DB_server:$DB_port", "$DB_user", "$DB_pass")
or die "Couldn't connect to database: " . DBI->errstr;
### Grab Server values from the database
$cbc=0;
$stmtA = "SELECT voicemail_dump_exten,ext_context,answer_transfer_agent,local_gmt,asterisk_version,max_vicidial_trunks FROM servers where server_ip = '$server_ip';";
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
while ( $record = $iter->each)
{
$DBvoicemail_dump_exten = "$record->[0]";
$DBext_context = "$record->[1]";
$DBanswer_transfer_agent = "$record->[2]";
$DBSERVER_GMT = "$record->[3]";
$DBasterisk_version = "$record->[4]";
$DBmax_vicidial_trunks = "$record->[5]";
if ($DBvoicemail_dump_exten) {$voicemail_dump_exten = $DBvoicemail_dump_exten;}
if ($DBext_context) {$ext_context = $DBext_context;}
if ($DBanswer_transfer_agent) {$answer_transfer_agent = $DBanswer_transfer_agent;}
if ($DBSERVER_GMT) {$SERVER_GMT = $DBSERVER_GMT;}
if ($DBasterisk_version) {$AST_ver = $DBasterisk_version;}
if ($DBmax_vicidial_trunks) {$max_vicidial_trunks = $DBmax_vicidial_trunks;}
}
@aryA = $sthA->fetchrow_array;
$DBvoicemail_dump_exten = "$aryA[0]";
$DBext_context = "$aryA[1]";
$DBanswer_transfer_agent = "$aryA[2]";
$DBSERVER_GMT = "$aryA[3]";
$DBasterisk_version = "$aryA[4]";
$DBmax_vicidial_trunks = "$aryA[5]";
if ($DBvoicemail_dump_exten) {$voicemail_dump_exten = $DBvoicemail_dump_exten;}
if ($DBext_context) {$ext_context = $DBext_context;}
if ($DBanswer_transfer_agent) {$answer_transfer_agent = $DBanswer_transfer_agent;}
if ($DBSERVER_GMT) {$SERVER_GMT = $DBSERVER_GMT;}
if ($DBasterisk_version) {$AST_ver = $DBasterisk_version;}
if ($DBmax_vicidial_trunks) {$max_vicidial_trunks = $DBmax_vicidial_trunks;}
$cbc++;
}
$sthA->finish();
$cbc=0;
$stmtA= "SELECT lead_id from vicidial_list where list_id='$list_id' and phone_number='$phone_number' order by modify_date limit 1;"
$dbhA->query($stmtA);
if ($dbhA->has_selected_record)
{
$iter=$dbhA->create_record_iterator;
$rec_countCUSTDATA=0;
while ( $record = $iter->each)
{
$insert_lead_id = "$record->[0]";
}
} else {
### insert a record into the vicidial_list table
$stmtA = "INSERT INTO vicidial_list (entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,called_since_last_reset,phone_code,phone_number,security_phrase,called_count,gmt_offset_now,comments) values('$SQLdate','$tsSQLdate','INBND','$fronter','$channel_group','VDCL','$list_id','Y','$phone_code','$phone_number','$channel_group','1','-5.00','$VLcomments');";
$dbhA->query($stmtA);
$dbhA->query("select LAST_INSERT_ID() LIMIT 1;");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
if ($sthArows > 0)
{
$rec_countCUSTDATA=0;
$iter=$dbhA->create_record_iterator;
$rec_countCUSTDATA=0;
while ($sthArows > $cbc)
{
$iterA=$dbhA->create_record_iterator;
while ($recordA = $iterA->each)
{$insert_lead_id = "$recordA->[0]";}
}
@aryA = $sthA->fetchrow_array;
$insert_lead_id = "$aryA[0]";
$cbc++;
}
$sthA->finish();
}
else
{
### insert a record into the vicidial_list table
$stmtA = "INSERT INTO vicidial_list (entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,called_since_last_reset,phone_code,phone_number,security_phrase,called_count,gmt_offset_now,comments) values('$SQLdate','$tsSQLdate','INBND','$fronter','$channel_group','VDCL','$list_id','Y','$phone_code','$phone_number','$channel_group','1','-5.00','$VLcomments');";
$affected_rows = $dbhA->do($stmtA);
$cbc=0;
$stmtA = "select LAST_INSERT_ID() LIMIT 1;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $cbc)
{
@aryA = $sthA->fetchrow_array;
$insert_lead_id = "$aryA[0]";
$cbc++;
}
$sthA->finish();
}
$new_lead_id = $insert_lead_id;
if($M){print STDERR "\n|$stmtA|$new_lead_id|\n";}
$PADlead_id = sprintf("%09s", $new_lead_id); while (length($PADlead_id) > 9) {chop($PADlead_id);}
# YmmddhhmmssLLLLLLLLL
$YqueryCID = "Y$CIDdate$PADlead_id";
$callerid = $YqueryCID;
### set the callerid
print "SET CALLERID $YqueryCID\n";
checkresult($result);
print STDERR "callerID changed: $YqueryCID\n";
$PADlead_id = sprintf("%09s", $new_lead_id); while (length($PADlead_id) > 9) {chop($PADlead_id);}
# YmmddhhmmssLLLLLLLLL
$YqueryCID = "Y$CIDdate$PADlead_id";
$callerid = $YqueryCID;
### set the callerid
print "SET CALLERID $YqueryCID\n";
checkresult($result);
print STDERR "callerID changed: $YqueryCID\n";
### Grab inbound_group values from the database
$stmtA = "SELECT drop_call_seconds,drop_message,drop_exten FROM vicidial_inbound_groups where group_id = '$channel_group';";
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$cbc=0;
$stmtA = "SELECT drop_call_seconds,drop_message,drop_exten FROM vicidial_inbound_groups where group_id = '$channel_group';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
while ( $record = $iter->each)
{
$DBdrop_call_seconds = "$record->[0]";
$DBdrop_message = "$record->[1]";
$DBdrop_exten = "$record->[2]";
if ($DBdrop_call_seconds) {$DROP_TIME = $DBdrop_call_seconds;}
if ($DBdrop_message) {$drop_message = $DBdrop_message;}
if ($DBdrop_exten) {$drop_exten = $DBdrop_exten;}
}
@aryA = $sthA->fetchrow_array;
$DBdrop_call_seconds = "$aryA[0]";
$DBdrop_message = "$aryA[1]";
$DBdrop_exten = "$aryA[2]";
if ($DBdrop_call_seconds) {$DROP_TIME = $DBdrop_call_seconds;}
if ($DBdrop_message) {$drop_message = $DBdrop_message;}
if ($DBdrop_exten) {$drop_exten = $DBdrop_exten;}
$cbc++;
}
$sthA->finish();
### insert a LIVE record to the vicidial_auto_calls table
$stmtA = "INSERT INTO vicidial_auto_calls values('','$server_ip','$channel_group','LIVE','$new_lead_id','$uniqueid','$callerid','$channel','$phone_code','$phone_number','$SQLdate','IN')";
$dbhA->query($stmtA);
$affected_rows = $dbhA->do($stmtA);
if($M){print STDERR "\n|$stmtA|\n";}
# $stmtA = "INSERT INTO vicidial_log (uniqueid,lead_id,campaign_id,call_date,start_epoch,status,phone_code,phone_number,user,processed) values('$uniqueid','$new_lead_id','$channel_group','$SQLdate','$now_date_epoch','QUEUE','$phone_code','$phone_number','VDCL','N')";
# if($M){print STDERR "\n|$stmtA|\n";}
# $dbhA->query($stmtA);
# if ($M) {print STDERR "-- VDAD : |$VDADlead_id|$new_lead_id|insert to vicidial_log: $uniqueid\n";}
$stmtA = "INSERT INTO vicidial_closer_log (lead_id,campaign_id,call_date,start_epoch,status,phone_code,phone_number,user,processed) values('$new_lead_id','$channel_group','$SQLdate','$now_date_epoch','QUEUE','$phone_code','$phone_number','VDCL','N')";
if($M){print STDERR "\n|$stmtA|\n";}
$dbhA->query($stmtA);
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL : |$new_lead_id|insert to vicidial_closer_log\n";}
$VDADlead_id = $new_lead_id;
@@ -361,17 +378,20 @@ if ($channel_status < 1)
$drop_timer = ($drop_timer + 360);
}
}
$cbc=0;
$stmtA = "SELECT next_agent_call FROM vicidial_inbound_groups where group_id='$channel_group';";
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$rec_countCUSTDATA=0;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
$rec_countCUSTDATA=0;
while ( $record = $iter->each)
{
$CAMP_callorder = "$record->[0]";
}
$rec_countCUSTDATA=0;
@aryA = $sthA->fetchrow_array;
$CAMP_callorder = "$aryA[0]";
$cbc++;
}
$sthA->finish();
$agent_call_order='order by last_call_finish';
if ($CAMP_callorder =~ /overall_user_level/i) {$agent_call_order = 'order by user_level desc,last_call_finish';}
@@ -379,52 +399,57 @@ if ($channel_status < 1)
if ($CAMP_callorder =~ /oldest_call_finish/i) {$agent_call_order = 'order by last_call_finish';}
if ($CAMP_callorder =~ /random/i) {$agent_call_order = 'order by random_id';}
$rec_countWAIT=0;
$rec_countWAIT=0;
$cbc=0;
$stmtA = "SELECT count(*) FROM vicidial_auto_calls where status = 'LIVE' and server_ip='$server_ip' and campaign_id = '$channel_group' and call_time < \"$SQLdateBEGIN\" and lead_id != '$VDADlead_id';";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
while ( $record = $iter->each)
{
$rec_countWAIT = "$record->[0]";
}
@aryA = $sthA->fetchrow_array;
$rec_countWAIT = "$aryA[0]";
$cbc++;
}
$sthA->finish();
if ($rec_countWAIT < 1)
{
$stmtA = "UPDATE vicidial_live_agents set status='QUEUE',lead_id='$new_lead_id',uniqueid='$unique_id', channel='$channel', callerid='$callerid' where status IN('CLOSER','READY') and server_ip='$server_ip' and campaign_id LIKE \"%CLOSER%\" and closer_campaigns LIKE \"% $channel_group %\" and last_update_time > '$BDtsSQLdate' $agent_call_order limit 1;";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD get agent: |$DROP_TIME|$drop_timer|$affected_rows|update of vla table: $channel_group|$server_ip\n|$stmtA|\n";}
if ($affected_rows > 0)
{
$cbc=0;
$stmtA = "SELECT conf_exten,user,extension FROM vicidial_live_agents where status = 'QUEUE' and server_ip='$server_ip' and campaign_id LIKE \"%CLOSER%\" and callerid='$callerid' and channel='$channel' order by last_call_time limit 1;";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$rec_countCUSTDATA=0;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
$rec_countCUSTDATA=0;
while ( $record = $iter->each)
{
$VDADconf_exten = "$record->[0]";
$VDADuser = "$record->[1]";
$VDADextension = "$record->[2]";
}
@aryA = $sthA->fetchrow_array;
$VDADconf_exten = "$aryA[0]";
$VDADuser = "$aryA[1]";
$VDADextension = "$aryA[2]";
$cbc++;
}
$sthA->finish();
$stmtA = "UPDATE vicidial_auto_calls set status='CLOSER' where callerid='$callerid';";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL XFER : |$affected_rows|update of vac table: $callerid\n|$stmtA|\n";}
$stmtA = "UPDATE vicidial_closer_log set user='$VDADuser' where lead_id='$new_lead_id' order by call_date desc limit 1;";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- closer log : |$affected_rows|update of vcl table: $new_lead_id\n|$stmtA|\n";}
$dbhA->close;
$dbhA->disconnect();
print STDERR "\nexiting the VDAD app, transferring call to $VDADconf_exten\n";
print "SET CONTEXT $ext_context\n";
@@ -449,6 +474,10 @@ if ($channel_status < 1)
exit;
}
else
{
print STDERR "NNNNNNNNNN No agent record found!!!\n";
}
}
else
{
@@ -504,20 +533,23 @@ if ($drop_seconds < 1)
}
else
{
$cbc=0;
$stmtA = "SELECT voicemail_ext FROM vicidial_inbound_groups where group_id = '$channel_group' limit 1;";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
{
$iter=$dbhA->create_record_iterator;
$rec_countCUSTDATA=0;
while ( $record = $iter->each)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$rec_countCUSTDATA=0;
while ($sthArows > $cbc)
{
$VDADvoicemail_ext = "$record->[0]";
$VDADvoicemail_ext = "$aryA[0]";
$VDADvoicemail_ext =~ s/\D//gi;
$DROPexten = "$voicemail_dump_exten$VDADvoicemail_ext";
}
}
$cbc++;
}
$sthA->finish();
}
}
@@ -539,38 +571,29 @@ if ($drop_seconds < 1)
{
### 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','','','','','','','','','')";
$dbhA->query($stmtA) or die "Couldn't execute query:\n";
$affected_rows = $dbhA->do($stmtA) or die "Couldn't execute query:\n";
if ($M) {print STDERR "-- VDCL call_hungup timout: |$VHqueryCID|$VDADconf_exten|$channel|insert to vicidial_manager\n";}
}
$stmtA = "DELETE FROM vicidial_auto_calls where callerid='$callerid' and server_ip='$server_ip' order by call_time desc limit 1;";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL vac record deleted: |$affected_rows| $channel_group|$server_ip\n";}
# $stmtA = "UPDATE vicidial_log set status='DROP',end_epoch='$now_date_epoch',length_in_sec='$drop_seconds' where uniqueid = '$uniqueid';";
# if($M){print STDERR "\n\n|$stmtA|\n";}
# $dbhA->query("$stmtA");
# my $affected_rows = $dbhA->get_affected_rows_length;
# if ($M) {print STDERR "-- VDCL vicidial_log update: |$affected_rows|$uniqueid\n";}
$stmtA = "UPDATE vicidial_closer_log set status='DROP',end_epoch='$now_date_epoch',length_in_sec='$drop_seconds' where lead_id = '$new_lead_id' order by start_epoch desc limit 1;";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL vicidial_closer_log update: |$affected_rows|$new_lead_id\n";}
$stmtA = "UPDATE vicidial_list set status='XDROP' where lead_id = '$new_lead_id';";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL vicidial_list update: |$affected_rows|$new_lead_id\n";}
}
$dbhA->close;
$dbhA->disconnect();
+132 -124
View File
@@ -1,6 +1,6 @@
#!/usr/bin/perl
#
# agi-VDADcloser_inbound.agi version 0.3
# agi-VDADcloser_inbound.agi version 0.4 *DBI-version*
#
# runs when a call comes in from an inbound call. This script will
# send the calls out to the closers that are logged in.
@@ -29,6 +29,7 @@
#
# changes:
# 60504-1236 - Added drop second/message/exten options from inbound_group
# 60811-1003 - Changed to DBI by Marin Blu
#
$V = 1; # set to 1 for verbose mode
@@ -39,7 +40,7 @@ $DROP_TIME = 360; ### number of seconds to wait until you drop a waiting call
### Make sure this file is in a path or put the absolute path to it
require("/home/cron/AST_SERVER_conf.pl"); # local configuration file
use Net::MySQL;
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;
@@ -225,91 +226,100 @@ exit;
if (!$DB_port) {$DB_port='3306';}
my $dbhA = Net::MySQL->new(hostname=>"$DB_server", database=>"$DB_database", user=>"$DB_user", password=>"$DB_pass", port => "$DB_port") or die "Couldn't connect to database: $DB_server - $DB_database\n";
my $dbhA = DBI->connect("DBI:mysql:$DB_database:$DB_server:$DB_port", "$DB_user", "$DB_pass")
or die "Couldn't connect to database: " . DBI->errstr;
### Grab Server values from the database
$cbc=0;
$stmtA = "SELECT voicemail_dump_exten,ext_context,answer_transfer_agent,local_gmt,asterisk_version,max_vicidial_trunks FROM servers where server_ip = '$server_ip';";
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
while ( $record = $iter->each)
{
$DBvoicemail_dump_exten = "$record->[0]";
$DBext_context = "$record->[1]";
$DBanswer_transfer_agent = "$record->[2]";
$DBSERVER_GMT = "$record->[3]";
$DBasterisk_version = "$record->[4]";
$DBmax_vicidial_trunks = "$record->[5]";
if ($DBvoicemail_dump_exten) {$voicemail_dump_exten = $DBvoicemail_dump_exten;}
if ($DBext_context) {$ext_context = $DBext_context;}
if ($DBanswer_transfer_agent) {$answer_transfer_agent = $DBanswer_transfer_agent;}
if ($DBSERVER_GMT) {$SERVER_GMT = $DBSERVER_GMT;}
if ($DBasterisk_version) {$AST_ver = $DBasterisk_version;}
if ($DBmax_vicidial_trunks) {$max_vicidial_trunks = $DBmax_vicidial_trunks;}
}
@aryA = $sthA->fetchrow_array;
$DBvoicemail_dump_exten = "$aryA[0]";
$DBext_context = "$aryA[1]";
$DBanswer_transfer_agent = "$aryA[2]";
$DBSERVER_GMT = "$aryA[3]";
$DBasterisk_version = "$aryA[4]";
$DBmax_vicidial_trunks = "$aryA[5]";
if ($DBvoicemail_dump_exten) {$voicemail_dump_exten = $DBvoicemail_dump_exten;}
if ($DBext_context) {$ext_context = $DBext_context;}
if ($DBanswer_transfer_agent) {$answer_transfer_agent = $DBanswer_transfer_agent;}
if ($DBSERVER_GMT) {$SERVER_GMT = $DBSERVER_GMT;}
if ($DBasterisk_version) {$AST_ver = $DBasterisk_version;}
if ($DBmax_vicidial_trunks) {$max_vicidial_trunks = $DBmax_vicidial_trunks;}
$cbc++;
}
$sthA->finish();
### insert a record into the vicidial_list table
$stmtA = "INSERT INTO vicidial_list (entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,called_since_last_reset,phone_code,phone_number,security_phrase,called_count,gmt_offset_now) values('$SQLdate','$tsSQLdate','INBND','$fronter','$channel_group','VDCL','$list_id','Y','$phone_code','$phone_number','$channel_group','1','-5.00');";
$dbhA->query($stmtA);
$dbhA->query("select LAST_INSERT_ID() LIMIT 1;");
if ($dbhA->has_selected_record)
$affected_rows = $dbhA->do($stmtA);
$cbc=0;
$stmtA = "select LAST_INSERT_ID() LIMIT 1;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $cbc)
{
$iterA=$dbhA->create_record_iterator;
while ($recordA = $iterA->each)
{$insert_lead_id = "$recordA->[0]";}
@aryA = $sthA->fetchrow_array;
$insert_lead_id = "$aryA[0]";
$cbc++;
}
$sthA->finish();
$new_lead_id = $insert_lead_id;
if($M){print STDERR "\n|$stmtA|$new_lead_id|\n";}
$PADlead_id = sprintf("%09s", $new_lead_id); while (length($PADlead_id) > 9) {chop($PADlead_id);}
# YmmddhhmmssLLLLLLLLL
$YqueryCID = "Y$CIDdate$PADlead_id";
$callerid = $YqueryCID;
### set the callerid
print "SET CALLERID $YqueryCID\n";
checkresult($result);
print STDERR "callerID changed: $YqueryCID\n";
$PADlead_id = sprintf("%09s", $new_lead_id); while (length($PADlead_id) > 9) {chop($PADlead_id);}
# YmmddhhmmssLLLLLLLLL
$YqueryCID = "Y$CIDdate$PADlead_id";
$callerid = $YqueryCID;
### set the callerid
print "SET CALLERID $YqueryCID\n";
checkresult($result);
print STDERR "callerID changed: $YqueryCID\n";
### Grab inbound_group values from the database
$cbc=0;
$stmtA = "SELECT drop_call_seconds,drop_message,drop_exten FROM vicidial_inbound_groups where group_id = '$channel_group';";
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
while ( $record = $iter->each)
{
$DBdrop_call_seconds = "$record->[0]";
$DBdrop_message = "$record->[1]";
$DBdrop_exten = "$record->[2]";
if ($DBdrop_call_seconds) {$DROP_TIME = $DBdrop_call_seconds;}
if ($DBdrop_message) {$drop_message = $DBdrop_message;}
if ($DBdrop_exten) {$drop_exten = $DBdrop_exten;}
}
@aryA = $sthA->fetchrow_array;
$DBdrop_call_seconds = "$aryA[0]";
$DBdrop_message = "$aryA[1]";
$DBdrop_exten = "$aryA[2]";
if ($DBdrop_call_seconds) {$DROP_TIME = $DBdrop_call_seconds;}
if ($DBdrop_message) {$drop_message = $DBdrop_message;}
if ($DBdrop_exten) {$drop_exten = $DBdrop_exten;}
$cbc++;
}
$sthA->finish();
### insert a LIVE record to the vicidial_auto_calls table
$stmtA = "INSERT INTO vicidial_auto_calls values('','$server_ip','$channel_group','LIVE','$new_lead_id','$uniqueid','$callerid','$channel','$phone_code','$phone_number','$SQLdate','IN')";
$dbhA->query($stmtA);
$affected_rows = $dbhA->do($stmtA);
if($M){print STDERR "\n|$stmtA|\n";}
$stmtA = "INSERT INTO vicidial_log (uniqueid,lead_id,campaign_id,call_date,start_epoch,status,phone_code,phone_number,user,processed) values('$uniqueid','$new_lead_id','$channel_group','$SQLdate','$now_date_epoch','XFER','$phone_code','$phone_number','$fronter','N')";
if($M){print STDERR "\n|$stmtA|\n";}
$dbhA->query($stmtA);
if ($M) {print STDERR "-- VDAD : |$new_lead_id|$fronter|insert to vicidial_log: $uniqueid\n";}
$stmtA = "INSERT INTO vicidial_log (uniqueid,lead_id,campaign_id,call_date,start_epoch,status,phone_code,phone_number,user,processed) values('$uniqueid','$new_lead_id','$channel_group','$SQLdate','$now_date_epoch','XFER','$phone_code','$phone_number','$fronter','N')";
if($M){print STDERR "\n|$stmtA|\n";}
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD : |$new_lead_id|$fronter|insert to vicidial_log: $uniqueid\n";}
$stmtA = "INSERT INTO vicidial_closer_log (lead_id,campaign_id,call_date,start_epoch,status,phone_code,phone_number,user,processed) values('$new_lead_id','$channel_group','$SQLdate','$now_date_epoch','QUEUE','$phone_code','$phone_number','VDCL','N')";
if($M){print STDERR "\n|$stmtA|\n";}
$dbhA->query($stmtA);
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL : |$new_lead_id|insert to vicidial_closer_log\n";}
$stmtA = "INSERT INTO vicidial_xfer_log (lead_id,campaign_id,call_date,phone_code,phone_number,user,closer) values('$new_lead_id','$channel_group','$SQLdate','$phone_code','$phone_number','$fronter','VDXL')";
if($M){print STDERR "\n|$stmtA|\n";}
$dbhA->query($stmtA);
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDXL : |$new_lead_id|insert to vicidial_closer_log\n";}
$VDADlead_id = $new_lead_id;
@@ -338,17 +348,19 @@ if ($channel_status < 1)
}
}
$cbc=0;
$stmtA = "SELECT next_agent_call FROM vicidial_inbound_groups where group_id='$channel_group';";
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$rec_countCUSTDATA=0;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
$rec_countCUSTDATA=0;
while ( $record = $iter->each)
{
$CAMP_callorder = "$record->[0]";
}
@aryA = $sthA->fetchrow_array;
$CAMP_callorder = "$aryA[0]";
$cbc++;
}
$sthA->finish();
$agent_call_order='order by last_call_finish';
if ($CAMP_callorder =~ /overall_user_level/i) {$agent_call_order = 'order by user_level desc,last_call_finish';}
@@ -356,62 +368,63 @@ if ($channel_status < 1)
if ($CAMP_callorder =~ /oldest_call_finish/i) {$agent_call_order = 'order by last_call_finish';}
if ($CAMP_callorder =~ /random/i) {$agent_call_order = 'order by random_id';}
$rec_countWAIT=0;
$rec_countWAIT=0;
$cbc=0;
$stmtA = "SELECT count(*) FROM vicidial_auto_calls where status = 'LIVE' and server_ip='$server_ip' and campaign_id = '$channel_group' and call_time < \"$SQLdateBEGIN\" and lead_id != '$VDADlead_id';";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
while ( $record = $iter->each)
{
$rec_countWAIT = "$record->[0]";
}
@aryA = $sthA->fetchrow_array;
$rec_countWAIT = "$aryA[0]";
$cbc++;
}
$sthA->finish();
if ($rec_countWAIT < 1)
{
$stmtA = "UPDATE vicidial_live_agents set status='QUEUE',lead_id='$new_lead_id',uniqueid='$unique_id', channel='$channel', callerid='$callerid' where status IN('CLOSER','READY') and server_ip='$server_ip' and campaign_id LIKE \"%CLOSER%\" and closer_campaigns LIKE \"% $channel_group %\" and last_update_time > '$BDtsSQLdate' $agent_call_order limit 1;";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD get agent: |$DROP_TIME|$drop_timer|$affected_rows|update of vla table: $channel_group|$server_ip\n";}
# if ($M) {print STDERR "|$stmtA|\n";}
if ($affected_rows > 0)
{
$cbc=0;
$stmtA = "SELECT conf_exten,user,extension FROM vicidial_live_agents where status = 'QUEUE' and server_ip='$server_ip' and campaign_id LIKE \"%CLOSER%\" and callerid='$callerid' and channel='$channel' order by last_call_time limit 1;";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$rec_countCUSTDATA=0;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
$rec_countCUSTDATA=0;
while ( $record = $iter->each)
{
$VDADconf_exten = "$record->[0]";
$VDADuser = "$record->[1]";
$VDADextension = "$record->[2]";
}
}
else
{
print STDERR "NNNNNNNNNN No agent record found!!!\n";
@aryA = $sthA->fetchrow_array;
$VDADconf_exten = "$aryA[0]";
$VDADuser = "$aryA[1]";
$VDADextension = "$aryA[2]";
$cbc++;
}
$sthA->finish();
$stmtA = "UPDATE vicidial_auto_calls set status='CLOSER' where callerid='$callerid';";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL XFER : |$affected_rows|update of vac table: $callerid\n|$stmtA|\n";}
$stmtA = "UPDATE vicidial_xfer_log set closer='$VDADuser' where lead_id = '$new_lead_id' order by call_date desc limit 1;";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDXL vicidial_xfer_log update: |$affected_rows|$new_lead_id|$VDADuser\n";}
$stmtA = "UPDATE vicidial_closer_log set user='$VDADuser' where lead_id='$new_lead_id' order by call_date desc limit 1;";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- closer log : |$affected_rows|update of vcl table: $new_lead_id\n|$stmtA|\n";}
$dbhA->close;
$dbhA->disconnect();
print STDERR "\nexiting the VDAD app, transferring call to $VDADconf_exten\n";
print "SET CONTEXT $ext_context\n";
@@ -436,6 +449,10 @@ if ($channel_status < 1)
exit;
}
else
{
print STDERR "NNNNNNNNNN No agent record found!!!\n";
}
}
else
{
@@ -491,20 +508,23 @@ if ($drop_seconds < 1)
}
else
{
$cbc=0;
$stmtA = "SELECT voicemail_ext FROM vicidial_inbound_groups where group_id = '$channel_group' limit 1;";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
{
$iter=$dbhA->create_record_iterator;
$rec_countCUSTDATA=0;
while ( $record = $iter->each)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$rec_countCUSTDATA=0;
while ($sthArows > $cbc)
{
$VDADvoicemail_ext = "$record->[0]";
$VDADvoicemail_ext = "$aryA[0]";
$VDADvoicemail_ext =~ s/\D//gi;
$DROPexten = "$voicemail_dump_exten$VDADvoicemail_ext";
}
}
$cbc++;
}
$sthA->finish();
}
}
@@ -526,39 +546,27 @@ if ($drop_seconds < 1)
{
### 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','','','','','','','','','')";
$dbhA->query($stmtA) or die "Couldn't execute query:\n";
$affected_rows = $dbhA->do($stmtA) or die "Couldn't execute query:\n";
if ($M) {print STDERR "-- VDCL call_hungup timout: |$VHqueryCID|$VDADconf_exten|$channel|insert to vicidial_manager\n";}
}
$stmtA = "DELETE FROM vicidial_auto_calls where callerid='$callerid' and server_ip='$server_ip' order by call_time desc limit 1;";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL vac record deleted: |$affected_rows| $channel_group|$server_ip\n";}
# $stmtA = "UPDATE vicidial_log set status='DROP',end_epoch='$now_date_epoch',length_in_sec='$drop_seconds' where uniqueid = '$uniqueid';";
# if($M){print STDERR "\n\n|$stmtA|\n";}
# $dbhA->query("$stmtA");
# my $affected_rows = $dbhA->get_affected_rows_length;
# if ($M) {print STDERR "-- VDCL vicidial_log update: |$affected_rows|$uniqueid\n";}
$stmtA = "UPDATE vicidial_closer_log set status='DROP',end_epoch='$now_date_epoch',length_in_sec='$drop_seconds' where lead_id = '$new_lead_id' order by start_epoch desc limit 1;";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL vicidial_closer_log update: |$affected_rows|$new_lead_id\n";}
$stmtA = "UPDATE vicidial_list set status='XDROP' where lead_id = '$new_lead_id';";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL vicidial_list update: |$affected_rows|$new_lead_id\n";}
}
$dbhA->close;
$dbhA->disconnect();
exit;
+124 -115
View File
@@ -1,6 +1,6 @@
#!/usr/bin/perl
#
# agi-VDADcloser_inbound_NOCID.agi version 0.3
# agi-VDADcloser_inbound_NOCID.agi version 0.4 *DBI-version*
#
# runs when a call comes in from an inbound call. This script will
# send the calls out to the closers that are logged in.
@@ -29,6 +29,7 @@
#
# changes:
# 60504-1238 - Added drop second/message/exten options from inbound_group
# 60811-1003 - Changed to DBI by Marin Blu
#
$V = 1; # set to 1 for verbose mode
@@ -39,7 +40,7 @@ $DROP_TIME = 360; ### number of seconds to wait until you drop a waiting call
### Make sure this file is in a path or put the absolute path to it
require("/home/cron/AST_SERVER_conf.pl"); # local configuration file
use Net::MySQL;
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;
@@ -226,42 +227,51 @@ exit;
if (!$DB_port) {$DB_port='3306';}
my $dbhA = Net::MySQL->new(hostname=>"$DB_server", database=>"$DB_database", user=>"$DB_user", password=>"$DB_pass", port => "$DB_port") or die "Couldn't connect to database: $DB_server - $DB_database\n";
my $dbhA = DBI->connect("DBI:mysql:$DB_database:$DB_server:$DB_port", "$DB_user", "$DB_pass")
or die "Couldn't connect to database: " . DBI->errstr;
### Grab Server values from the database
$cbc=0;
$stmtA = "SELECT voicemail_dump_exten,ext_context,answer_transfer_agent,local_gmt,asterisk_version,max_vicidial_trunks FROM servers where server_ip = '$server_ip';";
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
while ( $record = $iter->each)
{
$DBvoicemail_dump_exten = "$record->[0]";
$DBext_context = "$record->[1]";
$DBanswer_transfer_agent = "$record->[2]";
$DBSERVER_GMT = "$record->[3]";
$DBasterisk_version = "$record->[4]";
$DBmax_vicidial_trunks = "$record->[5]";
if ($DBvoicemail_dump_exten) {$voicemail_dump_exten = $DBvoicemail_dump_exten;}
if ($DBext_context) {$ext_context = $DBext_context;}
if ($DBanswer_transfer_agent) {$answer_transfer_agent = $DBanswer_transfer_agent;}
if ($DBSERVER_GMT) {$SERVER_GMT = $DBSERVER_GMT;}
if ($DBasterisk_version) {$AST_ver = $DBasterisk_version;}
if ($DBmax_vicidial_trunks) {$max_vicidial_trunks = $DBmax_vicidial_trunks;}
}
@aryA = $sthA->fetchrow_array;
$DBvoicemail_dump_exten = "$aryA[0]";
$DBext_context = "$aryA[1]";
$DBanswer_transfer_agent = "$aryA[2]";
$DBSERVER_GMT = "$aryA[3]";
$DBasterisk_version = "$aryA[4]";
$DBmax_vicidial_trunks = "$aryA[5]";
if ($DBvoicemail_dump_exten) {$voicemail_dump_exten = $DBvoicemail_dump_exten;}
if ($DBext_context) {$ext_context = $DBext_context;}
if ($DBanswer_transfer_agent) {$answer_transfer_agent = $DBanswer_transfer_agent;}
if ($DBSERVER_GMT) {$SERVER_GMT = $DBSERVER_GMT;}
if ($DBasterisk_version) {$AST_ver = $DBasterisk_version;}
if ($DBmax_vicidial_trunks) {$max_vicidial_trunks = $DBmax_vicidial_trunks;}
$cbc++;
}
$sthA->finish();
### insert a record into the vicidial_list table
$stmtA = "INSERT INTO vicidial_list (entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,called_since_last_reset,phone_code,phone_number,security_phrase,called_count,gmt_offset_now) values('$SQLdate','$tsSQLdate','INBND','$fronter','$channel_group','VDCL','$list_id','Y','$phone_code','$phone_number','$channel_group','1','-5.00');";
$dbhA->query($stmtA);
$dbhA->query("select LAST_INSERT_ID() LIMIT 1;");
if ($dbhA->has_selected_record)
$affected_rows = $dbhA->do($stmtA);
$cbc=0;
$stmtA = "select LAST_INSERT_ID() LIMIT 1;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $cbc)
{
$iterA=$dbhA->create_record_iterator;
while ($recordA = $iterA->each)
{$insert_lead_id = "$recordA->[0]";}
@aryA = $sthA->fetchrow_array;
$insert_lead_id = "$aryA[0]";
$cbc++;
}
$sthA->finish();
$new_lead_id = $insert_lead_id;
if($M){print STDERR "\n|$stmtA|$new_lead_id|\n";}
@@ -275,42 +285,42 @@ if($M){print STDERR "\n|$stmtA|$new_lead_id|\n";}
print STDERR "callerID changed: $YqueryCID\n";
### Grab inbound_group values from the database
$cbc=0;
$stmtA = "SELECT drop_call_seconds,drop_message,drop_exten FROM vicidial_inbound_groups where group_id = '$channel_group';";
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
while ( $record = $iter->each)
{
$DBdrop_call_seconds = "$record->[0]";
$DBdrop_message = "$record->[1]";
$DBdrop_exten = "$record->[2]";
if ($DBdrop_call_seconds) {$DROP_TIME = $DBdrop_call_seconds;}
if ($DBdrop_message) {$drop_message = $DBdrop_message;}
if ($DBdrop_exten) {$drop_exten = $DBdrop_exten;}
}
@aryA = $sthA->fetchrow_array;
$DBdrop_call_seconds = "$aryA[0]";
$DBdrop_message = "$aryA[1]";
$DBdrop_exten = "$aryA[2]";
if ($DBdrop_call_seconds) {$DROP_TIME = $DBdrop_call_seconds;}
if ($DBdrop_message) {$drop_message = $DBdrop_message;}
if ($DBdrop_exten) {$drop_exten = $DBdrop_exten;}
$cbc++;
}
$sthA->finish();
### insert a LIVE record to the vicidial_auto_calls table
$stmtA = "INSERT INTO vicidial_auto_calls values('','$server_ip','$channel_group','LIVE','$new_lead_id','$uniqueid','$callerid','$channel','$phone_code','$phone_number','$SQLdate','IN')";
$dbhA->query($stmtA);
$affected_rows = $dbhA->do($stmtA);
if($M){print STDERR "\n|$stmtA|\n";}
$stmtA = "INSERT INTO vicidial_log (uniqueid,lead_id,campaign_id,call_date,start_epoch,status,phone_code,phone_number,user,processed) values('$uniqueid','$new_lead_id','$channel_group','$SQLdate','$now_date_epoch','XFER','$phone_code','$phone_number','$fronter','N')";
if($M){print STDERR "\n|$stmtA|\n";}
$dbhA->query($stmtA);
if ($M) {print STDERR "-- VDAD : |$new_lead_id|$fronter|insert to vicidial_log: $uniqueid\n";}
$stmtA = "INSERT INTO vicidial_log (uniqueid,lead_id,campaign_id,call_date,start_epoch,status,phone_code,phone_number,user,processed) values('$uniqueid','$new_lead_id','$channel_group','$SQLdate','$now_date_epoch','XFER','$phone_code','$phone_number','$fronter','N')";
if($M){print STDERR "\n|$stmtA|\n";}
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD : |$new_lead_id|$fronter|insert to vicidial_log: $uniqueid\n";}
$stmtA = "INSERT INTO vicidial_closer_log (lead_id,campaign_id,call_date,start_epoch,status,phone_code,phone_number,user,processed) values('$new_lead_id','$channel_group','$SQLdate','$now_date_epoch','QUEUE','$phone_code','$phone_number','VDCL','N')";
if($M){print STDERR "\n|$stmtA|\n";}
$dbhA->query($stmtA);
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL : |$new_lead_id|insert to vicidial_closer_log\n";}
$stmtA = "INSERT INTO vicidial_xfer_log (lead_id,campaign_id,call_date,phone_code,phone_number,user,closer) values('$new_lead_id','$channel_group','$SQLdate','$phone_code','$phone_number','$fronter','VDXL')";
if($M){print STDERR "\n|$stmtA|\n";}
$dbhA->query($stmtA);
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDXL : |$new_lead_id|insert to vicidial_closer_log\n";}
$VDADlead_id = $new_lead_id;
@@ -339,17 +349,20 @@ if ($channel_status < 1)
}
}
$cbc=0;
$stmtA = "SELECT next_agent_call FROM vicidial_inbound_groups where group_id='$channel_group';";
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$rec_countCUSTDATA=0;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
$rec_countCUSTDATA=0;
while ( $record = $iter->each)
{
$CAMP_callorder = "$record->[0]";
}
@aryA = $sthA->fetchrow_array;
$CAMP_callorder = "$aryA[0]";
$cbc++;
}
$sthA->finish();
$agent_call_order='order by last_call_finish';
if ($CAMP_callorder =~ /overall_user_level/i) {$agent_call_order = 'order by user_level desc,last_call_finish';}
@@ -357,62 +370,63 @@ if ($channel_status < 1)
if ($CAMP_callorder =~ /oldest_call_finish/i) {$agent_call_order = 'order by last_call_finish';}
if ($CAMP_callorder =~ /random/i) {$agent_call_order = 'order by random_id';}
$rec_countWAIT=0;
$rec_countWAIT=0;
$cbc=0;
$stmtA = "SELECT count(*) FROM vicidial_auto_calls where status = 'LIVE' and server_ip='$server_ip' and campaign_id = '$channel_group' and call_time < \"$SQLdateBEGIN\" and lead_id != '$VDADlead_id';";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
while ( $record = $iter->each)
{
$rec_countWAIT = "$record->[0]";
}
@aryA = $sthA->fetchrow_array;
$rec_countWAIT = "$aryA[0]";
$cbc++;
}
$sthA->finish();
if ($rec_countWAIT < 1)
{
$stmtA = "UPDATE vicidial_live_agents set status='QUEUE',lead_id='$new_lead_id',uniqueid='$unique_id', channel='$channel', callerid='$callerid' where status IN('CLOSER','READY') and server_ip='$server_ip' and campaign_id LIKE \"%CLOSER%\" and closer_campaigns LIKE \"% $channel_group %\" and last_update_time > '$BDtsSQLdate' $agent_call_order limit 1;";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD get agent: |$DROP_TIME|$drop_timer|$affected_rows|update of vla table: $channel_group|$server_ip\n";}
# if ($M) {print STDERR "|$stmtA|\n";}
if ($affected_rows > 0)
{
$cbc=0;
$stmtA = "SELECT conf_exten,user,extension FROM vicidial_live_agents where status = 'QUEUE' and server_ip='$server_ip' and campaign_id LIKE \"%CLOSER%\" and callerid='$callerid' and channel='$channel' order by last_call_time limit 1;";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$rec_countCUSTDATA=0;
while ($sthArows > $cbc)
{
$iter=$dbhA->create_record_iterator;
$rec_countCUSTDATA=0;
while ( $record = $iter->each)
{
$VDADconf_exten = "$record->[0]";
$VDADuser = "$record->[1]";
$VDADextension = "$record->[2]";
}
}
else
{
print STDERR "NNNNNNNNNN No agent record found!!!\n";
@aryA = $sthA->fetchrow_array;
$VDADconf_exten = "$aryA[0]";
$VDADuser = "$aryA[1]";
$VDADextension = "$aryA[2]";
$cbc++;
}
$sthA->finish();
$stmtA = "UPDATE vicidial_auto_calls set status='CLOSER' where callerid='$callerid';";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL XFER : |$affected_rows|update of vac table: $callerid\n|$stmtA|\n";}
$stmtA = "UPDATE vicidial_xfer_log set closer='$VDADuser' where lead_id = '$new_lead_id' order by call_date desc limit 1;";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDXL vicidial_xfer_log update: |$affected_rows|$new_lead_id|$VDADuser\n";}
$stmtA = "UPDATE vicidial_closer_log set user='$VDADuser' where lead_id='$new_lead_id' order by call_date desc limit 1;";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- closer log : |$affected_rows|update of vcl table: $new_lead_id\n|$stmtA|\n";}
$dbhA->close;
$dbhA->disconnect();
print STDERR "\nexiting the VDAD app, transferring call to $VDADconf_exten\n";
print "SET CONTEXT $ext_context\n";
@@ -437,6 +451,11 @@ if ($channel_status < 1)
exit;
}
else
{
print STDERR "NNNNNNNNNN No agent record found!!!\n";
}
}
else
{
@@ -492,20 +511,23 @@ if ($drop_seconds < 1)
}
else
{
$cbc=0;
$stmtA = "SELECT voicemail_ext FROM vicidial_inbound_groups where group_id = '$channel_group' limit 1;";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
{
$iter=$dbhA->create_record_iterator;
$rec_countCUSTDATA=0;
while ( $record = $iter->each)
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$rec_countCUSTDATA=0;
while ($sthArows > $cbc)
{
$VDADvoicemail_ext = "$record->[0]";
$VDADvoicemail_ext = "$aryA[0]";
$VDADvoicemail_ext =~ s/\D//gi;
$DROPexten = "$voicemail_dump_exten$VDADvoicemail_ext";
}
}
$cbc++;
}
$sthA->finish();
}
}
@@ -527,40 +549,27 @@ if ($drop_seconds < 1)
{
### 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','','','','','','','','','')";
$dbhA->query($stmtA) or die "Couldn't execute query:\n";
$affected_rows = $dbhA->do($stmtA) or die "Couldn't execute query:\n";
if ($M) {print STDERR "-- VDCL call_hungup timout: |$VHqueryCID|$VDADconf_exten|$channel|insert to vicidial_manager\n";}
}
$stmtA = "DELETE FROM vicidial_auto_calls where callerid='$callerid' and server_ip='$server_ip' order by call_time desc limit 1;";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL vac record deleted: |$affected_rows| $channel_group|$server_ip\n";}
# $stmtA = "UPDATE vicidial_log set status='DROP',end_epoch='$now_date_epoch',length_in_sec='$drop_seconds' where uniqueid = '$uniqueid';";
# if($M){print STDERR "\n\n|$stmtA|\n";}
# $dbhA->query("$stmtA");
# my $affected_rows = $dbhA->get_affected_rows_length;
# if ($M) {print STDERR "-- VDCL vicidial_log update: |$affected_rows|$uniqueid\n";}
$stmtA = "UPDATE vicidial_closer_log set status='DROP',end_epoch='$now_date_epoch',length_in_sec='$drop_seconds' where lead_id = '$new_lead_id' order by start_epoch desc limit 1;";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL vicidial_closer_log update: |$affected_rows|$new_lead_id\n";}
$stmtA = "UPDATE vicidial_list set status='XDROP' where lead_id = '$new_lead_id';";
if($M){print STDERR "\n\n|$stmtA|\n";}
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
my $affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDCL vicidial_list update: |$affected_rows|$new_lead_id\n";}
}
$dbhA->close;
$dbhA->disconnect();
exit;