Test multi device

pull/1/head
adriano 2022-04-11 08:04:49 -03:00
parent 37f2cb26ad
commit 96f9e200d3
2 changed files with 18 additions and 7 deletions

View File

@ -37,7 +37,7 @@
"sequelize-cli": "^5.5.1",
"sequelize-typescript": "^1.1.0",
"socket.io": "^3.0.5",
"whatsapp-web.js": "^1.15.6",
"whatsapp-web.js": "github:pedroslopez/whatsapp-web.js",
"yup": "^0.32.8"
},
"devDependencies": {

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";
@ -37,6 +37,8 @@ const syncUnreadMessages = async (wbot: Session) => {
export const initWbot = async (whatsapp: Whatsapp): Promise<Session> => {
return new Promise((resolve, reject) => {
try {
const io = getIO();
const sessionName = whatsapp.name;
let sessionCfg;
@ -45,21 +47,30 @@ export const initWbot = async (whatsapp: Whatsapp): Promise<Session> => {
sessionCfg = JSON.parse(whatsapp.session);
}
const wbot: Session = new Client({session: sessionCfg,
puppeteer: {executablePath: process.env.CHROME_BIN || undefined
}
//NOVA OPÇÃO MD
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 },
});
//OPÇÃO DEFAULT NAO MD
// const wbot: Session = new Client({session: sessionCfg,
// puppeteer: {executablePath: process.env.CHROME_BIN || undefined
// }
// });
//OPÇÃO MD COM ERRO
// const io = getIO();
// const sessionName = whatsapp.name;
// const SESSION_FILE_PATH = './session.json'
// let sessionCfg
// if(fs.existsSync(SESSION_FILE_PATH)){
// sessionCfg = require(SESSION_FILE_PATH)
// }
// }
// const wbot: Session = new Client({ puppeteer: { headless: true }, clientId: 'bd_'+whatsapp.id})
wbot.initialize();
wbot.on("qr", async qr => {