fix(whatsapp): recognise @lid and @s.whatsapp.net JIDs in send_message target resolution - #37924
fix(whatsapp): recognise @lid and @s.whatsapp.net JIDs in send_message target resolution#37924liuhao1024 wants to merge 2 commits into
Conversation
…e target resolution WHATSAPP_JID_RE now matches WhatsApp JIDs (digits@lid and digits@s.whatsapp.net) as explicit targets in _parse_target_ref. Previously these fell through to the generic numeric / channel-name resolution paths, causing silent fallback to the home channel or bridge crashes from unrecognised JID formats. Fixes NousResearch#37906
…targets Adds @g.us (group JIDs) and @c.us (individual JIDs) to the WhatsApp JID regex in _parse_target_ref, alongside the existing @lid and @s.whatsapp.net patterns. Without this, group targets like 120363123456@g.us fall through to channel-name resolution and either error or silently route to the home channel (issue NousResearch#18646).
|
Updated this PR to also cover WhatsApp group JIDs ( This now also fixes #18646 — where New test coverage:
|
teknium1
left a comment
There was a problem hiding this comment.
Thanks for extending coverage to WhatsApp JID variants. Main already landed the original @lid, @s.whatsapp.net, and @g.us behavior in ea49a79633d93202d8e495648b2586ee5a1fbecc; tools/send_message_tool.py:47-50 now has a broader matcher for those plus broadcast/newsletter JIDs.
Problems
- Current main still omits
@c.usfrom that matcher, so the added@c.uscase remains valuable:_parse_target_ref()only treats a WhatsApp target as explicit when_WHATSAPP_JID_REmatches (tools/send_message_tool.py:590-595). - The old-base regex in this PR should not replace the current one: it would lose main's existing broadcast/newsletter support and case-insensitive matching (
tools/send_message_tool.py:47-50).
Suggested changes
- Salvage this as a narrow addition of
c\.usto main's existing suffix alternatives, plus the corresponding regression test.gateway/whatsapp_identity.py:109-111already preserves fully-qualified JIDs unchanged, and existing Cloud tests use15551234567@c.us(tests/gateway/test_whatsapp_cloud.py:869-887).
Automated hermes-sweeper review.
| # JIDs). The live WhatsAppAdapter and Baileys bridge both accept these | ||
| # natively, so _parse_target_ref should recognise them as explicit targets | ||
| # instead of letting them fall through to the generic numeric / channel-name | ||
| # resolution paths (which silently route to the home channel or crash). |
There was a problem hiding this comment.
Current main already has a broader _WHATSAPP_JID_RE here. Salvage this as an added c\.us alternative on that matcher rather than replacing it, so existing broadcast/newsletter support and re.IGNORECASE are retained.
What does this PR do?
Adds recognition of WhatsApp
@lidand@s.whatsapp.netJIDs as explicit targets in_parse_target_ref(). Previously, WhatsApp JIDs like12345@lidor919900123456@s.whatsapp.netfell through to the generic numeric / channel-name resolution paths, causing silent fallback to the home channel or bridge crashes.Related Issue
Fixes #37906
Type of Change
Changes Made
tools/send_message_tool.py: Added_WHATSAPP_JID_REregex pattern matchingdigits@lidanddigits@s.whatsapp.netJIDs. Added WhatsApp-specific branch in_parse_target_ref()that checks this regex before the generic E.164 phone number path.tests/tools/test_send_message_tool.py: Added 4 test cases:@lidJID recognition,@s.whatsapp.netJID recognition, whitespace tolerance, and non-numeric JID rejection.How to Test
pytest tests/tools/test_send_message_tool.py -k "whatsapp" -v— all 6 WhatsApp tests should pass_parse_target_ref("whatsapp", "12345@lid")returns("12345@lid", None, True)_parse_target_ref("whatsapp", "919900123456@s.whatsapp.net")returns("919900123456@s.whatsapp.net", None, True)_parse_target_ref("whatsapp", "+155****4567")still returns the E.164 number (no regression)pytest tests/tools/test_send_message_tool.py -v— all 133 tests passChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/ACode Intelligence
_parse_target_refintools/send_message_tool.py(callers: 2 in send_message_tool.py, 1 in test)_FEISHU_TARGET_RE,_WEIXIN_TARGET_RE,_SLACK_TARGET_RE— platform-specific regex check before generic fallback