hermes - 💡(How to fix) Fix send_message fails to deliver to Telegram forum topics (telegram:chat_id:thread_id) [1 pull requests]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

But this fallback silently delivers to the General topic instead of the correct one, and the user sees no error. The message appears to send successfully but lands in the wrong topic.

  • The standalone path (_send_telegram) surfaces this as an error
  • If the thread_id is invalid, an error should be returned (not silently fallback)

Root Cause

After reviewing the codebase, I identified multiple layers where thread/topic targeting can fail:

Fix Action

Fixed

Code Example

# Line 791-812
if thread_id is not None:
    effective_thread_id = TelegramAdapter._message_thread_id_for_send(str(thread_id))
    if effective_thread_id is not None:
        thread_kwargs["message_thread_id"] = effective_thread_id

---

if self._is_thread_not_found_error(send_err) and effective_thread_id is not None:
    # Thread doesn't exist — retry without message_thread_id
RAW_BUFFERClick to expand / collapse

Problem

The send_message tool cannot reliably deliver messages to specific topics within Telegram forum supergroups. When the agent is asked to send a file or message to a specific topic, the delivery ends up in the wrong location (General topic, home channel, or DM) instead of the requested topic.

Reproduction

  1. Configure Telegram gateway with a forum supergroup as home channel
  2. Agent receives a request like "schick mir die Datei auf Telegram"
  3. Agent calls send_message(target="telegram:-100XXXXXX:YYYYY", message="... MEDIA:/path/to/file")
  4. Message arrives in the wrong topic or the General channel instead of the specified topic

Root Cause Analysis

After reviewing the codebase, I identified multiple layers where thread/topic targeting can fail:

1. _send_telegram standalone path (tools/send_message_tool.py:757-912)

The standalone send path (used when gateway is not available or CLI sends directly) correctly extracts thread_id from the target and passes it as message_thread_id:

# Line 791-812
if thread_id is not None:
    effective_thread_id = TelegramAdapter._message_thread_id_for_send(str(thread_id))
    if effective_thread_id is not None:
        thread_kwargs["message_thread_id"] = effective_thread_id

However, this path uses a one-shot Bot instance (line 787: bot = Bot(token=token)) which doesn't share state with the gateway's connected adapter. If the thread_id is stale or invalid, there's no fallback mechanism.

2. Gateway live adapter path (gateway/platforms/telegram.py:1491-1630)

The gateway's send() method does have a fallback for "thread not found" errors (line 1595-1599):

if self._is_thread_not_found_error(send_err) and effective_thread_id is not None:
    # Thread doesn't exist — retry without message_thread_id

But this fallback silently delivers to the General topic instead of the correct one, and the user sees no error. The message appears to send successfully but lands in the wrong topic.

3. No thread_id validation before send

Neither path validates whether the thread_id is actually valid for the given chat_id before attempting to send. The Bot API returns "Message thread not found" for invalid thread IDs, but:

  • The standalone path (_send_telegram) surfaces this as an error
  • The gateway path falls back to the General topic silently

4. Session isolation exacerbates the problem

Each Telegram topic creates a separate agent session. When a session restarts:

  • The agent loses context about which topic/thread it was in
  • thread_id metadata may not be propagated correctly
  • The agent may not know the correct thread_id for a topic name

Expected Behavior

  • send_message(target="telegram:-100XXXXXX:YYYYY", ...) should deliver to the specified topic
  • If the thread_id is invalid, an error should be returned (not silently fallback)
  • The agent should be able to resolve topic names to thread_ids

Environment

  • Hermes Agent version: current (as of May 2026)
  • Platform: Telegram gateway

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING