feat: add options to handle whatsapp session on frontend

This commit is contained in:
canove
2020-10-27 16:08:50 -03:00
parent 73cb08a557
commit e573656276
11 changed files with 408 additions and 84 deletions

View File

@@ -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);

View File

@@ -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);

View File

@@ -16,7 +16,7 @@ interface Response {
const CreateWhatsAppService = async ({
name,
status = "INITIALIZING",
status = "OPENING",
isDefault = false
}: Request): Promise<Response> => {
const schema = Yup.object().shape({