From 6e2ba241b311406a2f98bfcfbfd884b65296f68c Mon Sep 17 00:00:00 2001 From: adriano Date: Wed, 14 Jun 2023 15:47:10 -0300 Subject: [PATCH] =?UTF-8?q?Altera=C3=A7=C3=A3o=20na=20cria=C3=A7=C3=A3o=20?= =?UTF-8?q?de=20tickets=20quando=20o=20usuario=20inicia=20a=20conversa=20p?= =?UTF-8?q?ara=20criar=20tickets=20com=20base=20no=20numero=20from=20to?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FindOrCreateTicketService.ts | 9 ++++--- .../WbotServices/wbotMessageListener.ts | 26 ++++++++----------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/backend/src/services/TicketServices/FindOrCreateTicketService.ts b/backend/src/services/TicketServices/FindOrCreateTicketService.ts index de661f0..0804d37 100644 --- a/backend/src/services/TicketServices/FindOrCreateTicketService.ts +++ b/backend/src/services/TicketServices/FindOrCreateTicketService.ts @@ -21,7 +21,8 @@ const FindOrCreateTicketService = async ( status: { [Op.or]: ["open", "pending", "queueChoice"] }, - contactId: groupContact ? groupContact.id : contact.id + contactId: groupContact ? groupContact.id : contact.id, + whatsappId: whatsappId } }); @@ -41,7 +42,8 @@ const FindOrCreateTicketService = async ( if (!ticket && groupContact) { ticket = await Ticket.findOne({ where: { - contactId: groupContact.id + contactId: groupContact.id, + whatsappId: whatsappId }, order: [["updatedAt", "DESC"]] }); @@ -71,7 +73,8 @@ const FindOrCreateTicketService = async ( // Sub seconds [Op.between]: [+subSeconds(new Date(), 0), +new Date()] }, - contactId: contact.id + contactId: contact.id, + whatsappId: whatsappId }, order: [["updatedAt", "DESC"]] }); diff --git a/backend/src/services/WbotServices/wbotMessageListener.ts b/backend/src/services/WbotServices/wbotMessageListener.ts index cd97403..12efab1 100644 --- a/backend/src/services/WbotServices/wbotMessageListener.ts +++ b/backend/src/services/WbotServices/wbotMessageListener.ts @@ -539,6 +539,7 @@ const handleMessage = async ( if (unreadMessages === 0 && whatsapp.farewellMessage && whatsapp.farewellMessage === msg.body) return; + const ticket = await FindOrCreateTicketService( contact, wbot.id!, @@ -550,21 +551,16 @@ const handleMessage = async ( // await updateTicketCacheByTicketId(ticket.id, {'contact.profilePicUrl': ticket.contact.profilePicUrl}) // Para responder para o cliente pelo mesmo whatsapp que ele enviou a mensagen - if (wbot.id != ticket.whatsappId) { - - // console.log('PARA RESPONDER PELO MEMOS WHATSAPP wbot.id: ', wbot.id, ' | wbot.status: ', wbot.status) - // console.log('WHATSAPP STATUS ticket.whatsappId: ', ticket.whatsappId) - - try { - await ticket.update({ whatsappId: wbot.id }); - } catch (error: any) { - console.error('===> Error on wbotMessageListener.ts into handleMessage fuction file: \n', error) - throw new AppError(error.message); - } - - - - } + // if (wbot.id != ticket.whatsappId) { + // // console.log('PARA RESPONDER PELO MEMOS WHATSAPP wbot.id: ', wbot.id, ' | wbot.status: ', wbot.status) + // // console.log('WHATSAPP STATUS ticket.whatsappId: ', ticket.whatsappId) + // try { + // await ticket.update({ whatsappId: wbot.id }); + // } catch (error: any) { + // console.error('===> Error on wbotMessageListener.ts into handleMessage fuction file: \n', error) + // throw new AppError(error.message); + // } + // } // if (msg.hasMedia) {