From fbbecdc0b2deddeed9b867a1e76d21adf8d1b568 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Ara=C3=BAjo=20Paes?= Date: Fri, 19 Aug 2022 08:36:36 -0300 Subject: [PATCH] :sparkles: Adding multidevice whatsapp support --- .gitattributes | 12 ++++++++++++ backend/.dockerignore | 3 ++- backend/.gitignore | 2 ++ backend/src/libs/wbot.ts | 21 +++++++++++---------- docker-compose.yaml | 1 + 5 files changed, 28 insertions(+), 11 deletions(-) create mode 100755 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100755 index 0000000..4e91794 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,12 @@ +* text=auto +*.sh text eol=lf +Dockerfile eol=lf +docker-compose.yml eol=lf +docker-compose.*.yml eol=lf +*.jpg binary +*.png binary +*.gif binary +*.woff binary +*.tff binary +*.eot binary +*.otf binary \ No newline at end of file diff --git a/backend/.dockerignore b/backend/.dockerignore index 0d40646..8c6a991 100644 --- a/backend/.dockerignore +++ b/backend/.dockerignore @@ -2,4 +2,5 @@ *Dockerfile* *docker-compose* node_modules -dist \ No newline at end of file +dist +.wwebjs_auth \ No newline at end of file diff --git a/backend/.gitignore b/backend/.gitignore index 1c092bc..167546d 100644 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -14,3 +14,5 @@ yarn-error.log # Ignore test-related files /coverage.data /coverage/ + +.wwebjs_auth/ \ No newline at end of file diff --git a/backend/src/libs/wbot.ts b/backend/src/libs/wbot.ts index 0ef7ecb..1b6794f 100644 --- a/backend/src/libs/wbot.ts +++ b/backend/src/libs/wbot.ts @@ -42,14 +42,18 @@ export const initWbot = async (whatsapp: Whatsapp): Promise => { if (whatsapp && whatsapp.session) { sessionCfg = JSON.parse(whatsapp.session); } - - const wbot: Session = new Client({ + + const args:String = process.env.CHROME_ARGS || ""; + + const wbot: Session = new Client({ session: sessionCfg, authStrategy: new LocalAuth({clientId: 'bd_'+whatsapp.id}), - puppeteer: { - args: ['--no-sandbox', '--disable-setuid-sandbox'], - executablePath: process.env.CHROME_BIN || undefined - }, + puppeteer: { + executablePath: process.env.CHROME_BIN || undefined, + // @ts-ignore + browserWSEndpoint: process.env.CHROME_WS || undefined, + args: args.split(' ') + } }); wbot.initialize(); @@ -73,9 +77,6 @@ export const initWbot = async (whatsapp: Whatsapp): Promise => { wbot.on("authenticated", async session => { logger.info(`Session: ${sessionName} AUTHENTICATED`); -// await whatsapp.update({ -// session: JSON.stringify(session) -// }); }); wbot.on("auth_failure", async msg => { @@ -151,4 +152,4 @@ export const removeWbot = (whatsappId: number): void => { } catch (err) { logger.error(err); } -}; +}; \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index e397ab1..3526645 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -24,6 +24,7 @@ services: - ${BACKEND_PORT:-8080}:3000 volumes: - ./backend/public/:/usr/src/app/public/ + - ./backend/.wwebjs_auth/:/usr/src/app/.wwebjs_auth/ networks: - whaticket