From 8f5f0faba64e04aabdf08833b149fa690f3ce0cb Mon Sep 17 00:00:00 2001 From: mattf Date: Tue, 22 Jun 2010 15:25:32 +0000 Subject: [PATCH] Added function for start_call_url to work with remote agents git-svn-id: svn://192.168.202.10@1453 3d104415-ff17-0410-8863-d5cf3c621b8a --- agc_2-X/trunk/UPGRADE | 2 + agc_2-X/trunk/bin/AST_VDremote_agents.pl | 46 +++- agc_2-X/trunk/bin/AST_send_URL.pl | 332 +++++++++++++++++++++++ 3 files changed, 378 insertions(+), 2 deletions(-) create mode 100644 agc_2-X/trunk/bin/AST_send_URL.pl diff --git a/agc_2-X/trunk/UPGRADE b/agc_2-X/trunk/UPGRADE index 5e22bb38..ef9ebd56 100644 --- a/agc_2-X/trunk/UPGRADE +++ b/agc_2-X/trunk/UPGRADE @@ -165,6 +165,8 @@ OTHER CHANGES: 39. Added web-configurable TTS voice option. Please make sure the Cepstral voice is installed before entering one. +40. Added function for start_call_url to work with remote agents + diff --git a/agc_2-X/trunk/bin/AST_VDremote_agents.pl b/agc_2-X/trunk/bin/AST_VDremote_agents.pl index 82132819..ff232490 100644 --- a/agc_2-X/trunk/bin/AST_VDremote_agents.pl +++ b/agc_2-X/trunk/bin/AST_VDremote_agents.pl @@ -34,7 +34,7 @@ # 100309-0555 - Added queuemetrics_loginout option # 100318-2307 - Added ra_user field input to vla table # 100524-1542 - Fixed live call detection bug on multi-server systems -# 100621-2152 - Added start_call_url and dispo_call_url functions for remote agents +# 100622-0917 - Added start_call_url function for remote agents, this launches a separate child script # ### begin parsing run-time options ### @@ -272,8 +272,10 @@ while($one_day_interval > 0) @QHuser=@MT; @QHcall_type=@MT; @QHcampaign_id=@MT; + @QHphone_number=@MT; + @QHalt_dial=@MT; ##### grab number of QUEUE calls right now and update - $stmtA = "SELECT vla.live_agent_id,vla.lead_id,vla.uniqueid,vla.user,vac.call_type,vac.campaign_id FROM vicidial_live_agents vla,vicidial_auto_calls vac where vla.server_ip='$server_ip' and vla.status IN('QUEUE') and vla.extension LIKE \"R/%\" and vla.uniqueid=vac.uniqueid and vla.channel=vac.channel;"; + $stmtA = "SELECT vla.live_agent_id,vla.lead_id,vla.uniqueid,vla.user,vac.call_type,vac.campaign_id,vac.phone_number,vac.alt_dial FROM vicidial_live_agents vla,vicidial_auto_calls vac where vla.server_ip='$server_ip' and vla.status IN('QUEUE') and vla.extension LIKE \"R/%\" and vla.uniqueid=vac.uniqueid and vla.channel=vac.channel;"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $vla_qh_ct=$sthA->rows; @@ -287,6 +289,9 @@ while($one_day_interval > 0) $QHuser[$w] = $aryA[3]; $QHcall_type[$w] = $aryA[4]; $QHcampaign_id[$w] = $aryA[5]; + $QHphone_number[$w] = $aryA[6]; + $QHalt_dial[$w] = $aryA[7]; + if (length($QHalt_dial[$w]) < 1) {$QHalt_dial[$w] = 'MAIN';} $w++; } $sthA->finish(); @@ -294,6 +299,8 @@ while($one_day_interval > 0) $w=0; while ($vla_qh_ct > $w) { + $start_call_url=''; + $stmtA = "UPDATE vicidial_live_agents set status='INCALL',last_call_time='$SQLdate',comments='REMOTE',calls_today=(calls_today + 1),last_state_change='$SQLdate' where live_agent_id='$QHlive_agent_id[$w]';"; $Aaffected_rows = $dbhA->do($stmtA); @@ -310,6 +317,8 @@ while($one_day_interval > 0) $stmtE = "UPDATE vicidial_inbound_group_agents set calls_today=(calls_today + 1) where user='$QHuser[$w]' and group_id='$QHcampaign_id[$w]';"; $Eaffected_rows = $dbhA->do($stmtE); + + $stmtG = "SELECT start_call_url FROM vicidial_inbound_groups where group_id='$QHcampaign_id[$w]';"; } else { @@ -318,6 +327,38 @@ while($one_day_interval > 0) $Daffected_rows=0; $Eaffected_rows=0; + + $stmtG = "SELECT start_call_url FROM vicidial_campaigns where campaign_id='$QHcampaign_id[$w]';"; + } + + $sthA = $dbhA->prepare($stmtG) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtG ", $dbhA->errstr; + $start_url_ct=$sthA->rows; + if ($start_url_ct > 0) + { + @aryA = $sthA->fetchrow_array; + $start_call_url = $aryA[0]; + } + $sthA->finish(); + + ### This is where the call to the start_call_url launch will go + + if (length($start_call_url) > 5) + { + $launch = $PATHhome . "/AST_send_URL.pl"; + $launch .= " --SYSLOG" if ($SYSLOG); + $launch .= " --lead_id=" . $QHlead_id[$w]; + $launch .= " --phone_number=" . $QHphone_number[$w]; + $launch .= " --user=" . $QHuser[$w]; + $launch .= " --call_type=" . $QHcall_type[$w]; + $launch .= " --campaign=" . $QHcampaign_id[$w]; + $launch .= " --uniqueid=" . $QHuniqueid[$w]; + $launch .= " --alt_dial=" . $QHalt_dial[$w]; + + system($launch . ' &'); + + $event_string="$launch|"; + &event_logger; } $event_string = "| QUEUEd listing UPDATEd: |$Aaffected_rows|$Baffected_rows|$Caffected_rows|$Daffected_rows|$Eaffected_rows| |$QHlive_agent_id[$w]|$QHlead_id[$w]|$QHuniqueid[$w]|$QHuser[$w]|$QHcall_type[$w]|$QHcampaign_id[$w]|"; @@ -527,6 +568,7 @@ while($one_day_interval > 0) # } # } + } ### no records exist so insert a new one else diff --git a/agc_2-X/trunk/bin/AST_send_URL.pl b/agc_2-X/trunk/bin/AST_send_URL.pl new file mode 100644 index 00000000..457804d6 --- /dev/null +++ b/agc_2-X/trunk/bin/AST_send_URL.pl @@ -0,0 +1,332 @@ +#!/usr/bin/perl +# +# AST_send_URL.pl version 2.4 +# +# DESCRIPTION: +# This script is spawned for remote agents when the Start Call URL is set in the +# campaign or in-group that the call came from when sent to the remote agent. +# +# +# Copyright (C) 2010 Matt Florell LICENSE: AGPLv2 +# +# CHANGES +# 100622-0929 - First Build +# + +$|++; +use Getopt::Long; + +### Initialize date/time vars ### +my $secX = time(); #Start time + +### Initialize run-time variables ### +my ($CLOhelp, $SYSLOG,$DB, $DBX); +my ($campaign, $lead_id, $phone_number, $call_type, $user, $uniqueid, $alt_dial); +my $FULL_LOG = 1; + +### begin parsing run-time options ### +if (scalar @ARGV) { + GetOptions('help!' => \$CLOhelp, + 'SYSLOG!' => \$SYSLOG, + 'campaign=s' => \$campaign, + 'lead_id=s' => \$lead_id, + 'phone_number=s' => \$phone_number, + 'call_type=s' => \$call_type, + 'user=s' => \$user, + 'uniqueid=s' => \$uniqueid, + 'alt_dial=s' => \$alt_dial, + 'debug!' => \$DB, + 'debugX!' => \$DBX, + 'fulllog!' => \$FULL_LOG); + + $DB = 1 if ($DBX); + if ($DB) + { + print "\n----- DEBUGGING -----\n\n"; + print "\n----- SUPER-DUPER DEBUGGING -----\n\n" if ($DBX); + print " SYSLOG: $SYSLOG\n" if ($SYSLOG); + print " campaign: $campaign\n" if ($campaign); + print " lead_id: $lead_id\n" if ($lead_id); + print " phone_number: $phone_number\n" if ($phone_number); + print " call_type: $call_type\n" if ($call_type); + print " user: $user\n" if ($user); + print " uniqueid: $uniqueid\n" if ($uniqueid); + print " alt_dial: $alt_dial\n" if ($alt_dial); + print "\n"; + } + if ($CLOhelp) + { + print "allowed run time options:\n"; + print " [--help] = this help screen\n"; + print " [--SYSLOG] = whether to log actions or not\n"; + print "required flags:\n"; + print " [--campaign] = campaign ID or In-group ID of the call\n"; + print " [--lead_id] = lead ID for the call\n"; + print " [--phone_number] = phone number of the call\n"; + print " [--call_type] = Inbound or outbound call\n"; + print " [--user] = remote user that received the call\n"; + print " [--uniqueid] = uniqueid of the call\n"; + print " [--alt_dial] = label of the phone number dialed\n"; + print "\n"; + print "You may prefix an option with 'no' to disable it.\n"; + print " ie. --noSYSLOG or --noFULLLOG\n"; + + exit 0; + } + } + +# default path to astguiclient configuration file: +$PATHconf = '/etc/astguiclient.conf'; + +open(conf, "$PATHconf") || die "can't open $PATHconf: $!\n"; +@conf = ; +close(conf); +$i=0; +foreach(@conf) + { + $line = $conf[$i]; + $line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi; + if ( ($line =~ /^PATHlogs/) && ($CLIlogs < 1) ) + {$PATHlogs = $line; $PATHlogs =~ s/.*=//gi;} + if ( ($line =~ /^VARserver_ip/) && ($CLIserver_ip < 1) ) + {$VARserver_ip = $line; $VARserver_ip =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_server/) && ($CLIDB_server < 1) ) + {$VARDB_server = $line; $VARDB_server =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_database/) && ($CLIDB_database < 1) ) + {$VARDB_database = $line; $VARDB_database =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_user/) && ($CLIDB_user < 1) ) + {$VARDB_user = $line; $VARDB_user =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_pass/) && ($CLIDB_pass < 1) ) + {$VARDB_pass = $line; $VARDB_pass =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_port/) && ($CLIDB_port < 1) ) + {$VARDB_port = $line; $VARDB_port =~ s/.*=//gi;} + $i++; + } + + if (!$VARDB_port) {$VARDB_port='3306';} + +if (length($lead_id) > 0) + { + ### find wget binary + $wgetbin = ''; + if ( -e ('/bin/wget')) {$wgetbin = '/bin/wget';} + else + { + if ( -e ('/usr/bin/wget')) {$wgetbin = '/usr/bin/wget';} + else + { + if ( -e ('/usr/local/bin/wget')) {$wgetbin = '/usr/local/bin/wget';} + else + { + print "Can't find wget binary! Exiting...\n"; + exit + } + } + } + + use Time::HiRes ('gettimeofday','usleep','sleep'); # necessary to have perl sleep command of less than one second + use DBI; + + $dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass") + or die "Couldn't connect to database: " . DBI->errstr; + + ### Grab Server values from the database + $stmtA = "SELECT vd_server_logs,local_gmt,ext_context FROM servers where server_ip = '$VARserver_ip';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $DBvd_server_logs = $aryA[0]; + $DBSERVER_GMT = $aryA[1]; + $ext_context = $aryA[2]; + if ($DBvd_server_logs =~ /Y/) {$SYSLOG = '1';} + else {$SYSLOG = '0';} + if (length($DBSERVER_GMT)>0) {$SERVER_GMT = $DBSERVER_GMT;} + } + $sthA->finish(); + + if ($call_type =~ /IN/) + {$stmtG = "SELECT start_call_url FROM vicidial_inbound_groups where group_id='$campaign';";} + else + {$stmtG = "SELECT start_call_url FROM vicidial_campaigns where campaign_id='$campaign';";} + $sthA = $dbhA->prepare($stmtG) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtG ", $dbhA->errstr; + $start_url_ct=$sthA->rows; + if ($start_url_ct > 0) + { + @aryA = $sthA->fetchrow_array; + $start_call_url = $aryA[0]; + } + $sthA->finish(); + + $VAR_lead_id = $lead_id; + $VAR_user = $user; + $VAR_phone_number = $phone_number; + $VAR_call_type = $call_type; + $VAR_uniqueid = $uniqueid; + $VAR_group_id = $campaign; + $VAR_campaign_id = $campaign; + $VAR_group = $campaign; + $VAR_alt_dial = $alt_dial; + + $stmtA = "SELECT lead_id,entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,phone_number,title,first_name,middle_initial,last_name,address1,address2,address3,city,state,province,postal_code,country_code,gender,date_of_birth,alt_phone,email,security_phrase,comments,called_count,last_local_call_time,rank,owner FROM vicidial_list where lead_id='$lead_id';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VAR_entry_date = $aryA[1]; + $VAR_modify_date = $aryA[2]; + $VAR_status = $aryA[3]; + $VAR_vendor_lead_code = $aryA[5]; + $VAR_source_id = $aryA[6]; + $VAR_list_id = $aryA[7]; + $VAR_title = $aryA[9]; + $VAR_first_name = $aryA[10]; + $VAR_middle_initial = $aryA[11]; + $VAR_last_name = $aryA[12]; + $VAR_address1 = $aryA[13]; + $VAR_address2 = $aryA[14]; + $VAR_address3 = $aryA[15]; + $VAR_city = $aryA[16]; + $VAR_state = $aryA[17]; + $VAR_province = $aryA[18]; + $VAR_postal_code = $aryA[19]; + $VAR_country_code = $aryA[20]; + $VAR_gender = $aryA[21]; + $VAR_date_of_birth = $aryA[22]; + $VAR_alt_phone = $aryA[23]; + $VAR_email = $aryA[24]; + $VAR_security_phrase = $aryA[25]; + $VAR_comments = $aryA[26]; + $VAR_called_count = $aryA[27]; + $VAR_last_local_call_time = $aryA[28]; + $VAR_rank = $aryA[29]; + $VAR_owner = $aryA[30]; + } + $sthA->finish(); + + if ($start_call_url =~ /--A--user_custom_/) + { + $stmtA = "select custom_one,custom_two,custom_three,custom_four,custom_five from vicidial_users where user='$user';;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VAR_user_custom_one = $aryA[0]; + $VAR_user_custom_two = $aryA[1]; + $VAR_user_custom_three = $aryA[2]; + $VAR_user_custom_four = $aryA[3]; + $VAR_user_custom_five = $aryA[4]; + } + } + + $start_call_url =~ s/^VAR//gi; + $start_call_url =~ s/--A--lead_id--B--/$VAR_lead_id/gi; + $start_call_url =~ s/--A--entry_date--B--/$VAR_entry_date/gi; + $start_call_url =~ s/--A--modify_date--B--/$VAR_modify_date/gi; + $start_call_url =~ s/--A--status--B--/$VAR_status/gi; + $start_call_url =~ s/--A--user--B--/$VAR_user/gi; + $start_call_url =~ s/--A--vendor_id--B--/$VAR_vendor_lead_code/gi; + $start_call_url =~ s/--A--vendor_lead_code--B--/$VAR_vendor_lead_code/gi; + $start_call_url =~ s/--A--source_id--B--/$VAR_source_id/gi; + $start_call_url =~ s/--A--list_id--B--/$VAR_list_id/gi; + $start_call_url =~ s/--A--phone_number--B--/$VAR_phone_number/gi; + $start_call_url =~ s/--A--title--B--/$VAR_title/gi; + $start_call_url =~ s/--A--first_name--B--/$VAR_first_name/gi; + $start_call_url =~ s/--A--middle_initial--B--/$VAR_middle_initial/gi; + $start_call_url =~ s/--A--last_name--B--/$VAR_last_name/gi; + $start_call_url =~ s/--A--address1--B--/$VAR_address1/gi; + $start_call_url =~ s/--A--address2--B--/$VAR_address2/gi; + $start_call_url =~ s/--A--address3--B--/$VAR_address3/gi; + $start_call_url =~ s/--A--city--B--/$VAR_city/gi; + $start_call_url =~ s/--A--state--B--/$VAR_state/gi; + $start_call_url =~ s/--A--province--B--/$VAR_province/gi; + $start_call_url =~ s/--A--postal_code--B--/$VAR_postal_code/gi; + $start_call_url =~ s/--A--country_code--B--/$VAR_country_code/gi; + $start_call_url =~ s/--A--gender--B--/$VAR_gender/gi; + $start_call_url =~ s/--A--date_of_birth--B--/$VAR_date_of_birth/gi; + $start_call_url =~ s/--A--alt_phone--B--/$VAR_alt_phone/gi; + $start_call_url =~ s/--A--email--B--/$VAR_email/gi; + $start_call_url =~ s/--A--security_phrase--B--/$VAR_security_phrase/gi; + $start_call_url =~ s/--A--comments--B--/$VAR_comments/gi; + $start_call_url =~ s/--A--called_count--B--/$VAR_called_count/gi; + $start_call_url =~ s/--A--last_local_call_time--B--/$VAR_last_local_call_time/gi; + $start_call_url =~ s/--A--rank--B--/$VAR_rank/gi; + $start_call_url =~ s/--A--owner--B--/$VAR_owner/gi; + $start_call_url =~ s/--A--dialed_number--B--/$VAR_phone_number/gi; + $start_call_url =~ s/--A--dialed_label--B--/$VAR_alt_dial/gi; + $start_call_url =~ s/--A--user_custom_one--B--/$VAR_user_custom_one/gi; + $start_call_url =~ s/--A--user_custom_two--B--/$VAR_user_custom_two/gi; + $start_call_url =~ s/--A--user_custom_three--B--/$VAR_user_custom_three/gi; + $start_call_url =~ s/--A--user_custom_four--B--/$VAR_user_custom_four/gi; + $start_call_url =~ s/--A--user_custom_five--B--/$VAR_user_custom_five/gi; + $start_call_url =~ s/ /+/gi; + $start_call_url =~ s/&/\\&/gi; + + `$wgetbin -q --output-document=/tmp/ASUtmp $start_call_url `; + + $event_string="$wgetbin -q --output-document=/tmp/ASUtmp $start_call_url|"; + &event_logger; + } + + +my $secZ = time(); +my $script_time = ($secZ - $secX); +print "DONE execute time: $script_time seconds\n"; + +exit 0; +# Program ends. + + +### Start of subs. + + +sub event_logger + { + my ($tms) = @_; + my($sec,$min,$hour,$mday,$mon,$year) = getTime($tms); + $now_date = $year.'-'.$mon.'-'.$mday.' '.$hour.':'.$min.':'.$sec; + $log_date = $year . '-' . $mon . '-' . $mday; + if (!$ASULOGfile) {$ASULOGfile = "$PATHlogs/sendurl.$log_date";} + + if ($DB) {print "$now_date|$event_string|\n";} + if ($SYSLOG) + { + ### open the log file for writing ### + open(Lout, ">>$ASULOGfile") + || die "Can't open $VDRLOGfile: $!\n"; + print Lout "$now_date|$event_string|\n"; + close(Lout); + } + $event_string=''; + } + + +# getTime usage: +# getTime($SecondsSinceEpoch); +# Options: +# $SecondsSinceEpoch : Request time in seconds, defaults to current date/time. +# Returns: +# ($sec, $min, $hour. $day, $mon, $year) +sub getTime + { + my ($tms) = @_; + $tms = time unless ($tms); + my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime($tms); + $year += 1900; + $mon++; + $mon = "0" . $mon if ($mon < 10); + $mday = "0" . $mday if ($mday < 10); + $min = "0" . $min if ($min < 10); + $sec = "0" . $sec if ($sec < 10); + return ($sec,$min,$hour,$mday,$mon,$year); + } + +### End of subs +