mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6493] [MERGED] fix(tgbot): answer the callbacks the bot cannot route #6306
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#6306
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/6493
Author: @BlindMaster24
Created: 9/12/2026
Status: ✅ Merged
Merged: 9/13/2026
Merged by: @MHSanaei
Base:
main← Head:fix/tgbot-answer-declined-callbacks📝 Commits (1)
29a14e9fix(tgbot): answer the callbacks the bot cannot route📊 Changes
2 files changed (+92 additions, -0 deletions)
View changed files
➕
internal/web/service/tgbot/tgbot_declined_callback_test.go(+81 -0)📝
internal/web/service/tgbot/tgbot_router.go(+11 -0)📄 Description
Summary
Three paths through
answerCallbackreturned without callingAnswerCallbackQuery: a payload that matches no case in the email-scopedswitch, one that matches nothing in the switch after it, and a button whose hash
had aged out of the 20-minute storage, which replied with a chat message only.
All three answer now, and the expired-hash path keeps its notice.
Why
Telegram keeps the tapped button in a loading state until the bot calls
answerCallbackQuery; the Bot API documents answering as mandatory for everycallback query. A callback that is never answered leaves that indicator running
until the client gives up, and the user is told nothing about what happened.
The reachable half: a button older than its payload
Payloads longer than 64 characters are not sent as button data —
encodeQueryreplaces them with an MD5 hash kept in
hashStorage(tgbot.go:493). Thatstorage is in-memory and TTL-limited:
Startcreates it with a 20-minuteexpiration (
tgbot.go:245) and a cron sweeps it every two minutes.Long payloads are ordinary, because the payload carries the client email:
client_individual_links <email>crosses 64 characters for an email of about 40(
tgbot_client.go:241),limit_traffic_in <email> ...at about 43, and thesame for every other per-client button.
So an admin opens a client card, comes back to it later — or the panel is
restarted, which empties the storage outright — and taps Refresh:
decodeQueryfails, the admin gets a "no query" chat message, and the buttonkeeps spinning: the tap is never resolved.
to miss among the bot's other messages.
It now answers with the same text, shown right where the tap happened, which
clears the indicator, and keeps the chat message:
sendCallbackAnswerTgBotis asingle unretried call while
SendMsgToTgbotretries connection errors, and theonly explanation for a dead button should not depend on one attempt succeeding.
The unroutable payloads
Three places dropped a tap on data the bot could not route:
tgbot_router.go:329), reached by an admin's payloadthat carries arguments. An unknown action there falls out of the switch into a
returnthat says nothing, and the two-token shape is exactly what an olderpanel version's buttons look like;
default:fall-through of the switch that follows it(
tgbot_router.go:1324): a payload that matches no case at all, including thesingle-token button names an older version used;
tgbot_router.go:316): a payload longer than 64characters travels as a hash, and once that hash ages out of
hashStorage(20 minutes, or a panel restart, which empties it)
decodeQueryfails and thetap is left unresolved.
All three now answer with the bot's generic error text. The expired-hash path
also keeps the chat message it already sent, because
sendCallbackAnswerTgBotis one unretried call while
SendMsgToTgbotretries connection errors — after arestart that notice is the only explanation the admin gets.
The numeric-pad answers this PR originally carried are gone, as the review
thread says:
add_client_limit_traffic_in,add_client_reset_exp_inandadd_client_ip_limit_inonly fall out of their parse on a payload the bot itselfnever generates, so the branch was unreachable and its test certified nothing.
The admin-only gate is left alone on purpose — refusing a non-admin silently is
the deliberate default-deny side of that check, and whether a client should be
told that a button exists but is not theirs is a product decision, not a routing
bug.
Type of change
Areas affected
How was this tested?
internal/web/service/tgbot/tgbot_declined_callback_test.godrivesanswerCallbackas an admin against a mocked Telegram API, withisRunningsetso a posted message would be counted:
TestUnroutableCallbackIsAnswered— three payloads that match nothing, eachanswered with nothing at all before the change:
no_such_callbackandget_backup_legacy(single token, the shape an older panel's button nameshad), and
add_client_legacy_step 5(the two-token shape, which reaches theemail-scoped switch). Asserts exactly one answer and zero posted messages.
TestExpiredCallbackHashIsAnsweredAndReported— a 32-hex payload that wasnever stored, with an empty
hashStorage. Zero answers before the change; oneanswer and one notice after it.
The two-token case is what found the third path: it was the one case that stayed
red on the first push of this test, because that payload returns out of the
email-scoped switch before reaching the answer added for the other two.
Screenshots / recordings
N/A — bot callbacks, no UI.
Breaking changes
One feedback detail changes on the expired-hash path: it gains a callback answer
in addition to the chat notice it already sent, so the admin sees a toast as well
as the message. Nothing is removed, and no other callback changes.
Checklist
go testcannot run the packages importinginternal/database, this one included;gofmtis clean and CI runs the new tests.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.