fix: store group messages from non-allowlisted senders as pending context #4402
+67
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When
groupPolicy: "allowlist"and a group message arrives from a sender not ingroupAllowFrom, the message is completely dropped at the access-control layer (allowed: false→continue). This means the agent cannot see messages from non-allowlisted group members in its[Chat messages since your last reply - for context]block.The groups docs describe the flow as:
But this context-storage path only runs after access control passes. Messages blocked by
groupAllowFromnever reach the mention-gating/context-storage logic — they are silently discarded.Use Case
You have a WhatsApp group with multiple participants (humans and bots). You only want certain numbers to trigger your agent (
groupAllowFrom), but you want the agent to see all messages as context so it has full conversational awareness when it does respond.Fix
Adds a new opt-in config flag
groupContextFromAll(default:false) that preserves backward compatibility while allowing non-allowlisted group members' messages to be stored as pending context.Config
Available at both the top-level WhatsApp config and per-account level. Per-account takes precedence.
Per-account (recommended):
Top-level (applies to all accounts):
Behavior
groupContextFromAllgroupAllowFromfalse(default)false(default)true[Chat messages since your last reply]) but cannot trigger a replytrueWhat "context only" means
[Chat messages since your last reply - for context]blockChanges
6 files changed:
src/web/inbound/access-control.ts— AddedstoreForContextto result type; whengroupContextFromAllis enabled and sender failsgroupAllowFrom, returnsstoreForContext: trueinstead of droppingsrc/web/inbound/monitor.ts— PassesstoreForContextmessages through ascontextOnlyinstead ofcontinue-ing; skips read receipts for context-only messagessrc/web/inbound/types.ts— AddedcontextOnly?: booleantoWebInboundMessagesrc/web/auto-reply/monitor/on-message.ts— StorescontextOnlymessages in group history viarecordPendingHistoryEntryIfEnabledwithout triggering replysrc/config/types.whatsapp.ts— AddedgroupContextFromAll?: booleanto both top-level and per-account WhatsApp configsrc/config/zod-schema.providers-whatsapp.ts— Added schema validation forgroupContextFromAllsrc/web/accounts.ts— AddedgroupContextFromAlltoResolvedWhatsAppAccountBackward Compatibility
groupContextFromAlldefaults tofalse— zero behavior change for existing installationsgroupPolicy: "open"orgroupPolicy: "disabled"behaviorTested
Verified locally with two bot instances in a WhatsApp group. Before the fix, Bot A could not see Bot B's messages. After enabling
groupContextFromAll: true, Bot A correctly sees Bot B's messages in its context window and can reference them when triggered.