Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(webhooks): resolve the chatId filter from chatId only

Yudhi Armyndharisd34387255ea2
diff --git a/src/modules/webhook/filters/filter-evaluator.spec.ts b/src/modules/webhook/filters/filter-evaluator.spec.ts
index ac0814dc7..4c0902e1e 100644
--- a/src/modules/webhook/filters/filter-evaluator.spec.ts
+++ b/src/modules/webhook/filters/filter-evaluator.spec.ts
@@ -202,13 +202,13 @@ describe('evaluateFilters', () => {
expect(evaluateFilters(f, 'message.received', msg({ chatId: '[email protected]', from: '[email protected]' }))).toBe(false);
});
- it('falls back to from when chatId is omitted (inbound group shape)', () => {
+ // `from` is the sender on a DM and this session on an outbound message, so reading it as the
+ // conversation would scope the filter to the wrong chat. A payload without chatId matches
+ // nothing rather than guessing.
+ it('does not read from as the conversation when chatId is absent', () => {
const f = filters({ field: 'chatId', operator: 'is', value: ['[email protected]'] });
expect(
evaluateFilters(f, 'message.received', msg({ from: '[email protected]', author: '[email protected]', isGroup: true })),
- ).toBe(true);
- expect(
- evaluateFilters(f, 'message.received', msg({ from: '[email protected]', author: '[email protected]', isGroup: true })),
).toBe(false);
});
diff --git a/src/modules/webhook/filters/filter-types.ts b/src/modules/webhook/filters/filter-types.ts
index a5380cdef..428815bcb 100644
--- a/src/modules/webhook/filters/filter-types.ts
+++ b/src/modules/webhook/filters/filter-types.ts
@@ -100,13 +100,14 @@ export const FILTER_FIELDS: Record<string, FieldDefinition[]> = {
resolve: data => str(data.to),
},
{
- // Conversation JID (DM or group). Prefer the explicit chatId carried on received /
- // edited / reaction / revoked payloads; fall back to `from` for older shapes where
- // the chat is only on that field (inbound group messages often use [email protected]).
+ // Conversation JID (DM or group). Every payload in this family carries it: `IncomingMessage`
+ // declares `chatId` required, and the edited, reaction and revoked events set it explicitly.
+ // Deliberately without a fall back to `from`, which is the sender on a DM and this session on
+ // an outbound message, so it would silently scope the filter to the wrong conversation.
field: 'chatId',
kind: 'id',
operators: ID_OPERATORS,
- resolve: data => str(data.chatId) ?? str(data.from),
+ resolve: data => str(data.chatId),
},
{
field: 'body',