fix(send_message): route standalone Telegram sends through TELEGRAM_PROXY#28480
Merged
Conversation
…ROXY When the send_message tool runs outside the gateway process (agent loop, TUI, cron, etc.), _gateway_runner_ref() returns None and the standalone path in _send_telegram constructs Bot(token=token) directly, bypassing any configured proxy. In regions where api.telegram.org is blocked, the send times out after ~5s with 'Telegram send failed: Timed out' and nothing ever shows up in gateway.log because the request never reaches the gateway. Resolve TELEGRAM_PROXY (via gateway.platforms.base.resolve_proxy_url, which also honours HTTPS_PROXY/HTTP_PROXY/ALL_PROXY and NO_PROXY) just before constructing the Bot. When a proxy is found, attach an HTTPXRequest(proxy=...) for both 'request' and 'get_updates_request', matching what gateway/platforms/telegram.py already does for in-gateway sends and what the Discord standalone sender already does. Any exception attaching the proxy falls back cleanly to a direct connection, preserving prior behaviour for users without a proxy configured. Adds tests/tools/test_send_message_telegram_proxy.py covering both the proxy-configured and no-proxy cases.
Contributor
🔎 Lint report:
|
| Rule | Count |
|---|---|
unresolved-import |
2 |
First entries
tools/send_message_tool.py:831: [unresolved-import] unresolved-import: Cannot resolve imported module `telegram.request`
tests/tools/test_send_message_telegram_proxy.py:23: [unresolved-import] unresolved-import: Cannot resolve imported module `pytest`
✅ Fixed issues: none
Unchanged: 4649 pre-existing issues carried over.
Diagnostics are surfaced as warnings — this check never fails the build.
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.
Salvage of #25419 (@pepelax).
Summary
In regions where
api.telegram.orgis blocked, calling thesend_messagetool from any process other than the gateway itself (agent loop, TUI, cron, ad-hoc scripts) silently failed with a 5s timeout — no entry in gateway.log because the request never reached the gateway.tools/send_message_tool.py::_send_telegramconstructedBot(token=token)with no proxy, even though the gateway adapter resolvedTELEGRAM_PROXYfor in-process calls. Affects both text and media sends.Changes
tools/send_message_tool.py: passTELEGRAM_PROXYviaHTTPXRequestwhen the in-process delegation path isn't available.tests/tools/test_send_message_telegram_proxy.py: coverage.Validation
scripts/run_tests.sh tests/tools/test_send_message_telegram_proxy.py -q→ 2/2 passing.Also supersedes #27701 (@leolulu) which fixed the media-only subset — closed with credit.
Authorship preserved via cherry-pick. AUTHOR_MAP entry added in follow-up commit.