From 3a7f1a2404a006163d3941930ae36ee42b89d4cf Mon Sep 17 00:00:00 2001 From: adriano Date: Thu, 28 Sep 2023 16:26:35 -0300 Subject: [PATCH] =?UTF-8?q?atualiza=C3=A7=C3=A3o=20para=20pegar=20a=20fila?= =?UTF-8?q?=20pelo=20nome=20a=20partir=20do=20argumento=20enviado=20pelo?= =?UTF-8?q?=20dialogflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WbotServices/wbotMessageListener.ts | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/backend/src/services/WbotServices/wbotMessageListener.ts b/backend/src/services/WbotServices/wbotMessageListener.ts index ae7aee7..dfcad00 100644 --- a/backend/src/services/WbotServices/wbotMessageListener.ts +++ b/backend/src/services/WbotServices/wbotMessageListener.ts @@ -523,7 +523,7 @@ async function sendDelayedMessages( number: `${contact.number}@c.us` }); - await transferTicket(+msgAction.actions[1], wbot, ticket); + await transferTicket(msgAction.actions[1], wbot, ticket); } else if (msgAction.actions[0] == "send_file") { const sourcePath = path.join(__dirname, `../../../public/bot`); @@ -751,11 +751,7 @@ const verifyQueue = async ( } }; -const transferTicket = async ( - queueIndex: number, - wbot: any, - ticket: Ticket -) => { +const transferTicket = async (queueName: any, wbot: any, ticket: Ticket) => { const botInfo = await BotIsOnQueue("botqueue"); const queuesWhatsGreetingMessage = await queuesOutBot( @@ -763,11 +759,19 @@ const transferTicket = async ( botInfo.botQueueId ); + let queue: any; + const queues = queuesWhatsGreetingMessage.queues; - // console.log('queues ---> ', queues) + // console.log("queues ---> ", console.log(JSON.stringify(queues, null, 6))); - await botTransferTicket(queues[queueIndex], ticket); + if (typeof queueName == "string") { + queue = queues.find((q: any) => q?.name == queueName.trim()); + } else if (typeof queueName == "number") { + queue = queues[queueName]; + } + + await botTransferTicket(queue, ticket); }; // const botMsgActions = (params: string) => { @@ -820,7 +824,7 @@ const queuesOutBot = async (wbot: any, botId: string | number) => { return { queues, greetingMessage }; }; -const botTransferTicket = async (queues: Queue, ticket: Ticket) => { +const botTransferTicket = async (queues: any, ticket: Ticket) => { console.log(">>>>>>>>>>>>>>>>> queues.id: ", queues.id); await ticket.update({ userId: null }); @@ -1237,7 +1241,7 @@ const handleMessage = async (msg: any, wbot: any): Promise => { await setMessageAsRead(ticket); } - let ticketHasQueue = false; + let ticketHasQueue = false; if ( botInfo.isOnQueue &&