fix(whatsapp): avoid dropping media-only messages

This commit is contained in:
Re-bin
2026-03-07 03:06:19 +00:00
parent 067965da50
commit 64112eb9ba
2 changed files with 11 additions and 2 deletions

View File

@@ -420,6 +420,10 @@ nanobot channels login
nanobot gateway 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>
<details> <details>

View File

@@ -124,21 +124,26 @@ export class WhatsAppClient {
if (!unwrapped) continue; if (!unwrapped) continue;
const content = this.getTextContent(unwrapped); const content = this.getTextContent(unwrapped);
let fallbackContent: string | null = null;
const mediaPaths: string[] = []; const mediaPaths: string[] = [];
if (unwrapped.imageMessage) { if (unwrapped.imageMessage) {
fallbackContent = '[Image]';
const path = await this.downloadMedia(msg, unwrapped.imageMessage.mimetype ?? undefined); const path = await this.downloadMedia(msg, unwrapped.imageMessage.mimetype ?? undefined);
if (path) mediaPaths.push(path); if (path) mediaPaths.push(path);
} else if (unwrapped.documentMessage) { } else if (unwrapped.documentMessage) {
fallbackContent = '[Document]';
const path = await this.downloadMedia(msg, unwrapped.documentMessage.mimetype ?? undefined, const path = await this.downloadMedia(msg, unwrapped.documentMessage.mimetype ?? undefined,
unwrapped.documentMessage.fileName ?? undefined); unwrapped.documentMessage.fileName ?? undefined);
if (path) mediaPaths.push(path); if (path) mediaPaths.push(path);
} else if (unwrapped.videoMessage) { } else if (unwrapped.videoMessage) {
fallbackContent = '[Video]';
const path = await this.downloadMedia(msg, unwrapped.videoMessage.mimetype ?? undefined); const path = await this.downloadMedia(msg, unwrapped.videoMessage.mimetype ?? undefined);
if (path) mediaPaths.push(path); 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; const isGroup = msg.key.remoteJid?.endsWith('@g.us') || false;
@@ -146,7 +151,7 @@ export class WhatsAppClient {
id: msg.key.id || '', id: msg.key.id || '',
sender: msg.key.remoteJid || '', sender: msg.key.remoteJid || '',
pn: msg.key.remoteJidAlt || '', pn: msg.key.remoteJidAlt || '',
content: content || '', content: finalContent,
timestamp: msg.messageTimestamp as number, timestamp: msg.messageTimestamp as number,
isGroup, isGroup,
...(mediaPaths.length > 0 ? { media: mediaPaths } : {}), ...(mediaPaths.length > 0 ? { media: mediaPaths } : {}),