feat: started multiple whatsapps support

This commit is contained in:
canove
2020-09-04 20:18:11 -03:00
parent f7fe3286b8
commit 8786c7ca5e
6 changed files with 72 additions and 36 deletions

View File

@@ -10,6 +10,7 @@ const Sentry = require("@sentry/node");
const wBot = require("./libs/wbot");
const wbotMessageListener = require("./services/wbotMessageListener");
const wbotMonitor = require("./services/wbotMonitor");
const Whatsapp = require("./models/Whatsapp");
const Router = require("./router");
@@ -55,13 +56,30 @@ io.on("connection", socket => {
});
});
wBot
.init()
.then(({ dbSession }) => {
wbotMessageListener();
wbotMonitor(dbSession);
})
.catch(err => console.log(err));
const startWhatsAppSessions = async () => {
const whatsapps = await Whatsapp.findAll();
if (whatsapps.length > 0) {
whatsapps.forEach(dbSession => {
wBot
.init(dbSession)
.then(() => {
wbotMessageListener(dbSession);
wbotMonitor(dbSession);
})
.catch(err => console.log(err));
});
}
};
startWhatsAppSessions();
// wBot
// .init()
// .then(({ dbSession }) => {
// wbotMessageListener();
// wbotMonitor(dbSession);
// })
// .catch(err => console.log(err));
app.use(Sentry.Handlers.errorHandler());