Dynamically Enable Visitor Side Chat

Introduction

The Chat initiated by the visitor (Reactive Chat) from the University portal page are routed to the agent based on the Team Service Time and the Agent availability/logged in CRM system. If either agent(s) or Team(s) are not available , then the visitor chat request is not serviced. Typically, the Visitor is serviced on Chat channel after he/she submits the questionnaire form. At times this can be frustrating if the Visitor is made aware, that he/she can’t be serviced due to non availability of Agent or Team , post filling the questionnaire form.

This post covers the know-how to build solution to dynamically enable or disable Reactive Chat or notify the Visitor based on the Agent/Team availability through JavaScript.

Solution

The request from the Visitor Chat is routed through the handler ,ChatActions.ashx, which is installed as part of Chat web component. This handler implements a method internally to determine whether the Visitor Chat request can be serviced or denied. The solution is to invoke this method and use to identify whether the Team(s)/Agent(s) are available to service the Visitor. To invoke this method in the handler, the action type –doCheck need to be passed as a part of query string & returns the Status, WaitTime & the position in the queue as string in the below format  {ReturnCode:{},WaitTime:{},Position:{}}

Using the value of ReturnCode, it can be determined whether the Chat can be serviced or not with reason.  The table below describes the possible value and its corresponding description

ReturnCode  Description
0 Success. The Chat request can be serviced for the Visitor
-1073690563 Failure. No Agents are available to service the Chat request from Visitor
-1073711694 Failure. No Team is available to service the Chat request from Visitor
-1073711703 Failure. User not available for routing due to chat request load. Here the WaitTime can be used to determine as to when the request can be serviced

The above can be implemented  in the sample page shipped along with the installable or it can be implemented in a different page which can then redirect to this sample page to initiate the chat. This post will walk through the solution for both the options. It’s left to the person implementing the solution to determine as to how it needs to be modelled based on the usability and ease of implementing it.

Option 1:

This option uses the existing sample page shipped along with the installable. The below screenshot is the sample page – ChatSamples.htm which is shipped along with the product.

ChatSamples

 

This sample page has reference to the script – TreatCode.js  & this script implements a function EstimateTime().  The data returned by this method will be used to determine whether Chat Service can be enabled or disabled. This method can’t be extended for determining the availability based on team. By default it checks only for the home team.

var data=EstimateTime();

var dataPattern = /(ReturnCode:-|ReturnCode:)[0-9]*/g;
var returnCodePattern = /((-)[0-9]*|0)/g;
var value = data.match(dataPattern)[0].match(returnCodePattern);

if (value == 0) {
//Enable the Chat

} else if (value == -1073690563) {
//Agent not available
//Hide the Chat

}else if (value == -1073711694) {
//Team not available to Service
//Hide the Chat
}else if (value == -1073711703) {
//User not available to route for Service
//Hide the Chat
}

 

 

Option 2:

In this option , we will not use the existing sample page but instead write a new page & assume this page contain the link/button to launch the Visitor Chat. The sample code below determines whether the Chat can be serviced to the Visitor . This script is hooked to document ready event and it executes when the page has loaded in the browser.  This script can be extended to check the Chat Service availability based on Team, by passing the Team Id to the query string parameter “TeamID“.  In this sample, its set to 0 to determine the availability of home team.

<script type=”text/javascript” src=”jquery-2.1.4.js”></script>
<script>
$(document).ready(function() {$.ajax({
url: “http://<Server where Media Web Component is installed>/Media/ChatActions/ChatAction.ashx”,
data: “doCheck=1&CurURL=” + top.window.location.href + “&CaseID=0&TeamID=<0>&MediaID=6&Email=&Auto=join&Name=”,
method: “POST”,
cache: false

}
).done(function(data) {
var dataPattern = /(ReturnCode:-|ReturnCode:)[0-9]*/g;
var returnCodePattern = /((-)[0-9]*|0)/g;
var value = data.match(dataPattern)[0].match(returnCodePattern);
if (value == 0) {
//Enable the Chat

} else if (value == -1073690563) {
//Agent not available
//Disable or hide the chat button/link
} else if (value == -1073711694) {
//Team not available to Service
//Disable or hide the chat button/link
}else if (value == -1073711703) {
//User not available to route for Service
//Hide the Chat
}

});

});

</script>

Conclusion

Apart from identifying whether the Visitor Chat request can be serviced or not , the solution can also be extended to estimate the wait time for servicing the Visitor Chat request.

Leave a Reply

Skip to toolbar