Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -29,5 +31,7 @@ module.exports = {
webVersionCacheType,
rateLimitMax,
rateLimitWindowMs,
recoverSessions
recoverSessions,
chromeBin,
headless
}
5 changes: 2 additions & 3 deletions src/controllers/sessionController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
6 changes: 3 additions & 3 deletions src/sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand Down