mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #5805] [Bug]: Telegram bot usage lookup fails when tgId JSON is compacted #4035
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#4035
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?
Originally created by @menzhu on GitHub (Jul 5, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5805
Describe the bug
When a client has a Telegram user ID, the Telegram bot usage query can fail after the inbound settings JSON is compacted during node sync/import.
The client row and traffic row exist, but the bot returns no result because the lookup only matches
"tgId": 123with a space after the colon. If the JSON contains"tgId":123, the inbound is not found.How to reproduce the problem
Configure a client with a Telegram user ID.
Sync/import or otherwise save the inbound so
inbounds.settingscontains compact JSON like:Make sure the client and traffic rows exist, for example
clients.tg_id = 123456789andclient_traffics.email = 'client-a'.Send a usage query to the Telegram bot from that Telegram user.
The bot replies that no configuration was found. Logs show:
Expected behavior
The Telegram bot should find the client by Telegram user ID regardless of JSON whitespace/serialization style.
Ideally the query should use the normalized
clients.tg_idcolumn or SQLite JSON functions, instead of matching a formatted JSON string.Actual behavior
The bot fails to find the inbound when
inbounds.settingscontains compact JSON:The current code appears to require a space after the colon:
That pattern matches
"tgId": 123456789but not"tgId":123456789. Reformatting the JSON to include the space makes the bot work immediately.Relevant logs
Screenshots
Sanitized verification:
Workaround tested: reformat
settingsso"tgId":123456789becomes"tgId": 123456789; after that the Telegram bot can return the usage data.3x-ui version
3.4.2 (Docker image ghcr.io/mhsanaei/3x-ui:latest)
Xray-core version
26.6.27
How did you install 3x-ui?
install.sh script
Operating system
Debian 12 (bookworm), Docker
Which parts of the panel are affected?
No response
Browser (only if it is a UI bug)
Not browser-specific; reproduced via Telegram bot and SQLite data
Is the panel behind a reverse proxy or CDN?
None
Before submitting
@github-actions[bot] commented on GitHub (Jul 5, 2026):
Confirmed in the source.
GetClientTrafficTgBotininternal/web/service/inbound_traffic.go(line 843) narrows candidate inbounds with:The
%%"tgId": %d%%pattern requires a literal space after the colon, so it does not match compact JSON such as"tgId":123456789. Since this is only a pre-filter — for each matched inbound the code does callGetClients(inbound)(internal/web/service/inbound.go:424, plainjson.Unmarshal) and then exact-comparesclient.TgID == tgId— an inbound that fails the LIKE step is never even fetched, so the later exact match never gets a chance to run. This is called from three places ininternal/web/service/tgbot/(tgbot_router.go,tgbot_client.go,tgbot_report.go), so any of those bot flows (usage query, client menu, scheduled report) can hit it wheneverinbounds.settingshas been serialized without the space, e.g. after node sync/import as described.Your suggestion to use the normalized column/JSON functions instead of a formatted-string match is consistent with how the codebase already avoids this class of bug elsewhere:
model.ClientRecord(internal/database/model/model.go:620, tableclients) already stores a normalizedtg_idcolumn (gorm:"column:tg_id"), populated from the sameClient.TgIDfield.GetAllEmails(internal/web/service/inbound.go:445) already queriesinbounds.settingsvia driver-portable JSON helpers (database.JSONClientsFromInbound()/JSONFieldText,internal/database/dialect.go) —JSON_EXTRACT/JSON_EACHon SQLite,jsonb_array_elements/->>on Postgres — instead of a LIKE-on-formatted-JSON pattern.So there is existing precedent for fixing this either by querying
clients.tg_iddirectly (if that table is reliably kept in sync for this lookup path) or by switching the inbound pre-filter to the same JSON-function helpers used byGetAllEmails, rather than widening the LIKE pattern to tolerate both spacing styles.I've labeled this a confirmed bug; no further information is needed to reproduce or diagnose it.
This reply was generated automatically. A maintainer may follow up.