[PR #5945] [MERGED] feat(api): add GET endpoint to look up clients by Telegram ID #6035

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5945
Author: @kimfom01
Created: 7/13/2026
Status: ✅ Merged
Merged: 7/28/2026
Merged by: @MHSanaei

Base: main ← Head: add-get-by-tgid-endpoint


📝 Commits (10+)

  • bf1e664 feat(api): add GET endpoint to look up clients by Telegram ID
  • 5131c4b fix: guard tgId=0 sentinel, index tg_id, deduplicate enrichment in getByTgId
  • 46059be refactor(api): move Telegram client lookup under /get/tgId/:tgId
  • ff8cd7c Merge branch 'main' into add-get-by-tgid-endpoint
  • 0586c9d Merge branch 'main' into add-get-by-tgid-endpoint
  • c0460af Merge branch 'main' into add-get-by-tgid-endpoint
  • db2816a Merge branch 'main' into add-get-by-tgid-endpoint
  • 9c2059b Merge branch 'main' into add-get-by-tgid-endpoint
  • 1c07282 Merge branch 'main' into add-get-by-tgid-endpoint
  • dfde23a Merge branch 'main' into add-get-by-tgid-endpoint

📊 Changes

7 files changed (+200 additions, -12 deletions)

View changed files

📝 frontend/public/openapi.json (+41 -0)
📝 frontend/src/pages/api-docs/endpoints.ts (+10 -0)
📝 internal/database/db.go (+14 -0)
📝 internal/database/model/model.go (+1 -1)
📝 internal/web/controller/client.go (+44 -11)
📝 internal/web/service/client_lookup.go (+10 -0)
➕ internal/web/service/client_lookup_test.go (+80 -0)

📄 Description

Summary

Add a REST endpoint to look up clients by Telegram user ID, enabling Telegram-bot-driven integrations to resolve clients without having to scan all inbounds client-side.

Why

There was no way to query clients by tgId over HTTP, the only consumer was the internal Telegram bot via InboundService.GetClientTrafficTgBot. Migrators from other panels (e.g. Remnawave) whose bot workflows rely on tgId lookups were blocked. Closes #5879

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?

  • Service-layer unit test (internal/web/service/client_lookup_test.go): 4 subtests covering multiple clients sharing one tgId, a single client, tgId=0, and nonexistent tgId, all against a throwaway SQLite DB via setupBulkDB(t).
  • Route-documentation test (TestAPIRoutesDocumented): confirms the new route appears in endpoints.ts and the generated openapi.json.
  • Manual curl: GET /panel/api/clients/getByTgId/1234567890 returns {"success":true,"obj":[...]} with the same shape as get/:email but wrapped in an array.

Breaking changes

None. Purely additive; no existing route or config changed.

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/5945 **Author:** [@kimfom01](https://github.com/kimfom01) **Created:** 7/13/2026 **Status:** ✅ Merged **Merged:** 7/28/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `add-get-by-tgid-endpoint` --- ### 📝 Commits (10+) - [`bf1e664`](https://github.com/MHSanaei/3x-ui/commit/bf1e664467a58f9a169d0b0e51d0fb4815503ccb) feat(api): add GET endpoint to look up clients by Telegram ID - [`5131c4b`](https://github.com/MHSanaei/3x-ui/commit/5131c4b76157a5cea926e0c1fda6e8cd84a5a499) fix: guard tgId=0 sentinel, index tg_id, deduplicate enrichment in getByTgId - [`46059be`](https://github.com/MHSanaei/3x-ui/commit/46059bed5e7b857dc07bf79bf16df82e8996046c) refactor(api): move Telegram client lookup under /get/tgId/:tgId - [`ff8cd7c`](https://github.com/MHSanaei/3x-ui/commit/ff8cd7cea709151d1ef5287f183bb68b712c53d2) Merge branch 'main' into add-get-by-tgid-endpoint - [`0586c9d`](https://github.com/MHSanaei/3x-ui/commit/0586c9d0153955fd2bab93fda4fa286996039857) Merge branch 'main' into add-get-by-tgid-endpoint - [`c0460af`](https://github.com/MHSanaei/3x-ui/commit/c0460afddc33b0c5d4fd290cab20c1dd0a003be8) Merge branch 'main' into add-get-by-tgid-endpoint - [`db2816a`](https://github.com/MHSanaei/3x-ui/commit/db2816a7c575bbaeb0cc9525fb12516d9804be87) Merge branch 'main' into add-get-by-tgid-endpoint - [`9c2059b`](https://github.com/MHSanaei/3x-ui/commit/9c2059b414f3715d094d0c790c35aeed7b7b26b8) Merge branch 'main' into add-get-by-tgid-endpoint - [`1c07282`](https://github.com/MHSanaei/3x-ui/commit/1c072826b8c6758ec986d9bdc35b22fdc01cd2b9) Merge branch 'main' into add-get-by-tgid-endpoint - [`dfde23a`](https://github.com/MHSanaei/3x-ui/commit/dfde23a7b9a476f43972874f3b405bc3c7786f1f) Merge branch 'main' into add-get-by-tgid-endpoint ### 📊 Changes **7 files changed** (+200 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `frontend/public/openapi.json` (+41 -0) 📝 `frontend/src/pages/api-docs/endpoints.ts` (+10 -0) 📝 `internal/database/db.go` (+14 -0) 📝 `internal/database/model/model.go` (+1 -1) 📝 `internal/web/controller/client.go` (+44 -11) 📝 `internal/web/service/client_lookup.go` (+10 -0) ➕ `internal/web/service/client_lookup_test.go` (+80 -0) </details> ### 📄 Description ## Summary Add a REST endpoint to look up clients by Telegram user ID, enabling Telegram-bot-driven integrations to resolve clients without having to scan all inbounds client-side. ## Why There was no way to query clients by tgId over HTTP, the only consumer was the internal Telegram bot via InboundService.GetClientTrafficTgBot. Migrators from other panels (e.g. Remnawave) whose bot workflows rely on tgId lookups were blocked. Closes #5879 ## Type of change - [ ] Bug fix - [x] New feature - [ ] Refactoring (no behavior change) - [ ] Documentation - [ ] Tests only - [ ] Build / CI / tooling - [ ] Other ## Areas affected - [ ] 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) - [ ] Telegram bot ## How was this tested? - Service-layer unit test (internal/web/service/client_lookup_test.go): 4 subtests covering multiple clients sharing one tgId, a single client, tgId=0, and nonexistent tgId, all against a throwaway SQLite DB via setupBulkDB(t). - Route-documentation test (TestAPIRoutesDocumented): confirms the new route appears in endpoints.ts and the generated openapi.json. - Manual curl: GET /panel/api/clients/getByTgId/1234567890 returns {"success":true,"obj":[...]} with the same shape as get/:email but wrapped in an array. ## Breaking changes None. Purely additive; no existing route or config changed. ## 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. - [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:05:54 +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#6035
No description provided.