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";
|
|
|
|
|
|
|
|
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}`)
|
|
|
|
|
|
|
|
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...')
|
|
|
|
|
2022-07-12 12:37:34 +00:00
|
|
|
await StartWhatsAppSession(whatsapp, backupSession);
|
2022-06-27 06:21:04 +00:00
|
|
|
|
|
|
|
}
|