runTimeStatus; $bh_name=$xml->name; //echo "name: $bh_name\n"; //echo "runTimeStatus: $bh_status\n"; //Parse BusinessHours Name for underscores $myvar = (explode("_",$bh_name)); $myProactiveChatTimer = $myvar[1]; $myMinAgentCount = $myvar[2]; $myMaxQueueDepth = $myvar[3]; $myMaxWaitTime = $myvar[4]; if ((empty($myProactiveChatTimer))||(!is_numeric($myProactiveChatTimer))) {$myProactiveChatTimer = '0';} if ((empty($myMinAgentCount))|| (!is_numeric($myMinAgentCount))) {$myMinAgentCount = '0';} if ((empty($myMaxQueueDepth))||(!is_numeric($myMaxQueueDepth))) {$myMaxQueueDepth = '5';} if ((empty($myMaxWaitTime))|| (!is_numeric($myMaxWaitTime))) {$myMaxWaitTime = '60';} $myProactiveChatTimer = $myProactiveChatTimer * 1000; //convert to ms //echo "\nmyProactiveChatTimer: ".$myProactiveChatTimer; //echo "\nmyMinAgentCount: ".$myMinAgentCount; //echo "\nmyMaxQueueDepth: ".$myMaxQueueDepth; //echo "\nmyMaxWaitTime: ".$myMaxWaitTime; //echo "\n\n"; //set open or closed based on runTimeStatus $chatStatus = 'closed'; if ($bh_status==1 or $bh_status==3){ $chatStatus = 'open'; // Capacity API - Checking Agents are available curl_reset($ch); $url = 'http://'.$ecehostname.'/system/egain/chat/entrypoint/capacity/' . $myChatEntryId; //echo $url."\n"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPGET, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2); //connection timeout curl_setopt($ch, CURLOPT_TIMEOUT, 3); //timeout in seconds for transaction $capacity = curl_exec($ch); //$info = curl_getinfo($ch); //print_r($info); curl_close($ch); $xml_data = str_replace("ns2:","",$capacity); $xml_capacity=simplexml_load_string($xml_data); $agentcount=(int) $xml_capacity->count; if ($agentcount < $myMinAgentCount){ $chatStatus = 'busy'; $chatBusyReason = 'MinAgentCount'; } else { curl_reset($ch); $url = 'http://'.$ecehostname.'/system/egain/chat/entrypoint/liveSessionStatus/' . $myChatEntryId; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPGET, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2); //connection timeout curl_setopt($ch, CURLOPT_TIMEOUT, 3); //timeout in seconds for transaction $liveSessionStatus = curl_exec($ch); //$info = curl_getinfo($ch); //print_r($info); //curl_close($ch); $xml_data = str_replace("ns2:","",$liveSessionStatus); $xml_liveSessionStatus=simplexml_load_string($xml_data); $queueDepth=(int) $xml_liveSessionStatus->queueDepth; $waitTime=(int) $xml_liveSessionStatus->waitTime; if ($queueDepth>$myMaxQueueDepth){ $chatStatus = 'busy'; $chatBusyReason = 'MaxQueueDepth'; } if ($waitTime>$myMaxWaitTime){ $chatStatus = 'busy'; $chatBusyReason = 'MaxWaitTime'; } } } echo "var chatStatus = '$chatStatus';\n"; echo "var chatBusyReason = '$chatBusyReason';\n"; echo "var chatTimer = '$myProactiveChatTimer';\n"; echo "\nconsole.log('------- Demo API Lookups Start------');"; echo "\nconsole.log('Filename: " . basename(__FILE__) . "');"; echo "\nconsole.log('ChatEntryId: $myChatEntryId');"; echo "\nconsole.log('BusinessHoursId: $myBusinessHoursId');"; echo "\nconsole.log('chatStatus: $chatStatus');"; echo "\nconsole.log('chatTimer: $myProactiveChatTimer');"; echo "\nconsole.log('chatBusyReason: $chatBusyReason');"; echo "\nconsole.log('------- min / max queue values------');"; echo "\nconsole.log('minAgentCount: $myMinAgentCount');"; echo "\nconsole.log('maxQueueDepth: $myMaxQueueDepth');"; echo "\nconsole.log('maxWaitTime: $myMaxWaitTime');"; echo "\nconsole.log('------- current queuevalues------');"; echo "\nconsole.log('agentcount: $agentcount');"; echo "\nconsole.log('queueDepth: $queueDepth');"; echo "\nconsole.log('waitTime: $waitTime');"; echo "\nconsole.log('------- Demo API Lookups End------');"; ?>