mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-08 08:11:38 +00:00
fix: require anchors for Telegram DM topic deliveries
This commit is contained in:
parent
3d585f8db5
commit
6daafb3fd4
2 changed files with 60 additions and 8 deletions
|
|
@ -259,16 +259,33 @@ class DeliveryRouter:
|
|||
|
||||
send_metadata = dict(metadata or {})
|
||||
if target.thread_id:
|
||||
has_explicit_direct_topic = (
|
||||
"direct_messages_topic_id" in send_metadata
|
||||
or "telegram_direct_messages_topic_id" in send_metadata
|
||||
)
|
||||
if (
|
||||
target.platform == Platform.TELEGRAM
|
||||
and _looks_like_telegram_private_chat_id(target.chat_id)
|
||||
and "thread_id" not in send_metadata
|
||||
and "message_thread_id" not in send_metadata
|
||||
and "direct_messages_topic_id" not in send_metadata
|
||||
and "telegram_direct_messages_topic_id" not in send_metadata
|
||||
and not has_explicit_direct_topic
|
||||
):
|
||||
send_metadata["telegram_direct_messages_topic_id"] = target.thread_id
|
||||
elif "thread_id" not in send_metadata:
|
||||
# Telegram has two similar-but-not-equivalent private topic modes:
|
||||
# true Bot API Direct Messages topics use direct_messages_topic_id,
|
||||
# while Hermes-created private DM lanes only route reliably with
|
||||
# message_thread_id plus a reply anchor to a message in that lane.
|
||||
# DeliveryRouter often handles proactive/cron sends, so an anchor
|
||||
# may not exist. Refuse the send rather than reporting success for
|
||||
# a message that lands in General/All Messages or is invisible.
|
||||
reply_anchor = send_metadata.get("telegram_reply_to_message_id")
|
||||
if reply_anchor is None:
|
||||
raise RuntimeError(
|
||||
"Telegram private DM topic delivery requires telegram_reply_to_message_id; "
|
||||
"send to the bare chat or provide a reply anchor"
|
||||
)
|
||||
send_metadata["thread_id"] = target.thread_id
|
||||
send_metadata["telegram_dm_topic_reply_fallback"] = True
|
||||
elif "thread_id" not in send_metadata and "message_thread_id" not in send_metadata and not has_explicit_direct_topic:
|
||||
send_metadata["thread_id"] = target.thread_id
|
||||
result = await adapter.send(target.chat_id, content, metadata=send_metadata or None)
|
||||
if getattr(result, "success", True) is False:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue