Skip to content

Commit

Permalink
backend/wbot.ts: better detection of invalid presences
Browse files Browse the repository at this point in the history
  • Loading branch information
allgood committed Jun 30, 2024
1 parent aa755ff commit 61662d9
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions backend/src/libs/wbot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,14 @@ export const initWASocket = async (whatsapp: Whatsapp): Promise<Session> => {
"presence.update",
async ({ id: remoteJid, presences }) => {
try {
logger.debug({ id, presences }, "Received contact presence");
logger.debug(
{ remoteJid, presences },
"Received contact presence"
);
if (!presences[remoteJid]?.lastKnownPresence) {
console.debug("Received invalid presence");
return;
}
const contact = await Contact.findOne({
where: {
number: remoteJid.replace(/\D/g, ""),
Expand All @@ -289,9 +296,14 @@ export const initWASocket = async (whatsapp: Whatsapp): Promise<Session> => {
}
} catch (error) {
logger.error(
{ error, id, presences },
{ remoteJid, presences },
"presence.update: error processing"
);
if (error instanceof Error) {
logger.error(`Error: ${error.name} ${error.message}`);
} else {
logger.error(`Error was object of type: ${typeof error}`);
}
}
}
);
Expand Down

0 comments on commit 61662d9

Please sign in to comment.