diff --git a/package.json b/package.json index aca237c13b..4a850302fd 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "type": "commonjs", "scripts": { "prebuild": "npm run db:generate", - "build": "tsc --noEmit && tsup", + "build": "NODE_OPTIONS=--max-old-space-size=2048 tsc --noEmit && NODE_OPTIONS=--max-old-space-size=2048 tsup", "start": "tsx ./src/main.ts", "start:prod": "node dist/main", "dev:server": "tsx watch ./src/main.ts", diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index 267832fb0d..8710811908 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -539,6 +539,17 @@ export class BaileysStartupService extends ChannelStartupService { if (full) { return webMessageInfo[0]; } + + // Row not found: return undefined, never a truthy empty envelope. Baileys' + // getMessage treats ANY truthy return as "message found" and relays it to + // satisfy a retry request — an empty { conversation: '' } burns one of the + // retry attempts and leaves the recipient stuck on "Waiting for this + // message" forever (issue #2705). undefined lets Baileys fall through to + // its placeholder/resend path instead. + if (!webMessageInfo[0]) { + return undefined; + } + if (webMessageInfo[0].message?.pollCreationMessage) { const messageSecretBase64 = webMessageInfo[0].message?.messageContextInfo?.messageSecret; @@ -556,7 +567,8 @@ export class BaileysStartupService extends ChannelStartupService { return webMessageInfo[0].message; } catch { - return { conversation: '' }; + // See above: undefined (not an empty envelope) on any lookup failure. + return undefined; } } @@ -1301,6 +1313,27 @@ export class BaileysStartupService extends ChannelStartupService { continue; } + // Unwrap disappearing-message / view-once envelopes BEFORE any content + // handling (issue #2773). Baileys delivers these messages with the real + // content nested under `ephemeralMessage.message` / `viewOnceMessage.message`; + // it only unwraps on demand via normalizeMessageContent, which Evolution + // never calls on the live path. Left wrapped, getContentType() reports + // `ephemeralMessage`, the extendedTextMessage->conversation flattening and + // the isMedia checks below never fire, and the message reaches webhooks and + // the database with its text/media buried — so every offer sent in a chat + // with disappearing messages on is effectively invisible to consumers. + // Note: `editedMessage` is handled above and already skipped by the guard, + // so it is intentionally NOT unwrapped here. + for (let i = 0; i < 5 && received.message; i++) { + const inner = + received.message.ephemeralMessage || + received.message.viewOnceMessage || + received.message.viewOnceMessageV2 || + received.message.viewOnceMessageV2Extension; + if (!inner?.message) break; + received.message = inner.message; + } + if (Long.isLong(received.messageTimestamp)) { received.messageTimestamp = received.messageTimestamp?.toNumber(); } diff --git a/src/api/services/monitor.service.ts b/src/api/services/monitor.service.ts index 438530b57e..3c96d13d27 100644 --- a/src/api/services/monitor.service.ts +++ b/src/api/services/monitor.service.ts @@ -3,7 +3,7 @@ import { ProviderFiles } from '@api/provider/sessions'; import { PrismaRepository } from '@api/repository/repository.service'; import { channelController } from '@api/server.module'; import { Events, Integration } from '@api/types/wa.types'; -import { CacheConf, Chatwoot, ConfigService, Database, DelInstance, ProviderSession } from '@config/env.config'; +import { Auth, CacheConf, Chatwoot, ConfigService, Database, DelInstance, ProviderSession } from '@config/env.config'; import { Logger } from '@config/logger.config'; import { INSTANCE_DIR, STORE_DIR } from '@config/path.config'; import { NotFoundException } from '@exceptions'; @@ -126,6 +126,16 @@ export class WAMonitoringService { }, }); + // The `token` column holds the instance's auth hash (its apikey). With + // AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES=false it must not leak through + // fetchInstances (issue #2677): the flag was only ever applied to the webhook + // `apiKey` field, never to this HTTP response, so the full token was returned + // unconditionally — a real exposure on a server that hosts several instances. + const expose = this.configService.get('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES; + if (!expose) { + return instances.map((instance) => ({ ...instance, token: null })); + } + return instances; }