fix: handling wwebjs erros without blocking routes

This commit is contained in:
canove
2020-09-22 16:33:13 -03:00
parent 0d8b4cd60c
commit 5c7a759efa
7 changed files with 80 additions and 74 deletions

View File

@@ -11,12 +11,7 @@ import uploadConfig from "./config/upload";
import AppError from "./errors/AppError";
import routes from "./routes";
import { initIO } from "./libs/socket";
import { initWbot } from "./libs/wbot";
// const wbotMonitor = require("./services/wbotMonitor");
import Whatsapp from "./models/Whatsapp";
import wbotMessageListener from "./services/WbotServices/wbotMessageListener";
import wbotMonitor from "./services/WbotServices/wbotMonitor";
import { StartWhatsAppSessions } from "./services/WbotServices/StartWhatsAppSessions";
Sentry.init({ dsn: process.env.SENTRY_DSN });
@@ -34,38 +29,8 @@ const server = app.listen(process.env.PORT, () => {
console.log(`Server started on port: ${process.env.PORT}`);
});
const io = initIO(server);
io.on("connection", socket => {
console.log("Client Connected");
socket.on("joinChatBox", ticketId => {
console.log("A client joined a ticket channel");
socket.join(ticketId);
});
socket.on("joinNotification", () => {
console.log("A client joined notification channel");
socket.join("notification");
});
socket.on("disconnect", () => {
console.log("Client disconnected");
});
});
const startWhatsAppSessions = async () => {
const whatsapps = await Whatsapp.findAll();
if (whatsapps.length > 0) {
whatsapps.forEach(whatsapp => {
initWbot(whatsapp)
.then(() => {
wbotMessageListener(whatsapp);
wbotMonitor(whatsapp);
})
.catch(err => console.log(err));
});
}
};
startWhatsAppSessions();
initIO(server);
StartWhatsAppSessions();
app.use(Sentry.Handlers.errorHandler());