fix(whatsapp): add error handling to messages.upsert handler (#695)

Wrap the inner message processing loop in a try-catch to prevent a
single malformed or edge-case message from crashing the entire handler.
Logs the error with remoteJid for debugging while continuing to process
remaining messages in the batch.

Co-authored-by: Ethan M <ethan@nanoclaw.local>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
glifocat
2026-03-04 14:02:21 +01:00
committed by GitHub
parent 58dec06e4c
commit 5e3d8b6c2c

View File

@@ -173,6 +173,7 @@ export class WhatsAppChannel implements Channel {
this.sock.ev.on('messages.upsert', async ({ messages }) => {
for (const msg of messages) {
try {
if (!msg.message) continue;
// Unwrap container types (viewOnceMessageV2, ephemeralMessage,
// editedMessage, etc.) so that conversation, extendedTextMessage,
@@ -235,6 +236,12 @@ export class WhatsAppChannel implements Channel {
is_bot_message: isBotMessage,
});
}
} catch (err) {
logger.error(
{ err, remoteJid: msg.key?.remoteJid },
'Error processing incoming message',
);
}
}
});
}