[GH-ISSUE #5682] [Bug]: Telegram bot isn't routed #3954

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

Originally created by @XFox111 on GitHub (Jun 30, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5682

Describe the bug

Since telegram is blocked on my server's ISP, I've set up routing rules, so its traffic goes through another server. I checked my rules with Route Tester.

Recently Telegram proxy option was deprecated, and instead, it was introduced that Telegram egress will be routed through Xray routing table (5eec1784)

How to reproduce the problem

  1. Setup an outbound config from a different server
  2. Add routing rule with IP matching geoip:telegram and outbound from step 1
  3. Add routing rule with Domain matching geosite:telegram and outbound from step 1
  4. Use Route Tester to verify that telegram.org goes through said outbound
  5. Install TShark on the server
  6. Run TShark with sudo tshark -i eth0 -f tcp -T fields -e ip.dst (eth0 here is your ISP interface)
  7. Go to Telegram bot settings and click "Send Test Message"
  8. Verify that Telegram IP (in my case, it's 149.154.166.110) is present in tshark output. That means that its traffic goes directly from the current server, and not through configured outbound

Expected behavior

Telegram bot traffic is routed through another server.

Actual behavior

Telegram bot traffic is not routed through another server.

Relevant logs

2026/06/30 13:44:23 WARNING - X-UI: [POST /main/panel/api/setting/testTgBot handler=controller.(*SettingController).testTgBot setting.go:254] Telegram test failed: telegram API test failed: API unreachable: telego: getMe: internal execution: request call: fasthttp do request: error when dialing 149.154.166.110:443: dialing to the given TCP address timed out Failed: telegram API test failed: API unreachable: telego: getMe: internal execution: request call: fasthttp do request: error when dialing

Screenshots

Image Image

3x-ui version

3.4.2

Xray-core version

26.6.22

How did you install 3x-ui?

Docker / Docker Compose

Operating system

Ubuntu 24.04

Which parts of the panel are affected?

Telegram bot

Browser (only if it is a UI bug)

No response

Is the panel behind a reverse proxy or CDN?

No response

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 @XFox111 on GitHub (Jun 30, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5682 ### Describe the bug Since telegram is blocked on my server's ISP, I've set up routing rules, so its traffic goes through another server. I checked my rules with Route Tester. Recently Telegram proxy option was deprecated, and instead, it was introduced that Telegram egress will be routed through Xray routing table (5eec1784) ### How to reproduce the problem 1. Setup an outbound config from a different server 2. Add routing rule with IP matching `geoip:telegram` and outbound from step 1 3. Add routing rule with Domain matching `geosite:telegram` and outbound from step 1 4. Use Route Tester to verify that `telegram.org` goes through said outbound 5. Install TShark on the server 6. Run TShark with `sudo tshark -i eth0 -f tcp -T fields -e ip.dst` (`eth0` here is your ISP interface) 7. Go to Telegram bot settings and click "Send Test Message" 8. Verify that Telegram IP (in my case, it's `149.154.166.110`) is present in tshark output. That means that its traffic goes directly from the current server, and not through configured outbound ### Expected behavior Telegram bot traffic is routed through another server. ### Actual behavior Telegram bot traffic is not routed through another server. ### Relevant logs ```shell 2026/06/30 13:44:23 WARNING - X-UI: [POST /main/panel/api/setting/testTgBot handler=controller.(*SettingController).testTgBot setting.go:254] Telegram test failed: telegram API test failed: API unreachable: telego: getMe: internal execution: request call: fasthttp do request: error when dialing 149.154.166.110:443: dialing to the given TCP address timed out Failed: telegram API test failed: API unreachable: telego: getMe: internal execution: request call: fasthttp do request: error when dialing ``` ### Screenshots <img width="1516" height="176" alt="Image" src="https://github.com/user-attachments/assets/232dc9d6-d4f5-482b-8bab-35244a0a1a9f" /> <img width="1589" height="335" alt="Image" src="https://github.com/user-attachments/assets/dad9b34b-395b-405d-a9ee-27f605fd3223" /> ### 3x-ui version 3.4.2 ### Xray-core version 26.6.22 ### How did you install 3x-ui? Docker / Docker Compose ### Operating system Ubuntu 24.04 ### Which parts of the panel are affected? Telegram bot ### Browser (only if it is a UI bug) _No response_ ### Is the panel behind a reverse proxy or CDN? _No response_ ### 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:07 +07:00
Author
Owner

@XFox111 commented on GitHub (Jun 30, 2026):

Routing config:

"routing": {
  "domainStrategy": "AsIs",
  "rules": [
    {
      "inboundTag": [
        "api"
      ],
      "outboundTag": "api",
      "type": "field"
    },
    {
      "ip": [
        "geoip:telegram"
      ],
      "outboundTag": "US-NYC-OUTBOUND-VLESS",
      "type": "field"
    },
    {
      "domain": [
        "geosite:telegram"
      ],
      "outboundTag": "US-NYC-OUTBOUND-VLESS",
      "type": "field"
    }
  ]
},
<!-- gh-comment-id:4842393190 --> @XFox111 commented on GitHub (Jun 30, 2026): Routing config: ```json "routing": { "domainStrategy": "AsIs", "rules": [ { "inboundTag": [ "api" ], "outboundTag": "api", "type": "field" }, { "ip": [ "geoip:telegram" ], "outboundTag": "US-NYC-OUTBOUND-VLESS", "type": "field" }, { "domain": [ "geosite:telegram" ], "outboundTag": "US-NYC-OUTBOUND-VLESS", "type": "field" } ] }, ```
Author
Owner

@github-actions[bot] commented on GitHub (Jun 30, 2026):

Commit 5eec1784 added routing for MTProto inbound proxy traffic through Xray — that is, connections that the bundled mtg binary makes to Telegram on behalf of MTProto proxy clients. It has no effect on the Telegram bot's own connections.

The Telegram bot is a Go process that dials the Telegram API directly via fasthttp; those connections originate from the Go runtime and never enter an Xray inbound, so Xray routing rules (geoip:telegram, geosite:telegram, or any other rule) do not apply to them.

How to route bot traffic through your proxy outbound

The panel provides a dedicated setting for this: Settings → Panel → "Panel Traffic Outbound" (panelOutbound). Selecting an outbound tag there causes the panel to:

  1. Inject a loopback SOCKS5 inbound (panel-egress, starting at port 62790) into the running Xray config.
  2. Add a routing rule that sends all traffic from that inbound to the chosen outbound tag.
  3. Configure the Telegram bot (and other panel HTTP clients such as version checks and geo-file updates) to dial through socks5://127.0.0.1:<bridge-port>.

The description in the UI (confirmed in internal/web/translation/en-US.json) reads:

Routes the panel's own requests — panel/Xray version checks and downloads, Telegram, and the normal geo-file update — through this Xray outbound to bypass server-side filtering of GitHub/Telegram.

Steps to apply:

  1. Go to Settings → Panel.
  2. Under Panel Traffic Outbound, select the outbound tag that routes through your other server (the tag you created in step 1 of your reproduction steps).
  3. Save. Saving settings restarts the Telegram bot, which then picks up the SOCKS5 bridge address.
  4. Click Send Test Message — the connection will now egress through the chosen outbound.

One important note: the injected routing rule matches by inboundTag (panel-egress) and sends that traffic directly to the named outbound, so the geoip:telegram / geosite:telegram rules you already have will not be evaluated for panel/bot traffic. The panel egress bypasses geo-matching by design. You need to point "Panel Traffic Outbound" at the outbound (or balancer) that reaches your relay server.

The relevant code paths are internal/web/service/tgbot/tgbot.go (lines 293–306, proxy resolution at bot start) and internal/web/service/setting.go (PanelEgressProxyURL, lines 447–468), with the bridge injection in internal/web/service/xray.go (injectPanelEgress, lines 362–420).

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

<!-- gh-comment-id:4842414195 --> @github-actions[bot] commented on GitHub (Jun 30, 2026): Commit 5eec1784 added routing for **MTProto inbound proxy** traffic through Xray — that is, connections that the bundled `mtg` binary makes to Telegram on behalf of MTProto proxy clients. It has no effect on the Telegram bot's own connections. The Telegram bot is a Go process that dials the Telegram API directly via `fasthttp`; those connections originate from the Go runtime and never enter an Xray inbound, so Xray routing rules (`geoip:telegram`, `geosite:telegram`, or any other rule) do not apply to them. **How to route bot traffic through your proxy outbound** The panel provides a dedicated setting for this: **Settings → Panel → "Panel Traffic Outbound"** (`panelOutbound`). Selecting an outbound tag there causes the panel to: 1. Inject a loopback SOCKS5 inbound (`panel-egress`, starting at port 62790) into the running Xray config. 2. Add a routing rule that sends all traffic from that inbound to the chosen outbound tag. 3. Configure the Telegram bot (and other panel HTTP clients such as version checks and geo-file updates) to dial through `socks5://127.0.0.1:<bridge-port>`. The description in the UI (confirmed in `internal/web/translation/en-US.json`) reads: > Routes the panel's own requests — panel/Xray version checks and downloads, Telegram, and the normal geo-file update — through this Xray outbound to bypass server-side filtering of GitHub/Telegram. Steps to apply: 1. Go to **Settings → Panel**. 2. Under **Panel Traffic Outbound**, select the outbound tag that routes through your other server (the tag you created in step 1 of your reproduction steps). 3. Save. Saving settings restarts the Telegram bot, which then picks up the SOCKS5 bridge address. 4. Click **Send Test Message** — the connection will now egress through the chosen outbound. One important note: the injected routing rule matches by `inboundTag` (`panel-egress`) and sends that traffic **directly to the named outbound**, so the `geoip:telegram` / `geosite:telegram` rules you already have will not be evaluated for panel/bot traffic. The panel egress bypasses geo-matching by design. You need to point "Panel Traffic Outbound" at the outbound (or balancer) that reaches your relay server. The relevant code paths are `internal/web/service/tgbot/tgbot.go` (lines 293–306, proxy resolution at bot start) and `internal/web/service/setting.go` (`PanelEgressProxyURL`, lines 447–468), with the bridge injection in `internal/web/service/xray.go` (`injectPanelEgress`, lines 362–420). *This reply was generated automatically; a maintainer may follow up.*
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#3954
No description provided.