Atualização para o carregamento parcial das sessões do whatsapp quando cair a aplicação e subir novamente
parent
56886611a7
commit
40dae953f4
|
@ -37,6 +37,7 @@ const autoRestore = async (whatsappId: string | number, started_action_by: strin
|
||||||
number = ''
|
number = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) });
|
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) });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,7 +138,7 @@ const monitor = async () => {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
console.log('Directory not found to get size info: ', sourcePath)
|
// console.log('Directory not found to get size info: ', sourcePath)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,12 +64,15 @@ const SendWhatsAppMessage = async ({
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (listWhatsapp.length > 1) {
|
if (listWhatsapp.length > 1) {
|
||||||
|
|
||||||
console.log('entrou --------------------->')
|
console.log('entrou --------------------->')
|
||||||
|
|
||||||
const _whatsapp = listWhatsapp[Math.floor(Math.random() * listWhatsapp.length)];
|
const _whatsapp = listWhatsapp[Math.floor(Math.random() * listWhatsapp.length)];
|
||||||
|
|
||||||
|
console.log('_whatsapp_whatsapp_whatsapp_whatsapp_whatsapp_whatsapp_whatsapp_whatsapp: ',_whatsapp)
|
||||||
|
|
||||||
await ticket.update({ whatsappId: +_whatsapp.id });
|
await ticket.update({ whatsappId: +_whatsapp.id });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,61 @@
|
||||||
|
import path from "path";
|
||||||
|
import autoRestore from "../../helpers/AutoRestore";
|
||||||
|
import { removeDir } from "../../helpers/DeleteDirectory";
|
||||||
|
import { insertOrUpeateWhatsCache, searchWhatsappCache } from "../../helpers/WhatsCache";
|
||||||
|
import { getIO } from "../../libs/socket";
|
||||||
import ListWhatsAppsService from "../WhatsappService/ListWhatsAppsService";
|
import ListWhatsAppsService from "../WhatsappService/ListWhatsAppsService";
|
||||||
import { StartWhatsAppSession } from "./StartWhatsAppSession";
|
import { StartWhatsAppSession } from "./StartWhatsAppSession";
|
||||||
|
const fs = require('fs')
|
||||||
|
|
||||||
|
let counter = 0
|
||||||
|
|
||||||
export const StartAllWhatsAppsSessions = async (): Promise<void> => {
|
export const StartAllWhatsAppsSessions = async (): Promise<void> => {
|
||||||
|
|
||||||
const whatsapps = await ListWhatsAppsService();
|
const whatsapps = await ListWhatsAppsService();
|
||||||
|
|
||||||
|
|
||||||
if (whatsapps.length > 0) {
|
if (whatsapps.length > 0) {
|
||||||
whatsapps.forEach(whatsapp => {
|
|
||||||
StartWhatsAppSession(whatsapp);
|
whatsapps.forEach(async whatsapp => {
|
||||||
|
|
||||||
|
// StartWhatsAppSession(whatsapp);
|
||||||
|
|
||||||
|
const sourcePath = path.join(process.cwd(), `.wwebjs_auth/`, `session-bd_${whatsapp.id}`)
|
||||||
|
|
||||||
|
if (fs.existsSync(sourcePath)) {
|
||||||
|
|
||||||
|
await removeDir(sourcePath)
|
||||||
|
|
||||||
|
console.log('Directory deleted on start process: ', sourcePath)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log('Directory not found to delete on start process: ', sourcePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
await whatsapp.update({ status: "RESTORING" });
|
||||||
|
await insertOrUpeateWhatsCache(`whatsapp:${whatsapp.id}`, {
|
||||||
|
status: "RESTORING",
|
||||||
|
})
|
||||||
|
|
||||||
|
const io = getIO();
|
||||||
|
io.emit("whatsappSession", {
|
||||||
|
action: "update",
|
||||||
|
session: whatsapp
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log('1 counter: ', counter)
|
||||||
|
|
||||||
|
setTimeout(async () => {
|
||||||
|
|
||||||
|
await autoRestore(whatsapp.id,)
|
||||||
|
|
||||||
|
}, counter)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
counter += 57000
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue