feat: back to bot ura when the user is waiting in a queue

feat-scaling-ticket-remote-creation
adriano 2024-03-18 18:05:59 -03:00
parent e80ed8d092
commit 52e63706c1
1 changed files with 67 additions and 34 deletions

View File

@ -947,6 +947,36 @@ const handleMessage = async (
await botSendMessage(ticket, menuMsg.value); await botSendMessage(ticket, menuMsg.value);
return; return;
} else if (
!msg.fromMe &&
msg.body == "#" &&
ticket.status == "pending" &&
ticket.queueId
) {
let choosenQueue = await ShowQueueService(botInfo.botQueueId);
await UpdateTicketService({
ticketData: {
status: "open",
userId: botInfo.userIdBot,
queueId: choosenQueue.id
},
ticketId: ticket.id
});
// const menuMsg: any = await menu(msg.body, wbot.id, contact.id);
// await botSendMessage(ticket, menuMsg.value);
// const data: any = await get({ key: "ura", parse: true });
// return await backUra(ticket.whatsappId, ticket.contactId, data);
const menuMsg: any = await menu(msg.body, wbot.id, contact.id);
console.log("menuMsg: ", menuMsg);
await botSendMessage(ticket, menuMsg.value);
// return;
} }
if (msg && !msg.fromMe && ticket.status == "pending") { if (msg && !msg.fromMe && ticket.status == "pending") {
@ -1017,7 +1047,6 @@ const menu = async (userTyped: string, whatsappId: any, contactId: any) => {
if (!option && userTyped != "0" && userTyped != "#") { if (!option && userTyped != "0" && userTyped != "#") {
if (!existSubMenu()) { if (!existSubMenu()) {
const response = await mainOptionsMenu(userTyped); const response = await mainOptionsMenu(userTyped);
if (response) return response; if (response) return response;
else { else {
@ -1089,35 +1118,7 @@ const menu = async (userTyped: string, whatsappId: any, contactId: any) => {
return data[1]; return data[1];
} else if (userTyped == "#") { } else if (userTyped == "#") {
let uraOptionSelected = await findObject(whatsappId, contactId, "ura"); return await backUra(whatsappId, contactId, data);
uraOptionSelected = uraOptionSelected[4].split("|").filter(Boolean);
let id = uraOptionSelected[0];
let history = `|${uraOptionSelected[0]}`;
if (uraOptionSelected.length > 1) {
const idRemove = uraOptionSelected[uraOptionSelected.length - 1];
history = await historyUra(whatsappId, contactId, idRemove, true);
const lstIds = history.split("|").filter(Boolean);
id = lstIds[lstIds.length - 1];
}
await createObject({
whatsappId,
contactId,
identifier: "ura",
value: id,
history
});
let response: any = data.find((o: any) => o.id == id);
return response;
} }
} }
@ -1261,6 +1262,38 @@ export {
mediaTypeWhatsappOfficial, mediaTypeWhatsappOfficial,
botSendMessage botSendMessage
}; };
async function backUra(whatsappId: any, contactId: any, data: any) {
let uraOptionSelected = await findObject(whatsappId, contactId, "ura");
uraOptionSelected = uraOptionSelected[4].split("|").filter(Boolean);
let id = uraOptionSelected[0];
let history = `|${uraOptionSelected[0]}`;
if (uraOptionSelected.length > 1) {
const idRemove = uraOptionSelected[uraOptionSelected.length - 1];
history = await historyUra(whatsappId, contactId, idRemove, true);
const lstIds = history.split("|").filter(Boolean);
id = lstIds[lstIds.length - 1];
}
await createObject({
whatsappId,
contactId,
identifier: "ura",
value: id,
history
});
let response: any = data.find((o: any) => o.id == id);
return response;
}
async function historyUra( async function historyUra(
whatsappId: any, whatsappId: any,
contactId: any, contactId: any,