mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-19 04:09:26 +00:00
feat: option to handle whatsapp session on app
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user