[PR #6879] [MERGED] feat(tgbot): route admin notifications to a forum topic #6495

Closed
opened 2026-11-02 04:09:10 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6879
Author: @gr219
Created: 10/20/2026
Status: ✅ Merged
Merged: 10/24/2026
Merged by: @MHSanaei

Base: main ← Head: feat/tgbot-forum-topics


📝 Commits (8)

  • 32d98c2 feat(tgbot): route admin notifications to a forum topic
  • 21e7bf9 fix(tgbot): treat topic 1 as the General topic
  • 7d2ad7c fix(tgbot): align docs helper with panel topic rules, drop dead broadcast hunk
  • 8f6a15f Merge remote-tracking branch 'origin/main' into pr/6879
  • a18bb37 Merge remote-tracking branch 'origin/main' into pr/6879
  • 24e39f0 test(tgbot): keep the admin-topic tests in tgbot_test.go
  • 86dbb72 fix(i18n): mention forum topics in every Telegram chat ID hint
  • 3720a84 docs(telegram): describe forum-topic chat IDs in the fa, ru and zh guides

📊 Changes

25 files changed (+245 additions, -53 deletions)

View changed files

📝 docs/components/tools/telegram-setup-helper.tsx (+1 -1)
📝 docs/content/docs/en/operations/telegram-bot.mdx (+6 -1)
📝 docs/content/docs/fa/operations/telegram-bot.mdx (+6 -1)
📝 docs/content/docs/ru/operations/telegram-bot.mdx (+6 -1)
📝 docs/content/docs/zh/operations/telegram-bot.mdx (+5 -1)
📝 docs/lib/xray/telegram.test.ts (+40 -2)
📝 docs/lib/xray/telegram.ts (+22 -9)
📝 internal/web/service/tgbot/tgbot.go (+63 -11)
📝 internal/web/service/tgbot/tgbot_client.go (+3 -3)
📝 internal/web/service/tgbot/tgbot_report.go (+4 -4)
📝 internal/web/service/tgbot/tgbot_send.go (+8 -6)
📝 internal/web/service/tgbot/tgbot_test.go (+68 -0)
📝 internal/web/translation/ar-EG.json (+1 -1)
📝 internal/web/translation/en-US.json (+1 -1)
📝 internal/web/translation/es-ES.json (+1 -1)
📝 internal/web/translation/fa-IR.json (+1 -1)
📝 internal/web/translation/id-ID.json (+1 -1)
📝 internal/web/translation/ja-JP.json (+1 -1)
📝 internal/web/translation/pt-BR.json (+1 -1)
📝 internal/web/translation/ru-RU.json (+1 -1)

...and 5 more files

📄 Description

Summary

Lets the Telegram Admin Chat ID setting target a forum topic: write an entry as chatId:topicId (e.g. -1001234567890:42) and every bot message to that chat is sent with message_thread_id, so it lands in the chosen topic instead of "General".

Why

In forum-enabled supergroups the bot currently posts everything (reports, login alerts, backups, command replies) into the General topic, because only a bare chat ID can be configured. Admins who split a group into topics have no way to route panel notifications to the right one.

Type of change

  • New feature
  • Documentation

Areas affected

  • Backend (API endpoints, login, settings)
  • Telegram bot

Details:

  • tgbot.go: new parseAdminChats replaces the inline loop. It accepts chatId[:topicId] entries, trims spaces, de-duplicates chats, and rejects a non-positive or conflicting topic for the same chat. Topics are kept in adminTopics next to adminIds under tgBotMutex. adminIds, and therefore checkAdmin, still holds plain chat IDs.
  • SendMsgToTgbot, SendMsgToTgbotDeleteAfter and every SendDocument (backups, config.json, ban logs, QR codes) now set MessageThreadID for chats that have a topic configured. Broadcasts are untouched because they never go to admin chats.
  • chatId:1 is treated as a bare chatId. General is thread 1 inside Telegram, but the Bot API rejects message_thread_id=1 and reaches General only when the field is left out. telego tags the field omitempty, so chats without a topic send no thread ID.
  • en-US setting description and docs/.../telegram-bot.mdx explain the syntax. The docs setup helper (docs/lib/xray/telegram.ts) follows the same rules as the Go parser: it keeps the suffix, merges repeated chats, and marks a second, different topic for the same chat as invalid.

How was this tested?

  • New tgbot_admin_topic_test.go: parsing table (plain, topic, spaces, duplicates), invalid inputs (123:, 123:0, 123:-5, 123:abc, conflicting topics, trailing comma), and inAdminTopic setting MessageThreadID only for configured chats. I broke the implementation on purpose and confirmed these tests fail.
  • go test ./internal/web/service/tgbot/ ./internal/web/controller/ pass (Go 1.27). gofmt is clean.
  • golangci-lint run (v2.15.0) on the tgbot package: 0 issues.
  • Docs: oxfmt --check, oxlint and vitest pass on the changed files, including new cases for topics, General (:1) and conflicting topics.
  • Not yet exercised against a live forum supergroup.

Breaking changes

None. Plain chat IDs parse exactly as before. Settings without : behave the same.

Checklist

  • I tested the change locally and confirmed the described behavior.
  • I added or updated tests for the new behavior (when applicable).
  • go build ./... and the test suite pass locally.
  • I updated the Wiki / README / API docs if user-facing behavior changed.
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6879 **Author:** [@gr219](https://github.com/gr219) **Created:** 10/20/2026 **Status:** ✅ Merged **Merged:** 10/24/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `feat/tgbot-forum-topics` --- ### 📝 Commits (8) - [`32d98c2`](https://github.com/MHSanaei/3x-ui/commit/32d98c2363b9b19d30362038d21d30bd60f67185) feat(tgbot): route admin notifications to a forum topic - [`21e7bf9`](https://github.com/MHSanaei/3x-ui/commit/21e7bf9c17ef2efd7abf061fd8cba270fcaffe45) fix(tgbot): treat topic 1 as the General topic - [`7d2ad7c`](https://github.com/MHSanaei/3x-ui/commit/7d2ad7c8af9727b6430deb265384b88953a916fb) fix(tgbot): align docs helper with panel topic rules, drop dead broadcast hunk - [`8f6a15f`](https://github.com/MHSanaei/3x-ui/commit/8f6a15fd9dfd75b477d833c38afa5d730f4783ae) Merge remote-tracking branch 'origin/main' into pr/6879 - [`a18bb37`](https://github.com/MHSanaei/3x-ui/commit/a18bb37cd0f366f1eb37fa7ccfaeb88011f9d558) Merge remote-tracking branch 'origin/main' into pr/6879 - [`24e39f0`](https://github.com/MHSanaei/3x-ui/commit/24e39f044f0619eca247fc3ef9f111f63e69cb41) test(tgbot): keep the admin-topic tests in tgbot_test.go - [`86dbb72`](https://github.com/MHSanaei/3x-ui/commit/86dbb72d4ace39d95ba683d88844323e75235243) fix(i18n): mention forum topics in every Telegram chat ID hint - [`3720a84`](https://github.com/MHSanaei/3x-ui/commit/3720a8418e62d7f1e8fa24c67e8726ab103b15d9) docs(telegram): describe forum-topic chat IDs in the fa, ru and zh guides ### 📊 Changes **25 files changed** (+245 additions, -53 deletions) <details> <summary>View changed files</summary> 📝 `docs/components/tools/telegram-setup-helper.tsx` (+1 -1) 📝 `docs/content/docs/en/operations/telegram-bot.mdx` (+6 -1) 📝 `docs/content/docs/fa/operations/telegram-bot.mdx` (+6 -1) 📝 `docs/content/docs/ru/operations/telegram-bot.mdx` (+6 -1) 📝 `docs/content/docs/zh/operations/telegram-bot.mdx` (+5 -1) 📝 `docs/lib/xray/telegram.test.ts` (+40 -2) 📝 `docs/lib/xray/telegram.ts` (+22 -9) 📝 `internal/web/service/tgbot/tgbot.go` (+63 -11) 📝 `internal/web/service/tgbot/tgbot_client.go` (+3 -3) 📝 `internal/web/service/tgbot/tgbot_report.go` (+4 -4) 📝 `internal/web/service/tgbot/tgbot_send.go` (+8 -6) 📝 `internal/web/service/tgbot/tgbot_test.go` (+68 -0) 📝 `internal/web/translation/ar-EG.json` (+1 -1) 📝 `internal/web/translation/en-US.json` (+1 -1) 📝 `internal/web/translation/es-ES.json` (+1 -1) 📝 `internal/web/translation/fa-IR.json` (+1 -1) 📝 `internal/web/translation/id-ID.json` (+1 -1) 📝 `internal/web/translation/ja-JP.json` (+1 -1) 📝 `internal/web/translation/pt-BR.json` (+1 -1) 📝 `internal/web/translation/ru-RU.json` (+1 -1) _...and 5 more files_ </details> ### 📄 Description ## Summary Lets the Telegram **Admin Chat ID** setting target a forum topic: write an entry as `chatId:topicId` (e.g. `-1001234567890:42`) and every bot message to that chat is sent with `message_thread_id`, so it lands in the chosen topic instead of "General". ## Why In forum-enabled supergroups the bot currently posts everything (reports, login alerts, backups, command replies) into the General topic, because only a bare chat ID can be configured. Admins who split a group into topics have no way to route panel notifications to the right one. ## Type of change - [x] New feature - [x] Documentation ## Areas affected - [x] Backend (API endpoints, login, settings) - [x] Telegram bot Details: - `tgbot.go`: new `parseAdminChats` replaces the inline loop. It accepts `chatId[:topicId]` entries, trims spaces, de-duplicates chats, and rejects a non-positive or conflicting topic for the same chat. Topics are kept in `adminTopics` next to `adminIds` under `tgBotMutex`. `adminIds`, and therefore `checkAdmin`, still holds plain chat IDs. - `SendMsgToTgbot`, `SendMsgToTgbotDeleteAfter` and every `SendDocument` (backups, config.json, ban logs, QR codes) now set `MessageThreadID` for chats that have a topic configured. Broadcasts are untouched because they never go to admin chats. - `chatId:1` is treated as a bare `chatId`. General is thread 1 inside Telegram, but the Bot API rejects `message_thread_id=1` and reaches General only when the field is left out. telego tags the field `omitempty`, so chats without a topic send no thread ID. - `en-US` setting description and `docs/.../telegram-bot.mdx` explain the syntax. The docs setup helper (`docs/lib/xray/telegram.ts`) follows the same rules as the Go parser: it keeps the suffix, merges repeated chats, and marks a second, different topic for the same chat as invalid. ## How was this tested? - New `tgbot_admin_topic_test.go`: parsing table (plain, topic, spaces, duplicates), invalid inputs (`123:`, `123:0`, `123:-5`, `123:abc`, conflicting topics, trailing comma), and `inAdminTopic` setting `MessageThreadID` only for configured chats. I broke the implementation on purpose and confirmed these tests fail. - `go test ./internal/web/service/tgbot/ ./internal/web/controller/` pass (Go 1.27). `gofmt` is clean. - `golangci-lint run` (v2.15.0) on the tgbot package: 0 issues. - Docs: `oxfmt --check`, `oxlint` and `vitest` pass on the changed files, including new cases for topics, General (`:1`) and conflicting topics. - Not yet exercised against a live forum supergroup. ## Breaking changes None. Plain chat IDs parse exactly as before. Settings without `:` behave the same. ## Checklist - [x] I tested the change locally and confirmed the described behavior. - [x] I added or updated tests for the new behavior (when applicable). - [x] `go build ./...` and the test suite pass locally. - [x] I updated the Wiki / README / API docs if user-facing behavior changed. - [x] My commits follow the project's existing message style. - [x] I have no unrelated changes mixed into this PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:09:10 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6495
No description provided.