From 7f52466c5043bbb9bbf2a13b1bfad93f9d2c616f Mon Sep 17 00:00:00 2001 From: Adriano Date: Wed, 21 Feb 2024 09:21:02 -0300 Subject: [PATCH 1/3] chore: change frontend port --- frontend/server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/server.js b/frontend/server.js index a05ba32..1b2d690 100644 --- a/frontend/server.js +++ b/frontend/server.js @@ -6,4 +6,4 @@ app.use(express.static(path.join(__dirname, "build"))); app.get("/*", function (req, res) { res.sendFile(path.join(__dirname, "build", "index.html")); }); -app.listen(3333); +app.listen(3341); From d7019ffb1ac1042cd8e4da51a3afbde0507a1efe Mon Sep 17 00:00:00 2001 From: Adriano Date: Mon, 18 Mar 2024 14:51:13 -0300 Subject: [PATCH 2/3] feat: add notification and sound alert for new tickets in user's service queue Details: - Implemented functionality to notify users with a sound alert when new tickets arrive in their service queues. fix: include responsible person's name when generating ticket already opened error in all languages Details: - Fixed the error generation process to include the name of the responsible person for the ticket when the system detects an attempt to create an already opened ticket. --- .gitignore | 2 + backend/src/errors/AppError.ts | 2 +- .../src/helpers/CheckContactOpenTickets.ts | 10 +- .../WbotServices/wbotMessageListener.ts | 4 +- .../components/NotificationsPopOver/index.js | 91 +++++++++++++------ frontend/src/translate/languages/en.js | 1 + frontend/src/translate/languages/es.js | 1 + frontend/src/translate/languages/pt.js | 1 + 8 files changed, 78 insertions(+), 34 deletions(-) diff --git a/.gitignore b/.gitignore index c86c332..ec325b8 100644 --- a/.gitignore +++ b/.gitignore @@ -40,6 +40,8 @@ WWebJS .env.development.local .env.test.local .env.production.local +.env.save +nano.save npm-debug.log* yarn-debug.log* diff --git a/backend/src/errors/AppError.ts b/backend/src/errors/AppError.ts index a8b1209..eed88bd 100644 --- a/backend/src/errors/AppError.ts +++ b/backend/src/errors/AppError.ts @@ -1,5 +1,5 @@ class AppError { - public readonly message: string; + public message: string; public readonly statusCode: number; diff --git a/backend/src/helpers/CheckContactOpenTickets.ts b/backend/src/helpers/CheckContactOpenTickets.ts index 303f4a7..0b4a52e 100644 --- a/backend/src/helpers/CheckContactOpenTickets.ts +++ b/backend/src/helpers/CheckContactOpenTickets.ts @@ -1,6 +1,7 @@ import { Op } from "sequelize"; import AppError from "../errors/AppError"; import Ticket from "../models/Ticket"; +import User from "../models/User"; import ListWhatsAppsNumber from "../services/WhatsappService/ListWhatsAppsNumber"; import { getSettingValue } from "./WhaticketSettings"; import ListWhatsAppsForQueueService from "../services/WhatsappService/ListWhatsAppsForQueueService"; @@ -38,8 +39,13 @@ const CheckContactOpenTickets = async ( if (ticket) { if (handle) return true; - - throw new AppError("ERR_OTHER_OPEN_TICKET"); + const userName = await User.findOne({ + where:{ id: ticket.userId } + }); + const error = new AppError("ERR_OTHER_OPEN_TICKET"); + error.message = `Erro: já existe um ticket criado com esse contato. Responsável: ${userName? userName.name.toUpperCase() : 'Aguardando'}`; + + throw error; } diff --git a/backend/src/services/WbotServices/wbotMessageListener.ts b/backend/src/services/WbotServices/wbotMessageListener.ts index d5da2bf..f2b24e0 100644 --- a/backend/src/services/WbotServices/wbotMessageListener.ts +++ b/backend/src/services/WbotServices/wbotMessageListener.ts @@ -409,7 +409,7 @@ const verifyQueue = async ( //test del transfere o atendimento se entrar na ura infinita const repet: any = await mostRepeatedPhrase(ticket.id); - if (repet.occurrences > 4) { + if (repet.occurrences > 10) { await UpdateTicketService({ ticketData: { status: "pending", queueId: queues[0].id }, ticketId: ticket.id @@ -884,7 +884,7 @@ const handleMessage = async ( console.log("repet.occurrences: ", repet.occurrences); - if (repet.occurrences > 4) { + if (repet.occurrences > 10) { await transferTicket(0, wbot, ticket); await SendWhatsAppMessage({ diff --git a/frontend/src/components/NotificationsPopOver/index.js b/frontend/src/components/NotificationsPopOver/index.js index b14678d..63f52a4 100644 --- a/frontend/src/components/NotificationsPopOver/index.js +++ b/frontend/src/components/NotificationsPopOver/index.js @@ -217,43 +217,76 @@ const NotificationsPopOver = () => { } }) + socket.on('notifyPeding', data =>{ + handleNotifications("", data); + }); + return () => { socket.disconnect() } }, [user]) - const handleNotifications = data => { - const { message, contact, ticket } = data + const handleNotifications = (data, notify) => { + let isQueue = false; + if(!notify){ + const { message, contact, ticket } = data - const options = { - body: `${message.body} - ${format(new Date(), "HH:mm")}`, - icon: contact.profilePicUrl, - tag: ticket.id, - renotify: true, - } - - const notification = new Notification( - `${i18n.t("tickets.notification.message")} ${contact.name}`, - options - ) - - notification.onclick = e => { - e.preventDefault() - window.focus() - historyRef.current.push(`/tickets/${ticket.id}`) - } - - setDesktopNotifications(prevState => { - const notfiticationIndex = prevState.findIndex( - n => n.tag === notification.tag - ) - if (notfiticationIndex !== -1) { - prevState[notfiticationIndex] = notification - return [...prevState] + const options = { + body: `${message.body} - ${format(new Date(), "HH:mm")}`, + icon: contact.profilePicUrl, + tag: ticket.id, + renotify: true, } - return [notification, ...prevState] - }) + const notification = new Notification( + `${i18n.t("tickets.notification.message")} ${contact.name}`, + options + ) + + notification.onclick = e => { + e.preventDefault() + window.focus() + historyRef.current.push(`/tickets/${ticket.id}`) + } + + setDesktopNotifications(prevState => { + const notfiticationIndex = prevState.findIndex( + n => n.tag === notification.tag + ) + if (notfiticationIndex !== -1) { + prevState[notfiticationIndex] = notification + return [...prevState] + } + return [notification, ...prevState] + }) + }else{ + user.queues.forEach(queue =>{ + if(queue.id === notify.data.queue?.id){ + isQueue = true; + } + }) + } + if(!isQueue && notify){ + return; + }else{ + const notification = new Notification(`${i18n.t("tickets.notification.messagePeding")} ${notify.data.queue?.name}`); + notification.onclick = e => { + e.preventDefault() + window.focus() + historyRef.current.push(`/tickets`) + } + + setDesktopNotifications(prevState => { + const notfiticationIndex = prevState.findIndex( + n => n.tag === notification.tag + ) + if (notfiticationIndex !== -1) { + prevState[notfiticationIndex] = notification + return [...prevState] + } + return [notification, ...prevState] + }) + } soundAlertRef.current() } diff --git a/frontend/src/translate/languages/en.js b/frontend/src/translate/languages/en.js index 7410d89..a499d94 100644 --- a/frontend/src/translate/languages/en.js +++ b/frontend/src/translate/languages/en.js @@ -241,6 +241,7 @@ const messages = { }, notification: { message: "Message from", + messagePeding: "new ticket in queue", }, tabs: { open: { title: "Inbox" }, diff --git a/frontend/src/translate/languages/es.js b/frontend/src/translate/languages/es.js index 6e047b2..a2c9f3a 100644 --- a/frontend/src/translate/languages/es.js +++ b/frontend/src/translate/languages/es.js @@ -245,6 +245,7 @@ const messages = { }, notification: { message: "Mensaje de", + messagePeding: "Nuevo billete en cola", }, tabs: { open: { title: "Bandeja" }, diff --git a/frontend/src/translate/languages/pt.js b/frontend/src/translate/languages/pt.js index 69117b9..13b220b 100644 --- a/frontend/src/translate/languages/pt.js +++ b/frontend/src/translate/languages/pt.js @@ -244,6 +244,7 @@ const messages = { }, notification: { message: "Mensagem de", + messagePeding: "Novo ticket na fila", }, tabs: { open: { title: "Inbox" }, From 7533a382cc0fbb33ce5bcd6b967821203810cf43 Mon Sep 17 00:00:00 2001 From: gustavo-gsp <79770296+gustavo-gsp@users.noreply.github.com> Date: Mon, 18 Mar 2024 15:07:47 -0300 Subject: [PATCH 3/3] Update server.js --- frontend/server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/server.js b/frontend/server.js index 1b2d690..a05ba32 100644 --- a/frontend/server.js +++ b/frontend/server.js @@ -6,4 +6,4 @@ app.use(express.static(path.join(__dirname, "build"))); app.get("/*", function (req, res) { res.sendFile(path.join(__dirname, "build", "index.html")); }); -app.listen(3341); +app.listen(3333);