-
Notifications
You must be signed in to change notification settings - Fork 26
Support Telegram Group Topics (message_thread_id) #509
Description
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
- User creates a Telegram supergroup
- Enables Topics
- Adds DevClaw bot
- 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→ projectalpha - Topic
Infra→ projectinfra - Topic
Research→ projectresearch
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
- Receive Telegram message
- Read
chat.idandmessage_thread_id - Resolve session key
telegram::topic: - Resolve optional project mapping
- Load project-specific context/tools
- Reply to the same topic thread
Compatibility
This change should be fully backwards compatible because:
message_thread_idonly 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.