Skip to content

Repository files navigation

cfwebhook

English   中文

Cloudflare Worker · HTTP Webhook → Telegram
MIT

Status page


English

中文 ▸

Cloudflare Worker that receives HTTP webhooks and forwards the body to Telegram and/or another webhook.

What it does

Path / Method Behavior
GET / Status page (“running”). Center orb → GitHub; elsewhere → copy webhook URL (location.origin). Also registers Telegram /webhook command + bot webhook in the background.
POST / Business receive: forward request body to Telegram and/or a downstream https/http webhook, according to which forwarding variables are configured. Body is not modified, except optional timestamp. Optional WHITE_IPs apply here only.
POST /telegram Telegram Bot callback (no IP allowlist). Admin (first chat id) can send /webhook to receive the public webhook URL.

Typical business flow:

  1. Client POSTs to your Worker root URL.
  2. Optional IP allowlist.
  3. Optional timezone timestamp (TIME_MARKER).
  4. Message is sent to Telegram when FORWARD_PATH_TGBOT is configured and to the downstream webhook when FORWARD_PATH_WEBHOOK is configured. If both are configured, both receive the message.
  5. Returns Success (or partial/error info).

Cloudflare variables

Settings → Variables and Secrets

Variable names are case-insensitive. Token, chat id, URL, timezone, and IP keep original case.

Variable Required Description
FORWARD_PATH_TGBOT No Configures Telegram forwarding. Value: token,admin_id[,id2,id3...]. First id = admin (can use /webhook). All ids receive Telegram messages.
FORWARD_PATH_WEBHOOK No Configures downstream webhook forwarding. https:// and http:// are both accepted. Worker POSTs the same body.
WHITE_IPs No Comma-separated IPs for POST / only. Empty / unset = allow all. Uses CF-Connecting-IP.
TIME_MARKER No IANA timezone, e.g. Asia/Shanghai. Empty / invalid / unset = off. Appends:
—————————
时间: 2026-08-03 02:00

Example FORWARD_PATH_TGBOT:

123456:AAF-xxxx,111111111,222222222

Bot command /webhook

  1. Open https://YOUR_WORKER_HOST/setup once — it registers /webhook and reports webhook status as JSON.
  2. Talk to the bot as the admin (first chat id) and send /webhook.
  3. One Telegram bot can only have one webhook URL. Use a dedicated bot for this Worker.

Deploy

  1. Connect this repo to Workers Builds (or deploy locally).
  2. Build: bun run build
  3. Deploy: npx wrangler deploy
  4. Set variables in the dashboard.
  5. Business webhook URL: https://YOUR_WORKER_HOST
bun install && bun run build && bun run deploy

Test

curl -X POST "https://YOUR_WORKER_URL" \
  -H "Content-Type: text/plain" \
  -d "hello from cfwebhook"

Warning & disclaimer

  • This project is for personal / internal notification forwarding only. You are solely responsible for how you deploy and use it.
  • Do not use it for spam, phishing, abuse, or any activity that violates Cloudflare Terms, Cloudflare AUP, or Telegram Terms.
  • Keep your Bot token and chat IDs secret. Prefer WHITE_IPs in production. Anyone who can POST your Worker URL can push messages into your Telegram chats.
  • Cloudflare / Telegram may rate-limit or suspend accounts for abuse or quota excess. The authors provide this software as-is, with no warranty, and are not liable for account bans, data loss, or damages arising from use.

License

MIT © 2026 jack (shengshk)


中文

◂ English

将 HTTP Webhook 请求体转发到 Telegram 和/或其他 webhook 的 Cloudflare Worker。

功能说明

路径 / 方法 行为
GET / 状态页。点中心 → GitHub;点其他区域 → 复制 Webhook(location.origin)。后台注册 Bot 的 /webhook 命令与 Telegram Webhook。
POST / 业务接收:根据是否配置 FORWARD_PATH_TGBOTFORWARD_PATH_WEBHOOK,转发到 Telegram 和/或下游 https/http webhook。不改动正文,仅可选追加时间戳。WHITE_IPs 只作用于此路径。
POST /telegram Telegram 回调(不走 IP 白名单)。仅管理 id(第一个) 可发 /webhook,Bot 回传公开 Webhook 链接。

业务流程:

  1. 客户端 POST 到 Worker 根路径。
  2. 可选 IP 白名单。
  3. 可选时区时间戳(TIME_MARKER)。
  4. 配置了 FORWARD_PATH_TGBOT 就发送到 Telegram,配置了 FORWARD_PATH_WEBHOOK 就发送到下游 Webhook;两者都配置时同时发送。
  5. 返回 Success(或部分成功 / 错误信息)。

在 Cloudflare 配置变量

设置 → 变量和密钥

变量名大小写不敏感。Token、chat id、URL、时区、IP 保持原样。

变量 必需 说明
FORWARD_PATH_TGBOT 配置 Telegram 转发。值为 token,管理id[,id2,id3...]第一个 id = 管理(可 /webhook)。全部 id 收 Telegram。
FORWARD_PATH_WEBHOOK 配置下游 Webhook 转发。https://http:// 均可。Worker 再 POST 同一正文。
WHITE_IPs 仅限制 POST /。逗号分隔。空 / 未配置 = 不限制。
TIME_MARKER IANA 时区,如 Asia/Shanghai。未配置 / 无效 = 关闭。开启时追加:
—————————
时间: 2026-08-03 02:00

FORWARD_PATH_TGBOT 示例:

123456:AAF-xxxx,111111111,222222222

Bot 命令 /webhook

  1. 浏览器打开一次 https://你的Worker域名/setup,会注册 /webhook,并以 JSON 返回状态。
  2. 管理 id(第一个) 在 Telegram 发送 /webhook
  3. 一个 Bot 只能绑定 一个 Webhook。请为本 Worker 使用独立 Bot

部署

  1. 接入 Workers Builds,或本地部署。
  2. 构建:bun run build
  3. 部署:npx wrangler deploy
  4. 在控制台配置变量。
  5. 业务 Webhook:https://你的Worker域名
bun install && bun run build && bun run deploy

测试

curl -X POST "https://你的Worker地址" \
  -H "Content-Type: text/plain" \
  -d "来自 cfwebhook 的测试"

警告与免责声明

  • 本项目仅供个人 / 内部通知转发。部署与使用后果由使用者自行承担。
  • 禁止用于垃圾信息、钓鱼、滥用,或任何违反 Cloudflare 服务条款可接受使用政策Telegram 服务条款 的行为。
  • 请妥善保管 Bot Token 与 chat id。生产环境建议配置 WHITE_IPs。任何人只要能 POST 你的 Worker 地址,即可向你的 Telegram 会话推送消息。
  • Cloudflare / Telegram 可能因滥用或超额限流、封禁账号。本软件按 MIT「按现状」 提供,不作任何保证;作者对账号封禁、数据丢失或由此产生的损失 不承担责任

许可证

MIT © 2026 jack (shengshk)

About

Cloudflare Worker: forward POST webhook body to Telegram

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages