34 lines
946 B
TypeScript
34 lines
946 B
TypeScript
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";
|
|
import { insertOrUpeateWhatsCache } from "../../helpers/WhatsCache";
|
|
|
|
export const StartWhatsAppSession = async (whatsapp: Whatsapp, backupSession: boolean = false): Promise<void> => {
|
|
await whatsapp.update({ status: "OPENING" });
|
|
|
|
console.log('kkkkkkkkkkkkkxxxxxxxxxxxxxxxxxx')
|
|
|
|
await insertOrUpeateWhatsCache(`whatsapp:${whatsapp.id}`, {
|
|
status: "OPENING",
|
|
})
|
|
|
|
const io = getIO();
|
|
io.emit("whatsappSession", {
|
|
action: "update",
|
|
session: whatsapp
|
|
});
|
|
|
|
try {
|
|
const wbot = await initWbot(whatsapp, backupSession);
|
|
wbotMessageListener(wbot);
|
|
wbotMonitor(wbot, whatsapp);
|
|
} catch (err) {
|
|
|
|
logger.error(`${err}`);
|
|
|
|
}
|
|
};
|