feat(telegram): add dedicated TELEGRAM_PROXY env var and config.yaml proxy_url support

Pass platform_env_var="TELEGRAM_PROXY" to resolve_proxy_url() in both
telegram.py (main connect) and telegram_network.py (fallback transport),
so a Telegram-specific proxy takes priority over the generic HTTPS_PROXY.

Also bridge telegram.proxy_url from config.yaml to the TELEGRAM_PROXY
env var (env var takes precedence if both are set), add OPTIONAL_ENV_VARS
entry, docs, and tests.

Composite salvage of four community PRs:
- Core approach (both call sites): #9414 by @leeyang1990
- config.yaml bridging + docs: #6530 by @WhiteWorld
- Naming convention: #9074 by @brantzh6
- Earlier proxy work: #7786 by @ten-ltw

Closes #9414, closes #9074, closes #7786, closes #6530

Co-authored-by: WhiteWorld <WhiteWorld@users.noreply.github.com>
Co-authored-by: brantzh6 <brantzh6@users.noreply.github.com>
Co-authored-by: ten-ltw <ten-ltw@users.noreply.github.com>
This commit is contained in:
leeyang1990
2026-04-15 20:03:48 -07:00
committed by Teknium
parent ff5bf0d6c8
commit c5acc6edb6
7 changed files with 68 additions and 2 deletions

View File

@@ -300,6 +300,42 @@ class TestLoadGatewayConfig:
assert config.platforms[Platform.TELEGRAM].extra["disable_link_previews"] is True
def test_bridges_telegram_proxy_url_from_config_yaml(self, tmp_path, monkeypatch):
hermes_home = tmp_path / ".hermes"
hermes_home.mkdir()
config_path = hermes_home / "config.yaml"
config_path.write_text(
"telegram:\n"
" proxy_url: socks5://127.0.0.1:1080\n",
encoding="utf-8",
)
monkeypatch.setenv("HERMES_HOME", str(hermes_home))
monkeypatch.delenv("TELEGRAM_PROXY", raising=False)
load_gateway_config()
import os
assert os.environ.get("TELEGRAM_PROXY") == "socks5://127.0.0.1:1080"
def test_telegram_proxy_env_takes_precedence_over_config(self, tmp_path, monkeypatch):
hermes_home = tmp_path / ".hermes"
hermes_home.mkdir()
config_path = hermes_home / "config.yaml"
config_path.write_text(
"telegram:\n"
" proxy_url: http://from-config:8080\n",
encoding="utf-8",
)
monkeypatch.setenv("HERMES_HOME", str(hermes_home))
monkeypatch.setenv("TELEGRAM_PROXY", "socks5://from-env:1080")
load_gateway_config()
import os
assert os.environ.get("TELEGRAM_PROXY") == "socks5://from-env:1080"
class TestHomeChannelEnvOverrides:
"""Home channel env vars should apply even when the platform was already