mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-18 03:39:29 +00:00
37 lines
856 B
TypeScript
37 lines
856 B
TypeScript
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<Message> => {
|
|
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;
|