Repository navigation
feat(telegram_relay): relay the Telegram Bot API through a Cloudflare Worker - #115
Merged
Merged
Conversation
… Worker Hosts in networks that block api.telegram.org often still reach Cloudflare. A Worker on a hostname of a Cloudflare zone passes the calls of listed bots and answers every other path with 404, so it does not turn into an open proxy. The tasks only call the Cloudflare API; the Worker's routing is unit-tested under node with fetch stubbed.
hackallcode
commented
Nov 21, 2026
hackallcode
commented
Nov 21, 2026
hackallcode
commented
Nov 21, 2026
hackallcode
commented
Nov 21, 2026
hackallcode
commented
Nov 21, 2026
hackallcode
commented
Nov 21, 2026
hackallcode
commented
Nov 21, 2026
hackallcode
commented
Nov 21, 2026
The etag Cloudflare returns hashes the script alone, so a change of bots or compatibility date went out reported as unchanged, and every run left a new Worker version. A deploy tag over script and metadata is read back first and the upload made only when it differs; --check reports the writes it would make. Every call fails with Cloudflare's status and errors instead of a censored result, hostnames are looked up by service so a renamed one is detached and uninstall finds them all, and a bot id list given as a string is refused.
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
Networks that block
api.telegram.orgoften still reach Cloudflare, so a bot or Alertmanager there can call the BotAPI through a Cloudflare Worker instead, with the Worker's URL as its API base (
telegram_configs[].api_url,python-telegram-bot's
base_url, Home Assistant's API endpoint).telegram_relayuploads that Worker and attaches it to a hostname of a Cloudflare zone. The Worker passes/bot<id>:<token>/...and/file/bot<id>:<token>/...of the bots intelegram_relay_bot_ids, with any method, queryand body, and answers every other path with 404, so it does not become an open proxy.
The etag Cloudflare returns hashes the script alone, so install tags the upload with a hash of the script and its
metadata and reads that tag back first: a rerun with nothing changed makes no write, a change of bots or
compatibility date is uploaded and reported, and
--checkreports the writes it would make. Hostnames are looked upby service, so a renamed one is detached;
uninstalldetaches them all and deletes the Worker. A refused call failswith Cloudflare's status and errors, and the token stays out of the output.
The tasks only talk to the Cloudflare API, which CI has no account for, so there is no molecule scenario. The Worker's
routing is unit-tested under
node --testwithfetchstubbed:make test/telegram-relay, also a step of the sanityjob.