mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-18 19:59:20 +00:00
feat: show an alert when connection with whatsapp brokes
This commit is contained in:
@@ -2,6 +2,7 @@ import { Request, Response } from "express";
|
||||
import { getWbot } from "../libs/wbot";
|
||||
import ShowWhatsAppService from "../services/WhatsappService/ShowWhatsAppService";
|
||||
import { StartWhatsAppSession } from "../services/WbotServices/StartWhatsAppSession";
|
||||
import UpdateWhatsAppService from "../services/WhatsappService/UpdateWhatsAppService";
|
||||
|
||||
const store = async (req: Request, res: Response): Promise<Response> => {
|
||||
const { whatsappId } = req.params;
|
||||
@@ -14,9 +15,11 @@ const store = async (req: Request, res: Response): Promise<Response> => {
|
||||
|
||||
const update = async (req: Request, res: Response): Promise<Response> => {
|
||||
const { whatsappId } = req.params;
|
||||
const whatsapp = await ShowWhatsAppService(whatsappId);
|
||||
|
||||
await whatsapp.update({ session: "" });
|
||||
const { whatsapp } = await UpdateWhatsAppService({
|
||||
whatsappId,
|
||||
whatsappData: { session: "" }
|
||||
});
|
||||
|
||||
StartWhatsAppSession(whatsapp);
|
||||
|
||||
|
||||
@@ -21,12 +21,6 @@ export const initWbot = async (whatsapp: Whatsapp): Promise<Session> => {
|
||||
sessionCfg = JSON.parse(whatsapp.session);
|
||||
}
|
||||
|
||||
const currentSessionIndex = sessions.findIndex(s => s.id === whatsapp.id);
|
||||
if (currentSessionIndex !== -1) {
|
||||
sessions[currentSessionIndex].destroy();
|
||||
sessions.splice(currentSessionIndex, 1);
|
||||
}
|
||||
|
||||
const wbot: Session = new Client({
|
||||
session: sessionCfg
|
||||
});
|
||||
|
||||
@@ -7,6 +7,7 @@ import Whatsapp from "../../models/Whatsapp";
|
||||
interface WhatsappData {
|
||||
name?: string;
|
||||
status?: string;
|
||||
session?: string;
|
||||
isDefault?: boolean;
|
||||
}
|
||||
|
||||
@@ -29,7 +30,7 @@ const UpdateWhatsAppService = async ({
|
||||
isDefault: Yup.boolean()
|
||||
});
|
||||
|
||||
const { name, status, isDefault } = whatsappData;
|
||||
const { name, status, isDefault, session } = whatsappData;
|
||||
|
||||
try {
|
||||
await schema.validate({ name, status, isDefault });
|
||||
@@ -58,6 +59,7 @@ const UpdateWhatsAppService = async ({
|
||||
await whatsapp.update({
|
||||
name,
|
||||
status,
|
||||
session,
|
||||
isDefault
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user