feat: telegram group topics support (message_thread_id) #509#512
Open
netandreus wants to merge 11 commits intolaurentenhoor:mainfrom
Open
feat: telegram group topics support (message_thread_id) #509#512netandreus wants to merge 11 commits intolaurentenhoor:mainfrom
netandreus wants to merge 11 commits intolaurentenhoor:mainfrom
Conversation
Adds optional messageThreadId parameter through the notification chain: Channel type -> resolveNotifyChannel -> notify -> sendMessage -> Telegram API. This enables per-topic routing in Telegram forum groups, where each project can have notifications sent to a specific forum topic instead of the main chat. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adds a new "issueComplete" notification event type that fires when an issue is closed via the CLOSE_ISSUE completion action. This provides visibility into the final delivery milestone of the pipeline. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…name When a project is registered with a mixed-case name (e.g. 'UpMoltWork'), the session key was built using project.name, resulting in keys like: agent:main:subagent:UpMoltWork-developer-junior-annabelle However, the gateway stores and looks up session keys case-sensitively, and new sessions are created with lowercase keys. This mismatch caused the heartbeat to not find the active session, consider the worker dead, and re-dispatch — resulting in workers being restarted every heartbeat cycle. Fix: use project.slug (which is always lowercase) to build the session key. Falls back to project.name.toLowerCase() for safety. Fixes: worker restart loop on projects with mixed-case names
…nish tool. Updated the logic for finding active slots to ensure case-insensitive comparison of session keys, enhancing the accuracy of slot matching for the current session.
…t/message-thread-id
This update introduces support for the optional messageThreadId parameter across various project resolution functions and tools, enabling topic-aware routing for Telegram channels. Key changes include: - New function `resolveProjectChannelScope` for building stable scope keys. - Updates to `resolveProjectSlug` and `getProject` to handle scoped inputs. - Migration logic for normalizing legacy topic fields in projects. - Adjustments in admin tools to accommodate messageThreadId for channel linking, un-linking, and listing. These enhancements improve the flexibility and accuracy of project management within chat environments, particularly for Telegram forum topics.
This update introduces the `notifyTarget` parameter in the dispatch and agent communication processes, allowing for more precise routing of messages to specific Telegram channels and topics. Key changes include: - Addition of `notifyTarget` in the `dispatchTask` and `sendToAgent` functions. - Implementation of `applyNotifyRoutingToGatewayParams` to handle the new routing logic. - Updates to project migration logic to ensure legacy topic fields are correctly normalized. These enhancements improve the flexibility of message delivery within Telegram environments, particularly for forum topics.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change adds Telegram forum topic support so DevClaw can treat each topic in a supergroup as a distinct binding: notifications and gateway agent runs stay in the correct thread, and projects can be registered or linked per topic instead of sharing one context for the whole chat.
Behavior for DMs and groups without topics is unchanged (
message_thread_idis absent in those cases).Closes:
message_thread_id) #509work_finish#508Contains:
What changed
Data model and resolution
Channelwith optionalmessageThreadId(aligned with the Telegram Bot API naming).resolveProjectChannelScope()and topic-awareresolveProjectSlug()/getProject()inlib/projects/io.ts:channel+channelId+accountId+ topic wins.messageThreadId), preserving existing setups.topicIdon disk tomessageThreadIdand strippedtopicIdon save (covered in tests).Notifications
resolveNotifyChannel()now returnsmessageThreadIdwhen the selected channel entry has one.notify()forwardsmessageThreadIdinto the Telegram runtimesendMessagepath so pipeline/dispatch alerts land in the same topic as the bound project.Dispatch and worker runs
dispatchTaskpasses anotifyTarget(chat + channel + account + optionalmessageThreadId) intosendToAgent.sendToAgentmaps that to gatewayagentparams (to,channel,accountId,threadId) so the worker session receivesmessageThreadIdinjection for tools—matching how OpenClaw routes Telegram forum threads.Tools and admin UX
channel_link/project_register: optionalmessageThreadIdto bind a project to a specific forum topic.work_finish,health,sync_labels,project_status, etc.: optionalmessageThreadIdwhen resolving the project from a Telegram chat so the correct slug is chosen in multi-topic groups.How to use it
message_thread_id(e.g. from incoming updates or Bot API payloads).channel="telegram", the groupchannelId, andmessageThreadIdset to that topic’s id.notify:telegram:<name>(or channel index) labels on issues so routing picks the channel entry that includes the topic id.Tests
lib/projects/projects.test.ts: legacytopicId→messageThreadIdmigration andresolveProjectSlugwithmessageThreadId.Run:
Also shipped on this branch
These landed together with the topic work (same merge target):
issueCompleteevent when an issue is closed.work_finishslot matching (case-insensitive session key comparison) and consistent use ofproject.slugfor session keys.jsonResulthelper inlib/json-result.tsfor robust plugin-sdk interop.package-lock.jsonrefresh (Node 22–aligned install).If you prefer a PR that only contains the Telegram topic commits, cherry-pick or rebase onto the base branch before opening the PR.