From d253b62b521c4675f0333190efaaf22614a6506b Mon Sep 17 00:00:00 2001 From: awade Date: Mon, 6 Mar 2023 20:24:35 +0000 Subject: [PATCH] ajustes de funcionalidades --- index copy.php | 73 ++++++++++++++++++++++++++++++++++++++ index.php | 82 ++++++++++++++++++++++++++++++++++--------- public/js/config.js | 5 +++ public/js/main.js | 13 ++++++- public/js/requests.js | 35 ++++++++++++------ public/js/util.js | 27 +++++++------- ws.php | 67 +++++++++++++++++++++++++++++++++++ 7 files changed, 260 insertions(+), 42 deletions(-) create mode 100644 index copy.php create mode 100644 ws.php diff --git a/index copy.php b/index copy.php new file mode 100644 index 0000000..8251e53 --- /dev/null +++ b/index copy.php @@ -0,0 +1,73 @@ + null, + 'my_uniqueid' => null, + 'obj_queue' => null, + 'obj_ws' => null, + 'supervisor_api' => null, + 'session_uniqueid' => null, + 'obj_notification' => null, + 'obj_contact' => null, + 'obj_status' => null, + 'session_window' => null +]; + +if ($geturl['t'] == 'gerar' && ($_SERVER['SERVER_NAME'] == 'localhost' || $geturl['password'] == 'S1MPL3S1P_CH4T')) { + foreach ($objs as $key => $val) { + $jsStartup[] = "localStorage.removeItem('{$key}')"; + } + $dados = true; +} + +if ($post) { + $objs['id_empresa'] = $post['empresa']; + $objs['obj_server'] = "http://{$post['servidor']}"; + $objs['my_uniqueid'] = $post['matricula']; + $objs['obj_queue'] = $post['fila']; + $objs['obj_ws'] = "ws://{$post['servidor']}:8080/wss"; + $objs['supervisor_api'] = "http://{$post['servidor']}"; + + foreach ($objs as $key => $val) { + $jsStartup[] = "localStorage.removeItem('{$key}')"; + if ($val) { + $jsStartup[] = sprintf("localStorage.setItem('{$key}', '%s')", $val); + } + } + $connected = true; +} + +?> + + + + + +
+

Informe o id da empresa:

+
+

Informe o Servidor:

+
+

Informe a Matricula:

+
+

Informe a fila:

+
+ +
+ + + + + + + \ No newline at end of file diff --git a/index.php b/index.php index c110175..2248148 100644 --- a/index.php +++ b/index.php @@ -7,37 +7,61 @@ use app\Provider\Crypt; $files = getconfig('app')['FILES']; $crypt = new Crypt('aes-256-cbc', getconfig('app')['PASSWORD']); $geturl = bootstrap(); +$post = is_postback(); $connected = false; -if($geturl['t'] == 'gerar' && ($_SERVER['SERVER_NAME'] == 'localhost' || $geturl['password'] == 'S1MPL3S1P_CH4T')){ - $expireToken = strtotime( '+1 days', time()); - $json_info = '{"servidor": "http://192.168.115.244:8081", "websocket": "ws://192.168.115.244:8081/wss", "matricula": "2424", "fila": "1", "expire": "'.$expireToken.'"}'; - echo $json_info; - echo "

"; - echo "Token: "; +if ($geturl['t'] == 'gerar' && $post['passwd'] == 'S1MPL3S1P_CH4T') { + $expireToken = strtotime("+{$post['expire']} days", time()); + $info = [ + "id_number" => $post['id_number'], + "id_empresa" => $post['id_empresa'], + "servidor" => $post['servidor'], + "websocket" => "ws://{$post['servidor']}:8080", + "matricula" => $post['matricula'], + "fila" => $post['fila'], + "expire" => $expireToken + ]; + $token = $crypt->encrypt(json_encode($info, true)); + echo "Token:

"; + echo "Ir para"; exit; } -$json = json_decode($crypt->decrypt(str_replace(' ', '+', $geturl['t'])), true); -if($geturl['t'] && $json ){ +/** + id_empresa + id_number + my_uniqueid + obj_queue + obj_server + obj_ws + **/ + +if ($geturl['t']) { $json = json_decode($crypt->decrypt(str_replace(' ', '+', $geturl['t'])), true); $objs = [ +<<<<<<< HEAD 'id_empresa' => $json['id_empresa'], 'obj_server' => $json['servidor'], 'my_uniqueid' => $json['matricula'], 'obj_queue' => $json['fila'], +======= + 'id_number' => $json['id_number'], + 'id_empresa' => $json['id_empresa'], + 'obj_server' => $json['servidor'], + 'my_uniqueid' => $json['matricula'], + 'obj_queue' => $json['fila'], +>>>>>>> 1e181ff (ajustes de funcionalidades) 'obj_ws' => $json['websocket'], - 'supervisor_api' => $json['api'], - 'session_uniqueid' => null, - 'obj_notification' => null, - 'obj_contact' => null, - 'obj_status' => null, + 'session_uniqueid' => null, + 'obj_notification' => null, + 'obj_contact' => null, + 'obj_status' => null, 'session_window' => null ]; - foreach($objs as $key => $val){ + foreach ($objs as $key => $val) { $jsStartup[] = "localStorage.removeItem('{$key}')"; - if($val){ + if ($val) { $jsStartup[] = sprintf("localStorage.setItem('{$key}', '%s')", $val); } } @@ -47,8 +71,32 @@ if($geturl['t'] && $json ){ - + + - + + +
+

Informe o id da empresa:

+
+

Informe o id do numero:

+
+

Informe o Servidor:

+
+

Informe a Matricula:

+
+

Informe a fila:

+
+

Token expira dias:

+
+

Password To generate token:

+
+ + +
+ + + + \ No newline at end of file diff --git a/public/js/config.js b/public/js/config.js index f035a35..a796ed2 100644 --- a/public/js/config.js +++ b/public/js/config.js @@ -1,5 +1,10 @@ const ws = localStorage.getItem('obj_ws') +<<<<<<< HEAD const server_api = localStorage.getItem('obj_server') +======= +const server_api = `http://${localStorage.getItem('obj_server')}` +const supervisor_api = localStorage.getItem('supervisor_api') ? localStorage.getItem('supervisor_api') : localStorage.getItem('obj_server') +>>>>>>> 1e181ff (ajustes de funcionalidades) let mediaRecorder const icontypes = ['csv', 'doc', 'pdf', 'txt', 'xls', 'zip', 'ppt'] const path = 'public' \ No newline at end of file diff --git a/public/js/main.js b/public/js/main.js index 0a80f63..9cc6c80 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -90,9 +90,15 @@ const selectNotification = (id) => { let protocolo const dataRequest = JSON.parse(localStorage.getItem('obj_contact')) +<<<<<<< HEAD listarAtendimentoAgente(localStorage.getItem('my_uniqueid')) +======= + listarAtendimentoAgente(localStorage.getItem('id_empresa'), localStorage.getItem('my_uniqueid')) +>>>>>>> 1e181ff (ajustes de funcionalidades) const allNotifications = JSON.parse(localStorage.getItem('obj_notification')) + + console.log(allNotifications) hideButtons(false) allNotifications.data.forEach(e => { @@ -142,7 +148,11 @@ const selectNotification = (id) => { dataContact.forEach(e => { const datesend = e.msg_date ? converdata(new Date(e.msg_date).getTime()) : 'algumas horas'; +<<<<<<< HEAD let typesend = localStorage.getItem('my_uniqueid') == e.src ? 'sender': 'receiver' +======= + let typesend = localStorage.getItem('my_uniqueid') == e.dst ? 'receiver' : 'sender' +>>>>>>> 1e181ff (ajustes de funcionalidades) if(e.type == 'text'){ $('.chat-window').append(` @@ -288,6 +298,7 @@ const sendMessage = (obj = {}) => { /** * ATUALIZA AS MENSAGEM QUE SAO RECEBIDAS NA TELA DO ATENDIMENTO + * Os dados são transmitidos pelo evento de WS * @param {*} ev */ const viewMessage = (ev) => { @@ -349,7 +360,7 @@ const receiveNotification = (data) => { } /** VALIDA O NUMERO, VERIFICA SE O TEM ALGMA MSG INICIAL, SE JA TEVE UM NUMERO NA VERIFICACAO */ - listarAtendimentoAgente(localStorage.getItem('my_uniqueid')) + listarAtendimentoAgente(localStorage.getItem('id_empresa'), localStorage.getItem('my_uniqueid')) validate = JSON.parse(localStorage.getItem('obj_notification')) const vald = validate.data.filter((e) => { diff --git a/public/js/requests.js b/public/js/requests.js index b565ee9..3429d67 100644 --- a/public/js/requests.js +++ b/public/js/requests.js @@ -14,11 +14,14 @@ const enviarMensagem = (dataSend) => { const listaMensagem = (uniqueid) => new Promise((resolve) => { $.ajax({ - url: `${server_api}/messages`, + url: `${server_api}/messages/${uniqueid}`, type: "GET", +<<<<<<< HEAD data: { uniqueid }, +======= +>>>>>>> 1e181ff (ajustes de funcionalidades) success: function (res) { localStorage.removeItem('obj_contact') localStorage.setItem('obj_contact', JSON.stringify(res)) @@ -32,12 +35,15 @@ const listaMensagem = (uniqueid) => new Promise((resolve) => { const listarAgentesDisponivel = (id_empresa) => new Promise((resolve) => { $.ajax({ - url: `${server_api}/supervisor`, + url: `${server_api}/supervisor/agentes/status/${id_empresa}/livre`, type: "GET", +<<<<<<< HEAD data: { id_empresa, agente_livre: "true" }, +======= +>>>>>>> 1e181ff (ajustes de funcionalidades) success: function (res) { resolve(res) }, @@ -47,13 +53,16 @@ const listarAgentesDisponivel = (id_empresa) => new Promise((resolve) => { }); }) -const listarAtendimentoAgente = (matricula) => new Promise((resolve) => { +const listarAtendimentoAgente = (id_empresa, matricula) => new Promise((resolve) => { $.ajax({ - url: `${server_api}/atendimentos`, + url: `${server_api}/atendimentos/${id_empresa}/${matricula}`, type: "GET", +<<<<<<< HEAD data: { matricula }, +======= +>>>>>>> 1e181ff (ajustes de funcionalidades) success: function (res) { localStorage.removeItem('obj_notification') localStorage.setItem('obj_notification', JSON.stringify(res)) @@ -67,11 +76,14 @@ const listarAtendimentoAgente = (matricula) => new Promise((resolve) => { const listarPausasAgente = (id_empresa) => new Promise((resolve) => { $.ajax({ - url: `${server_api}/pausas`, + url: `${server_api}/pausas/${id_empresa}`, type: "GET", +<<<<<<< HEAD data: { id_empresa }, +======= +>>>>>>> 1e181ff (ajustes de funcionalidades) success: function (res) { resolve(res) }, @@ -120,14 +132,14 @@ const sairPausa = (matricula) => new Promise((resolve) => { }); }) -const entrar = (matricula, queue, empresa) => new Promise((resolve) => { +const entrar = (matricula, id_fila, id_number) => new Promise((resolve) => { $.ajax({ url: `${server_api}/auth/conectar-chat`, type: "POST", data: JSON.stringify({ - id_fila: queue, matricula, - id_empresa: empresa + id_fila, + "id_number_channel": id_number }), success: function (res) { resolve(res) @@ -189,14 +201,17 @@ const finalizarAtendimento = (matricula, uniqueid) => new Promise((resolve) => { }); }) -const statusAgente = (empresa, matricula) => new Promise((resolve) => { +const statusAgente = (id_empresa, matricula) => new Promise((resolve) => { $.ajax({ - url: `${server_api}/supervisor`, + url: `${server_api}/supervisor/agentes/${id_empresa}/${matricula}`, type: "GET", +<<<<<<< HEAD data: { matricula, id_empresa: empresa }, +======= +>>>>>>> 1e181ff (ajustes de funcionalidades) success: function(res) { localStorage.removeItem('obj_status') localStorage.setItem('obj_status', JSON.stringify(res)) diff --git a/public/js/util.js b/public/js/util.js index 52f5d83..819923a 100644 --- a/public/js/util.js +++ b/public/js/util.js @@ -1,4 +1,4 @@ -/** ROLAGEM DO SCROLL ATE NO FINAL DO CHAT */ +/** ROLAGEM DO SCROLL AT� NO FINAL DO CHAT */ const scrollDown = () => { $(".chat-window").animate({scrollTop: 99999 * $(this).height() }, 1); } @@ -64,7 +64,7 @@ const alertModal = (title, message) => { } /** - * HABILITA O ENVIO DE ARQUIVO DE IMAGENS E APRESENTA UMA MODAL PARA APRESENTA��O DA IMAGEM SELECIONADA + * HABILITA O ENVIO DE ARQUIVO DE IMAGENS E APRESENTA UMA MODAL PARA APRESENTACAO DA IMAGEM SELECIONADA */ const startSendImage = () => { modalStart() @@ -87,7 +87,7 @@ const startSendImage = () => { } /** - * HABILITA O ENVIO DE ARQUIVO DE IMAGENS E APRESENTA UMA MODAL PARA APRESENTA��O DA IMAGEM SELECIONADA + * HABILITA O ENVIO DE ARQUIVO DE IMAGENS E APRESENTA UMA MODAL PARA APRESENTACAO DA IMAGEM SELECIONADA */ const openImgModal = (link) => { modalStart() @@ -170,7 +170,7 @@ const startPause = () => { }) $('#footer-content-right').on('click', '#pausesend', () => { - entrarPausa($("#selectpause").val(), localStorage.getItem('my_uniqueid'), localStorage.getItem('id_empresa')).then(() => { + entrarPausa($("#selectpause").val(), localStorage.getItem('my_uniqueid')).then(() => { $('#modalselect').css({display: 'none'}) monitorPausaAgente() }) @@ -221,6 +221,7 @@ const exitSystem = () => { }) } + const startFinalizar = () => { $("#finalizaratendimento").on('click', function(){ if(confirm('Deseja realmente finalizar o atendimento?')){ @@ -363,7 +364,6 @@ const buildNotification = (data = {}) => { const datesend = converdata(data.datetime) const status = data.status == 0 ? 'opacity-3' : '' - return `
@@ -434,7 +434,7 @@ const notifications = (obj = {}) => { /** STATUS DO AGENTE */ monitorPausaAgente() - listarAtendimentoAgente(localStorage.getItem('my_uniqueid')).then((notification) => { + listarAtendimentoAgente(localStorage.getItem('id_empresa'), localStorage.getItem('my_uniqueid')).then((notification) => { let chatList = '' $('#chats').empty() @@ -465,11 +465,12 @@ const notifications = (obj = {}) => { chatList += buildNotification({ uniqueid: e.uniqueid, number: e.cliente_id, - media: e.media, + media: e.context, name: e.profile_name, datetime: e.data_reg, status: e.status, - protocolo: e.protocolo + protocolo: e.protocolo, + media: e.media }) }) $('#chats').append(chatList) @@ -497,11 +498,11 @@ const monitorPausaAgente = () => { } }) - $('#myuniqueid').text(localStorage.getItem('my_uniqueid').split('@', 2)[1]) + $('#myuniqueid').text(localStorage.getItem('my_uniqueid')) /** CONFIGURACAO NOME */ $('#nameagent').text(agente.data[0].nome) /** CONFIGURACAO FILA */ - $('#queueagente').text(agente.data[0].fila.toUpperCase()) + $('#queueagente').text(agente.data[0].fila) } }) } @@ -509,7 +510,7 @@ const monitorPausaAgente = () => { const supervisorAgente = () => { /** MONITORA AS CONFIGURACOES */ setInterval(() => { - statusAgente(localStorage.getItem('id_empresa'),localStorage.getItem('my_uniqueid')).then((agente) => { + statusAgente(localStorage.getItem('my_uniqueid')).then((agente) => { if (agente.status == 'error' && agente.message == 'Agente não encontrado') { window.close() } @@ -562,11 +563,9 @@ const connect = (wsserver) => { ws.addEventListener("message", e => { /** att: atualizacao do websocket */ - if(e.data != 'att'){ + if(e.data != 'att'){ const data = JSON.parse(e?.data) - console.log(data) - if(localStorage.getItem('session_uniqueid') == null){ localStorage.setItem('session_uniqueid', data.event.mensagem.uniqueid) } diff --git a/ws.php b/ws.php new file mode 100644 index 0000000..0271d46 --- /dev/null +++ b/ws.php @@ -0,0 +1,67 @@ + + + + WebSocket client test + + + +

WebSocket Client Test

+
+ + + \ No newline at end of file