From 30c30447b00341c40f7e94b89b1f9fb7081cbe74 Mon Sep 17 00:00:00 2001 From: Robson Tenorio Date: Wed, 8 Jun 2022 15:07:03 -0300 Subject: [PATCH] Ticket enviado por API sendo encerrado automaticamente e recebimento de resposta do envio da API --- backend/src/controllers/ApiController.ts | 26 +++++++++++++-------- frontend/src/pages/Settings/index.js | 29 ++++++++++++++++++++++++ frontend/src/translate/languages/en.js | 8 +++++++ frontend/src/translate/languages/es.js | 8 +++++++ frontend/src/translate/languages/pt.js | 8 +++++++ 5 files changed, 70 insertions(+), 9 deletions(-) diff --git a/backend/src/controllers/ApiController.ts b/backend/src/controllers/ApiController.ts index 18f7cd9f..a5facbaa 100644 --- a/backend/src/controllers/ApiController.ts +++ b/backend/src/controllers/ApiController.ts @@ -14,6 +14,7 @@ import GetProfilePicUrl from "../services/WbotServices/GetProfilePicUrl"; import SendWhatsAppMedia from "../services/WbotServices/SendWhatsAppMedia"; import SendWhatsAppMessage from "../services/WbotServices/SendWhatsAppMessage"; import UpdateTicketService from "../services/TicketServices/UpdateTicketService"; +import ListSettingsServiceOne from "../services/SettingServices/ListSettingsServiceOne"; type WhatsappData = { whatsappId: number; @@ -98,21 +99,28 @@ export const index = async (req: Request, res: Response): Promise => { const contactAndTicket = await createContact(whatsappId, newContact.number); + let resp: any; + if (medias) { await Promise.all( medias.map(async (media: Express.Multer.File) => { - await SendWhatsAppMedia({ body, media, ticket: contactAndTicket }); + resp = await SendWhatsAppMedia({ body, media, ticket: contactAndTicket }); }) ); } else { - await SendWhatsAppMessage({ body, ticket: contactAndTicket, quotedMsg }); + resp = await SendWhatsAppMessage({ body, ticket: contactAndTicket, quotedMsg }); } - setTimeout(async () => { - await UpdateTicketService({ - ticketId: contactAndTicket.id, - ticketData: { status: "closed" } - }); - }, 1000); - return res.send({ error: "SUCCESS" }); + const listSettingsService = await ListSettingsServiceOne({ key: "closeTicketApi" }); + var closeTicketApi = listSettingsService?.value; + + if (closeTicketApi === 'enabled') { + setTimeout(async () => { + await UpdateTicketService({ + ticketId: contactAndTicket.id, + ticketData: { status: "closed" } + }); + }, 1000); + } + return res.send({ error: resp }); }; \ No newline at end of file diff --git a/frontend/src/pages/Settings/index.js b/frontend/src/pages/Settings/index.js index afd8875a..8eb3f805 100644 --- a/frontend/src/pages/Settings/index.js +++ b/frontend/src/pages/Settings/index.js @@ -208,6 +208,35 @@ const Settings = () => { + + + + + + {i18n.t("settings.settings.closeTicketApi.name")} + + + + + diff --git a/frontend/src/translate/languages/en.js b/frontend/src/translate/languages/en.js index f40ee753..7b5a27de 100644 --- a/frontend/src/translate/languages/en.js +++ b/frontend/src/translate/languages/en.js @@ -403,6 +403,14 @@ const messages = { disabled: "Closed", }, }, + closeTicketApi: { + name: "Close Ticket sent API", + note: "Automatically closes ticket when submitted via API", + options: { + enabled: "Enabled", + disabled: "Disabled", + }, + }, messagesList: { header: { assignedTo: "Assigned to:", diff --git a/frontend/src/translate/languages/es.js b/frontend/src/translate/languages/es.js index 64f495ec..db24dec9 100644 --- a/frontend/src/translate/languages/es.js +++ b/frontend/src/translate/languages/es.js @@ -393,6 +393,14 @@ const messages = { disabled: "Cerrado", }, }, + closeTicketApi: { + name: "Cerrar ticket enviado API", + note: "Cierra automáticamente el ticket cuando se envía a través de API", + options: { + enabled: "Habilitado", + disabled: "Habilitado", + }, + }, timeCreateNewTicket: { name: "Crear nuevo ticket después", note: "Selecciona el tiempo que tardará en abrir un nuevo ticket si el cliente te vuelve a contactar", diff --git a/frontend/src/translate/languages/pt.js b/frontend/src/translate/languages/pt.js index 026385cd..cccc6ed4 100644 --- a/frontend/src/translate/languages/pt.js +++ b/frontend/src/translate/languages/pt.js @@ -409,6 +409,14 @@ const messages = { disabled: "Fechado", }, }, + closeTicketApi: { + name: "Encerrar Ticket enviado API", + note: "Fecha automaticamente o ticket quando enviado por API", + options: { + enabled: "Ativado", + disabled: "Desativado", + }, + }, timeCreateNewTicket: { name: "Cria novo ticket após", note: "Selecione o tempo que será necessário para abrir um novo ticket, caso o cliente entre em contatos novamente",