← Back to PRs

#23721: feat(inbound-meta): expose account_id in inbound_meta.v1 schema

by ekson73 open 2026-02-22 16:34 View on GitHub →
channel: whatsapp-web size: XS
## Problem Multi-account setups (e.g. WhatsApp personal + business numbers) need the agent to know which account received the message. The `AccountId` field was already available in `TemplateContext` but not surfaced in the `inbound_meta.v1` system prompt. Without `account_id`, agents in multi-account setups cannot: - Distinguish which account/phone received the message - Apply per-account behavior (e.g. active mode vs bodyguard mode) - Prevent echo loops when the same workspace handles multiple accounts ## Use Case A user runs two WhatsApp accounts: personal (passive/bodyguard) and business (active). Both are bound to agents sharing the same workspace. The agent needs to know which account received the message to apply the correct persona. Without `account_id` in trusted metadata, the agent has no reliable way to distinguish the source. ## Solution Add `account_id` to the trusted `inbound_meta.v1` JSON payload in the system prompt. ```ts // In src/auto-reply/reply/inbound-meta.ts const payload = { schema: 'openclaw.inbound_meta.v1', chat_id: safeTrim(ctx.OriginatingTo), channel: channelValue, account_id: safeTrim(ctx.AccountId), // ← NEW // ... }; ``` This is a **session-stable field** (doesn't change per-turn), so it won't affect prompt caching. ## How to Verify 1. Configure two WhatsApp accounts (`eko` and `eqm`) 2. Send a message to each account 3. Check the system prompt — `account_id` should show the correct account name 4. Agent can now branch behavior based on `account_id` ## Files Changed - `src/auto-reply/reply/inbound-meta.ts` — add `account_id` to payload (1 line) - `src/auto-reply/reply/inbound-meta.test.ts` — add test for `account_id` presence 1 field added, 1 test added. All 14 existing tests continue to pass. ## Related - PR #23685 — fix `selfChatMode` config usage (related multi-account work) - Issue #23788 — selfChatMode regression bug

Most Similar PRs