Skip to content

feat(telegram_relay): relay the Telegram Bot API through a Cloudflare Worker - #115

Merged
hackallcode merged 2 commits into
masterfrom
feat/telegram-relay
Nov 21, 2026
Merged

hackallcode merged 2 commits into
masterfrom
feat/telegram-relay

Conversation

@hackallcode

@hackallcode hackallcode commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

Summary

Networks that block api.telegram.org often still reach Cloudflare, so a bot or Alertmanager there can call the Bot
API 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_relay uploads 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 in telegram_relay_bot_ids, with any method, query
and 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 --check reports the writes it would make. Hostnames are looked up
by service, so a renamed one is detached; uninstall detaches them all and deletes the Worker. A refused call fails
with 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 --test with fetch stubbed: make test/telegram-relay, also a step of the sanity
job.

… 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.
Comment thread roles/telegram_relay/tasks/install.yml Resolved
Comment thread roles/telegram_relay/tasks/install.yml Resolved
Comment thread roles/telegram_relay/tasks/install.yml Resolved
Comment thread roles/telegram_relay/tasks/install.yml Resolved
Comment thread roles/telegram_relay/tasks/install.yml Resolved
Comment thread roles/telegram_relay/tasks/install.yml Resolved
Comment thread roles/telegram_relay/README.md Resolved
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.
@hackallcode
hackallcode merged commit fec5e3d into master Nov 21, 2026
27 checks passed
@hackallcode
hackallcode deleted the feat/telegram-relay branch November 21, 2026 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant