From 5f55f4d50c214750ee1f0943d400484694ae82d8 Mon Sep 17 00:00:00 2001 From: adriano Date: Mon, 2 Jan 2023 17:54:18 -0300 Subject: [PATCH] =?UTF-8?q?Atualiza=C3=A7=C3=A3o=20da=20mensagem=20que=20?= =?UTF-8?q?=C3=A9=20enviada=20automaticamente=20para=20o=20cliente=20no=20?= =?UTF-8?q?envio=20proativo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/controllers/HitController.ts | 27 ++++++++++++++---------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/backend/src/controllers/HitController.ts b/backend/src/controllers/HitController.ts index 10f684d..3ba79a8 100644 --- a/backend/src/controllers/HitController.ts +++ b/backend/src/controllers/HitController.ts @@ -19,7 +19,7 @@ import hitPortalMonitoring from "../helpers/HitPortalMonitoring"; // type IndexQuery = { // centro_custo: string; // }; - + export const hit = async (req: Request, res: Response): Promise => { // const { @@ -41,17 +41,20 @@ export const hit = async (req: Request, res: Response): Promise => { try { - let response = await hitPortalMonitoring(req.body['centro_custo']) + let response = await hitPortalMonitoring(req.body['centro_custo']) - // console.log('RESPONSE: ', response) + if (!response || response.length == 0) { + console.log('Empty result from hit portal monitoring. Centro_de_custo: ',req.body['centro_custo']) + return res.status(200).json({ "message": "Ok" }); + } const botInfo = await BotIsOnQueue('botqueue') let ticket = await ShowTicketServiceByContactId(contact['contact.id']) if (ticket.id && ticket.status == 'pending') { - - await sendMessageHitMonitoring(response, ticket); + + await sendMessageHitMonitoring(response, ticket, contact); } else if (!ticket.id) { @@ -62,7 +65,7 @@ export const hit = async (req: Request, res: Response): Promise => { await UpdateTicketService({ ticketData: { queueId: botInfo.botQueueId }, ticketId: ticket.id }); - await sendMessageHitMonitoring(response, ticket); + await sendMessageHitMonitoring(response, ticket, contact); } @@ -84,12 +87,14 @@ export const hit = async (req: Request, res: Response): Promise => { return res.status(200).json({ "message": "Ok" }); }; -async function sendMessageHitMonitoring(response: any, ticket: Ticket) { - for (let i = 0; i < response.length; i++) { +async function sendMessageHitMonitoring(response: any, ticket: Ticket, contact: any) { - await SendWhatsAppMessage({ body: `*Situação do chamado na Operadora*\n\n*Incidente*:\n\n ${response[i].header}\n${response[i].body}`, ticket }); + if (response && response.length > 0) { - await new Promise(f => setTimeout(f, 1000)); + console.log('MESSAGE WILL BE SENT!') + + await SendWhatsAppMessage({ body: `*Olá. Somos a TI Espaçolaser.*\nIdentificamos em nossos monitoramentos que há um problema na internet da sua loja ${contact['contact.name']} e já estamos resolvendo. Abaixo seguem informações sobre o incidente para que possam acompanhar.\n\n*Situação do chamado na Operadora*\n\n*Incidente*:\n\n ${response[0].header}\n${response[0].body}`, ticket }); + + } - } }