Skip to content

Commit

Permalink
Version 1.1
Browse files Browse the repository at this point in the history
See README.md
  • Loading branch information
rutoru committed May 18, 2014
1 parent fa0d2bb commit b48af5d
Show file tree
Hide file tree
Showing 18 changed files with 400 additions and 72 deletions.
10 changes: 9 additions & 1 deletion README.md
Expand Up @@ -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最後の方で説明しています。

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

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

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


ライセンス
----------
Expand Down
12 changes: 6 additions & 6 deletions lib/Runa_CCA/Controller/CallFlow/NewService.php
Expand Up @@ -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;


Expand Down
150 changes: 150 additions & 0 deletions lib/Runa_CCA/Controller/Report.php
@@ -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
);


}

}
2 changes: 1 addition & 1 deletion lib/Runa_CCA/Controller/TwiMLApp.php
Expand Up @@ -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{

Expand Down
4 changes: 0 additions & 4 deletions lib/Runa_CCA/Model/CallFlow/NewService/QueueUrl.php
Expand Up @@ -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"];
Expand Down
11 changes: 11 additions & 0 deletions lib/Runa_CCA/Model/Database/OperatorLevel.php
Expand Up @@ -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;

}

}
2 changes: 1 addition & 1 deletion lib/Runa_CCA/Model/TwiMLApp.php
Expand Up @@ -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();
Expand Down
25 changes: 11 additions & 14 deletions lib/Runa_CCA/Model/Twilio.php
Expand Up @@ -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;

}

}


Expand Down
48 changes: 48 additions & 0 deletions lib/Runa_CCA/Model/Wallboard.php
@@ -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;

}

}
4 changes: 4 additions & 0 deletions lib/Runa_CCA/Route.php
Expand Up @@ -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');

Expand Down
10 changes: 10 additions & 0 deletions lib/Runa_CCA/View/Render.php
Expand Up @@ -202,6 +202,16 @@ public function display(){
);

break;

// WALLBOARD
case "WALLBOARD":

$this->app->render(
'Report/wallboard_msg.twig',
[
'wallboards' => $args[1], // Wallboard Object Array
]
);

}
}
Expand Down

0 comments on commit b48af5d

Please sign in to comment.