mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-25 00:51:20 +00:00
fix(tools): add outbound WhatsApp send_message routing
This commit is contained in:
parent
548cedb869
commit
dc15bc508f
2 changed files with 48 additions and 0 deletions
|
|
@ -331,6 +331,8 @@ async def _send_to_platform(platform, pconfig, chat_id, message, thread_id=None,
|
|||
result = await _send_discord(pconfig.token, chat_id, chunk)
|
||||
elif platform == Platform.SLACK:
|
||||
result = await _send_slack(pconfig.token, chat_id, chunk)
|
||||
elif platform == Platform.WHATSAPP:
|
||||
result = await _send_whatsapp(pconfig.extra, chat_id, chunk)
|
||||
elif platform == Platform.SIGNAL:
|
||||
result = await _send_signal(pconfig.extra, chat_id, chunk)
|
||||
elif platform == Platform.EMAIL:
|
||||
|
|
@ -514,6 +516,34 @@ async def _send_slack(token, chat_id, message):
|
|||
return {"error": f"Slack send failed: {e}"}
|
||||
|
||||
|
||||
async def _send_whatsapp(extra, chat_id, message):
|
||||
"""Send via the local WhatsApp bridge HTTP API."""
|
||||
try:
|
||||
import aiohttp
|
||||
except ImportError:
|
||||
return {"error": "aiohttp not installed. Run: pip install aiohttp"}
|
||||
try:
|
||||
bridge_port = extra.get("bridge_port", 3000)
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.post(
|
||||
f"http://localhost:{bridge_port}/send",
|
||||
json={"chatId": chat_id, "message": message},
|
||||
timeout=aiohttp.ClientTimeout(total=30),
|
||||
) as resp:
|
||||
if resp.status == 200:
|
||||
data = await resp.json()
|
||||
return {
|
||||
"success": True,
|
||||
"platform": "whatsapp",
|
||||
"chat_id": chat_id,
|
||||
"message_id": data.get("messageId"),
|
||||
}
|
||||
body = await resp.text()
|
||||
return {"error": f"WhatsApp bridge error ({resp.status}): {body}"}
|
||||
except Exception as e:
|
||||
return {"error": f"WhatsApp send failed: {e}"}
|
||||
|
||||
|
||||
async def _send_signal(extra, chat_id, message):
|
||||
"""Send via signal-cli JSON-RPC API."""
|
||||
try:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue