consultative transfers Local redirect fixes

added agi-VDADfixCXFER.agi script to fix consultative conference leave-3way-call redirection

git-svn-id: svn://192.168.202.10@145 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
mattf
2006-08-09 22:16:17 +00:00
parent aa20b8ab9f
commit f58314ae7d
4 changed files with 320 additions and 4 deletions
+210
View File
@@ -0,0 +1,210 @@
#!/usr/bin/perl
#
# agi-VDADfixCXFER.agi version 0.1 *DBI-version*
#
# runs when a Consultative transfer is released by the vicidial fronter as the
# call arrives on another channel so that the vicidial_live_agents record is
# updated to be accurate.
#
# You need to put lines similar to those below in your extensions.conf file:
#
# ;VICIDIAL Consultative Xfer fix script:
# exten => _8600XXX*.,1,AGI(agi-VDADfixCXFER.agi)
#
# Copyright (C) 2006 Matt Florell <vicidial@gmail.com> LICENSE: GPLv2
#
# changes:
# 60809-1749 - first build
#
$V = 1; # set to 1 for verbose mode
$M = 1; # set to 1 for 2 line messages mode
# default path to astguiclient configuration file:
$PATHconf = '/etc/astguiclient.conf';
open(conf, "$PATHconf") || die "can't open $PATHconf: $!\n";
@conf = <conf>;
close(conf);
$i=0;
foreach(@conf)
{
$line = $conf[$i];
$line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi;
if ( ($line =~ /^PATHhome/) && ($CLIhome < 1) )
{$PATHhome = $line; $PATHhome =~ s/.*=//gi;}
if ( ($line =~ /^PATHlogs/) && ($CLIlogs < 1) )
{$PATHlogs = $line; $PATHlogs =~ s/.*=//gi;}
if ( ($line =~ /^PATHagi/) && ($CLIagi < 1) )
{$PATHagi = $line; $PATHagi =~ s/.*=//gi;}
if ( ($line =~ /^PATHweb/) && ($CLIweb < 1) )
{$PATHweb = $line; $PATHweb =~ s/.*=//gi;}
if ( ($line =~ /^PATHsounds/) && ($CLIsounds < 1) )
{$PATHsounds = $line; $PATHsounds =~ s/.*=//gi;}
if ( ($line =~ /^PATHmonitor/) && ($CLImonitor < 1) )
{$PATHmonitor = $line; $PATHmonitor =~ 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++;
}
# Customized Variables
$server_ip = $VARserver_ip; # Asterisk server IP
if (!$VARDB_port) {$VARDB_port='3306';}
use DBI;
use Asterisk::AGI;
$AGI = new Asterisk::AGI;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = ($year + 1900);
$mon++;
if ($mon < 10) {$mon = "0$mon";}
if ($mday < 10) {$mday = "0$mday";}
if ($hour < 10) {$Fhour = "0$hour";}
if ($min < 10) {$min = "0$min";}
if ($sec < 10) {$sec = "0$sec";}
### begin parsing run-time options ###
if (length($ARGV[0])>1)
{
if ($V) {print STDERR "Perl Environment Dump:\n";}
$i=0;
while ($#ARGV >= $i)
{
$args = "$args $ARGV[$i]";
if ($V) {print STDERR "$i|$ARGV[$i]|\n";}
$i++;
}
### list of command-line array arguments:
@ARGV_vars = split(/-----/, $ARGV[0]);
if ($args =~ /--help/i)
{
print "allowed run time options:\n [-q] = quiet\n [-t] = test\n [-debug] = verbose debug messages\n\n";
}
else
{
if ($args =~ /-V/i)
{
$V=1;
}
if ($args =~ /-debug/i)
{
$DG=1;
}
if ($args =~ /-dbAVS/i)
{
$DGA=1;
}
if ($args =~ /-q/i)
{
$q=1;
$Q=1;
}
if ($args =~ /-t/i)
{
$TEST=1;
$T=1;
}
}
}
else
{
if ($V) {print "no command line options set\n";}
}
$|=1;
while(<STDIN>)
{
chomp;
last unless length($_);
if ($V)
{
if (/^agi_(\w+)\:\s+(.*)$/)
{
$AGI{$1} = $2;
}
}
if (/^agi_uniqueid\:\s+(.*)$/) {$unique_id = $1; $uniqueid = $unique_id;}
if (/^agi_channel\:\s+(.*)$/) {$channel = $1;}
if (/^agi_extension\:\s+(.*)$/) {$extension = $1;}
}
@EXTEN = split(/\*/, $extension);
$conf_exten = $EXTEN[0];
$lead_id = $EXTEN[1];
$user = $EXTEN[2];
if ($V)
{
if ($V) {print STDERR "AGI Environment Dump:\n";}
foreach $i (sort keys %AGI) {
if ($V) {print STDERR " -- $i = $AGI{$i}\n";}
}
}
if ($V) {print STDERR "AGI Environment Dump: |$unique_id|$channel|$extension|$type|$callerid|$calleridname|$priority|\n";}
if ($V) {print STDERR "\nCXFERfix : $lead_id $user $channel $uniqueid\n";}
$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
or die "Couldn't connect to database: " . DBI->errstr;
########## FIND AND UPDATE vicidial_live_agents ##########
$stmtA = "UPDATE vicidial_live_agents SET channel='$channel',call_server_ip='$server_ip',uniqueid='$uniqueid' where user='$user' and lead_id='$lead_id';";
if($M){print STDERR "\n\n|$stmtA|\n";}
$affected_rows = $dbhA->do($stmtA);
if ($M) {print STDERR "-- VDAD vicidial_live_agents update: |$affected_rows|$lead_id\n";}
$dbhA->disconnect();
print STDERR "\nexiting the CXFERfix app, transferring call to $conf_exten\n";
#print "SET CONTEXT $ext_context\n";
# checkresult($result);
print "SET EXTENSION $conf_exten\n";
checkresult($result);
print "SET PRIORITY 1\n";
checkresult($result);
exit;
sub checkresult {
my ($res) = @_;
my $retval;
$tests++;
chomp $res;
if ($res =~ /^200/) {
$res =~ /result=(-?\d+)/;
if (!length($1)) {
# print STDERR "FAIL ($res)\n";
$fail++;
} else {
# print STDERR "PASS ($1)\n";
$pass++;
}
} else {
# print STDERR "FAIL (unexpected result '$res')\n";
$fail++;
}
}
+3 -2
View File
@@ -615,12 +615,13 @@ if ($ACTION=="RedirectXtraCX")
}
else
{
$stmt="SELECT server_ip,conf_exten FROM vicidial_live_agents where lead_id='$lead_id' and user!='$user';";
$stmt="SELECT server_ip,conf_exten,user FROM vicidial_live_agents where lead_id='$lead_id' and user!='$user';";
if ($format=='debug') {echo "\n<!-- $stmt -->";}
$rslt=mysql_query($stmt, $link);
$rowx=mysql_fetch_row($rslt);
$dest_server_ip = $rowx[0];
$dest_session_id = $rowx[1];
$dest_user = $rowx[2];
$S='*';
$D_s_ip = explode('.', $dest_server_ip);
@@ -632,7 +633,7 @@ if ($ACTION=="RedirectXtraCX")
if (strlen($D_s_ip[2])<3) {$D_s_ip[2] = "0$D_s_ip[2]";}
if (strlen($D_s_ip[3])<2) {$D_s_ip[3] = "0$D_s_ip[3]";}
if (strlen($D_s_ip[3])<3) {$D_s_ip[3] = "0$D_s_ip[3]";}
$dest_dialstring = "$D_s_ip[0]$S$D_s_ip[1]$S$D_s_ip[2]$S$D_s_ip[3]$S$dest_session_id";
$dest_dialstring = "$D_s_ip[0]$S$D_s_ip[1]$S$D_s_ip[2]$S$D_s_ip[3]$S$dest_session_id$S$lead_id$S$dest_user$S";
$stmt="INSERT INTO vicidial_manager values('','','$NOW_TIME','NEW','N','$call_server_ip','','Redirect','$queryCID','Channel: $channel','Context: $ext_context','Exten: $dest_dialstring','Priority: $ext_priority','CallerID: $queryCID','','','','','');";
if ($format=='debug') {echo "\n<!-- $stmt -->";}
+40
View File
@@ -943,6 +943,46 @@ if ($stage == "end")
}
################################################################################
### VDADREcheckINCOMING - for auto-dial VICIDiaL dialing this will recheck for
### calls to see if the channel has updated
################################################################################
if ($ACTION == 'VDADREcheckINCOMING')
{
$MT[0]='';
$row=''; $rowx='';
$channel_live=1;
if ( (strlen($campaign)<1) || (strlen($server_ip)<1) || (strlen($lead_id)<1) )
{
$channel_live=0;
echo "0\n";
echo "Campaign $campaign is not valid\n";
echo "lead_id $lead_id is not valid\n";
exit;
}
else
{
### grab the call and lead info from the vicidial_live_agents table
$stmt = "SELECT lead_id,uniqueid,callerid,channel,call_server_ip FROM vicidial_live_agents where server_ip = '$server_ip' and user='$user' and campaign_id='$campaign' and lead_id='$lead_id';";
if ($DB) {echo "$stmt\n";}
$rslt=mysql_query($stmt, $link);
$queue_leadID_ct = mysql_num_rows($rslt);
if ($queue_leadID_ct > 0)
{
$row=mysql_fetch_row($rslt);
$lead_id =$row[0];
$uniqueid =$row[1];
$callerid =$row[2];
$channel =$row[3];
$call_server_ip =$row[4];
if (strlen($call_server_ip)<7) {$call_server_ip = $server_ip;}
echo "1\n" . $lead_id . '|' . $uniqueid . '|' . $callerid . '|' . $channel . '|' . $call_server_ip . "|\n";
}
}
}
################################################################################
### VDADcheckINCOMING - for auto-dial VICIDiaL dialing this will check for calls
### in the vicidial_live_agents table in QUEUE status, then
+67 -2
View File
@@ -115,6 +115,7 @@
# 60808-1145 - Added consultative transfers with customer data
# 60808-2232 - Added campaign name to pulldown for login screen
# 60809-1603 - Added option to locally transfer consult xfers
# 60809-1732 - Added recheck of transferred channels before customer gone mesg
#
require("dbconnect.php");
@@ -160,8 +161,8 @@ if (isset($_GET["relogin"])) {$relogin=$_GET["relogin"];}
$forever_stop=0;
$version = '2.0.89';
$build = '60809-1603';
$version = '2.0.90';
$build = '60809-1732';
if ($force_logout)
{
@@ -3069,6 +3070,69 @@ if ($enable_fast_refresh < 1) {echo "\tvar refresh_interval = 1000;\n";}
}
// ################################################################################
// Check to see if there is a call being sent from the auto-dialer to agent conf
function ReChecKCustoMerChaN()
{
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined')
{
xmlhttp = new XMLHttpRequest();
}
if (xmlhttp)
{
recheckVDAI_query = "server_ip=" + server_ip + "&session_name=" + session_name + "&user=" + user + "&pass=" + pass + "&campaign=" + campaign + "&ACTION=VDADREcheckINCOMING" + "&agent_log_id=" + agent_log_id + "&lead_id=" + document.vicidial_form.lead_id.value;
xmlhttp.open('POST', 'vdc_db_query.php');
xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
xmlhttp.send(recheckVDAI_query);
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
var recheck_incoming = null;
recheck_incoming = xmlhttp.responseText;
// alert(xmlhttp.responseText);
var recheck_VDIC_array=recheck_incoming.split("\n");
if (recheck_VDIC_array[0] == '1')
{
var reVDIC_data_VDAC=recheck_VDIC_array[1].split("|");
if (reVDIC_data_VDAC[3] == lastcustchannel)
{
// do nothing
}
else
{
alert("Channel has changed from:\n" + lastcustchannel + '|' + lastcustserverip + "\nto:\n" + reVDIC_data_VDAC[3] + '|' + reVDIC_data_VDAC[4]);
document.vicidial_form.callchannel.value = reVDIC_data_VDAC[3];
lastcustchannel = reVDIC_data_VDAC[3];
document.vicidial_form.callserverip.value = reVDIC_data_VDAC[4];
lastcustserverip = reVDIC_data_VDAC[4];
custchannellive = 1;
}
}
}
}
delete xmlhttp;
}
}
// ################################################################################
// Check to see if there is a call being sent from the auto-dialer to agent conf
function check_for_auto_incoming()
@@ -4620,6 +4684,7 @@ if ($enable_fast_refresh < 1) {echo "\tvar refresh_interval = 1000;\n";}
}
if (logout_stop_timeouts==1) {WaitingForNextStep=1;}
if ( (custchannellive < -30) && (lastcustchannel.length > 3) ) {CustomerChanneLGone();}
if ( (custchannellive < -10) && (lastcustchannel.length > 3) ) {ReChecKCustoMerChaN();}
if ( (nochannelinsession > 16) && (check_n > 15) ) {NoneInSession();}
if (wrapup_seconds > 0)
{