From 853f537361de47185b29c6f074d7089ed6f4a1bc Mon Sep 17 00:00:00 2001 From: adriano Date: Wed, 7 Feb 2024 17:07:06 -0300 Subject: [PATCH 1/3] fix: Update frontend to prevent React.js emoji-related errors --- frontend/src/components/MessageInput/index.js | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/frontend/src/components/MessageInput/index.js b/frontend/src/components/MessageInput/index.js index 30c72d1..f760ff5 100644 --- a/frontend/src/components/MessageInput/index.js +++ b/frontend/src/components/MessageInput/index.js @@ -321,16 +321,33 @@ const MessageInput = ({ ticketStatus }) => { setTabOption('open') } - const message = { + if (templateParams) { + for (let key in templateParams) { + if (templateParams.hasOwnProperty(key)) { + // let value = templateParams[key] + // console.log('key: ', key, ' | ', 'VALUE: ', value) + + if (key === '_reactName') { + templateParams = null + break + } + } + } + } + + let message = { read: 1, fromMe: true, mediaUrl: "", - body: (signMessage && !templateParams) - ? `*${user?.name}:*\n${inputMessage.trim()}` - : inputMessage.trim(), - quotedMsg: replyingMessage, - params: templateParams + body: (signMessage && !templateParams) ? `*${user?.name}:*\n${inputMessage.trim()}` : inputMessage.trim(), + quotedMsg: replyingMessage } + + if (templateParams) { + message = { ...message, params: templateParams } + } + + try { const { data } = await api.post(`/messages/${ticketId}`, message) From 7bab4bf6b9743a7bf6b9387595cccbc1015f5e41 Mon Sep 17 00:00:00 2001 From: adriano Date: Wed, 7 Feb 2024 17:52:07 -0300 Subject: [PATCH 2/3] feat: Optimize database by reopening bot tickets instead of creating new ones --- .../WbotServices/wbotMessageListener.ts | 57 +++++++++++++++++-- 1 file changed, 51 insertions(+), 6 deletions(-) diff --git a/backend/src/services/WbotServices/wbotMessageListener.ts b/backend/src/services/WbotServices/wbotMessageListener.ts index 8047d02..8d60993 100644 --- a/backend/src/services/WbotServices/wbotMessageListener.ts +++ b/backend/src/services/WbotServices/wbotMessageListener.ts @@ -89,6 +89,8 @@ import SettingTicket from "../../models/SettingTicket"; import mostRepeatedPhrase from "../../helpers/MostRepeatedPhrase"; import ListWhatsAppsNumber from "../WhatsappService/ListWhatsAppsNumber"; import { createObject, findObject, get } from "../../helpers/RedisClient"; +import FindOrCreateTicketServiceBot from "../TicketServices/FindOrCreateTicketServiceBot" +import ShowTicketService from "../TicketServices/ShowTicketService" var lst: any[] = getWhatsappIds(); @@ -663,12 +665,39 @@ const handleMessage = async ( ) return; - const ticket = await FindOrCreateTicketService( - contact, - wbot.id!, - unreadMessages - // groupContact - ); + let ticket; + + const _botInfo = await BotIsOnQueue("botqueue"); + + if (_botInfo.isOnQueue) { + let ticket_obj: any = await FindOrCreateTicketServiceBot( + contact, + wbot.id!, + unreadMessages + // groupContact + ); + + ticket = ticket_obj.ticket; + + if (ticket_obj.created) { + let queue = await ShowQueueService(_botInfo.botQueueId); + + await UpdateTicketService({ + ticketData: { queueId: queue.id }, + ticketId: ticket.id + }); + + ticket = await ShowTicketService(ticket.id); + } + } else { + ticket = await FindOrCreateTicketService( + contact, + wbot.id!, + unreadMessages + // groupContact + ); + } + if (getSettingValue("oneContactChatWithManyWhats")?.value == "disabled") { // Para responder para o cliente pelo mesmo whatsapp que ele enviou a mensagen @@ -739,6 +768,22 @@ const handleMessage = async ( } else { console.log("MSG body: ", msg.body); + if (msg.type != "chat") { + botSendMessage( + ticket, + `Desculpe, nao compreendi!\nEnvie apenas texto quando estiver interagindo com o bot!\n _Digite *0* para voltar ao menu principal._` + ); + return; + } + + if (msg.type == "chat" && String(msg.body).length > 120) { + botSendMessage( + ticket, + `Desculpe, nao compreendi!\nTexto acima de 120 caracteres!\n _Digite *0* para voltar ao menu principal._` + ); + return; + } + const menuMsg: any = await menu(msg.body, wbot.id, contact.id); console.log("menuMsg: ", menuMsg); From c444012963ba430023e52e47acf56da8adbdeaf6 Mon Sep 17 00:00:00 2001 From: adriano Date: Thu, 8 Feb 2024 09:13:19 -0300 Subject: [PATCH 3/3] feat: Uncomment code to allow backend to send disk space information to frontend --- .../helpers/SchedulingNotifySendMessage.ts | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/backend/src/helpers/SchedulingNotifySendMessage.ts b/backend/src/helpers/SchedulingNotifySendMessage.ts index 78399d7..3ba8e8c 100644 --- a/backend/src/helpers/SchedulingNotifySendMessage.ts +++ b/backend/src/helpers/SchedulingNotifySendMessage.ts @@ -90,33 +90,33 @@ const monitor = async () => { } - // exec("df -h /", (error: any, stdout: any, stderr: any) => { + exec("df -h /", (error: any, stdout: any, stderr: any) => { - // if (error) { - // console.log(`exec error: ${error.message}`); - // return; - // } - // if (stderr) { - // console.log(`exec stderr: ${stderr}`); - // return; - // } + if (error) { + console.log(`exec error: ${error.message}`); + return; + } + if (stderr) { + console.log(`exec stderr: ${stderr}`); + return; + } - // stdout = stdout.split(/\r?\n/) - // stdout = stdout[1].trim().split(/\s+/) + stdout = stdout.split(/\r?\n/) + stdout = stdout[1].trim().split(/\s+/) - // // DISK SPACE MONITORING - // const io = getIO(); - // io.emit("diskSpaceMonit", { - // action: "update", - // diskSpace: { - // size: stdout[1], - // used: stdout[2], - // available: stdout[3], - // use: stdout[4] - // } - // }); + // DISK SPACE MONITORING + const io = getIO(); + io.emit("diskSpaceMonit", { + action: "update", + diskSpace: { + size: stdout[1], + used: stdout[2], + available: stdout[3], + use: stdout[4] + } + }); - // }); + });