mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-18 19:59:20 +00:00
fix: handling wwebjs erros without blocking routes
This commit is contained in:
@@ -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());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user