Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
}

Expand Down Expand Up @@ -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();
}
Expand Down
12 changes: 11 additions & 1 deletion src/api/services/monitor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<Auth>('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES;
if (!expose) {
return instances.map((instance) => ({ ...instance, token: null }));
}

return instances;
}

Expand Down
Loading