Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| vendors:cisco:uc:ece:demojs [2019/03/06 15:05] – gerardorourke | vendors:cisco:uc:ece:demojs [2019/03/15 09:34] (current) – gerardorourke | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Demo Website Javascript ====== | ====== Demo Website Javascript ====== | ||
| - | Using below you can create a Proactive Chat & Change website based on open / closed / busy values. | ||
| - | ==== JavaScript - PHP File===== | + | This detail here has been improved |
| - | <code php> | + | [[vendors:cisco:uc:ece:apiexample]] |
| - | <?php | + | |
| - | header(' | + | |
| - | // todo - check values of GET variables before setting them - and give them a default if not valid | + | |
| - | // Author: Gerry O' | + | |
| - | // Date: Feb 2019 | + | |
| - | // This is code created for a demo website and is not production ready. Update, secure and improve error handling if used on a a production website | + | |
| - | // Use at your own risk - provided for education purposes only | + | |
| - | + | ||
| - | + | ||
| - | $myChatEntryId = htmlspecialchars($_GET[" | + | |
| - | $myBusinessHoursId = htmlspecialchars($_GET[" | + | |
| - | $ccehostname = ' | + | |
| - | $ecehostname = ' | + | |
| - | $cceuser = ' | + | |
| - | $ccepass = ' | + | |
| - | + | ||
| - | $url = ' | + | |
| - | + | ||
| - | $ch = curl_init($url); | + | |
| - | | + | |
| - | curl_setopt($ch, | + | |
| - | curl_setopt($ch, | + | |
| - | curl_setopt($ch, | + | |
| - | curl_setopt($ch, | + | |
| - | curl_setopt($ch, | + | |
| - | curl_setopt($ch, | + | |
| - | $output = curl_exec($ch); | + | |
| - | //echo $output." | + | |
| - | //$info = curl_getinfo($ch); | + | |
| - | // | + | |
| - | curl_close($ch); | + | |
| - | + | ||
| - | $xml=simplexml_load_string($output); | + | |
| - | //echo $xml; | + | |
| - | // | + | |
| - | + | ||
| - | $bh_status=(int) $xml-> | + | |
| - | $bh_name=$xml-> | + | |
| - | //echo "name: $bh_name\n"; | + | |
| - | //echo " | + | |
| - | + | ||
| - | //Parse BusinessHours Name for underscores | + | |
| - | $myvar = (explode(" | + | |
| - | $myProactiveChatTimer = $myvar[1]; | + | |
| - | $myMinAgentCount = $myvar[2]; | + | |
| - | $myMaxQueueDepth = $myvar[3]; | + | |
| - | $myMaxWaitTime = $myvar[4]; | + | |
| - | if ((empty($myProactiveChatTimer))||(!is_numeric($myProactiveChatTimer))) {$myProactiveChatTimer = ' | + | |
| - | if ((empty($myMinAgentCount))|| (!is_numeric($myMinAgentCount))) {$myMinAgentCount = ' | + | |
| - | if ((empty($myMaxQueueDepth))||(!is_numeric($myMaxQueueDepth))) {$myMaxQueueDepth = ' | + | |
| - | if ((empty($myMaxWaitTime))|| (!is_numeric($myMaxWaitTime))) {$myMaxWaitTime = ' | + | |
| - | $myProactiveChatTimer = $myProactiveChatTimer * 1000; //convert to ms | + | |
| - | + | ||
| - | //echo " | + | |
| - | //echo " | + | |
| - | //echo " | + | |
| - | //echo " | + | |
| - | //echo " | + | |
| - | //set open or closed based on runTimeStatus | + | |
| - | + | ||
| - | $chatStatus = ' | + | |
| - | + | ||
| - | if ($bh_status==1 or $bh_status==3){ | + | |
| - | $chatStatus = ' | + | |
| - | + | ||
| - | // Capacity API - Checking Agents are available | + | |
| - | curl_reset($ch); | + | |
| - | $url = ' | + | |
| - | //echo $url." | + | |
| - | $ch = curl_init($url); | + | |
| - | curl_setopt($ch, | + | |
| - | curl_setopt($ch, | + | |
| - | curl_setopt($ch, | + | |
| - | curl_setopt($ch, | + | |
| - | $capacity = curl_exec($ch); | + | |
| - | //$info = curl_getinfo($ch); | + | |
| - | // | + | |
| - | curl_close($ch); | + | |
| - | + | ||
| - | $xml_data = str_replace(" | + | |
| - | $xml_capacity=simplexml_load_string($xml_data); | + | |
| - | $agentcount=(int) $xml_capacity-> | + | |
| - | if ($agentcount < $myMinAgentCount){ | + | |
| - | $chatStatus = ' | + | |
| - | $chatBusyReason = ' | + | |
| - | } else { | + | |
| - | curl_reset($ch); | + | |
| - | $url = ' | + | |
| - | $ch = curl_init($url); | + | |
| - | curl_setopt($ch, | + | |
| - | curl_setopt($ch, | + | |
| - | curl_setopt($ch, | + | |
| - | curl_setopt($ch, | + | |
| - | $liveSessionStatus = curl_exec($ch); | + | |
| - | //$info = curl_getinfo($ch); | + | |
| - | // | + | |
| - | // | + | |
| - | $xml_data = str_replace(" | + | |
| - | $xml_liveSessionStatus=simplexml_load_string($xml_data); | + | |
| - | $queueDepth=(int) $xml_liveSessionStatus-> | + | |
| - | $waitTime=(int) $xml_liveSessionStatus-> | + | |
| - | + | ||
| - | if ($queueDepth> | + | |
| - | $chatStatus = ' | + | |
| - | $chatBusyReason = ' | + | |
| - | } | + | |
| - | if ($waitTime> | + | |
| - | $chatStatus = ' | + | |
| - | $chatBusyReason = ' | + | |
| - | } | + | |
| - | + | ||
| - | } | + | |
| - | } | + | |
| - | + | ||
| - | echo "var chatStatus = ' | + | |
| - | echo "var chatBusyReason = ' | + | |
| - | echo "var chatTimer = ' | + | |
| - | echo " | + | |
| - | echo " | + | |
| - | echo " | + | |
| - | echo " | + | |
| - | echo " | + | |
| - | echo " | + | |
| - | echo " | + | |
| - | echo " | + | |
| - | echo " | + | |
| - | echo " | + | |
| - | echo " | + | |
| - | echo " | + | |
| - | echo " | + | |
| - | echo " | + | |
| - | echo " | + | |
| - | echo " | + | |
| - | ?> | + | |
| - | </ | + | |
| - | + | ||
| - | ===== Website Javascript - which updates the webpage ===== | + | |
| - | <code javascript> | + | |
| - | if (chatStatus == ' | + | |
| - | $('# | + | |
| - | $('# | + | |
| - | $('# | + | |
| - | $('# | + | |
| - | $('# | + | |
| - | $('# | + | |
| - | } | + | |
| - | if (chatStatus == ' | + | |
| - | $('# | + | |
| - | $('# | + | |
| - | $('# | + | |
| - | $('# | + | |
| - | $('# | + | |
| - | $('# | + | |
| - | //Proactive Chat | + | |
| - | setTimeout(function() { | + | |
| - | if (chatTimer != 0){ | + | |
| - | $('# | + | |
| - | } | + | |
| - | }, chatTimer); | + | |
| - | } | + | |
| - | if (chatStatus == ' | + | |
| - | $('# | + | |
| - | $('# | + | |
| - | $('# | + | |
| - | $('# | + | |
| - | $('# | + | |
| - | $('# | + | |
| - | } | + | |
| - | + | ||
| - | function disableProactiveChat() { | + | |
| - | window.chatTimer = 0; | + | |
| - | console.log(' | + | |
| - | } | + | |
| - | + | ||
| - | console.log(' | + | |
| - | console.log(' | + | |
| - | </ | + | |
| - | + | ||
| - | ===== HTML ===== | + | |
| - | ==== Simple HTML Example showing how to update page ==== | + | |
| - | <code html> | + | |
| - | < | + | |
| - | < | + | |
| - | < | + | |
| - | </ | + | |
| - | + | ||
| - | ===== HTML ===== | + | |
| - | ==== 'Chat on' HTML ==== | + | |
| - | Note: It disables the proactive chat (by calling a function) and then also calls the ECE Chat | + | |
| - | + | ||
| - | <code html> | + | |
| - | <div id=" | + | |
| - | <a onclick=" | + | |
| - | <div class=" | + | |
| - | <div class=" | + | |
| - | <img id=" | + | |
| - | </ | + | |
| - | <div class=" | + | |
| - | </ | + | |
| - | </ | + | |
| - | </ | + | |
| - | ==== HTML for Proactive Chat ==== | + | |
| - | Note - uses Bootstrap CSS **Modal** for Popup - [[https:// | + | |
| - | + | ||
| - | <code html> | + | |
| - | <!-- Modal --> | + | |
| - | <div class=" | + | |
| - | <div class=" | + | |
| - | <div class=" | + | |
| - | <div class=" | + | |
| - | <h5 class=" | + | |
| - | <button type=" | + | |
| - | <span aria-hidden=" | + | |
| - | </ | + | |
| - | </ | + | |
| - | <div class=" | + | |
| - | < | + | |
| - | < | + | |
| - | </ | + | |
| - | <div class=" | + | |
| - | <button type=" | + | |
| - | <button type=" | + | |
| - | </ | + | |
| - | </ | + | |
| - | </ | + | |
| - | </ | + | |
| - | </ | + | |