fix: bot send ura message to whatsapp distinct
parent
9e84e4cf08
commit
9366a186a4
|
@ -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"]]
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
|
@ -1603,7 +1603,7 @@ function delForm(ticket: any) {
|
|||
}
|
||||
|
||||
const menu = async (userTyped: string, whatsappId: any, contactId: any) => {
|
||||
let whatsapp = await whatsappCache(whatsappId);
|
||||
let whatsapp = await whatsappCache(whatsappId);
|
||||
|
||||
let lastId = await findObject(
|
||||
whatsappId,
|
||||
|
@ -1614,9 +1614,7 @@ const menu = async (userTyped: string, whatsappId: any, contactId: any) => {
|
|||
const data: any = await get({
|
||||
key: whatsapp?.number ? `ura_${whatsapp?.number}` : "ura",
|
||||
parse: true
|
||||
});
|
||||
|
||||
console.log("lastId[0]: ", lastId[0]);
|
||||
});
|
||||
|
||||
if (!lastId[0]) {
|
||||
await createObject({
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue