feat: route Telegram file downloads through the gateway proxy - #353
Open
surafelfikru wants to merge 1 commit into
Open
surafelfikru wants to merge 1 commit into
surafelfikru wants to merge 1 commit into
Conversation
Telegram serves API methods from /bot<token>/ but uploaded files from
/file/bot<token>/, and the proxy only routed the first, so every media download
404'd behind the gateway while text messages kept working, which reads as broken
media handling rather than a missing route. This adds the file route next to the
existing one, so photos, documents and voice notes resolve:
location /telegram-file/ {
rewrite ^/telegram-file/(.*)$ /file/bot${TG_BOT_TOKEN}/$1 break;
proxy_pass https://api.telegram.org;
}
nginx.sh needs no change; it builds its envsubst list by grepping ${VAR} out of
the template, so TG_BOT_TOKEN is already picked up from the existing route.
Collaborator
Author
|
Let me know if the plugin extensions for the nginx configuration is the correct approach and i will start working on it. |
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.
Telegram serves API methods from
/bot<token>/but uploaded files from/file/bot<token>/, and the proxy only routed the first, so every media download 404'd behind the gateway while text messages kept working — which reads as broken media handling rather than a missing route. This adds the file route next to the existing one, so photos, documents and voice notes resolve:nginx.shneeds no change; it builds its envsubst list by grepping${VAR}out of the template, soTG_BOT_TOKENis already picked up from the existing/telegram/route. Verified by rendering the template through the same grep-and-envsubst thatnginx.shruns: the token expands and nginx's own$1capture group is left alone.One note for later. This route belongs to a plugin, but it sits in core, like the Slack and Mattermost ones. A plugin cannot add a route on its own today. The template has no
includeline, and the Dockerfile copiesproxy/*flat, so a file shipped by a plugin is copied but never read. We could change this with anincludeinside theserverblock and a Dockerfile line that collectsplugins/*/proxy/*.conf. Two rules would make it safe. First, collect the files at build time, not with a glob at runtime. Then the list of routes is fixed inside the image, and the agent cannot add one while the container is running. Second, runenvsubston each plugin file with only the variables that the file itself declares. Right nownginx.shgreps the variable names out of the template and gives them toenvsubst. If we did the same for plugin files, a plugin could write${ANTHROPIC_API_KEY}inside its own route and read the real key. With a per-file list, a name that is not declared stays as plain text, nginx does not know it, and the container fails to start instead of leaking the key: