fix: bot send ura message to whatsapp distinct

feat_faro
adriano 2024-05-31 10:41:12 -03:00
parent 9e84e4cf08
commit 9366a186a4
2 changed files with 38 additions and 11 deletions

View File

@ -9,6 +9,8 @@ import AppError from "../../errors/AppError";
import { userInfo } from "os";
import ShowQueueService from "../QueueService/ShowQueueService";
import UpdateTicketService from "./UpdateTicketService";
import { getSettingValue } from "../../helpers/WhaticketSettings"
import ListWhatsAppsNumber from "../WhatsappService/ListWhatsAppsNumber"
const FindOrCreateTicketServiceBot = async (
@ -20,14 +22,40 @@ const FindOrCreateTicketServiceBot = async (
try {
let ticket = await Ticket.findOne({
where: {
// let ticket = await Ticket.findOne({
// where: {
// status: {
// [Op.or]: ["open", "pending", "queueChoice"]
// },
// contactId: groupContact ? groupContact.id : contact.id
// }
// });
let ticket;
if (getSettingValue("oneContactChatWithManyWhats")?.value == "enabled") {
let whats = await ListWhatsAppsNumber(whatsappId);
ticket = await Ticket.findOne({
where: {
status: {
[Op.or]: ["open", "pending", "queueChoice"]
},
contactId: groupContact ? groupContact.id : contact.id
contactId: groupContact ? groupContact.id : contact.id,
whatsappId: { [Op.in]: whats.whatsapps.map((w: any) => w.id) }
}
});
} else {
ticket = await Ticket.findOne({
where: {
status: {
[Op.or]: ["open", "pending", "queueChoice"]
},
contactId: groupContact ? groupContact.id : contact.id
}
});
}
const { queues, greetingMessage, phoneNumberId } =
await ShowWhatsAppService(whatsappId);
@ -70,7 +98,8 @@ const FindOrCreateTicketServiceBot = async (
ticket = await Ticket.findOne({
where: {
contactId: contact.id,
userId: botInfo.userIdBot
userId: botInfo.userIdBot,
whatsappId: whatsappId
},
order: [["updatedAt", "DESC"]]
});

View File

@ -311,7 +311,7 @@ const question = async (
ticket,
"Te estamos transfiriendo para hablar con un asesor. Espera a que te atiendan."
);
transferTicket("Asesor", wbot, ticket);
transferTicket("OET_asesor", wbot, ticket);
delForm(ticket);
del(`form:${ticket.id}:request`);
return;
@ -1616,8 +1616,6 @@ const menu = async (userTyped: string, whatsappId: any, contactId: any) => {
parse: true
});
console.log("lastId[0]: ", lastId[0]);
if (!lastId[0]) {
await createObject({
whatsappId,
@ -2110,7 +2108,7 @@ async function getProduct(ticket: any, nit: any, wbot: any) {
`No te identificamos como cliente en nuestra base de datos, te transferimos con un asesor`,
ticket,
wbot,
"Asesor"
"OET_asesor"
);
return;
}
@ -2120,7 +2118,7 @@ async function getProduct(ticket: any, nit: any, wbot: any) {
`No se encontraron productos para el nit ingresado. Trasladaremos tu servicio para hablar con un asesor. Espera a que te atiendan.`,
ticket,
wbot,
"Asesor"
"OET_asesor"
);
return;
}