Ajustes para mensagens fora do expediente

adriano 2023-08-21 15:59:42 -03:00
parent 763d707ca5
commit 05faebe89c
1 changed files with 44 additions and 38 deletions

View File

@ -53,7 +53,6 @@ import BotIsOnQueue from "../../helpers/BotIsOnQueue";
import Queue from "../../models/Queue"; import Queue from "../../models/Queue";
import SettingTicket from "../../models/SettingTicket"; import SettingTicket from "../../models/SettingTicket";
import fs from "fs"; import fs from "fs";
import { StartWhatsAppSession } from "../../services/WbotServices/StartWhatsAppSession"; import { StartWhatsAppSession } from "../../services/WbotServices/StartWhatsAppSession";
@ -1236,53 +1235,60 @@ const handleMessage = async (msg: any, wbot: any): Promise<void> => {
await setMessageAsRead(ticket); await setMessageAsRead(ticket);
} }
let ticketHasQueue = false; let ticketHasQueue = false;
if (ticket?.queueId) { if (
ticketHasQueue = true; 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) { if (ticketHasQueue) {
// MESSAGE TO HOLIDAY // MESSAGE TO HOLIDAY
const holiday: any = await isHoliday(); const holiday: any = await isHoliday();
if (holiday && holiday.set) { if (holiday && holiday.set) {
if (msg.fromMe && holiday.msg == msg.body) { if (msg.fromMe && holiday.msg == msg.body) {
console.log("HOLIDAY MESSAGE IGNORED"); console.log("HOLIDAY MESSAGE IGNORED");
return; return;
} }
botSendMessage(ticket, holiday.msg); botSendMessage(ticket, holiday.msg);
return; return;
} }
// MESSAGES TO SATURDAY OR SUNDAY // MESSAGES TO SATURDAY OR SUNDAY
const weekend: any = await isWeekend(); const weekend: any = await isWeekend();
if (weekend && weekend.set) { if (weekend && weekend.set) {
if (msg.fromMe && weekend.msg == msg.body) { if (msg.fromMe && weekend.msg == msg.body) {
console.log("WEEKEND MESSAGE IGNORED"); console.log("WEEKEND MESSAGE IGNORED");
return; return;
} }
botSendMessage(ticket, weekend.msg); botSendMessage(ticket, weekend.msg);
return; return;
} }
// MESSAGE TO BUSINESS TIME // MESSAGE TO BUSINESS TIME
const businessTime = await isOutBusinessTime(); const businessTime = await isOutBusinessTime();
if (businessTime && businessTime.set) { if (businessTime && businessTime.set) {
if (msg.fromMe && businessTime.msg == msg.body) { if (msg.fromMe && businessTime.msg == msg.body) {
console.log("BUSINESS TIME MESSAGE IGNORED"); console.log("BUSINESS TIME MESSAGE IGNORED");
return; return;
} }
botSendMessage(ticket, businessTime.msg);
return;
}
}
botSendMessage(ticket, businessTime.msg);
return;
}
}
} catch (err) { } catch (err) {
Sentry.captureException(err); Sentry.captureException(err);
console.log("xxxxxxxxxxxxx err: ", err); console.log("xxxxxxxxxxxxx err: ", err);