Skip to content

Commit

Permalink
feat: lógica de desconexão, com tentativa de restauração
Browse files Browse the repository at this point in the history
fix: ajuste para gerar novo qrcode, respeitando a rotina de desconexão/conexão.
  • Loading branch information
ldurans committed Dec 14, 2022
1 parent a442708 commit ef74480
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
13 changes: 9 additions & 4 deletions backend/src/controllers/WhatsAppSessionController.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Request, Response } from "express";
// import path from "path";
// import { rmdir } from "fs/promises";
import { getWbot, removeWbot } from "../libs/wbot";
import { apagarPastaSessao, getWbot, removeWbot } from "../libs/wbot";
import ShowWhatsAppService from "../services/WhatsappService/ShowWhatsAppService";
import { StartWhatsAppSession } from "../services/WbotServices/StartWhatsAppSession";
import UpdateWhatsAppService from "../services/WhatsappService/UpdateWhatsAppService";
Expand All @@ -28,14 +28,19 @@ const store = async (req: Request, res: Response): Promise<Response> => {

const update = async (req: Request, res: Response): Promise<Response> => {
const { whatsappId } = req.params;
const { isQrcode } = req.body;
const { tenantId } = req.user;

if (isQrcode) {
await apagarPastaSessao(whatsappId);
}

const { whatsapp } = await UpdateWhatsAppService({
whatsappId,
whatsappData: { session: "" },
tenantId
});

// await apagarPastaSessao(whatsappId);
StartWhatsAppSession(whatsapp);
return res.status(200).json({ message: "Starting session." });
};
Expand All @@ -51,8 +56,8 @@ const remove = async (req: Request, res: Response): Promise<Response> => {
if (channel.type === "whatsapp") {
const wbot = getWbot(channel.id);
await setValue(`${channel.id}-retryQrCode`, 0);
// await wbot.destroy(); // --> fecha o client e conserva a sessão para reconexão (criar função desconectar)
await wbot.logout(); // --> encerra a sessão e desconecta o bot do whatsapp, geando um novo QRCODE
await wbot.destroy(); // --> fecha o client e conserva a sessão para reconexão (criar função desconectar)
// await wbot.logout(); // --> encerra a sessão e desconecta o bot do whatsapp. Apresenta problema constante e crasha
removeWbot(channel.id);
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/sessaoWhatsapp/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ export default {
// this.handleOpenQrModal(channel)
this.loading = true
try {
await RequestNewQrCode(channel.id)
await RequestNewQrCode({ id: channel.id, isQrcode: true })
setTimeout(() => {
this.handleOpenQrModal(channel)
}, 2000)
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/service/sessoesWhatsapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ export function DeleteWhatsappSession (whatsAppId) {
})
}

export function RequestNewQrCode (whatsAppId) {
export function RequestNewQrCode (data) {
return request({
url: `/whatsappsession/${whatsAppId}`,
method: 'put'
url: `/whatsappsession/${data.id}`,
method: 'put',
data
})
}

Expand Down

0 comments on commit ef74480

Please sign in to comment.