Skip to content

feat(telegram): Private Chat Topics support (Bot API 9.4)#3005

Closed
web3blind wants to merge 1 commit into
NousResearch:mainfrom
web3blind:feat/dm-private-chat-topics
Closed

feat(telegram): Private Chat Topics support (Bot API 9.4)#3005
web3blind wants to merge 1 commit into
NousResearch:mainfrom
web3blind:feat/dm-private-chat-topics

Conversation

@web3blind

Copy link
Copy Markdown
Contributor

Summary

Implements Telegram Private Chat Topics support (Bot API 9.4, February 2026), allowing bots to create and manage isolated topic threads within 1-on-1 private chats.

Closes #2598

What changed

gateway/platforms/telegram.py

  • _create_dm_topic() — Creates a forum topic in a DM chat via createForumTopic (Bot API 9.4). Handles duplicate topic errors gracefully.

  • _setup_dm_topics() — Runs at gateway startup. Loads topic thread_ids from config if already persisted (preventing duplicate creation on restart). Only calls the API for topics that don't have a thread_id yet.

  • _persist_dm_topic_thread_id() — After creating a new topic, saves its thread_id back to config.yaml. This is the key fix for the duplication bug — without persistence, every gateway restart would attempt to re-create all topics.

  • _get_dm_topic_info() — Looks up topic config (name, skill binding) by thread_id from the runtime cache.

  • _cache_dm_topic_from_message() — Discovers topic mappings from incoming forum_topic_created service messages.

  • _build_message_event() — Updated to resolve DM topic names and inject skill context hints (e.g., "Accessibility Auditor [skill: accessibility-auditor]") into chat_topic for session routing.

tests/gateway/test_dm_topics.py

16 tests covering all new methods — loading from config, creating via API, persistence, cache behavior, error handling, and edge cases.

Configuration

New config section under platforms.telegram.extra:

platforms:
  telegram:
    extra:
      dm_topics:
      - chat_id: 123456789
        topics:
        - name: General
          icon_color: 7322096
          thread_id: 100  # auto-persisted after first creation
        - name: My Project
          icon_color: 9367192
          skill: my-skill  # optional: auto-loads this skill in the topic

How it works

  1. User configures desired DM topics in config.yaml
  2. On gateway startup, _setup_dm_topics() checks each topic:
    • If thread_id exists in config → loads into memory cache (no API call)
    • If no thread_id → calls createForumTopic, caches result, persists thread_id to config
  3. Incoming messages with message_thread_id are matched to the cached topics
  4. Each topic gets an isolated session (existing build_session_key already supports thread_id)
  5. Topics with a skill binding automatically inject context for the agent

Session isolation

The existing session routing (gateway/session.py) already supports thread_id in the session key format:

agent:main:telegram:dm:{chat_id}:{thread_id}

So each DM topic automatically gets its own independent conversation history, memory flush, and context.

Implements Telegram Private Chat Topics for 1-on-1 DM conversations,
allowing bots to create and manage isolated topic threads within a
single private chat. Based on Bot API 9.4 (Feb 2026).

Changes:
- _create_dm_topic(): create forum topics in DM chats
- _setup_dm_topics(): load/create topics from config at startup
- _persist_dm_topic_thread_id(): save thread_ids to config.yaml
- _get_dm_topic_info(): topic lookup with hot-reload from config —
  topics added externally are picked up without gateway restart
- _reload_dm_topics_from_config(): live config reload for new topics
- _cache_dm_topic_from_message(): dynamic topic discovery
- _build_message_event(): DM topic name resolution + skill context

No gateway restart needed when adding topics externally.

Closes NousResearch#2598
@web3blind web3blind force-pushed the feat/dm-private-chat-topics branch from 1c7dd5b to 5506139 Compare March 25, 2026 19:46
teknium1 added a commit that referenced this pull request Mar 26, 2026
Cherry-picked from PR #3005 by web3blind.
Adds DM topic creation, persistence, and session isolation via Bot API 9.4.
Closes #2598
teknium1 added a commit that referenced this pull request Mar 26, 2026
)

Salvages PR #3005 by web3blind. Cherry-picked onto current main with functional skill binding and docs added.

- DM topic creation via createForumTopic (Bot API 9.4, Feb 2026)
- Config-driven topics with thread_id persistence across restarts
- Session isolation via existing build_session_key thread_id support
- auto_skill field on MessageEvent for topic-skill bindings
- Gateway auto-loads bound skill on new sessions (same as /skill commands)
- Docs: full Private Chat Topics section in Telegram messaging guide
- 20 tests (17 original + 3 for auto_skill)

Closes #2598
Co-authored-by: web3blind <web3blind@users.noreply.github.com>
@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #3163. Your DM Private Chat Topics implementation was cherry-picked onto current main with authorship preserved. Added on top: functional skill binding (auto_skill field on MessageEvent, gateway auto-loads the bound skill on new sessions) and a full docs section for the Telegram messaging guide. Thanks for the solid contribution!

@teknium1 teknium1 closed this Mar 26, 2026
outsourc-e pushed a commit to outsourc-e/hermes-agent that referenced this pull request Mar 26, 2026
…usResearch#2598)

Salvages PR NousResearch#3005 by web3blind. Cherry-picked onto current main with functional skill binding and docs added.

- DM topic creation via createForumTopic (Bot API 9.4, Feb 2026)
- Config-driven topics with thread_id persistence across restarts
- Session isolation via existing build_session_key thread_id support
- auto_skill field on MessageEvent for topic-skill bindings
- Gateway auto-loads bound skill on new sessions (same as /skill commands)
- Docs: full Private Chat Topics section in Telegram messaging guide
- 20 tests (17 original + 3 for auto_skill)

Closes NousResearch#2598
Co-authored-by: web3blind <web3blind@users.noreply.github.com>
angelburgosrosado pushed a commit to angelburgosrosado/hermes-agent that referenced this pull request Apr 27, 2026
…usResearch#2598)

Salvages PR NousResearch#3005 by web3blind. Cherry-picked onto current main with functional skill binding and docs added.

- DM topic creation via createForumTopic (Bot API 9.4, Feb 2026)
- Config-driven topics with thread_id persistence across restarts
- Session isolation via existing build_session_key thread_id support
- auto_skill field on MessageEvent for topic-skill bindings
- Gateway auto-loads bound skill on new sessions (same as /skill commands)
- Docs: full Private Chat Topics section in Telegram messaging guide
- 20 tests (17 original + 3 for auto_skill)

Closes NousResearch#2598
Co-authored-by: web3blind <web3blind@users.noreply.github.com>
angelburgosrosado pushed a commit to angelburgosrosado/hermes-agent that referenced this pull request Apr 28, 2026
Cherry-picked from PR NousResearch#3005 by web3blind.
Adds DM topic creation, persistence, and session isolation via Bot API 9.4.
Closes NousResearch#2598
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
…usResearch#2598)

Salvages PR NousResearch#3005 by web3blind. Cherry-picked onto current main with functional skill binding and docs added.

- DM topic creation via createForumTopic (Bot API 9.4, Feb 2026)
- Config-driven topics with thread_id persistence across restarts
- Session isolation via existing build_session_key thread_id support
- auto_skill field on MessageEvent for topic-skill bindings
- Gateway auto-loads bound skill on new sessions (same as /skill commands)
- Docs: full Private Chat Topics section in Telegram messaging guide
- 20 tests (17 original + 3 for auto_skill)

Closes NousResearch#2598
Co-authored-by: web3blind <web3blind@users.noreply.github.com>
olympus-terminal pushed a commit to olympus-terminal/hermes-agent that referenced this pull request May 16, 2026
…usResearch#2598)

Salvages PR NousResearch#3005 by web3blind. Cherry-picked onto current main with functional skill binding and docs added.

- DM topic creation via createForumTopic (Bot API 9.4, Feb 2026)
- Config-driven topics with thread_id persistence across restarts
- Session isolation via existing build_session_key thread_id support
- auto_skill field on MessageEvent for topic-skill bindings
- Gateway auto-loads bound skill on new sessions (same as /skill commands)
- Docs: full Private Chat Topics section in Telegram messaging guide
- 20 tests (17 original + 3 for auto_skill)

Closes NousResearch#2598
Co-authored-by: web3blind <web3blind@users.noreply.github.com>
CumulusService pushed a commit to Cumulus-Service-GmbH/hermes-agent that referenced this pull request May 30, 2026
Cherry-picked from PR NousResearch#3005 by web3blind.
Adds DM topic creation, persistence, and session isolation via Bot API 9.4.
Closes NousResearch#2598
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
…usResearch#2598)

Salvages PR NousResearch#3005 by web3blind. Cherry-picked onto current main with functional skill binding and docs added.

- DM topic creation via createForumTopic (Bot API 9.4, Feb 2026)
- Config-driven topics with thread_id persistence across restarts
- Session isolation via existing build_session_key thread_id support
- auto_skill field on MessageEvent for topic-skill bindings
- Gateway auto-loads bound skill on new sessions (same as /skill commands)
- Docs: full Private Chat Topics section in Telegram messaging guide
- 20 tests (17 original + 3 for auto_skill)

Closes NousResearch#2598
Co-authored-by: web3blind <web3blind@users.noreply.github.com>
Egavasyug pushed a commit to Egavasyug/hermes-agent that referenced this pull request Jun 10, 2026
…usResearch#2598)

Salvages PR NousResearch#3005 by web3blind. Cherry-picked onto current main with functional skill binding and docs added.

- DM topic creation via createForumTopic (Bot API 9.4, Feb 2026)
- Config-driven topics with thread_id persistence across restarts
- Session isolation via existing build_session_key thread_id support
- auto_skill field on MessageEvent for topic-skill bindings
- Gateway auto-loads bound skill on new sessions (same as /skill commands)
- Docs: full Private Chat Topics section in Telegram messaging guide
- 20 tests (17 original + 3 for auto_skill)

Closes NousResearch#2598
Co-authored-by: web3blind <web3blind@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Telegram Private Chat Topics support for project-based conversations

2 participants