@ -0,0 +1,20 @@ |
|||||||
|
/node_modules |
||||||
|
/public/hot |
||||||
|
/public/storage |
||||||
|
/storage/*.key |
||||||
|
/vendor |
||||||
|
.env |
||||||
|
.env.backup |
||||||
|
.phpunit.result.cache |
||||||
|
docker-compose.override.yml |
||||||
|
Homestead.json |
||||||
|
Homestead.yaml |
||||||
|
npm-debug.log |
||||||
|
yarn-error.log |
||||||
|
/.idea |
||||||
|
/stubs |
||||||
|
/public/node_modules |
||||||
|
/public/vendor |
||||||
|
/banco |
||||||
|
/websocket/vendor |
||||||
|
composer.lock |
@ -1,4 +0,0 @@ |
|||||||
RewriteEngine on |
|
||||||
RewriteCond %{REQUEST_FILENAME} !-f |
|
||||||
RewriteCond %{REQUEST_FILENAME} !-d |
|
||||||
RewriteRule ^(.*)$ index.php/$1 [L] |
|
@ -0,0 +1,29 @@ |
|||||||
|
FROM php:8.0-apache |
||||||
|
RUN apt-get update && apt-get install -y \ |
||||||
|
vim |
||||||
|
ADD https://raw.githubusercontent.com/mlocati/docker-php-extension-installer/master/install-php-extensions /usr/local/bin/ |
||||||
|
|
||||||
|
RUN chmod uga+x /usr/local/bin/install-php-extensions && sync && \ |
||||||
|
install-php-extensions pdo_pgsql |
||||||
|
|
||||||
|
RUN echo "ServerName 192.168.115.65" >> /etc/apache2/apache2.conf &&\ |
||||||
|
a2enmod rewrite &&\ |
||||||
|
a2dissite 000-default |
||||||
|
|
||||||
|
COPY apache2.conf /etc/apache2/ |
||||||
|
COPY ports.conf /etc/apache2/ |
||||||
|
COPY . . |
||||||
|
RUN a2enmod headers |
||||||
|
RUN service apache2 restart |
||||||
|
|
||||||
|
WORKDIR /var/www/html |
||||||
|
|
||||||
|
COPY index.php index.php |
||||||
|
|
||||||
|
RUN chmod -R 777 /var/www/html/ |
||||||
|
RUN chmod -R 777 /tmp |
||||||
|
RUN chown -R www-data:www-data /var/www/html |
||||||
|
EXPOSE 8081 |
||||||
|
EXPOSE 8090 |
||||||
|
EXPOSE 5432 |
||||||
|
ENTRYPOINT ["./inicia.sh"] |
@ -0,0 +1,49 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace app\Controllers; |
||||||
|
|
||||||
|
use app\Core\Controller; |
||||||
|
use app\Interfaces\IApiMedia; |
||||||
|
use app\Models\SystemMessage; |
||||||
|
use Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Description of SupervisorController |
||||||
|
* |
||||||
|
* @author root |
||||||
|
*/ |
||||||
|
class SystemMessageController extends Controller |
||||||
|
{ |
||||||
|
/** @var SystemMessage $sysMessage model de mensagens do sistema */ |
||||||
|
protected $sysMessage; |
||||||
|
|
||||||
|
public function __construct() |
||||||
|
{ |
||||||
|
$this->sysMessage = new SystemMessage(); |
||||||
|
} |
||||||
|
public function sendMessageSystem($momento, $variavels, IApiMedia $api, $numero, $fila = null) |
||||||
|
{ //$variavels = [["nome" => '@cliente', "valor" => 'afonso']] |
||||||
|
try { |
||||||
|
$msgs = $this->sysMessage->findMessage($momento, $fila); |
||||||
|
if (empty($msgs)) { |
||||||
|
$msgs = $this->sysMessage->findMessage($momento); |
||||||
|
} |
||||||
|
|
||||||
|
foreach ($msgs as $key => $msg) { |
||||||
|
$msg->texto = str_replace('\n', "\n", $msg->texto); |
||||||
|
if ($variavels) { |
||||||
|
foreach ($variavels as $key => $variavel) { |
||||||
|
$vari = $variavel['nome']; |
||||||
|
$pattern = "/$vari/i"; |
||||||
|
$msg->texto = preg_replace($pattern, utf8_decode($variavel['valor']), $msg->texto); |
||||||
|
} |
||||||
|
} |
||||||
|
$api->enviarMsg($numero, $msg->texto); |
||||||
|
} |
||||||
|
return $msgs; |
||||||
|
} catch (Exception $ex) { |
||||||
|
logger()->error($ex->getMessage()); |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -1,23 +1,24 @@ |
|||||||
<?php |
<?php |
||||||
|
|
||||||
namespace app\Core; |
|
||||||
use app\Providers\Logger; |
|
||||||
|
|
||||||
/** |
namespace app\Core; |
||||||
* Description of Controller |
|
||||||
* |
/** |
||||||
* @author Lucas Awade |
* Description of Controller |
||||||
*/ |
* |
||||||
abstract class Controller { |
* @author Lucas Awade |
||||||
|
*/ |
||||||
const LOGGER_ACTIVE = true; |
abstract class Controller |
||||||
|
{ |
||||||
private $message; |
|
||||||
|
const LOGGER_ACTIVE = true; |
||||||
public function message($message = null){ |
|
||||||
if(!$message){ |
private $message; |
||||||
return $this->message; |
|
||||||
} |
public function message($message = null) |
||||||
$this->message = $message; |
{ |
||||||
|
if (!$message) { |
||||||
|
return $this->message; |
||||||
} |
} |
||||||
} |
$this->message = $message; |
||||||
|
} |
||||||
|
} |
@ -1,174 +0,0 @@ |
|||||||
<?php |
|
||||||
|
|
||||||
namespace app\Core; |
|
||||||
|
|
||||||
use app\Core\Commands; |
|
||||||
use app\Controllers\AgentController; |
|
||||||
use app\Controllers\QueueController; |
|
||||||
use app\Controllers\BilheteController; |
|
||||||
use app\Controllers\ClassificacaoController; |
|
||||||
|
|
||||||
/** |
|
||||||
* Description of Media |
|
||||||
* |
|
||||||
* @author Lucas Awade |
|
||||||
*/ |
|
||||||
class Media |
|
||||||
{ |
|
||||||
|
|
||||||
private $agente; |
|
||||||
private $queue; |
|
||||||
private $bilheteController; |
|
||||||
private $commands; |
|
||||||
private $classificacao; |
|
||||||
public $media; |
|
||||||
|
|
||||||
public function __construct() |
|
||||||
{ |
|
||||||
$this->bilheteController = new BilheteController(); |
|
||||||
$this->agente = new AgentController(); |
|
||||||
$this->queue = new QueueController(); |
|
||||||
$this->classificacao = new ClassificacaoController(); |
|
||||||
$this->commands = new Commands(); |
|
||||||
} |
|
||||||
|
|
||||||
public function selecionaAtendimento($number, $queue = null, $option = null, $media) |
|
||||||
{ |
|
||||||
$atendimento = $this->agente->inService($number); |
|
||||||
|
|
||||||
/** |
|
||||||
* SE POSSUI ATENDIMENTO RETORNA OS DADOS DA CHAMADA |
|
||||||
*/ |
|
||||||
if ($atendimento->origem_destino) { |
|
||||||
$ramal = (($atendimento->phone == 'CLIENT') ? $atendimento->ramal : $atendimento->origem_destino); |
|
||||||
return $this->response(true, ["ramal" => $ramal, "uniqueid" => $atendimento->uniqueid], null); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* VERIFICA SE E UM AGENTE |
|
||||||
*/ |
|
||||||
if ($this->agente->isAgent($number)) { |
|
||||||
return $this->validacaoDoAgente($number, $option); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* VALIDA A ESTRATEGIA USADA NA FILA |
|
||||||
*/ |
|
||||||
$ramal = $this->agente->priority($queue); |
|
||||||
if (!$ramal) { |
|
||||||
$ramal = $this->queue->strategy($queue); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* VALIDA A O ATENDIMENTO DO CLIENTE |
|
||||||
*/ |
|
||||||
return $this->validacaoDoCliente($number, $queue, $ramal, $media); |
|
||||||
} |
|
||||||
|
|
||||||
private function response($status, $data, $message) |
|
||||||
{ |
|
||||||
return array('STATUS' => $status, 'MESSAGE' => $message, 'DATA' => $data); |
|
||||||
} |
|
||||||
|
|
||||||
public function getClientQueueData($number, $atendimentoFila) |
|
||||||
{ |
|
||||||
$clientInQueue = false; |
|
||||||
$queuePosition = 0; |
|
||||||
$clientQueue = ''; |
|
||||||
|
|
||||||
foreach ($atendimentoFila as $clientes) { |
|
||||||
if ($clientes->src == $number) { |
|
||||||
$clientInQueue = true; |
|
||||||
$clientQueue = $clientes->fila; |
|
||||||
break; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
foreach ($atendimentoFila as $clientes) { |
|
||||||
$queuePosition = $queuePosition + 1; |
|
||||||
if ($clientes->src == $number) { |
|
||||||
break; |
|
||||||
} |
|
||||||
} |
|
||||||
return ["IN_QUEUE" => $clientInQueue, "QUEUE_POSITION" => $queuePosition, "CLIENT_QUEUE" => $clientQueue]; |
|
||||||
} |
|
||||||
|
|
||||||
function validacaoDoAgente($number, $option) |
|
||||||
{ |
|
||||||
$agent = $this->agente->getAgente($number); |
|
||||||
|
|
||||||
if (!$agent) { |
|
||||||
$msg = "Faça o login para iniciar o atendimento!\n"; |
|
||||||
return $this->response(false, '', $msg); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* VERIFICA CLASSIFICACAO DE ATENDIMENTO |
|
||||||
*/ |
|
||||||
$chamadaSemClassificacao = $this->classificacao->agentClassificacaoPending($agent->matricula, $agent->dac); |
|
||||||
|
|
||||||
if ($chamadaSemClassificacao) { |
|
||||||
$classificacaoRegisterReturn = $this->classificacao->agentClassificacaoRegister( |
|
||||||
$agent->matricula, |
|
||||||
$agent->dac, |
|
||||||
$chamadaSemClassificacao, |
|
||||||
$option |
|
||||||
); |
|
||||||
if ($classificacaoRegisterReturn) { |
|
||||||
return $this->response(false, '', CONF_NAME_REPONSE . " : " . $this->classificacao->message()); |
|
||||||
} |
|
||||||
|
|
||||||
$classificacaoList = $this->classificacao->agentClassificacaoList($agent->dac); |
|
||||||
return $this->response(false, '', CONF_NAME_REPONSE . " : " . $classificacaoList); |
|
||||||
} |
|
||||||
|
|
||||||
$msg = "Você não pode abrir um atendimento conectado!\n"; |
|
||||||
return $this->response(false, '', $msg); |
|
||||||
} |
|
||||||
|
|
||||||
function validacaoDoCliente($number, $queue, $ramal, $media) |
|
||||||
{ |
|
||||||
|
|
||||||
$atendimentoFila = $this->bilheteController->bilheteForaHorario(CONF_EVENT_WHATSAPP_ESPERA, null, null, $media); |
|
||||||
$clienteFila = $this->getClientQueueData($number, $atendimentoFila); |
|
||||||
|
|
||||||
$clienteEmFila = $clienteFila['IN_QUEUE']; |
|
||||||
$posicaoFila = $clienteFila['QUEUE_POSITION']; |
|
||||||
logger('deburguer')->info(print_r(["media" => $media, "cliente" => $clienteFila, "queue" => $queue], true)); |
|
||||||
if ((!$this->agente->infoAgentes($media, $queue)) && (!$clienteEmFila)) { |
|
||||||
$this->bilheteController->bilheteInQueue($number, '0', '0', 'NO ANSWER', $queue, CONF_EVENT_WHATSAPP_ESPERA, 'null', null, $media); |
|
||||||
$msg = 'Não temos nenhum atendente disponível no momento, iremos lhe atender assim que um atendente estiver disponível!'; |
|
||||||
return $this->response(false, '', $msg); |
|
||||||
} |
|
||||||
|
|
||||||
if (($clienteEmFila) && ($clienteFila['CLIENT_QUEUE'] != $queue)) { |
|
||||||
$msg = 'Você está na posição ' . $posicaoFila . ' da fila ' . $clienteFila['CLIENT_QUEUE'] . '. Aguarde ser atendido!'; |
|
||||||
return $this->response(false, '', $msg); |
|
||||||
} |
|
||||||
|
|
||||||
if ((!$this->agente->infoAgentes($media, $queue)) && ($clienteEmFila)) { //CLIENTE EM FILA MAS NENHUM ATENDENTE LOGADO |
|
||||||
$msg = 'Não temos nenhum atendente disponível no momento, iremos lhe atender assim que um atendente estiver disponível!'; |
|
||||||
return $this->response(false, '', $msg); |
|
||||||
} |
|
||||||
|
|
||||||
$agent = $this->agente->getAgente($ramal); |
|
||||||
$chamadaSemClassificacao = $this->classificacao->agentClassificacaoPending($agent->matricula, $agent->dac); |
|
||||||
|
|
||||||
if ((!$ramal) || ($chamadaSemClassificacao)) { |
|
||||||
if (!$clienteEmFila) { |
|
||||||
$this->bilheteController->bilheteInQueue($number, '0', '0', 'NO ANSWER', $queue, CONF_EVENT_WHATSAPP_ESPERA, 'null', null, $media); |
|
||||||
} |
|
||||||
$atendimentoFila = $this->bilheteController->bilheteForaHorario(CONF_EVENT_WHATSAPP_ESPERA, $queue, null, null, $media); |
|
||||||
$posicaoFila = count($atendimentoFila); |
|
||||||
$msg = "Nossos atendentes estão ocupados, por favor aguarde que iremos lhe atender! Você está na posição *$posicaoFila*."; |
|
||||||
return $this->response(false, '', $msg); |
|
||||||
} |
|
||||||
|
|
||||||
$uniqueid = $this->agente->openService($ramal, $number); |
|
||||||
$protocol = $this->bilheteController->generateProtocol($uniqueid); |
|
||||||
$this->bilheteController->tempoEsperaSupervisor($uniqueid); |
|
||||||
$msg = "Atendimento iniciado!\n"; |
|
||||||
$msg .= "Número do protocolo do atendimento é $protocol\n"; |
|
||||||
return $this->response(true, ["ramal" => $ramal, "uniqueid" => $uniqueid, "protocol" => $protocol, "apelido" => $agent->nome], $msg); |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,9 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace app\Interfaces; |
||||||
|
|
||||||
|
interface IApi |
||||||
|
{ |
||||||
|
function router($rota, $request); |
||||||
|
function retorno($mensagem, $status = null, $dados = null); |
||||||
|
} |
@ -0,0 +1,38 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace app\Middleware; |
||||||
|
|
||||||
|
use app\Interfaces\IApi; |
||||||
|
|
||||||
|
|
||||||
|
class ApiInfo implements IApi |
||||||
|
{ |
||||||
|
function router($rota, $request) |
||||||
|
{ |
||||||
|
$this->showConf(); |
||||||
|
} |
||||||
|
function retorno($mensagem, $status = null, $dados = null) |
||||||
|
{ |
||||||
|
//{ "status": "success", "message": "register created!", "data": [ "id": 20 ] } |
||||||
|
$data = []; |
||||||
|
$data['message'] = utf8_encode($mensagem); |
||||||
|
|
||||||
|
if (!empty($status)) { |
||||||
|
$data['status'] = "success"; |
||||||
|
} else { |
||||||
|
$data['status'] = "error"; |
||||||
|
} |
||||||
|
if (!empty($dados)) { |
||||||
|
$data['data'] = $dados; |
||||||
|
} |
||||||
|
echo json_encode($data); |
||||||
|
} |
||||||
|
|
||||||
|
function showConf() |
||||||
|
{ |
||||||
|
$dados['version_system'] = INFO_VERSION_SYSTEM; |
||||||
|
$dados['conf_db_host'] = CONF_DB_HOST; |
||||||
|
$dados['conf_db_port'] = CONF_DB_PORT; |
||||||
|
$this->retorno('Sucesso', "success", [$dados]); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,64 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace app\Middleware; |
||||||
|
|
||||||
|
use app\Interfaces\IApi; |
||||||
|
use app\Models\SupervisorModel; |
||||||
|
|
||||||
|
|
||||||
|
class ApiSupervisor implements IApi |
||||||
|
{ |
||||||
|
/** @var SupervisorModel $supervisor model de supervisor */ |
||||||
|
protected $supervisor; |
||||||
|
|
||||||
|
public function __construct() |
||||||
|
{ |
||||||
|
$this->supervisor = new SupervisorModel(); |
||||||
|
} |
||||||
|
|
||||||
|
function router($rota, $request) |
||||||
|
{ |
||||||
|
switch ($rota) { |
||||||
|
case 'listarAgentesDisponivel': |
||||||
|
$this->listaAgentesDisponivel(); |
||||||
|
break; |
||||||
|
default: |
||||||
|
echo json_encode(['status' => '404']); |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
function listaAgentesDisponivel() |
||||||
|
{ |
||||||
|
try { |
||||||
|
$ret = $this->supervisor->listaAgentesDisponivel(); |
||||||
|
$agentes = []; |
||||||
|
foreach ($ret as $key => $value) { |
||||||
|
array_push($agentes, $value); |
||||||
|
} |
||||||
|
$this->retorno( |
||||||
|
$agentes ? "Sucesso" : "Nenhum agente disponivel", |
||||||
|
$agentes ? $agentes : null, |
||||||
|
$agentes ? $agentes : null |
||||||
|
); |
||||||
|
} catch (\Exception $th) { |
||||||
|
$this->retorno($th->getMessage()); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
function retorno($mensagem, $status = null, $dados = null) |
||||||
|
{ |
||||||
|
//{ "status": "success", "message": "register created!", "data": [ "id": 20 ] } |
||||||
|
$data = []; |
||||||
|
$data['message'] = utf8_encode($mensagem); |
||||||
|
if (!empty($status)) { |
||||||
|
$data['status'] = "success"; |
||||||
|
} else { |
||||||
|
$data['status'] = "error"; |
||||||
|
} |
||||||
|
if (!empty($dados)) { |
||||||
|
$data['data'] = $dados; |
||||||
|
} |
||||||
|
echo json_encode($data); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,182 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace app\Models; |
||||||
|
|
||||||
|
use app\Core\Connect; |
||||||
|
use app\Core\Model; |
||||||
|
|
||||||
|
class Atendimento extends Model |
||||||
|
{ |
||||||
|
private $evento = 'md_evento'; |
||||||
|
private $atendimento = 'md_atendimento'; |
||||||
|
|
||||||
|
public function getAtendimentoByCliente($cliente_id, $evento = 'EMESPERA') |
||||||
|
{ |
||||||
|
$this->query = "SELECT ma.*, me.fila as fila FROM {$this->atendimento} ma |
||||||
|
INNER JOIN {$this->evento} me |
||||||
|
ON ma.uniqueid = me.uniqueid |
||||||
|
WHERE ma.cliente_id = :cliente_id |
||||||
|
AND (SELECT m2.evento FROM md_evento m2 WHERE ma.uniqueid = m2.uniqueid ORDER BY id DESC LIMIT 1) = :evento"; |
||||||
|
return $this->read($this->query, ['cliente_id' => $cliente_id, 'evento' => $evento])->fetch(); |
||||||
|
} |
||||||
|
|
||||||
|
public function getStatusAtendimento($uniqueid) |
||||||
|
{ |
||||||
|
$this->query = "SELECT evento FROM md_evento WHERE uniqueid = :uniqueid ORDER BY id DESC LIMIT 1"; |
||||||
|
return $this->read($this->query, ['uniqueid' => $uniqueid])->fetch(); |
||||||
|
} |
||||||
|
|
||||||
|
public function findAtendId($uniqueid) |
||||||
|
{ |
||||||
|
$this->query = "SELECT ma.*, me.fila as fila FROM {$this->atendimento} ma |
||||||
|
INNER JOIN {$this->evento} me |
||||||
|
ON ma.uniqueid = me.uniqueid |
||||||
|
WHERE ma.uniqueid = :uniqueid "; |
||||||
|
return $this->read($this->query, ['uniqueid' => $uniqueid])->fetch(); |
||||||
|
} |
||||||
|
|
||||||
|
public function getAtendimentoByEvento($fila, $evento = 'EMESPERA') |
||||||
|
{ |
||||||
|
$this->query = "SELECT ma.* FROM {$this->atendimento} ma |
||||||
|
INNER JOIN {$this->evento} me |
||||||
|
ON ma.uniqueid = me.uniqueid |
||||||
|
WHERE (SELECT m2.evento FROM md_evento m2 WHERE ma.uniqueid = m2.uniqueid ORDER BY id DESC LIMIT 1) = :evento |
||||||
|
AND me.fila = :fila"; |
||||||
|
return $this->read($this->query, ['evento' => $evento, 'fila' => $fila])->fetchAll(); |
||||||
|
} |
||||||
|
|
||||||
|
public function findAtendAgent($matricula, $quantidade = 10) |
||||||
|
{ |
||||||
|
$data = []; |
||||||
|
$this->query = "SELECT ma.*, |
||||||
|
ma.nome AS profile_name, |
||||||
|
ppr.protocolo as protocolo, |
||||||
|
(SELECT m2.evento FROM md_evento m2 WHERE ma.uniqueid = m2.uniqueid ORDER BY id DESC LIMIT 1) AS evento, |
||||||
|
CASE |
||||||
|
WHEN (SELECT m2.evento FROM md_evento m2 WHERE ma.uniqueid = m2.uniqueid ORDER BY id DESC LIMIT 1) = 'START' THEN 1 |
||||||
|
ELSE 0 |
||||||
|
END AS status |
||||||
|
FROM {$this->atendimento} ma |
||||||
|
INNER JOIN pbx_protocolo_reg ppr ON ma.uniqueid = ppr.uniqueid "; |
||||||
|
if ($matricula) { |
||||||
|
$this->query .= " WHERE ma.matricula = :matricula "; |
||||||
|
$data['matricula'] = $matricula; |
||||||
|
} |
||||||
|
if (empty($quantidade)) { |
||||||
|
$data['quantidade'] = 10; |
||||||
|
} else { |
||||||
|
$data['quantidade'] = $quantidade; |
||||||
|
} |
||||||
|
|
||||||
|
$this->query .= " ORDER BY status DESC, data_reg DESC |
||||||
|
LIMIT :quantidade "; |
||||||
|
|
||||||
|
return $this->read($this->query, $data)->fetchAll(); |
||||||
|
} |
||||||
|
|
||||||
|
public function findAtenEmAberto($cliente_id = null) |
||||||
|
{ |
||||||
|
$this->query = "SELECT ma.* FROM {$this->atendimento} ma |
||||||
|
WHERE (SELECT m2.evento FROM md_evento m2 WHERE ma.uniqueid = m2.uniqueid ORDER BY id DESC LIMIT 1) = 'START' |
||||||
|
AND ma.matricula notnull "; |
||||||
|
$data = []; |
||||||
|
if ($cliente_id) { |
||||||
|
$data['cliente_id'] = $cliente_id; |
||||||
|
$this->query .= 'AND ma.cliente_id = :cliente_id'; |
||||||
|
return $this->read($this->query, $data)->fetch(); |
||||||
|
} |
||||||
|
return $this->read($this->query, $data)->fetchAll(); |
||||||
|
} |
||||||
|
|
||||||
|
public function getAtendimentoAbertoByAgente($matricula) |
||||||
|
{ |
||||||
|
$this->query = "SELECT ma.* FROM {$this->atendimento} ma |
||||||
|
WHERE (SELECT m2.evento FROM md_evento m2 WHERE ma.uniqueid = m2.uniqueid ORDER BY id DESC LIMIT 1) = 'START' |
||||||
|
AND ma.matricula = :matricula "; |
||||||
|
return $this->read($this->query, ['matricula' => $matricula])->fetchAll(); |
||||||
|
} |
||||||
|
|
||||||
|
// public function getAtendFila($fila, $evento = 'LOST_CONNECTION') |
||||||
|
// { |
||||||
|
// $this->query = "SELECT ma.*, me.fila as fila FROM {$this->atendimento} ma |
||||||
|
// INNER JOIN {$this->evento} me |
||||||
|
// ON ma.uniqueid = me.uniqueid |
||||||
|
// WHERE me.evento = :evento |
||||||
|
// AND me.fila = :fila |
||||||
|
// AND (SELECT m2.evento FROM md_evento m2 WHERE ma.uniqueid = m2.uniqueid ORDER BY id DESC LIMIT 1) = 'LOST_CONNECTION' "; |
||||||
|
// return $this->read($this->query, ['evento' => $evento, 'fila' => $fila])->fetchAll(); |
||||||
|
// } |
||||||
|
public function getAtendFila($fila) |
||||||
|
{ |
||||||
|
$this->query = "SELECT ma.*, me.fila as fila FROM {$this->atendimento} ma |
||||||
|
INNER JOIN {$this->evento} me |
||||||
|
ON ma.uniqueid = me.uniqueid |
||||||
|
AND me.evento IN('EMESPERA', 'LOST_CONNECTION') |
||||||
|
WHERE me.fila = :fila |
||||||
|
AND (SELECT m2.evento FROM md_evento m2 WHERE ma.uniqueid = m2.uniqueid ORDER BY id DESC LIMIT 1) IN('EMESPERA', 'LOST_CONNECTION') "; |
||||||
|
return $this->read($this->query, ['fila' => $fila])->fetchAll(); |
||||||
|
} |
||||||
|
|
||||||
|
public function getAtendAbandonado($fila = null) |
||||||
|
{ |
||||||
|
$data = []; |
||||||
|
$this->query = "SELECT ma.*, me.fila as fila FROM {$this->atendimento} ma |
||||||
|
INNER JOIN {$this->evento} me |
||||||
|
ON ma.uniqueid = me.uniqueid |
||||||
|
AND me.evento = 'ABANDON' |
||||||
|
WHERE (SELECT m2.evento FROM md_evento m2 WHERE ma.uniqueid = m2.uniqueid ORDER BY id DESC LIMIT 1) = 'ABANDON' |
||||||
|
AND ma.data_reg >= CURRENT_DATE "; |
||||||
|
if ($fila) { |
||||||
|
$this->query .= ' AND me.fila = :fila'; |
||||||
|
$data['fila'] = $fila; |
||||||
|
} |
||||||
|
return $this->read($this->query, $data)->fetchAll(); |
||||||
|
} |
||||||
|
|
||||||
|
public function createAtendimento($matricula, $cliente_id, $direcao, $context, $nome) |
||||||
|
{ |
||||||
|
$unique = uniqid('', true); |
||||||
|
$this->query = "INSERT INTO {$this->atendimento} ( |
||||||
|
matricula, |
||||||
|
cliente_id, |
||||||
|
direcao, |
||||||
|
uniqueid, |
||||||
|
context, |
||||||
|
nome) |
||||||
|
VALUES( |
||||||
|
:matricula, |
||||||
|
:cliente_id, |
||||||
|
:direcao, |
||||||
|
:uniqueid, |
||||||
|
:context, |
||||||
|
:nome);"; |
||||||
|
|
||||||
|
$data['uniqueid'] = $unique; |
||||||
|
$data['matricula'] = $matricula; |
||||||
|
$data['cliente_id'] = $cliente_id; |
||||||
|
$data['direcao'] = $direcao; |
||||||
|
$data['context'] = $context; |
||||||
|
$data['nome'] = $nome; |
||||||
|
|
||||||
|
$return = $this->create($this->query, $data); |
||||||
|
if ($return) { |
||||||
|
return $unique; |
||||||
|
} |
||||||
|
|
||||||
|
return $return; |
||||||
|
} |
||||||
|
|
||||||
|
public function updAtendimento($uniqueid, $matricula) |
||||||
|
{ |
||||||
|
$this->query = "UPDATE {$this->atendimento} SET matricula = :matricula WHERE uniqueid = :uniqueid;"; |
||||||
|
$data['matricula'] = $matricula; |
||||||
|
$data['uniqueid'] = $uniqueid; |
||||||
|
return $this->update($this->query, $data); |
||||||
|
} |
||||||
|
|
||||||
|
public function getQuantiAtendimentSimultaneos() |
||||||
|
{ |
||||||
|
$this->query = "SELECT prm_media_simultaneo FROM pbx_parametros LIMIT 1"; |
||||||
|
return $this->read($this->query)->fetch(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,50 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace app\Models; |
||||||
|
|
||||||
|
use app\Core\Model; |
||||||
|
|
||||||
|
class Evento extends Model |
||||||
|
{ |
||||||
|
private $evento = 'md_evento'; |
||||||
|
|
||||||
|
public function createEvento($uniqueid, $evento, $data_evento, $data_reg, $fila = null, $matricula = null) |
||||||
|
{ |
||||||
|
$this->query = "INSERT INTO {$this->evento} (uniqueid, |
||||||
|
evento, |
||||||
|
data_evento, |
||||||
|
data_reg, |
||||||
|
fila, |
||||||
|
matricula ) |
||||||
|
VALUES(:uniqueid, |
||||||
|
:evento, |
||||||
|
:data_evento, |
||||||
|
:data_reg, |
||||||
|
:fila, |
||||||
|
:matricula );"; |
||||||
|
|
||||||
|
$data['uniqueid'] = $uniqueid; |
||||||
|
$data['evento'] = $evento; |
||||||
|
$data['data_evento'] = $data_evento; |
||||||
|
$data['data_reg'] = $data_reg; |
||||||
|
$data['fila'] = $fila; |
||||||
|
$data['matricula'] = $matricula; |
||||||
|
|
||||||
|
$return = $this->create($this->query, $data); |
||||||
|
return $return; |
||||||
|
} |
||||||
|
|
||||||
|
public function findEventFinish($uniqueid) |
||||||
|
{ |
||||||
|
$this->query = "SELECT * FROM {$this->evento} |
||||||
|
WHERE uniqueid = :uniqueid |
||||||
|
AND evento in ('COMPLETE_AGENT', 'COMPLETE_AGENT');"; |
||||||
|
return $this->read($this->query, ['uniqueid' => $uniqueid])->fetch(); |
||||||
|
} |
||||||
|
|
||||||
|
public function getStatusAtendimento($uniqueid) |
||||||
|
{ |
||||||
|
$this->query = "SELECT evento FROM {$this->evento} WHERE uniqueid = :uniqueid ORDER BY id DESC LIMIT 1"; |
||||||
|
return $this->read($this->query, ['uniqueid' => $uniqueid])->fetch(); |
||||||
|
} |
||||||
|
} |
@ -1,19 +1,22 @@ |
|||||||
<?php |
<?php |
||||||
|
|
||||||
namespace app\Models; |
namespace app\Models; |
||||||
use app\Core\Model; |
|
||||||
|
|
||||||
/** |
use app\Core\Model; |
||||||
* Description of EventQueue |
|
||||||
* |
|
||||||
* @author root |
|
||||||
*/ |
|
||||||
class Parametros extends Model { |
|
||||||
|
|
||||||
const TABLE = 'pbx_parametros'; |
/** |
||||||
|
* Description of EventQueue |
||||||
|
* |
||||||
|
* @author root |
||||||
|
*/ |
||||||
|
class Parametros extends Model |
||||||
|
{ |
||||||
|
|
||||||
public function findProtocolByParams($uniqueid){ |
const TABLE = 'pbx_parametros'; |
||||||
$this->query = "SELECT prm_agente_proto, prm_use_proto_parceiro FROM " . self::TABLE . " WHERE id = :id;"; |
|
||||||
return $this->read($this->query, ['id' => 1])->fetch(); |
public function findProtocolByParams() |
||||||
} |
{ |
||||||
} |
$this->query = "SELECT prm_agente_proto, prm_use_proto_parceiro, prm_pausa_grupo, prm_media_simultaneo FROM " . self::TABLE . " WHERE id = :id;"; |
||||||
|
return $this->read($this->query, ['id' => 1])->fetch(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,408 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace app\Models; |
||||||
|
|
||||||
|
use app\Core\Model; |
||||||
|
|
||||||
|
class SupervisorModel extends Model |
||||||
|
{ |
||||||
|
|
||||||
|
const USUARIOS = "pbx_usuarios"; |
||||||
|
const SUPERVISOR_AGENTE = "md_supervisor"; |
||||||
|
const EVENTO_AGENTE = 'pbx_eventos_agentes'; |
||||||
|
const BILHETE = 'pbx_bilhetes'; |
||||||
|
const EVENTOS_DACS = 'pbx_eventos_dacs'; |
||||||
|
|
||||||
|
private $supervisor = 'md_supervisor'; |
||||||
|
private $atendimento = 'md_atendimento'; |
||||||
|
|
||||||
|
public function listaAgentesDisponivel($status = null, $somenteLivre = true) |
||||||
|
{ |
||||||
|
$data = []; |
||||||
|
$this->query = " SELECT *, |
||||||
|
( |
||||||
|
SELECT |
||||||
|
count(*) |
||||||
|
FROM |
||||||
|
md_atendimento ma |
||||||
|
WHERE 'START' = (SELECT m2.evento FROM md_evento m2 |
||||||
|
WHERE ma.uniqueid = m2.uniqueid |
||||||
|
ORDER BY m2.id DESC LIMIT 1) |
||||||
|
AND ma.matricula = ms.matricula |
||||||
|
|
||||||
|
) AS countAtendimentos, |
||||||
|
( |
||||||
|
SELECT |
||||||
|
count(*) |
||||||
|
FROM |
||||||
|
md_atendimento ma |
||||||
|
WHERE ma.data_reg >= current_date |
||||||
|
AND ma.matricula = ms.matricula |
||||||
|
) AS numero_atendimento_dia |
||||||
|
|
||||||
|
FROM md_supervisor ms |
||||||
|
WHERE 1=1 |
||||||
|
"; |
||||||
|
if ($somenteLivre) { |
||||||
|
$this->query .= " AND ( |
||||||
|
SELECT |
||||||
|
count(*) |
||||||
|
FROM |
||||||
|
md_atendimento ma |
||||||
|
WHERE 'START' = (SELECT m2.evento FROM md_evento m2 |
||||||
|
WHERE ma.uniqueid = m2.uniqueid |
||||||
|
ORDER BY m2.id DESC LIMIT 1) |
||||||
|
AND ma.matricula = ms.matricula |
||||||
|
|
||||||
|
) < (SELECT prm_media_simultaneo FROM pbx_parametros pp LIMIT 1 )"; |
||||||
|
} |
||||||
|
if ($status) { |
||||||
|
$this->query .= " AND ms.status = :status "; |
||||||
|
$data['status'] = $status; |
||||||
|
} |
||||||
|
$this->query .= " ORDER BY countAtendimentos "; |
||||||
|
return $this->read($this->query, $data)->fetchAll(); |
||||||
|
} |
||||||
|
|
||||||
|
public function statusAgente($matricula) |
||||||
|
{ |
||||||
|
$this->query = "SELECT |
||||||
|
*, |
||||||
|
( |
||||||
|
SELECT |
||||||
|
count(*) |
||||||
|
FROM |
||||||
|
md_atendimento ma |
||||||
|
WHERE 'START' = (SELECT m2.evento FROM md_evento m2 |
||||||
|
WHERE ma.uniqueid = m2.uniqueid |
||||||
|
ORDER BY m2.id DESC LIMIT 1) |
||||||
|
AND ma.matricula = ms.matricula |
||||||
|
) AS numero_atendimento |
||||||
|
FROM |
||||||
|
md_supervisor ms |
||||||
|
WHERE ms.matricula = :matricula "; |
||||||
|
|
||||||
|
return $this->read($this->query, ['matricula' => $matricula])->fetch(); |
||||||
|
} |
||||||
|
|
||||||
|
public function findByMatricula($matricula) |
||||||
|
{ |
||||||
|
//Codigo acrescentado para não permitir logar o agente no chat e pabx simultaneamente. |
||||||
|
$this->query = "SELECT matricula from ( SELECT matricula FROM " . self::SUPERVISOR_AGENTE |
||||||
|
. " UNION " |
||||||
|
. " SELECT matricula FROM pbx_supervisor_agentes ) AS agt WHERE (matricula = :matricula)"; |
||||||
|
return $this->read($this->query, ['matricula' => $matricula])->fetch(); |
||||||
|
} |
||||||
|
|
||||||
|
public function findAllAgentes($queue = null) |
||||||
|
{ |
||||||
|
|
||||||
|
$data = []; |
||||||
|
$this->query = "SELECT * FROM " . self::SUPERVISOR_AGENTE . " WHERE 1=1 "; |
||||||
|
if ($queue) { |
||||||
|
$this->query .= " AND fila = :queue "; |
||||||
|
$data['queue'] = $queue; |
||||||
|
} |
||||||
|
return $this->read($this->query, $data)->fetchAll(); |
||||||
|
} |
||||||
|
|
||||||
|
public function findAllAgentesPBX($queue = null, $media = null) |
||||||
|
{ |
||||||
|
|
||||||
|
$data = []; |
||||||
|
$this->query = "SELECT * FROM pbx_supervisor_agentes WHERE 1=1 "; |
||||||
|
if ($queue) { |
||||||
|
$this->query .= " AND fila = :queue "; |
||||||
|
$data['queue'] = $queue; |
||||||
|
} |
||||||
|
|
||||||
|
if($media){ |
||||||
|
$this->query .= " AND media <> :media"; |
||||||
|
$data['media'] = $media; |
||||||
|
} |
||||||
|
return $this->read($this->query, $data)->fetchAll(); |
||||||
|
} |
||||||
|
|
||||||
|
public function findByAgent($matricula) |
||||||
|
{ |
||||||
|
$this->query = "SELECT * FROM " . self::USUARIOS . " WHERE matricula = :matricula;"; |
||||||
|
return $this->read($this->query, ['matricula' => $matricula])->fetch(); |
||||||
|
} |
||||||
|
|
||||||
|
public function findAgentByRamal($ramal) |
||||||
|
{ |
||||||
|
$this->query = "SELECT * FROM " . self::SUPERVISOR_AGENTE . " WHERE ramal = :ramal;"; |
||||||
|
return $this->read($this->query, ['ramal' => $ramal])->fetch(); |
||||||
|
} |
||||||
|
|
||||||
|
public function findAgentByMatricula($matricula) |
||||||
|
{ |
||||||
|
$this->query = "SELECT * FROM " . self::SUPERVISOR_AGENTE . " WHERE matricula = :matricula;"; |
||||||
|
return $this->read($this->query, ['matricula' => $matricula])->fetch(); |
||||||
|
} |
||||||
|
|
||||||
|
public function findAgentByMatriculaPbx($matricula) |
||||||
|
{ |
||||||
|
$this->query = "SELECT * FROM pbx_supervisor_agentes WHERE matricula = :matricula;"; |
||||||
|
return $this->read($this->query, ['matricula' => $matricula])->fetch(); |
||||||
|
} |
||||||
|
|
||||||
|
public function findAgentByQueue($queue, $status) |
||||||
|
{ |
||||||
|
$data = []; |
||||||
|
$this->query = "SELECT * |
||||||
|
FROM md_supervisor ms |
||||||
|
WHERE ms.fila = :queue |
||||||
|
AND ms.status = :status |
||||||
|
ORDER BY ( |
||||||
|
SELECT |
||||||
|
count(*) |
||||||
|
FROM |
||||||
|
md_atendimento ma |
||||||
|
WHERE 'START' = (SELECT m2.evento FROM md_evento m2 |
||||||
|
WHERE ma.uniqueid = m2.uniqueid |
||||||
|
ORDER BY m2.id DESC LIMIT 1) |
||||||
|
AND ma.matricula = ms.matricula |
||||||
|
) |
||||||
|
"; |
||||||
|
|
||||||
|
$data['queue'] = $queue; |
||||||
|
$data['status'] = $status; |
||||||
|
return $this->read($this->query, $data)->fetchAll(); |
||||||
|
} |
||||||
|
|
||||||
|
######################################## |
||||||
|
### SUPERVISOR AGENTE ### |
||||||
|
######################################## |
||||||
|
|
||||||
|
public function addAgent($matricula, $fila, $nome, $chamada_classificado = 1) |
||||||
|
{ |
||||||
|
$this->query = "INSERT INTO " . self::SUPERVISOR_AGENTE . " |
||||||
|
( |
||||||
|
matricula, |
||||||
|
tempo_login, |
||||||
|
fila, |
||||||
|
status, |
||||||
|
duracao, |
||||||
|
chamada_classificado, |
||||||
|
nome |
||||||
|
) |
||||||
|
VALUES( |
||||||
|
:matricula, |
||||||
|
:tempo_login, |
||||||
|
:fila, |
||||||
|
:status, |
||||||
|
:duracao, |
||||||
|
:chamada_classificado, |
||||||
|
:nome |
||||||
|
);"; |
||||||
|
|
||||||
|
return $this->create($this->query, [ |
||||||
|
'matricula' => $matricula, |
||||||
|
'tempo_login' => 'now()', |
||||||
|
'fila' => $fila, |
||||||
|
'status' => 'LIVRE', |
||||||
|
'duracao' => 'now()', |
||||||
|
'nome' => $nome, |
||||||
|
'chamada_classificado' => $chamada_classificado |
||||||
|
]); |
||||||
|
} |
||||||
|
|
||||||
|
public function addAgent2( |
||||||
|
$nome, |
||||||
|
$matricula, |
||||||
|
$ramal, |
||||||
|
$dac, |
||||||
|
$tempo_login, |
||||||
|
$status = 'LIVRE', |
||||||
|
$motivoPausa = null, |
||||||
|
$origemDestino = null, |
||||||
|
$media = 1, |
||||||
|
$modo_atendimento = 'Automatico', |
||||||
|
$chamada_classificado = 1 |
||||||
|
) { |
||||||
|
$data = []; |
||||||
|
$this->query = "INSERT INTO pbx_supervisor_agentes ( |
||||||
|
tempo_login, |
||||||
|
nome, |
||||||
|
ramal, |
||||||
|
matricula, |
||||||
|
origem_destino, |
||||||
|
status, |
||||||
|
motivo_pausa, |
||||||
|
chamada_classificado, |
||||||
|
modo_atendimento, |
||||||
|
dac, |
||||||
|
duracao, |
||||||
|
logado, |
||||||
|
media) VALUES( |
||||||
|
:tempo_login, |
||||||
|
:nome, |
||||||
|
:ramal, |
||||||
|
:matricula, |
||||||
|
:origem_destino, |
||||||
|
:status, |
||||||
|
:motivo_pausa, |
||||||
|
:chamada_classificado, |
||||||
|
:modo_atendimento, |
||||||
|
:dac, |
||||||
|
:duracao, |
||||||
|
:logado, |
||||||
|
:media) "; |
||||||
|
$data['tempo_login'] = $tempo_login; |
||||||
|
$data['nome'] = $nome; |
||||||
|
$data['matricula'] = $matricula; |
||||||
|
$data['ramal'] = $ramal; |
||||||
|
$data['duracao'] = 'now()'; |
||||||
|
$data['logado'] = 'now()'; |
||||||
|
$data['dac'] = $dac; |
||||||
|
$data['origem_destino'] = $origemDestino; |
||||||
|
$data['status'] = $status; |
||||||
|
$data['motivo_pausa'] = $motivoPausa; |
||||||
|
$data['media'] = $media; |
||||||
|
$data['modo_atendimento'] = $modo_atendimento; |
||||||
|
$data['chamada_classificado'] = ($chamada_classificado ? '1' : '0'); |
||||||
|
return $this->create($this->query, $data); |
||||||
|
} |
||||||
|
|
||||||
|
public function updateAgent( |
||||||
|
$matricula, |
||||||
|
$status = 'LIVRE', |
||||||
|
$motivo_pausa = null |
||||||
|
) { |
||||||
|
$this->query = "UPDATE {$this->supervisor} SET status = :status, motivo_pausa = :motivo_pausa, duracao = :duracao"; |
||||||
|
$this->query .= " WHERE matricula = :matricula"; |
||||||
|
$data = []; |
||||||
|
$data['status'] = $status; |
||||||
|
$data['motivo_pausa'] = $motivo_pausa; |
||||||
|
$data['matricula'] = $matricula; |
||||||
|
$data['duracao'] = 'now()'; |
||||||
|
// logger('teste')->debug(print_r($data, true), true); |
||||||
|
return $this->update($this->query, $data); |
||||||
|
} |
||||||
|
|
||||||
|
public function updateAgent2( |
||||||
|
$matricula, |
||||||
|
$ramal, |
||||||
|
$dac, |
||||||
|
$status = 'LIVRE', |
||||||
|
$atualizaDuracao = false, |
||||||
|
$motivoPausa = null, |
||||||
|
$origemDestino = null, |
||||||
|
$disponivel_atendimento = 1 |
||||||
|
) { |
||||||
|
$data = []; |
||||||
|
$this->query = "UPDATE pbx_supervisor_agentes SET |
||||||
|
origem_destino = :origem_destino, |
||||||
|
status = :status, |
||||||
|
motivo_pausa = :motivo_pausa, |
||||||
|
dac = :dac, |
||||||
|
ramal = :ramal, |
||||||
|
logado = :logado, |
||||||
|
disponivel_atendimento = :disponivel_atendimento "; |
||||||
|
if ($atualizaDuracao) { |
||||||
|
$data['duracao'] = 'now()'; |
||||||
|
$this->query .= " , duracao = :duracao"; |
||||||
|
} |
||||||
|
$this->query .= " WHERE matricula = :matricula"; |
||||||
|
$data['matricula'] = $matricula; |
||||||
|
$data['ramal'] = $ramal; |
||||||
|
$data['dac'] = $dac; |
||||||
|
$data['origem_destino'] = $origemDestino; |
||||||
|
$data['status'] = $status; |
||||||
|
$data['logado'] = 'now()'; |
||||||
|
$data['motivo_pausa'] = $motivoPausa; |
||||||
|
$data['disponivel_atendimento'] = $disponivel_atendimento; |
||||||
|
return $this->update($this->query, $data); |
||||||
|
} |
||||||
|
|
||||||
|
public function updateRefreshAgent($matricula, $ramal, $duracao = false) |
||||||
|
{ |
||||||
|
$data = []; |
||||||
|
$this->query = "UPDATE " . self::SUPERVISOR_AGENTE . " SET logado = :logado "; |
||||||
|
if ($duracao) { |
||||||
|
$this->query .= ", duracao = :duracao "; |
||||||
|
$data['duracao'] = 'now()'; |
||||||
|
} |
||||||
|
$this->query .= " WHERE matricula = :matricula AND ramal = :ramal;"; |
||||||
|
|
||||||
|
$data['logado'] = 'now()'; |
||||||
|
$data['matricula'] = $matricula; |
||||||
|
$data['ramal'] = $ramal; |
||||||
|
return $this->update($this->query, $data); |
||||||
|
} |
||||||
|
|
||||||
|
public function updateSala2Agent($matricula, $ramal, $sala2 = null) |
||||||
|
{ |
||||||
|
$data = []; |
||||||
|
$this->query = "UPDATE " . self::SUPERVISOR_AGENTE . " SET sala_2 = :sala_2 WHERE matricula = :matricula AND ramal = :ramal;"; |
||||||
|
$data['sala_2'] = $sala2; |
||||||
|
$data['matricula'] = $matricula; |
||||||
|
$data['ramal'] = $ramal; |
||||||
|
return $this->update($this->query, $data); |
||||||
|
} |
||||||
|
|
||||||
|
public function deleteAgentPbx($matricula, $media = null, $oper = '=') |
||||||
|
{ |
||||||
|
$data = []; |
||||||
|
$this->query = "DELETE FROM pbx_supervisor_agentes WHERE matricula = :matricula "; |
||||||
|
if($media){ |
||||||
|
$this->query .= "AND media {$oper} :media "; |
||||||
|
$data['media'] = $media; |
||||||
|
} |
||||||
|
$data['matricula'] = $matricula; |
||||||
|
return $this->delete($this->query, $data); |
||||||
|
} |
||||||
|
|
||||||
|
public function deleteAgent($matricula) |
||||||
|
{ |
||||||
|
$data = []; |
||||||
|
$this->query = "DELETE FROM " . self::SUPERVISOR_AGENTE . " WHERE matricula = :matricula"; |
||||||
|
$data['matricula'] = $matricula; |
||||||
|
return $this->delete($this->query, $data); |
||||||
|
} |
||||||
|
|
||||||
|
public function updateLogadoAll($media = null) |
||||||
|
{ |
||||||
|
$data = []; |
||||||
|
$this->query = "UPDATE " . self::SUPERVISOR_AGENTE . " SET logado = :logado "; |
||||||
|
if ($media) { |
||||||
|
$this->query .= " WHERE sala_1 = :sala_1; "; |
||||||
|
} |
||||||
|
$data['logado'] = 'now()'; |
||||||
|
$data['sala_1'] = $media; |
||||||
|
return $this->update($this->query, $data); |
||||||
|
} |
||||||
|
|
||||||
|
######################################## |
||||||
|
### EVENTOS ### |
||||||
|
######################################## |
||||||
|
|
||||||
|
public function addEventoLoginAgent($matricula, $idDac, $flag = 1, $ramal) |
||||||
|
{ |
||||||
|
$data = []; |
||||||
|
$this->query = "INSERT INTO " . self::EVENTO_AGENTE . "(matricula, login, logoff, id_dac, flag, ramal) VALUES(:matricula, :login, :logoff, :id_dac, :flag, :ramal) "; |
||||||
|
$data['matricula'] = $matricula; |
||||||
|
$data['login'] = 'now()'; |
||||||
|
$data['logoff'] = 'now()'; |
||||||
|
$data['id_dac'] = $idDac; |
||||||
|
$data['flag'] = $flag; |
||||||
|
$data['ramal'] = $ramal; |
||||||
|
return $this->create($this->query, $data); |
||||||
|
} |
||||||
|
|
||||||
|
public function updateEventoLogoffAgent($matricula, $ramal, $dac, $flag = 2) |
||||||
|
{ |
||||||
|
$data = []; |
||||||
|
$this->query = "UPDATE " . self::EVENTO_AGENTE . " SET logoff = :logoff, flag = :flag " |
||||||
|
. "WHERE matricula = :matricula AND id_dac = :id_dac AND ramal = :ramal " |
||||||
|
. "AND login = (SELECT MAX(login) FROM pbx_eventos_agentes WHERE matricula = :matricula AND id_dac = :id_dac AND ramal= :ramal);"; |
||||||
|
|
||||||
|
$data['logoff'] = 'now()'; |
||||||
|
$data['flag'] = $flag; |
||||||
|
$data['matricula'] = $matricula; |
||||||
|
$data['id_dac'] = $dac; |
||||||
|
$data['ramal'] = $ramal; |
||||||
|
return $this->update($this->query, $data); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,34 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace app\Models; |
||||||
|
|
||||||
|
use app\Core\Model; |
||||||
|
|
||||||
|
/** |
||||||
|
* Description of Ramal |
||||||
|
* |
||||||
|
* @author Lucas Awade |
||||||
|
*/ |
||||||
|
class SystemMessage extends Model |
||||||
|
{ |
||||||
|
|
||||||
|
private $table = 'md_system_message'; |
||||||
|
|
||||||
|
public function findMessage($momento, $fila = null) |
||||||
|
{ |
||||||
|
$data = []; |
||||||
|
$data['momento'] = $momento; |
||||||
|
$this->query = "SELECT * FROM {$this->table} m WHERE 1=1"; |
||||||
|
|
||||||
|
if (!empty($fila)) { |
||||||
|
$data['fila'] = $fila; |
||||||
|
$this->query .= " AND (m.fila = :fila OR m.fila IS null)"; |
||||||
|
} else { |
||||||
|
$this->query .= " AND m.fila IS null"; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
$this->query .= " AND m.momento = :momento ORDER BY ordem"; |
||||||
|
return $this->read($this->query, $data)->fetchAll(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,227 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace app\Providers; |
||||||
|
|
||||||
|
use app\Interfaces\IApiMedia; |
||||||
|
use Twilio\Rest\Client; |
||||||
|
|
||||||
|
class ApiTwilio implements IApiMedia |
||||||
|
{ |
||||||
|
private $sid = 'ACab626d6f133aa20b21879d37cd21b139'; |
||||||
|
private $token = '131e5ed83468349ff93250ca72417d70'; |
||||||
|
private $numeroTwilio = '553140428280'; |
||||||
|
|
||||||
|
/** @var string $hook resposta do webhook */ |
||||||
|
private $hook; |
||||||
|
|
||||||
|
function getContentType() |
||||||
|
{ |
||||||
|
return 'text/xml'; |
||||||
|
} |
||||||
|
|
||||||
|
function getchannel() |
||||||
|
{ |
||||||
|
return CONF_WHATSAPP_CHANNEL; |
||||||
|
} |
||||||
|
function enviarMedia($whatsapp, $link, $type, $titulo = null) |
||||||
|
{ |
||||||
|
/* |
||||||
|
twilio só suporta esses formatos. |
||||||
|
Images JPG, JPEG, PNG |
||||||
|
Audio MP3, OGG, AMR |
||||||
|
Documents PDF |
||||||
|
Video MP4 (with H.264 video codec and AAC audio) |
||||||
|
Contacts vCard (.vcf)*/ |
||||||
|
|
||||||
|
$twilio = new Client($this->sid, $this->token); |
||||||
|
$message = $twilio->messages->create( |
||||||
|
"whatsapp:+$whatsapp", // to |
||||||
|
[ |
||||||
|
"from" => "whatsapp:+{$this->numeroTwilio}", |
||||||
|
"mediaUrl" => [$link] |
||||||
|
] |
||||||
|
); |
||||||
|
logger('twilio')->info(var_export($message->body, true)); |
||||||
|
return $message->body; |
||||||
|
} |
||||||
|
function enviarMsg($whatsapp, $mensagem, $encode = true) |
||||||
|
{ |
||||||
|
if ($encode) { |
||||||
|
$mensagem = utf8_encode($mensagem); |
||||||
|
} |
||||||
|
$twilio = new Client($this->sid, $this->token); |
||||||
|
$message = $twilio->messages->create( |
||||||
|
"whatsapp:+$whatsapp", // to |
||||||
|
[ |
||||||
|
"from" => "whatsapp:+{$this->numeroTwilio}", |
||||||
|
"body" => $mensagem, |
||||||
|
] |
||||||
|
); |
||||||
|
logger('twilio')->info(var_export($message->body, true)); |
||||||
|
return $message->body; |
||||||
|
} |
||||||
|
function enviarMsgIterativaLista($whatsapp, $mensagem, $nomeButton, $sections) |
||||||
|
{ |
||||||
|
} |
||||||
|
function enviarMsgIterativaBotao($whatsapp, $mensagem, $buttons) |
||||||
|
{ |
||||||
|
} |
||||||
|
function enviarContato($whatsapp, $nome, $contato) |
||||||
|
{ |
||||||
|
} |
||||||
|
function enviarLocalizacao($whatsapp, $longitude, $latitude, $nome = null, $endereco = null) |
||||||
|
{ |
||||||
|
} |
||||||
|
function baixarMidia() |
||||||
|
{ |
||||||
|
$request = new Requests(); |
||||||
|
if (in_array($this->getType(), ['location', 'contacts', 'text'])) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
logger('baixarMidia')->info('url: ' . $this->hook['MediaUrl0']); |
||||||
|
$request->setUrl($this->hook['MediaUrl0']); |
||||||
|
$name = $this->getId(); |
||||||
|
$request->requestType("GET"); |
||||||
|
$request->setMetodo(''); |
||||||
|
$pathfile = $request->storage . $name; |
||||||
|
$retorno = $request->exec(); |
||||||
|
file_put_contents($pathfile, $retorno); |
||||||
|
if (file_exists($pathfile)) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
return false; |
||||||
|
} |
||||||
|
function getProfile() |
||||||
|
{ |
||||||
|
return $this->hook['ProfileName']; |
||||||
|
} |
||||||
|
function getPhone() |
||||||
|
{ |
||||||
|
return $this->hook['WaId']; |
||||||
|
} |
||||||
|
function getType() |
||||||
|
{ |
||||||
|
$type = $this->hook['MediaContentType0']; |
||||||
|
if ($type) { |
||||||
|
$type = explode('/', $type); |
||||||
|
if ($type[0] == 'application') { |
||||||
|
return 'document'; |
||||||
|
} |
||||||
|
return $type[0]; |
||||||
|
} |
||||||
|
return 'text'; |
||||||
|
} |
||||||
|
function getMimetype() |
||||||
|
{ |
||||||
|
return $this->hook['MediaContentType0']; |
||||||
|
} |
||||||
|
function getId() |
||||||
|
{ |
||||||
|
return $this->hook['MessageSid']; |
||||||
|
} |
||||||
|
function getIsValidMessage() |
||||||
|
{ |
||||||
|
logger('getIsValidMessage')->info('getIsValidMessage: ' + is_array($this->hook)); |
||||||
|
return is_array($this->hook); |
||||||
|
} |
||||||
|
function getMessage() |
||||||
|
{ |
||||||
|
return $this->hook['Body']; |
||||||
|
} |
||||||
|
function setMessage($msg) |
||||||
|
{ |
||||||
|
$this->hook['Body'] = $msg; |
||||||
|
} |
||||||
|
function getContactFormatted() |
||||||
|
{ |
||||||
|
return false; |
||||||
|
} |
||||||
|
function getContactPhone() |
||||||
|
{ |
||||||
|
return false; |
||||||
|
} |
||||||
|
function getGeolocation($type) |
||||||
|
{ |
||||||
|
return false; |
||||||
|
} |
||||||
|
function setHook($hook) |
||||||
|
{ |
||||||
|
//$array = "SmsMessageSid=SM3f3e0cac9d0da519ec0ffa7f15eaa15b&NumMedia=0&ProfileName=Lucas&SmsSid=SM3f3e0cac9d0da519ec0ffa7f15eaa15b&WaId=556596107663&SmsStatus=received&Body=sdsdfads&To=whatsapp%3A%2B14155238886&NumSegments=1&MessageSid=SM3f3e0cac9d0da519ec0ffa7f15eaa15b&AccountSid=ACab626d6f133aa20b21879d37cd21b139&From=whatsapp%3A%2B556596107663&ApiVersion=2010-04-01"; |
||||||
|
$array = explode("&", urldecode($hook)); |
||||||
|
$map = []; |
||||||
|
foreach ($array as $key => $value) { |
||||||
|
$auxi = $array = explode("=", $value); |
||||||
|
$map[$auxi[0]] = $auxi[1]; |
||||||
|
} |
||||||
|
|
||||||
|
// mensagem normal |
||||||
|
// [SmsMessageSid] => SM3f3e0cac9d0da519ec0ffa7f15eaa15b |
||||||
|
// [NumMedia] => 0 |
||||||
|
// [ProfileName] => Lucas |
||||||
|
// [SmsSid] => SM3f3e0cac9d0da519ec0ffa7f15eaa15b |
||||||
|
// [WaId] => 556596107663 |
||||||
|
// [SmsStatus] => received |
||||||
|
// [Body] => sdsdfads |
||||||
|
// [To] => whatsapp%3A%2B14155238886 |
||||||
|
// [NumSegments] => 1 |
||||||
|
// [MessageSid] => SM3f3e0cac9d0da519ec0ffa7f15eaa15b |
||||||
|
// [AccountSid] => ACab626d6f133aa20b21879d37cd21b139 |
||||||
|
// [From] => whatsapp%3A%2B556596107663 |
||||||
|
// [ApiVersion] => 2010-04-01 |
||||||
|
|
||||||
|
// imagem |
||||||
|
// [MediaContentType0] => image/jpeg |
||||||
|
// [SmsMessageSid] => MM0e531d626f74ec950e637d7491b0080c |
||||||
|
// [NumMedia] => 1 |
||||||
|
// [ProfileName] => Lucas |
||||||
|
// [SmsSid] => MM0e531d626f74ec950e637d7491b0080c |
||||||
|
// [WaId] => 556596107663 |
||||||
|
// [SmsStatus] => received |
||||||
|
// [Body] => |
||||||
|
// [To] => whatsapp:+14155238886 |
||||||
|
// [NumSegments] => 1 |
||||||
|
// [MessageSid] => MM0e531d626f74ec950e637d7491b0080c |
||||||
|
// [AccountSid] => ACab626d6f133aa20b21879d37cd21b139 |
||||||
|
// [From] => whatsapp:+556596107663 |
||||||
|
// [MediaUrl0] => https://api.twilio.com/2010-04-01/Accounts/ACab626d6f133aa20b21879d37cd21b139/Messages/MM0e531d626f74ec950e637d7491b0080c/Media/ME4ff81dee03f2cd1b7875d87954e8abd7 |
||||||
|
// [ApiVersion] => 2010-04-01 |
||||||
|
|
||||||
|
// documento n�o valido |
||||||
|
// [SmsMessageSid] => MM2f04ee178bf6843dd26ac19e6e193c19 |
||||||
|
// [NumMedia] => 0 |
||||||
|
// [ProfileName] => Lucas |
||||||
|
// [SmsSid] => MM2f04ee178bf6843dd26ac19e6e193c19 |
||||||
|
// [WaId] => 556596107663 |
||||||
|
// [SmsStatus] => received |
||||||
|
// [Body] => INSTALA��O WHATSAPP.docx |
||||||
|
// [To] => whatsapp:+553140428280 |
||||||
|
// [NumSegments] => 1 |
||||||
|
// [MessageSid] => MM2f04ee178bf6843dd26ac19e6e193c19 |
||||||
|
// [AccountSid] => ACab626d6f133aa20b21879d37cd21b139 |
||||||
|
// [From] => whatsapp:+556596107663 |
||||||
|
// [ApiVersion] => 2010-04-01 |
||||||
|
|
||||||
|
// documento pdf |
||||||
|
// [MediaContentType0] => application/pdf |
||||||
|
// [SmsMessageSid] => MM1042d93ac503a7468b7d3fb3a0ca77d5 |
||||||
|
// [NumMedia] => 1 |
||||||
|
// [ProfileName] => Lucas |
||||||
|
// [SmsSid] => MM1042d93ac503a7468b7d3fb3a0ca77d5 |
||||||
|
// [WaId] => 556596107663 |
||||||
|
// [SmsStatus] => received |
||||||
|
// [Body] => Cap1-_atlas_.pdf |
||||||
|
// [To] => whatsapp:+553140428280 |
||||||
|
// [NumSegments] => 1 |
||||||
|
// [MessageSid] => MM1042d93ac503a7468b7d3fb3a0ca77d5 |
||||||
|
// [AccountSid] => ACab626d6f133aa20b21879d37cd21b139 |
||||||
|
// [From] => whatsapp:+556596107663 |
||||||
|
// [MediaUrl0] => https://api.twilio.com/2010-04-01/Accounts/ACab626d6f133aa20b21879d37cd21b139/Messages/MM1042d93ac503a7468b7d3fb3a0ca77d5/Media/ME8fead4a393c68d2fcd14bdff03cc8e74 |
||||||
|
// [ApiVersion] => 2010-04-01 |
||||||
|
$this->hook = $map; |
||||||
|
} |
||||||
|
function retornaTituloDocument() |
||||||
|
{ |
||||||
|
return $this->hook['Body']; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,139 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace app\Providers; |
||||||
|
|
||||||
|
class Requests |
||||||
|
{ |
||||||
|
/** @var string $token token de autenticação das requesições */ |
||||||
|
protected $token; |
||||||
|
|
||||||
|
/** @var string $url url base das requsições */ |
||||||
|
protected $url; |
||||||
|
|
||||||
|
/** @var string $metodo endpoint da requsição */ |
||||||
|
protected $metodo; |
||||||
|
|
||||||
|
/** @var string $query query da requsição */ |
||||||
|
protected $query; |
||||||
|
|
||||||
|
/** @var string $query tipo da requsição */ |
||||||
|
protected $requestType; |
||||||
|
|
||||||
|
/** @var array $params parametros da request */ |
||||||
|
protected $params = array(); |
||||||
|
|
||||||
|
/** @var RequestURL $request description */ |
||||||
|
protected $request; |
||||||
|
|
||||||
|
/** @var string $contentType tipo da requsição */ |
||||||
|
protected $contentType; |
||||||
|
|
||||||
|
/** @var string $storage caminho dos arquivos */ |
||||||
|
public $storage = CONF_PATH_FILES; |
||||||
|
|
||||||
|
function __construct() |
||||||
|
{ |
||||||
|
$this->request = new RequestURL(); |
||||||
|
$this->setToken(); |
||||||
|
$this->setUrl(CONF_WHATSAPP_AUTH_URL); |
||||||
|
} |
||||||
|
|
||||||
|
function response($result) |
||||||
|
{ |
||||||
|
if ($result) { |
||||||
|
if (json_decode($result, true) !== null) { |
||||||
|
return json_decode($result, true); |
||||||
|
} |
||||||
|
return $result; |
||||||
|
} else { |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
function exec() |
||||||
|
{ |
||||||
|
$this->setQuery(json_encode($this->params)); //SET QUERY |
||||||
|
$this->request->setUrl($this->url . $this->metodo, false); |
||||||
|
|
||||||
|
$header = array(); |
||||||
|
$header[] = "Authorization: Bearer {$this->token}"; |
||||||
|
if ($this->requestType == 'POST') { |
||||||
|
$header[] = 'Content-Type: application/json'; |
||||||
|
$this->request->post_field($this->getQuery(), true); |
||||||
|
} |
||||||
|
$this->request->header($header); |
||||||
|
$this->request->method_request($this->requestType); |
||||||
|
return $this->request->exec_request(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Recebe o tipo de Requisi��o GET/POST |
||||||
|
* |
||||||
|
* @return boolean |
||||||
|
*/ |
||||||
|
function requestType($req = null) |
||||||
|
{ |
||||||
|
if (!$req) { |
||||||
|
return $this->requestType; |
||||||
|
} |
||||||
|
|
||||||
|
if (strtoupper($req) == "GET") { |
||||||
|
return $this->requestType = "GET"; |
||||||
|
} else if (strtoupper($req) == "POST") { |
||||||
|
return $this->requestType = "POST"; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Verifica se todos os parametros passados foram completados. |
||||||
|
* |
||||||
|
* @param array $args |
||||||
|
* @return true|false |
||||||
|
*/ |
||||||
|
function getArgs($args) |
||||||
|
{ |
||||||
|
foreach ($args as $value) { |
||||||
|
if (!$value) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
function setMetodo($metodo) |
||||||
|
{ |
||||||
|
$this->metodo = $metodo; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Escreve a query para ser passada para o curl |
||||||
|
* |
||||||
|
* @param string $query |
||||||
|
*/ |
||||||
|
function setQuery($query) |
||||||
|
{ |
||||||
|
return $this->query .= $query; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* retorna a string pronta da query do curl e limpa a variavel. |
||||||
|
* |
||||||
|
* @return string $query |
||||||
|
*/ |
||||||
|
function getQuery() |
||||||
|
{ |
||||||
|
$query = $this->query; |
||||||
|
unset($this->query); |
||||||
|
return $query; |
||||||
|
} |
||||||
|
|
||||||
|
function setToken() |
||||||
|
{ |
||||||
|
$this->token = CONF_WHATSAPP_AUTH_TOKEN; |
||||||
|
} |
||||||
|
|
||||||
|
public function setUrl($url) |
||||||
|
{ |
||||||
|
$this->url = $url; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,9 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace app\Providers; |
||||||
|
|
||||||
|
use app\Providers\ApiTwilio; |
||||||
|
|
||||||
|
class Whatsapp extends ApiTwilio |
||||||
|
{ |
||||||
|
} |
@ -1,17 +1,22 @@ |
|||||||
{ |
{ |
||||||
"name": "simplesip/whatsapp", |
"name": "simplesip/whatsapp", |
||||||
"description": "Projeto WhatsApp", |
"description": "Projeto WhatsApp", |
||||||
"authors": [ |
"authors": [{ |
||||||
{ |
"name": "Simples IP Desenvolvimento", |
||||||
"name": "Simples IP Desenvolvimento", |
"email": "lucasawade46@gmail.com" |
||||||
"email": "lucasawade46@gmail.com" |
}], |
||||||
} |
|
||||||
], |
|
||||||
"autoload": { |
"autoload": { |
||||||
"psr-4": { |
"psr-4": { |
||||||
"app\\": "app/", |
"app\\": "app/", |
||||||
"scripts\\": "scripts/" |
"scripts\\": "scripts/", |
||||||
|
"websocket\\": "websocket/", |
||||||
|
"service\\": "service/", |
||||||
|
"tests\\": "tests/" |
||||||
} |
} |
||||||
}, |
}, |
||||||
"require": {} |
"require": { |
||||||
} |
"cboden/ratchet": "^0.4.4", |
||||||
|
"textalk/websocket": "^1.3.1", |
||||||
|
"twilio/sdk": "^5.42.2" |
||||||
|
} |
||||||
|
} |
@ -1,18 +0,0 @@ |
|||||||
{ |
|
||||||
"_readme": [ |
|
||||||
"This file locks the dependencies of your project to a known state", |
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", |
|
||||||
"This file is @generated automatically" |
|
||||||
], |
|
||||||
"content-hash": "824e80b41f5059974728f7d2650347b2", |
|
||||||
"packages": [], |
|
||||||
"packages-dev": [], |
|
||||||
"aliases": [], |
|
||||||
"minimum-stability": "stable", |
|
||||||
"stability-flags": [], |
|
||||||
"prefer-stable": false, |
|
||||||
"prefer-lowest": false, |
|
||||||
"platform": [], |
|
||||||
"platform-dev": [], |
|
||||||
"plugin-api-version": "2.0.0" |
|
||||||
} |
|
@ -0,0 +1,18 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
/* |
||||||
|
|-------------------------------------------------------------------------- |
||||||
|
| Momonts |
||||||
|
|-------------------------------------------------------------------------- |
||||||
|
| |
||||||
|
| Eventos utilizados pelo gerenciamento dos atendimentos. |
||||||
|
| |
||||||
|
*/ |
||||||
|
|
||||||
|
define("CONF_MOMENT_SAUDACAO", 'SAUDACAO'); |
||||||
|
define("CONF_MOMENT_INICIAR_ATENDIMENTO", 'INICIAR_ATENDIMENTO'); |
||||||
|
define("CONF_MOMENT_FINALIZAR_ATENDIMENTO", 'FINALIZAR_ATENDIMENTO'); |
||||||
|
define("CONF_MOMENT_CANCELAR_FILA", 'CANCELAR_FILA'); //entrou na fila mas n tem agente logado |
||||||
|
define("CONF_MOMENT_ENTRAR_FILA_SEM", 'ENTRAR_FILA_SEM'); //entrou na fila mas n tem agente livre |
||||||
|
define("CONF_MOMENT_ENTRAR_FILA_COM", 'ENTRAR_FILA_COM'); |
||||||
|
define("CONF_MOMENT_ERRO_ATEND", 'LOST_CONNECTION');// quando estiver em atendimento e perder a conexão com websocket |
@ -0,0 +1,530 @@ |
|||||||
|
ALTER TABLE |
||||||
|
pbx_supervisor_agentes |
||||||
|
ADD |
||||||
|
media int NOT NULL DEFAULT 0; |
||||||
|
|
||||||
|
-- pbx_eventos_agentes |
||||||
|
ALTER TABLE |
||||||
|
pbx_eventos_agentes |
||||||
|
ADD |
||||||
|
entrada_indisponivel timestamp(0) NULL; |
||||||
|
|
||||||
|
ALTER TABLE |
||||||
|
pbx_eventos_agentes |
||||||
|
ADD |
||||||
|
saida_indisponivel timestamp(0) NULL; |
||||||
|
|
||||||
|
select |
||||||
|
id, |
||||||
|
prm_sk_host_chat, |
||||||
|
prm_chat_api, |
||||||
|
prm_media_simultaneo, |
||||||
|
prm_chat_api_supervisor into pbx_parametros_bk |
||||||
|
from |
||||||
|
pbx_parametros |
||||||
|
where |
||||||
|
id = 1; |
||||||
|
|
||||||
|
alter table |
||||||
|
pbx_parametros drop column prm_chat_api_supervisor; |
||||||
|
|
||||||
|
alter table |
||||||
|
pbx_parametros |
||||||
|
add |
||||||
|
prm_chat_api_supervisor varchar(255); |
||||||
|
|
||||||
|
alter table |
||||||
|
pbx_parametros drop column prm_sk_host_chat; |
||||||
|
|
||||||
|
alter table |
||||||
|
pbx_parametros |
||||||
|
add |
||||||
|
prm_sk_host_chat varchar(255); |
||||||
|
|
||||||
|
alter table |
||||||
|
pbx_parametros drop column prm_chat_api; |
||||||
|
|
||||||
|
alter table |
||||||
|
pbx_parametros |
||||||
|
add |
||||||
|
prm_chat_api varchar(255); |
||||||
|
|
||||||
|
update |
||||||
|
pbx_parametros |
||||||
|
set |
||||||
|
prm_chat_api_supervisor = ( |
||||||
|
select |
||||||
|
prm_chat_api_supervisor |
||||||
|
from |
||||||
|
pbx_parametros_bk |
||||||
|
where |
||||||
|
id = 1 |
||||||
|
); |
||||||
|
|
||||||
|
update |
||||||
|
pbx_parametros |
||||||
|
set |
||||||
|
prm_chat_api = ( |
||||||
|
select |
||||||
|
prm_chat_api |
||||||
|
from |
||||||
|
pbx_parametros_bk |
||||||
|
where |
||||||
|
id = 1 |
||||||
|
); |
||||||
|
|
||||||
|
update |
||||||
|
pbx_parametros |
||||||
|
set |
||||||
|
prm_sk_host_chat = ( |
||||||
|
select |
||||||
|
prm_sk_host_chat |
||||||
|
from |
||||||
|
pbx_parametros_bk |
||||||
|
where |
||||||
|
id = 1 |
||||||
|
); |
||||||
|
|
||||||
|
drop table pbx_parametros_bk; |
||||||
|
|
||||||
|
select |
||||||
|
id, |
||||||
|
prm_sk_host_chat, |
||||||
|
prm_chat_api, |
||||||
|
prm_media_simultaneo, |
||||||
|
prm_chat_api_supervisor |
||||||
|
from |
||||||
|
pbx_parametros |
||||||
|
where |
||||||
|
id = 1; |
||||||
|
|
||||||
|
ALTER TABLE |
||||||
|
pbx_parametros |
||||||
|
ADD |
||||||
|
prm_media_simultaneo int not NULL DEFAULT 3; |
||||||
|
|
||||||
|
CREATE TABLE md_supervisor ( |
||||||
|
id SERIAL NOT NULL PRIMARY KEY, |
||||||
|
ramal varchar NULL, |
||||||
|
matricula varchar NULL, |
||||||
|
nome varchar NULL, |
||||||
|
tempo_login timestamp NULL, |
||||||
|
fila varchar NULL, |
||||||
|
status varchar NULL, |
||||||
|
duracao timestamp NULL, |
||||||
|
uniqueid varchar NULL DEFAULT '', |
||||||
|
status_agente int NOT NULL DEFAULT 0, |
||||||
|
motivo_pausa varchar NULL, |
||||||
|
chamada_classificado int NOT NULL DEFAULT 1, |
||||||
|
cliente_id varchar NULL |
||||||
|
); |
||||||
|
|
||||||
|
CREATE TABLE md_message ( |
||||||
|
id SERIAL NOT NULL PRIMARY KEY, |
||||||
|
uniqueid varchar NOT NULL, |
||||||
|
src varchar NOT NULL, |
||||||
|
dst varchar NOT NULL, |
||||||
|
type varchar NOT NULL, |
||||||
|
content varchar NOT NULL, |
||||||
|
profile_name varchar NOT NULL, |
||||||
|
msg_date timestamptz NULL DEFAULT now(), |
||||||
|
media varchar NULL, |
||||||
|
status varchar NULL, |
||||||
|
file_name varchar NULL, |
||||||
|
id_provedor varchar NULL, |
||||||
|
mimetype varchar NULL |
||||||
|
); |
||||||
|
|
||||||
|
CREATE TABLE md_evento ( |
||||||
|
id SERIAL NOT NULL PRIMARY KEY, |
||||||
|
uniqueid varchar NOT NULL, |
||||||
|
evento varchar NOT NULL, |
||||||
|
data_evento timestamp NULL, |
||||||
|
data_reg timestamp NULL DEFAULT now(), |
||||||
|
fila varchar NOT NULL, |
||||||
|
matricula varchar NULL |
||||||
|
); |
||||||
|
|
||||||
|
CREATE TABLE md_atendimento ( |
||||||
|
id SERIAL NOT NULL PRIMARY KEY, |
||||||
|
matricula varchar NULL, |
||||||
|
cliente_id varchar NOT NULL, |
||||||
|
direcao varchar(1) NOT NULL, |
||||||
|
uniqueid varchar NULL, |
||||||
|
context varchar NULL, |
||||||
|
data_reg timestamp NULL DEFAULT now(), |
||||||
|
nome varchar NULL |
||||||
|
); |
||||||
|
|
||||||
|
CREATE TABLE md_system_message ( |
||||||
|
id SERIAL NOT NULL PRIMARY KEY, |
||||||
|
data_reg timestamp NULL DEFAULT now(), |
||||||
|
texto varchar NOT NULL, |
||||||
|
ordem int NOT NULL, |
||||||
|
momento varchar NULL |
||||||
|
); |
||||||
|
|
||||||
|
INSERT INTO |
||||||
|
md_system_message (data_reg, texto, ordem, momento) |
||||||
|
VALUES |
||||||
|
( |
||||||
|
now(), |
||||||
|
'Olá @cliente_name tudo certo?', |
||||||
|
0, |
||||||
|
'SAUDACAO' |
||||||
|
), |
||||||
|
( |
||||||
|
now(), |
||||||
|
'@cliente_name escolha uma das opções abaixo para iniciar o atendimento', |
||||||
|
0, |
||||||
|
'SAUDACAO' |
||||||
|
), |
||||||
|
( |
||||||
|
now(), |
||||||
|
'Cancelado o atendimento!', |
||||||
|
0, |
||||||
|
'CANCELAR_FILA' |
||||||
|
), |
||||||
|
( |
||||||
|
now(), |
||||||
|
'Atendimento iniciado com @agente_name!', |
||||||
|
0, |
||||||
|
'INICIAR_ATENDIMENTO' |
||||||
|
), |
||||||
|
( |
||||||
|
now(), |
||||||
|
'Atendimento finalizado!', |
||||||
|
0, |
||||||
|
'FINALIZAR_ATENDIMENTO' |
||||||
|
), |
||||||
|
( |
||||||
|
now(), |
||||||
|
'Não temos nenhum atendente disponível no momento, iremos lhe atender assim que um atendente estiver disponível!', |
||||||
|
0, |
||||||
|
'ENTRAR_FILA_SEM' |
||||||
|
), |
||||||
|
( |
||||||
|
now(), |
||||||
|
'Nossos atendentes estão ocupados, por favor aguarde que iremos lhe atender!', |
||||||
|
0, |
||||||
|
'ENTRAR_FILA_COM' |
||||||
|
), |
||||||
|
( |
||||||
|
now(), |
||||||
|
'Para finalar o atendimento digite \n*"/finalizar"*.', |
||||||
|
0, |
||||||
|
'INICIAR_ATENDIMENTO' |
||||||
|
), |
||||||
|
( |
||||||
|
now(), |
||||||
|
'Para sair da fila digite \n*"/cancelar"*.', |
||||||
|
0, |
||||||
|
'ENTRAR_FILA_SEM' |
||||||
|
), |
||||||
|
( |
||||||
|
now(), |
||||||
|
'Para sair da fila digite \n*"/cancelar"*.', |
||||||
|
0, |
||||||
|
'ENTRAR_FILA_COM' |
||||||
|
); |
||||||
|
|
||||||
|
CREATE TABLE md_supervisor ( |
||||||
|
id SERIAL NOT NULL PRIMARY KEY, |
||||||
|
ramal varchar NULL, |
||||||
|
matricula varchar NULL, |
||||||
|
nome varchar NULL, |
||||||
|
tempo_login timestamp NULL, |
||||||
|
fila varchar NULL, |
||||||
|
status varchar NULL, |
||||||
|
duracao timestamp NULL, |
||||||
|
uniqueid varchar varying NULL DEFAULT '', |
||||||
|
status_agente int NOT NULL DEFAULT 0, |
||||||
|
motivo_pausa varchar NULL, |
||||||
|
chamada_classificado int NOT NULL DEFAULT 1, |
||||||
|
cliente_id varchar NULL |
||||||
|
); |
||||||
|
|
||||||
|
CREATE TABLE pbx_notifica_media ( |
||||||
|
id SERIAL NOT NULL PRIMARY KEY, |
||||||
|
uniqueid character varying NOT NULL, |
||||||
|
src character varying NOT NULL, |
||||||
|
msg character varying NOT NULL, |
||||||
|
notif_date timestamp WITHOUT TIME ZONW DEFAULT(NOW()) |
||||||
|
); |
||||||
|
|
||||||
|
CREATE TABLE pbx_lista_negra_palavras ( |
||||||
|
id SERIAL NOT NULL PRIMARY KEY, |
||||||
|
palavra character varying NOT NULL, |
||||||
|
date_create timestamp WITHOUT TIME ZONW DEFAULT(NOW()) |
||||||
|
); |
||||||
|
|
||||||
|
INSERT INTO |
||||||
|
pbx_lista_negra_palavras (palavra) |
||||||
|
VALUES |
||||||
|
('Anus'), |
||||||
|
('Baba-ovo'), |
||||||
|
('Babaovo'), |
||||||
|
('Babaca'), |
||||||
|
('Bacura'), |
||||||
|
('Bagos'), |
||||||
|
('Baitola'), |
||||||
|
('Bebum'), |
||||||
|
('Besta'), |
||||||
|
('Bicha'), |
||||||
|
('Bisca'), |
||||||
|
('Bixa'), |
||||||
|
('Boazuda'), |
||||||
|
('Boceta'), |
||||||
|
('Boco'), |
||||||
|
('Boiola'), |
||||||
|
('Bolagato'), |
||||||
|
('Boquete'), |
||||||
|
('Bolcat'), |
||||||
|
('Bosseta'), |
||||||
|
('Bosta'), |
||||||
|
('Bostana'), |
||||||
|
('Brecha'), |
||||||
|
('Brexa'), |
||||||
|
('Brioco'), |
||||||
|
('Bronha'), |
||||||
|
('Buca'), |
||||||
|
('Buceta'), |
||||||
|
('Bunda'), |
||||||
|
('Bunduda'), |
||||||
|
('Burra'), |
||||||
|
('Burro'), |
||||||
|
('Busseta'), |
||||||
|
('Cachorra'), |
||||||
|
('Cachorro'), |
||||||
|
('Cadela'), |
||||||
|
('Caga'), |
||||||
|
('Cagado'), |
||||||
|
('Cagao'), |
||||||
|
('Cagona'), |
||||||
|
('Canalha'), |
||||||
|
('Caralho'), |
||||||
|
('Casseta'), |
||||||
|
('Cassete'), |
||||||
|
('Checheca'), |
||||||
|
('Chereca'), |
||||||
|
('Chibumba'), |
||||||
|
('Chibumbo'), |
||||||
|
('Chifruda'), |
||||||
|
('Chifrudo'), |
||||||
|
('Chota'), |
||||||
|
('Chochota'), |
||||||
|
('Chupada'), |
||||||
|
('Chupado'), |
||||||
|
('Clitoris'), |
||||||
|
('Cocaina'), |
||||||
|
('Coco'), |
||||||
|
('Corna'), |
||||||
|
('Corno'), |
||||||
|
('Cornuda'), |
||||||
|
('Cornudo'), |
||||||
|
('Corrupta'), |
||||||
|
('Corrupto'), |
||||||
|
('Cretina'), |
||||||
|
('Cretino'), |
||||||
|
('Cruz-credo'), |
||||||
|
('Cu'), |
||||||
|
('Culhao'), |
||||||
|
('Curalho'), |
||||||
|
('Cuzao'), |
||||||
|
('Cuzuda'), |
||||||
|
('Cuzudo'), |
||||||
|
('Debil'), |
||||||
|
('Debiloide'), |
||||||
|
('Defunto'), |
||||||
|
('Demonio'), |
||||||
|
('Difunto'), |
||||||
|
('Doida'), |
||||||
|
('Doido'), |
||||||
|
('Egua'), |
||||||
|
('Escrota'), |
||||||
|
('Escroto'), |
||||||
|
('Esporrada'), |
||||||
|
('Esporrado'), |
||||||
|
('Esporro'), |
||||||
|
('Estupida'), |
||||||
|
('Estupidez'), |
||||||
|
('Estupido'), |
||||||
|
('Fedida'), |
||||||
|
('Fedido'), |
||||||
|
('Fedor'), |
||||||
|
('Fedorenta'), |
||||||
|
('Feia'), |
||||||
|
('Feio'), |
||||||
|
('Feiosa'), |
||||||
|
('Feioso'), |
||||||
|
('Feioza'), |
||||||
|
('Feiozo'), |
||||||
|
('Felacao'), |
||||||
|
('Fenda'), |
||||||
|
('Foda'), |
||||||
|
('Fodao'), |
||||||
|
('Fode'), |
||||||
|
('FodidaFodido'), |
||||||
|
('Fornica'), |
||||||
|
('Fudendo'), |
||||||
|
('Fudecao'), |
||||||
|
('Fudida'), |
||||||
|
('Fudido'), |
||||||
|
('Furada'), |
||||||
|
('Furado'), |
||||||
|
('Furão'), |
||||||
|
('Furnica'), |
||||||
|
('Furnicar'), |
||||||
|
('Furo'), |
||||||
|
('Furona'), |
||||||
|
('Gaiata'), |
||||||
|
('Gaiato'), |
||||||
|
('Gay'), |
||||||
|
('Gonorrea'), |
||||||
|
('Gonorreia'), |
||||||
|
('Gosma'), |
||||||
|
('Gosmenta'), |
||||||
|
('Gosmento'), |
||||||
|
('Grelinho'), |
||||||
|
('Grelo'), |
||||||
|
('Homo-sexual'), |
||||||
|
('Homossexual'), |
||||||
|
('Homossexual'), |
||||||
|
('Idiota'), |
||||||
|
('Idiotice'), |
||||||
|
('Imbecil'), |
||||||
|
('Iscrota'), |
||||||
|
('Iscroto'), |
||||||
|
('Japa'), |
||||||
|
('Ladra'), |
||||||
|
('Ladrao'), |
||||||
|
('Ladroeira'), |
||||||
|
('Ladrona'), |
||||||
|
('Lalau'), |
||||||
|
('Leprosa'), |
||||||
|
('Leproso'), |
||||||
|
('Lésbica'), |
||||||
|
('Macaca'), |
||||||
|
('Macaco'), |
||||||
|
('Machona'), |
||||||
|
('Machorra'), |
||||||
|
('Manguaca'), |
||||||
|
('Mangua¦a'), |
||||||
|
('Masturba'), |
||||||
|
('Meleca'), |
||||||
|
('Merda'), |
||||||
|
('Mija'), |
||||||
|
('Mijada'), |
||||||
|
('Mijado'), |
||||||
|
('Mijo'), |
||||||
|
('Mocrea'), |
||||||
|
('Mocreia'), |
||||||
|
('Moleca'), |
||||||
|
('Moleque'), |
||||||
|
('Mondronga'), |
||||||
|
('Mondrongo'), |
||||||
|
('Naba'), |
||||||
|
('Nadega'), |
||||||
|
('Nojeira'), |
||||||
|
('Nojenta'), |
||||||
|
('Nojento'), |
||||||
|
('Nojo'), |
||||||
|
('Olhota'), |
||||||
|
('Otaria'), |
||||||
|
('Ot-ria'), |
||||||
|
('Otario'), |
||||||
|
('Ot-rio'), |
||||||
|
('Paca'), |
||||||
|
('Paspalha'), |
||||||
|
('Paspalhao'), |
||||||
|
('Paspalho'), |
||||||
|
('Pau'), |
||||||
|
('Peia'), |
||||||
|
('Peido'), |
||||||
|
('Pemba'), |
||||||
|
('Pênis'), |
||||||
|
('Pentelha'), |
||||||
|
('Pentelho'), |
||||||
|
('Perereca'), |
||||||
|
('Peru'), |
||||||
|
('Pica'), |
||||||
|
('Picao'), |
||||||
|
('Pilantra'), |
||||||
|
('Piranha'), |
||||||
|
('Piroca'), |
||||||
|
('Piroco'), |
||||||
|
('Piru'), |
||||||
|
('Porra'), |
||||||
|
('Prega'), |
||||||
|
('Prostibulo'), |
||||||
|
('Prost-bulo'), |
||||||
|
('Prostituta'), |
||||||
|
('Prostituto'), |
||||||
|
('Punheta'), |
||||||
|
('Punhetao'), |
||||||
|
('Pus'), |
||||||
|
('Pustula'), |
||||||
|
('Puta'), |
||||||
|
('Puto'), |
||||||
|
('Puxa-saco'), |
||||||
|
('Puxasaco'), |
||||||
|
('Rabao'), |
||||||
|
('Rabo'), |
||||||
|
('Rabuda'), |
||||||
|
('Rabudao'), |
||||||
|
('Rabudo'), |
||||||
|
('Rabudona'), |
||||||
|
('Racha'), |
||||||
|
('Rachada'), |
||||||
|
('Rachadao'), |
||||||
|
('Rachadinha'), |
||||||
|
('Rachadinho'), |
||||||
|
('Rachado'), |
||||||
|
('Ramela'), |
||||||
|
('Remela'), |
||||||
|
('Retardada'), |
||||||
|
('Retardado'), |
||||||
|
('Ridícula'), |
||||||
|
('Rola'), |
||||||
|
('Rolinha'), |
||||||
|
('Rosca'), |
||||||
|
('Sacana'), |
||||||
|
('Safada'), |
||||||
|
('Safado'), |
||||||
|
('Sapatao'), |
||||||
|
('Sifilis'), |
||||||
|
('Siririca'), |
||||||
|
('Tarada'), |
||||||
|
('Tarado'), |
||||||
|
('Testuda'), |
||||||
|
('Tezao'), |
||||||
|
('Tezuda'), |
||||||
|
('Tezudo'), |
||||||
|
('Trocha'), |
||||||
|
('Trolha'), |
||||||
|
('Troucha'), |
||||||
|
('Trouxa'), |
||||||
|
('Troxa'), |
||||||
|
('Vaca'), |
||||||
|
('Vagabunda'), |
||||||
|
('Vagabundo'), |
||||||
|
('Vagina'), |
||||||
|
('Veada'), |
||||||
|
('Veadao'), |
||||||
|
('Veado'), |
||||||
|
('Viada'), |
||||||
|
('Víado'), |
||||||
|
('Viado'), |
||||||
|
('Viadao'), |
||||||
|
('Xavasca'), |
||||||
|
('Xerereca'), |
||||||
|
('Xexeca'), |
||||||
|
('Xibiu'), |
||||||
|
('Xibumba'), |
||||||
|
('Xota'), |
||||||
|
('Xochota'), |
||||||
|
('Xoxota'), |
||||||
|
('Xana'), |
||||||
|
('ladrão'), |
||||||
|
('viado'), |
||||||
|
('Xaninha'); |
@ -0,0 +1,21 @@ |
|||||||
|
{ |
||||||
|
"event": { |
||||||
|
"type": "mensagem", |
||||||
|
"contact": { |
||||||
|
"name": "Lucas", |
||||||
|
"number": "556596107663", |
||||||
|
"matricula": "" |
||||||
|
}, |
||||||
|
"mensagem": { |
||||||
|
"type": "text", |
||||||
|
"content": "ola", |
||||||
|
"id_provedor": null, |
||||||
|
"dst": "1040", |
||||||
|
"uniqueid": 1638191429, |
||||||
|
"media": "whatsapp", |
||||||
|
"datetime": 1638191429, |
||||||
|
"status": "sent", |
||||||
|
"mimetype": false |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,17 @@ |
|||||||
|
{ |
||||||
|
"contacts": [{ |
||||||
|
"profile": { |
||||||
|
"name": "Lucas" |
||||||
|
}, |
||||||
|
"wa_id": "556596107663" |
||||||
|
}], |
||||||
|
"messages": [{ |
||||||
|
"from": "556596107663", |
||||||
|
"id": "ABEGVWWWEHZjAhBQHfcZqjRX4rWUHoW5CZul", |
||||||
|
"text": { |
||||||
|
"body": "Test" |
||||||
|
}, |
||||||
|
"timestamp": "1637696166", |
||||||
|
"type": "text" |
||||||
|
}] |
||||||
|
} |
@ -0,0 +1,10 @@ |
|||||||
|
version: '3' |
||||||
|
services: |
||||||
|
mid: |
||||||
|
container_name: mid |
||||||
|
build: . |
||||||
|
volumes: |
||||||
|
- $PWD/data:/var/www/html/aplicativo/integracao/media/storage/files |
||||||
|
ports: |
||||||
|
- 8090:8090 |
||||||
|
- 8081:8081 |
@ -0,0 +1,15 @@ |
|||||||
|
# If you just change the port or add more ports here, you will likely also |
||||||
|
# have to change the VirtualHost statement in |
||||||
|
# /etc/apache2/sites-enabled/000-default.conf |
||||||
|
|
||||||
|
Listen 8081 |
||||||
|
|
||||||
|
<IfModule ssl_module> |
||||||
|
Listen 443 |
||||||
|
</IfModule> |
||||||
|
|
||||||
|
<IfModule mod_gnutls.c> |
||||||
|
Listen 443 |
||||||
|
</IfModule> |
||||||
|
|
||||||
|
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 438 B |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 9.7 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 8.0 KiB |
After Width: | Height: | Size: 8.1 KiB |
After Width: | Height: | Size: 9.3 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 8.3 KiB |
After Width: | Height: | Size: 35 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 126 KiB |