44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
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";
|
|
|
|
import { getRestoreControll, setRestoreControll, shifRestoreControll } from "../../helpers/RestoreControll";
|
|
import ShowWhatsAppService from "../WhatsappService/ShowWhatsAppService";
|
|
import { restartWhatsSession } from "../../helpers/RestartWhatsSession";
|
|
|
|
import dir from 'path';
|
|
|
|
import autoRestore from "../../helpers/AutoRestore";
|
|
import { creationTime } from "../../helpers/CreationTime";
|
|
import { splitDateTime } from "../../helpers/SplitDateTime";
|
|
|
|
import { format } from "date-fns";
|
|
import ptBR from 'date-fns/locale/pt-BR';
|
|
import path from "path";
|
|
const fs = require('fs')
|
|
|
|
export const StartWhatsAppSession = async (whatsapp: Whatsapp, backupSession: boolean = false): Promise<void> => {
|
|
|
|
await whatsapp.update({ 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}`);
|
|
|
|
}
|
|
};
|