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