[GH-ISSUE #6327] [Feature]: Support multiple telegram api url #4299

Open
opened 2026-10-31 20:38:39 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @bincrew on GitHub (Aug 25, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6327

In regions where the official Telegram API (api.telegram.org) is blocked (e.g., Russia), users running a local 3x-ui panel must route Telegram bot traffic through a custom base URL pointing to an Nginx reverse proxy hosted on an external, unrestricted VPS.
Currently, 3x-ui only allows specifying a single Telegram API URL/proxy. This creates a Single Point of Failure (SPOF):
If the remote VPS hosting the Nginx reverse proxy loses connectivity or goes offline, 3x-ui cannot reach Telegram.
As a result, critical system notifications — including alerts that the node itself went offline or recovered — fail to deliver because the notification delivery mechanism relies on the very server that went down.

Describe the solution you'd like

Add support for multiple Telegram API base URLs with automatic fallback execution.
Proposed Behavior:
Sequential Retry: When sending a bot notification, 3x-ui sends the request to the primary Telegram API URL/proxy.
Failover: If the request fails (e.g., connection timeout, HTTP 5xx errors, or socket errors), 3x-ui automatically retries using the secondary URL, tertiary URL, etc., before giving up.
UI Configuration:
Allow entering comma-separated or newline-separated URLs in the custom Telegram API Base URL field, or
Provide an explicit list/array input for fallback Telegram API URLs.

Alternatives you've considered

External Load Balancers (HAProxy / DNS Failover): Configuring external HAProxy nodes or dynamic DNS failover across multiple VPS servers works, but it adds significant operational complexity, cost, and infrastructure overhead for a setup that could be handled natively within 3x-ui application logic.

Concrete use case

Many 3x-ui users already maintain multi-node deployments across several remote VPS instances. Allowing 3x-ui to natively failover Telegram API requests across these existing nodes would drastically increase notification reliability without requiring extra infrastructure.

Mockups, screenshots, or examples

No response

Which parts of the panel would this affect?

No response

Are you willing to help?

  • I'd like to implement this feature myself and open a PR.
  • I can help test once a PR is open.

Before submitting

  • I searched existing issues and this feature has not been requested.
  • This feature request is written in English.
Originally created by @bincrew on GitHub (Aug 25, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6327 ### Is your feature request related to a problem? In regions where the official Telegram API (api.telegram.org) is blocked (e.g., Russia), users running a local 3x-ui panel must route Telegram bot traffic through a custom base URL pointing to an Nginx reverse proxy hosted on an external, unrestricted VPS. Currently, 3x-ui only allows specifying a single Telegram API URL/proxy. This creates a Single Point of Failure (SPOF): If the remote VPS hosting the Nginx reverse proxy loses connectivity or goes offline, 3x-ui cannot reach Telegram. As a result, critical system notifications — including alerts that the node itself went offline or recovered — fail to deliver because the notification delivery mechanism relies on the very server that went down. ### Describe the solution you'd like Add support for multiple Telegram API base URLs with automatic fallback execution. Proposed Behavior: Sequential Retry: When sending a bot notification, 3x-ui sends the request to the primary Telegram API URL/proxy. Failover: If the request fails (e.g., connection timeout, HTTP 5xx errors, or socket errors), 3x-ui automatically retries using the secondary URL, tertiary URL, etc., before giving up. UI Configuration: Allow entering comma-separated or newline-separated URLs in the custom Telegram API Base URL field, or Provide an explicit list/array input for fallback Telegram API URLs. ### Alternatives you've considered External Load Balancers (HAProxy / DNS Failover): Configuring external HAProxy nodes or dynamic DNS failover across multiple VPS servers works, but it adds significant operational complexity, cost, and infrastructure overhead for a setup that could be handled natively within 3x-ui application logic. ### Concrete use case Many 3x-ui users already maintain multi-node deployments across several remote VPS instances. Allowing 3x-ui to natively failover Telegram API requests across these existing nodes would drastically increase notification reliability without requiring extra infrastructure. ### Mockups, screenshots, or examples _No response_ ### Which parts of the panel would this affect? _No response_ ### Are you willing to help? - [ ] I'd like to implement this feature myself and open a PR. - [ ] I can help test once a PR is open. ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this feature has not been requested. - [x] This feature request is written in English.
Author
Owner

@github-actions[bot] commented on GitHub (Aug 25, 2026):

You're right about the current limitation — 3x-ui stores and uses exactly one Telegram Bot API base URL, and nothing in the code splits, iterates or fails over that value. But the single point of failure you describe can already be removed today without a second API URL, using Panel Traffic Outbound plus an Xray balancer. Details below.

What the code does now

tgBotAPIServer is a single string setting (internal/web/service/setting.go:77, getter/setter at :534-540), validated as one URL:

// internal/web/service/setting.go:1331-1337
if allSetting.TgBotAPIServer != "" {
    u, err := SanitizeHTTPURL(allSetting.TgBotAPIServer)

SanitizeHTTPURL (internal/web/service/url_safety.go:16-40) runs url.Parse on the whole field, so a comma- or newline-separated value is never split into a list anywhere.

It is then handed to the bot once, at construction:

// internal/web/service/tgbot/tgbot.go:429-431
if apiServerUrl != "" {
    options = append(options, telego.WithAPIServer(apiServerUrl))
}

The retry loop in SendMsgToTgbot does exist, but it retries the same endpoint — internal/web/service/tgbot/tgbot_send.go:145-172, three attempts with 1s/2s/4s backoff:

// Retry logic with exponential backoff for connection errors
maxRetries := 3

So when your Nginx relay VPS is down, all three attempts fail against the same host and the alert is dropped with logger.Warning("Error sending telegram message:", err) (tgbot_send.go:169).

For whoever picks this up: it is not a purely send-side change. bot is a single package-level *telego.Bot (tgbot.go:32) whose API server is fixed at construction, and the update stream is bound to that same object — bot.UpdatesViaLongPolling(ctx, &params) (internal/web/service/tgbot/tgbot_router.go:41) behind a strict singleton guard (tgbot_router.go:24-30). Failing over would have to move the long-polling receiver too, not just outgoing messages.

What you can do today

Since v3.7.0 the panel can route its own egress (including Telegram) through an Xray outbound — and that setting accepts a balancer tag, which is exactly the multi-endpoint failover you're asking for, one layer lower:

// internal/web/service/xray.go:452-460
// The configured tag may name a routing balancer instead of a concrete
// outbound. ...
if routingTagIsBalancer(routing, outboundTag) {
    rule["balancerTag"] = outboundTag
} else {
    rule["outboundTag"] = outboundTag
}

Concretely:

  1. In the Xray template, define one outbound per unrestricted VPS you already run, and a balancers entry listing those tags.
  2. Settings → General → Panel Traffic Outbound (panelOutbound) — the picker shows a separate Balancers group (frontend/src/pages/settings/GeneralTab.tsx:119-137); select the balancer.
  3. Leave Telegram API Server (tgBotAPIServer) empty, so the bot talks to api.telegram.org directly and the tunnel — not an Nginx relay — is what crosses the border. That removes the relay from the path entirely.
  4. For health-aware selection rather than blind spreading, add burstObservatory and a leastPing strategy to the balancer. Both observatory and burstObservatory are first-class fields of the panel's generated config (internal/xray/config.go:23-24), so they survive config generation.

Two caveats worth knowing:

  • If Xray is not running, or the injected bridge isn't in the running config, PanelEgressProxyURL() returns "" and the panel falls back to a direct connection, with a warning in the log (internal/web/service/setting.go:477-498).
  • The bot resolves that proxy once at start (tgbot.go:299-306, and the comment there says so). That is fine for failover, though — the resolved value is a loopback SOCKS address; the actual per-connection failover happens inside Xray's balancer, so a dead member does not require a bot restart.

Settings reference: docs/content/docs/en/operations/telegram-bot.mdx (Settings table, tgBotProxy / tgBotAPIServer) and docs/content/docs/en/config/panel.mdx (panelOutbound).

Related, not a duplicate: #5058 asked for Telegram over a custom outbound and is what panelOutbound came from; it does not cover a list of API base URLs, so your request stands on its own. I left the enhancement label and the title as they are.

Verdict: Feature request

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

<!-- gh-comment-id:5413594817 --> @github-actions[bot] commented on GitHub (Aug 25, 2026): You're right about the current limitation — 3x-ui stores and uses exactly **one** Telegram Bot API base URL, and nothing in the code splits, iterates or fails over that value. But the single point of failure you describe can already be removed today without a second API URL, using **Panel Traffic Outbound** plus an Xray balancer. Details below. ## What the code does now `tgBotAPIServer` is a single string setting (`internal/web/service/setting.go:77`, getter/setter at `:534-540`), validated as one URL: ```go // internal/web/service/setting.go:1331-1337 if allSetting.TgBotAPIServer != "" { u, err := SanitizeHTTPURL(allSetting.TgBotAPIServer) ``` `SanitizeHTTPURL` (`internal/web/service/url_safety.go:16-40`) runs `url.Parse` on the whole field, so a comma- or newline-separated value is never split into a list anywhere. It is then handed to the bot once, at construction: ```go // internal/web/service/tgbot/tgbot.go:429-431 if apiServerUrl != "" { options = append(options, telego.WithAPIServer(apiServerUrl)) } ``` The retry loop in `SendMsgToTgbot` does exist, but it retries the **same** endpoint — `internal/web/service/tgbot/tgbot_send.go:145-172`, three attempts with 1s/2s/4s backoff: ```go // Retry logic with exponential backoff for connection errors maxRetries := 3 ``` So when your Nginx relay VPS is down, all three attempts fail against the same host and the alert is dropped with `logger.Warning("Error sending telegram message:", err)` (`tgbot_send.go:169`). For whoever picks this up: it is not a purely send-side change. `bot` is a single package-level `*telego.Bot` (`tgbot.go:32`) whose API server is fixed at construction, and the **update stream is bound to that same object** — `bot.UpdatesViaLongPolling(ctx, &params)` (`internal/web/service/tgbot/tgbot_router.go:41`) behind a strict singleton guard (`tgbot_router.go:24-30`). Failing over would have to move the long-polling receiver too, not just outgoing messages. ## What you can do today Since v3.7.0 the panel can route **its own** egress (including Telegram) through an Xray outbound — and that setting accepts a **balancer tag**, which is exactly the multi-endpoint failover you're asking for, one layer lower: ```go // internal/web/service/xray.go:452-460 // The configured tag may name a routing balancer instead of a concrete // outbound. ... if routingTagIsBalancer(routing, outboundTag) { rule["balancerTag"] = outboundTag } else { rule["outboundTag"] = outboundTag } ``` Concretely: 1. In the Xray template, define one outbound per unrestricted VPS you already run, and a `balancers` entry listing those tags. 2. Settings → General → **Panel Traffic Outbound** (`panelOutbound`) — the picker shows a separate **Balancers** group (`frontend/src/pages/settings/GeneralTab.tsx:119-137`); select the balancer. 3. Leave **Telegram API Server** (`tgBotAPIServer`) **empty**, so the bot talks to `api.telegram.org` directly and the tunnel — not an Nginx relay — is what crosses the border. That removes the relay from the path entirely. 4. For health-aware selection rather than blind spreading, add `burstObservatory` and a `leastPing` strategy to the balancer. Both `observatory` and `burstObservatory` are first-class fields of the panel's generated config (`internal/xray/config.go:23-24`), so they survive config generation. Two caveats worth knowing: - If Xray is not running, or the injected bridge isn't in the running config, `PanelEgressProxyURL()` returns `""` and the panel falls back to a **direct** connection, with a warning in the log (`internal/web/service/setting.go:477-498`). - The bot resolves that proxy once at start (`tgbot.go:299-306`, and the comment there says so). That is fine for failover, though — the resolved value is a loopback SOCKS address; the actual per-connection failover happens inside Xray's balancer, so a dead member does not require a bot restart. Settings reference: `docs/content/docs/en/operations/telegram-bot.mdx` (Settings table, `tgBotProxy` / `tgBotAPIServer`) and `docs/content/docs/en/config/panel.mdx` (`panelOutbound`). Related, not a duplicate: #5058 asked for Telegram over a custom outbound and is what `panelOutbound` came from; it does not cover a list of API base URLs, so your request stands on its own. I left the `enhancement` label and the title as they are. Verdict: Feature request *This reply was generated automatically; a maintainer may follow up.* <!-- claude-issue:analyst -->
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#4299
No description provided.