diff --git a/.env.example b/.env.example index 1e1f5d15..89168694 100644 --- a/.env.example +++ b/.env.example @@ -14,6 +14,8 @@ DISABLED_CALLBACKS=message_ack|message_reaction|unread_count|message_edit|messag WEB_VERSION='2.2328.5' # OPTIONAL, THE VERSION OF WHATSAPP WEB TO USE WEB_VERSION_CACHE_TYPE=none # OPTIONAL, DETERMINTES WHERE TO GET THE WHATSAPP WEB VERSION(local, remote or none), DEFAULT 'none' RECOVER_SESSIONS=TRUE # OPTIONAL, SHOULD WE RECOVER THE SESSION IN CASE OF PAGE FAILURES +CHROME_BIN= # OPTIONAL, PATH TO CHROME BINARY +HEADLESS=TRUE # OPTIONAL, RUN CHROME IN HEADLESS MODE ## Session File Storage ## SESSIONS_PATH=./sessions # OPTIONAL diff --git a/src/config.js b/src/config.js index e28d994a..ffecabad 100644 --- a/src/config.js +++ b/src/config.js @@ -15,6 +15,8 @@ const webVersionCacheType = process.env.WEB_VERSION_CACHE_TYPE || 'none' const rateLimitMax = process.env.RATE_LIMIT_MAX || 1000 const rateLimitWindowMs = process.env.RATE_LIMIT_WINDOW_MS || 1000 const recoverSessions = (process.env.RECOVER_SESSIONS || '').toLowerCase() === 'true' +const chromeBin = process.env.CHROME_BIN || null +const headless = process.env.HEADLESS ? (process.env.HEADLESS).toLowerCase() === 'true' : true module.exports = { sessionFolderPath, @@ -29,5 +31,7 @@ module.exports = { webVersionCacheType, rateLimitMax, rateLimitWindowMs, - recoverSessions + recoverSessions, + chromeBin, + headless } diff --git a/src/controllers/sessionController.js b/src/controllers/sessionController.js index 51186f94..d8bd8869 100644 --- a/src/controllers/sessionController.js +++ b/src/controllers/sessionController.js @@ -42,9 +42,8 @@ const startSession = async (req, res) => { } */ // wait until the client is created - waitForNestedObject(setupSessionReturn.client, 'pupPage') - .then(res.json({ success: true, message: setupSessionReturn.message })) - .catch((err) => { sendErrorResponse(res, 500, err.message) }) + await waitForNestedObject(setupSessionReturn.client, 'pupPage') + res.json({ success: true, message: setupSessionReturn.message }) } catch (error) { /* #swagger.responses[500] = { description: "Server Failure.", diff --git a/src/sessions.js b/src/sessions.js index 45fccf5f..39a03d2c 100644 --- a/src/sessions.js +++ b/src/sessions.js @@ -2,7 +2,7 @@ const { Client, LocalAuth } = require('whatsapp-web.js') const fs = require('fs') const path = require('path') const sessions = new Map() -const { baseWebhookURL, sessionFolderPath, maxAttachmentSize, setMessagesAsSeen, webVersion, webVersionCacheType, recoverSessions } = require('./config') +const { baseWebhookURL, sessionFolderPath, maxAttachmentSize, setMessagesAsSeen, webVersion, webVersionCacheType, recoverSessions, chromeBin, headless } = require('./config') const { triggerWebhook, waitForNestedObject, checkIfEventisEnabled } = require('./utils') // Function to validate if the session is ready @@ -97,8 +97,8 @@ const setupSession = (sessionId) => { const clientOptions = { puppeteer: { - executablePath: process.env.CHROME_BIN || null, - // headless: false, + executablePath: chromeBin, + headless, args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-gpu', '--disable-dev-shm-usage'] }, userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36',