Merge pull request #432 from Kouthk/patch-2

🔨configuração para utilizar whatsapp multi-device
This commit is contained in:
Cassio Santos
2022-05-24 21:39:31 -03:00
committed by GitHub

View File

@@ -1,5 +1,5 @@
import qrCode from "qrcode-terminal";
import { Client } from "whatsapp-web.js";
import { Client, LocalAuth } from "whatsapp-web.js";
import { getIO } from "./socket";
import Whatsapp from "../models/Whatsapp";
import AppError from "../errors/AppError";
@@ -42,17 +42,14 @@ export const initWbot = async (whatsapp: Whatsapp): Promise<Session> => {
if (whatsapp && whatsapp.session) {
sessionCfg = JSON.parse(whatsapp.session);
}
const args:String = process.env.CHROME_ARGS || "";
const wbot: Session = new Client({
const wbot: Session = new Client({
session: sessionCfg,
puppeteer: {
executablePath: process.env.CHROME_BIN || undefined,
// @ts-ignore
browserWSEndpoint: process.env.CHROME_WS || undefined,
args: args.split(' ')
}
authStrategy: new LocalAuth({clientId: 'bd_'+whatsapp.id}),
puppeteer: {
args: ['--no-sandbox', '--disable-setuid-sandbox'],
executablePath: process.env.CHROME_BIN || undefined
},
});
wbot.initialize();
@@ -76,9 +73,9 @@ export const initWbot = async (whatsapp: Whatsapp): Promise<Session> => {
wbot.on("authenticated", async session => {
logger.info(`Session: ${sessionName} AUTHENTICATED`);
await whatsapp.update({
session: JSON.stringify(session)
});
// await whatsapp.update({
// session: JSON.stringify(session)
// });
});
wbot.on("auth_failure", async msg => {