Added agent_heartbeat for 3way-press-1 outside-agents

git-svn-id: svn://192.168.202.10@3797 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
mattf
2024-01-15 05:01:58 +00:00
parent 251c26f479
commit 0b2408b88b
7 changed files with 95 additions and 11 deletions
+12 -4
View File
@@ -23,16 +23,17 @@
#exten => _49907.,n,Hangup
#
#
# Copyright (C) 2023 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
# Copyright (C) 2024 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
#
# changes:
# 231113-2016 - First Build
# 231118-1600 - Added endings for HUNGUP and TIMEOUT
# 231227-1428 - Added multi-phone ability
# 240114-0942 - Added agent_heartbeat
#
$script = 'agi-3way_press_agent.agi';
$build = '231227-1428';
$build = '240114-0942';
$at='@';
$S='*';
@@ -406,7 +407,7 @@ if ( ($CALLphone_numbers_ct > 0) && (length($CALLphone_numbers) > 4) )
$allCIDs .= "$VIDqueryCID|";
### Insert the call to vicidial_3way_press_live
$stmtA="INSERT INTO vicidial_3way_press_live SET call_date=\"$SQLdate\",caller_code='$calleridname',call_3way_id='$VIDqueryCID',lead_id='$lead_id',phone_number='$CALLphone_numbers_ARY[$vp]',dialstring='$temp_prefix_code$CALLphone_numbers_ARY[$vp]',outbound_cid='$original_cid',user='$CALLuser',session_id='$CALLsession_id',server_ip='$CALLserver_ip',session_id_3way='',status='NEW';";
$stmtA="INSERT INTO vicidial_3way_press_live SET call_date=\"$SQLdate\",caller_code='$calleridname',call_3way_id='$VIDqueryCID',lead_id='$lead_id',phone_number='$CALLphone_numbers_ARY[$vp]',dialstring='$temp_prefix_code$CALLphone_numbers_ARY[$vp]',outbound_cid='$original_cid',user='$CALLuser',session_id='$CALLsession_id',server_ip='$CALLserver_ip',session_id_3way='',status='NEW',agent_heartbeat=NOW();";
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
$affected_rowsA = $dbhA->do($stmtA);
if ($AGILOG) {$agi_string = "-- vicidial_3way_press_live INSERT: |$affected_rowsA|$stmtA|"; &agi_output;}
@@ -436,7 +437,7 @@ else
$allCIDs .= "$VIDqueryCID|";
### Insert the call to vicidial_3way_press_live
$stmtA="INSERT INTO vicidial_3way_press_live SET call_date=\"$SQLdate\",caller_code='$calleridname',call_3way_id='$VIDqueryCID',lead_id='$lead_id',phone_number='$phone_number',dialstring='$dialstring',outbound_cid='$original_cid',user='$CALLuser',session_id='$CALLsession_id',server_ip='$CALLserver_ip',session_id_3way='',status='NEW';";
$stmtA="INSERT INTO vicidial_3way_press_live SET call_date=\"$SQLdate\",caller_code='$calleridname',call_3way_id='$VIDqueryCID',lead_id='$lead_id',phone_number='$phone_number',dialstring='$dialstring',outbound_cid='$original_cid',user='$CALLuser',session_id='$CALLsession_id',server_ip='$CALLserver_ip',session_id_3way='',status='NEW',agent_heartbeat=NOW();";
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
$affected_rowsA = $dbhA->do($stmtA);
if ($AGILOG) {$agi_string = "-- vicidial_3way_press_live INSERT: |$affected_rowsA|$stmtA|"; &agi_output;}
@@ -471,6 +472,13 @@ while ($wait_loop < 100)
$AGI->stream_file('hold_tone');
}
### Update agent_heartbeat on all outside-agent calls
$stmtA="UPDATE vicidial_3way_press_live SET agent_heartbeat=NOW() where call_3way_id IN('$allCIDs');";
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
$affected_rowsA = $dbhA->do($stmtA);
if ($AGILOG) {$agi_string = "-- vicidial_3way_press_live agent_heartbeat UPDATE: |$affected_rowsA|$stmtA|"; &agi_output;}
### Find all associated outside-agent calls
$stmtA = "SELECT status,call_3way_id FROM vicidial_3way_press_live where call_3way_id IN('$allCIDs') order by status desc limit 11;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
+65 -3
View File
@@ -53,10 +53,11 @@
# 231113-2041 - First Build
# 231227-1427 - Added multi-phone ability
# 240108-1503 - Added call_channel and call_transfer logging
# 240114-0946 - Added check of agent_heartbeat
#
$script = 'agi-3way_press_outside.agi';
$build = '231227-1427';
$build = '240114-0946';
$at='@';
$S='*';
@@ -332,7 +333,8 @@ $CALLsession_id='';
$CALLuser='';
$CALLlead_id='';
$CALLsession_id_3way='';
$stmtA = "SELECT server_ip,session_id,user,lead_id,session_id_3way FROM vicidial_3way_press_live where call_3way_id='$calleridname' order by call_date desc limit 1;";
$CALLagent_heartbeat=0;
$stmtA = "SELECT server_ip,session_id,user,lead_id,session_id_3way,UNIX_TIMESTAMP(agent_heartbeat) FROM vicidial_3way_press_live where call_3way_id='$calleridname' order by call_date desc limit 1;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
@@ -345,9 +347,39 @@ if ($sthArows > 0)
$CALLuser = $aryA[2];
$CALLlead_id = $aryA[3];
$CALLsession_id_3way = $aryA[4];
$CALLagent_heartbeat = $aryA[5];
}
$sthA->finish();
$heartbeat_test = ( (time()) - 9);
if ( ($sthArows > 0) && ($CALLagent_heartbeat <= $heartbeat_test) )
{
if ($AGILOG) {$agi_string = "3-WAY AGENT ERROR: heartbeat gone, exiting... |($CALLagent_heartbeat < $heartbeat_test)|$calleridname|"; &agi_output;}
### Update the call in vicidial_3way_press_live
$stmtA="DELETE FROM vicidial_3way_press_live where call_3way_id='$calleridname';";
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
$affected_rowsA = $dbhA->do($stmtA);
if ($AGILOG) {$agi_string = "-- vicidial_3way_press_live agent gone DELETE: |$affected_rowsA|$stmtA|"; &agi_output;}
### Update the call in vicidial_3way_press_log
$stmtA="UPDATE vicidial_3way_press_log SET result=CONCAT(result,'|Agent Gone: $SQLdate') where call_3way_id='$calleridname';";
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
$affected_rowsA = $dbhA->do($stmtA);
if ($AGILOG) {$agi_string = "-- vicidial_3way_press_log agent gone UPDATE: |$affected_rowsA|$stmtA|"; &agi_output;}
print "SET CONTEXT $context\n";
$result = <STDIN>;
checkresult($result);
print "SET EXTENSION i\n";
$result = <STDIN>;
checkresult($result);
print "SET PRIORITY 1\n";
$result = <STDIN>;
checkresult($result);
exit;
}
$stmtA = "SELECT user FROM vicidial_live_agents where lead_id='$lead_id' and server_ip='$CALLserver_ip' order by live_agent_id desc limit 1;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
@@ -451,7 +483,7 @@ if ($stage =~ /accepted/i)
$AGI->stream_file('hold_tone');
}
$stmtA = "SELECT status,session_id_3way FROM vicidial_3way_press_live where call_3way_id='$calleridname' order by call_date desc limit 1;";
$stmtA = "SELECT status,session_id_3way,UNIX_TIMESTAMP(agent_heartbeat) FROM vicidial_3way_press_live where call_3way_id='$calleridname' order by call_date desc limit 1;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
@@ -461,9 +493,39 @@ if ($stage =~ /accepted/i)
@aryA = $sthA->fetchrow_array;
$CALLstatus = $aryA[0];
$CALLconf_exten = $aryA[1];
$CALLagent_heartbeat = $aryA[2];
}
$sthA->finish();
$heartbeat_test = ( (time()) - 9);
if ($CALLagent_heartbeat <= $heartbeat_test)
{
if ($AGILOG) {$agi_string = "3-WAY AGENT ERROR: heartbeat gone 2, exiting... |($CALLagent_heartbeat < $heartbeat_test)|$calleridname|"; &agi_output;}
### Update the call in vicidial_3way_press_live
$stmtA="DELETE FROM vicidial_3way_press_live where call_3way_id='$calleridname';";
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
$affected_rowsA = $dbhA->do($stmtA);
if ($AGILOG) {$agi_string = "-- vicidial_3way_press_live agent gone 2 DELETE: |$affected_rowsA|$stmtA|"; &agi_output;}
### Update the call in vicidial_3way_press_log
$stmtA="UPDATE vicidial_3way_press_log SET result=CONCAT(result,'|Agent Gone: $SQLdate') where call_3way_id='$calleridname';";
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
$affected_rowsA = $dbhA->do($stmtA);
if ($AGILOG) {$agi_string = "-- vicidial_3way_press_log agent gone 2 UPDATE: |$affected_rowsA|$stmtA|"; &agi_output;}
print "SET CONTEXT $context\n";
$result = <STDIN>;
checkresult($result);
print "SET EXTENSION i\n";
$result = <STDIN>;
checkresult($result);
print "SET PRIORITY 1\n";
$result = <STDIN>;
checkresult($result);
exit;
}
if ( ($CALLstatus =~ /RESERVED/) && (length($CALLconf_exten) > 0) )
{
### Update the call in vicidial_3way_press_live
+3 -1
View File
@@ -1,4 +1,4 @@
Agent 3-way Press-1 Calls DOC Started: 2023-11-13 Updated: 2024-01-10
Agent 3-way Press-1 Calls DOC Started: 2023-11-13 Updated: 2024-01-14
This document will go over how to set up Agent Screen 3-way calls with outside
@@ -44,6 +44,7 @@ Transfer = The outside-user call is transferred to the agent and customer.
Declined = The outside-user call did not press '1' to accept the call.
Too Slow = Multi-Call Only, The outside-user did press '1' to accept the call, but another outside-user pressed '1' before them.
Defeated = Multi-Call Only, another outside-user pressed '1' before them, so this call was hung up.
Agent Gone = The agent 3way call is gone, no ability to accept outside-agent transfer
Hungup = Either the call timed out or another outside-user pressed '1' before them, so this call was hung up.
@@ -133,6 +134,7 @@ server_ip VARCHAR(15),
session_id_3way VARCHAR(20) default '',
status VARCHAR(40),
call_channel VARCHAR(100) default '',
agent_heartbeat DATETIME,
index(call_date),
index(caller_code),
index(call_3way_id),
+1
View File
@@ -82,3 +82,4 @@ IQNANQ - In-Queue call No-Agent-No-Queue drop
SRDROP - SHARED outbound campaign drop to in-group, not included in most DROP stats
HUCXXX - Enhanced Disconnect Logging level 3 failed calls, where 'XXX' is the disconnect code. For example: "HUC18" for Cause 18 (SIP 408 Request timeout)
ADAIR - Dead Air Auto, for AMD NOAUDIODATA calls
ACFLTR - Inbound call areacode filter check
+2 -1
View File
@@ -5065,6 +5065,7 @@ server_ip VARCHAR(15),
session_id_3way VARCHAR(20) default '',
status VARCHAR(40),
call_channel VARCHAR(100) default '',
agent_heartbeat DATETIME,
index(call_date),
index(caller_code),
index(call_3way_id),
@@ -5573,4 +5574,4 @@ INSERT INTO `wallboard_reports` VALUES ('AGENTS_AND_QUEUES','Agents and Queues',
UPDATE system_settings set vdc_agent_api_active='1';
UPDATE system_settings SET db_schema_version='1704',db_schema_update_date=NOW(),reload_timestamp=NOW();
UPDATE system_settings SET db_schema_version='1705',db_schema_update_date=NOW(),reload_timestamp=NOW();
+4
View File
@@ -2589,3 +2589,7 @@ ALTER TABLE vicidial_3way_press_log_archive ADD call_channel VARCHAR(100) defaul
ALTER TABLE vicidial_3way_press_log_archive ADD call_transfer ENUM('N','Y') default 'N';
UPDATE system_settings SET db_schema_version='1704',db_schema_update_date=NOW() where db_schema_version < 1704;
ALTER TABLE vicidial_3way_press_live ADD agent_heartbeat DATETIME;
UPDATE system_settings SET db_schema_version='1705',db_schema_update_date=NOW() where db_schema_version < 1705;
@@ -7,6 +7,7 @@
#
# 231228-2204 - First build
# 240108-1556 - Added channel/server display
# 240114-1018 - Added Agent Gone summary stat
#
$startMS = microtime();
@@ -443,6 +444,7 @@ else
$TOTtooslow=0;
$TOTdefeated=0;
$TOTtransfer=0;
$TOTagentgone=0;
$stmt = "SELECT date_format(call_date, '%Y-%m-%d %H:%i:%s') as date,user,lead_id,phone_number,outbound_cid,result,call_channel,server_ip from ".$vicidial_3way_press_log_table." where call_date <= '$query_date_END' and call_date >= '$query_date_BEGIN' $user_SQL $phone_number_SQL order by call_date desc limit 100000";
$rslt=mysql_to_mysqli($stmt, $link);
@@ -487,6 +489,7 @@ else
if (preg_match("/Declined/",$Rresult[$i])) {$TOTdeclined++;}
if (preg_match("/Too Slow/",$Rresult[$i])) {$TOTtooslow++;}
if (preg_match("/Defeated/",$Rresult[$i])) {$TOTdefeated++;}
if (preg_match("/Agent Gone/",$Rresult[$i])) {$TOTagentgone++;}
if (preg_match("/Transfer/",$Rresult[$i])) {$TOTtransfer++; $Rtransfer[$i]++;}
else
{$BD='<font color=red>'; $ED='</font>';}
@@ -520,6 +523,7 @@ else
$TOTtooslow = sprintf("%10s", $TOTtooslow);
$TOTdefeated = sprintf("%10s", $TOTdefeated);
$TOTtransfer = sprintf("%10s", $TOTtransfer);
$TOTagentgone = sprintf("%10s", $TOTagentgone);
$ASCII_text.=""._QXZ("Results Summary").":\n";
$ASCII_text.="+------------+------------+\n";
@@ -529,6 +533,7 @@ else
$ASCII_text.="| "._QXZ("Declined",10)." | $TOTdeclined |\n";
$ASCII_text.="| "._QXZ("Too Slow",10)." | $TOTtooslow |\n";
$ASCII_text.="| "._QXZ("Defeated",10)." | $TOTdefeated |\n";
$ASCII_text.="| "._QXZ("Agent Gone",10)." | $TOTagentgone |\n";
$ASCII_text.="| "._QXZ("Transfer",10)." | $TOTtransfer |\n";
$ASCII_text.="+------------+------------+\n";
@@ -546,6 +551,7 @@ else
$file_output .= "\""._QXZ("Declined")."\",\"".trim($TOTdeclined)."\"\n";
$file_output .= "\""._QXZ("Too Slow")."\",\"".trim($TOTtooslow)."\"\n";
$file_output .= "\""._QXZ("Defeated")."\",\"".trim($TOTdefeated)."\"\n";
$file_output .= "\""._QXZ("Agent Gone")."\",\"".trim($TOTagentgone)."\"\n";
$file_output .= "\""._QXZ("Transfer")."\",\"".trim($TOTtransfer)."\"\n";
$file_output .= "\n";
$file_output .= "\""._QXZ("Results Detail").":\"\n";