Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
inprogress [2019/08/29 13:42] – gerardorourkeinprogress [2019/09/04 22:24] (current) – gerardorourke
Line 1: Line 1:
 ===== In progress ===== ===== In progress =====
- 
-Reference:  
-https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ms763809(v%3Dvs.85) 
  
 <code> <code>
-<%@language=JScript%>+<%@language = JScript %>
  
-<%+    <%
  
-/* +    /* 
-MIT License+    Author: Gerard O'Rourke - Purplepi.ie 
 +    Date: 02 September 2019 
 +    Version 1.0 
 +    /*
  
-Copyright (c) 2019 Gerard O'Rourke - purplepi.ie+    /* 
 +    MIT License
  
-Permission is hereby granted, free of charge, to any person obtaining a copy +    Copyright (c) 2019 Gerard O'Rourke - purplepi.ie
-of this software and associated documentation files (the "Software"), to deal +
-in the Software without restriction, including without limitation the rights +
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +
-copies of the Software, and to permit persons to whom the Software is +
-furnished to do so, subject to the following conditions:+
  
-The above copyright notice and this permission notice shall be included in all +    Permission is hereby granted, free of charge, to any person obtaining a copy 
-copies or substantial portions of the Software.+    of this software and associated documentation files (the "Software"), to deal 
 +    in the Software without restriction, including without limitation the rights 
 +    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
 +    copies of the Software, and to permit persons to whom the Software is 
 +    furnished to do so, subject to the following conditions:
  
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +    The above copyright notice and this permission notice shall be included in all 
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +    copies or substantial portions of the Software.
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +
-SOFTWARE. +
-*/+
  
-// Query String - Retrieve dyanmic values for the Business Hours and ECE API IDs. +    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
-var myQuerySring = Request.QueryString; +    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
-var myChatEntryId = Request.QueryString("chatEntryId"); +    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
-var myBusinessHoursId= Request.QueryString("businessHoursId");+    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
 +    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 +    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
 +    SOFTWARE. 
 +    */
  
-//var myChatEntryId = getUrlVars()["chatEntryId"]; +    /* 
-//Response.Write("\nconsole.log('myChatEntryId: " + myChatEntryId + "')");+ Location of File:  
 + Example: D:\ECE\eService\templates\chat\businessHours\ 
 + Example URL: http://ucce-ece-db-12.lab2.purplepi.ie/system/templates/chat/businessHours/chatStatus.asp?businessHoursId=5001&chatEntryId=1001 
 + */
  
  
-var businessHoursUrl = "http://localhost/xmlfiles/businessHours.xml" +    try { //Start of Global Try
-var liveSessionStatusUrl = "http://localhost/xmlfiles/liveSessionStatus.xml" +
-var capacityUrl = "http://localhost/xmlfiles/capacity.xml"+
  
 +// ******************************************************************************************** //
 +// ******************* You should review and change the BELOW variables  ********************** //
 +// ******************************************************************************************** //
  
 +        // Variables CCE & ECE Server Details
 +        var ccehostname = 'ucce-hds-a.lab2.purplepi.ie';
 +        var ecehostname = 'ucce-ece-db-12.lab2.purplepi.ie';
 +        var cceuser = '[email protected]'; //create a PCCE User Administrator dedicated for this role.
 +        var ccepass = 'myPa$$w0rd!';
 +        var debuglevel = 1; // 0 = disabled, 1 = minimum, 2 = all - recommend to set to 1
 +        var SXH_OPTION_2_VALUE = 13056; // SXH_OPTION_IGNORE_SERVER_SSL_CERT_ERROR_FLAGS -> 'SXH_OPTION_2_VALUE = 13056;' to ignore all SSL errors
 +        var resolveTimeout = 3000; // DNS Resolve Timeout (ms)
 +        var connectTimeout = 3000; // Value (ms) is applied to establishing a communication socket with the target server
 +        var sendTimeout = 3000; // The value applies to sending an individual packet of request data (if any) on the communication socket to the target server. (ms)
 +        var receiveTimeout = 3000; // The value applies to receiving a packet of response data from the target server (ms)
  
-// Default Values if unable to read valid values from BusinessHours Name +        // Default Values if unable to read valid values from BusinessHours Name 
-var defaultProactiveChatTimer = '0'; +        var defaultProactiveChatTimer = '0'; // value here is set in ms, e.g. for a 10 second Proactive Chat, enter '10000' 
-var defaultMinAgentCount = '0'; +        var defaultMinAgentCount = '0'; 
-var defaultMaxQueueDepth = '10'; +        var defaultMaxQueueDepth = '0'; 
-var defaultMaxWaitTime = '120';+        var defaultMaxWaitTime = '120';
  
-//Retrieve BusinessHours Details from CCE BusinessHours API +// ******************************************************************************************** // 
-var srvXmlHttp +// ******************* You should review and change the ABOVE variables  ********************** // 
-srvXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP.3.0"); +// ******************************************************************************************** //
-srvXmlHttp.open ("GET", businessHoursUrl, false); +
-srvXmlHttp.send();+
  
-var businessHours = srvXmlHttp.responseXML; 
-var businessHoursName = businessHours.selectSingleNode("//department/name"); 
-var runTimeStatus = businessHours.selectSingleNode("//runTimeStatus"); 
  
-var businessHoursNameArray = businessHoursName.text.split("_"); 
-var myBusinessHoursName = businessHoursNameArray[0]; 
-var myProactiveChatTimer = businessHoursNameArray[1]; 
-var myMinAgentCount = businessHoursNameArray[2]; 
-var myMaxQueueDepth = businessHoursNameArray[3]; 
-var myMaxWaitTime = businessHoursNameArray[4]; 
  
-// Check if Valid Values from BusinessHour - if not - overwrite with the default values. +        // Declare Global Variables used in both businessHours and ECE APIs 
-if (isNaN(myProactiveChatTimer)){ +        var myProactiveChatTimer 
- myProactiveChatTimer = defaultProactiveChatTimer; +        var myMaxQueueDepth 
-}  +        var myMaxWaitTime 
-if (isNaN(myMinAgentCount)){ +        var myMinAgentCount
- myMinAgentCount = defaultMinAgentCount; +
-}  +
-if (isNaN(myMaxQueueDepth)){ +
- myMaxQueueDepth = defaultMaxQueueDepth; +
-}  +
-if (isNaN(myMaxWaitTime)){ +
- myMaxWaitTime = defaultMaxWaitTime; +
-} +
  
-var chatStatus = 'closed'; +        // Query String - Retrieve dyanmic values for the Business Hours and ECE API IDs. 
-var chatBusyReason = 'unknown'; +        var myQuerySring = Request.QueryString; 
-var chatTimer = '0';+        var myChatEntryId = Request.QueryString("chatEntryId"); 
 +        var myBusinessHoursId = Request.QueryString("businessHoursId");
  
-if (runTimeStatus.text == 1 || runTimeStatus.text == 3){chatStatus = 'open';}+        // CCE & ECE URLs 
 +        var businessHoursUrl = 'https://' + ccehostname + '/unifiedconfig/config/businesshour/' + myBusinessHoursId; 
 +        var liveSessionStatusUrl = 'http://' + ecehostname + '/system/egain/chat/entrypoint/liveSessionStatus/' + myChatEntryId; 
 +        var capacityUrl = 'http://' + ecehostname + '/system/egain/chat/entrypoint/capacity/' + myChatEntryId;
  
-srvXmlHttp.open ("GET", liveSessionStatusUrl, false); +        // Initial JS variable values 
-srvXmlHttp.send(); +        var chatStatus = 'closed'; //Defaults value until overwritten 
-var liveSessionStatus = srvXmlHttp.responseXML; +        var chatStatusReason = 'out of service'; //Defaults value until overwritten 
-var waitTime = liveSessionStatus.selectSingleNode("//ns2:waitTime"); +        var chatTimer = '0'; //Defaults value until overwritten
-var queueDepth = liveSessionStatus.selectSingleNode("//ns2:queueDepth");+
  
-srvXmlHttp.open ("GET", capacityUrl, false); +        Response.ContentType = "application/javascript"; // Set Content Type
-srvXmlHttp.send(); +
-var capacity = srvXmlHttp.responseXML; +
-var count = capacity.selectSingleNode("//ns2:count");+
  
 +        if (debuglevel > 0) {
 +            Response.Write("\nconsole.log('chatStatus QueryString: " + Request.QueryString + "');");
 +        }
  
-Response.ContentType="application/javascript"; +        chatstatus = businessHoursAPI() // BusinessHours API - returns 'open' or 'closed'
-Response.Write("var chatStatus = '" + chatStatus + "';\n"); +
-Response.Write("var chatBusyReason = '" + chatBusyReason + "';\n"); +
-Response.Write("var chatTimer = '" + chatTimer + "';\n");+
  
-Response.Write("\nconsole.log('------- Cisco CCE Custom chatStatus Console Output - Start ------')"); +        if (chatstatus == 'open') { 
-Response.Write("\nconsole.log(" + Request.QueryString + ");"); +            chatstatus = liveSessionStatusAPI() // ECE  liveSessionStatus API  -  returns 'open' or 'busy' or if unable to read - 'closed' with chatStatusReason 'out of service' 
-Response.Write("\nconsole.log(" + myChatEntryId + ");"); +        }
-Response.Write("\nconsole.log(" + myBusinessHoursId + ");");+
  
 +        if (chatstatus == 'open' && myMinAgentCount > 0) {
 +            chatstatus = capacityAPI() // ECE  Capacity API  - returns 'open' or 'busy' or if unable to read - 'closed' with chatStatusReason 'out of service'
 +        }
  
-Response.Write("\nconsole.log('Full BusinessHoursName: " + businessHoursName.text + "')"); +        Response.Write("\nvar chatStatus = '" + chatStatus + "';"); 
-Response.Write("\nconsole.log('myBusinessHoursName: " + myBusinessHoursName + "')"); +        Response.Write("\nvar chatStatusReason = '" + chatStatusReason + "';"); 
-Response.Write("\nconsole.log('myProactiveChatTimer: " + myProactiveChatTimer + "')"); +        Response.Write("\nvar chatTimer = '" + myProactiveChatTimer + "';");
-Response.Write("\nconsole.log('myMinAgentCount: " + myMinAgentCount + "')"); +
-Response.Write("\nconsole.log('myMaxQueueDepth: " + myMaxQueueDepth + "')"); +
-Response.Write("\nconsole.log('myMaxWaitTime: " + myMaxWaitTime + "')"); +
-Response.Write("\nconsole.log('runTimeStatus: " + runTimeStatus.text + "')"); +
-Response.Write("\nconsole.log('waitTime: " + waitTime.text + "')"); +
-Response.Write("\nconsole.log('queueDepth: " + queueDepth.text + "')"); +
-Response.Write("\nconsole.log('agentCount: " + count.text + "')"); +
-Response.Write("\nconsole.log('------- Cisco CCE Custom chatStatus Console Output - End ------')"); +
-%>+
  
-</code>+ Response.Write("\nconsole.log('chatStatus chatStatus: " + chatStatus + "');"); 
 + Response.Write("\nconsole.log('chatStatus chatStatusReason: " + chatStatusReason + "');"); 
 + Response.Write("\nconsole.log('chatStatus chatTimer: " + myProactiveChatTimer + "');");
  
 +
 +// ******************************************************************************************** //
 +// ******************************** Functions ************************************************* //
 +// ******************************************************************************************** //
 +
 +        function businessHoursAPI() {
 +            try {
 +                var srvXmlHttp
 +                srvXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP.3.0");
 +                srvXmlHttp.setOption(2, SXH_OPTION_2_VALUE); //Ignore SSL Certs
 +                srvXmlHttp.setTimeouts(resolveTimeout, connectTimeout, sendTimeout, receiveTimeout);
 +                srvXmlHttp.open("GET", businessHoursUrl, false, cceuser, ccepass);
 +                srvXmlHttp.send();
 +
 +                var httpstatus = srvXmlHttp.status;
 +
 +                if (debuglevel > 0) {
 +                    Response.Write("\nconsole.log('chatStatus CCE API HTTP Status: " + httpstatus + "')");
 +                }
 +
 +                if (httpstatus != 200) {
 +                    chatStatus = 'closed';
 +                    chatStatusReason = 'out of service';
 + myProactiveChatTimer = '0';
 +                    return chatStatus;
 +                }
 +
 +                chatStatusReason = ''; //Clear 'out of service' value
 +
 +                var businessHours = srvXmlHttp.responseXML;
 +                var businessHoursName = businessHours.selectSingleNode("//businessHour/name");
 +                var runTimeStatus = businessHours.selectSingleNode("//businessHour/runTimeStatus");
 +                var configuredStatus = businessHours.selectSingleNode("//businessHour/configuredStatus/status");
 +                if (configuredStatus.text > 0) {
 +                    var reasonText = businessHours.selectSingleNode("//businessHour/configuredStatus/statusReason/reasonText");
 +                }
 +
 +                //Parse Business Hours Name to retrieve the Proactive Chat Timer, Min Agent Count, Max Queue Depth & Max Wait Timeouts
 +                var businessHoursNameArray = businessHoursName.text.split("_");
 +                var myBusinessHoursName = businessHoursNameArray[0];
 +                myProactiveChatTimer = businessHoursNameArray[1];
 +                myMinAgentCount = businessHoursNameArray[2];
 +                myMaxQueueDepth = businessHoursNameArray[3];
 +                myMaxWaitTime = businessHoursNameArray[4];
 +
 +                myProactiveChatTimer = myProactiveChatTimer*1000; //Convert ChatTimer from seconds to milliseconds
 +
 +                // Check if Valid Values from BusinessHour - if not - overwrite with the default values.
 +                if (isNaN(myProactiveChatTimer)) {
 +                    myProactiveChatTimer = defaultProactiveChatTimer;
 +                }
 +                if (isNaN(myMinAgentCount)) {
 +                    myMinAgentCount = defaultMinAgentCount;
 +                }
 +                if (isNaN(myMaxQueueDepth)) {
 +                    myMaxQueueDepth = defaultMaxQueueDepth;
 +                }
 +                if (isNaN(myMaxWaitTime)) {
 +                    myMaxWaitTime = defaultMaxWaitTime;
 +                }
 +
 +                if ((runTimeStatus.text == 0 || runTimeStatus.text == 2) && configuredStatus.text > 0) {
 +                    chatStatusReason = reasonText.text;
 +                }
 +
 +                if (runTimeStatus.text == 1 || runTimeStatus.text == 3) {
 +                    chatStatus = 'open';
 +                }
 +
 +                if (debuglevel > 1) {
 +                    Response.Write("\nconsole.log('chatStatus BusinessHoursName: " + businessHoursName.text + "')");
 +                    if (configuredStatus.text > 0) {
 +                        Response.Write("\nconsole.log('chatStatus reasonText: " + reasonText.text + "')");
 +                    }
 +                    Response.Write("\nconsole.log('chatStatus myBusinessHoursName: " + myBusinessHoursName + "')");
 +                    Response.Write("\nconsole.log('chatStatus myProactiveChatTimer: " + myProactiveChatTimer + "')");
 +                    Response.Write("\nconsole.log('chatStatus myMinAgentCount: " + myMinAgentCount + "')");
 +                    Response.Write("\nconsole.log('chatStatus myMaxQueueDepth: " + myMaxQueueDepth + "')");
 +                    Response.Write("\nconsole.log('chatStatus myMaxWaitTime: " + myMaxWaitTime + "')");
 +                    Response.Write("\nconsole.log('chatStatus runTimeStatus: " + runTimeStatus.text + "')");
 +                }
 +
 +                return chatStatus;
 +            } //Try
 + catch (err) {
 +                chatStatus = 'closed';
 +                chatStatusReason = 'out of service';
 + myProactiveChatTimer = '0';
 +
 +                if (debuglevel > 0) {
 +                    Response.Write("\nconsole.log('chatStatus Error BusinessHours API')");
 +                }
 +                return chatStatus;
 +            } //Catch
 +        } //Function
 +
 +
 +        function liveSessionStatusAPI() {
 +            try {
 +                var srvXmlHttp
 +                srvXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP.3.0");
 +                srvXmlHttp.setOption(2, SXH_OPTION_2_VALUE); //Ignore SSL Certs
 +                srvXmlHttp.open("GET", liveSessionStatusUrl, false);
 +                srvXmlHttp.send();
 +
 +                var httpstatus = srvXmlHttp.status;
 +
 +                if (debuglevel > 0) {
 +                    Response.Write("\nconsole.log('chatStatus ECE LiveSession API HTTP Status: " + httpstatus + "')");
 +                }
 +
 +                if (httpstatus != 200) {
 +                    chatStatus = 'closed';
 +                    chatStatusReason = 'out of service';
 + myProactiveChatTimer = '0';
 +                    return chatStatus;
 +                }
 +
 +                var liveSessionStatus = srvXmlHttp.responseXML;
 +                var waitTime = liveSessionStatus.selectSingleNode("//ns2:waitTime");
 +                var queueDepth = liveSessionStatus.selectSingleNode("//ns2:queueDepth");
 +
 +                if (parseInt(queueDepth.text, 10) > myMaxQueueDepth) {
 +                    chatStatus = 'busy';
 +                    chatStatusReason = 'MaxQueueDepth';
 + myProactiveChatTimer = '0';
 +                }
 +
 +                if (parseInt(waitTime.text, 10) > myMaxWaitTime) {
 +                    chatStatus = 'busy';
 +                    chatStatusReason = 'MaxWaitTime';
 + myProactiveChatTimer = '0';
 +                }
 +
 +                if (debuglevel > 1) {
 +                    Response.Write("\nconsole.log('chatStatus waitTime: " + waitTime.text + "')");
 +                    Response.Write("\nconsole.log('chatStatus queueDepth: " + queueDepth.text + "')");
 +                }
 +
 +                return chatStatus;
 +            } //Try
 +            catch (err) {
 +                chatStatus = 'closed';
 +                chatStatusReason = 'out of service';
 + myProactiveChatTimer = '0';
 +
 +                if (debuglevel > 0) {
 +                    Response.Write("\nconsole.log('chatStatus Error Live Session API')");
 +                }
 +                return chatStatus;
 +            } //Catch
 +        } //Function
 +
 +
 +
 +        function capacityAPI() {
 +            try {
 +
 +                srvXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP.3.0");
 +                srvXmlHttp.setOption(2, SXH_OPTION_2_VALUE); //Ignore SSL Certs
 +                srvXmlHttp.open("GET", capacityUrl, false);
 +                srvXmlHttp.send();
 +
 +                var httpstatus = srvXmlHttp.status;
 +
 +                if (debuglevel > 0) {
 +                    Response.Write("\nconsole.log('chatStatus ECE Capacity API HTTP Status: " + httpstatus + "')");
 +                }
 +
 +                if (httpstatus != 200) {
 +                    chatStatus = 'closed';
 +                    chatStatusReason = 'out of service';
 +                    return chatStatus;
 +                }
 +
 +                var capacity = srvXmlHttp.responseXML;
 +                var count = capacity.selectSingleNode("//ns2:count");
 +
 +                if (parseInt(count.text, 10) < myMinAgentCount) {
 +                    chatStatus = 'busy';
 +                    chatStatusReason = 'myMinAgentCount';
 + myProactiveChatTimer = '0';
 +                }
 +
 +                if (debuglevel > 1) {
 +                    Response.Write("\nconsole.log('chatStatus agentCount: " + count.text + "')");
 +                }
 +
 +                return chatStatus;
 +            } // Try
 +            catch (err) {
 +                chatStatus = 'closed';
 +                chatStatusReason = 'out of service';
 + chatTimer = '0';
 +              if (debuglevel > 0) {
 +                    Response.Write("\nconsole.log('chatStatus Error Capacity API')");
 +                }
 +                return chatStatus;
 +
 +            } //Catch
 +        } //Function
 +    } //End of Global Try
 +
 +catch (err) {
 +    chatStatus = 'closed';
 +    chatStatusReason = 'out of service';
 +    chatTimer = '0';
 +
 +    Response.Write("\nvar chatStatus = '" + chatStatus + "';");
 +    Response.Write("\nvar chatStatusReason = '" + chatStatusReason + "';");
 +    Response.Write("\nvar chatTimer = '" + chatTimer + "';");
 +    Response.Write("\nconsole.log('chatStatus Global Error')");
 +}
 +
 +%>
 +</code>
  • inprogress.1567082566.txt.gz
  • Last modified: 2019/08/29 13:42
  • by gerardorourke