Browse Source

refatorando core mídia e provider positus

websocket
lucas cardoso 3 years ago
parent
commit
4e92df9cd9
  1. 134
      app/Core/CoreMedia.php
  2. 1
      app/Core/Model.php
  3. 156
      app/Providers/Positus.php

134
app/Core/CoreMedia.php

@ -13,7 +13,6 @@ use app\Interfaces\IApiMedia;
use app\Models\Atendimento;
use app\Models\Evento;
use app\Models\ListaNegraPalavras;
use app\Models\Ramal;
use app\Models\SupervisorModel;
use websocket\WsInterface;
@ -24,20 +23,47 @@ use websocket\WsInterface;
*/
class CoreMedia
{
private $api;
private $request;
private $commands;
private $queue;
private $agente;
private $palavroes;
private $ws;
private $atendimento;
private $supervisor;
private $eventos;
private $host;
private $bilheteController;
private $message;
private $systemController;
/** @var IApiMedia $api api do provedor de mensagens */
protected $api;
/** @var array $request hook da requisição de webhook*/
protected $request;
/** @var Commands $commands classe de comandos do sistema*/
protected $commands;
/** @var QueueController $queue controller da queue*/
protected $queue;
/** @var AgentController $agente controller do agente*/
protected $agente;
/** @var ListaNegraPalavras $palavroes model de palavras banida*/
protected $palavroes;
/** @var WsInterface $ws classe de comandos do sistema*/
protected $ws;
/** @var Atendimento $atendimento model de atendimentos*/
protected $atendimento;
/** @var SupervisorModel $supervisor model de supervisor*/
protected $supervisor;
/** @var Evento $eventos model de eventos*/
protected $eventos;
/** @var BilheteController $eventos controller dos bilhetess*/
protected $bilheteController;
/** @var Message $message model de mensagens*/
protected $message;
/** @var SystemMessageController $systemController controller de mensagens de sistema*/
protected $systemController;
/** @var Crypt $crypt core de criptografia*/
protected $crypt;
public function __construct()
{
@ -54,7 +80,7 @@ class CoreMedia
$this->bilheteController = new BilheteController;
$this->systemController = new SystemMessageController();
}
public function setApi($api)
public function setApi(IApiMedia $api)
{
$this->api = $api;
}
@ -83,32 +109,7 @@ class CoreMedia
//verifica se tem atendimento em aberto, se tiver ja manda msg para o agente via ws
$atendiment = $this->atendimento->findAtenEmAberto($this->api->getPhone());
if ($atendiment) {
$this->message->addMessage(
$atendiment->uniqueid,
$this->api->getPhone(),
$atendiment->matricula,
$this->api->getType(),
$this->retornaConteudo(),
empty($this->api->getProfile()) ? '' : $this->api->getProfile(),
$this->api->getchannel(),
"sended",
$this->api->getMimetype(),
$this->api->retornaTituloDocument(),
$this->api->getId()
);
$this->ws->enviaMsg(
$this->api->convertToWebsocket(
$this->retornaConteudo(),
$atendiment->matricula,
$atendiment->uniqueid,
$this->api->getType(),
$this->api->getProfile(),
$this->api->getPhone(),
time(),
$this->api->getId(),
$this->api->getMimetype()
)
);
$this->enviaMensagemAgente($atendiment);
return null;
}
//verifica se tem atendimento em espera, se tiver ja mostra a sua posição na fila
@ -253,39 +254,52 @@ class CoreMedia
}
}
public function listaFilas()
{
$ramal = new Ramal();
$user = $ramal->findRamal($this->api->getPhone());
$search = $this->queue->listaAllFilas();
$listaPausas = [];
foreach ($search as $key => $value) {
$value->nome = strtolower($value->nome);
array_push($listaPausas, ['title' => substr($value->nome, 0, 23), 'sub' => "/E {$value->nome} {$user->callerid}"]);
}
return $listaPausas;
}
public function retornaConteudo()
{
switch ($this->api->getType()) {
case 'text':
return $this->api->getMessage();
case 'image':
return $this->api->getLinkDownload($this->host);
case 'sticker':
return $this->api->getLinkDownload($this->host);
case 'video':
return $this->api->getLinkDownload($this->host);
case 'voice':
case 'audio':
return $this->api->getLinkDownload($this->host);
case 'document':
return $this->api->getLinkDownload($this->host);
return $this->api->getId();
case 'contacts':
return null;
case 'location':
return null;
}
}
function enviaMensagemAgente($atendiment)
{
$this->message->addMessage(
$atendiment->uniqueid,
$this->api->getPhone(),
$atendiment->matricula,
$this->api->getType(),
$this->retornaConteudo(),
empty($this->api->getProfile()) ? '' : $this->api->getProfile(),
$this->api->getchannel(),
"sended",
$this->api->getMimetype(),
$this->api->retornaTituloDocument(),
$this->api->getId()
);
$this->ws->enviaMsg(
$this->api->convertToWebsocket(
$this->retornaConteudo(),
$atendiment->matricula,
$atendiment->uniqueid,
$this->api->getType(),
$this->api->getProfile(),
$this->api->getPhone(),
time(),
$this->api->getId(),
$this->api->getMimetype()
)
);
}
}

1
app/Core/Model.php

@ -107,7 +107,6 @@ abstract class Model
protected function update($query, $data)
{
try {
logger('Query')->error('Query: ' . $query, debug_backtrace());
$stmt = Connect::getInstance()->prepare($query);
$this->strquery($stmt, $data);
$stmt->execute();

156
app/Providers/Positus.php

@ -3,33 +3,34 @@
namespace app\Providers;
use app\Interfaces\IApiMedia;
use app\Providers\RequestURL;
class Positus implements IApiMedia
class Positus extends Requests implements IApiMedia
{
private $token;
private $url;
private $metodo;
private $query;
private $requestType;
private $request;
private $params = array();
/** @var string $hook resposta do webhook */
private $hook;
private $storage = CONF_PATH_FILES;
public $channel = CONF_WHATSAPP_CHANNEL;
public $timeout_client_resposta = CONF_WHATSAPP_TIMEOUT_CLIENT_RESPOSTA;
private $channel = CONF_WHATSAPP_CHANNEL;
function __construct()
public function getchannel()
{
return CONF_WHATSAPP_CHANNEL;
}
function setHook($hook)
{
$this->hook = $hook;
}
function setToken()
{
$this->token = CONF_WHATSAPP_AUTH_TOKEN;
$this->url = CONF_WHATSAPP_AUTH_URL;
$this->request = new RequestURL();
}
public function getchannel()
function setUrl()
{
return CONF_WHATSAPP_CHANNEL;
$this->url = CONF_WHATSAPP_AUTH_URL;
}
public function convertToWebsocket($content, $matricula = '', $uniqueid, $type, $name, $number, $data, $idProvedor, $mimetype)
{
if ($number) {
@ -59,21 +60,7 @@ class Positus implements IApiMedia
}
return null;
}
function enviaImagem($whatsapp, $link, $titulo = null)
{
}
function enviaSticker($whatsapp, $link)
{
}
function enviaVideo($whatsapp, $link, $titulo = null)
{
}
function enviaAudio($whatsapp, $link)
{
}
function enviaDocumento($whatsapp, $link, $titulo = null)
{
}
function enviarMedia($whatsapp, $link, $type, $titulo = null)
{
$tipos = [];
@ -263,10 +250,6 @@ class Positus implements IApiMedia
//throw $th;
}
}
function setStorage($storage)
{
$this->storage = $storage;
}
/**
* Profile WhatsApp
@ -393,109 +376,6 @@ class Positus implements IApiMedia
return false;
}
function setHook($hook)
{
$this->hook = $hook;
}
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;
}
/**
* 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;
}
/**
* Recebe o tipo de Requisi<EFBFBD><EFBFBD>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";
}
}
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);
}
// logger('core')->debug('header: ' . var_export($header, true), debug_backtrace());
// logger('core')->debug('body: ' . var_export($this->params, true), debug_backtrace());
$this->request->header($header);
$this->request->method_request($this->requestType);
return $this->request->exec_request();
//return $this->response($response);
}
function response($result)
{
if ($result) {
if (json_decode($result, true) !== null) {
return json_decode($result, true);
}
return $result;
} else {
return false;
}
}
/**
* Create file and download in browser
*/
public function getLinkDownload($host)
{
return $host . "whatsapp/download/{$this->getId()}/{$this->getMimetype()}";
}
public function retornaTituloDocument()
{

Loading…
Cancel
Save