diff --git a/backend/src/services/TicketServices/UpdateTicketService.ts b/backend/src/services/TicketServices/UpdateTicketService.ts index df0e321..1c3b10a 100644 --- a/backend/src/services/TicketServices/UpdateTicketService.ts +++ b/backend/src/services/TicketServices/UpdateTicketService.ts @@ -80,7 +80,7 @@ const UpdateTicketService = async ({ if (msg?.trim().length > 0) { setTimeout(async () => { - sendWhatsAppMessageSocket(ticket, msg); + sendWhatsAppMessageSocket(ticket, `\u200e${msg}`); }, 2000); } diff --git a/backend/src/services/WbotServices/wbotMessageListener.ts b/backend/src/services/WbotServices/wbotMessageListener.ts index 1c0286f..1cd1661 100644 --- a/backend/src/services/WbotServices/wbotMessageListener.ts +++ b/backend/src/services/WbotServices/wbotMessageListener.ts @@ -392,7 +392,7 @@ const verifyQueue = async ( if (outService.length > 0) { const { type, msg: msgOutService } = outService[0]; console.log(`${type} message ignored on queue`); - botSendMessage(ticket, msgOutService); + botSendMessage(ticket, `\u200e${msgOutService}`); return; } @@ -583,7 +583,7 @@ const botTransferTicketToUser = async ( }; const botSendMessage = (ticket: Ticket, msg: string) => { - const { phoneNumberId } = ticket; + const { phoneNumberId } = ticket; const debouncedSentMessage = debounce( async () => { @@ -641,27 +641,10 @@ const handleMessage = async ( let msgContact: any = wbot.msgContact; // let groupContact: Contact | undefined; - if (msg.fromMe) { - const whatsapp = await whatsappInfo(wbot.id); - - if (whatsapp?.number) { - const ticketExpiration = await SettingTicket.findOne({ - where: { key: "ticketExpiration", number: whatsapp.number } - }); - - if ( - ticketExpiration && - ticketExpiration.value == "enabled" && - ticketExpiration?.message.trim() == msg.body.trim() - ) { - console.log("*********** TICKET EXPIRATION"); - return; - } - } - + if (msg.fromMe) { // messages sent automatically by wbot have a special character in front of it - // if so, this message was already been stored in database; - // if (/\u200e/.test(msg.body[0])) return; + // if so, this message was already been stored in database; + if (/\u200e/.test(msg.body[0])) return; // media messages sent from me from cell phone, first comes with "hasMedia = false" and type = "image/ptt/etc" // in this case, return and let this message be handled by "media_uploaded" event, when it will have "hasMedia = true" @@ -933,25 +916,28 @@ const handleMessage = async ( ticket.status == "pending" && ticket.queueId ) { - let choosenQueue = await ShowQueueService(botInfo.botQueueId); + if (botInfo.isOnQueue) { + let choosenQueue = await ShowQueueService(botInfo.botQueueId); - await UpdateTicketService({ - ticketData: { - status: "open", - userId: botInfo.userIdBot, - queueId: choosenQueue.id - }, - ticketId: ticket.id - }); - const menuMsg: any = await menu(msg.body, wbot.id, contact.id); - await botSendMessage(ticket, menuMsg.value); + await UpdateTicketService({ + ticketData: { + status: "open", + userId: botInfo.userIdBot, + queueId: choosenQueue.id + }, + ticketId: ticket.id + }); + const menuMsg: any = await menu(msg.body, wbot.id, contact.id); + await botSendMessage(ticket, menuMsg.value); + } return; } else if ( !msg.fromMe && msg.body == "#" && ticket.status == "pending" && - ticket.queueId + ticket.queueId && + botInfo.isOnQueue ) { let choosenQueue = await ShowQueueService(botInfo.botQueueId); @@ -988,7 +974,7 @@ const handleMessage = async ( if (ticket?.queueId) { ticketHasQueue = true; } - + if (ticketHasQueue && ticket.status != "open") { let whatsapp: any = await whatsappInfo(ticket?.whatsappId); @@ -1002,7 +988,7 @@ const handleMessage = async ( return; } - botSendMessage(ticket, msgOutService); + botSendMessage(ticket, `\u200e${msgOutService}`); return; } } diff --git a/backend/src/services/WhatsappService/ListWhatsAppsNumber.ts b/backend/src/services/WhatsappService/ListWhatsAppsNumber.ts index 8bb9758..928b8d5 100644 --- a/backend/src/services/WhatsappService/ListWhatsAppsNumber.ts +++ b/backend/src/services/WhatsappService/ListWhatsAppsNumber.ts @@ -9,12 +9,12 @@ const ListWhatsAppsNumber = async ( let whatsapps: any = []; if (whatsapp) { - if (status) { + if (status) { whatsapps = await Whatsapp.findAll({ raw: true, where: { number: whatsapp.number, status: status, }, attributes: ["id", "number", "status", "isDefault", "url", 'isOfficial'] - }); + }); } else { whatsapps = await Whatsapp.findAll({ raw: true, diff --git a/frontend/src/components/NotificationsPopOver/index.js b/frontend/src/components/NotificationsPopOver/index.js index 63f52a4..89a1155 100644 --- a/frontend/src/components/NotificationsPopOver/index.js +++ b/frontend/src/components/NotificationsPopOver/index.js @@ -269,7 +269,7 @@ const NotificationsPopOver = () => { if(!isQueue && notify){ return; }else{ - const notification = new Notification(`${i18n.t("tickets.notification.messagePeding")} ${notify.data.queue?.name}`); + const notification = new Notification(`${i18n.t("tickets.notification.messagePeding")} ${notify?.data?.queue?.name}`); notification.onclick = e => { e.preventDefault() window.focus()