Finalização do restore remoto
parent
f589b29387
commit
9a55f7d5d8
|
@ -3,6 +3,7 @@ import { getIO } from "../libs/socket";
|
|||
import ShowWhatsAppService from "../services/WhatsappService/ShowWhatsAppService";
|
||||
import { logger } from "../utils/logger";
|
||||
import * as Sentry from "@sentry/node";
|
||||
import Whatsapp from "../models/Whatsapp";
|
||||
|
||||
|
||||
// type IndexQuery = {
|
||||
|
@ -15,8 +16,11 @@ export const wbotMonitorRemote = async (req: Request, res: Response): Promise<Re
|
|||
|
||||
console.log('-----------> ACTION: ', req.body['action'])
|
||||
|
||||
let whatsapp = await ShowWhatsAppService(whatsappId)
|
||||
// let whatsapp = await ShowWhatsAppService(whatsappId)
|
||||
|
||||
const whatsapp: any = await Whatsapp.findByPk(whatsappId, { raw: true })
|
||||
|
||||
if (whatsapp) {
|
||||
if (action === 'disconnected') {
|
||||
logger.info(`Disconnected session: ${whatsapp.name}, reason: ${reason}`);
|
||||
}
|
||||
|
@ -27,6 +31,8 @@ export const wbotMonitorRemote = async (req: Request, res: Response): Promise<Re
|
|||
session: whatsapp
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
return res.status(200).json({ "message": "Ok" });
|
||||
};
|
||||
|
||||
|
@ -39,55 +45,37 @@ export const wbotMonitorQrcodeRemote = async (req: Request, res: Response): Prom
|
|||
|
||||
console.log('-----------> whatsappId: ', req.body['whatsappId'])
|
||||
|
||||
let whatsapp = await ShowWhatsAppService(whatsappId)
|
||||
const whatsapp: any = await Whatsapp.findByPk(whatsappId, { raw: true })
|
||||
// let whatsapp = await ShowWhatsAppService(whatsappId)
|
||||
|
||||
if (whatsapp) {
|
||||
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> => {
|
||||
export const wbotMonitorQrcodeNumberRead = async (req: Request, res: Response): Promise<Response> => {
|
||||
|
||||
// const { whatsappId } = req.body
|
||||
const { number } = req.body
|
||||
|
||||
// console.log('-----------> whatsappId: ', req.body['whatsappId'])
|
||||
console.log('-----------> number read: ', number)
|
||||
|
||||
// let whatsapp = await ShowWhatsAppService(whatsappId)
|
||||
const io = getIO();
|
||||
io.emit("whatsappSession", {
|
||||
action: "error",
|
||||
msg: `Numero lido: ${number} \nEssa sessão de whatsapp foi desconectada porque o numero que esta descrito no nome dessa sessão não corresponde ao numero lido!`
|
||||
});
|
||||
|
||||
// const io = getIO();
|
||||
// io.emit("whatsappSession", {
|
||||
// action: "update",
|
||||
// session: whatsapp
|
||||
// });
|
||||
|
||||
|
||||
// return res.status(200).json({ "message": "Ok" });
|
||||
// };
|
||||
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" });
|
||||
// };
|
|
@ -15,6 +15,8 @@ import { setRestoreControll, getRestoreControll, shifRestoreControll } from "../
|
|||
|
||||
import autoRestore from "../helpers/AutoRestore";
|
||||
import axios from "axios";
|
||||
import Whatsapp from "../models/Whatsapp";
|
||||
import endPointQuery from "../helpers/EndPointQuery";
|
||||
|
||||
|
||||
// let lstRestore: any = []
|
||||
|
@ -68,7 +70,28 @@ const restart = async (req: Request, res: Response): Promise<Response> => {
|
|||
|
||||
}
|
||||
|
||||
await autoRestore(whatsappId, 'human')
|
||||
let whatsapp: any = await Whatsapp.findByPk(whatsappId)
|
||||
|
||||
if (whatsapp) {
|
||||
|
||||
await whatsapp.update({ status: 'OPENING' });
|
||||
|
||||
const io = getIO();
|
||||
io.emit("whatsappSession", {
|
||||
action: "update",
|
||||
session: whatsapp
|
||||
});
|
||||
|
||||
whatsapp = JSON.parse(JSON.stringify(whatsapp))
|
||||
|
||||
console.log('whatsapp url: ', whatsapp.url)
|
||||
|
||||
await endPointQuery(`${whatsapp.url}/api/restore`, {})
|
||||
}
|
||||
|
||||
|
||||
|
||||
autoRestore(whatsappId)
|
||||
|
||||
return res.status(200).json({ message: "Starting session." });
|
||||
};
|
||||
|
|
|
@ -14,9 +14,7 @@ import { number } from "yargs";
|
|||
|
||||
const autoRestore = async (whatsappId: string | number, started_action_by: string = '') => {
|
||||
|
||||
return
|
||||
|
||||
const whatsapp = await ShowWhatsAppService(whatsappId);
|
||||
/*const whatsapp = await ShowWhatsAppService(whatsappId);
|
||||
|
||||
// console.log('>>>>>>>>>>> Whatsapp.id: ', whatsappId)
|
||||
|
||||
|
@ -42,7 +40,7 @@ const autoRestore = async (whatsappId: string | number, started_action_by: strin
|
|||
if (started_action_by.trim().length > 0)
|
||||
fs.writeFileSync(`${sourcePath}/${timestamp}_restore_${number}_triggered_by_${started_action_by}_id_${whatsappId}.txt`, `Whatsapp id: ${whatsapp.id} \nDate: ${dateToday.fullDate} ${dateToday.fullTime}`, (error: any) => { console.log(error) });
|
||||
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
setRestoreControll({ 'id': +whatsappId, 'disabled': true })
|
||||
|
|
|
@ -7,6 +7,6 @@ const userRoutes = Router();
|
|||
|
||||
userRoutes.post("/whatsapp/connection/monitor", WbotMonitorController.wbotMonitorRemote);
|
||||
userRoutes.post("/whatsapp/connection/qrcode", WbotMonitorController.wbotMonitorQrcodeRemote);
|
||||
// userRoutes.post("/whatsapp/delete/message", WbotMonitorController.DeleteWhatsAppMessage);
|
||||
userRoutes.post("/whatsapp/connection/number", WbotMonitorController.wbotMonitorQrcodeNumberRead);
|
||||
|
||||
export default userRoutes;
|
||||
|
|
Loading…
Reference in New Issue