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) {