From e376a9b2c9575e34fa6ac132f499b354b7bd8ebb Mon Sep 17 00:00:00 2001 From: spniyant Date: Thu, 9 Apr 2026 15:39:54 -0400 Subject: [PATCH] feat(telegram): support custom base_url for credential proxy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When extra.base_url is set in the Telegram platform config, use it as the base URL for all Telegram API requests instead of api.telegram.org. This allows agents to route Telegram traffic through the credential proxy, which injects the real bot token — the VM never sees it. Also supports extra.base_file_url for file downloads (defaults to base_url if not set separately). Co-Authored-By: Claude Opus 4.6 (1M context) --- gateway/platforms/telegram.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/gateway/platforms/telegram.py b/gateway/platforms/telegram.py index d8113eab0a..af447d565c 100644 --- a/gateway/platforms/telegram.py +++ b/gateway/platforms/telegram.py @@ -518,6 +518,16 @@ class TelegramAdapter(BasePlatformAdapter): # Build the application builder = Application.builder().token(self.config.token) + custom_base_url = self.config.extra.get("base_url") + if custom_base_url: + builder = builder.base_url(custom_base_url) + builder = builder.base_file_url( + self.config.extra.get("base_file_url", custom_base_url) + ) + logger.info( + "[%s] Using custom Telegram base_url: %s", + self.name, custom_base_url, + ) # PTB defaults (pool_timeout=1s) are too aggressive on flaky networks and # can trigger "Pool timeout: All connections in the connection pool are occupied" @@ -547,7 +557,6 @@ class TelegramAdapter(BasePlatformAdapter): for k in ("HTTPS_PROXY", "HTTP_PROXY", "ALL_PROXY", "https_proxy", "http_proxy", "all_proxy") ) disable_fallback = (os.getenv("HERMES_TELEGRAM_DISABLE_FALLBACK_IPS", "").strip().lower() in ("1", "true", "yes", "on")) - fallback_ips = self._fallback_ips() if not fallback_ips: fallback_ips = await discover_fallback_ips()