# NousResearch/hermes-agent · WhatsApp send_message target parsing and JID normalization

## Open now

- 1 issue, 0 PRs open on GitHub.
- #37906: send_message tool fails for WhatsApp: @lid JIDs not recognized, home channel fallback, and raw phone numbers cause jidDecode error

Most members concern send_message handling of WhatsApp targets: recognizing JID formats (group, DM, @lid) as explicit targets, normalizing bare phone numbers to JIDs, and avoiding fallback to the home channel. One member is about Slack falling back to a home DM, and one generic WhatsApp failure report is vaguer, so the group is not entirely uniform.

## TL;DR

- 21 member(s): 1 open issue(s), 8 closed issue(s), 0 open PR(s), 1 merged PR(s), 11 PR(s) closed without merging.
- A fix was merged to main in PR #50379. Verify it addresses your case.
- **Recommended:** read PR #50379 (and any competing PRs below) before filing. Confirm the merged change covers your symptom.

## Maintainer resolution verdict

- Internal-tracker verdict over this cluster's issue members: `partially_resolved` · deciding PR(s): `pr-50379`. This is distinct from the fix status above. Weigh it yourself.

## How this cluster was grouped

- Link evidence (`STRUCTURAL_PARTIAL`): some members are connected by structural evidence (shared changed files, or a closing/superseded reference); the rest are joined by an automated relevance judgement over their text.
- Members outside that structural core may belong to a different underlying problem.
- Pairwise link density `0.09`: the share of member pairs that carry a link, counting a structural link in full and a relevance-only link at 0.36. `1.00` means every pair is linked.

## Open related issues

- #37906: send_message tool fails for WhatsApp: @lid JIDs not recognized, home channel fallback, and raw phone numbers cause jidDecode error

## Closed / duplicate issues

- #2899: \[Bug\]: Slack send_message can fall back to home DM instead of explicit channel target
- #8637: WhatsApp bridge crashes on bare phone numbers — missing JID normalization
- #18646: \[Bug\]: send_message ignores WhatsApp group target, routes to home channel instead
- #31396: \[Bug\]: send_message silently delivers to home channel and reports success when target resolution fails (WhatsApp LID format)
- #32538: \[Bug\]: WhatsApp Integration Failure
- #41407: \[Bug\] send_message WhatsApp targets: group/LID JIDs silently fall back to home channel
- #41660: WhatsApp send fails with bare phone number — missing @s.whatsapp.net JID suffix
- #59136: WhatsApp LID format not recognized in send_message tool

## Prior & competing PRs

- **#8639: fix(whatsapp): normalize bare phone targets to JIDs**. closed without merge · fix tier `suggested`
  - maintainer direction: category `merged_via`; implication `superseded`
  - _suggested-tier fix detail withheld; re-request with `?tier=all` to include it._
- **#41415: fix(#41407): recognize WhatsApp JID formats (groups, DMs, LIDs)**. closed without merge · fix tier `suggested`
  - maintainer direction: category `merged_via`; implication `superseded`; refs `ea49a79633d93202d8e495648b2586ee5a1fbecc`, `#46622`
  - _suggested-tier fix detail withheld; re-request with `?tier=all` to include it._
- **#41581: fix(whatsapp): recognize JID targets and reject bare digits (#41407)**. closed without merge · fix tier `suggested`
  - maintainer direction: category `uncategorized`; implication `needs_llm`
  - _suggested-tier fix detail withheld; re-request with `?tier=all` to include it._
- **#41866: fix(whatsapp): normalize bare phone numbers to full JID for outgoing sends (#41660)**. closed without merge · fix tier `suggested`
  - maintainer direction: category `implemented_elsewhere`; implication `superseded`; refs `#8639`
  - _suggested-tier fix detail withheld; re-request with `?tier=all` to include it._
- **#50379: fix(whatsapp): normalize bare phone targets to JIDs (salvage #8639)**. merged to main · fix tier `verified`
  - maintainer direction: category `merged`
  - files: `gateway/whatsapp_identity.py`, `plugins/platforms/whatsapp/adapter.py`, `tests/gateway/test_whatsapp_connect.py`, `tests/gateway/test_whatsapp_to_jid.py`
  - fix hunks:
  - `gateway/whatsapp_identity.py`

    ```diff
    @@ -67,6 +67,57 @@ def normalize_whatsapp_identifier(value: str) -> str:
         )
     
     
    +# A target that is "just a phone number" — optional leading ``+`` then digits
    +# and the usual human separators (spaces, dots, dashes, parens). Anything that
    +# already carries an ``@`` is a fully-qualified JID and must pass through
    +# untouched (group ``@g.us``, LID ``@lid``, ``status@broadcast`` etc.).
    +_BARE_PHONE_RE = re.compile(r"^\+?[\d\s().\-]+$")
    +
    +
    +def to_whatsapp_jid(value: str) -> str:
    +    """Normalize an *outbound* WhatsApp target to a bridge-safe JID.
    +
    +    Baileys' ``jidDecode`` crashes on a bare phone number — it expects a
    +    fully-qualified JID such as ``[redacted:email]``. This helper
    +    is the inverse of :func:`normalize_whatsapp_identifier`: instead of
    +    stripping a JID down to its numeric core for comparison, it *builds* the
    +    JID a send must use.
    +
    +    Behaviour:
    +
    +    - ``"+50766715226"`` / ``"50766715226"`` → ``"[redacted:email]"``
    +    - ``"[redacted:email]"`` → unchanged
    +    - ``"[redacted:email]"`` / ``"130631430344750@lid"`` → unchanged
    +    - ``"user:[redacted:email]"`` style colon-before-``@`` → ``@`` form
    +    - anything that isn't a recognizable bare phone → returned unchanged so
    +      the bridge can surface a meaningful error rather than us mangling it.
    +
    +    Returns ``""`` for an empty/whitespace input.
    +    """
    +    if not value:
    +        return ""
    +
    +    normalized = str(value).strip()
    +    # Drop a device suffix before the domain: ``user:device@domain`` is a
    +    # legacy Baileys shape whose ``:device`` part is not addressable — collapse
    +    # it to ``user@domain``. (Mirrors normalize_whatsapp_identifier, which
    +    # splits the bare id on ``:`` for the same reason.)
    +    if ":" in normalized and "@" in normalized:
    +        prefix, _, domain = normalized.partition("@")
    +        normalized = f"{prefix.split(':', 1)[0]}@{domain}"
    +
    +    # Already a fully-qualified JID — leave it alone.
    +    if "@" in normalized:
    +        return normalized
    +
    +    if _BARE_PHONE_RE.fullmatch(normalized):
    +        digits = re.sub(r"\D+", "", normalized)
    +        if digits:
    +            return f"{digits}@s.whatsapp.net"
    +
    +    return normalized
    +
    +
     def expand_whatsapp_aliases(identifier: str) -> Set[str]:
         """Resolve WhatsApp phone/LID aliases via bridge session mapping files.
     
    ```
  - `plugins/platforms/whatsapp/adapter.py`

    ```diff
    @@ -182,6 +182,7 @@ def _terminate_bridge_process(proc, *, force: bool = False) -> None:
     
     from gateway.config import Platform, PlatformConfig
     from gateway.platforms.whatsapp_common import WhatsAppBehaviorMixin
    +from gateway.whatsapp_identity import to_whatsapp_jid
     from gateway.platforms.base import (
         BasePlatformAdapter,
         MessageEvent,
    ```

    ```diff
    @@ -726,6 +727,8 @@ async def send(
             if not content or not content.strip():
                 return SendResult(success=True, message_id=None)
     
    +        chat_id = to_whatsapp_jid(chat_id)
    +
             try:
                 import aiohttp
     
    ```

    ```diff
    @@ -785,7 +788,7 @@ async def edit_message(
                 async with self._http_session.post(
                     f"http://127.0.0.1:{self._bridge_port}/edit",
                     json={
    -                    "chatId": chat_id,
    +                    "chatId": to_whatsapp_jid(chat_id),
                         "messageId": message_id,
                         "message": content,
                     },
    ```

    ```diff
    @@ -820,7 +823,7 @@ async def _send_media_to_bridge(
                     return SendResult(success=False, error=f"File not found: {file_path}")
     
                 payload: Dict[str, Any] = {
    -                "chatId": chat_id,
    +                "chatId": to_whatsapp_jid(chat_id),
                     "filePath": file_path,
                     "mediaType": media_type,
                 }
    ```

    ```diff
    @@ -932,7 +935,7 @@ async def send_typing(self, chat_id: str, metadata=None) -> None:
                 # socket in CLOSE_WAIT. See #18451.
                 async with self._http_session.post(
                     f"http://127.0.0.1:{self._bridge_port}/typing",
    -                json={"chatId": chat_id},
    +                json={"chatId": to_whatsapp_jid(chat_id)},
                     timeout=aiohttp.ClientTimeout(total=5)
                 ):
                     pass
    ```

    ```diff
    @@ -950,7 +953,7 @@ async def get_chat_info(self, chat_id: str) -> Dict[str, Any]:
                 import aiohttp
     
                 async with self._http_session.get(
    -                f"http://127.0.0.1:{self._bridge_port}/chat/{chat_id}",
    +                f"http://127.0.0.1:{self._bridge_port}/chat/{to_whatsapp_jid(chat_id)}",
                     timeout=aiohttp.ClientTimeout(total=10)
                 ) as resp:
                     if resp.status == 200:
    ```

    ```diff
    @@ -1238,10 +1241,11 @@ async def _standalone_send(
             return {"error": "aiohttp not installed. Run: pip install aiohttp"}
         try:
             bridge_port = extra.get("bridge_port", 3000)
    +        normalized_chat_id = to_whatsapp_jid(chat_id)
             async with aiohttp.ClientSession() as session:
                 async with session.post(
                     f"http://localhost:{bridge_port}/send",
    -                json={"chatId": chat_id, "message": message},
    +                json={"chatId": normalized_chat_id, "message": message},
                     timeout=aiohttp.ClientTimeout(total=30),
                 ) as resp:
                     if resp.status == 200:
    ```

    ```diff
    @@ -1249,7 +1253,7 @@ async def _standalone_send(
                         return {
                             "success": True,
                             "platform": "whatsapp",
    -                        "chat_id": chat_id,
    +                        "chat_id": normalized_chat_id,
                             "message_id": data.get("messageId"),
                         }
                     body = await resp.text()
    ```
  - `tests/gateway/test_whatsapp_connect.py`

    ```diff
    @@ -262,6 +262,51 @@ async def test_send_marks_retryable_fatal_when_managed_bridge_exits(self):
             mock_fh.close.assert_called_once()
             assert adapter._bridge_log_fh is None
     
    +    @pytest.mark.asyncio
    +    async def test_send_normalizes_bare_phone_numbers_to_jid(self):
    +        """A bare phone target (with or without +) becomes a full JID.
    +
    +        Baileys' jidDecode crashes on a bare number (#8637); the adapter
    +        must rewrite it to ``<digits>@s.whatsapp.net`` before the bridge
    +        call. Regression guard for that crash.
    +        """
    +        adapter = _make_adapter()
    +        adapter._running = True
    +        adapter._bridge_process = None  # unmanaged bridge — skip exit check
    +
    +        mock_resp = MagicMock()
    +        mock_resp.status = 200
    +        mock_resp.json = AsyncMock(return_value={"messageId": "msg-1"})
    +        mock_session = MagicMock()
    +        mock_session.post = MagicMock(return_value=_AsyncCM(mock_resp))
    +        adapter._http_session = mock_session
    +
    +        result = await adapter.send("+50766715226", "hello")
    +
    +        assert result.success is True
    +        payload = mock_session.post.call_args.kwargs["json"]
    +        assert payload["chatId"] == "[redacted:email]"
    +
    +    @pytest.mark.asyncio
    +    async def test_send_leaves_group_jid_untouched(self):
    +        """A fully-qualified group JID must pass through unchanged."""
    +        adapter = _make_adapter()
    +        adapter._running = True
    +        adapter._bridge_process = None
    +
    +        mock_resp = MagicMock()
    +        mock_resp.status = 200
    +        mock_resp.json = AsyncMock(return_value={"messageId": "msg-2"})
    +        mock_session = MagicMock()
    +        mock_session.post = MagicMock(return_value=_AsyncCM(mock_resp))
    +        adapter._http_session = mock_session
    +
    +        result = await adapter.send("[redacted:email]", "hello")
    +
    +        assert result.success is True
    +        payload = mock_session.post.call_args.kwargs["json"]
    +        assert payload["chatId"] == "[redacted:email]"
    +
         @pytest.mark.asyncio
         async def test_poll_messages_marks_retryable_fatal_when_managed_bridge_exits(self):
             adapter = _make_adapter()
    ```
  - `tests/gateway/test_whatsapp_to_jid.py`

    ```diff
    @@ -0,0 +1,56 @@
    +"""Unit tests for gateway.whatsapp_identity.to_whatsapp_jid.
    +
    +``to_whatsapp_jid`` is the outbound inverse of
    +``normalize_whatsapp_identifier``: it builds the bridge-safe JID a send
    +must use. Baileys' ``jidDecode`` crashes on a bare phone number (#8637),
    +so every outbound target must be rewritten to ``<digits>@s.whatsapp.net``
    +before it reaches the bridge.
    +"""
    +
    +import pytest
    +
    +from gateway.whatsapp_identity import to_whatsapp_jid
    +
    +
    +class TestToWhatsappJid:
    +    @pytest.mark.parametrize(
    +        "raw,expected",
    +        [
    +            # bare phone numbers → user JID
    +            ("+50766715226", "[redacted:email]"),
    +            ("50766715226", "[redacted:email]"),
    +            # human-formatted phone numbers get stripped to digits
    +            ("+1 (555) 123-4567", "[redacted:email]"),
    +            ("+1.555.123.4567", "[redacted:email]"),
    +        ],
    +    )
    +    def test_bare_phone_becomes_user_jid(self, raw, expected):
    +        assert to_whatsapp_jid(raw) == expected
    +
    +    @pytest.mark.parametrize(
    +        "jid",
    +        [
    +            "[redacted:email]",  # already a user JID
    +            "[redacted:email]",    # group JID
    +            "130631430344750@lid",         # linked identity
    +            "status@broadcast",            # broadcast pseudo-chat
    +            "123@newsletter",              # channel/newsletter
    +        ],
    +    )
    +    def test_fully_qualified_jid_passes_through(self, jid):
    +        assert to_whatsapp_jid(jid) == jid
    +
    +    def test_device_suffixed_colon_form_collapses_to_at(self):
    +        # ``user:device@domain`` (legacy) → ``user@domain``
    +        assert to_whatsapp_jid("60123456789:[redacted:email]") == (
    +            "[redacted:email]"
    +        )
    +
    +    @pytest.mark.parametrize("empty", ["", "   ", None])
    +    def test_empty_input_returns_empty(self, empty):
    +        assert to_whatsapp_jid(empty) == ""
    +
    +    def test_unrecognized_target_passes_through_unchanged(self):
    +        # Not a phone, no ``@`` — leave it for the bridge to reject with a
    +        # meaningful error rather than mangling it into a bogus JID.
    +        assert to_whatsapp_jid("not-a-number") == "not-a-number"
    ```
- **#31398: fix(send_message): accept WhatsApp JID targets**. closed without merge
  - maintainer direction: category `duplicate_of`; implication `duplicate`; refs `#20718`, `#18899`
- **#37924: fix(whatsapp): recognise @lid and @s.whatsapp.net JIDs in send_message target resolution**. closed without merge
  - maintainer direction: category `implemented_elsewhere`; implication `superseded`; refs `ea49a79633d93202d8e495648b2586ee5a1fbecc`
- **#41667: fix(whatsapp): normalise bare phone numbers to JIDs before bridge send**. closed without merge
  - maintainer direction: category `implemented_elsewhere`; implication `superseded`; refs `#8639`
- **#41689: Normalize bare WhatsApp phone targets to JIDs**. closed without merge
  - maintainer direction: category `duplicate_of`; implication `duplicate`; refs `#41667`, `#41660`
- **#45438: fix(send_message): recognize WhatsApp JIDs as explicit send targets**. closed without merge
  - maintainer direction: category `duplicate_of`; implication `duplicate`; refs `#12620`, `#37924`
- **#59166: fix(send_message): accept WhatsApp LID targets**. closed without merge
  - maintainer direction: category `implemented_elsewhere`; implication `superseded`; refs `ea49a79633d93202d8e495648b2586ee5a1fbecc`, `#59136`
- **#59199: fix(tools): recognize WhatsApp LID format in send_message target parsing**. closed without merge
  - maintainer direction: category `duplicate_of`; implication `duplicate`; refs `#59166`, `#59136`, `#41415`, `#41581`

## Fix status

- Merged to main in PR #50379 (cited above). No release data is tracked. Verify downstream.
- Fix last verified (merged) `2026-06-21`.
- Subsystem: `agent`
