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,22 @@
import { Client as Session } from "whatsapp-web.js";
import { getWbot } from "../libs/wbot";
import AppError from "../errors/AppError";
import GetDefaultWhatsApp from "./GetDefaultWhatsApp";
import Ticket from "../models/Ticket";
const GetTicketWbot = async (ticket: Ticket): Promise<Session> => {
if (!ticket.whatsappId) {
const defaultWhatsapp = await GetDefaultWhatsApp();
if (!defaultWhatsapp) {
throw new AppError("No default WhatsApp found. Check Connection page.");
}
await ticket.$set("whatsapp", defaultWhatsapp);
}
const wbot = getWbot(ticket.whatsappId);
return wbot;
};
export default GetTicketWbot;