2022-06-27 06:21:04 +00:00
|
|
|
import path from "path";
|
|
|
|
import { number } from "yup";
|
|
|
|
import { removeWbot } from "../libs/wbot";
|
|
|
|
import Whatsapp from "../models/Whatsapp";
|
|
|
|
import { StartWhatsAppSession } from "../services/WbotServices/StartWhatsAppSession";
|
|
|
|
import { copyFolder } from "./CopyFolder";
|
|
|
|
import { removeDir } from "./DeleteDirectory";
|
2023-01-01 23:40:00 +00:00
|
|
|
// import internetConnection from "./InternetConnection";
|
2022-06-27 06:21:04 +00:00
|
|
|
|
|
|
|
const fsPromises = require("fs/promises");
|
|
|
|
const fs = require('fs')
|
|
|
|
|
|
|
|
// Restart session
|
2022-07-12 12:37:34 +00:00
|
|
|
export const restartWhatsSession = async (whatsapp: Whatsapp, backupSession: boolean = false) => {
|
2022-06-27 06:21:04 +00:00
|
|
|
|
|
|
|
console.log('RESTARTING THE whatsapp.id: ', whatsapp.id)
|
|
|
|
|
|
|
|
const sourcePath = path.join(__dirname, `../../.wwebjs_auth/sessions/`, `session-bd_${whatsapp.id}`)
|
|
|
|
const destPath = path.join(__dirname, `../../.wwebjs_auth/`, `session-bd_${whatsapp.id}`)
|
|
|
|
|
2022-11-16 13:23:14 +00:00
|
|
|
console.log('================> sourcePath: ', sourcePath)
|
|
|
|
console.log('================> destPath: ', destPath)
|
2022-06-27 06:21:04 +00:00
|
|
|
|
|
|
|
removeWbot(whatsapp.id)
|
|
|
|
|
2023-01-01 23:40:00 +00:00
|
|
|
await removeDir(destPath)
|
2022-06-27 06:21:04 +00:00
|
|
|
|
2023-01-01 23:40:00 +00:00
|
|
|
if (fs.existsSync(sourcePath)) {
|
2022-06-27 06:21:04 +00:00
|
|
|
// copy the good session for restars the new session
|
2023-01-01 23:40:00 +00:00
|
|
|
copyFolder(sourcePath, destPath)
|
2022-06-27 06:21:04 +00:00
|
|
|
}
|
2023-01-01 23:40:00 +00:00
|
|
|
else {
|
|
|
|
console.log('Directory not found to copy: ', sourcePath)
|
2022-06-27 06:21:04 +00:00
|
|
|
}
|
2023-01-01 23:40:00 +00:00
|
|
|
|
2022-06-27 06:21:04 +00:00
|
|
|
console.log('RESTARTING SESSION...')
|
|
|
|
|
2023-01-01 23:40:00 +00:00
|
|
|
// await StartWhatsAppSession(whatsapp, backupSession);
|
2022-11-16 13:23:14 +00:00
|
|
|
|
|
|
|
setTimeout(() => StartWhatsAppSession(whatsapp, backupSession), 2000);
|
2022-06-27 06:21:04 +00:00
|
|
|
|
|
|
|
}
|