Skip to content

Your lightweight open-source personal agent.

fix(whatsapp): avoid dropping media-only messages

Re-bin64112eb9ba98
diff --git a/README.md b/README.md
index 0c4960876..d2a1c59c4 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`
+
</details>
<details>
diff --git a/bridge/src/whatsapp.ts b/bridge/src/whatsapp.ts
index 279fe5a35..b91baccc5 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 } : {}),