Permalink
Browse files

Version 1.1

See README.md
  • Loading branch information...
rutoru committed May 18, 2014
1 parent fa0d2bb commit b48af5dc2aa3e5b2c194d66ab73a695610ca0359
@@ -8,7 +8,7 @@ Runa-CCAは、[Twilio](http://twilio.kddi-web.com)を使った、やや本格的

[Twilio](http://twilio.kddi-web.com)調査中というのと、プログラミング勉強中というのとで、いろいろといまいちです。バージョンアップしていきます。

最新はVersion 1.0。バージョンについてはREADME最後の方で説明しています。
最新はVersion 1.1。バージョンについてはREADME最後の方で説明しています。

概要
------
@@ -65,6 +65,14 @@ MySQLのテーブルに格納されます。レポートの参照は、MySQLの
+ SystemAdmin ... キュー管理+オペレータ管理
+ Twilioからリクエストされる部分について、Twilio推奨の認証(検証)方法を導入しました。
+ 上記実現のため、ソースコードならびにDB構造の変更を行っています。

#### Version 1.1 ####
ウォールボード機能を追加しました。

+ Webクライアントの管理画面(Configurator)からウォールボードを起動します。1.1ではログインユーザの所属するキューの情報をリアルタイムで表示します。10秒更新です。
+ TwiML出力方法の変更。Webクライアント側と合わせてTwigを利用するようにしました。
+ 不要ファイルの削除と、細かなバグ修正を実施。


ライセンス
----------
@@ -29,42 +29,42 @@ static function start($method){
case "main" :
$response = (new \Runa_CCA\Model\CallFlow\NewService\Main())->main($params);
(new \Runa_CCA\View\Twiml())->createTwiml($response);
(new \Runa_CCA\View\Twiml($app))->createTwiml($response);
break;
// Go to Wait
case "wait" :
$response = (new \Runa_CCA\Model\CallFlow\NewService\Wait())->wait($params);
(new \Runa_CCA\View\Twiml())->createTwiml($response);
(new \Runa_CCA\View\Twiml($app))->createTwiml($response);
break;
// Go to Info
case "info" :
$response = (new \Runa_CCA\Model\CallFlow\NewService\Info())->info();
(new \Runa_CCA\View\Twiml())->createTwiml($response);
(new \Runa_CCA\View\Twiml($app))->createTwiml($response);
break;
// Go to EnqueAction
case "enqueaction" :
$response = (new \Runa_CCA\Model\CallFlow\NewService\EnqueAction())->insert($params);
(new \Runa_CCA\View\Twiml())->createTwiml($response);
(new \Runa_CCA\View\Twiml($app))->createTwiml($response);
break;
// Go to QueueUrl
case "guidance" :
$response = (new \Runa_CCA\Model\CallFlow\NewService\QueueUrl())->insert($params);
(new \Runa_CCA\View\Twiml())->createTwiml($response);
(new \Runa_CCA\View\Twiml($app))->createTwiml($response);
break;
// Go to StatusCallback
case "statuscallback" :
$response = (new \Runa_CCA\Model\CallFlow\NewService\StatusCallback())->insert($params);
(new \Runa_CCA\View\Twiml())->createTwiml($response);
(new \Runa_CCA\View\Twiml($app))->createTwiml($response);
break;
@@ -0,0 +1,150 @@
<?php
/**
* Report Class
*
* @author rutoru
* @package Runa-CCA
*/
namespace Runa_CCA\Controller;
class Report {
/**
* portal
*
* @param String $menu Menu Name
*/
static function portal($menu){
// Get Parameters
$app = \Slim\Slim::getInstance();
$params = $app->request->params();
// Set 'auth' false when a non-verified user comes.
if(! isset($_SESSION['auth'])){
$_SESSION['auth'] = false;
// A verified user's 'auth' remains true.
}
// Verify the user if 'auth' is not set.
if($_SESSION['auth'] == false){
// Display an error and route to login page.
$render = new \Runa_CCA\View\Render($app);
$render->display("NOAUTH");
// Switch the page if the user has already been verified.
}else{
// Check the operator level.
// The operator with level SYSTEMADMIN or SUPERVISOR or OPERATOR can log in.
if(isset($_SESSION['operator_lv']) &&
$_SESSION['operator_lv'] <= (new \Runa_CCA\Model\Database\OperatorLevel())->getReportBorder()){
switch ($menu){
// Wallboard.
case "WALLBOARD":
Self::displayQueues($app, $params);
break;
// Go to Error
default :
\Runa_CCA\Controller\Error::display("ERROR");
break;
}
}else{
// Destroy Session
$_SESSION = array();
if (isset($_COOKIE[session_name()])){
setcookie(session_name(), '', time() - 3600, '/');
}
session_destroy();
// Display an error and route to login page.
$render = new \Runa_CCA\View\Render($app);
$render->display("NOAUTH");
}
}
}
/**
* displayQueues
*
* @param \Slim\Slim $app Slim Object
* @param Array $params Input parameters
*/
static function displayQueues($app, $params){
// Initialize waitTimes value.
$waitTimes = [0];
// Initialize wallboard.
$wallboard = array();
// Get Twilio information.
$twilioClient = (new \Runa_CCA\Model\Twilio())->getTwilioClient();
// DB Connection
$dbConn = (new \Runa_CCA\Model\DB())->getIlluminateConnection();
// Select twilio_queue_id.
// When an error occurs, Slim will catch the error and display error message according to the setting in Route class.
$stmt = $dbConn->getPdo()->prepare(
'SELECT queue.twilio_queue_id FROM queue '.
'INNER JOIN operator_queue '.
'ON operator_queue.queue_id = queue.queue_id '.
'AND operator_queue.operator_id = :operator_id'
);
$stmt->bindValue('operator_id', $_SESSION['operator_id']);
$stmt->execute();
// Get the queue values.
foreach ($stmt->fetchAll() as $twilioQueueId){
// Get data from Twilio.
$twilioQueue = $twilioClient->account->queues->get($twilioQueueId["twilio_queue_id"]);
// Get wait_time.
foreach ($twilioQueue->members as $member) {
$waitTimes[] = $member->wait_time;
}
// Create Wallboard object.
$wallboard[] = new \Runa_CCA\Model\Wallboard(
$twilioQueue->sid,
$twilioQueue->friendly_name,
$twilioQueue->current_size,
$twilioQueue->max_size,
$twilioQueue->average_wait_time,
max($waitTimes)
);
}
// Set Session Data as global in Twig Template.
$twig = $app->view()->getEnvironment();
$twig->addGlobal("session", $_SESSION);
// Go to Operator Add page with the result of the validation.
$render = new \Runa_CCA\View\Render($app);
$render->display(
"WALLBOARD", // Switch Flag
$wallboard // Wallboard Object
);
}
}
@@ -23,7 +23,7 @@ static function createTwiMLApp(){
if((new \Runa_CCA\Model\Twilio())->validateTwilioRequest($app, $params)){
$response = (new \Runa_CCA\Model\TwiMLApp())->createTwiMLApp($params);
(new \Runa_CCA\View\Twiml())->createTwiml($response);
(new \Runa_CCA\View\Twiml($app))->createTwiml($response);
}else{
@@ -54,10 +54,6 @@ public function insert($params){
$queue->ApiVersion = $params["ApiVersion"];
$queue->Direction = $params["Direction"];
$queue->ForwardedFrom = $params["ForwardedFrom"];
// This parameter is set when the IncomingPhoneNumber
// that received the call has had its VoiceCallerIdLookup value set to true ($0.01 per look up).
// from Twilio Site
// $enqueue->CallerName = $params["CallerName"];
$queue->QueueSid = $params["QueueSid"];
$queue->QueueTime = $params["QueueTime"];
$queue->DequeingCallSid = $params["DequeingCallSid"];
@@ -82,5 +82,16 @@ public function getQueueConfigBorder(){
return Self::LV_SYSTEMADMIN_ID;
}
/**
* getReportBorder
*
* @return String Border line of entering the report page
*/
public function getReportBorder(){
return Self::LV_OPERATOR_ID;
}
}
@@ -37,7 +37,7 @@ public function createTwiMLApp($params){
$number = \Base\Conf::h($params['PhoneNumber']);
// DB Connection
$dbConn = \Runa_CCA\Model\DB::getIlluminateConnection();
$dbConn = (new \Runa_CCA\Model\DB())->getIlluminateConnection();
// Check if the queue exists.
$queueObj = \Runa_CCA\Model\Database\Queue::where('queue_id', '=', $number)->first();
@@ -69,38 +69,35 @@ public function validateTwilioRequest($app, $params){
// Get the request.
$req = $app->request;
// Get the X-Twilio-Signature header.
$twilioSignature = $req->headers->get('HTTP_X_TWILIO_SIGNATURE');
// Get the Twilio request URL.
$url = $req->getUrl().$req->getPath();
// Create Validator
$validator = new \Services_Twilio_RequestValidator(\Base\Conf::ACCOUNT_TOKEN);
// The post variables in the Twilio request.
// Validation needs all date of the parameters.
$postVars = $params;
// Debug
$app->log->debug(strftime("[%Y/%m/%d %H:%M:%S]:".__FILE__.":".__LINE__));
$app->log->debug("Twilio Signature, Requested URL and Posted variables:");
$app->log->debug(print_r($twilioSignature,true));
$app->log->debug(print_r($url,true));
$app->log->debug(print_r($postVars,true));
$app->log->debug(print_r($params,true));
// Validate
if ($validator->validate($twilioSignature, $url, $postVars)) {
// Validation needs all post parameters.
if ($validator->validate($twilioSignature, $url, $params)) {
return true;
}else{
return false;
}
}
@@ -0,0 +1,48 @@
<?php
/**
* Wallboard Class
*
* @author rutoru
* @package Runa-CCA
*/
namespace Runa_CCA\Model;
class Wallboard {
/**
* Object Variables
*/
public $sid;
public $friendly_name;
public $current_size;
public $max_size;
public $average_wait_time;
public $max_wait_time;
/**
* Constructor
*
* @param String $sid sid
* @param String $friendly_name friendly_name
* @param String $current_size current_size
* @param String $max_size max_size
* @param String $average_wait_time average_wait_time
* @param String $max_wait_time max_wait_time
*/
public function __construct($sid,
$friendly_name,
$current_size,
$max_size,
$average_wait_time,
$max_wait_time){
$this->sid = $sid;
$this->friendly_name = $friendly_name;
$this->current_size = $current_size;
$this->max_size = $max_size;
$this->average_wait_time = $average_wait_time;
$this->max_wait_time = $max_wait_time;
}
}
@@ -34,6 +34,10 @@ static function registration($app){
$app->post('/conf/queueadd', function(){\Runa_CCA\Controller\QueueConfiguration::portal("MNGQUEUE");});
$app->post('/conf/queuemod', function(){\Runa_CCA\Controller\QueueConfiguration::portal("MODQUEUE");});
// Reporting
// Wallboard
$app->map ('/report/wallboard', function(){\Runa_CCA\Controller\Report::portal("WALLBOARD");})->via('GET', 'POST');
// Softphone
$app->map ('/softphone', function(){\Runa_CCA\Controller\Softphone::portal();})->via('GET', 'POST');
@@ -202,6 +202,16 @@ public function display(){
);
break;
// WALLBOARD
case "WALLBOARD":
$this->app->render(
'Report/wallboard_msg.twig',
[
'wallboards' => $args[1], // Wallboard Object Array
]
);
}
}
Oops, something went wrong.

0 comments on commit b48af5d

Please sign in to comment.