fix(send_message): wire Telegram fallback transport into one-shot sends#20924
Open
SandroHub013 wants to merge 1 commit into
Open
fix(send_message): wire Telegram fallback transport into one-shot sends#20924SandroHub013 wants to merge 1 commit into
SandroHub013 wants to merge 1 commit into
Conversation
Closes NousResearch#20915. `tools/send_message_tool.py::_send_telegram` was instantiating a plain `telegram.Bot` with the default `HTTPXRequest`, bypassing the `TelegramFallbackTransport` that the gateway adapter (`gateway/platforms/telegram.py`) sets up. On networks where the system DNS resolves `api.telegram.org` to a blocked IP (a common condition in some regions), the gateway adapter still works but the `send_message` tool — and any cron job built on it — silently times out. Fix: factor the gateway's network setup into a new helper `gateway.platforms.telegram_network.create_bot_with_fallback(token)` and call it from `_send_telegram`. The helper honors the same env vars as the gateway adapter: - `HERMES_TELEGRAM_DISABLE_FALLBACK_IPS=1` to skip fallback - `HERMES_TELEGRAM_FALLBACK_IPS=ip1,ip2` for explicit IPs - `TELEGRAM_PROXY` (and standard `HTTPS_PROXY` etc.) for proxy use The one-shot path doesn't have access to the gateway's per-platform config object, so the helper falls back on env-var configuration plus DoH auto-discovery via `discover_fallback_ips()`. The send_message-tool change is wrapped in a defensive try/except so that import errors (e.g. minimal test environments) degrade gracefully to the previous `Bot(token=token)` behaviour. Tests: 6 new in `tests/gateway/test_telegram_network_create_bot.py` covering disabled / explicit-env-IPs / discovery-success / discovery-empty / discovery-raises / proxy-precedence. Existing 67 telegram_network tests + 95 send_message_tool tests stay green.
This was referenced Jun 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #20915.
What
tools/send_message_tool.py::_send_telegramwas instantiating a plaintelegram.Botwith the defaultHTTPXRequest, bypassing theTelegramFallbackTransportthat the gateway adapter (gateway/platforms/telegram.py) configures. On networks where the system DNS resolvesapi.telegram.orgto a blocked IP, the gateway adapter still works but thesend_messagetool — and every cron job built on it — silently times out.Fix
Factored the gateway's network setup into a new async helper:
_send_telegramnow calls it instead of constructingBot(token=token)directly.The helper honors the same env vars as the gateway adapter:
HERMES_TELEGRAM_DISABLE_FALLBACK_IPS=1— skip fallback entirelyHERMES_TELEGRAM_FALLBACK_IPS=ip1,ip2— explicit fallback IPsTELEGRAM_PROXY(and standardHTTPS_PROXY/HTTP_PROXY) — proxy precedenceWhen no env IPs are configured, the helper auto-discovers via
discover_fallback_ips()(DNS-over-HTTPS through Google + Cloudflare). If discovery fails or returns nothing, the helper degrades to a plainBot— identical to the prior behaviour, so users on healthy networks see no change.Why factor a helper instead of duplicating?
The gateway adapter (
TelegramAdapter.start) has a config-object-driven IP list, two separate request pools (one for polling, one for bot ops), and platform-specific timeout overrides. The send_message tool runs without a config object and only needs one request pool. Putting both behind one helper would either bloat the helper or duplicate the gateway's complexity in_send_telegram. The helper covers the 80% case (single pool, env-driven config) that the one-shot tool path needs; the gateway keeps its bespoke setup.Out of scope (intentional)
gateway/platforms/telegram.py) is not migrated to use the new helper. Its setup needs the config-object pathway and twin request pools; refactoring that is a separate cleanup.cron/— cron jobs that send Telegram messages go throughsend_message_tool, so they pick up this fix automatically.Tests
The 6 new tests cover: disabled-via-env, explicit-env-IPs, discovery-success, discovery-empty, discovery-raises, and proxy-takes-precedence-over-fallback.