fix(tools): wire Telegram proxy to Bot in send_message so media uploads stop timing out#27701
Closed
leolulu wants to merge 1 commit into
Closed
fix(tools): wire Telegram proxy to Bot in send_message so media uploads stop timing out#27701leolulu wants to merge 1 commit into
leolulu wants to merge 1 commit into
Conversation
The _send_telegram function in send_message_tool.py created a Bot without
proxy configuration, causing all media file uploads to timeout in
environments that require a proxy to reach api.telegram.org.
The gateway adapter (telegram.py) already resolves the proxy via
resolve_proxy_url('TELEGRAM_PROXY') and passes it to HTTPXRequest, but
the send_message tool's one-shot Bot instance was missing this step.
Fix: call resolve_proxy_url('TELEGRAM_PROXY') and create an HTTPXRequest
with the resolved proxy + matching timeouts (connect=10s, read/write=20s)
before passing it to Bot(request=...).
This aligns the send_message tool's Telegram transport with the gateway
adapter, fixing media uploads (photos, videos, audio, documents) for all
proxy-dependent environments.
Closes #9291 (partial — media delivery timeout due to missing proxy)
Collaborator
Contributor
|
Closing in favor of #25419 — both fix the same bug ( |
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.
Summary
In environments that require a proxy to reach
api.telegram.org, thesend_messagetool fails to deliver any media files (photos, videos, audio, documents) because theBotinstance it creates has no proxy configured — unlike the gateway adapter which correctly uses one.Problem
The gateway adapter (
gateway/platforms/telegram.py) resolves the proxy viaresolve_proxy_url("TELEGRAM_PROXY")and passes it toHTTPXRequest, so all gateway replies work fine behind a proxy.However, the
send_messagetool (tools/send_message_tool.py) creates its own separateBotinstance without any proxy:This
botis used for both text and media sends. In proxy-dependent environments, the TCP connection toapi.telegram.orgcannot be established directly, causing everysend_messagecall to timeout. The gateway itself is unaffected because it uses a different, properly proxiedBotinstance.Fix
Reuse the same proxy resolution chain as the gateway adapter:
Timeout values match the gateway adapter (
telegram.pylines 1219–1221). When no proxy is configured, behavior is unchanged.Testing
Verified locally with
TELEGRAM_PROXY:send_messagewith.oggaudiosend_messagewith.htmlfilesend_messagewith.mdfileRelated
HERMES_TELEGRAM_HTTP_MEDIA_WRITE_TIMEOUTnot wired to PTB