[PR #6999] [MERGED] fix(tgbot): send fresh screens for typed commands #6570

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6999
Author: @HamedSanaei
Created: 10/28/2026
Status: ✅ Merged
Merged: 11/3/2026
Merged by: @MHSanaei

Base: main ← Head: codex/fix-telegram-command-screens


📝 Commits (3)

  • 35bc7db fix(tgbot): send fresh screens for typed commands
  • 411a16f fix(tgbot): retire keyboards when old menus cannot be deleted
  • c08b8bf Merge remote-tracking branch 'origin/main' into pr/6999

📊 Changes

9 files changed (+207 additions, -77 deletions)

View changed files

➕ internal/web/service/tgbot/command_screen_test.go (+142 -0)
📝 internal/web/service/tgbot/screen.go (+27 -14)
📝 internal/web/service/tgbot/screen_legacy.go (+2 -2)
📝 internal/web/service/tgbot/screen_views.go (+7 -7)
📝 internal/web/service/tgbot/screens_test.go (+8 -39)
📝 internal/web/service/tgbot/tgbot_client.go (+3 -3)
📝 internal/web/service/tgbot/tgbot_reports_usage_test.go (+4 -4)
📝 internal/web/service/tgbot/tgbot_router.go (+7 -7)
📝 internal/web/service/tgbot/tgbot_send.go (+7 -1)

📄 Description

Summary

Send a fresh screen for typed Telegram commands instead of editing the remembered menu message. Keep callback navigation on the existing edit-first path. After a successful replacement, delete the old menu or remove its keyboard if deletion fails.

Why

Closes #6997.

The command handler draws a screen and then removes the incoming command. Previously, every screen render first tried to edit the remembered message ID. A successful edit therefore did not guarantee a newly visible response when the user returned after clearing chat history.

Commands now explicitly request a new message through the shared renderer. The delivery choice is an argument passed through the existing views, not mutable bot-wide or chat-wide mode state. This covers admin/client /start, admin /status, admin/client /usage, and admin /clearall; callbacks retain their normal edit behavior. Notices, authorization, client ownership checks, menu content, artwork and active-menu keyboards are unchanged.

Telegram restricts message deletion to messages less than 48 hours old. If deletion fails after the new screen is sent, retire the previous menu's buttons through the existing reply-markup edit helper, with a bounded timeout. Cleanup is best effort: even if both cleanup calls fail, keep the newly sent screen tracked. Never delete or strip the previous menu when sending its replacement fails.

Related: #6968 addresses rejected cached artwork. This PR addresses command delivery even when editing the old message succeeds; it does not include the artwork-recovery changes.

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?

The new regressions use real temporary database records and an httptest Telegram API server that accepts edits of the remembered message.

  • RED: all eight command cases produced only an edit and command deletion, with no new menu. The failed-send preservation regression also failed against the original code.
  • GREEN: commands send a new menu before retiring the previous one and deleting the command; subsequent callbacks edit the new menu. Admin/client /start is repeated to cover another cleared-history/re-entry cycle.
  • A failed Telegram screen send preserves the previous tracked menu and does not delete it or strip its keyboard.
  • A separate RED/GREEN regression covers Telegram rejecting deletion of the previous menu: remove only its keyboard after the new send, and retain the new screen even if keyboard cleanup also fails. This addresses the LOW finding in the initial automated review.
  • The old test requiring the second /start to edit the existing message is replaced by these stronger command regressions. Existing initial-start and default edit-first renderer tests remain.
  • Existing client-usage authorization tests keep their assertions and explicitly select callback-style delivery after the private helper signature change.

Validation:

  • Targeted command regressions and the complete Telegram package: passed.
  • go vet -p=2 ./...: passed.
  • make verify: passed, including all Go tests/build, lint/typecheck/format, 2,018 frontend tests, production and Storybook builds, generation checks and published OpenAPI consistency.
  • make race: passed across Go packages.
  • All 11 CI checks passed on final head 411a16f6, including race, fuzz smoke, both PostgreSQL suites and node end-to-end tests. The initial automated review covered 35bc7dba; its one LOW is addressed in the follow-up, with no automatic re-review on synchronization.

Manual reproduction:

  1. Open an authorized private bot chat and use /start to establish a menu.
  2. Clear the conversation history, reopen it, and press Start again.
  3. Confirm a newly sent menu remains after the command is removed.
  4. Use its buttons and confirm navigation edits that menu.
  5. Repeat with an authorized client account and the other screen-producing commands.

No live Telegram account or bot was contacted. The tests model the successful-old-edit condition; Telegram clients' history-deletion visibility was not validated directly.

Breaking changes

None. No API route, database schema, setting, translation, dependency, panel UI or Xray runtime changes. Typed screen-producing commands intentionally get a new message ID; the previous menu is retired only after the new send succeeds.

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. No frontend changes; these checks still ran.
  • I updated the Wiki / README / API docs if user-facing behavior changed. N/A: existing commands and controls are preserved; the renderer comments are updated.
  • 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/6999 **Author:** [@HamedSanaei](https://github.com/HamedSanaei) **Created:** 10/28/2026 **Status:** ✅ Merged **Merged:** 11/3/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `codex/fix-telegram-command-screens` --- ### 📝 Commits (3) - [`35bc7db`](https://github.com/MHSanaei/3x-ui/commit/35bc7dbad36e16f03198307f107e2a2c80788c9d) fix(tgbot): send fresh screens for typed commands - [`411a16f`](https://github.com/MHSanaei/3x-ui/commit/411a16f6cda66b396b0f70b78c587d683f6501b4) fix(tgbot): retire keyboards when old menus cannot be deleted - [`c08b8bf`](https://github.com/MHSanaei/3x-ui/commit/c08b8bfc1ec3fb3f5007cc085978ebc43300b4b8) Merge remote-tracking branch 'origin/main' into pr/6999 ### 📊 Changes **9 files changed** (+207 additions, -77 deletions) <details> <summary>View changed files</summary> ➕ `internal/web/service/tgbot/command_screen_test.go` (+142 -0) 📝 `internal/web/service/tgbot/screen.go` (+27 -14) 📝 `internal/web/service/tgbot/screen_legacy.go` (+2 -2) 📝 `internal/web/service/tgbot/screen_views.go` (+7 -7) 📝 `internal/web/service/tgbot/screens_test.go` (+8 -39) 📝 `internal/web/service/tgbot/tgbot_client.go` (+3 -3) 📝 `internal/web/service/tgbot/tgbot_reports_usage_test.go` (+4 -4) 📝 `internal/web/service/tgbot/tgbot_router.go` (+7 -7) 📝 `internal/web/service/tgbot/tgbot_send.go` (+7 -1) </details> ### 📄 Description ## Summary Send a fresh screen for typed Telegram commands instead of editing the remembered menu message. Keep callback navigation on the existing edit-first path. After a successful replacement, delete the old menu or remove its keyboard if deletion fails. ## Why Closes #6997. The command handler draws a screen and then removes the incoming command. Previously, every screen render first tried to edit the remembered message ID. A successful edit therefore did not guarantee a newly visible response when the user returned after clearing chat history. Commands now explicitly request a new message through the shared renderer. The delivery choice is an argument passed through the existing views, not mutable bot-wide or chat-wide mode state. This covers admin/client `/start`, admin `/status`, admin/client `/usage`, and admin `/clearall`; callbacks retain their normal edit behavior. Notices, authorization, client ownership checks, menu content, artwork and active-menu keyboards are unchanged. Telegram [restricts message deletion](https://core.telegram.org/bots/api#deletemessage) to messages less than 48 hours old. If deletion fails after the new screen is sent, retire the previous menu's buttons through the existing [reply-markup edit](https://core.telegram.org/bots/api#editmessagereplymarkup) helper, with a bounded timeout. Cleanup is best effort: even if both cleanup calls fail, keep the newly sent screen tracked. Never delete or strip the previous menu when sending its replacement fails. Related: #6968 addresses rejected cached artwork. This PR addresses command delivery even when editing the old message succeeds; it does not include the artwork-recovery changes. ## 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? The new regressions use real temporary database records and an `httptest` Telegram API server that accepts edits of the remembered message. - RED: all eight command cases produced only an edit and command deletion, with no new menu. The failed-send preservation regression also failed against the original code. - GREEN: commands send a new menu before retiring the previous one and deleting the command; subsequent callbacks edit the new menu. Admin/client `/start` is repeated to cover another cleared-history/re-entry cycle. - A failed Telegram screen send preserves the previous tracked menu and does not delete it or strip its keyboard. - A separate RED/GREEN regression covers Telegram rejecting deletion of the previous menu: remove only its keyboard after the new send, and retain the new screen even if keyboard cleanup also fails. This addresses the LOW finding in the initial automated review. - The old test requiring the second `/start` to edit the existing message is replaced by these stronger command regressions. Existing initial-start and default edit-first renderer tests remain. - Existing client-usage authorization tests keep their assertions and explicitly select callback-style delivery after the private helper signature change. Validation: - Targeted command regressions and the complete Telegram package: passed. - `go vet -p=2 ./...`: passed. - `make verify`: passed, including all Go tests/build, lint/typecheck/format, 2,018 frontend tests, production and Storybook builds, generation checks and published OpenAPI consistency. - `make race`: passed across Go packages. - [All 11 CI checks](https://github.com/MHSanaei/3x-ui/actions/runs/40731115525) passed on final head `411a16f6`, including race, fuzz smoke, both PostgreSQL suites and node end-to-end tests. The initial automated review covered `35bc7dba`; its one LOW is addressed in the follow-up, with no automatic re-review on synchronization. Manual reproduction: 1. Open an authorized private bot chat and use `/start` to establish a menu. 2. Clear the conversation history, reopen it, and press Start again. 3. Confirm a newly sent menu remains after the command is removed. 4. Use its buttons and confirm navigation edits that menu. 5. Repeat with an authorized client account and the other screen-producing commands. No live Telegram account or bot was contacted. The tests model the successful-old-edit condition; Telegram clients' history-deletion visibility was not validated directly. ## Breaking changes None. No API route, database schema, setting, translation, dependency, panel UI or Xray runtime changes. Typed screen-producing commands intentionally get a new message ID; the previous menu is retired only after the new send succeeds. ## 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. - [x] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. No frontend changes; these checks still ran. - [x] I updated the Wiki / README / API docs if user-facing behavior changed. N/A: existing commands and controls are preserved; the renderer comments are updated. - [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 changed title from [PR #6999] fix(tgbot): send fresh screens for typed commands to [PR #6999] [MERGED] fix(tgbot): send fresh screens for typed commands 2026-11-07 14:34:02 +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#6570
No description provided.