[GH-ISSUE #5851] [Bug]: Telegram Bot Returns Incorrect Subscription Link Using Host Name Instead of Domain #4064

Closed
opened 2026-10-31 20:36:53 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @parsa-fathi on GitHub (Jul 7, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5851

Describe the bug

Description:

When requesting a client's subscription link through the Telegram bot in 3x-ui, the generated URL is always incorrect.

Instead of using the configured domain name, the bot uses the server's host name as the domain part of the subscription URL. As a result, the generated subscription link becomes invalid or inaccessible for clients.

Steps to Reproduce:

  1. Configure a panel with a valid domain name.
  2. Create a client/inbound normally.
  3. Open the 3x-ui Telegram bot.
  4. Request the subscription link for the client.
  5. Check the generated subscription URL.

Expected Behavior:
The Telegram bot should generate the subscription link using the configured domain name, matching the link shown in the panel.

Actual Behavior:
The Telegram bot generates the subscription link using the server host name instead of the configured domain name.

Impact:
Users receive incorrect subscription links from the Telegram bot and may be unable to import or update their configurations until the link is manually corrected.

Image

How to reproduce the problem

  1. Configure a panel with a valid domain name.
  2. Create a client/inbound normally.
  3. Open the 3x-ui Telegram bot.
  4. Request the subscription link for the client.
  5. Check the generated subscription URL.

Expected behavior

No response

Actual behavior

No response

Relevant logs


Screenshots

No response

3x-ui version

3.4.2

Xray-core version

No response

How did you install 3x-ui?

install.sh script

Operating system

Ubuntu26

Which parts of the panel are affected?

No response

Browser (only if it is a UI bug)

No response

Is the panel behind a reverse proxy or CDN?

None

Before submitting

  • I searched existing issues and this bug has not been reported.
  • I am running the latest released version of 3x-ui (or have verified the bug still exists on it).
  • This bug report is written in English.
  • I have redacted any sensitive data (tokens, real domains, client UUIDs).
Originally created by @parsa-fathi on GitHub (Jul 7, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5851 ### Describe the bug **Description:** When requesting a client's subscription link through the Telegram bot in 3x-ui, the generated URL is always incorrect. Instead of using the configured domain name, the bot uses the server's host name as the domain part of the subscription URL. As a result, the generated subscription link becomes invalid or inaccessible for clients. **Steps to Reproduce:** 1. Configure a panel with a valid domain name. 2. Create a client/inbound normally. 3. Open the 3x-ui Telegram bot. 4. Request the subscription link for the client. 5. Check the generated subscription URL. **Expected Behavior:** The Telegram bot should generate the subscription link using the configured domain name, matching the link shown in the panel. **Actual Behavior:** The Telegram bot generates the subscription link using the server host name instead of the configured domain name. **Impact:** Users receive incorrect subscription links from the Telegram bot and may be unable to import or update their configurations until the link is manually corrected. <img width="468" height="134" alt="Image" src="https://github.com/user-attachments/assets/4e289386-770b-47fd-94cc-6f0bb671e674" /> ### How to reproduce the problem 1. Configure a panel with a valid domain name. 2. Create a client/inbound normally. 3. Open the 3x-ui Telegram bot. 4. Request the subscription link for the client. 5. Check the generated subscription URL. ### Expected behavior _No response_ ### Actual behavior _No response_ ### Relevant logs ```shell ``` ### Screenshots _No response_ ### 3x-ui version 3.4.2 ### Xray-core version _No response_ ### How did you install 3x-ui? install.sh script ### Operating system Ubuntu26 ### Which parts of the panel are affected? _No response_ ### Browser (only if it is a UI bug) _No response_ ### Is the panel behind a reverse proxy or CDN? None ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this bug has not been reported. - [x] I am running the latest released version of 3x-ui (or have verified the bug still exists on it). - [x] This bug report is written in English. - [x] I have redacted any sensitive data (tokens, real domains, client UUIDs).
bsakaguchi 2026-10-31 20:36:53 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@github-actions[bot] commented on GitHub (Jul 7, 2026):

Confirmed as a bug in the Telegram bot's link-building logic, not in the panel itself.

Root cause: buildSubscriptionURLs in internal/web/service/tgbot/tgbot_client.go (lines 150-177) resolves the subscription host in this order:

  1. subDomain setting ("Listen Domain" under Panel Settings -> Subscription Settings)
  2. webDomain setting ("Listen Domain" under Panel Settings -> Panel Settings)
  3. The server's OS hostname (os.Hostname(), cached at bot startup by SetHostname() in tgbot.go)
  4. "localhost"

Both subDomain and webDomain default to an empty string (internal/web/service/setting.go, lines 38 and 88) and their UI description explicitly says to leave them blank in normal installs ("leave blank to listen on all domains and IPs"). When you reach the panel through your domain without filling in either field, the subscription link shown in the panel/web UI is still correct because it is built from the incoming HTTP request's Host header (SettingService.BuildSubURIBase, internal/web/service/setting.go lines 1243-1260), not from a stored setting. The Telegram bot has no HTTP request to read a host from, so with both domain fields blank it falls through to the OS hostname, which is what you are seeing.

Workaround: in Panel Settings -> Subscription Settings, set either:

  • Listen Domain (subDomain) to your domain, or
  • Reverse Proxy URI (subURI) to the full base URL, e.g. https://your-domain.com/sub/

buildSubscriptionURLs checks subURI first and uses it verbatim when set, otherwise it uses subDomain before ever falling back to the hostname, so either setting will make the bot's link match the one shown in the panel.

This reply was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:4904327124 --> @github-actions[bot] commented on GitHub (Jul 7, 2026): Confirmed as a bug in the Telegram bot's link-building logic, not in the panel itself. **Root cause:** `buildSubscriptionURLs` in `internal/web/service/tgbot/tgbot_client.go` (lines 150-177) resolves the subscription host in this order: 1. `subDomain` setting ("Listen Domain" under Panel Settings -> Subscription Settings) 2. `webDomain` setting ("Listen Domain" under Panel Settings -> Panel Settings) 3. The server's OS hostname (`os.Hostname()`, cached at bot startup by `SetHostname()` in `tgbot.go`) 4. `"localhost"` Both `subDomain` and `webDomain` default to an empty string (`internal/web/service/setting.go`, lines 38 and 88) and their UI description explicitly says to leave them blank in normal installs ("leave blank to listen on all domains and IPs"). When you reach the panel through your domain without filling in either field, the subscription link shown *in the panel/web UI* is still correct because it is built from the incoming HTTP request's `Host` header (`SettingService.BuildSubURIBase`, `internal/web/service/setting.go` lines 1243-1260), not from a stored setting. The Telegram bot has no HTTP request to read a host from, so with both domain fields blank it falls through to the OS hostname, which is what you are seeing. **Workaround:** in Panel Settings -> Subscription Settings, set either: - `Listen Domain` (`subDomain`) to your domain, or - `Reverse Proxy URI` (`subURI`) to the full base URL, e.g. `https://your-domain.com/sub/` `buildSubscriptionURLs` checks `subURI` first and uses it verbatim when set, otherwise it uses `subDomain` before ever falling back to the hostname, so either setting will make the bot's link match the one shown in the panel. *This reply was generated automatically; a maintainer may follow up.*
Author
Owner

@Morteza820 commented on GitHub (Jul 8, 2026):

Dear parsa, change the host name to your sub link in terminal..
it will be solved.
BR,

<!-- gh-comment-id:4912614349 --> @Morteza820 commented on GitHub (Jul 8, 2026): Dear parsa, change the host name to your sub link in terminal.. it will be solved. BR,
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#4064
No description provided.