feat(telegram-bot): route notifications into a per-channel forum topic#10893
Open
dugynoo wants to merge 1 commit into
Open
feat(telegram-bot): route notifications into a per-channel forum topic#10893dugynoo wants to merge 1 commit into
dugynoo wants to merge 1 commit into
Conversation
Adds an opt-in `/setforum` command that mirrors every Huly chunter channel the user has notifications for to its own forum topic inside the bot's DM, turning the legacy linear inbox into a per-channel layout similar to other chat clients. Inbound posts and replies inside a topic route back to the matching Huly channel. How it works: - `/setforum` stores the user's Telegram id on the integration as the forum chat id (DM-only in this iteration). The handler refuses early if Threaded Mode is not enabled on the bot via @Botfather, using the `has_topics_enabled` bit on `getMe` (Bot API 9.4) so the check does not pollute the chat with a probe topic. - `/unsetforum` clears the stored forum chat id and reverts to the legacy single-thread DM layout. - `processNotification` calls `resolveForumTopic` whenever a forum chat id is configured. The first notification for a Huly channel lazily creates a topic named `#channel-name` (or the DM peer's display name) and the mapping is persisted in a new `telegram_bot.forum_topics` table keyed on (workspace, account, channel_id). - `handleForumTopicMessage` routes top-level Telegram posts inside a known topic to `sendMessage` on the matching ChunterSpace; reply-to-message inside a topic still threads through `onReply` as before. Replies that target the topic's first system message are treated as fresh posts, not threaded replies to a synthetic message id. - Forum service messages (`forum_topic_created`/`_edited`/`_closed`/...) are skipped at the top of `bot.on(message())` because they carry a `message_thread_id` but should not be answered with the keyboard fallback. Notes: - Behaviour is fully opt-in: users that never run `/setforum` see the legacy linear DM inbox unchanged. - Only chunter (Channel, DirectMessage) sources are routed. Other activity message sources fall back to the legacy DM so unknown notification kinds do not get silently dropped. - Schema migrations are idempotent (`CREATE TABLE IF NOT EXISTS`); no rewrite of existing data is required for upgrade.
|
Connected to Huly®: UBERF-16483 |
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.
Summary
Adds an opt-in
/setforumcommand that turns the telegram-bot's linear DMinbox into a forum-topic layout, one topic per Huly chunter channel.
Top-level posts inside a topic become new Huly chat messages, and replies
to specific notifications still thread through to Huly as before.
The new flow is fully backwards-compatible: users that never run
/setforumsee the existing single-thread DM unchanged.What changes
/setforum(DM-only in this iteration) stores the user's Telegram idas
forumChatIdon their integration. UsesgetMe().has_topics_enabled(Bot API 9.4) to refuse early if Threaded Mode is not enabled, instead
of probing with
createForumTopic+deleteForumTopicwhich leaves aservice message in the chat.
/unsetforumclears the routing and reverts to the legacy DM layout.processNotificationcallsresolveForumTopicwheneverforumChatIdis set on any of the user's integrations. The first notification for a
Huly channel lazily creates a topic named
#channel-name(or the DMpeer's display name) via
createForumTopic. The mapping is persistedin a new
telegram_bot.forum_topicstable.handleForumTopicMessageroutes top-level Telegram posts inside aknown topic to
sendMessageon the matching ChunterSpace, so userscan start fresh threads from Telegram. Reply-to-message inside a topic
still flows through
onReplyfor thread linking."replying" to the synthetic topic head when they open it to type) are
treated as fresh forum-routed posts instead of attempting to thread
them back to a non-existent activity message.
_reopened/general_forum_topic_hidden/_unhidden) are skipped at the top
of bot.on(message()) because they carry a message_thread_id but should
not trigger the workspace/channel keyboard fallback.
Testing
(v0.7.423): /setforum, notification to a channel produces a topic
named #channel-name, top-level reply lands as a new ChatMessage,
reply-to-notification threads via the existing onReply path.
Notes
multiple users sharing one chat is a natural follow-up but requires a
PK change on forum_topics for per-chat dedup and is intentionally
deferred to a separate PR.
activity message kinds fall back to the legacy DM so unknown sources
are not silently dropped.
migration is required to upgrade an existing deployment.