From e44efb45d90d552686dbbc2a39a8a179ca6747ff Mon Sep 17 00:00:00 2001 From: adriano Date: Tue, 25 Jun 2024 09:35:28 -0300 Subject: [PATCH] feat: enforce file attachment for evidence in URA form submission --- .../WbotServices/wbotMessageListener.ts | 50 +++++++++---------- .../src/components/TicketListItem/index.js | 2 +- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/backend/src/services/WbotServices/wbotMessageListener.ts b/backend/src/services/WbotServices/wbotMessageListener.ts index b6f1b80..56e82ea 100644 --- a/backend/src/services/WbotServices/wbotMessageListener.ts +++ b/backend/src/services/WbotServices/wbotMessageListener.ts @@ -278,7 +278,7 @@ const question = async ( ) { await botSendMessage( ticket, - "¡Envía uno o más archivos simultáneamente!" + "Por favor adjuntar evidencias.\n¡Envía uno o más archivos simultáneamente!" ); return; } @@ -327,22 +327,9 @@ const question = async ( } } - // currentId = await get({ key: `form:${ticket.id}:current` }); - let index = ask.findIndex((obj: any) => obj.id == currentId); if (index != -1) { - console.log( - "msg?.body: ", - msg?.body, - " | sendFile?.filePath: ", - sendFile?.filePath, - " | index: ", - index, - " | ask[index]?.item?.file: ", - ask[index]?.item?.file - ); - if (!ask[index]?.item?.file && !sendFile) { ask[index].value = msg?.body; } @@ -352,18 +339,22 @@ const question = async ( if (index + 1 <= ask.length - 1) { if (ask[index + 1]?.item?.file && !sendFile) { - await botSendMessage( - ticket, - "¿Quieres enviar archivo? Ingrese *Sí* o *No*" - ); + // await botSendMessage( + // ticket, + // "¿Quieres enviar archivo? Ingrese *Sí* o *No*" + // ); await set( `form:${ticket.id}:file`, JSON.stringify({ status: "waiting" }) ); - return; + set( + `form:${ticket.id}:file`, + JSON.stringify({ ...sendFile, status: "yes" }) + ); + // return; } - // Next question + await botSendMessage(ticket, ask[index + 1].question); await set(`form:${ticket.id}:current`, `${ask[index + 1].id}`); } else { @@ -1222,7 +1213,7 @@ const handleMessage = async ( return; } } - + // if ( @@ -1390,7 +1381,7 @@ const handleMessage = async ( msg?.body?.trim() != "0" && msg?.body?.trim() != "#" ) { - await question(fillingOutForm, msg, ticket, contact, wbot); + await question(fillingOutForm, msg, ticket, contact, wbot); return; } @@ -1603,7 +1594,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,7 +1605,7 @@ const menu = async (userTyped: string, whatsappId: any, contactId: any) => { const data: any = await get({ key: whatsapp?.number ? `ura_${whatsapp?.number}` : "ura", parse: true - }); + }); if (!lastId[0]) { await createObject({ @@ -1964,7 +1955,7 @@ async function backUra(whatsappId: any, contactId: any, data: any) { let uraOptionSelected = await findObject( whatsappId, - contactId, + contactId, _whatsapp?.number ? `ura_${_whatsapp?.number}` : "ura" ); @@ -2205,6 +2196,13 @@ async function setSoport(ticket: any, wbot: any, contact: any) { }) .join(""); + let request = await get({ + key: `form:${ticket.id}:request`, + parse: true + }); + + payload += `${request.nit}`; + let payloadFile = fillingOutForm.ask.find((a: any) => a?.item?.file); let files = ""; @@ -2251,7 +2249,7 @@ async function setSoport(ticket: any, wbot: any, contact: any) { `; - // console.log("DATA: ", data); + console.log("DATA REQUEST: ", data); // return; var config = { diff --git a/frontend/src/components/TicketListItem/index.js b/frontend/src/components/TicketListItem/index.js index 0d71944..417b9d1 100644 --- a/frontend/src/components/TicketListItem/index.js +++ b/frontend/src/components/TicketListItem/index.js @@ -229,7 +229,7 @@ const TicketListItem = ({ ticket, remoteTicketsControll, settings }) => { variant="body2" color="textPrimary" > - {ticket.contact.name} + {ticket?.contact?.name} {ticket.status === "closed" && (