mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6760] [MERGED] feat(tgbot): rebuild the Telegram bot around editable screens and inline lists #6443
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#6443
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/6760
Author: @DIMFLIX
Created: 10/7/2026
Status: ✅ Merged
Merged: 10/24/2026
Merged by: @MHSanaei
Base:
main← Head:feat/tgbot-screens📝 Commits (10+)
e5ff472feat(tgbot): render the bot as one editable screen messageb32cd3afeat(tgbot): browse inbounds and clients in inline mode63edd48refactor(tgbot): move the client card, its pickers and links onto screens56b30eafeat(tgbot): keep one live card per kind of panel notification2bd0482feat(panel): warn when the bot has no inline modeb2831c5refactor(tgbot): finish the add-client wizard on the screen layerbb214c4chore(tgbot): note why the broadcast flow keeps its own cardseb5d8fdrefactor(tgbot): delete the senders the screen layer replacede03a9aerefactor(tgbot): route the last wizard prompts and notices through one pathed34872fix(tgbot): scope the inline browser to the user, not the chat📊 Changes
62 files changed (+7447 additions, -1943 deletions)
View changed files
📝
docs/content/docs/en/reference/api/settings.mdx(+8 -1)📝
docs/public/openapi.json(+70 -0)📝
frontend/public/openapi.json(+70 -0)📝
frontend/src/generated/examples.ts(+6 -0)📝
frontend/src/generated/schemas.ts(+29 -0)📝
frontend/src/generated/types.ts(+7 -0)📝
frontend/src/generated/zod.ts(+8 -0)📝
frontend/src/pages/api-docs/endpoints.ts(+7 -0)📝
frontend/src/pages/settings/TelegramTab.tsx(+62 -3)📝
internal/web/controller/setting.go(+37 -0)➕
internal/web/service/tgbot/helpers.go(+22 -0)➕
internal/web/service/tgbot/i18n_keys_test.go(+131 -0)➕
internal/web/service/tgbot/notices.go(+166 -0)➕
internal/web/service/tgbot/notices_test.go(+156 -0)➕
internal/web/service/tgbot/screen.go(+477 -0)➕
internal/web/service/tgbot/screen_client_qr.go(+136 -0)➕
internal/web/service/tgbot/screen_client_views.go(+383 -0)➕
internal/web/service/tgbot/screen_inline.go(+598 -0)➕
internal/web/service/tgbot/screen_inline_test.go(+620 -0)➕
internal/web/service/tgbot/screen_legacy.go(+146 -0)...and 42 more files
📄 Description
Summary
Reworks the Telegram bot around a single editable screen message per chat, and moves every list (inbounds, clients) into inline mode. A chat with the bot now shows one live screen instead of a pile of stale messages, and lists are searchable instead of being button grids.
Why
No issue to close; this came out of using the bot and finding the UX unworkable.
Type of change
Areas affected
What changes
One screen per chat. A single photo message per chat is tracked and edited on every action.
replaceScreensends the new screen before deleting the old one, so a slow send never leaves the chat empty. Screen art is the bot's own avatar, read throughgetUserProfilePhotosand refreshed in the background; a bot without an avatar gets a generated tile, so a screen always renders.Lists live in inline mode. Inbounds and clients are browsed through the inline query, with the caller's access level checked before a result is built. The query carries the list's intent (
inb:/cl:/add:), so the browser is scoped to the user who opened it rather than to server-side chat state.The bot knows who is talking to it.
/startand every screen branch on the caller's level: an admin gets the menu, a client gets its own usage, links and QR, a stranger gets only its own Telegram id.Categorised menu. Server / Clients / Traffic / Maintenance, with a way out of every screen — enforced in the one function that builds screens, so a new screen cannot be written as a dead end.
Add client opens on a draft: the client's fields are filled on the card and the inbounds are attached afterwards, instead of forcing an inbound choice first.
Broadcast is reachable from the menu (it existed only behind
/broadcast); its preview is the copy itself; its composing messages are cleared when the run ends or is abandoned; a cancelled run withdraws what it already delivered; and the summary card can be dismissed by any recipient.Panel-side warnings. Two BotFather switches the API can read but never set, and that stay invisible until something silently does not work:
POST /panel/api/setting/tgBotCapabilitiesreports whether the bot has inline mode enabled (lists never open without it) and whether group privacy is on (in groups the bot then only sees/start@bot). The Telegram settings tab warns for both, with a re-check button. New route is registered inendpoints.ts.Removed. The per-action senders the screen layer replaced — every message now goes through one path.
Design notes
The three decisions that are not visible from the diff, because a reviewer would otherwise reasonably ask "why is this a photo?", "why is the list not a keyboard?", and "how does this not leak the whole panel?".
A screen is one message, edited in place. Every screen is a single photo message per chat, keyed by chat id, and an action edits that message instead of posting another. Two consequences worth stating:
replaceScreensends the new screen before deleting the old, so a slow send never leaves the chat momentarily empty.The picture is the bot's own avatar. That is the whole point of the photo: an operator who sets a picture for the bot in @BotFather gets it as the artwork behind every screen, panel-wide, with no separate upload. It is read with
getUserProfilePhotos()and deliberately notgetChat().photo— the latter hands back aChatPhotofile_id, whichsendPhotorefuses withcan't use file of type ChatPhoto as Photo. The avatar is cached per screen kind and re-probed by a background goroutine, so a new picture appears without a restart. A bot with no avatar gets a generated dark tile, and art uploaded for one screen kind outranks the avatar, so a screen always has a picture and the fallback never masquerades as the avatar.Lists are inline queries, not button grids. A callback keyboard holds a handful of buttons; a panel has hundreds of clients. Inbounds and clients are therefore browsed through the inline query, which also gives Telegram's own search for free — the reason the old grids are gone rather than kept as a fallback. The query text carries the list's intent (
inb:/add:/cl:), because an inline query arrives with no chat and no server-side memory of which screen launched it; nothing is kept in server state, so a panel restart can neither lose the intent nor fall back to the wrong list. Picking an item posts its marker as the user's own message, which the router matches, resolves ownership for, and opens — a marker that fails the ownership check is refused. An inline answer is capped at 50 results by Telegram, so it is paged withnext_offset; a result id is capped at 64 bytes, so long ones are shortened by hash.How was this tested?
Automated
go build ./...clean.go test ./internal/web/service/tgbot/— 130 test functions in the package, 58 of them added here. Green.go test ./internal/web/green, including the route-registry contract test for the new endpoint.go test -race -shuffle=on ./internal/...clean across 47 packages.golangci-lint run0 issues.npx vitest run→ 182 files, 1797 tests passed;npx oxlint src toolsclean.codegen(thenpm run genstaleness gate) passes; bothfrontend/public/openapi.jsonanddocs/public/openapi.jsonare regenerated.The bot tests are behavioural rather than structural: they assert the sequence of Bot API calls. Examples: one screen per chat (a second render edits, it does not send); send-before-delete order; a QR screen carrying its codes as its own picture with no extra documents; a finished broadcast card carrying only the hide button; a broadcast copy delivered to a client carrying the hide button and the callback gate letting a client reach it; a client's
/startnever drawing an admin control; the add-client wizard opening on a draft; a long list arriving paged instead of rejected; and every i18n key the bot asks for existing in all 13 locale files (a missing key resolves to an empty string at runtime and silently blanks a button).Manual
Ran a panel built from this branch, exposed it through a Cloudflare quick tunnel, and used a real bot in a real chat:
/startas admin and as a client, adding a client through the wizard and attaching several inbounds, per-client links and QR, a broadcast to several recipients including a cancellation mid-run, and both panel warnings with the bot's inline mode toggled off and group privacy enabled.Screenshots / recordings
https://github.com/user-attachments/assets/89afb7a7-8d58-434a-a3b4-2b60a7bda49a
Breaking changes
None for panel users. The bot's own interaction model changes by design (one screen, inline lists), but no configuration, database migration or API contract change is required.
Checklist
go build ./...and the test suite pass locally.npm run lint,npm run typecheck, andnpm run buildpass.Two notes on the unticked boxes, rather than ticking them optimistically:
npx tsc --noEmitfails onsrc/test/setup.msw.ts('onUnhandledFrame' does not exist in type 'PartialObjectDeep<ListenOptions, ...>'). That file is untouched by this PR and is identical tomain, so the error is pre-existing upstream. The two frontend files this PR does touch aresrc/pages/settings/TelegramTab.tsxandsrc/pages/api-docs/endpoints.ts;oxlintis clean on them and the frontend test suite passes.endpoints.tsso it appears in the panel's API docs, and the docs OpenAPI copy plus the generated MDX are refreshed.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.