[PR #6682] [CLOSED] Route Telegram bot traffic via a selectable routing inbound tag #6407

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6682
Author: @freeb5d
Created: 9/29/2026
Status: ❌ Closed

Base: main ← Head: feat/telegram-bot-routing


📝 Commits (3)

  • b0539d6 Route Telegram bot traffic through a selectable routing inbound tag
  • 85f671f Handle string-form inboundTag, skip egress lookup when bot bridge exists, add tests
  • 47c268b Cache the panel egress lookup in the bot dialer

📊 Changes

6 files changed (+161 additions, -9 deletions)

View changed files

📝 frontend/src/pages/xray/routing/RoutingTab.tsx (+2 -0)
📝 internal/web/controller/xray_setting.go (+8 -0)
📝 internal/web/service/setting.go (+19 -0)
📝 internal/web/service/tgbot/tgbot.go (+27 -9)
📝 internal/web/service/xray.go (+67 -0)
📝 internal/web/service/xray_config_inject_test.go (+38 -0)

📄 Description

Problem

On servers where Telegram is filtered (e.g. hosts in Iran), the Telegram bot cannot reach the Telegram API, and the only workaround is a dedicated proxy setting.

Change

  • Adds a virtual telegram-bot entry to Routing -> Inbound tags.
  • When a routing rule uses that tag, the generated Xray config gets a loopback-only SOCKS inbound with the same tag. The rule can send the bot's traffic to any outbound or balancer. If no rule uses the tag, nothing is added and the bot connects directly.
  • The bot now picks its route per connection: explicit bot proxy, then the telegram-bot bridge, then the panel-egress bridge, then direct. No bot restart is needed when Xray starts later or a rule is added.

Testing

Not fully tested. The changed Go files are gofmt-clean, but the full build could not run in my environment (no C compiler for the SQLite driver) and I have not run the frontend build or tried it against a filtered server. Please verify: add a rule with Inbound tag telegram-bot and an outbound, restart Xray, then use the Telegram test in settings.


🔄 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/6682 **Author:** [@freeb5d](https://github.com/freeb5d) **Created:** 9/29/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feat/telegram-bot-routing` --- ### 📝 Commits (3) - [`b0539d6`](https://github.com/MHSanaei/3x-ui/commit/b0539d6715fe18b4a2f83a74d053859451e11f62) Route Telegram bot traffic through a selectable routing inbound tag - [`85f671f`](https://github.com/MHSanaei/3x-ui/commit/85f671f6c5e4351d6d435b94a40667a1fb2632da) Handle string-form inboundTag, skip egress lookup when bot bridge exists, add tests - [`47c268b`](https://github.com/MHSanaei/3x-ui/commit/47c268b6797031d36e3ab0e47afe799982bfe01b) Cache the panel egress lookup in the bot dialer ### 📊 Changes **6 files changed** (+161 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `frontend/src/pages/xray/routing/RoutingTab.tsx` (+2 -0) 📝 `internal/web/controller/xray_setting.go` (+8 -0) 📝 `internal/web/service/setting.go` (+19 -0) 📝 `internal/web/service/tgbot/tgbot.go` (+27 -9) 📝 `internal/web/service/xray.go` (+67 -0) 📝 `internal/web/service/xray_config_inject_test.go` (+38 -0) </details> ### 📄 Description ## Problem On servers where Telegram is filtered (e.g. hosts in Iran), the Telegram bot cannot reach the Telegram API, and the only workaround is a dedicated proxy setting. ## Change - Adds a virtual `telegram-bot` entry to **Routing -> Inbound tags**. - When a routing rule uses that tag, the generated Xray config gets a loopback-only SOCKS inbound with the same tag. The rule can send the bot's traffic to any outbound or balancer. If no rule uses the tag, nothing is added and the bot connects directly. - The bot now picks its route per connection: explicit bot proxy, then the `telegram-bot` bridge, then the panel-egress bridge, then direct. No bot restart is needed when Xray starts later or a rule is added. ## Testing Not fully tested. The changed Go files are gofmt-clean, but the full build could not run in my environment (no C compiler for the SQLite driver) and I have not run the frontend build or tried it against a filtered server. Please verify: add a rule with Inbound tag `telegram-bot` and an outbound, restart Xray, then use the Telegram test in settings. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:08:32 +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#6407
No description provided.