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";
|
2023-01-01 23:40:00 +00:00
|
|
|
// import { insertOrUpeateWhatsCache } from "../../helpers/WhatsCache";
|
2022-01-06 01:26:15 +00:00
|
|
|
|
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
|
|
|
|
2022-01-06 01:26:15 +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);
|
2022-01-06 01:26:15 +00:00
|
|
|
wbotMessageListener(wbot);
|
|
|
|
wbotMonitor(wbot, whatsapp);
|
2022-06-27 06:21:04 +00:00
|
|
|
} catch (err) {
|
|
|
|
|
2022-02-22 20:36:11 +00:00
|
|
|
logger.error(`${err}`);
|
2022-06-27 06:21:04 +00:00
|
|
|
|
2022-01-06 01:26:15 +00:00
|
|
|
}
|
|
|
|
};
|