42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
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";
|
|
// import internetConnection from "./InternetConnection";
|
|
|
|
const fsPromises = require("fs/promises");
|
|
const fs = require('fs')
|
|
|
|
// Restart session
|
|
export const restartWhatsSession = async (whatsapp: Whatsapp, backupSession: boolean = false) => {
|
|
|
|
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}`)
|
|
|
|
console.log('================> sourcePath: ', sourcePath)
|
|
console.log('================> destPath: ', destPath)
|
|
|
|
removeWbot(whatsapp.id)
|
|
|
|
await removeDir(destPath)
|
|
|
|
if (fs.existsSync(sourcePath)) {
|
|
// copy the good session for restars the new session
|
|
copyFolder(sourcePath, destPath)
|
|
}
|
|
else {
|
|
console.log('Directory not found to copy: ', sourcePath)
|
|
}
|
|
|
|
console.log('RESTARTING SESSION...')
|
|
|
|
// await StartWhatsAppSession(whatsapp, backupSession);
|
|
|
|
setTimeout(() => StartWhatsAppSession(whatsapp, backupSession), 2000);
|
|
|
|
} |