projeto-hit/backend/src/services/WbotServices/StartWhatsAppSession.ts

44 lines
1.4 KiB
TypeScript
Raw Normal View History

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";
2023-01-01 23:40:00 +00:00
// import { insertOrUpeateWhatsCache } from "../../helpers/WhatsCache";
2022-12-14 12:29:42 +00:00
import { getRestoreControll, setRestoreControll, shifRestoreControll } from "../../helpers/RestoreControll";
import ShowWhatsAppService from "../WhatsappService/ShowWhatsAppService";
import { restartWhatsSession } from "../../helpers/RestartWhatsSession";
2022-12-23 16:35:07 +00:00
import dir from 'path';
2022-12-14 12:29:42 +00:00
import autoRestore from "../../helpers/AutoRestore";
2022-12-23 16:35:07 +00:00
import { creationTime } from "../../helpers/CreationTime";
import { splitDateTime } from "../../helpers/SplitDateTime";
import { format } from "date-fns";
import ptBR from 'date-fns/locale/pt-BR';
2023-01-01 23:40:00 +00:00
import path from "path";
2023-01-04 15:17:59 +00:00
const fs = require('fs')
2023-01-01 23:40:00 +00:00
export const StartWhatsAppSession = async (whatsapp: Whatsapp, backupSession: boolean = false): Promise<void> => {
2022-12-14 12:29:42 +00:00
2023-01-04 15:17:59 +00:00
await whatsapp.update({ status: "OPENING" });
2022-12-14 12:29:42 +00:00
const io = getIO();
io.emit("whatsappSession", {
action: "update",
session: whatsapp
});
try {
2022-07-12 12:37:34 +00:00
const wbot = await initWbot(whatsapp, backupSession);
wbotMessageListener(wbot);
wbotMonitor(wbot, whatsapp);
} catch (err) {
logger.error(`${err}`);
}
};