Skip to content

Support Telegram Group Topics (message_thread_id) #509

@netandreus

Description

@netandreus

Could you please add support for Telegram Group Topics in the DevClaw Telegram integration.

Telegram supergroups can enable Topics, which create separate threaded discussions inside the same group. Each topic has a unique
message_thread_id.

DevClaw could use this ID to create isolated sessions per topic, allowing multiple independent DevClaw workflows within a single Telegram group.

Motivation

Currently, when DevClaw is used inside a Telegram group, all messages
share the same conversation context.

With topic support:

  • Each topic = separate DevClaw session
  • Multiple projects can run in parallel
  • Context does not mix between workflows
  • One Telegram group can act as a multi-project workspace

Telegram Background

Telegram does not expose a separate "forum" entity in the UI. Instead:

  • Users create a Group
  • If the group is a Supergroup, they can enable Topics

When topics are enabled, Telegram internally treats the group as a
forum-style group.

Messages in topics include the field:

message.message_thread_id

This identifies the topic thread inside the group.

Proposed Implementation

1. Detect Topic Messages

Telegram messages may contain:

message.message_thread_id

If present, the message belongs to a topic.

2. Session Isolation

Include the thread ID in the DevClaw session key.

Example:

sessionKey = `telegram:${chatId}:${threadId || "main"}`

This preserves current behavior for:

  • Direct messages
  • Groups without topics

3. Sending Replies to the Correct Topic

When replying through the Telegram Bot API, include the thread ID:

sendMessage({
  chat_id: chatId,
  text: response,
  message_thread_id: threadId
})

This ensures DevClaw replies stay inside the correct topic thread.

Example Workflow

  1. User creates a Telegram supergroup
  2. Enables Topics
  3. Adds DevClaw bot
  4. Creates topics such as:
  • DevClaw General
  • Project Alpha
  • Infrastructure
  • Research
  • Experiments

Each topic becomes a separate DevClaw session.

Project-to-Topic Routing

Beyond basic topic support, DevClaw could support project-aware routing inside Telegram groups.

Idea

Map each Telegram topic to a DevClaw project automatically.

Example:

  • Topic Project Alpha → project alpha
  • Topic Infra → project infra
  • Topic Research → project research

Benefits

  • Automatically load the correct project context
  • Reduce manual project selection
  • Enable multi-project workflows inside a single Telegram group

Possible Implementation

Mapping configuration example:

{
  "telegramTopicProjects": {
    "<chatId>:<threadId>": "project-alpha",
    "<chatId>:<threadId-2>": "infra"
  }
}

Or infer the project name from the topic title.

Suggested Flow

  1. Receive Telegram message
  2. Read chat.id and message_thread_id
  3. Resolve session key
    telegram::topic:
  4. Resolve optional project mapping
  5. Load project-specific context/tools
  6. Reply to the same topic thread

Compatibility

This change should be fully backwards compatible because:

  • message_thread_id only exists when topics are enabled
  • Existing group and DM behavior remains unchanged

References

Potential Impact

This feature would significantly improve DevClaw usability for teams managing multiple projects inside Telegram by turning a single group into a structured multi-project workspace.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions