hermes - 💡(How to fix) Fix feat(telegram): auto-create forum topic on new session (parity with MATRIX_AUTO_THREAD)

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…

Code Example

# Auto-thread.
if not thread_id and ((not is_dm and self._auto_thread) or (is_dm and self._dm_auto_thread)):
    thread_id = event_id
    self._threads.mark(thread_id)
RAW_BUFFERClick to expand / collapse

Feature Description

Auto-create a forum topic in Telegram supergroups when a new conversation session starts, and route all messages for that session into the topic. This keeps the group clean — each conversation gets its own isolated thread, just like Slack/Discord threads.

Motivation

Currently, when a user starts a new /new chat in a Telegram group with topics enabled, the conversation stays in whatever topic the /new command was sent from. This means:

  • Multiple concurrent conversations all pile into the same topic
  • Context switching between conversations is hard — messages interleave
  • The group becomes noisy and hard to follow

Matrix already has MATRIX_AUTO_THREAD (env var, default true) that does exactly this — on new session, it creates a thread and routes messages there. Telegram should have parity.

Proposed Solution

Add a TELEGRAM_AUTO_TOPIC env var (or extra.auto_topic config key), defaulting to false for backward compatibility.

When enabled and the chat is a supergroup with topics enabled:

  1. On new session — call Telegram Bot API createForumTopic with a name like "Chat 2026-05-19 02:30" (timestamp-based).
  2. Store the returned message_thread_id in session metadata.
  3. Route all subsequent messages for that session using message_thread_id in sendMessage.
  4. On session end/reset — optionally call closeForumTopic to archive the topic.

Reference Implementation

Matrix platform already does this at gateway/platforms/matrix.py:1714:

# Auto-thread.
if not thread_id and ((not is_dm and self._auto_thread) or (is_dm and self._dm_auto_thread)):
    thread_id = event_id
    self._threads.mark(thread_id)

For Telegram, the equivalent would be in the message handler, calling createForumTopic before session creation.

Alternatives Considered

  • Manual topic creation — user creates topics manually before starting chats. Too much friction.
  • Reuse existing topics — always send to a single "Hermes" topic. Doesn't solve the interleaving problem.
  • No change — accept the noise. Suboptimal UX for topic-enabled groups.

Additional Context

  • Telegram Bot API supports createForumTopic, editForumTopic, closeForumTopic, reopenForumTopic, deleteForumTopic since Bot API 6.3
  • The gateway already has full thread/topic support for delivery (telegram:chat_id:thread_id format in send_message)
  • DM Topics (extra.dm_topics) already exist for private chats — this extends the concept to group topics
  • The _GENERAL_TOPIC_THREAD_ID = "1" constant already exists in telegram.py for the General topic

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

hermes - 💡(How to fix) Fix feat(telegram): auto-create forum topic on new session (parity with MATRIX_AUTO_THREAD)