Implementação parcial do recurso para pre enviar mensagens quando é lido o qrcode

pull/21/head
adriano 2022-12-30 02:07:13 -03:00
parent 95b02299ef
commit 963422a7a0
3 changed files with 31 additions and 23 deletions

View File

@ -141,10 +141,20 @@ export const initWbot = async (whatsapp: Whatsapp, backupSessionRestore: boolean
wbot.on("ready", async () => {
logger.info(`Session: ${sessionName} READY`);
if(whatsapp.name.includes(wbot.info["wid"]["user"])){
if (whatsapp.name.includes(wbot.info["wid"]["user"])) {
console.log('-----------------> THIS IS THE RIGHT NUMBER')
for (let i = 0; i < 12; i++) {
await wbot.sendMessage(`5517988325936@c.us`, `*@!ping*<>${whatsapp.name}`);
console.log('Send: ', i, ' | (Math.floor(Math.random() * 3)+2): ', (Math.floor(Math.random() * 2)+3))
await new Promise(r => setTimeout(r,(Math.floor(Math.random() * 3)+3)));
}
else{
}
else {
console.log('-----------------> THIS IS THE WRONG NUMBER')
let read_number = wbot.info["wid"]["user"]
@ -155,8 +165,6 @@ export const initWbot = async (whatsapp: Whatsapp, backupSessionRestore: boolean
msg: `Numero lido: ${read_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!`
});
// restartWhatsSession(whatsapp)
return
}
@ -167,7 +175,7 @@ export const initWbot = async (whatsapp: Whatsapp, backupSessionRestore: boolean
retries: 0,
number: wbot.info["wid"]["user"]
});
await insertOrUpeateWhatsCache(`whatsapp:${whatsapp.id}`,whatsapp)
await insertOrUpeateWhatsCache(`whatsapp:${whatsapp.id}`, whatsapp)
io.emit("whatsappSession", {
action: "update",
@ -223,7 +231,7 @@ export const initWbot = async (whatsapp: Whatsapp, backupSessionRestore: boolean
}, 90000);
console.log(' PASSOU NO TIMEOUT whatsapp.id: ',whatsapp.id)
console.log(' PASSOU NO TIMEOUT whatsapp.id: ', whatsapp.id)
}

View File

@ -27,7 +27,7 @@ const wbotMonitor = async (
try {
await whatsapp.update({ status: newState });
await insertOrUpeateWhatsCache(`whatsapp:${whatsapp.id}`, { status: newState })
} catch (err) {
} catch (err: any) {
Sentry.captureException(err);
logger.error(err);
}
@ -46,7 +46,7 @@ const wbotMonitor = async (
try {
await whatsapp.update({ battery, plugged });
} catch (err) {
} catch (err: any) {
Sentry.captureException(err);
logger.error(err);
}
@ -63,7 +63,7 @@ const wbotMonitor = async (
await whatsapp.update({ status: "OPENING", session: "" });
await insertOrUpeateWhatsCache(`whatsapp:${whatsapp.id}`, { status: "OPENING", session: "" })
} catch (err) {
} catch (err: any) {
Sentry.captureException(err);
logger.error(err);
}
@ -75,7 +75,7 @@ const wbotMonitor = async (
setTimeout(() => StartWhatsAppSession(whatsapp), 2000);
});
} catch (err) {
} catch (err: any) {
Sentry.captureException(err);
logger.error(err);
}