[PR #6760] [MERGED] feat(tgbot): rebuild the Telegram bot around editable screens and inline lists #6443

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

📋 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+)

  • e5ff472 feat(tgbot): render the bot as one editable screen message
  • b32cd3a feat(tgbot): browse inbounds and clients in inline mode
  • 63edd48 refactor(tgbot): move the client card, its pickers and links onto screens
  • 56b30ea feat(tgbot): keep one live card per kind of panel notification
  • 2bd0482 feat(panel): warn when the bot has no inline mode
  • b2831c5 refactor(tgbot): finish the add-client wizard on the screen layer
  • bb214c4 chore(tgbot): note why the broadcast flow keeps its own cards
  • eb5d8fd refactor(tgbot): delete the senders the screen layer replaced
  • e03a9ae refactor(tgbot): route the last wizard prompts and notices through one path
  • ed34872 fix(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

  • The bot posted a new message for almost every action, so a chat with it accumulated stale menus that were never cleaned up.
  • Listing inbounds or clients was done with callback-button grids, which become unusable past a handful of entries. Anything with many elements has to go through an inline query.
  • The bot had no notion of who was talking to it: a panel client could be handed the admin menu, which listed every client's email.

No issue to close; this came out of using the bot and finding the UX unworkable.

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Documentation
  • Tests only
  • Build / CI / tooling
  • Other

Areas affected

  • Frontend (UI / panel pages)
  • Backend (API endpoints, login, settings)
  • Xray config generation
  • Subscription (share links / Clash / JSON)
  • Statistics / traffic counters
  • Database / migrations
  • Install / upgrade script
  • Docker image
  • Multi-node (sub-nodes)
  • Telegram bot

What changes

One screen per chat. A single photo message per chat is tracked and edited on every action. replaceScreen sends 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 through getUserProfilePhotos and 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. /start and 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/tgBotCapabilities reports 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 in endpoints.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:

  • replaceScreen sends the new screen before deleting the old, so a slow send never leaves the chat momentarily empty.
  • When an edit fails — content unchanged, or the message is past Telegram's 48-hour edit window — the screen is re-sent rather than surfaced as an error. A stale button tap therefore degrades to a fresh screen, never to a silent dead end.

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 not getChat().photo — the latter hands back a ChatPhoto file_id, which sendPhoto refuses with can'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 with next_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 run 0 issues.
  • Frontend: npx vitest run → 182 files, 1797 tests passed; npx oxlint src tools clean.
  • codegen (the npm run gen staleness gate) passes; both frontend/public/openapi.json and docs/public/openapi.json are 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 /start never 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: /start as 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

  • 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.
  • For frontend changes: npm run lint, npm run typecheck, and npm run build pass.
  • 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.

Two notes on the unticked boxes, rather than ticking them optimistically:

  • typecheck / build: npx tsc --noEmit fails on src/test/setup.msw.ts ('onUnhandledFrame' does not exist in type 'PartialObjectDeep<ListenOptions, ...>'). That file is untouched by this PR and is identical to main, so the error is pre-existing upstream. The two frontend files this PR does touch are src/pages/settings/TelegramTab.tsx and src/pages/api-docs/endpoints.ts; oxlint is clean on them and the frontend test suite passes.
  • Docs: no Wiki/README page added. The new endpoint is registered in endpoints.ts so 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.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6760 **Author:** [@DIMFLIX](https://github.com/DIMFLIX) **Created:** 10/7/2026 **Status:** ✅ Merged **Merged:** 10/24/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `feat/tgbot-screens` --- ### 📝 Commits (10+) - [`e5ff472`](https://github.com/MHSanaei/3x-ui/commit/e5ff472657b77853ceb024e979930c948a3cafed) feat(tgbot): render the bot as one editable screen message - [`b32cd3a`](https://github.com/MHSanaei/3x-ui/commit/b32cd3a4cc68adb9079aa319ae31797ce737de40) feat(tgbot): browse inbounds and clients in inline mode - [`63edd48`](https://github.com/MHSanaei/3x-ui/commit/63edd48fa5ae8d23398852ba3729cd97870a2c8a) refactor(tgbot): move the client card, its pickers and links onto screens - [`56b30ea`](https://github.com/MHSanaei/3x-ui/commit/56b30eaecc75809bed918ea9265554e4ed09c82e) feat(tgbot): keep one live card per kind of panel notification - [`2bd0482`](https://github.com/MHSanaei/3x-ui/commit/2bd04820912b81ab8f5d7e76e4281461dc03ae80) feat(panel): warn when the bot has no inline mode - [`b2831c5`](https://github.com/MHSanaei/3x-ui/commit/b2831c576bcb85612b6bf7513aa25c611766b4d0) refactor(tgbot): finish the add-client wizard on the screen layer - [`bb214c4`](https://github.com/MHSanaei/3x-ui/commit/bb214c4de6b918ca49cbf0e1b948b8d5715d5e0a) chore(tgbot): note why the broadcast flow keeps its own cards - [`eb5d8fd`](https://github.com/MHSanaei/3x-ui/commit/eb5d8fd32cb43716ce6cef063e34d333d70a7bc8) refactor(tgbot): delete the senders the screen layer replaced - [`e03a9ae`](https://github.com/MHSanaei/3x-ui/commit/e03a9ae0da4fdb0532c280c714b09e25bbfb49f5) refactor(tgbot): route the last wizard prompts and notices through one path - [`ed34872`](https://github.com/MHSanaei/3x-ui/commit/ed34872aeafede2a801001ac965175f3fce82fc5) fix(tgbot): scope the inline browser to the user, not the chat ### 📊 Changes **62 files changed** (+7447 additions, -1943 deletions) <details> <summary>View changed files</summary> 📝 `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_ </details> ### 📄 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 - The bot posted a new message for almost every action, so a chat with it accumulated stale menus that were never cleaned up. - Listing inbounds or clients was done with callback-button grids, which become unusable past a handful of entries. Anything with many elements has to go through an inline query. - The bot had no notion of who was talking to it: a panel client could be handed the admin menu, which listed every client's email. No issue to close; this came out of using the bot and finding the UX unworkable. ## Type of change - [x] Bug fix - [x] New feature - [x] Refactoring (no behavior change) - [ ] Documentation - [ ] Tests only - [ ] Build / CI / tooling - [ ] Other ## Areas affected - [x] Frontend (UI / panel pages) - [x] Backend (API endpoints, login, settings) - [ ] Xray config generation - [ ] Subscription (share links / Clash / JSON) - [ ] Statistics / traffic counters - [ ] Database / migrations - [ ] Install / upgrade script - [ ] Docker image - [ ] Multi-node (sub-nodes) - [x] Telegram bot ## What changes **One screen per chat.** A single photo message per chat is tracked and edited on every action. `replaceScreen` sends 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 through `getUserProfilePhotos` and 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.** `/start` and 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/tgBotCapabilities` reports 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 in `endpoints.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: - `replaceScreen` sends the new screen *before* deleting the old, so a slow send never leaves the chat momentarily empty. - When an edit fails — content unchanged, or the message is past Telegram's 48-hour edit window — the screen is re-sent rather than surfaced as an error. A stale button tap therefore degrades to a fresh screen, never to a silent dead end. **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 **not** `getChat().photo` — the latter hands back a `ChatPhoto` file_id, which `sendPhoto` refuses with `can'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 with `next_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 run` 0 issues. - Frontend: `npx vitest run` → 182 files, 1797 tests passed; `npx oxlint src tools` clean. - `codegen` (the `npm run gen` staleness gate) passes; both `frontend/public/openapi.json` and `docs/public/openapi.json` are 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 `/start` never 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: `/start` as 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 - [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. - [ ] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. - [ ] 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. Two notes on the unticked boxes, rather than ticking them optimistically: - **typecheck / build**: `npx tsc --noEmit` fails on `src/test/setup.msw.ts` (`'onUnhandledFrame' does not exist in type 'PartialObjectDeep<ListenOptions, ...>'`). That file is untouched by this PR and is identical to `main`, so the error is pre-existing upstream. The two frontend files this PR does touch are `src/pages/settings/TelegramTab.tsx` and `src/pages/api-docs/endpoints.ts`; `oxlint` is clean on them and the frontend test suite passes. - **Docs**: no Wiki/README page added. The new endpoint is registered in `endpoints.ts` so it appears in the panel's API docs, and the docs OpenAPI copy plus the generated MDX are refreshed. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:08:48 +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#6443
No description provided.