mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[PR #6490] [MERGED] fix(tgbot): send the admin traffic reports as one message #6303
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#6303
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/6490
Author: @BlindMaster24
Created: 9/12/2026
Status: ✅ Merged
Merged: 9/13/2026
Merged by: @MHSanaei
Base:
main← Head:fix/tgbot-report-batching📝 Commits (3)
a50fd20fix(tgbot): send the admin traffic reports as one messagee74be3fMerge branch 'main' into fix/tgbot-report-batchinga960ac3Merge remote-tracking branch 'upstream/main' into fix/tgbot-report-batching📊 Changes
2 files changed (+217 additions, -21 deletions)
View changed files
➕
internal/web/service/tgbot/tgbot_report_batching_test.go(+189 -0)📝
internal/web/service/tgbot/tgbot_router.go(+28 -21)📄 Description
Summary
Two details the batching must not lose are part of this change: the reset report
still answers when the panel has no clients, and both reports are HTML-escaped
as a whole, because a single stray
<in a remark or an email now costs the~15-client page it lands on instead of one client's message.
Both admin reports looped over every client and called
SendMsgToTgbotinsidethe loop, so one tap produced one Telegram message per client. They now
accumulate a single report, which
SendMsgToTgbotalready pages at 2000characters per message.
Why
Two callbacks built their output by sending inside the loop:
reset_all_traffics_c—/clearall→ Confirm, plus the Reset alltraffics button (
tgbot_router.go:1259)get_sorted_traffic_usage_report— the Sorted traffic usage report buttonon the bot's main keyboard (
tgbot_router.go:1287)What the operator sees today
An operator with a few hundred clients taps Sorted traffic usage report (the
button exists precisely for that size of panel). The bot then issues one
sendMessageper client, back to back, with 100 ms between them.as
429 Too Many Requests, andSendMsgToTgbotclassifies a rate-limitanswer as neither
connectionnortimeoutnorclosed, so it stopsretrying and logs
Error sending telegram message:once per message(
tgbot_send.go:154). The report arrives in fragments, silently missing theclients whose messages were refused, and the log fills with one warning line
per refused message.
worker slot in the 10-goroutine pool that also serves every other callback.
The single-message path avoids all of it:
SendMsgToTgbotalready splits along report with
pageMessage, so the same content goes out as a handful ofpaged messages, and the page ceiling is the documented 2000-character message
limit rather than the client count.
This is the same burst pattern as the merged
#6340(per-refresh log spam);only the loop was left.
The two things batching changes
A panel with no clients. Reset all traffics → Confirm always ended with
the "process finished" reply and its
ReplyKeyboardRemove. Guarding the wholesend with
report.Len() > 0made an empty panel answer nothing: the prompt hadalready been deleted, so the operator tapped Confirm and watched the message
vanish.
FinishProcessis appended unconditionally again and that guard is gonefrom the path.
An unescaped
<. Both reports go out throughSendMsgToTgbot, which setsParseMode: "HTML", and the text carries operator input — the inbound remark(
clientInfoMsg→describeAttachedInbounds) and the email, both raw. Before,a remark like
DE <fast>broke that one client's message and the rest of thereport still arrived; with ~15 clients per page it now costs the whole page, and
the 400 matches none of the
connection/timeout/closedsubstrings the retrylogic looks for, so the page is dropped with one warning.
Both reports are therefore escaped as a whole before they are sent. That is safe
because none of the i18n values on these two paths carry markup in any of the 13
locales (checked across
internal/web/translation/*.json); the bot's HTML markuplives in the command help and welcome strings, not in the report strings.
Type of change
Areas affected
How was this tested?
internal/web/service/tgbot/tgbot_report_batching_test.goseeds one inbound withthree clients — each with its traffic row, its
clients/client_inboundslinkand its settings entry, so all three reach the report — and drives the admin
callbacks through
answerCallbackagainst a mocked Telegram API that recordswhat Telegram would have received:
TestTrafficUsageReportIsOneMessage— exactly onesendMessagefor thewhole report. On the old code that tap sends three, so it fails before the fix.
TestResetAllTrafficsAnswersWithNoClients— an empty panel. Asserts onemessage, non-empty text and
{"remove_keyboard":true}. Fails on the versionthat guarded the whole send.
TestTrafficUsageReportEscapesHtml— an inbound remarkedDE <fast>. Assertsthe text carries
<fast>and no raw<fast>. Fails without the escape.The message text is otherwise unchanged: the per-client blocks are the same
clientInfoMsgoutput, now separated by a blank line and joined into onereport, and the "no result" entries for emails without a traffic row are
appended to the same report.
Both loops share the mechanism, but the tests drive the read-only report path and
the empty-panel answer;
reset_all_traffics_cperforms real resets through thetraffic writer once clients exist, which the throwaway-DB test environment does
not stand up.
Screenshots / recordings
N/A — bot messages, no UI.
Breaking changes
None for the values the bot itself formats. Values carrying
<,&,>,"or
'are now escaped, which is what Telegram's HTML parse requires — such areport previously lost the page it landed on. The reply keyboard is still
removed, and
SendMsgToTgbotapplies it to the last page.Checklist
go build ./...and the test suite pass locally. — same reason as above.npm run lint,npm run typecheck, andnpm run buildpass. — no frontend files touched.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.