From 6ceb8dc0387594d4cc9710fb683f1cd3c9a4c08b Mon Sep 17 00:00:00 2001 From: Claudemir Todo Bom Date: Thu, 16 May 2024 16:41:31 -0300 Subject: [PATCH] Default messages for finish and outOfHours --- .../TicketServices/UpdateTicketService.ts | 3 +-- .../WbotServices/wbotMessageListener.ts | 24 ++++++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/backend/src/services/TicketServices/UpdateTicketService.ts b/backend/src/services/TicketServices/UpdateTicketService.ts index 908db5d0..9039a9f1 100644 --- a/backend/src/services/TicketServices/UpdateTicketService.ts +++ b/backend/src/services/TicketServices/UpdateTicketService.ts @@ -110,8 +110,7 @@ const UpdateTicketService = async ({ if (setting?.value === "enabled") { if (ticketTraking.ratingAt == null && !justClose) { - - const ratingTxt = ratingMessage || ""; + const ratingTxt = ratingMessage?.trim() || ""; let bodyRatingMessage = `\u200e${ratingTxt}\n\n`; bodyRatingMessage += "Digite de 1 à 3 para qualificar nosso atendimento:\n*1* - _Insatisfeito_\n*2* - _Satisfeito_\n*3* - _Muito Satisfeito_\n\n"; diff --git a/backend/src/services/WbotServices/wbotMessageListener.ts b/backend/src/services/WbotServices/wbotMessageListener.ts index a0431384..a76f1d32 100644 --- a/backend/src/services/WbotServices/wbotMessageListener.ts +++ b/backend/src/services/WbotServices/wbotMessageListener.ts @@ -838,8 +838,8 @@ const startQueue = async (wbot: Session, ticket: Ticket, queue: Queue) => { !isNil(currentSchedule) && (!currentSchedule || currentSchedule.inActivity === false) ) { - - const body = formatBody(`${queue.outOfHoursMessage}\n\n*[ # ]* - Voltar ao Menu Principal`, ticket.contact); + const outOfHoursMessage = queue.outOfHoursMessage.trim() || "Estamos fora do horário de expediente"; + const body = formatBody(`${outOfHoursMessage}\n\n*[ # ]* - Voltar ao Menu Principal`, ticket.contact); const sentMessage = await wbot.sendMessage( `${contact.number}@${ticket.isGroup ? "g.us" : "s.whatsapp.net"}`, { text: body, @@ -1028,7 +1028,7 @@ export const handleRating = async ( } if (!Number.isNaN(rate) && Number.isInteger(rate) && !isNull(rate)) { - const { complationMessage } = await ShowWhatsAppService( + const whatsapp = await ShowWhatsAppService( ticket.whatsappId, ticket.companyId ); @@ -1048,6 +1048,8 @@ export const handleRating = async ( userId: ticketTraking.userId, rate: finalRate, }); + + const complationMessage = whatsapp.complationMessage.trim() || "Atendimento finalizado"; const body = formatBody(`\u200e${complationMessage}`, ticket.contact); await SendWhatsAppMessage({ body, ticket }); @@ -1306,7 +1308,9 @@ const handleMessage = async ( order: [["createdAt", "DESC"]], }); - if (unreadMessages === 0 && whatsapp.complationMessage && formatBody(whatsapp.complationMessage, contact).trim().toLowerCase() === lastMessage?.body.trim().toLowerCase()) { + const complationMessage = whatsapp.complationMessage.trim() || "Atendimento finalizado"; + + if (unreadMessages === 0 && complationMessage && formatBody(complationMessage, contact).trim().toLowerCase() === lastMessage?.body.trim().toLowerCase()) { return; } @@ -1402,7 +1406,7 @@ const handleMessage = async ( !isNil(currentSchedule) && (!currentSchedule || currentSchedule.inActivity === false) ) { - const body = `${whatsapp.outOfHoursMessage}`; + const body = `${whatsapp.outOfHoursMessage.trim() || "Estamos fora do horário de expediente"}`; const debouncedSentMessage = debounce( async () => { @@ -1448,15 +1452,14 @@ const handleMessage = async ( if ( scheduleType.value === "queue" && - queue.outOfHoursMessage !== null && - queue.outOfHoursMessage !== "" && !isNil(schedule) ) { const startTime = moment(schedule.startTime, "HH:mm"); const endTime = moment(schedule.endTime, "HH:mm"); if (now.isBefore(startTime) || now.isAfter(endTime)) { - const body = `${queue.outOfHoursMessage}`; + const outOfHoursMessage = queue.outOfHoursMessage?.trim() || "Estamos fora do horário de expediente"; + const body = `${outOfHoursMessage}`; const debouncedSentMessage = debounce( async () => { await wbot.sendMessage( @@ -1536,15 +1539,14 @@ const handleMessage = async ( if ( scheduleType.value === "queue" && - queue.outOfHoursMessage !== null && - queue.outOfHoursMessage !== "" && !isNil(schedule) ) { const startTime = moment(schedule.startTime, "HH:mm"); const endTime = moment(schedule.endTime, "HH:mm"); if (now.isBefore(startTime) || now.isAfter(endTime)) { - const body = queue.outOfHoursMessage; + const outOfHoursMessage = queue.outOfHoursMessage?.trim() || "Estamos fora do horário de expediente"; + const body = outOfHoursMessage; const debouncedSentMessage = debounce( async () => { await wbot.sendMessage(