mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-18 14:52:04 +00:00
fix(whatsapp): normalize bare phone targets to JIDs before bridge send
Baileys' jidDecode crashes ("Cannot destructure property 'user' of
jidDecode(...) as it is undefined") when handed a bare phone number, so
sending a WhatsApp message to +50766715226 / 50766715226 returned HTTP
500 and never delivered (#8637).
Add to_whatsapp_jid() to gateway/whatsapp_identity.py — the outbound
inverse of normalize_whatsapp_identifier: it builds the JID a send must
use (bare phone -> <digits>@s.whatsapp.net) and passes through already
qualified JIDs (@g.us, @lid, status@broadcast, @newsletter) unchanged.
Wire it at every outbound bridge call site in the WhatsApp adapter
(send, edit, media, typing, get_chat_info, and the standalone cron /
send_message sender).
Co-authored-by: Hermes Agent <noreply@nousresearch.com>
This commit is contained in:
parent
f72690825e
commit
a4b1554c73
4 changed files with 162 additions and 6 deletions
|
|
@ -182,6 +182,7 @@ sys.path.insert(0, str(Path(__file__).resolve().parents[3]))
|
|||
|
||||
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,
|
||||
|
|
@ -726,6 +727,8 @@ class WhatsAppAdapter(WhatsAppBehaviorMixin, BasePlatformAdapter):
|
|||
if not content or not content.strip():
|
||||
return SendResult(success=True, message_id=None)
|
||||
|
||||
chat_id = to_whatsapp_jid(chat_id)
|
||||
|
||||
try:
|
||||
import aiohttp
|
||||
|
||||
|
|
@ -785,7 +788,7 @@ class WhatsAppAdapter(WhatsAppBehaviorMixin, BasePlatformAdapter):
|
|||
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,
|
||||
},
|
||||
|
|
@ -820,7 +823,7 @@ class WhatsAppAdapter(WhatsAppBehaviorMixin, BasePlatformAdapter):
|
|||
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,
|
||||
}
|
||||
|
|
@ -932,7 +935,7 @@ class WhatsAppAdapter(WhatsAppBehaviorMixin, BasePlatformAdapter):
|
|||
# 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
|
||||
|
|
@ -950,7 +953,7 @@ class WhatsAppAdapter(WhatsAppBehaviorMixin, BasePlatformAdapter):
|
|||
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:
|
||||
|
|
@ -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:
|
||||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue