Differences

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

Link to this comparison view

Both sides previous revision Previous revision
inprogress [2019/09/01 20:28]
gerardorourke
inprogress [2019/09/04 22:24] (current)
gerardorourke
Line 2: Line 2:
  
 <​code>​ <​code>​
-<​%@language=JScript%>​+<​%@language = JScript %>
  
- <%+    ​<%
  
- /* +    ​/* 
- Author: Gerard O'​Rourke +    Author: Gerard O'​Rourke ​- Purplepi.ie 
- Date: 29 Auguest ​2019+    Date: 02 September ​2019 
 +    Version 1.0 
 +    /*
  
- To Do: Timeouts, Error handling when Site returns incorrect data or no data, put code into functions. +    /* 
- Test 200 OK but with wrong URL (incorrect response - not able to parse) +    MIT License
- Test with incorrect URL and non 200 OK response (404, 503 etc) +
- Test Timeout options+
  
- /*+    Copyright (c) 2019 Gerard O'​Rourke - purplepi.ie
  
- /* +    Permission is hereby granted, free of charge, to any person obtaining a copy 
- MIT License+    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:
  
- Copyright (c) 2019 Gerard O'​Rourke - purplepi.ie+    The above copyright notice and this permission notice shall be included in all 
 +    copies or substantial portions of the Software.
  
- Permission is hereby granted, free of charge, to any person obtaining a copy +    THE SOFTWARE IS PROVIDED ​"AS IS", ​WITHOUT WARRANTY OF ANY KINDEXPRESS OR 
- of this software and associated documentation files (the "Software")to deal +    ​IMPLIEDINCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
- in the Software without restrictionincluding without limitation the rights +    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
- to usecopymodifymergepublishdistributesublicenseand/or sell +    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIMDAMAGES OR OTHER 
- copies of the Software, and to permit persons to whom the Software is +    LIABILITYWHETHER IN AN ACTION OF CONTRACTTORT OR OTHERWISEARISING FROM
- furnished to do so, subject to the following conditions:+    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
 +    ​SOFTWARE. 
 +    */
  
- The above copyright notice and this permission notice shall be included in all +    /* 
- copies or substantial portions ​of the Software.+ 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 
 + */
  
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,​ 
- 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. 
- */ 
  
 +    try { //Start of Global Try
  
- try { //Start of Global Try+// ******************************************************************************************** // 
 +// ******************* You should review and change the BELOW variables ​ ********************** // 
 +// ******************************************************************************************** //
  
- // CCE & ECE Server Details +        ​// Variables ​CCE & ECE Server Details 
- var ccehostname = '​ucce-hds-a.lab2.purplepi.ie';​ +        var ccehostname = '​ucce-hds-a.lab2.purplepi.ie';​ 
- var ecehostname = '​ucce-ece-db-12.lab2.purplepi.ie';​ +        var ecehostname = '​ucce-ece-db-12.lab2.purplepi.ie';​ 
- var cceuser = '​chatapiuser@lab2.purplepi.ie';​ +        var cceuser = '​chatapiuser@lab2.purplepi.ie'; ​//create a PCCE User Administrator dedicated for this role. 
- var ccepass = '​myPa$$w0rd!';​+        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 = '​0';​ +        var defaultMaxQueueDepth = '​0';​ 
- var defaultMaxWaitTime = '​120';​ +        var defaultMaxWaitTime = '​120';​
- var debuglevel = 0; // 0 = off, 1 = minimum, 2 = all  +
-  +
- // Declare Global Variables used in both businessHours and ECE APIs +
- var myProactiveChatTimer +
- var myMaxQueueDepth +
- var myMaxWaitTime +
- var myMinAgentCount+
  
- // Query String - Retrieve dyanmic values for the Business Hours and ECE API IDs. +// ******************************************************************************************** // 
- var myQuerySring = Request.QueryString;​ +// ******************* You should review ​and change the ABOVE variables ​ ********************** // 
- var myChatEntryId = Request.QueryString("​chatEntryId"​);​ +// ******************************************************************************************** //
- var myBusinessHoursId= Request.QueryString("​businessHoursId"​);​+
  
- // 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;​ 
  
- // Initial JS variable values 
- var chatStatus = '​closed';​ //Defaults value until overwritten 
- var chatStatusReason = 'out of service';​ //Defaults value until overwritten 
- var chatTimer = '​0';​ //Defaults value until overwritten 
  
- Response.ContentType="​application/javascript"; ​// Set Content Type+        ​// Declare Global Variables used in both businessHours and ECE APIs 
 +        var myProactiveChatTimer 
 +        var myMaxQueueDepth 
 +        var myMaxWaitTime 
 +        var myMinAgentCount
  
- if (debuglevel > 0){ +        // Query String - Retrieve dyanmic values for the Business Hours and ECE API IDs. 
- Response.Write("​\nconsole.log('​chatStatus ​QueryString: " + Request.QueryString ​"');"); +        var myQuerySring = Request.QueryString
- }+        var myChatEntryId = Request.QueryString("​chatEntryId"); 
 +        var myBusinessHoursId = Request.QueryString("​businessHoursId");
  
- chatstatus ​businessHoursAPI() ​// BusinessHours API - returns ​'open' ​or 'closed'+        // 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;​
  
- if (chatstatus == '​open'​){ +        ​// Initial JS variable values 
- chatstatus = liveSessionStatusAPI() ​// ECE  liveSessionStatus API  -  returns '​open'​ or '​busy'​ or if unable to read - '​closed' ​with chatStatusReason 'out of service'​ +        var chatStatus = '​closed'​; //Defaults value until overwritten 
- }+        var chatStatusReason ​'out of service'​; //Defaults value until overwritten 
 +        var chatTimer = '​0';​ //Defaults value until overwritten
  
- if (chatstatus == '​open'​ && myMinAgentCount > 0){ +        ​Response.ContentType ​= "application/​javascript"; ​// Set Content Type
- chatstatus = capacityAPI() //​ ECE  Capacity API  - returns '​open'​ or '​busy'​ or if unable to read - '​closed'​ with chatStatusReason 'out of service'​ +
-+
-  +
- Response.Write("​\nvar chatStatus ​'" ​+ chatStatus + "';"); +
- Response.Write("​\nvar chatStatusReason = '"​ + chatStatusReason + "';"​);​ +
- Response.Write("​\nvar chatTimer = '"​ + chatTimer + "';"​);​  +
- +
  
- function businessHoursAPI(){ +        if (debuglevel > 0) { 
- try { +            ​Response.Write("\nconsole.log('​chatStatus QueryString:​ " + Request.QueryString + "');"​);​ 
- var srvXmlHttp +        }
- srvXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP.3.0"); +
- srvXmlHttp.setOption(2,​13056); ​ //Ignore SSL Certs +
- srvXmlHttp.open ("GET", businessHoursUrl,​ false, cceuser, ccepass); +
- srvXmlHttp.send();​+
  
- var httpstatus ​srvXmlHttp.status;​ +        chatstatus ​businessHoursAPI() // BusinessHours ​API - returns ​'open' or '​closed'​
-  +
- if (debuglevel > 0)+
- Response.Write("​\nconsole.log('​chatStatus CCE API HTTP Status: " + httpstatus + "')"); +
-+
-  +
- if (httpstatus != 200){ +
- chatStatus = '​closed'​+
- chatStatusReason = 'out of service';​ +
- 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 +        if (chatstatus ​== '​open'​) { 
- var businessHoursNameArray = businessHoursName.text.split("​_"​);​ +            ​chatstatus ​liveSessionStatusAPI() // ECE  liveSessionStatus API  -  returns '​open'​ or '​busy'​ or if unable to read - '​closed'​ with chatStatusReason 'out of service'​ 
- var myBusinessHoursName ​businessHoursNameArray[0];​ +        }
- myProactiveChatTimer ​businessHoursNameArray[1];​ +
- myMinAgentCount ​businessHoursNameArray[2];​ +
- myMaxQueueDepth = businessHoursNameArray[3];​ +
- myMaxWaitTime = businessHoursNameArray[4];​+
  
- // Check if Valid Values from BusinessHour - if not - overwrite with the default values. +        ​if (chatstatus ​== '​open'​ && ​myMinAgentCount ​> 0) { 
- if (isNaN(myProactiveChatTimer)){ +            ​chatstatus ​capacityAPI() // ECE  Capacity API  - returns '​open'​ or '​busy'​ or if unable to read - '​closed'​ with chatStatusReason 'out of service'​ 
- 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) { +        Response.Write("​\nvar chatStatus ​'"​ + chatStatus + "';"​); 
- chatStatusReason = reasonText.text+        ​Response.Write("​\nvar ​chatStatusReason = '"​ + chatStatusReason + "';"​)
- }+        ​Response.Write("​\nvar chatTimer = '"​ + myProactiveChatTimer + "';"​);​
  
- if (runTimeStatus.text == 1 || runTimeStatus.text == 3){ + Response.Write("​\nconsole.log('​chatStatus chatStatus: " + chatStatus + "'​);"); 
- chatStatus ​= 'open'; + Response.Write("​\nconsole.log('​chatStatus ​chatStatusReason:​ " + chatStatusReason + "');")
- }+ Response.Write("​\nconsole.log('​chatStatus chatTimer: " + myProactiveChatTimer + "'​);"​);​
  
- 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';​ 
  
- if (debuglevel > 0){ +// ******************************************************************************************** // 
- Response.Write("​\nconsole.log('​chatStatus Error BusinessHours API'​)"​);​ +// ******************************** Functions ************************************************* // 
- }+// ******************************************************************************************** //
  
- return chatStatus; +        function businessHoursAPI() { 
-  +            try { 
- } //Catch +                var srvXmlHttp 
- //Function+                ​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;​
  
- function liveSessionStatusAPI(){ +                ​if (debuglevel > 0) { 
- try { +                    Response.Write("​\nconsole.log('​chatStatus ​CCE API HTTP Status: " + httpstatus + "'​)"​);​ 
- var srvXmlHttp +                }
- srvXmlHttp = Server.CreateObject("​Msxml2.ServerXMLHTTP.3.0"​);​ +
- srvXmlHttp.setOption(2,​13056); ​ //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';​ +
- 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';​ +
-+
-  +
- if (parseInt(waitTime.text,​10) > myMaxWaitTime){ +
- chatStatus = '​busy';​ +
- chatStatusReason = '​MaxWaitTime';​ +
- } +
  
- if (debuglevel > 1){ +                ​if (httpstatus != 200) { 
- Response.Write("​\nconsole.log('​chatStatus ​waitTime: " + waitTime.text + "')")+                    chatStatus ​= '​closed'; 
- Response.Write("​\nconsole.log('​chatStatus ​queueDepth: " + queueDepth.text + "'​)"​)+                    ​chatStatusReason = 'out of service';​ 
- }+ myProactiveChatTimer = '​0';​ 
 +                    return ​chatStatus;​ 
 +                }
  
- return chatStatus; +                chatStatusReason = ''​; //Clear 'out of service'​ value
-//Try+
  
- catch(err{ +                var businessHours = srvXmlHttp.responseXML;​ 
- chatStatus ​'​closed'​+                var businessHoursName = businessHours.selectSingleNode("//​businessHour/​name"​); 
- chatStatusReason ​'out of service'​+                var runTimeStatus ​businessHours.selectSingleNode("//​businessHour/​runTimeStatus"​)
- if (debuglevel ​> 0){ +                var configuredStatus ​businessHours.selectSingleNode("//​businessHour/​configuredStatus/​status"​)
- Response.Write("\nconsole.log('​chatStatus Error Live Session API'​)"​);​ +                if (configuredStatus.text ​> 0) { 
-+                    var reasonText = businessHours.selectSingleNode("//businessHour/configuredStatus/statusReason/​reasonText"​);​ 
- return chatStatus;​ +                }
-//Catch +
-//Function +
- +
  
 +                //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];​
  
- function capacityAPI(){ +                myProactiveChatTimer ​myProactiveChatTimer*1000; //Convert ChatTimer from seconds to milliseconds
- try { +
-  +
- srvXmlHttp ​Server.CreateObject("​Msxml2.ServerXMLHTTP.3.0"​); +
- srvXmlHttp.setOption(2,​13056);  ​//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,​10myMinAgentCount){ +                // Check if Valid Values from BusinessHour - if not - overwrite with the default values. 
- chatStatus ​'​busy'​+                ​if (isNaN(myProactiveChatTimer)) { 
- chatStatusReason ​'​myMinAgentCount'​+                    myProactiveChatTimer = defaultProactiveChatTimer;​ 
- } +                } 
 +                if (isNaN(myMinAgentCount)) { 
 +                    ​myMinAgentCount ​defaultMinAgentCount
 +                } 
 +                if (isNaN(myMaxQueueDepth)) { 
 +                    myMaxQueueDepth ​defaultMaxQueueDepth;​ 
 +                } 
 +                if (isNaN(myMaxWaitTime)) { 
 +                    myMaxWaitTime = defaultMaxWaitTime
 +                }
  
- if (debuglevel > 1){ +                ​if ((runTimeStatus.text == 0 || runTimeStatus.text == 2&& configuredStatus.text > 0
- Response.Write("​\nconsole.log('​chatStatus agentCount: " + count.text + "'​)"); +                    chatStatusReason = reasonText.text
- }+                }
  
- return chatStatus;​ +                if (runTimeStatus.text == 1 || runTimeStatus.text == 3) { 
- } // Try +                    chatStatus = '​open';​ 
-  +                } 
- catch(err) { + 
- chatStatus = '​closed';​ +                if (debuglevel > 1) { 
- chatStatusReason = 'out of service';​ +                    Response.Write("​\nconsole.log('​chatStatus BusinessHoursName:​ " + businessHoursName.text + "'​)"​);​ 
- if (debuglevel > 0){ +                    if (configuredStatus.text > 0) { 
- Response.Write("​\nconsole.log('​chatStatus Error Capacity API'​)"​);​ +                        Response.Write("​\nconsole.log('​chatStatus reasonText: " + reasonText.text + "'​)"​);​ 
- +                    } 
- return chatStatus;​ +                    Response.Write("​\nconsole.log('​chatStatus myBusinessHoursName:​ " + myBusinessHoursName + "'​)"​);​ 
-  +                    Response.Write("​\nconsole.log('​chatStatus myProactiveChatTimer:​ " + myProactiveChatTimer + "'​)"​);​ 
- } //Catch +                    Response.Write("​\nconsole.log('​chatStatus myMinAgentCount:​ " + myMinAgentCount + "'​)"​);​ 
- } //​Function  +                    Response.Write("​\nconsole.log('​chatStatus myMaxQueueDepth:​ " + myMaxQueueDepth + "'​)"​);​ 
- } //End of Global Try +                    Response.Write("​\nconsole.log('​chatStatus myMaxWaitTime:​ " + myMaxWaitTime + "'​)"​);​ 
-  +                    Response.Write("​\nconsole.log('​chatStatus runTimeStatus:​ " + runTimeStatus.text + "'​)"​);​ 
- catch(err) { +                } 
- chatStatus = '​closed';​ + 
- chatStatusReason = 'out of service';​ +                ​return chatStatus;​ 
- chatTimer=0;​ +            } //Try 
-  + catch (err) { 
- Response.Write("​\nvar chatStatus = '"​ + chatStatus + "';"​);​ +                ​chatStatus = '​closed';​ 
- Response.Write("​\nvar chatStatusReason = '"​ + chatStatusReason + "';"​);​ +                chatStatusReason = 'out of service';​ 
- Response.Write("​\nvar chatTimer = '"​ + chatTimer + "';"​);​  + myProactiveChatTimer = '​0';​ 
-  + 
- Response.Write("​\nconsole.log('​chatStatus Global Error'​)"​);​ +                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>​ </​code>​