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

@ -528,7 +528,7 @@ const transferTicket = async (
ticket: Ticket,
sendGreetingMessage?: boolean
) => {
const botInfo = await BotIsOnQueue("botqueue");
const botInfo = await BotIsOnQueue("botqueue");
const queuesWhatsGreetingMessage = await queuesOutBot(
wbot,
@ -947,6 +947,36 @@ const handleMessage = async (
await botSendMessage(ticket, menuMsg.value);
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") {
@ -1017,7 +1047,6 @@ const menu = async (userTyped: string, whatsappId: any, contactId: any) => {
if (!option && userTyped != "0" && userTyped != "#") {
if (!existSubMenu()) {
const response = await mainOptionsMenu(userTyped);
if (response) return response;
else {
@ -1026,7 +1055,7 @@ const menu = async (userTyped: string, whatsappId: any, contactId: any) => {
contactId,
"ura"
);
uraOptionSelected = uraOptionSelected[4].split("|");
if (uraOptionSelected.length == 1) {
@ -1089,36 +1118,8 @@ const menu = async (userTyped: string, whatsappId: any, contactId: any) => {
return data[1];
} else if (userTyped == "#") {
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;
}
return await backUra(whatsappId, contactId, data);
}
}
function existSubMenu() {
@ -1134,7 +1135,7 @@ const menu = async (userTyped: string, whatsappId: any, contactId: any) => {
const menuValues = data
.filter((m: any) => m.idmaster == currentMenu[3])
.map((m: any) => m.value);
.map((m: any) => m.value);
let menuOption = data.find(
(o: any) =>
@ -1261,6 +1262,38 @@ export {
mediaTypeWhatsappOfficial,
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(
whatsappId: any,
contactId: any,