From 05faebe89c213f4adf47da1044d5ac29659b8023 Mon Sep 17 00:00:00 2001 From: adriano Date: Mon, 21 Aug 2023 15:59:42 -0300 Subject: [PATCH] Ajustes para mensagens fora do expediente --- .../WbotServices/wbotMessageListener.ts | 82 ++++++++++--------- 1 file changed, 44 insertions(+), 38 deletions(-) diff --git a/backend/src/services/WbotServices/wbotMessageListener.ts b/backend/src/services/WbotServices/wbotMessageListener.ts index d1f4083..44b93b5 100644 --- a/backend/src/services/WbotServices/wbotMessageListener.ts +++ b/backend/src/services/WbotServices/wbotMessageListener.ts @@ -53,7 +53,6 @@ import BotIsOnQueue from "../../helpers/BotIsOnQueue"; import Queue from "../../models/Queue"; import SettingTicket from "../../models/SettingTicket"; - import fs from "fs"; import { StartWhatsAppSession } from "../../services/WbotServices/StartWhatsAppSession"; @@ -1236,53 +1235,60 @@ const handleMessage = async (msg: any, wbot: any): Promise => { await setMessageAsRead(ticket); } - let ticketHasQueue = false; + let ticketHasQueue = false; - if (ticket?.queueId) { - ticketHasQueue = true; - } + 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 (ticketHasQueue) { + // MESSAGE TO HOLIDAY + const holiday: any = await isHoliday(); - if (holiday && holiday.set) { - if (msg.fromMe && holiday.msg == msg.body) { - console.log("HOLIDAY MESSAGE IGNORED"); - return; - } + if (holiday && 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 && weekend.set) { - if (msg.fromMe && weekend.msg == msg.body) { - console.log("WEEKEND MESSAGE IGNORED"); - return; - } + if (weekend && weekend.set) { + if (msg.fromMe && weekend.msg == msg.body) { + console.log("WEEKEND MESSAGE IGNORED"); + return; + } - 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 && businessTime.set) { - if (msg.fromMe && businessTime.msg == msg.body) { - console.log("BUSINESS TIME MESSAGE IGNORED"); - return; - } - - botSendMessage(ticket, businessTime.msg); - return; - } - } + if (businessTime && businessTime.set) { + if (msg.fromMe && businessTime.msg == msg.body) { + console.log("BUSINESS TIME MESSAGE IGNORED"); + return; + } + botSendMessage(ticket, businessTime.msg); + return; + } + } } catch (err) { Sentry.captureException(err); console.log("xxxxxxxxxxxxx err: ", err);