2022-01-06 01:26:15 +00:00
|
|
|
import { initWbot } from "../../libs/wbot";
|
|
|
|
import Whatsapp from "../../models/Whatsapp";
|
|
|
|
import { wbotMessageListener } from "./wbotMessageListener";
|
|
|
|
import { getIO } from "../../libs/socket";
|
|
|
|
import wbotMonitor from "./wbotMonitor";
|
|
|
|
import { logger } from "../../utils/logger";
|
|
|
|
|
|
|
|
export const StartWhatsAppSession = async (
|
|
|
|
whatsapp: Whatsapp
|
|
|
|
): Promise<void> => {
|
2022-02-14 01:39:33 +00:00
|
|
|
await whatsapp.update({ status: "OPENING" });
|
2022-01-06 01:26:15 +00:00
|
|
|
|
|
|
|
const io = getIO();
|
|
|
|
io.emit("whatsappSession", {
|
|
|
|
action: "update",
|
|
|
|
session: whatsapp
|
|
|
|
});
|
|
|
|
|
|
|
|
try {
|
|
|
|
const wbot = await initWbot(whatsapp);
|
|
|
|
wbotMessageListener(wbot);
|
|
|
|
wbotMonitor(wbot, whatsapp);
|
2022-02-22 20:36:11 +00:00
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
logger.error(`${err}`);
|
2022-02-14 01:39:33 +00:00
|
|
|
|
2022-01-06 01:26:15 +00:00
|
|
|
}
|
|
|
|
};
|