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: { status: {
[Op.or]: ["open", "pending", "queueChoice"] [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) { if (!ticket && groupContact) {
ticket = await Ticket.findOne({ ticket = await Ticket.findOne({
where: { where: {
contactId: groupContact.id contactId: groupContact.id,
whatsappId: whatsappId
}, },
order: [["updatedAt", "DESC"]] order: [["updatedAt", "DESC"]]
}); });
@ -71,7 +73,8 @@ const FindOrCreateTicketService = async (
// Sub seconds // Sub seconds
[Op.between]: [+subSeconds(new Date(), 0), +new Date()] [Op.between]: [+subSeconds(new Date(), 0), +new Date()]
}, },
contactId: contact.id contactId: contact.id,
whatsappId: whatsappId
}, },
order: [["updatedAt", "DESC"]] order: [["updatedAt", "DESC"]]
}); });

View File

@ -539,6 +539,7 @@ const handleMessage = async (
if (unreadMessages === 0 && whatsapp.farewellMessage && whatsapp.farewellMessage === msg.body) return; if (unreadMessages === 0 && whatsapp.farewellMessage && whatsapp.farewellMessage === msg.body) return;
const ticket = await FindOrCreateTicketService( const ticket = await FindOrCreateTicketService(
contact, contact,
wbot.id!, wbot.id!,
@ -550,21 +551,16 @@ const handleMessage = async (
// await updateTicketCacheByTicketId(ticket.id, {'contact.profilePicUrl': ticket.contact.profilePicUrl}) // await updateTicketCacheByTicketId(ticket.id, {'contact.profilePicUrl': ticket.contact.profilePicUrl})
// Para responder para o cliente pelo mesmo whatsapp que ele enviou a mensagen // Para responder para o cliente pelo mesmo whatsapp que ele enviou a mensagen
if (wbot.id != ticket.whatsappId) { // if (wbot.id != ticket.whatsappId) {
// // console.log('PARA RESPONDER PELO MEMOS WHATSAPP wbot.id: ', wbot.id, ' | wbot.status: ', wbot.status)
// console.log('PARA RESPONDER PELO MEMOS WHATSAPP wbot.id: ', wbot.id, ' | wbot.status: ', wbot.status) // // console.log('WHATSAPP STATUS ticket.whatsappId: ', ticket.whatsappId)
// console.log('WHATSAPP STATUS ticket.whatsappId: ', ticket.whatsappId) // try {
// await ticket.update({ whatsappId: wbot.id });
try { // } catch (error: any) {
await ticket.update({ whatsappId: wbot.id }); // console.error('===> Error on wbotMessageListener.ts into handleMessage fuction file: \n', error)
} catch (error: any) { // throw new AppError(error.message);
console.error('===> Error on wbotMessageListener.ts into handleMessage fuction file: \n', error) // }
throw new AppError(error.message); // }
}
}
// //
if (msg.hasMedia) { if (msg.hasMedia) {