import AppError from "../../errors/AppError"; import GetWbotMessage from "../../helpers/GetWbotMessage"; import Message from "../../models/Message"; import Ticket from "../../models/Ticket"; const DeleteWhatsAppMessage = async (messageId: string): Promise => { const message = await Message.findByPk(messageId, { include: [ { model: Ticket, as: "ticket", include: ["contact"] } ] }); if (!message) { throw new AppError("No message found with this ID."); } const { ticket } = message; const messageToDelete = await GetWbotMessage(ticket, messageId); try { await messageToDelete.delete(true); } catch (err) { throw new AppError( "Couldn't delete message from WhatsApp. Check connections page." ); } return message; }; export default DeleteWhatsAppMessage;