mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6510] [MERGED] feat(tgbot): add /broadcast to relay an admin message to all clients #6319
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6319
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/6510
Author: @DIMFLIX
Created: 9/13/2026
Status: ✅ Merged
Merged: 9/26/2026
Merged by: @MHSanaei
Base:
main← Head:feat/tgbot-broadcast📝 Commits (6)
72e5f73feat(tgbot): add /broadcast to relay an admin message to all clients088a32efix(tgbot): harden broadcast composition per reviewe4b2a13fix(tgbot): reset broadcast state on stop and classify 403 as skipped804508cfix(tgbot): count unreachable recipients in broadcast progress throttlecc13eb5Merge remote-tracking branch 'origin/main' into pr/6510ac2cde4fix(tgbot): key broadcast compositions by admin, not chat📊 Changes
17 files changed (+1666 additions, -0 deletions)
View changed files
📝
internal/web/service/tgbot/tgbot.go(+2 -0)➕
internal/web/service/tgbot/tgbot_broadcast.go(+525 -0)➕
internal/web/service/tgbot/tgbot_broadcast_test.go(+941 -0)📝
internal/web/service/tgbot/tgbot_router.go(+16 -0)📝
internal/web/translation/ar-EG.json(+14 -0)📝
internal/web/translation/en-US.json(+14 -0)📝
internal/web/translation/es-ES.json(+14 -0)📝
internal/web/translation/fa-IR.json(+14 -0)📝
internal/web/translation/id-ID.json(+14 -0)📝
internal/web/translation/ja-JP.json(+14 -0)📝
internal/web/translation/pt-BR.json(+14 -0)📝
internal/web/translation/ru-RU.json(+14 -0)📝
internal/web/translation/tr-TR.json(+14 -0)📝
internal/web/translation/uk-UA.json(+14 -0)📝
internal/web/translation/vi-VN.json(+14 -0)📝
internal/web/translation/zh-CN.json(+14 -0)📝
internal/web/translation/zh-TW.json(+14 -0)📄 Description
What
An admin-only
/broadcastcommand for the Telegram bot. The admin sends any message — text, rich text, photos, a video, a file, a sticker or a whole album — confirms it with an inline button, and the bot delivers an exact copy of it to every client that has a Telegram ID linked, on behalf of the bot.Why
There is currently no way to reach all clients at once: notifications only cover exhausted quotas, so an operator who wants to announce maintenance or a new feature has to copy the message to each client chat by hand.
How it works
/broadcastasks for a message (one broadcast at a time; a second command is refused while one runs).copyMessagesends with a small pause,429 retry_afterhonored per recipient, failures counted without stopping the run, progress edited into one card at most every 25 sends or 3 seconds, and a cancel button checked between sends. The final delivered/failed/skipped summary is edited into the card so it is never duplicated.notifyExhaustedwalk: clients with a linkedtg_id, deduplicated, admins excluded — they already receive the reports. The message content is never logged.Design note: copy instead of content parsing
The first draft of this feature parsed the admin's message into a draft (text/media kind/file id) and re-sent it with
sendMessage/sendPhoto/... That broke on the newrich_messageformat, would need a new parser for every Telegram message type, and ran into caption length limits.copyMessage/copyMessagesavoid all of that: content arrives 1:1 with formatting preserved, future message types work for free, and — unlikeforwardMessage— there is no "Forwarded from" header, so the admin's identity stays private.Albums arrive as separate updates sharing a
media_group_id; their ids are buffered with a short debounce, sorted (copyMessagesrequires strictly increasing ids), and delivered as onecopyMessagescall so recipients see the original album.Notes / limitations
Testing
tgbot_broadcast_test.go(stdlibtesting, table-driven): recipient collection against a real DB (dedup, admin exclusion,tg_id == 0), run counters (delivered/failed), mid-run cancel, 429 retry pauses via a swappable sender, single-slot runner, admin-only command and callbacks, album buffering with out-of-order updates, wire assertions forcopyMessage/copyMessagesbodies, and an end-to-end confirm throughanswerCallbackagainst a mock API.go build ./...,go test ./internal/web/service/tgbot/ -count=1,make test-go,golangci-lint runall pass.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.