mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-19 20:29:17 +00:00
feat: add options to handle whatsapp session on frontend
This commit is contained in:
@@ -1,11 +1,20 @@
|
||||
import { initWbot } from "../../libs/wbot";
|
||||
import Whatsapp from "../../models/Whatsapp";
|
||||
import wbotMessageListener from "./wbotMessageListener";
|
||||
import { getIO } from "../../libs/socket";
|
||||
import wbotMonitor from "./wbotMonitor";
|
||||
|
||||
export const StartWhatsAppSession = async (
|
||||
whatsapp: Whatsapp
|
||||
): Promise<void> => {
|
||||
await whatsapp.update({ status: "OPENING" });
|
||||
|
||||
const io = getIO();
|
||||
io.emit("whatsappSession", {
|
||||
action: "update",
|
||||
session: whatsapp
|
||||
});
|
||||
|
||||
try {
|
||||
const wbot = await initWbot(whatsapp);
|
||||
wbotMessageListener(wbot);
|
||||
|
||||
@@ -54,7 +54,7 @@ const wbotMonitor = async (
|
||||
wbot.on("disconnected", async reason => {
|
||||
console.log("Disconnected session:", sessionName, reason);
|
||||
try {
|
||||
await whatsapp.update({ status: "DISCONNECTED", session: "" });
|
||||
await whatsapp.update({ status: "OPENING", session: "" });
|
||||
} catch (err) {
|
||||
Sentry.captureException(err);
|
||||
console.log(err);
|
||||
|
||||
Reference in New Issue
Block a user