function managePost() { error_log(print_R($_POST, TRUE)); $type = $_POST["type"]; if ($type == "nextcall") { nextAgentCall($_POST); } else { if ($type == "agentstate") { $redis = getRedisInstance(); if ($redis) { $agentid = $_POST["agent"]; $agentstate = $_POST["state"]; if ($agentstate == "true") { $agentstate = true; } else { $agentstate = false; } $redis->set($agentid . '_state', $agentstate); nextCall($agentid); // modify logic to not call always } } else { if ($type == "assignagent") { $agentid = $_POST["agent"]; $customers = $_POST["customers"]; $customers = explode(',', $customers); error_log(print_R($customers, TRUE)); $redis = getRedisInstance(); if ($redis) { foreach ($customers as $customer) { if (trim($customer) != '') { error_log($agentid . ' ' . $customer); $redis->rpush($agentid . '_customer_queue', $customer); } } } } } } http_response_code(200); }
function nextCall($agentid) { $redis = getRedisInstance(); if ($redis) { error_log("HasRedis"); $agentavailable = $redis->get($agentid . '_state'); // get state of agent from redis if ($agentavailable) { error_log("agentavailable"); if ($redis->llen($agentid . '_customer_queue') > 0) { error_log("people in queue"); $nextcustomer_no = $redis->lpop($agentid . '_customer_queue'); // get next customer id redis $redis->set($agentid . '_currentcustomer', $nextcustomer_no); doOutboundCall($agentid, $nextcustomer_no); } else { $redis->set($agentid . '_currentcustomer', 'done'); } } } }
<?php require 'common.php'; header('Content-Type: text/event-stream'); header('Cache-Control: no-cache'); // recommended to prevent caching of event data. /** * Constructs the SSE data format and flushes that data to the client. * * @param string $id Timestamp/id of this connection. * @param string $msg Line of text that should be transmitted. */ function sendMsg($id, $msg) { echo "id: {$id}" . PHP_EOL; echo "data: {$msg}" . PHP_EOL; echo PHP_EOL; ob_flush(); flush(); } $redis = getRedisInstance(); $agentid = $_REQUEST['agentid']; $currentcustomer = $redis->get($agentid . '_currentcustomer'); sendMsg($agentid, $currentcustomer);