projeto-hit/backend/src/controllers/WbotMonitorController.ts

93 lines
2.2 KiB
TypeScript
Raw Normal View History

import { Request, Response } from "express";
import { getIO } from "../libs/socket";
import ShowWhatsAppService from "../services/WhatsappService/ShowWhatsAppService";
import { logger } from "../utils/logger";
import * as Sentry from "@sentry/node";
// type IndexQuery = {
// centro_custo: string;
// };
export const wbotMonitorRemote = async (req: Request, res: Response): Promise<Response> => {
const { action, whatsappId, reason } = req.body
console.log('-----------> ACTION: ', req.body['action'])
let whatsapp = await ShowWhatsAppService(whatsappId)
if (action === 'disconnected') {
logger.info(`Disconnected session: ${whatsapp.name}, reason: ${reason}`);
}
const io = getIO();
io.emit("whatsappSession", {
action: "update",
session: whatsapp
});
return res.status(200).json({ "message": "Ok" });
};
export const wbotMonitorQrcodeRemote = async (req: Request, res: Response): Promise<Response> => {
const { whatsappId } = req.body
console.log('-----------> whatsappId: ', req.body['whatsappId'])
let whatsapp = await ShowWhatsAppService(whatsappId)
const io = getIO();
io.emit("whatsappSession", {
action: "update",
session: whatsapp
});
return res.status(200).json({ "message": "Ok" });
};
// export const wbotMonitorNumberRead = async (req: Request, res: Response): Promise<Response> => {
// const { whatsappId } = req.body
// console.log('-----------> whatsappId: ', req.body['whatsappId'])
// let whatsapp = await ShowWhatsAppService(whatsappId)
// const io = getIO();
// io.emit("whatsappSession", {
// action: "update",
// session: whatsapp
// });
// return res.status(200).json({ "message": "Ok" });
// };
// export const DeleteWhatsAppMessage = async (req: Request, res: Response): Promise<Response> => {
// const { whatsappId } = req.body
// console.log('-----------> whatsappId: ', req.body['whatsappId'])
// let whatsapp = await ShowWhatsAppService(whatsappId)
// const io = getIO();
// io.emit("whatsappSession", {
// action: "update",
// session: whatsapp
// });
// return res.status(200).json({ "message": "Ok" });
// };