[PR #6697] [CLOSED] feat(tgbot): let customers fetch their own configs and guides #6417

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6697
Author: @pcxzs
Created: 9/30/2026
Status: ❌ Closed

Base: main ← Head: feat/tgbot-customer-menu


📝 Commits (7)

  • 8dd2a13 feat(tgbot): let customers fetch their own configs and guides
  • 933fd81 docs(tgbot): describe the customer self-service menu
  • 6e7d20f fix(tgbot): serve main's client verbs and give the menu an entry point
  • 929d711 Merge branch 'main' into feat/tgbot-customer-menu
  • 828e006 Merge branch 'main' into feat/tgbot-customer-menu
  • 6318bea docs(tgbot): put the expiry and quota header where the bot shows it
  • e7e490d test(tgbot): check each restored client verb sends its own output

📊 Changes

29 files changed (+1821 additions, -107 deletions)

View changed files

📝 docs/content/docs/en/operations/telegram-bot.mdx (+20 -0)
➕ internal/web/service/tgbot/tgbot_configs.go (+109 -0)
➕ internal/web/service/tgbot/tgbot_configs_test.go (+308 -0)
➕ internal/web/service/tgbot/tgbot_customer.go (+94 -0)
➕ internal/web/service/tgbot/tgbot_customer_fixture_test.go (+58 -0)
➕ internal/web/service/tgbot/tgbot_customer_keyboard.go (+28 -0)
➕ internal/web/service/tgbot/tgbot_customer_review_test.go (+217 -0)
➕ internal/web/service/tgbot/tgbot_customer_test.go (+124 -0)
➕ internal/web/service/tgbot/tgbot_guide.go (+64 -0)
➕ internal/web/service/tgbot/tgbot_guide_menu_test.go (+62 -0)
➕ internal/web/service/tgbot/tgbot_guide_test.go (+49 -0)
➕ internal/web/service/tgbot/tgbot_header.go (+45 -0)
📝 internal/web/service/tgbot/tgbot_router.go (+53 -68)
➕ internal/web/service/tgbot/tgbot_selfaction.go (+97 -0)
➕ internal/web/service/tgbot/tgbot_selfaction_test.go (+128 -0)
📝 internal/web/service/tgbot/tgbot_send.go (+1 -13)
📝 internal/web/translation/ar-EG.json (+28 -2)
📝 internal/web/translation/en-US.json (+28 -2)
📝 internal/web/translation/es-ES.json (+28 -2)
📝 internal/web/translation/fa-IR.json (+28 -2)

...and 9 more files

📄 Description

Summary

Part 2 of the Telegram bot split discussed in #6428, following #6518 (access
levels and /start binding). A bound customer can now get their own links, QR
codes and per-platform setup guide from the bot, without asking the admin.

Why

Today a customer who wants a config has to ask the operator for it, and the
operator has to find the client and paste a link into a private chat. The panel
already has the subscription URL, the share links and the QR codes, and
main already lets a linked customer fetch all three — but only by tapping a
button on one specific admin message, with no menu to navigate from and no
instructions for what to do with the link afterwards.

What changes

  • A customer menu (client_menu) reachable from the existing client commands,
    opening a keyboard of what the customer can do for themselves.
  • client_one_link / link_one: a picker that asks which of the client's links
    to send instead of returning all of them, which matters for a client attached
    to several inbounds.
  • clientHeader: every link page now names the config it is showing, with its
    expiry date and remaining quota, so a customer holding several can tell them
    apart. A config with no quota reads as unlimited rather than as zero left.
  • guide_menu / guide_<platform>: plain-text setup instructions for
    iPhone/iPad, Android, Windows, macOS and Linux, each naming a currently
    maintained app. Telegram only accepts http, https and tg:// in link
    buttons, so these are text and not tap-through links.
  • The three copy-pasted client pickers in tgbot_router.go collapse into one
    clientEmailPicker call each, which drops ~60 lines of duplication.

Builds on the helpers already in main rather than replacing them:
clientSubLinks (in-process, so it does not need the subscription host to
resolve here), sendClientSubLinks, sendClientIndividualLinks,
sendClientQRLinks, clientOwnedByTgUser and the chatUser actor keying.

Outside internal/web/service/tgbot/:

  • 13 locale files: 26 new keys, all translated. No new section; they extend the
    existing tgbot.buttons and tgbot.messages objects.

Not in this PR: renewal requests and reminders, per-user notification
settings, messaging the admin, the multi-bind ceiling, and the admin roster and
bulk actions. Customer self-reset (credential rotation) is deliberately absent.
A QR chooser that asks whether you want the subscription URL or a single
individual link is also not here — it changes the existing QR behavior, so it
should be reviewed on its own.

Security

  • Every per-client callback re-checks ownership (ownsClient) before it acts.
    The email in callback data is only a claim, since the keyboard outlives the
    message it was sent with.
  • link_one carries an attacker-chosen index alongside the email.
    clientSelfTarget drops it before the check, and splitClientLinkIndex
    refuses a negative or unparsable index rather than reading past the slice.
  • Strangers still get only /start and /id, and groups are still ignored.
    Those paths are untouched.
  • Admin-only callbacks stay out of the customer allowlist. There is a test that
    pins client_cancel, client_edit, set_bindmax, admin_settings and
    broadcast_confirm against isClientSelfCallback.
  • Tests cover a foreign client being refused, the owner being served, an index
    smuggled into link_one, and an unbound account being told how to bind
    rather than shown a menu whose buttons would each refuse it.

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

How was this tested?

  • New unit tests: tgbot_selfaction_test.go (verb splitting, the index being
    stripped before the check, unusable input refused), tgbot_configs_test.go
    (link labels, out-of-range index, ownership both ways, header and quota
    labels, the configs step naming the config first), tgbot_customer_test.go
    (menu routing, admin callbacks outside the allowlist, unbound vs bound),
    tgbot_guide_test.go and tgbot_guide_menu_test.go (every platform
    resolves, unknown tags refused).
  • go build ./..., go vet ./..., go test -shuffle=on -count=1 ./...,
    golangci-lint (0 issues), oxlint, tsc --noEmit and the i18n dead-keys
    test all pass locally. No frontend source changed, so no frontend build was
    needed.
  • Not yet tested against a live panel with a real bot token; the customer taps
    above are covered by unit tests only.

Screenshots / recordings

The customer menu and one of the setup guides, from a test bot:

  • Menu: My configs → All links / One link / Subscription URL / QR codes /
    Setup guide
  • Guide: iPhone / Android / Windows / macOS / Linux, one tap each

Breaking changes

None. main's existing client_sub_links, client_individual_links and
client_qr_links callbacks keep their current behavior, their routing and their
clientOwnedByTgUser check; this branch only adds new verbs alongside them.

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.

🔄 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/6697 **Author:** [@pcxzs](https://github.com/pcxzs) **Created:** 9/30/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feat/tgbot-customer-menu` --- ### 📝 Commits (7) - [`8dd2a13`](https://github.com/MHSanaei/3x-ui/commit/8dd2a134233190daa80ef3996920612bf46deeee) feat(tgbot): let customers fetch their own configs and guides - [`933fd81`](https://github.com/MHSanaei/3x-ui/commit/933fd81efa61ea1c5f277f8af40e70546c277b6c) docs(tgbot): describe the customer self-service menu - [`6e7d20f`](https://github.com/MHSanaei/3x-ui/commit/6e7d20f84e4cc9c8092a6caf647d9be7895600a9) fix(tgbot): serve main's client verbs and give the menu an entry point - [`929d711`](https://github.com/MHSanaei/3x-ui/commit/929d71183a0a82f7ebef752f02f1183a7d8b487e) Merge branch 'main' into feat/tgbot-customer-menu - [`828e006`](https://github.com/MHSanaei/3x-ui/commit/828e006a450919c2b243f2b4acb517ae83891ea3) Merge branch 'main' into feat/tgbot-customer-menu - [`6318bea`](https://github.com/MHSanaei/3x-ui/commit/6318bea33f90497e7e2650cb47570746d4ef8454) docs(tgbot): put the expiry and quota header where the bot shows it - [`e7e490d`](https://github.com/MHSanaei/3x-ui/commit/e7e490d2773b7f5aeec58c6c0ed727deb52d9424) test(tgbot): check each restored client verb sends its own output ### 📊 Changes **29 files changed** (+1821 additions, -107 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/en/operations/telegram-bot.mdx` (+20 -0) ➕ `internal/web/service/tgbot/tgbot_configs.go` (+109 -0) ➕ `internal/web/service/tgbot/tgbot_configs_test.go` (+308 -0) ➕ `internal/web/service/tgbot/tgbot_customer.go` (+94 -0) ➕ `internal/web/service/tgbot/tgbot_customer_fixture_test.go` (+58 -0) ➕ `internal/web/service/tgbot/tgbot_customer_keyboard.go` (+28 -0) ➕ `internal/web/service/tgbot/tgbot_customer_review_test.go` (+217 -0) ➕ `internal/web/service/tgbot/tgbot_customer_test.go` (+124 -0) ➕ `internal/web/service/tgbot/tgbot_guide.go` (+64 -0) ➕ `internal/web/service/tgbot/tgbot_guide_menu_test.go` (+62 -0) ➕ `internal/web/service/tgbot/tgbot_guide_test.go` (+49 -0) ➕ `internal/web/service/tgbot/tgbot_header.go` (+45 -0) 📝 `internal/web/service/tgbot/tgbot_router.go` (+53 -68) ➕ `internal/web/service/tgbot/tgbot_selfaction.go` (+97 -0) ➕ `internal/web/service/tgbot/tgbot_selfaction_test.go` (+128 -0) 📝 `internal/web/service/tgbot/tgbot_send.go` (+1 -13) 📝 `internal/web/translation/ar-EG.json` (+28 -2) 📝 `internal/web/translation/en-US.json` (+28 -2) 📝 `internal/web/translation/es-ES.json` (+28 -2) 📝 `internal/web/translation/fa-IR.json` (+28 -2) _...and 9 more files_ </details> ### 📄 Description ## Summary Part 2 of the Telegram bot split discussed in #6428, following #6518 (access levels and `/start` binding). A bound customer can now get their own links, QR codes and per-platform setup guide from the bot, without asking the admin. ## Why Today a customer who wants a config has to ask the operator for it, and the operator has to find the client and paste a link into a private chat. The panel already has the subscription URL, the share links and the QR codes, and `main` already lets a linked customer fetch all three — but only by tapping a button on one specific admin message, with no menu to navigate from and no instructions for what to do with the link afterwards. ## What changes - A customer menu (`client_menu`) reachable from the existing client commands, opening a keyboard of what the customer can do for themselves. - `client_one_link` / `link_one`: a picker that asks which of the client's links to send instead of returning all of them, which matters for a client attached to several inbounds. - `clientHeader`: every link page now names the config it is showing, with its expiry date and remaining quota, so a customer holding several can tell them apart. A config with no quota reads as unlimited rather than as zero left. - `guide_menu` / `guide_<platform>`: plain-text setup instructions for iPhone/iPad, Android, Windows, macOS and Linux, each naming a currently maintained app. Telegram only accepts `http`, `https` and `tg://` in link buttons, so these are text and not tap-through links. - The three copy-pasted client pickers in `tgbot_router.go` collapse into one `clientEmailPicker` call each, which drops ~60 lines of duplication. Builds on the helpers already in `main` rather than replacing them: `clientSubLinks` (in-process, so it does not need the subscription host to resolve here), `sendClientSubLinks`, `sendClientIndividualLinks`, `sendClientQRLinks`, `clientOwnedByTgUser` and the `chatUser` actor keying. **Outside `internal/web/service/tgbot/`:** - 13 locale files: 26 new keys, all translated. No new section; they extend the existing `tgbot.buttons` and `tgbot.messages` objects. **Not in this PR:** renewal requests and reminders, per-user notification settings, messaging the admin, the multi-bind ceiling, and the admin roster and bulk actions. Customer self-reset (credential rotation) is deliberately absent. A QR *chooser* that asks whether you want the subscription URL or a single individual link is also not here — it changes the existing QR behavior, so it should be reviewed on its own. ## Security - Every per-client callback re-checks ownership (`ownsClient`) before it acts. The email in callback data is only a claim, since the keyboard outlives the message it was sent with. - `link_one` carries an attacker-chosen index alongside the email. `clientSelfTarget` drops it before the check, and `splitClientLinkIndex` refuses a negative or unparsable index rather than reading past the slice. - Strangers still get only `/start` and `/id`, and groups are still ignored. Those paths are untouched. - Admin-only callbacks stay out of the customer allowlist. There is a test that pins `client_cancel`, `client_edit`, `set_bindmax`, `admin_settings` and `broadcast_confirm` against `isClientSelfCallback`. - Tests cover a foreign client being refused, the owner being served, an index smuggled into `link_one`, and an unbound account being told how to bind rather than shown a menu whose buttons would each refuse it. ## Type of change - [ ] Bug fix - [x] New feature - [ ] Refactoring (no behavior change) - [x] Documentation - [x] 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) - [x] Telegram bot ## How was this tested? - New unit tests: `tgbot_selfaction_test.go` (verb splitting, the index being stripped before the check, unusable input refused), `tgbot_configs_test.go` (link labels, out-of-range index, ownership both ways, header and quota labels, the configs step naming the config first), `tgbot_customer_test.go` (menu routing, admin callbacks outside the allowlist, unbound vs bound), `tgbot_guide_test.go` and `tgbot_guide_menu_test.go` (every platform resolves, unknown tags refused). - `go build ./...`, `go vet ./...`, `go test -shuffle=on -count=1 ./...`, `golangci-lint` (0 issues), `oxlint`, `tsc --noEmit` and the i18n dead-keys test all pass locally. No frontend source changed, so no frontend build was needed. - Not yet tested against a live panel with a real bot token; the customer taps above are covered by unit tests only. ## Screenshots / recordings The customer menu and one of the setup guides, from a test bot: - Menu: `My configs` → All links / One link / Subscription URL / QR codes / Setup guide - Guide: iPhone / Android / Windows / macOS / Linux, one tap each ## Breaking changes None. `main`'s existing `client_sub_links`, `client_individual_links` and `client_qr_links` callbacks keep their current behavior, their routing and their `clientOwnedByTgUser` check; this branch only adds new verbs alongside them. ## Checklist - [ ] 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. - [x] 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. --- <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:37 +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#6417
No description provided.