mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6518] [MERGED] feat(tgbot): access levels and /start account binding #6325
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#6325
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/6518
Author: @pcxzs
Created: 9/14/2026
Status: ✅ Merged
Merged: 9/27/2026
Merged by: @MHSanaei
Base:
main← Head:feat/tgbot-access-binding📝 Commits (6)
83447c2feat(tgbot): gate the bot behind three user levels41200f1feat(tgbot): bind Telegram accounts through /start deep links750e154fix(tgbot): harden invite claims after reviewc6a08b2Merge remote-tracking branch 'origin/main' into pr/6518224a715fix(tgbot): answer group chats again and make the claim race test bite34b0a7adocs(tgbot): document access levels and invite links📊 Changes
25 files changed (+801 additions, -11 deletions)
View changed files
📝
docs/content/docs/en/operations/telegram-bot.mdx(+11 -2)📝
docs/content/docs/fa/operations/telegram-bot.mdx(+11 -2)📝
docs/content/docs/ru/operations/telegram-bot.mdx(+12 -2)📝
docs/content/docs/zh/operations/telegram-bot.mdx(+9 -2)📝
frontend/src/pages/clients/ClientFormModal.tsx(+4 -1)📝
internal/web/service/client_lookup.go(+11 -0)📝
internal/web/service/tgbot/tgbot_client.go(+1 -0)➕
internal/web/service/tgbot/tgbot_invite.go(+237 -0)➕
internal/web/service/tgbot/tgbot_invite_test.go(+221 -0)➕
internal/web/service/tgbot/tgbot_level.go(+72 -0)➕
internal/web/service/tgbot/tgbot_level_test.go(+100 -0)📝
internal/web/service/tgbot/tgbot_router.go(+21 -2)📝
internal/web/translation/ar-EG.json(+7 -0)📝
internal/web/translation/en-US.json(+7 -0)📝
internal/web/translation/es-ES.json(+7 -0)📝
internal/web/translation/fa-IR.json(+7 -0)📝
internal/web/translation/id-ID.json(+7 -0)📝
internal/web/translation/ja-JP.json(+7 -0)📝
internal/web/translation/pt-BR.json(+7 -0)📝
internal/web/translation/ru-RU.json(+7 -0)...and 5 more files
📄 Description
Summary
Gives the Telegram bot access levels and a way for a customer to link their own Telegram account to their client, via a
/startdeep link built from the client's subId. This is the first part of #6428, split as suggested there: access levels and account binding first, standing on their own against currentmain.Why
Any Telegram account that finds the bot is treated the same as a customer an admin has bound. Binding is also manual: the customer sends
/id, and the admin copies the ChatID into the client. Both have to change before the bot can face customers, and everything else in #6428 builds on them.What changed
Access levels. Each update resolves to stranger, client or admin (
tgbot_level.go):/startand/id, nothing else./startanswers with the existingaskToAddUserIdtext (their ChatID), so manual binding still works. A stranger's callback taps are answered and dropped./start /help /status /id /usage.tg_idcolumn of the clients table, so no update, a stranger's included, triggers a scan of the inbound JSON. Ownership of a specific client is still #6489'sclientOwnedByTgUser, unchanged.Private chats only. The bot ignores updates from groups and channels. Authorization keys on the sender, but wizard state keys on the chat, and those are the same identity only in a private chat. A button tapped in a group is still answered so it stops spinning, and each ignored chat is logged once so an operator can see why the bot is quiet there.
Binding. The admin client card gets an Invite Link button next to Set Telegram User. It produces
https://t.me/<bot>?start=<payload>, and the first account to open it is bound through the existingSetClientTelegramUserID:A-Za-z0-9_-(up to 64 characters) and a subId may contain#,&or non-ASCII. A subId too long to fit is refused with a log line rather than truncated./startwithout a payload is not counted.Whether the subId should double as the invite token at all is an open question for review; see the comment below.
Scope
tgbot/:ClientService.GetRecordsBySubIDinclient_lookup.go.tooltipprop on the Subscription ID field inClientFormModal.tsx.Type of change
Areas affected
How was this tested?
New tests:
tgbot_level_test.go:levelOfagainst a seeded binding.gateCommand: a stranger gets no reply, a client gets "unknown command".gateCallback: a stranger's forged tap is answered and dropped.tgbot_invite_test.go:#,&,?and non-ASCII, plus the 64-character limit.These reuse the existing
staleButtonServer/newLinksCallbackTgbotfixtures.Checks run:
gofmt,go vet ./...,golangci-lint,go test -race -shuffle=on ./internal/web/service/...,go test -shuffle=on ./....npm run typecheck,npm run lint(oxlint) andoxfmt --check.Breaking changes
None for bound customers or admins in private chats. Two visible changes:
/start(showing their ChatID) and/id. Previously they could open the customer menu, whose every button answered "configuration not found".Checklist
go build ./...and the test suite pass locally.npm run lint,npm run typecheck, andnpm run buildpass.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.