Added available_agents and status_link button options as well as validation of active in-group to the chat_customer screen.

git-svn-id: svn://192.168.202.10@2464 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
mattf
2016-01-09 02:23:52 +00:00
parent 2deeac7ee4
commit 4dde6be345
9 changed files with 129 additions and 11 deletions
+3
View File
@@ -230,6 +230,9 @@ OTHER CHANGES:
58. Added in-group option for On-Hook CID Number.
59. Added available_agents and status_link button options as well as validation
of active in-group to the chat_customer screen.
+16 -2
View File
@@ -1,4 +1,4 @@
CHAT MESSAGING Started 2014-05-01 Updated 2015-12-19
CHAT MESSAGING Started 2014-05-01 Updated 2016-01-08
After over 18 months of development, the Chat Messaging system for Vicidial was added to svn/trunk on December 13th, 2015(svn revision 2428). Our Chat messaging allows for customers to chat with agents from websites, as well as allowing managers to chat with agents and agents to chat with other agents all within their existing agent screen.
@@ -46,7 +46,17 @@ In the Administration web screen, there is a new link at the top of the screen n
CUSTOMER CHAT INSTRUCTIONS:
There is a new folder in the web directory called "chat_customer". You will find a file in this folder called "customer_chat_code.php" that you can use to write your own web page for a customer to chat from, or you can just use that page as your Chat URL. The Chat URL is a field in the System Settings that you need to populate in order for the customer chat to work. To use the default for this, just add "chat_customer/customer_chat_code.php" to your current Vicidial webserver URL. For example, if your current webserver url is "http://192.168.1.2/" then you can use this as your Chat URL: "http://192.168.1.2/chat_customer/customer_chat_code.php"
There is a new folder in the web directory called "chat_customer". You will find a file in this folder called "customer_chat_code.php" that you can use to write your own web page for a customer to chat from, or you can just use that page as your Chat URL. The Chat URL is a field in the System Settings that you need to populate in order for the customer chat to work. To use the default for this, just add "chat_customer/customer_chat_code.php" to your current Vicidial webserver URL. For example, if your current webserver url is "http://192.168.1.2/" then you can use this as your Chat URL:
"http://192.168.1.2/chat_customer/customer_chat_code.php"
or
"http://192.168.1.2/chat_customer/vicidial_chat_customer_side.php"
There are several variables you can use to assemble a link to a customer chat window on your website:
group_id - the Inbound Chat Group that you want to use
language - if different than default English, the language the customer chat screen should use
available_agents - only allow chats to start if there are LOGGED_IN agents or WAITING_ONLY agents available
status_link - set to Y if you want to use as a button only on your website showing if chat agents are available or not(150 x 37 pixels)
If you want to link to chat with a specific in-group, you can use a link like this,
@@ -63,6 +73,10 @@ If you want to put a chat page within your own IFRAME and use a specific in-grou
http://192.168.1.2/chat_customer/vicidial_chat_customer_side.php?group_id=TESTCHAT&language=new_spanish
If you want to link to a chat status button with a specific in-group and langauge and only if agents are ready and waiting, you can use a link like this,
http://192.168.1.2/chat_customer/vicidial_chat_customer_side.php?status_link=Y&user=&lead_id=&group_id=MIKECHAT&language=new_spanish&available_agents=WAITING_ONLY
Chat settings in System Settings:
+5 -2
View File
@@ -1,7 +1,7 @@
<?php
# customer_chat_code.php
#
# Copyright (C) 2015 Joe Johnson, Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
# Copyright (C) 2016 Joe Johnson, Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
#
# Example for incorporating the customer side of the Vicidial chat into a web page.
# Can be called as an include file, if desired.
@@ -10,6 +10,7 @@
# 151212-0829 - First Build for customer chat
# 151217-1015 - Allow for group_id variable
# 151219-1415 - Added header and language variable
# 160108-1659 - Added available_agents variable
#
if (isset($_GET["lead_id"])) {$lead_id=$_GET["lead_id"];}
@@ -26,8 +27,10 @@ if (isset($_GET["unique_userID"])) {$unique_userID=$_GET["unique_userID"];}
elseif (isset($_POST["unique_userID"])) {$unique_userID=$_POST["unique_userID"];}
if (isset($_GET["language"])) {$language=$_GET["language"];}
elseif (isset($_POST["language"])) {$language=$_POST["language"];}
if (isset($_GET["available_agents"])) {$available_agents=$_GET["available_agents"];}
elseif (isset($_POST["available_agents"])) {$available_agents=$_POST["available_agents"];}
$URL_vars="?user=".urlencode($unique_userID)."&lead_id=".$lead_id."&group_id=".urlencode($chat_group_id)."&chat_id=".$chat_id."&email=".urlencode($email)."&language=".urlencode($language);
$URL_vars="?user=".urlencode($unique_userID)."&lead_id=".$lead_id."&group_id=".urlencode($chat_group_id)."&chat_id=".$chat_id."&email=".urlencode($email)."&language=".urlencode($language)."&available_agents=".urlencode($available_agents);
header ("Content-type: text/html; charset=utf-8");
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header ("Pragma: no-cache"); // HTTP/1.0
@@ -6,6 +6,7 @@
# 151213-1106 - Added variable filtering
# 151217-1016 - Allow for carrying of group_id through to new chat
# 151219-0850 - Added translation code
# 160108-1710 - Added available_agents variable
#
require("dbconnect_mysqli.php");
@@ -40,6 +41,8 @@ if (isset($_GET["current_message_count"])) {$current_message_count=$_GET["curr
elseif (isset($_POST["current_message_count"])) {$current_message_count=$_POST["current_message_count"];}
if (isset($_GET["language"])) {$language=$_GET["language"];}
elseif (isset($_POST["language"])) {$language=$_POST["language"];}
if (isset($_GET["available_agents"])) {$available_agents=$_GET["available_agents"];}
elseif (isset($_POST["available_agents"])) {$available_agents=$_POST["available_agents"];}
$chat_member_name = preg_replace('/[^- \.\,\_0-9a-zA-Z]/',"",$chat_member_name);
if (!$user) {echo "No user, no using."; exit;}
@@ -50,6 +53,7 @@ $chat_level = preg_replace('/[^- \_\.0-9a-zA-Z]/','',$chat_level);
$group_id = preg_replace('/[^- \_0-9a-zA-Z]/','',$group_id);
$language = preg_replace('/[^-\_0-9a-zA-Z]/','',$language);
$chat_member_name = preg_replace("/\'|\"|\\\\|;/","",$chat_member_name);
$available_agents = preg_replace('/[^-\_0-9a-zA-Z]/','',$available_agents);
if ($non_latin < 1)
{
@@ -174,7 +178,7 @@ if ($action=="update_chat_window" && $chat_id) {
$status_stmt="SELECT status, chat_creator from vicidial_live_chats where chat_id='$chat_id'";
$status_rslt=mysql_to_mysqli($status_stmt, $link);
if (mysqli_num_rows($status_rslt)==0) {
echo "<font class='chat_title alert'>"._QXZ("Chat does not exist or has been closed").": $chat_id</font><BR/><BR/><font class='chat_title'><a href='".$chat_url."?group_id=$group_id&language=$language'>"._QXZ("GO BACK TO CHAT FORM")."</a></font>\n";
echo "<font class='chat_title alert'>"._QXZ("Chat does not exist or has been closed").": $chat_id</font><BR/><BR/><font class='chat_title'><a href='".$chat_url."?group_id=$group_id&language=$language&available_agents=$available_agents'>"._QXZ("GO BACK TO CHAT FORM")."</a></font>\n";
} else {
$status_row=mysqli_fetch_row($status_rslt);
@@ -219,7 +223,7 @@ if ($action=="update_chat_window" && $chat_id) {
echo "<input type='hidden' id='current_message_count' name='current_message_count' value='$current_messages'>\n";
} else {
echo "<font class='chat_title bold'>"._QXZ("You have left chat").": $chat_id.</font><BR/><BR/><font class='chat_title'><a href='".$chat_url."?group_id=$group_id&language=$language'>"._QXZ("GO BACK TO CHAT FORM")."</a></font>\n";
echo "<font class='chat_title bold'>"._QXZ("You have left chat").": $chat_id.</font><BR/><BR/><font class='chat_title'><a href='".$chat_url."?group_id=$group_id&language=$language&available_agents=$available_agents'>"._QXZ("GO BACK TO CHAT FORM")."</a></font>\n";
}
} else {
if ($status_row[1]=="NONE") {
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

@@ -1,7 +1,7 @@
<?php
# vicidial_chat_customer_side.php
#
# Copyright (C) 2015 Joe Johnson, Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
# Copyright (C) 2016 Joe Johnson, Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
#
# The main page of the customer chat interface. This will display a form for the customer
# to fill out to attempt to initiate a chat with an available agent in the in-group
@@ -14,6 +14,7 @@
# 151217-1017 - Allow for pre-populating of group_id
# 151219-0850 - Added translation code
# 151220-0959 - Only search for phone number if greater than 4 digits
# 160108-1700 - Added available_agents, status_link button options and validation of active in-group
#
require("dbconnect_mysqli.php");
@@ -43,12 +44,18 @@ if (isset($_GET["language"])) {$language=$_GET["language"];}
elseif (isset($_POST["language"])) {$language=$_POST["language"];}
if (isset($_GET["stage"])) {$stage=$_GET["stage"];}
elseif (isset($_POST["stage"])) {$stage=$_POST["stage"];}
if (isset($_GET["available_agents"])) {$available_agents=$_GET["available_agents"];}
elseif (isset($_POST["available_agents"])) {$available_agents=$_POST["available_agents"];}
if (isset($_GET["status_link"])) {$status_link=$_GET["status_link"];}
elseif (isset($_POST["status_link"])) {$status_link=$_POST["status_link"];}
$PHP_SELF=$_SERVER["PHP_SELF"];
$lead_id = preg_replace("/[^0-9]/","",$lead_id);
$chat_id = preg_replace('/[^- \_\.0-9a-zA-Z]/','',$chat_id);
$group_id = preg_replace('/[^- \_0-9a-zA-Z]/','',$group_id);
$language = preg_replace('/[^-\_0-9a-zA-Z]/','',$language);
$available_agents = preg_replace('/[^-\_0-9a-zA-Z]/','',$available_agents);
$status_link = preg_replace('/[^-\_0-9a-zA-Z]/','',$status_link);
if ($non_latin < 1)
{
@@ -109,9 +116,92 @@ if (strlen($language) > 1)
if ($SSallow_chats < 1)
{
header ("Content-type: text/html; charset=utf-8");
echo _QXZ("Error, chat disabled on this system");
if ($status_link == 'Y')
{echo "<img src=\"./images/"._QXZ("chat_status_button_OFF.gif")."\" width=150 height=37 alt=\""._QXZ("no chat agents available")."\">";}
else
{echo _QXZ("Error, chat disabled on this system");}
exit;
}
if (strlen($group_id) > 1)
{
$group_active='N';
$group_name='';
$stmt = "SELECT active,group_name FROM vicidial_inbound_groups where group_id='$group_id';";
$rslt=mysql_to_mysqli($stmt, $link);
if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00XXX',$user,$server_ip,$session_name,$one_mysql_log);}
if ($DB) {echo "$stmt\n";}
$group_good_ct = mysqli_num_rows($rslt);
if ($group_good_ct > 0)
{
$row=mysqli_fetch_row($rslt);
$group_active = $row[0];
$group_name = $row[1];
}
if ($group_active == 'N')
{
header ("Content-type: text/html; charset=utf-8");
if ($status_link == 'Y')
{echo "<img src=\"./images/"._QXZ("chat_status_button_OFF.gif")."\" width=150 height=37 alt=\""._QXZ("no chat agents available")."\">";}
else
{echo _QXZ("Error, group is not active").": $group_id $group_name";}
exit;
}
if ($available_agents == 'WAITING_ONLY')
{
$waiting_agents=0;
$stmt = "SELECT count(*) FROM vicidial_live_agents where closer_campaigns LIKE \"% $group_id %\" and status IN('READY','CLOSER');";
$rslt=mysql_to_mysqli($stmt, $link);
if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00XXX',$user,$server_ip,$session_name,$one_mysql_log);}
if ($DB) {echo "$stmt\n";}
$group_good_ct = mysqli_num_rows($rslt);
if ($group_good_ct > 0)
{
$row=mysqli_fetch_row($rslt);
$waiting_agents = $row[0];
}
if ($waiting_agents < 1)
{
header ("Content-type: text/html; charset=utf-8");
if ($status_link == 'Y')
{echo "<img src=\"./images/"._QXZ("chat_status_button_OFF.gif")."\" width=150 height=37 alt=\""._QXZ("no chat agents available")."\">";}
else
{echo _QXZ("We are sorry, there are no waiting agents at this time. Please try again later.").": $group_id $group_name";}
exit;
}
}
if ($available_agents == 'LOGGED_IN')
{
$loggedin_agents=0;
$stmt = "SELECT count(*) FROM vicidial_live_agents where closer_campaigns LIKE \"% $group_id %\";";
$rslt=mysql_to_mysqli($stmt, $link);
if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00XXX',$user,$server_ip,$session_name,$one_mysql_log);}
if ($DB) {echo "$stmt\n";}
$group_good_ct = mysqli_num_rows($rslt);
if ($group_good_ct > 0)
{
$row=mysqli_fetch_row($rslt);
$loggedin_agents = $row[0];
}
if ($loggedin_agents < 1)
{
header ("Content-type: text/html; charset=utf-8");
if ($status_link == 'Y')
{echo "<img src=\"./images/"._QXZ("chat_status_button_OFF.gif")."\" width=150 height=37 alt=\""._QXZ("no chat agents available")."\">";}
else
{echo _QXZ("We are sorry, there are no logged in agents at this time. Please try again later.").": $group_id $group_name";}
exit;
}
}
if ($status_link == 'Y')
{
echo "<a href=\"".$PHP_SELF."?group_id=$group_id&language=$language&available_agents=$available_agents\"><img src=\"./images/"._QXZ("chat_status_button_ON.gif")."\" width=150 height=37 border=0 alt=\""._QXZ("Agents Available, click to chat now")."\"></a>";
exit;
}
}
# http://192.168.1.2/chat_customer/vicidial_chat_customer_side.php?user=1440723435.60926&lead_id=1079350&group_id=CHAT_TEST_GROUP&chat_id=254&email=joej%40test.com
@@ -276,6 +366,7 @@ echo '<?xml version="1.0" encoding="UTF-8"?>
<script language="Javascript">
var language='<?php echo $language ?>';
var group_id='<?php echo $group_id ?>';
var available_agents='<?php echo $available_agents ?>';
function PleaseWait() {
document.getElementById('chat_request_span').style.display="none";
@@ -307,7 +398,7 @@ function LeaveChat(chat_id, user, chat_member_name) {
}
if (xmlhttp)
{
chat_query = "&action=leave_chat&chat_id="+chat_id+"&group_id="+group_id+"&user="+user+"&chat_member_name="+chat_member_name+"&language="+language;
chat_query = "&action=leave_chat&chat_id="+chat_id+"&group_id="+group_id+"&user="+user+"&chat_member_name="+chat_member_name+"&language="+language+"&available_agents="+available_agents;
// alert(chat_query);
xmlhttp.open('POST', 'customer_chat_functions.php');
xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
@@ -342,7 +433,7 @@ function UpdateChatWindow() {
}
if (xmlhttp)
{
chat_query = "&chat_id="+chat_id+"&group_id="+group_id+"&user="+user+"&current_message_count="+current_message_count+"&language="+language+"&action=update_chat_window&keepalive=1";
chat_query = "&chat_id="+chat_id+"&group_id="+group_id+"&user="+user+"&current_message_count="+current_message_count+"&language="+language+"&available_agents="+available_agents+"&action=update_chat_window&keepalive=1";
xmlhttp.open('POST', 'customer_chat_functions.php');
xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
xmlhttp.send(chat_query);
@@ -379,7 +470,7 @@ function CustomerSendMessage(chat_id, user, message, chat_member_name) {
}
if (xmlhttp)
{
chat_query = "&chat_message="+chat_message+"&chat_id="+chat_id+"&group_id="+group_id+"&chat_member_name="+chat_member_name+"&user="+user+"&language="+language+"&chat_level=0&action=send_message";
chat_query = "&chat_message="+chat_message+"&chat_id="+chat_id+"&group_id="+group_id+"&chat_member_name="+chat_member_name+"&user="+user+"&language="+language+"&available_agents="+available_agents+"&chat_level=0&action=send_message";
xmlhttp.open('POST', 'customer_chat_functions.php');
xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
xmlhttp.send(chat_query);
@@ -412,6 +503,7 @@ $chat_title= _QXZ("Request chat with agent"); # This can be modified for customi
<form action="<?php echo $PHP_SELF; ?>" method="post">
<input type=hidden name=stage value="send_request">
<input type=hidden name=language value="<?php echo $language; ?>">
<input type=hidden name=available_agents value="<?php echo $available_agents; ?>">
<span id="chat_request_span">
<table width="500" border=0 cellpadding=1 cellspacing=1 height="300">
<tr>
@@ -503,6 +595,7 @@ $chat_title= _QXZ("Request chat with agent"); # This can be modified for customi
<input type="hidden" id="group_id" name="group_id" value="<?php echo $group_id; ?>">
<input type="hidden" id="lead_id" name="lead_id" value="<?php echo $lead_id; ?>">
<input type="hidden" id="language" name="language" value="<?php echo $language; ?>">
<input type="hidden" id="available_agents" name="available_agents" value="<?php echo $available_agents; ?>">
</form>
</body>
@@ -555,6 +648,7 @@ $chat_title= _QXZ("Request chat with agent"); # This can be modified for customi
<input type="hidden" id="lead_id" name="lead_id" value="<?php echo $lead_id; ?>">
<input type="hidden" id="group_id" name="group_id" value="<?php echo $group_id; ?>">
<input type="hidden" id="language" name="language" value="<?php echo $language; ?>">
<input type="hidden" id="available_agents" name="available_agents" value="<?php echo $available_agents; ?>">
<audio id='CustomerChatAudioAlertFile'><source src="sounds/chat_alert.mp3" type="audio/mpeg"></audio>
</form>
</body>