migrated receive message logic to typescript

This commit is contained in:
canove
2020-09-22 09:15:18 -03:00
parent 391cd5495c
commit 48dbf7e859
14 changed files with 423 additions and 403 deletions

View File

@@ -0,0 +1,34 @@
import { getIO } from "../libs/socket";
import { getWbot } from "../libs/wbot";
import Message from "../models/Message";
import Ticket from "../models/Ticket";
const SetTicketMessagesAsRead = async (ticket: Ticket): Promise<void> => {
const wbot = getWbot(ticket.whatsappId);
await Message.update(
{ read: true },
{
where: {
ticketId: ticket.id,
read: false
}
}
);
try {
await wbot.sendSeen(`${ticket.contact.number}@c.us`);
} catch (err) {
console.log(
"Could not mark messages as read. Maybe whatsapp session disconnected?"
);
}
const io = getIO();
io.to("notification").emit("ticket", {
action: "updateUnread",
ticketId: ticket.id
});
};
export default SetTicketMessagesAsRead;