From 64112eb9ba985bae151b2c40a1760886823b5747 Mon Sep 17 00:00:00 2001 From: Re-bin Date: Sat, 7 Mar 2026 03:06:19 +0000 Subject: [PATCH] fix(whatsapp): avoid dropping media-only messages --- README.md | 4 ++++ bridge/src/whatsapp.ts | 9 +++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0c49608..d2a1c59 100644 --- a/README.md +++ b/README.md @@ -420,6 +420,10 @@ nanobot channels login nanobot gateway ``` +> WhatsApp bridge updates are not applied automatically for existing installations. +> If you upgrade nanobot and need the latest WhatsApp bridge, run: +> `rm -rf ~/.nanobot/bridge && nanobot channels login` +
diff --git a/bridge/src/whatsapp.ts b/bridge/src/whatsapp.ts index 279fe5a..b91bacc 100644 --- a/bridge/src/whatsapp.ts +++ b/bridge/src/whatsapp.ts @@ -124,21 +124,26 @@ export class WhatsAppClient { if (!unwrapped) continue; const content = this.getTextContent(unwrapped); + let fallbackContent: string | null = null; const mediaPaths: string[] = []; if (unwrapped.imageMessage) { + fallbackContent = '[Image]'; const path = await this.downloadMedia(msg, unwrapped.imageMessage.mimetype ?? undefined); if (path) mediaPaths.push(path); } else if (unwrapped.documentMessage) { + fallbackContent = '[Document]'; const path = await this.downloadMedia(msg, unwrapped.documentMessage.mimetype ?? undefined, unwrapped.documentMessage.fileName ?? undefined); if (path) mediaPaths.push(path); } else if (unwrapped.videoMessage) { + fallbackContent = '[Video]'; const path = await this.downloadMedia(msg, unwrapped.videoMessage.mimetype ?? undefined); if (path) mediaPaths.push(path); } - if (!content && mediaPaths.length === 0) continue; + const finalContent = content || (mediaPaths.length === 0 ? fallbackContent : '') || ''; + if (!finalContent && mediaPaths.length === 0) continue; const isGroup = msg.key.remoteJid?.endsWith('@g.us') || false; @@ -146,7 +151,7 @@ export class WhatsAppClient { id: msg.key.id || '', sender: msg.key.remoteJid || '', pn: msg.key.remoteJidAlt || '', - content: content || '', + content: finalContent, timestamp: msg.messageTimestamp as number, isGroup, ...(mediaPaths.length > 0 ? { media: mediaPaths } : {}),