From cf67523babba082bc6db63719eaeaa7ba1c8c25b Mon Sep 17 00:00:00 2001 From: adriano Date: Wed, 9 Aug 2023 18:03:38 -0300 Subject: [PATCH] =?UTF-8?q?Corre=C3=A7=C3=A3o=20para=20exibir=20mensagens?= =?UTF-8?q?=20de=20configura=C3=A7=C3=A3o=20de=20ticket=20apos=20transferi?= =?UTF-8?q?r=20o=20atendimento=20para=20fila?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/helpers/BotIsOnQueue.ts | 18 ++-- .../WbotServices/wbotMessageListener.ts | 83 +++++++++++-------- 2 files changed, 56 insertions(+), 45 deletions(-) diff --git a/backend/src/helpers/BotIsOnQueue.ts b/backend/src/helpers/BotIsOnQueue.ts index 62fbebb..bc19e2b 100644 --- a/backend/src/helpers/BotIsOnQueue.ts +++ b/backend/src/helpers/BotIsOnQueue.ts @@ -7,16 +7,16 @@ import ListUsersService from "../services/UserServices/ListUsersService"; import { isHoliday, isOutBusinessTime, isWeekend } from "./TicketConfig"; const _botIsOnQueue = async (botName: string) => { - // MESSAGE TO HOLIDAY - const holiday: any = await isHoliday(); - // MESSAGES TO SATURDAY OR SUNDAY - const weekend: any = await isWeekend(); - // MESSAGE TO BUSINESS TIME - const businessTime: any = await isOutBusinessTime(); + // // MESSAGE TO HOLIDAY + // const holiday: any = await isHoliday(); + // // MESSAGES TO SATURDAY OR SUNDAY + // const weekend: any = await isWeekend(); + // // MESSAGE TO BUSINESS TIME + // const businessTime: any = await isOutBusinessTime(); - if (holiday?.set || weekend?.set || businessTime?.set) { - return { isOnQueue: false }; - } + // if (holiday?.set || weekend?.set || businessTime?.set) { + // return { isOnQueue: false }; + // } const botInfoFile = dir.join(os.tmpdir(), `botInfo.json`); diff --git a/backend/src/services/WbotServices/wbotMessageListener.ts b/backend/src/services/WbotServices/wbotMessageListener.ts index 66cec08..ae7aee7 100644 --- a/backend/src/services/WbotServices/wbotMessageListener.ts +++ b/backend/src/services/WbotServices/wbotMessageListener.ts @@ -6,7 +6,7 @@ import * as Sentry from "@sentry/node"; import { copyFolder } from "../../helpers/CopyFolder"; import { removeDir } from "../../helpers/DeleteDirectory"; import path from "path"; - + import { isHoliday, isOutBusinessTime, @@ -99,8 +99,6 @@ import ShowQueryItemService from "../SLM/ShowQueryItemService"; import QueryItem from "../../models/QueryItem"; import SettingTicket from "../../models/SettingTicket"; - - var lst: any[] = getWhatsappIds(); interface Session extends Client { @@ -435,7 +433,7 @@ async function sendDelayedMessages( } else { botSendMessage( ticket, - `Ops! Não foi possível validar seu protocolo devido a um erro na comunicação com o servidor.Tente novamente mais tarde.\n_Digite *0* para falar com a HIT._` + `Ops! Não foi possível validar seu protocolo devido a um erro na comunicação com o servidor.Tente novamente mais tarde.\n_Digite *0* para voltar ao menu anterior._` ); } } @@ -476,7 +474,7 @@ async function sendDelayedMessages( if (response.trim().length == 0) { botSendMessage( ticket, - `Não existe nenhum chamado para essa operação!\n _Digite *0* para falar com a HIT._` + `Não existe nenhum chamado para essa operação!\n _Digite *0* para voltar ao menu anterior._` ); } else if (response.trim().length > 0) { let valid = await chamadoStatus(params[1]); @@ -508,7 +506,7 @@ async function sendDelayedMessages( } catch (error) { botSendMessage( ticket, - `Houve um erro ao realizar a consulta!\n _Digite *0* para falar com a HIT._` + `Houve um erro ao realizar a consulta!\n _Digite *0* para voltar ao menu anterior._` ); } } else if (msgAction.actions[0] == "queue_transfer") { @@ -609,7 +607,7 @@ const sendDialogflowAwswer = async ( if (msg.type != "chat") { botSendMessage( ticket, - `Desculpe, nao compreendi!\nEnvie apenas texto quando estiver interagindo com o bot!\n _Digite *0* para falar com a HIT._` + `Desculpe, nao compreendi!\nEnvie apenas texto quando estiver interagindo com o bot!\n _Digite *0* para voltar ao menu anterior._` ); return; } @@ -617,7 +615,7 @@ const sendDialogflowAwswer = async ( if (msg.type == "chat" && String(msg.body).length > 120) { botSendMessage( ticket, - `Desculpe, nao compreendi!\nTexto acima de 120 caracteres!\n _Digite *0* para falar com a HIT._` + `Desculpe, nao compreendi!\nTexto acima de 120 caracteres!\n _Digite *0* para voltar ao menu anterior._` ); return; } @@ -1239,52 +1237,65 @@ const handleMessage = async (msg: any, wbot: any): Promise => { await setMessageAsRead(ticket); } - // MESSAGE TO HOLIDAY - const holiday: any = await isHoliday(); + let ticketHasQueue = false; - if (holiday.set) { - if (msg.fromMe && holiday.msg == msg.body) { - console.log("HOLIDAY MESSAGE IGNORED"); + if ( + botInfo.isOnQueue && + ticket?.queueId && + botInfo.botQueueId != ticket?.queueId + ) { + console.log("BOT SECTION"); + ticketHasQueue = true; + } else if (!botInfo.isOnQueue && ticket?.queueId) { + console.log("NO BOT SECTION"); + ticketHasQueue = true; + } + + if (ticketHasQueue) { + // MESSAGE TO HOLIDAY + const holiday: any = await isHoliday(); + + if (holiday.set) { + if (msg.fromMe && holiday.msg == msg.body) { + console.log("HOLIDAY MESSAGE IGNORED"); + return; + } + + botSendMessage(ticket, holiday.msg); return; } - botSendMessage(ticket, holiday.msg); - return; - } + // MESSAGES TO SATURDAY OR SUNDAY + const weekend: any = await isWeekend(); - // MESSAGES TO SATURDAY OR SUNDAY - const weekend: any = await isWeekend(); + if (weekend.set) { + if (msg.fromMe && weekend.msg == msg.body) { + console.log("WEEKEND MESSAGE IGNORED"); + return; + } - if (weekend.set) { - if (msg.fromMe && weekend.msg == msg.body) { - console.log("WEEKEND MESSAGE IGNORED"); + botSendMessage(ticket, weekend.msg); return; } - botSendMessage(ticket, weekend.msg); - return; - } + // MESSAGE TO BUSINESS TIME + const businessTime = await isOutBusinessTime(); - // MESSAGE TO BUSINESS TIME - const businessTime = await isOutBusinessTime(); + if (businessTime.set) { + if (msg.fromMe && businessTime.msg == msg.body) { + console.log("BUSINESS TIME MESSAGE IGNORED"); + return; + } - if (businessTime.set) { - if (msg.fromMe && businessTime.msg == msg.body) { - console.log("BUSINESS TIME MESSAGE IGNORED"); + botSendMessage(ticket, businessTime.msg); return; } - - botSendMessage(ticket, businessTime.msg); - return; } - - } catch (err) { Sentry.captureException(err); console.log("xxxxxxxxxxxxx err: ", err); logger.error(`Error handling whatsapp message: Err: ${err}`); - } - + } }; const handleMsgAck = async (msg_id: any, ack: any) => {