From f848b67b34e72ebb2c5bfeec4e13f25eaff15799 Mon Sep 17 00:00:00 2001 From: mattf Date: Fri, 14 Dec 2018 22:07:17 +0000 Subject: [PATCH] Added lead_callback_info Non-Agent API function, it outputs scheduled callback data for a specific lead git-svn-id: svn://192.168.202.10@3057 3d104415-ff17-0410-8863-d5cf3c621b8a --- UPGRADE | 3 + docs/NON-AGENT_API.txt | 43 ++++++- www/vicidial/non_agent_api.php | 228 ++++++++++++++++++++++++++++++++- 3 files changed, 271 insertions(+), 3 deletions(-) diff --git a/UPGRADE b/UPGRADE index a3bc66b0..40ff43be 100644 --- a/UPGRADE +++ b/UPGRADE @@ -368,6 +368,9 @@ OTHER CHANGES: 102. Added SYSTEM options to the campaign detail Manual Dial Filter feature +103. Added lead_callback_info Non-Agent API function, it outputs scheduled + callback data for a specific lead + diff --git a/docs/NON-AGENT_API.txt b/docs/NON-AGENT_API.txt index 67a68fee..c920ec4f 100644 --- a/docs/NON-AGENT_API.txt +++ b/docs/NON-AGENT_API.txt @@ -1,4 +1,4 @@ -NON-AGENT API DOCUMENT Started: 2008-07-24 Updated: 2018-09-16 +NON-AGENT API DOCUMENT Started: 2008-07-24 Updated: 2018-12-14 This document describes the functions of an API(Application Programming Interface) for all functions NOT directly relating to the VICIDIAL Agent screen. @@ -47,6 +47,8 @@ ccc_lead_info - outputs lead data for cross-cluster-communication call lead_status_search - displays all field values of all leads that match the status and call date in request call_status_stats - report on number of calls made by campaign and ingroup, with hourly and status breakdowns call_dispo_report - call disposition breakdown report +lead_callback_info - outputs scheduled callback data for a specific lead + New scripts: /vicidial/non_agent_api.php - the script that is accessed to execute commands @@ -137,6 +139,7 @@ Changes: 180208-1655 - Added call_dispo_report function 180331-1716 - Added options to update_campaign, add_user, update_phone. Added function update_did 180916-1059 - Added check for daily list reset limit +181214-1606 - Added lead_callback_info function API Functions use the 'function' variable @@ -659,6 +662,44 @@ TD|6666|554443||501|-4.00|1|9998887112|Mr|Billy'Oj|U|O'Reillyo|ad1|ad2|ad3|city +-------------------------------------------------------------------------------- +lead_callback_info - outputs scheduled callback data for a specific lead + +NOTE: api user for this function must have user_level set to 7 or higher and "view reports" enabled + +REQUIRED FIELDS- +source - description of what originated the API call (maximum 20 characters) +lead_id - 16-40 characters + +SETTINGS FIELDS- +stage - the format of the exported data: csv, tab, newline, pipe(default) +header - include a header(YES) or not(NO). This is optional, default is not to include a header +search_location - Where to check for scheduled callback records in the system, can select only one(default is CURRENT): + CURRENT - check for active scheduled callbacks + ARCHIVE - check for archived scheduled callbacks + ALL - check for both active and archived scheduled callbacks + +Example URL strings for API calls: +http://server/vicidial/non_agent_api.php?source=test&user=6666&pass=1234&function=lead_callback_info&lead_id=12345&stage=pipe&header=YES&search_location=ALL +http://server/vicidial/non_agent_api.php?source=test&user=6666&pass=1234&function=lead_callback_info&lead_id=846446&search_location=ALL&header=YES + +Example responses: +ERROR: lead_callback_info USER DOES NOT HAVE PERMISSION TO GET LEAD INFO - 6666|0 +ERROR: lead_callback_info INVALID SEARCH PARAMETERS - 6666|| +ERROR: lead_callback_info LEAD NOT FOUND - 6666|| +ERROR: lead_callback_info CALLBACK NOT FOUND - 6666|| + +A SUCCESS response will not show "SUCCESS", but instead will just print the results in the following format(The most recent callback entry will be at the bottom of the results): +lead_id|callback_type|recipient|callback_status|lead_status|callback_date|entry_date|user|list_id|campaign_id|user_group|customer_timezone|customer_time|comments +846446|ARCHIVE|USERONLY|INACTIVE|CBTEST|2018-09-01 15:00:00|2018-08-27 01:06:45|6666|107|TESTCAMP|ADMIN|AUS-ACST-N-Northern Territory Time Zone|2018-08-27 00:00:00| +846446|ARCHIVE|USERONLY|INACTIVE|CBTEST|2018-12-14 14:00:00|2018-12-14 16:42:32|6666|107|TESTCAMP|ADMIN||2018-12-14 14:00:00|Call back after lunch +846446|CURRENT|USERONLY|INACTIVE|CBTEST|2018-12-14 19:00:00|2018-12-14 16:44:08|6666|107|TESTCAMP|ADMIN||2018-12-14 19:00:00|Call back after dinner +846446|CURRENT|USERONLY|ACTIVE|CBLEAD|2018-12-17 10:00:00|2018-12-14 16:50:56|6666|107|TESTCAMP|ADMIN|USA-EST-Y-Eastern US Time Zone|2018-12-17 10:00:00|try back Monday morning + + + + + -------------------------------------------------------------------------------- update_log_entry - updates the status of a vicidial_log or vicidial_closer_log entry diff --git a/www/vicidial/non_agent_api.php b/www/vicidial/non_agent_api.php index a489f365..ff77fae2 100644 --- a/www/vicidial/non_agent_api.php +++ b/www/vicidial/non_agent_api.php @@ -133,10 +133,11 @@ # 180331-1716 - Added options to update_campaign, add_user, update_phone. Added function update_did # 180529-1102 - Fix for QM live monitoring # 180916-1059 - Added check for daily list reset limit +# 181214-1606 - Added lead_callback_info function # -$version = '2.14-110'; -$build = '180916-1059'; +$version = '2.14-111'; +$build = '181214-1606'; $api_url_log = 0; $startMS = microtime(); @@ -7181,6 +7182,229 @@ if ($function == 'ccc_lead_info') + +################################################################################ +### lead_callback_info - outputs scheduled callback data for a specific lead +################################################################################ +if ($function == 'lead_callback_info') + { + if(strlen($source)<2) + { + $result = 'ERROR'; + $result_reason = "Invalid Source"; + echo "$result: $result_reason - $source\n"; + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + echo "ERROR: Invalid Source: |$source|\n"; + exit; + } + else + { + if ( (!preg_match("/ $function /",$api_allowed_functions)) and (!preg_match("/ALL_FUNCTIONS/",$api_allowed_functions)) ) + { + $result = 'ERROR'; + $result_reason = "auth USER DOES NOT HAVE PERMISSION TO USE THIS FUNCTION"; + echo "$result: $result_reason: |$user|$function|\n"; + $data = "$allowed_user"; + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + exit; + } + $stmt="SELECT count(*) from vicidial_users where user='$user' and vdc_agent_api_access='1' and view_reports='1' and user_level > 6 and active='Y';"; + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $allowed_user=$row[0]; + if ($allowed_user < 1) + { + $result = 'ERROR'; + $result_reason = "lead_callback_info USER DOES NOT HAVE PERMISSION TO GET LEAD INFO"; + echo "$result: $result_reason: |$user|$allowed_user|\n"; + $data = "$allowed_user"; + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + exit; + } + else + { + $call_search_SQL=''; + $search_ready=0; + + if ( (strlen($lead_id)>0) and (strlen($lead_id)<12) ) + { + $call_search_SQL .= "where lead_id='$lead_id'"; + $search_ready++; + } + if ($search_ready < 1) + { + $result = 'ERROR'; + $result_reason = "lead_callback_info INVALID SEARCH PARAMETERS"; + $data = "$user|$lead_id"; + echo "$result: $result_reason: $data\n"; + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + exit; + } + else + { + $stmt="SELECT admin_viewable_groups,allowed_campaigns from vicidial_user_groups where user_group='$LOGuser_group';"; + if ($DB) {$MAIN.="|$stmt|\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $LOGadmin_viewable_groups = $row[0]; + $LOGallowed_campaigns = $row[1]; + + $LOGallowed_campaignsSQL=''; + if ( (!preg_match("/ALL-CAMPAIGNS/i",$LOGallowed_campaigns)) ) + { + $LOGallowed_campaignsSQL = preg_replace('/\s-/i','',$LOGallowed_campaigns); + $LOGallowed_campaignsSQL = preg_replace('/\s/i',"','",$LOGallowed_campaignsSQL); + $LOGallowed_campaignsSQL = "and campaign_id IN('$LOGallowed_campaignsSQL')"; + } + + $k=0; + $output=''; + $DLset=0; + if ($stage == 'csv') + {$DL = ','; $DLset++;} + if ($stage == 'tab') + {$DL = "\t"; $DLset++;} + if ($stage == 'newline') + {$DL = "\n"; $DLset++;} + if ($stage == 'pipe') + {$DL = '|'; $DLset++;} + if ($DLset < 1) + {$DL='|'; $stage='pipe';} + if (strlen($time_format) < 1) + {$time_format = 'HF';} + if ($header == 'YES') + { + $output .= 'lead_id' . $DL . 'callback_type' . $DL . 'recipient' . $DL . 'callback_status' . $DL . 'lead_status' . $DL . 'callback_date' . $DL . 'entry_date' . $DL . 'user' . $DL . 'list_id' . $DL . 'campaign_id' . $DL . 'user_group' . $DL . 'customer_timezone' . $DL . 'customer_time' . $DL . 'comments' . "\n"; + } + + if ( ($search_location == 'ARCHIVE') or ($search_location == 'ALL') ) + { + # search archive callbacks + $stmt="SELECT recipient,status,lead_status,callback_time,entry_time,user,list_id,campaign_id,user_group,comments,customer_timezone,customer_time from vicidial_callbacks_archive $call_search_SQL order by callback_id;"; + $rslt=mysql_to_mysqli($stmt, $link); + if ($DB) {echo "$stmt\n";} + $vcb_to_list = mysqli_num_rows($rslt); + $r=0; + while ($vcb_to_list > $r) + { + $row=mysqli_fetch_row($rslt); + $callback_type = 'ARCHIVE'; + $CBrecipient = $row[0]; + $CBstatus = $row[1]; + $CBlead_status = $row[2]; + $CBcallback_time = $row[3]; + $CBentry_time = $row[4]; + $CBuser = $row[5]; + $CBlist_id = $row[6]; + $CBcampaign_id = $row[7]; + $CBuser_group = $row[8]; + $CBcomments = $row[9]; + $CBcustomer_timezone = $row[10]; + $CBcustomer_timezone = preg_replace("/,/",'-',$CBcustomer_timezone); + $CBcustomer_time = $row[11]; + + if ( (strlen($LOGallowed_campaignsSQL) > 3) and ($api_list_restrict > 0) ) + { + $stmt="SELECT count(*) from vicidial_lists where list_id='$CBlist_id' $LOGallowed_campaignsSQL;"; + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $allowed_list=$row[0]; + if ($allowed_list < 1) + { + $result = 'ERROR'; + $result_reason = "lead_callback_info LEAD NOT FOUND"; + echo "$result: $result_reason: |$user|$allowed_user|\n"; + $data = "$allowed_user"; + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + exit; + } + } + + $output .= "$lead_id$DL$callback_type$DL$CBrecipient$DL$CBstatus$DL$CBlead_status$DL$CBcallback_time$DL$CBentry_time$DL$CBuser$DL$CBlist_id$DL$CBcampaign_id$DL$CBuser_group$DL$CBcustomer_timezone$DL$CBcustomer_time$DL$CBcomments\n"; + $r++; + } + } + + if ( ($search_location == 'CURRENT') or ($search_location == 'ALL') or ($search_location == '') ) + { + # search current callbacks + $stmt="SELECT recipient,status,lead_status,callback_time,entry_time,user,list_id,campaign_id,user_group,comments,customer_timezone,customer_time from vicidial_callbacks $call_search_SQL order by callback_id;"; + $rslt=mysql_to_mysqli($stmt, $link); + if ($DB) {echo "$stmt\n";} + $vcb_to_list = mysqli_num_rows($rslt); + $r=0; + while ($vcb_to_list > $r) + { + $row=mysqli_fetch_row($rslt); + $callback_type = 'CURRENT'; + $CBrecipient = $row[0]; + $CBstatus = $row[1]; + $CBlead_status = $row[2]; + $CBcallback_time = $row[3]; + $CBentry_time = $row[4]; + $CBuser = $row[5]; + $CBlist_id = $row[6]; + $CBcampaign_id = $row[7]; + $CBuser_group = $row[8]; + $CBcomments = $row[9]; + $CBcustomer_timezone = $row[10]; + $CBcustomer_timezone = preg_replace("/,/",'-',$CBcustomer_timezone); + $CBcustomer_time = $row[11]; + + if ( (strlen($LOGallowed_campaignsSQL) > 3) and ($api_list_restrict > 0) ) + { + $stmt="SELECT count(*) from vicidial_lists where list_id='$CBlist_id' $LOGallowed_campaignsSQL;"; + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $allowed_list=$row[0]; + if ($allowed_list < 1) + { + $result = 'ERROR'; + $result_reason = "lead_callback_info LEAD NOT FOUND"; + echo "$result: $result_reason: |$user|$allowed_user|\n"; + $data = "$allowed_user"; + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + exit; + } + } + + $output .= "$lead_id$DL$callback_type$DL$CBrecipient$DL$CBstatus$DL$CBlead_status$DL$CBcallback_time$DL$CBentry_time$DL$CBuser$DL$CBlist_id$DL$CBcampaign_id$DL$CBuser_group$DL$CBcustomer_timezone$DL$CBcustomer_time$DL$CBcomments\n"; + $r++; + } + } + + if ( ( ( ($header == 'NO') or ($header == '') ) and (strlen($output) > 10) ) or ( ($header == 'YES') and (strlen($output) > 170) ) ) + { + echo "$output"; + + $result = 'SUCCESS'; + $data = "$user|$lead_id|$stage|$search_location"; + $result_reason = "lead_callback_info $output"; + + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + } + else + { + $result = 'ERROR'; + $result_reason = "lead_callback_info CALLBACK NOT FOUND"; + $data = "$user|$lead_id|$stage|$search_location"; + echo "$result: $result_reason: $data\n"; + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + exit; + } + } + } + } + exit; + } +################################################################################ +### lead_callback_info - outputs lead data for cross-cluster-communication call +################################################################################ + + + + + ################################################################################ ### lead_field_info - pulls the value of one field of a lead ################################################################################