Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@adam91holt
Copy link
Contributor

Problem

When groupPolicy: "allowlist" and a group message arrives from a sender not in groupAllowFrom, the message is completely dropped at the access-control layer (allowed: falsecontinue). 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:

requireMention? yes → mentioned? no → store for context only

But this context-storage path only runs after access control passes. Messages blocked by groupAllowFrom never 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):

{
  channels: {
    whatsapp: {
      accounts: {
        "default": {
          groupAllowFrom: ["+15551234567", "+15559876543"],
          groupPolicy: "allowlist",
          groupContextFromAll: true  // <-- NEW: see all group messages as context
        }
      }
    }
  }
}

Top-level (applies to all accounts):

{
  channels: {
    whatsapp: {
      groupContextFromAll: true
    }
  }
}

Behavior

groupContextFromAll Sender in groupAllowFrom Result
false (default) No Message dropped (existing behavior)
false (default) Yes Message processed normally
true No Message stored as pending context (visible in [Chat messages since your last reply]) but cannot trigger a reply
true Yes Message processed normally

What "context only" means

  • Message appears in the [Chat messages since your last reply - for context] block
  • Message cannot trigger the agent (no reply generated)
  • No read receipts sent for context-only messages
  • Sender name and number are visible in context

Changes

6 files changed:

  • src/web/inbound/access-control.ts — Added storeForContext to result type; when groupContextFromAll is enabled and sender fails groupAllowFrom, returns storeForContext: true instead of dropping
  • src/web/inbound/monitor.ts — Passes storeForContext messages through as contextOnly instead of continue-ing; skips read receipts for context-only messages
  • src/web/inbound/types.ts — Added contextOnly?: boolean to WebInboundMessage
  • src/web/auto-reply/monitor/on-message.ts — Stores contextOnly messages in group history via recordPendingHistoryEntryIfEnabled without triggering reply
  • src/config/types.whatsapp.ts — Added groupContextFromAll?: boolean to both top-level and per-account WhatsApp config
  • src/config/zod-schema.providers-whatsapp.ts — Added schema validation for groupContextFromAll
  • src/web/accounts.ts — Added groupContextFromAll to ResolvedWhatsAppAccount

Backward Compatibility

  • groupContextFromAll defaults to falsezero behavior change for existing installations
  • Opt-in only: users must explicitly enable it
  • No changes to DM behavior
  • No changes to groupPolicy: "open" or groupPolicy: "disabled" behavior

Tested

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.

When groupPolicy is 'allowlist', messages from senders not in
groupAllowFrom were completely dropped (allowed: false + continue).
This meant the agent couldn't see messages from other bots or
non-allowlisted group members in its context window.

The docs state that non-mentioned messages should be 'stored for
context only', but this only applied after access control passed.

Changes:
- Add storeForContext flag to InboundAccessControlResult
- When a group message fails groupAllowFrom, set storeForContext: true
  instead of silently dropping
- Pass contextOnly flag through to WebInboundMessage
- In on-message handler, store contextOnly messages in group history
  without triggering a reply
- Skip read receipts for context-only messages

Fixes: group members not in groupAllowFrom are now visible in the
agent's '[Chat messages since your last reply]' context block.
- groupContextFromAll: boolean (default: false) - opt-in flag
- When enabled, group messages from senders not in groupAllowFrom
  are stored as pending context instead of being dropped
- Available at both top-level whatsapp config and per-account level
- Added to types, zod schema, resolved account, and access control
- Default false preserves existing behavior
@moltbot-barnacle moltbot-barnacle bot added the channel: whatsapp-web Channel integration: whatsapp-web label Jan 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: whatsapp-web Channel integration: whatsapp-web

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant