diff --git a/UPGRADE b/UPGRADE index bdb3ff8d..44268c54 100644 --- a/UPGRADE +++ b/UPGRADE @@ -86,6 +86,10 @@ OTHER CHANGES: 18. Added display options for agent screen Transfer-conf buttons in the User Group modification screen. +19. Added ra_call_control function to agent API to allow for hangup and transfer + of calls sent to a Remote Agent also allows for setting of a disposition + for more information read the AGENT_API.txt doc. + diff --git a/docs/AGENT_API.txt b/docs/AGENT_API.txt index 03e26a29..fed803e2 100644 --- a/docs/AGENT_API.txt +++ b/docs/AGENT_API.txt @@ -20,7 +20,7 @@ update_fields - changes values for selected data fields in the agent interface set_timer_action - sets timer action for the current call the agent is on st_login_log - looks up the vicidial_users.custom_three field and logs event from CRM st_get_agent_active_lead - looks up active lead info for an agent and outputs lead information - +ra_call_control - remote agent call control: hangup/transfer calls being handled by remote agents New scripts: @@ -344,6 +344,40 @@ SUCCESS: st_get_agent_active_lead lead found - 6666|7275551212|123456|9987-12347 +-------------------------------------------------------------------------------- +ra_call_control - + +DESCRIPTION: +Allows for remote agent call control: hangup/transfer calls being handled by remote agents, also options for recording a disposition and call length + +VALUES: +value - + REQUIRED, The call ID of the call as received as CallerIDname field or a special SIP-header, i.e. Y0315201639000402027 +agent_user - + REQUIRED, alphanumeric string for remote agent user +stage - + REQUIRED, one of these choices: 'HANGUP','EXTENSIONTRANSFER','INGROUPTRANSFER' +ingroup_choices - + OPTIONAL, only required if INGROUPTRANSFER stage is used, must be a single active in-group, reserved option of "DEFAULTINGROUP" can be used to send the call to the default in-group for the in-group or campaign that originated the call to the remote agent +phone_number - + OPTIONAL, only required if EXTENSIONTRANSFER stage is used, must be a full number when dialed that will dial through the default context +status - + OPTIONAL, status of the call, maximum of 6 characters, if not set, status will be RAXFER + +EXAMPLE URLS: +http://server/agc/api.php?source=test&user=6666&pass=1234&agent_user=1028&function=ra_call_control&stage=INGROUPTRANSFER&ingroup_choices=DEFAULTINGROUP&value=Y0316001655000402028 + +RESPONSES: +ERROR: ra_call_control not valid - Y0315201639000402027|6666|INGROUPTRANSFER +ERROR: no user found - 6666 +ERROR: user not logged in - 6666 +ERROR: no active call found - Y0315201639000402027 +ERROR: phone_number is not valid - 9 +ERROR: ingroup is not valid - TESTINGROUP +ERROR: stage is not valid - XYZ +SUCCESS: ra_call_control transferred - 6666|Y0315201639000402027|SALESLINE +SUCCESS: ra_call_control hungup - 6666|Y0315201639000402027|HANGUP + diff --git a/docs/VICIDIAL_statuses.txt b/docs/VICIDIAL_statuses.txt index 9e70d877..d3ee6c91 100644 --- a/docs/VICIDIAL_statuses.txt +++ b/docs/VICIDIAL_statuses.txt @@ -52,3 +52,4 @@ CPDERR - Sangoma Call Progress Detection CPD Error TIMEOT - Inbound call Drop Timeout, call waited until drop-seconds and was sent on to the drop action AFTHRS - Inbound after hours drop, call received outside of in-group call time NANQUE - Inbound no agent no queue drop, no agent logged in +RAXFER - Remote Agent API transfer diff --git a/www/agc/api.php b/www/agc/api.php index be13e2d9..fa3b0cde 100644 --- a/www/agc/api.php +++ b/www/agc/api.php @@ -1,7 +1,7 @@ LICENSE: AGPLv2 +# Copyright (C) 2010 Matt Florell LICENSE: AGPLv2 # # This script is designed as an API(Application Programming Interface) to allow # other programs to interact with the VICIDIAL Agent screen @@ -27,6 +27,8 @@ # - $ingroup_choices - (' TEST_IN SALESLINE -') # - $set_as_default - ('YES','NO') # - $alt_user +# - $stage +# - $status # CHANGELOG: # 80703-2225 - First build of script @@ -40,10 +42,11 @@ # 91130-1307 - Added change_ingroups(Manager InGroup change feature) # 91211-1805 - Added st_login_log and st_get_agent_active_lead functions, added alt_user # 91228-1059 - Added update_fields function +# 100315-2021 - Added ra_call_control function # -$version = '2.2.0-11'; -$build = '91228-1059'; +$version = '2.2.0-12'; +$build = '100315-2021'; require("dbconnect.php"); @@ -140,6 +143,10 @@ if (isset($_GET["rank"])) {$rank=$_GET["rank"];} elseif (isset($_POST["rank"])) {$rank=$_POST["rank"];} if (isset($_GET["owner"])) {$owner=$_GET["owner"];} elseif (isset($_POST["owner"])) {$owner=$_POST["owner"];} +if (isset($_GET["stage"])) {$stage=$_GET["stage"];} + elseif (isset($_POST["stage"])) {$stage=$_POST["stage"];} +if (isset($_GET["status"])) {$status=$_GET["status"];} + elseif (isset($_POST["status"])) {$status=$_POST["status"];} header ("Content-type: text/html; charset=utf-8"); header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 @@ -250,7 +257,7 @@ if ($function == 'version') ################################################################################ -### BEGIN - user validation section +### BEGIN - user validation section (most functions run through this first) ################################################################################ if ($ACTION == 'LogiNCamPaigns') @@ -310,6 +317,7 @@ else if ($format=='debug') { + $DB=1; echo "\n"; echo "\n"; echo "";} + # $rslt=mysql_query($stmt, $link); + $result = 'SUCCESS'; + $result_reason = "ra_call_control hungup"; + echo "$result: $result_reason - $agent_user|$value|HANGUP\n"; + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + } + if ($stage=='EXTENSIONTRANSFER') + { + $processed++; + if (strlen($phone_number) < 2) + { + $result = 'ERROR'; + $result_reason = "phone_number is not valid"; + echo "$result: $result_reason - $phone_number\n"; + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + } + else + { + $stmt = "select ext_context from servers where server_ip='$server_ip';"; + if ($DB) {echo "$stmt\n";} + $rslt=mysql_query($stmt, $link); + $row=mysql_fetch_row($rslt); + $ext_context = $row[0]; + + $TRANSFERcid = $value; + $TRANSFERcid = preg_replace("/^..../",'XAPI',$TRANSFERcid); + + $stmtX="INSERT INTO vicidial_manager values('','','$NOW_TIME','NEW','N','$server_ip','','Redirect','$TRANSFERcid','Channel: $channel','Context: $ext_context','Exten: $phone_number','Priority: 1','CallerID: $TRANSFERcid','','','','','');"; + # if ($format=='debug') {echo "\n";} + # $rslt=mysql_query($stmt, $link); + $result = 'SUCCESS'; + $result_reason = "ra_call_control transfer"; + echo "$result: $result_reason - $agent_user|$value|$phone_number\n"; + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + } + } + if ($stage=='INGROUPTRANSFER') + { + $processed++; + if (strlen($ingroup_choices) < 2) + { + $result = 'ERROR'; + $result_reason = "ingroup is not valid"; + echo "$result: $result_reason - $ingroup_choices\n"; + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + } + else + { + $stmt = "select ext_context from servers where server_ip='$server_ip';"; + if ($DB) {echo "$stmt\n";} + $rslt=mysql_query($stmt, $link); + $row=mysql_fetch_row($rslt); + $ext_context = $row[0]; + + if (preg_match("/DEFAULTINGROUP/",$ingroup_choices)) + { + if ($call_type=='IN') + { + $stmt = "select default_xfer_group from vicidial_inbound_groups where group_id='$campaign_id';"; + } + else + { + $stmt = "select default_xfer_group from vicidial_campaigns where campaign_id='$campaign_id';"; + } + if ($DB) {echo "$stmt\n";} + $rslt=mysql_query($stmt, $link); + $row=mysql_fetch_row($rslt); + $ingroup_choices = $row[0]; + } + + $stmt = "select count(*) from vicidial_inbound_groups where group_id='$ingroup_choices' and active='Y';"; + if ($DB) {echo "$stmt\n";} + $rslt=mysql_query($stmt, $link); + $row=mysql_fetch_row($rslt); + $ingroupactive = $row[0]; + + if ($ingroupactive < 1) + { + $result = 'ERROR'; + $result_reason = "ingroup is not valid"; + echo "$result: $result_reason - $ingroup_choices\n"; + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + } + else + { + $TRANSFERcid = $value; + $TRANSFERcid = preg_replace("/^..../",'XAPI',$TRANSFERcid); + + $TRANSFERexten = "90009*$ingroup_choices**$lead_id**$vdac_phone**$agent_user**"; + + $stmtX="INSERT INTO vicidial_manager values('','','$NOW_TIME','NEW','N','$server_ip','','Redirect','$TRANSFERcid','Channel: $channel','Context: $ext_context','Exten: $TRANSFERexten','Priority: 1','CallerID: $TRANSFERcid','','','','','');"; + # if ($format=='debug') {echo "\n";} + # $rslt=mysql_query($stmt, $link); + $result = 'SUCCESS'; + $result_reason = "ra_call_control transfer"; + echo "$result: $result_reason - $agent_user|$value|$phone_number\n"; + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + } + } + } + if ($processed < 1) + { + $result = 'ERROR'; + $result_reason = "stage is not valid"; + echo "$result: $result_reason - $stage\n"; + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + } + + if ($result == 'SUCCESS') + { + if (strlen($status)<1) + {$status='RAXFER';} + if ($call_type=='IN') + { + $stmt = "UPDATE vicidial_closer_log SET status='$status' where uniqueid='$uniqueid' and lead_id='$lead_id' and campaign_id='$campaign_id' order by call_date desc limit 1;"; + } + else + { + $stmt = "UPDATE vicidial_log SET status='$status',user='$agent_user' where uniqueid='$uniqueid' and lead_id='$lead_id' order by call_date desc limit 1;"; + } + if ($format=='debug') {echo "\n";} + $rslt=mysql_query($stmt, $link); + + $stmt = "UPDATE vicidial_list SET status='$status' where lead_id='$lead_id' limit 1;"; + if ($format=='debug') {echo "\n";} + $rslt=mysql_query($stmt, $link); + + $StarTtime = date("U"); + $RArandom = (rand(1000000, 9999999) + 10000000); + + ############################################# + ##### START QUEUEMETRICS LOGGING LOOKUP ##### + $stmt = "SELECT enable_queuemetrics_logging,queuemetrics_server_ip,queuemetrics_dbname,queuemetrics_login,queuemetrics_pass,queuemetrics_log_id FROM system_settings;"; + $rslt=mysql_query($stmt, $link); + if ($DB) {echo "$stmt\n";} + $qm_conf_ct = mysql_num_rows($rslt); + if ($qm_conf_ct > 0) + { + $row=mysql_fetch_row($rslt); + $enable_queuemetrics_logging = $row[0]; + $queuemetrics_server_ip = $row[1]; + $queuemetrics_dbname = $row[2]; + $queuemetrics_login = $row[3]; + $queuemetrics_pass = $row[4]; + $queuemetrics_log_id = $row[5]; + } + ##### END QUEUEMETRICS LOGGING LOOKUP ##### + ########################################### + if ($enable_queuemetrics_logging > 0) + { + $linkB=mysql_connect("$queuemetrics_server_ip", "$queuemetrics_login", "$queuemetrics_pass"); + mysql_select_db("$queuemetrics_dbname", $linkB); + + $stmt = "SELECT time_id from queue_log where call_id='$value' and queue='$campaign_id' and agent='Agent/$ra_user' and verb='CONNECT';"; + $rslt=mysql_query($stmt, $linkB); + if ($DB) {echo "$stmt\n";} + $qm_con_ct = mysql_num_rows($rslt); + if ($qm_con_ct > 0) + { + $row=mysql_fetch_row($rslt); + $ra_time_id = $row[0]; + $ra_length = ($StarTtime - $ra_time_id); + } + if ($ra_length < 1) {$ra_length=1;} + $ra_stage = preg_replace("/XFER|CLOSER|-/",'',$ra_stage); + if ($ra_stage < 0.25) {$ra_stage=0;} + + $stmt = "INSERT INTO queue_log SET partition='P01',time_id='$StarTtime',call_id='$value',queue='$campaign_id',agent='Agent/$ra_user',verb='COMPLETEAGENT',data1='$ra_stage',data2='$ra_length',data3='$queue_position',serverid='$queuemetrics_log_id';"; + if ($format=='debug') {echo "\n";} + $rslt=mysql_query($stmt, $linkB); + + $stmt = "INSERT INTO queue_log SET partition='P01',time_id='$StarTtime',call_id='$value',queue='$campaign_id',agent='Agent/$ra_user',verb='CALLSTATUS',data1='$status',serverid='$queuemetrics_log_id';"; + if ($format=='debug') {echo "\n";} + $rslt=mysql_query($stmt, $linkB); + + $stmt = "INSERT INTO queue_log SET partition='P01',time_id='$StarTtime',call_id='NONE',queue='NONE',agent='Agent/$ra_user',verb='PAUSEALL',serverid='$queuemetrics_log_id';"; + if ($format=='debug') {echo "\n";} + $rslt=mysql_query($stmt, $linkB); + + $stmt = "INSERT INTO queue_log SET partition='P01',time_id='$StarTtime',call_id='NONE',queue='NONE',agent='Agent/$ra_user',verb='UNPAUSEALL',serverid='$queuemetrics_log_id';"; + if ($format=='debug') {echo "\n";} + $rslt=mysql_query($stmt, $linkB); + } + + ### finally send the call + if ($format=='debug') {echo "\n";} + $rslt=mysql_query($stmtX, $link); + + $stmt = "UPDATE vicidial_live_agents set random_id='$RArandom',last_call_finish='$NOW_TIME',lead_id='',uniqueid='',callerid='',channel='',last_state_change='$NOW_TIME' where user='$ra_user' and server_ip='$ra_server_ip';"; + if ($format=='debug') {echo "\n";} + $rslt=mysql_query($stmt, $link); + + $stmt = "UPDATE vicidial_live_agents set status='READY' where user='$ra_user' and server_ip='$ra_server_ip';"; + if ($format=='debug') {echo "\n";} + $rslt=mysql_query($stmt, $link); + + $stmt = "DELETE from vicidial_auto_calls where callerid='$value';"; + if ($format=='debug') {echo "\n";} + $rslt=mysql_query($stmt, $link); + } + } + else + { + $result = 'ERROR'; + $result_reason = "no active call found"; + echo "$result: $result_reason - $value\n"; + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + } + } + else + { + $result = 'ERROR'; + $result_reason = "agent_user is not logged in"; + echo "$result: $result_reason - $agent_user\n"; + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + } + } + } +################################################################################ +### END - ra_call_control +################################################################################ + + + + if ($format=='debug') {