eventosModel = new Evento(); $this->atendimentoModel = new Atendimento(); $this->supervisor = new SupervisorModel(); $this->queue = new QueueController(); $this->systemController = new SystemMessageController(); } function router($rota, $request) { $request = json_decode($request, true); switch ($rota) { case 'listarAgentesDisponivel': $this->listaAgentesDisponivel(); break; case 'removerAtendimentoFila': $this->removerAtendimentoFila($request); 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 removerAtendimentoFila($request) { try { $atendimento = $this->atendimentoModel->findAtendId($request['uniqueid']); logger()->error(print_r($request, true)); $this->api = returnChannel($atendimento->context); $ret = $this->eventosModel->createEvento( $atendimento->uniqueid, CONF_EVENT_ABANDONADA, date('Y-m-d H:i:s'), date('Y-m-d H:i:s'), $atendimento->fila ); if ($ret) { //envia as mensagens do sistema do momento atual para o cliente $this->systemController->sendMessageSystem( CONF_MOMENT_CANCELAR_FILA, [], $this->api, $atendimento->cliente_id ); $filas = $this->queue->listAllQueueWhatsApp($this->api->getMessage()); if ($filas['LIST']) { $this->api->enviarMsg($atendimento->cliente_id, $filas['LIST']); } $this->retorno( $ret ? "Sucesso" : "Erro", $ret ? $ret : null, ); } else { $this->retorno("Não foi possível cancelar o atendimento!"); } } 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); } }