[PR #6604] [MERGED] fix(tgbot): scope the add-client wizard to the admin, not the chat #6372

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6604
Author: @sdhfsl
Created: 9/19/2026
Status: ✅ Merged
Merged: 9/26/2026
Merged by: @MHSanaei

Base: main ← Head: fix-bot-group-draft


📝 Commits (8)

  • 959e6fd fix(panel): accept 2FA codes from adjacent TOTP windows
  • f3096bb fix(panel): share TOTP skew tolerance with VerifyTwoFactorCode
  • 198ac75 Merge branch 'main' into main
  • acb0297 Merge branch 'MHSanaei:main' into main
  • 35b92a1 Merge branch 'MHSanaei:main' into main
  • 4687a85 fix(tgbot): scope the add-client wizard to the admin, not the chat
  • 27567af test(tgbot): pin the sender key the typed wizard steps read
  • 9a34cf3 Merge branch 'main' into fix-bot-group-draft

📊 Changes

7 files changed (+177 additions, -51 deletions)

View changed files

📝 internal/web/service/tgbot/tgbot.go (+42 -20)
📝 internal/web/service/tgbot/tgbot_add_client_expiry_test.go (+2 -2)
➕ internal/web/service/tgbot/tgbot_client_draft_per_admin_test.go (+102 -0)
📝 internal/web/service/tgbot/tgbot_client_draft_per_chat_test.go (+2 -2)
📝 internal/web/service/tgbot/tgbot_delete_after_test.go (+2 -2)
📝 internal/web/service/tgbot/tgbot_draft_render_test.go (+4 -4)
📝 internal/web/service/tgbot/tgbot_router.go (+23 -21)

📄 Description

Summary

Keys the add-client wizard's draft and conversation state by (chat, user) instead of by chat alone, so two admins in one group chat no longer fill in one client between them.

Why

Closes #6593.

clientDrafts and userStateStore were keyed by chat id only (internal/web/service/tgbot/tgbot.go). That fixed two admins in different chats, but in a group chat both admins are in the same chat, so they still reached one *clientDraft and one wizard step: the second admin's wizard opened pre-filled with the first one's email and limits, and whichever of them tapped a control last decided what the other created.

A private chat is unaffected — its chat id and user id are equal, so the new key matches what the chat id alone used to be. A message with no sender (a channel post) keys to user 0, an id no admin can hold.

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 regression test TestAddClientDraftIsPerAdminInGroupChat (internal/web/service/tgbot/tgbot_client_draft_per_admin_test.go): two admins tap add_client_to in the same group chat (same chat id, different From.ID) and then both render their card again.

Before the change it fails with the defect the issue describes:

tgbot_client_draft_per_admin_test.go:53: admin A's card shows email "ix3orqd7",
want its own "pdenag8i" from admin B's draft

After it passes, and it also pins the second half of the issue — the step each admin is on is their own: after admin A taps add_client_ch_default_email, A is awaiting_email and B has no step at all.

Commands run:

  • go test ./internal/web/service/tgbot/ — pass
  • go test -race -shuffle=on -count=1 ./internal/web/service/tgbot/ — pass, no data race
  • gofmt -l internal/web/service/tgbot/ — clean
  • go build ./... — passes for every package except the root and internal/web, which need frontend/dist (gitignored). This is unrelated to the change and reproduces on a clean main in the same checkout.
  • go test ./... — the tgbot package and internal/web/service pass. On my Windows box five packages fail for environment reasons: root and internal/web (all:dist: no matching files found), internal/amneziawgnet (tunnel tests needing real network), internal/crypto/nodetoken (TestFileKeySourceRejectsLoosePerms — no POSIX permission bits), internal/logger and internal/web/service/panel (one timing and one env-var test each). I re-ran each of these on a clean checkout without this change and they fail identically, so none of them is a regression from this PR.

Existing tests that used the old key were updated to the new one (tgbot_add_client_expiry_test.go, tgbot_client_draft_per_chat_test.go, tgbot_delete_after_test.go, tgbot_draft_render_test.go); no assertions were weakened.

Screenshots / recordings

N/A — no UI change.

Breaking changes

None. The wizard's behavior in private chats and the callback data are unchanged.

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. (see note above on the Windows-only environment failures)
  • For frontend changes: npm run lint, npm run typecheck, and npm run build pass. — N/A, no frontend change.
  • I updated the Wiki / README / API docs if user-facing behavior changed. — N/A
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

Scope note

The issue also mentions that both admins in a group still see and can tap the same card, so either admin's tap re-renders the other's inline keyboard. This PR does not change that: making the card itself per-admin means deciding where a group's wizard card should live (e.g. moving the flow to a private chat), which is a UX decision the issue author explicitly left open. The change here is limited to the draft and the step, which is the scope the issue's Notes describe.


🔄 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/6604 **Author:** [@sdhfsl](https://github.com/sdhfsl) **Created:** 9/19/2026 **Status:** ✅ Merged **Merged:** 9/26/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix-bot-group-draft` --- ### 📝 Commits (8) - [`959e6fd`](https://github.com/MHSanaei/3x-ui/commit/959e6fd62b07efd1038d70ecc18c3bc59ce2e3c2) fix(panel): accept 2FA codes from adjacent TOTP windows - [`f3096bb`](https://github.com/MHSanaei/3x-ui/commit/f3096bb3c1e3091647101d80939da52ab054b21d) fix(panel): share TOTP skew tolerance with VerifyTwoFactorCode - [`198ac75`](https://github.com/MHSanaei/3x-ui/commit/198ac751d71b3b063a61b59efed80d50444febbf) Merge branch 'main' into main - [`acb0297`](https://github.com/MHSanaei/3x-ui/commit/acb0297c9b95da9d4157e751fe2789e851b34746) Merge branch 'MHSanaei:main' into main - [`35b92a1`](https://github.com/MHSanaei/3x-ui/commit/35b92a16d3770ee1c0351a1f5db75b635788fa32) Merge branch 'MHSanaei:main' into main - [`4687a85`](https://github.com/MHSanaei/3x-ui/commit/4687a854d353a81bf758a2512b4dc2fae7d85f6b) fix(tgbot): scope the add-client wizard to the admin, not the chat - [`27567af`](https://github.com/MHSanaei/3x-ui/commit/27567aff5973a466a45ab260ea9cd82b9a23636b) test(tgbot): pin the sender key the typed wizard steps read - [`9a34cf3`](https://github.com/MHSanaei/3x-ui/commit/9a34cf3c04626e60c65dda0d90d847f22958ef88) Merge branch 'main' into fix-bot-group-draft ### 📊 Changes **7 files changed** (+177 additions, -51 deletions) <details> <summary>View changed files</summary> 📝 `internal/web/service/tgbot/tgbot.go` (+42 -20) 📝 `internal/web/service/tgbot/tgbot_add_client_expiry_test.go` (+2 -2) ➕ `internal/web/service/tgbot/tgbot_client_draft_per_admin_test.go` (+102 -0) 📝 `internal/web/service/tgbot/tgbot_client_draft_per_chat_test.go` (+2 -2) 📝 `internal/web/service/tgbot/tgbot_delete_after_test.go` (+2 -2) 📝 `internal/web/service/tgbot/tgbot_draft_render_test.go` (+4 -4) 📝 `internal/web/service/tgbot/tgbot_router.go` (+23 -21) </details> ### 📄 Description ## Summary Keys the add-client wizard's draft and conversation state by `(chat, user)` instead of by chat alone, so two admins in one group chat no longer fill in one client between them. ## Why Closes #6593. `clientDrafts` and `userStateStore` were keyed by chat id only (`internal/web/service/tgbot/tgbot.go`). That fixed two admins in *different* chats, but in a group chat both admins are in the same chat, so they still reached one `*clientDraft` and one wizard step: the second admin's wizard opened pre-filled with the first one's email and limits, and whichever of them tapped a control last decided what the other created. A private chat is unaffected — its chat id and user id are equal, so the new key matches what the chat id alone used to be. A message with no sender (a channel post) keys to user 0, an id no admin can hold. ## Type of change - [x] 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) - [x] Telegram bot ## How was this tested? New regression test `TestAddClientDraftIsPerAdminInGroupChat` (`internal/web/service/tgbot/tgbot_client_draft_per_admin_test.go`): two admins tap `add_client_to` in the same group chat (same chat id, different `From.ID`) and then both render their card again. Before the change it fails with the defect the issue describes: ``` tgbot_client_draft_per_admin_test.go:53: admin A's card shows email "ix3orqd7", want its own "pdenag8i" from admin B's draft ``` After it passes, and it also pins the second half of the issue — the step each admin is on is their own: after admin A taps `add_client_ch_default_email`, A is `awaiting_email` and B has no step at all. Commands run: - `go test ./internal/web/service/tgbot/` — pass - `go test -race -shuffle=on -count=1 ./internal/web/service/tgbot/` — pass, no data race - `gofmt -l internal/web/service/tgbot/` — clean - `go build ./...` — passes for every package except the root and `internal/web`, which need `frontend/dist` (gitignored). This is unrelated to the change and reproduces on a clean `main` in the same checkout. - `go test ./...` — the tgbot package and `internal/web/service` pass. On my Windows box five packages fail for environment reasons: root and `internal/web` (`all:dist: no matching files found`), `internal/amneziawgnet` (tunnel tests needing real network), `internal/crypto/nodetoken` (`TestFileKeySourceRejectsLoosePerms` — no POSIX permission bits), `internal/logger` and `internal/web/service/panel` (one timing and one env-var test each). I re-ran each of these on a clean checkout without this change and they fail identically, so none of them is a regression from this PR. Existing tests that used the old key were updated to the new one (`tgbot_add_client_expiry_test.go`, `tgbot_client_draft_per_chat_test.go`, `tgbot_delete_after_test.go`, `tgbot_draft_render_test.go`); no assertions were weakened. ## Screenshots / recordings N/A — no UI change. ## Breaking changes None. The wizard's behavior in private chats and the callback data are unchanged. ## 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. *(see note above on the Windows-only environment failures)* - [ ] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. — N/A, no frontend change. - [ ] I updated the Wiki / README / API docs if user-facing behavior changed. — N/A - [x] My commits follow the project's existing message style. - [x] I have no unrelated changes mixed into this PR. ## Scope note The issue also mentions that both admins in a group still see and can tap the *same* card, so either admin's tap re-renders the other's inline keyboard. This PR does not change that: making the card itself per-admin means deciding where a group's wizard card should live (e.g. moving the flow to a private chat), which is a UX decision the issue author explicitly left open. The change here is limited to the draft and the step, which is the scope the issue's Notes describe. --- <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:18 +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#6372
No description provided.