Fix SingletonLock issue on restart

This commit is contained in:
Deep Koluguri 2026-06-19 15:59:36 -04:00
parent a75fcfd67d
commit fc02bb1dfd
1 changed files with 19 additions and 0 deletions

View File

@ -23,6 +23,25 @@ app.use(express.json());
app.use(express.static(path.join(__dirname, 'public'))); app.use(express.static(path.join(__dirname, 'public')));
// Initialize WhatsApp Web Client with LocalAuth to persist session // Initialize WhatsApp Web Client with LocalAuth to persist session
function removeSingletonLock() {
try {
const authPath = path.join(__dirname, '.wwebjs_auth');
if (require('fs').existsSync(authPath)) {
const sessions = require('fs').readdirSync(authPath);
for (const session of sessions) {
const lockPath = path.join(authPath, session, 'SingletonLock');
if (require('fs').existsSync(lockPath)) {
require('fs').unlinkSync(lockPath);
console.log(`[WhatsApp Bot] Removed stale SingletonLock at ${lockPath}`);
}
}
}
} catch (err) {
console.error('[WhatsApp Bot] Error removing SingletonLock:', err);
}
}
removeSingletonLock();
const client = new Client({ const client = new Client({
authStrategy: new LocalAuth({ authStrategy: new LocalAuth({
dataPath: './.wwebjs_auth' dataPath: './.wwebjs_auth'