feat: option to handle whatsapp session on app

This commit is contained in:
canove
2020-08-13 20:29:41 -03:00
parent cdc4411f70
commit 9914c6752c
10 changed files with 160 additions and 60 deletions

View File

@@ -1,8 +1,8 @@
const Whatsapp = require("../models/Whatsapp");
// const { getIO } = require("../libs/socket");
// const { getWbot, init } = require("../libs/wbot");
const { getIO } = require("../libs/socket");
const { getWbot } = require("../libs/wbot");
exports.show = async (req, res, next) => {
exports.show = async (req, res) => {
const { sessionId } = req.params;
const dbSession = await Whatsapp.findByPk(sessionId);
@@ -13,6 +13,28 @@ exports.show = async (req, res, next) => {
return res.status(200).json(dbSession);
};
exports.delete = async (req, res) => {
const wbot = getWbot();
const io = getIO();
const { sessionId } = req.params;
const dbSession = await Whatsapp.findByPk(sessionId);
if (!dbSession) {
return res.status(200).json({ message: "Session not found" });
}
await dbSession.update({ session: "", status: "pending" });
wbot.logout();
io.emit("session", {
action: "logout",
session: dbSession,
});
return res.status(200).json({ message: "session disconnected" });
};
// exports.getContacts = async (req, res, next) => {
// const io = getIO();
// const wbot = getWbot();