Skip to content

fix(whatsapp): normalize targets for groups and E.164 - #631

Merged
steipete merged 1 commit into
openclaw:mainfrom
imfing:fix-normalize
Jan 10, 2026
Merged

steipete merged 1 commit into
openclaw:mainfrom
imfing:fix-normalize

Conversation

@imfing

@imfing imfing commented Jan 10, 2026

Copy link
Copy Markdown
Contributor

Overview

Fixes WhatsApp target normalization to properly handle both E.164 phone numbers and WhatsApp group JIDs, preventing groups from being incorrectly processed as phone numbers.

Changes

  • Utils: New normalizeWhatsAppTarget() and isWhatsAppGroupJid() functions
  • Logic: Replace all normalizeE164() calls with normalizeWhatsAppTarget() for WhatsApp targets
  • Preservation: Group JIDs (@g.us suffix) are now preserved instead of being mangled
  • Messages: Updated error messages to reflect support for both E.164 and group JID formats

Behavior

  • Phone numbers: Normalized to E.164 format (e.g., +1555123)
  • Group JIDs: Preserved as-is (e.g., [email protected])
  • Prefixes: Strips whatsapp: and whatsapp:group: prefixes automatically
  • Validation: Returns empty string for invalid targets

Files Changed

src/utils.ts                        | +18 (new utilities)
src/utils.test.ts                   | +31 (comprehensive tests)
src/cron/isolated-agent.ts          | +17/-5
src/gateway/server-methods/agent.ts | +12/-3
src/infra/outbound/targets.ts       | +14/-3
src/infra/heartbeat-runner.test.ts  | +15 (group target test)
src/infra/outbound/targets.test.ts  | +8 (group target test)

Total: 7 files, +118/-11 lines

Testing

  • ✅ Unit tests for normalizeWhatsAppTarget() with groups and phone numbers
  • ✅ Unit tests for isWhatsAppGroupJid() with various prefix formats
  • ✅ Heartbeat delivery preserves group JIDs
  • ✅ Outbound target resolution handles group JIDs
  • ✅ All existing tests pass

Examples

// Before (incorrect for groups)
normalizeE164("[email protected]") // => "+120363401234567890" ❌

// After (correct)
normalizeWhatsAppTarget("[email protected]") // => "[email protected]" ✅
normalizeWhatsAppTarget("+1555123") // => "+1555123" ✅
normalizeWhatsAppTarget("whatsapp:group:[email protected]") // => "[email protected]" ✅

@steipete
steipete merged commit 991f6dd into openclaw:main Jan 10, 2026
@steipete

Copy link
Copy Markdown
Contributor

Landed via temp rebase onto main.

  • Gate: pnpm lint && pnpm build && pnpm test
  • Land commit: f0700e9
  • Merge commit: 991f6dd

Thanks @imfing!

@imfing
imfing deleted the fix-normalize branch January 11, 2026 00:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants