Skip to content

fix(whatsapp): propagate fromMe through inbound message pipeline#32167

Merged
steipete merged 2 commits intoopenclaw:mainfrom
scoootscooob:fix/whatsapp-dm-fromme-propagation
Mar 2, 2026
Merged

fix(whatsapp): propagate fromMe through inbound message pipeline#32167
steipete merged 2 commits intoopenclaw:mainfrom
scoootscooob:fix/whatsapp-dm-fromme-propagation

Conversation

@scoootscooob
Copy link
Contributor

Problem

In WhatsApp DM conversations, agents cannot distinguish owner-sent messages from contact messages. The fromMe flag from Baileys' WAMessage.key is extracted during inbound processing (for access-control filtering) but then discarded — it is never stored in WebInboundMessage or passed to the transcript formatter.

This means in self-chat or any scenario where owner messages appear in the conversation, they look identical to contact messages, breaking the agent's ability to reason about conversation context.

Re-filing of #12482 (closed by stale bot).

Fix

  1. src/web/inbound/types.ts — Add fromMe?: boolean to WebInboundMessage type
  2. src/web/inbound/monitor.ts — Store Boolean(msg.key?.fromMe) when constructing the inbound message
  3. src/auto-reply/envelope.ts — Accept fromMe in formatInboundEnvelope; prefix DM body with (self): when true
  4. src/web/auto-reply/monitor/message-line.ts — Pass msg.fromMe through buildInboundLineformatInboundEnvelope

All changes are additive (optional fields) — fully backward compatible.

Test plan

  • New test: DM with fromMe: true produces (self): body prefix
  • New test: group message with fromMe: true still uses sender label (no (self) prefix)
  • Existing envelope tests pass (14/14)
  • Existing WhatsApp auto-reply tests pass (13/13)
  • tsgo --noEmit clean on changed files

Closes #32061

🤖 Generated with Claude Code

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 2, 2026

Greptile Summary

Successfully propagates WhatsApp's fromMe flag through the inbound message pipeline to enable agents to distinguish owner-sent messages from contact messages in DM conversations.

Key Changes:

  • Added optional fromMe?: boolean field to WebInboundMessage type for backward compatibility
  • Extracted and stored fromMe from Baileys' WAMessage.key using safe optional chaining
  • Modified formatInboundEnvelope to prefix self-sent DM messages with (self):
  • Group chat messages correctly retain sender labels regardless of fromMe status
  • Added comprehensive test coverage for new behavior

Implementation Quality:

  • Clean, minimal implementation touching only necessary files
  • Defensive programming with Boolean(msg.key?.fromMe) for safe extraction
  • Logic correctly handles all cases: DM self-messages get (self): prefix, DM contact messages and group messages maintain existing behavior
  • Full backward compatibility—existing code works unchanged
  • Well-tested with two new test cases covering DM and group chat scenarios

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • Clean implementation with no logical errors, comprehensive test coverage, full backward compatibility through optional fields, and solves the stated problem effectively. The changes are minimal and focused, with defensive programming practices throughout.
  • No files require special attention

Last reviewed commit: 9a6670b

scoootscooob and others added 2 commits March 2, 2026 21:18
The `fromMe` flag from Baileys' WAMessage.key was only used for
access-control filtering and then discarded.  This meant agents
could not distinguish owner-sent messages from contact messages
in DM conversations (everything appeared as from the contact).

Add `fromMe` to `WebInboundMessage`, store it during message
construction, and thread it through `buildInboundLine` →
`formatInboundEnvelope` so DM transcripts prefix owner messages
with `(self):`.

Closes openclaw#32061

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@steipete steipete force-pushed the fix/whatsapp-dm-fromme-propagation branch from 9a6670b to 2bcc9ff Compare March 2, 2026 21:20
@steipete steipete merged commit af637de into openclaw:main Mar 2, 2026
9 checks passed
@steipete
Copy link
Contributor

steipete commented Mar 2, 2026

Landed via temp rebase onto main.

  • Gate: pnpm -s vitest run src/auto-reply/envelope.test.ts src/web/auto-reply/monitor/process-message.inbound-contract.test.ts src/web/auto-reply/monitor/process-message.test.ts
  • Land commit: 2bcc9ff
  • Merge commit: af637de

Thanks @scoootscooob!

mrosmarin added a commit to mrosmarin/openclaw that referenced this pull request Mar 2, 2026
* main: (154 commits)
  fix: harden exec allowlist regex literal handling (openclaw#32162) (thanks @stakeswky)
  fix(exec): escape regex literals in allowlist path matching
  fix: OpenAI OAuth TLS preflight gating (openclaw#32051) (thanks @alexfilatov)
  Auth: gate OpenAI OAuth TLS preflight in doctor
  Fix TLS cert preflight classification false positive
  Add OpenAI OAuth TLS preflight and doctor prerequisite check
  fix(gateway): hot-reload channelHealthCheckMinutes without full restart
  refactor: harden plugin install flow and main DM route pinning
  fix: propagate whatsapp inbound fromMe context (openclaw#32167) (thanks @scoootscooob)
  fix(whatsapp): propagate fromMe through inbound message pipeline
  refactor: harden msteams lifecycle and attachment flows
  fix(config): move sensitive-schema hint warnings to debug
  test(perf): reduce heavy fixture and guardrail overhead
  perf(core): speed up routing, pairing, slack, and security scans
  refactor: unify queueing and normalize telegram slack flows
  fix: harden bundled plugin install fallback semantics (openclaw#32096) (thanks @scoootscooob)
  fix(plugins): prefer bundled plugin ids over bare npm specs
  fix: distinguish warning message for non-OpenClaw vs missing npm package
  fix(plugins): fall back to bundled plugin when npm spec resolves to non-OpenClaw package (openclaw#32019)
  fix: harden msteams revoked-context fallback delivery (openclaw#27224) (thanks @openperf)
  ...
OWALabuy pushed a commit to kcinzgg/openclaw that referenced this pull request Mar 4, 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 size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agent cannot distinguish owner vs contact messages in DM history

2 participants