From 1c93c16f8496bd207c65965547b4ed7ef2d2a01e Mon Sep 17 00:00:00 2001 From: adriano Date: Thu, 13 Jun 2024 17:50:30 -0300 Subject: [PATCH] feat: Add support for WhatsApp groups --- backend/src/controllers/TicketController.ts | 2 +- .../FindOrCreateTicketService.ts | 10 ++++- .../WbotServices/wbotMessageListener.ts | 39 ++++++++++++------- .../components/NotificationsPopOver/index.js | 4 +- .../src/components/TicketListItem/index.js | 2 +- 5 files changed, 36 insertions(+), 21 deletions(-) diff --git a/backend/src/controllers/TicketController.ts b/backend/src/controllers/TicketController.ts index da1399d..c9d914c 100644 --- a/backend/src/controllers/TicketController.ts +++ b/backend/src/controllers/TicketController.ts @@ -114,7 +114,7 @@ export const index = async (req: Request, res: Response): Promise => { withUnreadMessages, unlimited, searchParamContent - }); + }); return res .status(200) diff --git a/backend/src/services/TicketServices/FindOrCreateTicketService.ts b/backend/src/services/TicketServices/FindOrCreateTicketService.ts index fb14349..9ab8cdd 100644 --- a/backend/src/services/TicketServices/FindOrCreateTicketService.ts +++ b/backend/src/services/TicketServices/FindOrCreateTicketService.ts @@ -60,10 +60,11 @@ const FindOrCreateTicketService = async ( order: [["updatedAt", "DESC"]] }); - if (ticket) { + if (ticket) { await ticket.update({ status: "pending", userId: null, + queueId: null, unreadMessages }); } @@ -96,7 +97,12 @@ const FindOrCreateTicketService = async ( if (!ticket) { let status = "pending"; - if (queues.length > 1 && !botInfo.isOnQueue && !queueId) { + if ( + queues.length > 1 && + !botInfo.isOnQueue && + !queueId && + !groupContact + ) { status = "queueChoice"; } diff --git a/backend/src/services/WbotServices/wbotMessageListener.ts b/backend/src/services/WbotServices/wbotMessageListener.ts index c017331..db8604a 100644 --- a/backend/src/services/WbotServices/wbotMessageListener.ts +++ b/backend/src/services/WbotServices/wbotMessageListener.ts @@ -372,6 +372,12 @@ const verifyQueue = async ( ticket: Ticket, contact: Contact ) => { + + if(ticket?.isGroup){ + + return + } + const { queues, greetingMessage } = await ShowWhatsAppService(wbot.id!); let selectedOption = null; @@ -703,7 +709,7 @@ const handleMessage = async ( try { let msgContact: any = wbot.msgContact; - // let groupContact: Contact | undefined; + let groupContact: Contact | undefined; if (msg.fromMe) { // messages sent automatically by wbot have a special character in front of it @@ -743,18 +749,21 @@ const handleMessage = async ( // console.log('----------> chat: ', JSON.parse(JSON.stringify(chat))) - // if (chat.isGroup) { - // let msgGroupContact; - // if (msg.fromMe) { - // msgGroupContact = await wbot.getContactById(msg.to); - // } else { - // msgGroupContact = await wbot.getContactById(msg.from); - // } + console - // groupContact = await verifyContact(msgGroupContact); - // } + if (chat.isGroup) { + // let msgGroupContact; + // if (msg.fromMe) { + // msgGroupContact = await wbot.getContactById(msg.to); + // } else { + // msgGroupContact = await wbot.getContactById(msg.from); + // } + + groupContact = await verifyContact(wbot.getContactById); + } + const whatsapp = await ShowWhatsAppService(wbot.id!); const unreadMessages = msg.fromMe ? 0 : chat.unreadCount; @@ -777,12 +786,12 @@ const handleMessage = async ( const _botInfo = await BotIsOnQueue("botqueue"); - if (_botInfo.isOnQueue) { + if (_botInfo.isOnQueue && !chat.isGroup) { let ticket_obj: any = await FindOrCreateTicketServiceBot( contact, wbot.id!, - unreadMessages - // groupContact + unreadMessages, + groupContact ); ticket = ticket_obj.ticket; @@ -801,8 +810,8 @@ const handleMessage = async ( ticket = await FindOrCreateTicketService( contact, wbot.id!, - unreadMessages - // groupContact + unreadMessages, + groupContact ); } diff --git a/frontend/src/components/NotificationsPopOver/index.js b/frontend/src/components/NotificationsPopOver/index.js index 1e46dd1..866c4a4 100644 --- a/frontend/src/components/NotificationsPopOver/index.js +++ b/frontend/src/components/NotificationsPopOver/index.js @@ -387,10 +387,10 @@ const NotificationsPopOver = () => { vertical: "top", horizontal: "right", }} - classes={{ paper: classes.popoverPaper }} + classes={{ paper: classes?.popoverPaper }} onClose={handleClickAway} > - + {notifications.length === 0 ? ( {i18n.t("notifications.noTickets")} diff --git a/frontend/src/components/TicketListItem/index.js b/frontend/src/components/TicketListItem/index.js index 0d71944..417b9d1 100644 --- a/frontend/src/components/TicketListItem/index.js +++ b/frontend/src/components/TicketListItem/index.js @@ -229,7 +229,7 @@ const TicketListItem = ({ ticket, remoteTicketsControll, settings }) => { variant="body2" color="textPrimary" > - {ticket.contact.name} + {ticket?.contact?.name} {ticket.status === "closed" && (