diff --git a/backend/src/services/WbotServices/SendWhatsAppMedia.ts b/backend/src/services/WbotServices/SendWhatsAppMedia.ts index b4c2e35..19c4e0c 100644 --- a/backend/src/services/WbotServices/SendWhatsAppMedia.ts +++ b/backend/src/services/WbotServices/SendWhatsAppMedia.ts @@ -5,10 +5,11 @@ import { exec } from "child_process"; import path from "path"; import ffmpegPath from "@ffmpeg-installer/ffmpeg"; import mime from "mime-types"; -import iconv from 'iconv-lite'; +import iconv from "iconv-lite"; import AppError from "../../errors/AppError"; import GetTicketWbot from "../../helpers/GetTicketWbot"; import Ticket from "../../models/Ticket"; +import { verifyMediaMessage } from "./wbotMessageListener"; interface Request { media: Express.Multer.File; @@ -185,9 +186,7 @@ const SendWhatsAppMedia = async ({ ...options } ); - - await ticket.update({ lastMessage: media.filename }); - + await verifyMediaMessage(sentMessage, ticket, ticket.contact); return sentMessage; } catch (err) { Sentry.captureException(err); diff --git a/backend/src/services/WbotServices/SendWhatsAppMessage.ts b/backend/src/services/WbotServices/SendWhatsAppMessage.ts index 1f16495..31de397 100644 --- a/backend/src/services/WbotServices/SendWhatsAppMessage.ts +++ b/backend/src/services/WbotServices/SendWhatsAppMessage.ts @@ -1,4 +1,4 @@ -import { WASocket, WAMessage } from "@whiskeysockets/baileys"; +import { WAMessage } from "@whiskeysockets/baileys"; import * as Sentry from "@sentry/node"; import AppError from "../../errors/AppError"; import GetTicketWbot from "../../helpers/GetTicketWbot"; @@ -6,6 +6,7 @@ import Message from "../../models/Message"; import Ticket from "../../models/Ticket"; import formatBody from "../../helpers/Mustache"; +import { verifyMessage } from "./wbotMessageListener"; interface Request { body: string; @@ -59,9 +60,7 @@ const SendWhatsAppMessage = async ({ ...options } ); - - await ticket.update({ lastMessage: formattedBody }); - + await verifyMessage(sentMessage, ticket, ticket.contact); return sentMessage; } catch (err) { Sentry.captureException(err); diff --git a/backend/src/services/WbotServices/wbotMessageListener.ts b/backend/src/services/WbotServices/wbotMessageListener.ts index e5d0dfc..bd6bde8 100644 --- a/backend/src/services/WbotServices/wbotMessageListener.ts +++ b/backend/src/services/WbotServices/wbotMessageListener.ts @@ -511,7 +511,7 @@ const saveMediaToFile = async (media) => { } } -const verifyMediaMessage = async ( +export const verifyMediaMessage = async ( msg: proto.IWebMessageInfo, ticket: Ticket, contact: Contact,