diff --git a/app/Actions/CriarAtendimentoAction.php b/app/Actions/CriarAtendimentoAction.php index 07e9f1b..310e55d 100644 --- a/app/Actions/CriarAtendimentoAction.php +++ b/app/Actions/CriarAtendimentoAction.php @@ -1,5 +1,7 @@ atendimentoRepository = new AtendimentoRepository; $this->eventosAtendimentosRepository = new EventosAtendimentoRepository; $this->supervisorRepository = new SupervisorRepository; @@ -29,21 +32,21 @@ class CriarAtendimentoAction } function __invoke($fila, $numero_client, ?string $uniqueid, IApiMedia $api) { - try { - $this->atendimentoRepository->db->begin(); + try { + $this->atendimentoRepository->db->begin(); if (empty($uniqueid)) { $id = $this->atendimentoRepository->create(new AtendimentoModel( - uniqueid: null, - matricula: null, - cliente_id: $numero_client, - provedor: $api->getchannel(), - nome: $api->getProfile(), - data_reg: 'now()', - id_empresa: $api->getNumberChannel()->id_empresa, - id_number_channel: $api->getNumberChannel()->id - )); - $uniqueid = $this->atendimentoRepository->get(['id' => $id])->uniqueid; - + uniqueid: null, + matricula: null, + cliente_id: $numero_client, + provedor: $api->getchannel(), + nome: $api->getProfile(), + data_reg: 'now()', + id_empresa: $api->getNumberChannel()->id_empresa, + id_number_channel: $api->getNumberChannel()->id + )); + $uniqueid = $this->atendimentoRepository->get(['id' => $id])->uniqueid; + if ($uniqueid) { $this->eventosAtendimentosRepository->create(new EventosAtendimentosModel( id: null, @@ -56,11 +59,11 @@ class CriarAtendimentoAction )); } } - $agentes = $this->supervisorRepository->list(['fila'=> $fila, 'id_empresa'=> $api->getNumberChannel()->id_empresa]); + $agentes = $this->supervisorRepository->list(['fila' => $fila, 'id_empresa' => $api->getNumberChannel()->id_empresa]); if (empty($agentes)) { $this->systemMessageAction->__invoke( CONF_MOMENT_ENTRAR_FILA_SEM, - [], + [], $api, $numero_client, $fila @@ -72,7 +75,7 @@ class CriarAtendimentoAction if (empty($agent)) { $this->systemMessageAction->__invoke( CONF_MOMENT_ENTRAR_FILA_COM, - [], + [], $api, $numero_client, $fila @@ -84,83 +87,79 @@ class CriarAtendimentoAction $this->atendimentoRepository->db->commit(); return null; } - $retServe = $this->atendimentoRepository->update(['uniqueid' => $uniqueid,'matricula' => $agent[0]->matricula, 'id_usuario' => $agent[0]->id_usuario]); + $retServe = $this->atendimentoRepository->update(['uniqueid' => $uniqueid, 'matricula' => $agent[0]->matricula, 'id_usuario' => $agent[0]->id_usuario]); if (empty($retServe)) { $api->enviarMsg( $numero_client, 'Erro ao gerar atendimento!' ); - + throw new Exception("Erro ao gerar atendimento!", 1); - } //Gera protocolo $action = new GenerateProtocolAction; $protocol = $action($uniqueid); //cria o evento de inicio de atendimento e criar o protocolo - if (empty($protocol)) { - throw new Exception("Não foi possivel gerar protocolo!", 1); - } - $event = $this->eventosAtendimentosRepository->getStatusAtendimento($uniqueid); - $retCria = $this->eventosAtendimentosRepository->create( - new EventosAtendimentosModel( + if (empty($protocol)) { + throw new Exception("Não foi possivel gerar protocolo!", 1); + } + $event = $this->eventosAtendimentosRepository->getStatusAtendimento($uniqueid); + $retCria = $this->eventosAtendimentosRepository->create( + new EventosAtendimentosModel( null, - $uniqueid, - CONF_EVENT_START, - 'now()', - 'now()', - $fila, - $agent[0]->id_usuario - ) - ); - if (!empty($retCria) && $event->evento != CONF_EVENT_START) { - $action = new AtualizaStatusAgenteAction; - $action(SupervisorModel::ArrayTo(json_decode(json_encode($agent[0]), true))); - $this->systemMessageAction->__invoke( - CONF_MOMENT_INICIAR_ATENDIMENTO, + $uniqueid, + CONF_EVENT_START, + 'now()', + 'now()', + $fila, + $agent[0]->id_usuario + ) + ); + if (!empty($retCria) && $event->evento != CONF_EVENT_START) { + $action = new AtualizaStatusAgenteAction; + $action(SupervisorModel::ArrayTo(json_decode(json_encode($agent[0]), true))); + $this->systemMessageAction->__invoke( + CONF_MOMENT_INICIAR_ATENDIMENTO, [["nome" => "@agente_name", "valor" => utf8_encode($agent[0]->nome)]], - $api, - $numero_client, - $fila - ); - $api->enviarMsg( - $numero_client, - "Número do protocolo do atendimento é $protocol\n" - ); - $ws = new WsInterface(); - try { - if ($event->evento == CONF_EVENT_ERRO_ATEND) { - $ws->enviaMsg($ws->enviaActions( - 'Este atendimento foi realocado para sua responsabilidade.', - 're_start', - $agent[0]->id_empresa, - $uniqueid - )); - $this->messageRepository->addMessage( - $uniqueid, - $agent[0]->matricula, - $agent[0]->matricula, - 're_start', - 'Este atendimento foi realocado para sua responsabilidade.', - $agent[0]->nome, - $api->getchannel(), - 'read' - ); - } - else { - $ws->enviaMsg($ws->enviaActions('Atendimento iniciado!', 'start', $agent[0]->matricula, $uniqueid)); - } - } - catch (\Exception $th) { - $ws->enviaActions('Atendimento iniciado!', 'start', $agent[0]->matricula, $uniqueid); + $api, + $numero_client, + $fila + ); + $api->enviarMsg( + $numero_client, + "Número do protocolo do atendimento é $protocol\n" + ); + $ws = new WsInterface(); + try { + if ($event->evento == CONF_EVENT_ERRO_ATEND) { + $ws->enviaMsg($ws->enviaActions( + 'Este atendimento foi realocado para sua responsabilidade.', + 're_start', + $agent[0]->id_empresa, + $uniqueid + )); + $this->messageRepository->addMessage( + $uniqueid, + $agent[0]->matricula, + $agent[0]->matricula, + 're_start', + 'Este atendimento foi realocado para sua responsabilidade.', + $agent[0]->nome, + $api->getchannel(), + 'read' + ); + } else { + $ws->enviaMsg($ws->enviaActions('Atendimento iniciado!', 'start', $agent[0]->matricula, $uniqueid)); } + } catch (\Exception $th) { + $ws->enviaActions('Atendimento iniciado!', 'start', $agent[0]->matricula, $uniqueid); } + } $this->atendimentoRepository->db->commit(); return; } catch (\Throwable $th) { $this->atendimentoRepository->db->rollback(); throw new Exception($th->getMessage(), 1); - } } } \ No newline at end of file diff --git a/app/Actions/FinalizarAtemdimentoAction.php b/app/Actions/FinalizarAtemdimentoAction.php index ca59464..de07e38 100644 --- a/app/Actions/FinalizarAtemdimentoAction.php +++ b/app/Actions/FinalizarAtemdimentoAction.php @@ -3,6 +3,7 @@ namespace app\Actions; use app\Core\UtilsChannel; +use app\Interfaces\IApiMedia; use app\Models\AtendimentoModel; use app\Models\EventosAtendimentosModel; use app\Models\SupervisorModel; @@ -21,16 +22,17 @@ class FinalizarAtemdimentoAction protected SupervisorRepository $supervisorRepository; protected MessageRepository $messageRepository; + protected ?IApiMedia $provedor; - - function __construct() + function __construct(?IApiMedia $provedor) { $this->eventosAtendimentosRepository = new EventosAtendimentoRepository; $this->numberChannelRepository = new NumberChannelRepository; $this->supervisorRepository = new SupervisorRepository; $this->atendimentoRepository = new AtendimentoRepository; $this->messageRepository = new MessageRepository; + $this->provedor = $provedor; } function __invoke(String $uniqueid, ?String $matricula_agente, string $eventoType) { @@ -72,8 +74,10 @@ class FinalizarAtemdimentoAction $ws = new WsInterface(); $mesg = $this->returnMessageWhatsapp($eventoType); - $number = $this->numberChannelRepository->get(['id' => $atendimento->id_number_channel]); - $provedor = UtilsChannel::factoryChannel($number); + if (empty($this->provedor)) { + $number = $this->numberChannelRepository->get(['id' => $atendimento->id_number_channel]); + $this->provedor = UtilsChannel::factoryChannel($number); + } $this->messageRepository->addMessage( $atendimento->uniqueid, @@ -95,7 +99,7 @@ class FinalizarAtemdimentoAction $systemMessageAction( momento: CONF_MOMENT_FINALIZAR_ATENDIMENTO, variavels: [["nome" => "@autor_name", "valor" => $agente->nome]], - api: $provedor, + api: $this->provedor, numero: $atendimento->cliente_id ); $ws->enviaMsg($ws->enviaActions($mesg, 'finish', $agente->matricula, $atendimento->uniqueid)); diff --git a/app/Controllers/AtendimentosController.php b/app/Controllers/AtendimentosController.php index 2075050..93f43c9 100644 --- a/app/Controllers/AtendimentosController.php +++ b/app/Controllers/AtendimentosController.php @@ -86,7 +86,7 @@ class AtendimentosController extends Controller implements IModule if (empty($body['matricula'])) { throw new Exception("Parametro matricula é obrigatório"); } - $action = new FinalizarAtemdimentoAction(); + $action = new FinalizarAtemdimentoAction(null); $ret = $action($body['uniqueid'], $body['matricula'], CONF_EVENT_TIMERMINO_AGENTE); diff --git a/app/Controllers/WebhookController.php b/app/Controllers/WebhookController.php index dd97980..e969c31 100644 --- a/app/Controllers/WebhookController.php +++ b/app/Controllers/WebhookController.php @@ -53,7 +53,7 @@ class WebhookController extends Controller implements IModule static function route() { return function (RouteCollectorProxy $group) { - $group->any('/whatsapp/{number}', [self::class , 'inicia']); + $group->any('/whatsapp/{number}', [self::class, 'inicia']); }; } @@ -62,6 +62,9 @@ class WebhookController extends Controller implements IModule try { $body = json_decode($request->getBody()->getContents(), true); + if (empty($body)) { + $body = $request->getParsedBody(); + } logger('webhook')->info(var_export($body, true)); $number = $this->numberChannelRepository->get($args); @@ -71,9 +74,11 @@ class WebhookController extends Controller implements IModule if (!$this->api->getIsValidMessage()) { $response->getBody()->write( - $this->retorno('Sucesso', - true - )); + $this->retorno( + 'Sucesso', + true + ) + ); return $response; } if (!$this->api->baixarMidia()) { @@ -82,20 +87,24 @@ class WebhookController extends Controller implements IModule // VERIFICA SE ? UM COMANDO if ($this->commands->isCommand($this->api)) { $response->getBody()->write( - $this->retorno('Sucesso', - true - )); + $this->retorno( + 'Sucesso', + true + ) + ); return $response; } //verifica se tem atendimento em aberto, se tiver ja manda msg para o agente via ws - $atendiment = $this->atendimentoRepository->findAtenEmAberto($this->api->getPhone()); + $atendiment = $this->atendimentoRepository->findAtenEmAberto($this->api->getPhone(), $number->id); if ($atendiment) { $this->enviaMensagemAgente($atendiment); $response->getBody()->write( - $this->retorno('Sucesso', - true - )); + $this->retorno( + 'Sucesso', + true + ) + ); return $response; } //verifica se tem atendimento em espera, se tiver ja mostra a sua posi��o na fila @@ -112,9 +121,11 @@ class WebhookController extends Controller implements IModule $this->api->enviarMsg($this->api->getPhone(), $filaAtualClient['MESSAGE']); } $response->getBody()->write( - $this->retorno('Sucesso', - true - )); + $this->retorno( + 'Sucesso', + true + ) + ); return $response; } //verifica se o cliente escolheu uma fila caso n�o escolheu manda as filas @@ -123,31 +134,35 @@ class WebhookController extends Controller implements IModule //manda as mensagens personalizada do moment CONF_MOMENT_SAUDACAO $this->systemMessageAction( CONF_MOMENT_SAUDACAO, - [["nome" => "@cliente_name", "valor" => $this->api->getProfile()]], + [["nome" => "@cliente_name", "valor" => $this->api->getProfile()]], $this->api, $this->api->getPhone() ); $this->api->enviarMsg($this->api->getPhone(), $filas['LIST']); $response->getBody()->write( - $this->retorno('Sucesso', - true - )); + $this->retorno( + 'Sucesso', + true + ) + ); return $response; } // cria a atendimento $this->criaAtendimentoAction($filas['QUEUE'], $this->api->getPhone(), null, $this->api); $response->getBody()->write( - $this->retorno('Sucesso', - true - )); - } - catch (Throwable $th) { + $this->retorno( + 'Sucesso', + true + ) + ); + } catch (Throwable $th) { logger('WebhookController.inicia')->error($th->getMessage()); $response->getBody()->write( - $this->retorno($th->getMessage(), - false, - [$th->getTraceAsString()] - ) + $this->retorno( + $th->getMessage(), + false, + [$th->getTraceAsString()] + ) ); } return $response; @@ -178,18 +193,18 @@ class WebhookController extends Controller implements IModule ); $ws->enviaMsg( $ws->convertToWebsocket( - $this->retornaConteudo(), - $atendiment->matricula, - $atendiment->uniqueid, - $this->api->getType(), - $this->api->getProfile(), - $this->api->getPhone(), - time(), - $this->api->getId(), - $this->api->getMimetype(), - $this->api->retornaTituloDocument(), - $this->api->getchannel() - ) + $this->retornaConteudo(), + $atendiment->matricula, + $atendiment->uniqueid, + $this->api->getType(), + $this->api->getProfile(), + $this->api->getPhone(), + time(), + $this->api->getId(), + $this->api->getMimetype(), + $this->api->retornaTituloDocument(), + $this->api->getchannel() + ) ); } public function retornaConteudo() diff --git a/app/Core/Commands.php b/app/Core/Commands.php index 342d322..7c71f3d 100644 --- a/app/Core/Commands.php +++ b/app/Core/Commands.php @@ -62,7 +62,7 @@ class Commands { try { $this->atendimentoRepository->db->begin(); - $atendimento = $this->atendimentoRepository->get(['client_id' => $numero, 'evento' => CONF_EVENT_START]); + $atendimento = $this->atendimentoRepository->get(['client_id' => $numero, 'evento' => CONF_EVENT_START, 'id_number_channel' => $this->api->getNumberChannel()->id]); //verifica se existe atendimento if (empty($atendimento)) { $this->atendimentoRepository->db->rollback(); @@ -70,7 +70,7 @@ class Commands return true; } - $action = new FinalizarAtemdimentoAction; + $action = new FinalizarAtemdimentoAction($this->api); $ret = $action($atendimento->uniqueid, $atendimento->matricula, CONF_EVENT_TIMERMINO_CLIENTE); if ($ret) { @@ -82,7 +82,7 @@ class Commands } } catch (\Exception $th) { $this->atendimentoRepository->db->rollback(); - $this->api->enviarMsg($numero, CONF_NAME_REPONSE . " : Erro ao finalizar! "); + $this->api->enviarMsg($numero, CONF_NAME_REPONSE . " : " . $th->getMessage()); return true; } } diff --git a/app/Core/UtilsChannel.php b/app/Core/UtilsChannel.php index 0398582..9615f72 100644 --- a/app/Core/UtilsChannel.php +++ b/app/Core/UtilsChannel.php @@ -1,5 +1,7 @@ number = $number; + } function getContentType() { return 'text/xml'; } - function getchannel() + function getchannel(): string { return CONF_WHATSAPP_CHANNEL; } function enviarMedia($whatsapp, $link, $type, $titulo = null) { /* - twilio só suporta esses formatos. + 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); + $twilio = new Client($this->number->work_space, $this->number->token); $message = $twilio->messages->create( "whatsapp:+$whatsapp", // to [ - "from" => "whatsapp:+{$this->numeroTwilio}", + "from" => "whatsapp:+{$this->number->number}", "mediaUrl" => [$link] ] ); @@ -49,29 +53,17 @@ class ApiTwilio implements IApiMedia if ($encode) { $mensagem = utf8_encode($mensagem); } - $twilio = new Client($this->sid, $this->token); + $twilio = new Client($this->number->work_space, $this->number->token); $message = $twilio->messages->create( "whatsapp:+$whatsapp", // to [ - "from" => "whatsapp:+{$this->numeroTwilio}", + "from" => "whatsapp:+{$this->number->number}", "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(); @@ -79,7 +71,7 @@ class ApiTwilio implements IApiMedia return true; } logger('baixarMidia')->info('url: ' . $this->hook['MediaUrl0']); - $request->setToken(base64_encode("{$this->sid}:{$this->token}")); + $request->setToken(base64_encode("{$this->number->work_space}:{$this->number->token}")); $request->setUrl($this->hook['MediaUrl0']); $name = $this->getId(); $request->requestType("GET"); @@ -134,92 +126,12 @@ class ApiTwilio implements IApiMedia { $this->hook['Body'] = $msg; } - function getContactFormatted() - { - return false; - } - function getContactPhone() - { - return false; - } - function getGeolocation($type) - { - return false; - } - function setHook($hook) + + function setHook(array $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; + $this->hook = $hook; } function retornaTituloDocument() { @@ -228,4 +140,8 @@ class ApiTwilio implements IApiMedia } return $this->hook['Body']; } + function getNumberChannel(): NumberChannelModel + { + return $this->number; + } } \ No newline at end of file diff --git a/app/Providers/Positus.php b/app/Providers/Positus.php index 4c41a43..3f274a0 100644 --- a/app/Providers/Positus.php +++ b/app/Providers/Positus.php @@ -45,11 +45,13 @@ class Positus implements IApiMedia $header = []; $header['Authorization'] = "Bearer {$this->number->token}"; $header['Content-Type'] = "application/json"; - return $this->clientReq->post("messages", - [ - 'body' => json_encode($params), - 'headers' => $header, - ]); + return $this->clientReq->post( + "messages", + [ + 'body' => json_encode($params), + 'headers' => $header, + ] + ); } function enviarMsg($whatsapp, $mensagem, $encode = true) @@ -70,11 +72,13 @@ class Positus implements IApiMedia 'headers' => $header, ], true)); - return $this->clientReq->post("$this->url{$this->number->number}/messages", - [ - 'body' => json_encode($params), - 'headers' => $header, - ]); + return $this->clientReq->post( + "$this->url{$this->number->number}/messages", + [ + 'body' => json_encode($params), + 'headers' => $header, + ] + ); } function enviarHSM($numero, $namespace, $nameTemplate, $parametrosHeader = [], $parametrosBody = []) @@ -103,11 +107,13 @@ class Positus implements IApiMedia ); $header = []; $header['Authorization'] = "Bearer {$this->number->token}"; - return $this->clientReq->post('messages', - [ - 'body' => $params, - 'headers' => $header, - ]); + return $this->clientReq->post( + 'messages', + [ + 'body' => $params, + 'headers' => $header, + ] + ); } function baixarMidia() @@ -119,10 +125,12 @@ class Positus implements IApiMedia $pathfile = $this->storage . $name; $header = []; $header['Authorization'] = "Bearer {$this->number->token}"; - $retorno = $this->clientReq->get('media/' . $name, - [ - 'headers' => $header, - ]); + $retorno = $this->clientReq->get( + 'media/' . $name, + [ + 'headers' => $header, + ] + ); file_put_contents($pathfile, $retorno->getBody()->getContents()); if (file_exists($pathfile)) { return true; @@ -210,8 +218,7 @@ class Positus implements IApiMedia return $this->hook['messages'][0]['interactive']['list_reply']['description']; } return $this->hook['messages'][0]['interactive']['list_reply']['title']; - } - else { + } else { return $this->hook['messages'][0]['interactive']['button_reply']['title']; } } @@ -222,44 +229,6 @@ class Positus implements IApiMedia { $this->hook['messages'][0]['text']['body'] = $msg; } - /** - * Returns the name of the contact - * @return string|boolean - */ - function getContactFormatted() - { - $formatted = $this->hook['messages'][0]['contacts'][0]['name']['formatted_name']; - if ($formatted) { - return $formatted; - } - return false; - } - - /** - * Returns the phone of the contact - * @return string|boolean - */ - function getContactPhone() - { - $contact = $this->hook['messages'][0]['contacts'][0]['phones'][0]['wa_id']; - if ($contact) { - return $contact; - } - return false; - } - - /** - * Returns the latitude|longitude of the location - * @return string|boolean - */ - function getGeolocation($type) - { - $geolocation = $this->hook['messages'][0]['location'][strtolower($type)]; - if ($geolocation) { - return $geolocation; - } - return false; - } function retornaTituloDocument() { diff --git a/app/Repositories/AtendimentoRepository.php b/app/Repositories/AtendimentoRepository.php index 98a6512..42d1d81 100644 --- a/app/Repositories/AtendimentoRepository.php +++ b/app/Repositories/AtendimentoRepository.php @@ -58,7 +58,7 @@ class AtendimentoRepository extends Repository return $this->db->read($query, $data)->fetchAll(); } - public function findAtenEmAberto($cliente_id = null) + public function findAtenEmAberto($cliente_id = null, $id_number_channel = null) { $table = $this->table; $tableEventosAtendimento = EventosAtendimentosModel::$table; @@ -66,11 +66,16 @@ class AtendimentoRepository extends Repository WHERE (SELECT m2.evento FROM $tableEventosAtendimento m2 WHERE ma.uniqueid = m2.uniqueid ORDER BY id DESC LIMIT 1) = 'START' AND ma.matricula notnull "; $data = []; + if ($id_number_channel) { + $data['id_number_channel'] = $id_number_channel; + $query .= ' AND ma.id_number_channel = :id_number_channel'; + } if ($cliente_id) { $data['cliente_id'] = $cliente_id; - $query .= 'AND ma.cliente_id = :cliente_id'; + $query .= ' AND ma.cliente_id = :cliente_id'; return $this->db->read($query, $data)->fetch(); } + return $this->db->read($query, $data)->fetchAll(); } diff --git a/service/ServiceTimeout.php b/service/ServiceTimeout.php index 901b977..bff4312 100644 --- a/service/ServiceTimeout.php +++ b/service/ServiceTimeout.php @@ -126,7 +126,7 @@ class ServiceTimeout implements IService $atendimento = $this->atendimentoRepository->get(['cliente_id' => $numero, 'evento' => CONF_EVENT_START]); //cria o evento pra finalizar - $action = new FinalizarAtemdimentoAction; + $action = new FinalizarAtemdimentoAction(null); $ret = $action($atendimento->uniqueid, $atendimento->matricula, CONF_EVENT_TIMEOUT_CLIENTE); if ($ret) { return true;