Skip to content

fix(whatsapp): propagate fromMe flag through DM message pipeline#21890

Open
mactsk wants to merge 1 commit intoopenclaw:mainfrom
mactsk:fix/propagate-fromme-in-dm
Open

fix(whatsapp): propagate fromMe flag through DM message pipeline#21890
mactsk wants to merge 1 commit intoopenclaw:mainfrom
mactsk:fix/propagate-fromme-in-dm

Conversation

@mactsk
Copy link

@mactsk mactsk commented Feb 20, 2026

Summary

Fixes #12482

In WhatsApp DMs, the agent cannot distinguish between messages sent by the gateway owner and messages from the contact. This makes it impossible for the agent to follow a two-way conversation correctly.

Changes

  • Add fromMe?: boolean field to WebInboundMessage type
  • Propagate Boolean(msg.key?.fromMe) from the Baileys message into the inbound message
  • Pass fromMe through buildInboundLine() to formatInboundEnvelope()
  • In DM envelopes, append (you) to the from field when fromMe is true, producing [WhatsApp +1555 (you)] message for owner messages

Security

  • Boolean(msg.key?.fromMe) safely defaults to false for null/undefined
  • The (you) marker passes through sanitizeEnvelopeHeaderPart (no injection risk)
  • The marker only appears in the agent's internal transcript, never in outbound messages
  • fromMe field is optional throughout — fully backward-compatible

Test plan

  • DM with fromMe: true → envelope contains (you)
  • DM with fromMe: false → no (you) marker
  • Group with fromMe: true → no (you) marker (groups unaffected)
  • fromMe omitted → no (you) marker (backward compat)
  • All existing envelope tests pass (16/16)

🤖 Generated with Claude Code

Greptile Summary

Adds a fromMe flag to the WhatsApp inbound message pipeline so the agent can distinguish between messages sent by the gateway owner and messages from the contact in DMs. The flag flows from Baileys' msg.key.fromMe through WebInboundMessagebuildInboundLine()formatInboundEnvelope(), where DM messages with fromMe: true get a (you) suffix appended to the from field in the envelope header (e.g., [WhatsApp +1555 (you)] message).

  • New optional fromMe?: boolean field added to WebInboundMessage type, ensuring backward compatibility
  • Boolean(msg.key?.fromMe) safely coerces null/undefined to false
  • The (you) marker only applies to DM messages (not groups), and passes through sanitizeEnvelopeHeaderPart safely
  • 4 new test cases cover DM fromMe true/false, group fromMe true, and omitted fromMe scenarios

Confidence Score: 5/5

  • This PR is safe to merge — it's a well-scoped, backward-compatible addition with thorough test coverage.
  • The change is minimal and focused: a single optional boolean field threaded through the existing pipeline, with a small formatting change gated behind two conditions (isDirect && fromMe). All edge cases are tested (4 new tests). The field is optional throughout, so no existing callers break. The Boolean() coercion safely handles null/undefined. No security concerns — the marker only appears in internal agent transcripts.
  • No files require special attention.

Last reviewed commit: 7fc1a3b

(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!

In WhatsApp DMs, the agent cannot distinguish between messages sent by
the gateway owner and messages from the contact.  This makes it
impossible for the agent to follow the conversation correctly.

- Add `fromMe` field to `WebInboundMessage` type
- Propagate `Boolean(msg.key?.fromMe)` from the Baileys message
- Pass `fromMe` through `buildInboundLine` to `formatInboundEnvelope`
- In DM envelopes, append "(you)" to the from field when fromMe is true
  so the agent sees `[WhatsApp +1555 (you)] message` for owner messages

Closes openclaw#12482

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@openclaw-barnacle openclaw-barnacle bot added channel: whatsapp-web Channel integration: whatsapp-web size: S labels Feb 20, 2026
@openclaw-barnacle
Copy link

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle bot added the stale Marked as stale due to inactivity label Feb 28, 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: S stale Marked as stale due to inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agent cannot distinguish owner's messages from contact's messages in DM history

1 participant