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

View File

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