diff --git a/whatsapp-gateway/server.js b/whatsapp-gateway/server.js index 25f2885..d5a11b1 100644 --- a/whatsapp-gateway/server.js +++ b/whatsapp-gateway/server.js @@ -23,6 +23,25 @@ app.use(express.json()); app.use(express.static(path.join(__dirname, 'public'))); // 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({ authStrategy: new LocalAuth({ dataPath: './.wwebjs_auth'