Alteração na criação de tickets quando o usuario inicia a conversa para criar tickets com base no numero from to

adriano 2023-06-14 15:47:10 -03:00
parent e88bd10244
commit 6e2ba241b3
2 changed files with 17 additions and 18 deletions

View File

@ -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"]]
});

View File

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