Differences
This shows you the differences between two versions of the page.
| 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: | ||
| < | < | ||
| - | < | + | < |
| - | <% | + | |
| - | /* | + | |
| - | Author: Gerard O' | + | Author: Gerard O' |
| - | Date: 29 Auguest | + | Date: 02 September |
| + | 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' |
| - | /* | + | Permission is hereby granted, free of charge, to any person obtaining a copy |
| - | MIT License | + | of this software and associated documentation files (the " |
| + | in the Software without restriction, | ||
| + | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| + | copies of the Software, and to permit persons to whom the Software is | ||
| + | | ||
| - | Copyright (c) 2019 Gerard O' | + | 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 |
| - | of this software and associated documentation files (the "Software"), to deal | + | |
| - | in the Software without restriction, including without limitation the rights | + | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| - | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | + | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| - | copies of the Software, and to permit persons to whom the Software is | + | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 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 |
| + | | ||
| + | */ | ||
| - | The above copyright notice and this permission notice shall be included in all | + | /* |
| - | copies or substantial portions | + | Location |
| + | Example: D: | ||
| + | Example URL: http:// | ||
| + | */ | ||
| - | 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, | ||
| - | 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 | + | |
| - | var ccehostname = ' | + | var ccehostname = ' |
| - | var ecehostname = ' | + | var ecehostname = ' |
| - | var cceuser = ' | + | var cceuser = ' |
| - | var ccepass = ' | + | var ccepass = ' |
| + | 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 -> ' | ||
| + | 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 | + | |
| - | var defaultProactiveChatTimer = ' | + | var defaultProactiveChatTimer = ' |
| - | var defaultMinAgentCount = ' | + | var defaultMinAgentCount = ' |
| - | var defaultMaxQueueDepth = ' | + | var defaultMaxQueueDepth = ' |
| - | var defaultMaxWaitTime = ' | + | var defaultMaxWaitTime = ' |
| - | 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 |
| - | var myChatEntryId = Request.QueryString(" | + | // ******************************************************************************************** // |
| - | var myBusinessHoursId= Request.QueryString(" | + | |
| - | // CCE & ECE URLs | ||
| - | var businessHoursUrl = ' | ||
| - | var liveSessionStatusUrl = ' | ||
| - | var capacityUrl = ' | ||
| - | // Initial JS variable values | ||
| - | var chatStatus = ' | ||
| - | var chatStatusReason = 'out of service'; | ||
| - | var chatTimer = ' | ||
| - | Response.ContentType=" | + | |
| + | 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(" | + | var myQuerySring = Request.QueryString; |
| - | } | + | var myChatEntryId = Request.QueryString(" |
| + | var myBusinessHoursId = Request.QueryString(" | ||
| - | chatstatus | + | // CCE & ECE URLs |
| + | var businessHoursUrl | ||
| + | var liveSessionStatusUrl = ' | ||
| + | var capacityUrl = ' | ||
| - | if (chatstatus == ' | + | |
| - | chatstatus = liveSessionStatusAPI() | + | var chatStatus = ' |
| - | } | + | var chatStatusReason |
| + | var chatTimer = ' | ||
| - | if (chatstatus == ' | + | |
| - | chatstatus = capacityAPI() // | + | |
| - | } | + | |
| - | + | ||
| - | Response.Write(" | + | |
| - | Response.Write(" | + | |
| - | Response.Write(" | + | |
| - | + | ||
| - | function businessHoursAPI(){ | + | if (debuglevel > 0) { |
| - | try { | + | |
| - | var srvXmlHttp | + | } |
| - | srvXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP.3.0"); | + | |
| - | srvXmlHttp.setOption(2, | + | |
| - | srvXmlHttp.open ("GET", businessHoursUrl, | + | |
| - | srvXmlHttp.send(); | + | |
| - | var httpstatus | + | chatstatus |
| - | + | ||
| - | if (debuglevel > 0){ | + | |
| - | Response.Write(" | + | |
| - | } | + | |
| - | + | ||
| - | if (httpstatus != 200){ | + | |
| - | chatStatus = ' | + | |
| - | chatStatusReason = 'out of service'; | + | |
| - | return chatStatus; | + | |
| - | } | + | |
| - | + | ||
| - | chatStatusReason = ''; | + | |
| - | + | ||
| - | var businessHours = srvXmlHttp.responseXML; | + | |
| - | var businessHoursName = businessHours.selectSingleNode("// | + | |
| - | var runTimeStatus = businessHours.selectSingleNode("// | + | |
| - | var configuredStatus = businessHours.selectSingleNode("// | + | |
| - | if (configuredStatus.text > 0) { | + | |
| - | var reasonText = businessHours.selectSingleNode("// | + | |
| - | } | + | |
| - | //Parse Business Hours Name to retrieve the Proactive Chat Timer, Min Agent Count, Max Queue Depth & Max Wait Timeouts | + | if (chatstatus |
| - | var businessHoursNameArray = businessHoursName.text.split(" | + | |
| - | var myBusinessHoursName | + | } |
| - | myProactiveChatTimer | + | |
| - | myMinAgentCount | + | |
| - | myMaxQueueDepth = businessHoursNameArray[3]; | + | |
| - | myMaxWaitTime = businessHoursNameArray[4]; | + | |
| - | // Check if Valid Values from BusinessHour - if not - overwrite with the default values. | + | |
| - | if (isNaN(myProactiveChatTimer)){ | + | |
| - | myProactiveChatTimer | + | } |
| - | } | + | |
| - | if (isNaN(myMinAgentCount)){ | + | |
| - | myMinAgentCount | + | |
| - | } | + | |
| - | if (isNaN(myMaxQueueDepth)){ | + | |
| - | myMaxQueueDepth = defaultMaxQueueDepth; | + | |
| - | } | + | |
| - | if (isNaN(myMaxWaitTime)){ | + | |
| - | myMaxWaitTime = defaultMaxWaitTime; | + | |
| - | } | + | |
| - | if ((runTimeStatus.text == 0 || runTimeStatus.text == 2) && configuredStatus.text > 0) { | + | Response.Write(" |
| - | chatStatusReason = reasonText.text; | + | |
| - | } | + | |
| - | if (runTimeStatus.text == 1 || runTimeStatus.text == 3){ | + | Response.Write(" |
| - | chatStatus | + | Response.Write(" |
| - | } | + | Response.Write(" |
| - | if (debuglevel > 1){ | ||
| - | Response.Write(" | ||
| - | if (configuredStatus.text > 0) { | ||
| - | Response.Write(" | ||
| - | } | ||
| - | Response.Write(" | ||
| - | Response.Write(" | ||
| - | Response.Write(" | ||
| - | Response.Write(" | ||
| - | Response.Write(" | ||
| - | Response.Write(" | ||
| - | } | ||
| - | |||
| - | return chatStatus; | ||
| - | } //Try | ||
| - | |||
| - | catch(err) { | ||
| - | chatStatus = ' | ||
| - | chatStatusReason = 'out of service'; | ||
| - | if (debuglevel > 0){ | + | // ******************************************************************************************** // |
| - | Response.Write(" | + | // ******************************** Functions ************************************************* // |
| - | } | + | // ******************************************************************************************** // |
| - | return chatStatus; | + | function businessHoursAPI() { |
| - | + | try { | |
| - | } //Catch | + | var srvXmlHttp |
| - | } //Function | + | |
| + | srvXmlHttp.setOption(2, | ||
| + | srvXmlHttp.setTimeouts(resolveTimeout, | ||
| + | srvXmlHttp.open(" | ||
| + | srvXmlHttp.send(); | ||
| + | var httpstatus = srvXmlHttp.status; | ||
| - | function liveSessionStatusAPI(){ | + | |
| - | try { | + | Response.Write(" |
| - | var srvXmlHttp | + | } |
| - | srvXmlHttp = Server.CreateObject(" | + | |
| - | srvXmlHttp.setOption(2, | + | |
| - | srvXmlHttp.open (" | + | |
| - | srvXmlHttp.send(); | + | |
| - | + | ||
| - | var httpstatus = srvXmlHttp.status; | + | |
| - | + | ||
| - | if (debuglevel > 0){ | + | |
| - | Response.Write(" | + | |
| - | } | + | |
| - | + | ||
| - | if (httpstatus != 200){ | + | |
| - | chatStatus = ' | + | |
| - | chatStatusReason = 'out of service'; | + | |
| - | return chatStatus; | + | |
| - | } | + | |
| - | + | ||
| - | var liveSessionStatus = srvXmlHttp.responseXML; | + | |
| - | var waitTime = liveSessionStatus.selectSingleNode("// | + | |
| - | var queueDepth = liveSessionStatus.selectSingleNode("// | + | |
| - | + | ||
| - | if (parseInt(queueDepth.text, | + | |
| - | chatStatus = ' | + | |
| - | chatStatusReason = ' | + | |
| - | } | + | |
| - | + | ||
| - | if (parseInt(waitTime.text, | + | |
| - | chatStatus = ' | + | |
| - | chatStatusReason = ' | + | |
| - | } | + | |
| - | if (debuglevel > 1){ | + | |
| - | Response.Write(" | + | chatStatus |
| - | Response.Write(" | + | |
| - | } | + | myProactiveChatTimer = ' |
| + | return | ||
| + | } | ||
| - | return chatStatus; | + | chatStatusReason = '' |
| - | } //Try | + | |
| - | catch(err) { | + | var businessHours = srvXmlHttp.responseXML; |
| - | chatStatus | + | var businessHoursName = businessHours.selectSingleNode("// |
| - | chatStatusReason | + | var runTimeStatus |
| - | if (debuglevel | + | var configuredStatus |
| - | Response.Write("\nconsole.log(' | + | if (configuredStatus.text |
| - | } | + | var reasonText = businessHours.selectSingleNode("//businessHour/configuredStatus/statusReason/ |
| - | 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 |
| - | try { | + | |
| - | + | ||
| - | srvXmlHttp | + | |
| - | srvXmlHttp.setOption(2, | + | |
| - | srvXmlHttp.open (" | + | |
| - | srvXmlHttp.send(); | + | |
| - | + | ||
| - | var httpstatus = srvXmlHttp.status; | + | |
| - | + | ||
| - | if (debuglevel > 0){ | + | |
| - | Response.Write(" | + | |
| - | } | + | |
| - | + | ||
| - | if (httpstatus != 200){ | + | |
| - | chatStatus = ' | + | |
| - | chatStatusReason = 'out of service'; | + | |
| - | return chatStatus; | + | |
| - | } | + | |
| - | + | ||
| - | var capacity = srvXmlHttp.responseXML; | + | |
| - | var count = capacity.selectSingleNode("// | + | |
| - | if (parseInt(count.text, | + | // Check if Valid Values from BusinessHour - if not - overwrite with the default values. |
| - | chatStatus | + | |
| - | chatStatusReason | + | myProactiveChatTimer = defaultProactiveChatTimer; |
| - | } | + | } |
| + | if (isNaN(myMinAgentCount)) { | ||
| + | | ||
| + | } | ||
| + | if (isNaN(myMaxQueueDepth)) { | ||
| + | myMaxQueueDepth | ||
| + | } | ||
| + | if (isNaN(myMaxWaitTime)) { | ||
| + | myMaxWaitTime = defaultMaxWaitTime; | ||
| + | } | ||
| - | if (debuglevel > 1){ | + | |
| - | Response.Write(" | + | chatStatusReason = reasonText.text; |
| - | } | + | } |
| - | return chatStatus; | + | if (runTimeStatus.text == 1 || runTimeStatus.text == 3) { |
| - | } // Try | + | chatStatus = ' |
| - | + | } | |
| - | catch(err) { | + | |
| - | chatStatus = ' | + | if (debuglevel > 1) { |
| - | chatStatusReason = 'out of service'; | + | Response.Write(" |
| - | if (debuglevel > 0){ | + | if (configuredStatus.text > 0) { |
| - | Response.Write(" | + | Response.Write(" |
| - | } | + | } |
| - | return chatStatus; | + | Response.Write(" |
| - | + | Response.Write(" | |
| - | } //Catch | + | Response.Write(" |
| - | } // | + | Response.Write(" |
| - | } //End of Global Try | + | Response.Write(" |
| - | + | Response.Write(" | |
| - | catch(err) { | + | } |
| - | chatStatus = ' | + | |
| - | chatStatusReason = 'out of service'; | + | |
| - | chatTimer=0; | + | } //Try |
| - | + | catch (err) { | |
| - | Response.Write(" | + | |
| - | Response.Write(" | + | chatStatusReason = 'out of service'; |
| - | Response.Write(" | + | myProactiveChatTimer = ' |
| - | + | ||
| - | Response.Write(" | + | if (debuglevel > 0) { |
| - | } | + | Response.Write(" |
| - | + | } | |
| - | %> | + | return chatStatus; |
| + | } //Catch | ||
| + | } // | ||
| + | |||
| + | |||
| + | function liveSessionStatusAPI() { | ||
| + | try { | ||
| + | var srvXmlHttp | ||
| + | srvXmlHttp = Server.CreateObject(" | ||
| + | srvXmlHttp.setOption(2, | ||
| + | srvXmlHttp.open(" | ||
| + | srvXmlHttp.send(); | ||
| + | |||
| + | var httpstatus = srvXmlHttp.status; | ||
| + | |||
| + | if (debuglevel > 0) { | ||
| + | Response.Write(" | ||
| + | } | ||
| + | |||
| + | if (httpstatus != 200) { | ||
| + | chatStatus = ' | ||
| + | chatStatusReason = 'out of service'; | ||
| + | myProactiveChatTimer = ' | ||
| + | return chatStatus; | ||
| + | } | ||
| + | |||
| + | var liveSessionStatus = srvXmlHttp.responseXML; | ||
| + | var waitTime = liveSessionStatus.selectSingleNode("// | ||
| + | var queueDepth = liveSessionStatus.selectSingleNode("// | ||
| + | |||
| + | if (parseInt(queueDepth.text, | ||
| + | chatStatus = ' | ||
| + | chatStatusReason = ' | ||
| + | myProactiveChatTimer = ' | ||
| + | } | ||
| + | |||
| + | if (parseInt(waitTime.text, | ||
| + | chatStatus = ' | ||
| + | chatStatusReason = ' | ||
| + | myProactiveChatTimer = ' | ||
| + | } | ||
| + | |||
| + | if (debuglevel > 1) { | ||
| + | Response.Write(" | ||
| + | Response.Write(" | ||
| + | } | ||
| + | |||
| + | return chatStatus; | ||
| + | } //Try | ||
| + | | ||
| + | chatStatus = ' | ||
| + | chatStatusReason = 'out of service'; | ||
| + | myProactiveChatTimer = ' | ||
| + | |||
| + | | ||
| + | Response.Write(" | ||
| + | } | ||
| + | return chatStatus; | ||
| + | } //Catch | ||
| + | } // | ||
| + | |||
| + | |||
| + | |||
| + | function capacityAPI() { | ||
| + | try { | ||
| + | |||
| + | srvXmlHttp = Server.CreateObject(" | ||
| + | srvXmlHttp.setOption(2, | ||
| + | srvXmlHttp.open(" | ||
| + | srvXmlHttp.send(); | ||
| + | |||
| + | var httpstatus = srvXmlHttp.status; | ||
| + | |||
| + | if (debuglevel > 0) { | ||
| + | Response.Write(" | ||
| + | } | ||
| + | |||
| + | if (httpstatus != 200) { | ||
| + | chatStatus = ' | ||
| + | chatStatusReason = 'out of service'; | ||
| + | | ||
| + | } | ||
| + | |||
| + | var capacity = srvXmlHttp.responseXML; | ||
| + | var count = capacity.selectSingleNode("// | ||
| + | |||
| + | if (parseInt(count.text, | ||
| + | chatStatus = ' | ||
| + | chatStatusReason = ' | ||
| + | myProactiveChatTimer = ' | ||
| + | } | ||
| + | |||
| + | if (debuglevel > 1) { | ||
| + | Response.Write(" | ||
| + | } | ||
| + | |||
| + | return chatStatus; | ||
| + | } // Try | ||
| + | catch (err) { | ||
| + | chatStatus = ' | ||
| + | chatStatusReason = 'out of service'; | ||
| + | chatTimer = ' | ||
| + | if (debuglevel > 0) { | ||
| + | Response.Write(" | ||
| + | } | ||
| + | return chatStatus; | ||
| + | |||
| + | | ||
| + | } // | ||
| + | } //End of Global Try | ||
| + | |||
| + | catch (err) { | ||
| + | chatStatus = ' | ||
| + | chatStatusReason = 'out of service'; | ||
| + | chatTimer = '0'; | ||
| + | |||
| + | Response.Write(" | ||
| + | Response.Write(" | ||
| + | Response.Write(" | ||
| + | Response.Write(" | ||
| + | } | ||
| + | |||
| + | %> | ||
| </ | </ | ||