Add a platform-aware route target system so a single route can forward to several destinations at once (e.g. a Discord channel and a Telegram group). Route.target becomes Route.targets[] with per-entry platform, channelId/threadId for Discord and chatId/topicId for Telegram; the legacy single-target format is normalized on load and accepted by the admin API. Implement the Telegram driver with HTML rendering and Bot API sendMessage (chat_id + message_thread_id for topics, retry on 429/5xx), plus /gh commands served over POST /telegram/webhook: login, logout, comment, merge and close. The comment/merge/close commands resolve the issue or PR from the replied-to notification message. OAuth binding now stores a D1 telegram_links mapping and replies with a confirmation. Sync the Telegram webhook from the scheduled trigger via setWebhook.
5.5 KiB
Deployment
Cloudflare Setup
1. Create KV Namespace
npx wrangler kv namespace create KV
This outputs a namespace ID. Update wrangler.jsonc with the ID:
{
"kv_namespaces": [
{
"binding": "KV",
"id": "your-namespace-id",
},
],
}
2. Set Secrets
npx wrangler secret put GITHUB_WEBHOOK_SECRET
npx wrangler secret put GITHUB_APP_ID
npx wrangler secret put GITHUB_PRIVATE_KEY # PKCS#8 PEM (BEGIN PRIVATE KEY)
npx wrangler secret put GITHUB_CLIENT_ID
npx wrangler secret put GITHUB_CLIENT_SECRET
npx wrangler secret put DISCORD_TOKEN
npx wrangler secret put DISCORD_PUBLIC_KEY # Discord app public key (Developer Portal) — required for interactions
npx wrangler secret put TELEGRAM_TOKEN # Telegram bot token (BotFather) — required for Telegram routes
npx wrangler secret put ADMIN_USER_IDS # comma-separated GitHub IDs/logins allowed into the Web UI
::: tip Target channels are configured per route
There is no global channel secret. Each route in the Web UI declares its own target channel (and optional thread), so DISCORD_CHANNEL_ID is not needed.
:::
::: warning GitHub App private key must be PKCS#8
GitHub issues private keys in PKCS#1 format (BEGIN RSA PRIVATE KEY). Cloudflare Workers' JWT signing requires PKCS#8. Convert first:
openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt \
-in your-app.private-key.pem -out gh_pk_pkcs8.pem
Then upload gh_pk_pkcs8.pem as GITHUB_PRIVATE_KEY.
:::
Discord interactions arrive via the HTTPS Interactions Endpoint, so set DISCORD_PUBLIC_KEY and point the Interactions Endpoint URL at https://your-domain/discord/interactions. See Interactions Endpoint below.
3. Deploy
npx wrangler deploy
Your worker is now live at https://webhooker.<your-subdomain>.workers.dev.
4. Configure GitHub Webhook
- Go to your GitHub App settings
- Set Webhook URL to
https://webhooker.<your-subdomain>.workers.dev/webhook - Set Webhook secret to match
GITHUB_WEBHOOK_SECRET
GitHub App Setup
1. Create App
- Go to https://github.com/settings/apps/new
- Fill in:
- GitHub App name:
WebHooker(or your choice) - Homepage URL: your domain
- Webhook URL:
https://your-domain/webhook - Webhook secret: generate and copy to
GITHUB_WEBHOOK_SECRET
- GitHub App name:
- Set permissions:
- Repository permissions: Contents (read), Issues (write), Pull requests (write), Metadata (read)
- Organization permissions: Members (read) — if needed
- Subscribe to events (all 23 supported):
- Push, Pull request, Issues, Issue comment, Workflow run, Release, Create, Delete, Star, Fork, Check run, Pull request review, Pull request review comment, Commit comment, Deployment status, Member, Label, Milestone, Discussion, Discussion comment, Repository, Code scanning alert, Dependabot alert
- Generate private key → save contents to
GITHUB_PRIVATE_KEYenv var
2. Install App
- After creation, go to the App settings page
- Click "Install App" → select org/user
- Choose repositories to monitor
3. Configure OAuth
- Go to App → OAuth settings
- Set Callback URL:
https://your-domain/auth/github/callback - Copy Client ID and Client Secret to env
Discord Bot Setup
-
Create a new application → go to Bot section
-
Copy the bot token to
DISCORD_TOKEN -
Invite the bot with the
botandapplications.commandsscopes and theView Channels+Send Messages+Send Messages in Threadspermissions (combined integer274877910016):https://discord.com/oauth2/authorize?client_id=YOUR_BOT_CLIENT_ID&permissions=274877910016&scope=bot+applications.commands -
Configure target channels per route in the Web UI (
/admin) — no global channel ID is required.
Interactions Endpoint
Messages are sent via the Discord REST API, so pushing works with just DISCORD_TOKEN. Interactions (slash commands, buttons, modals) arrive through the HTTPS Interactions Endpoint:
- Copy the application Public Key (Developer Portal → General Information) to
DISCORD_PUBLIC_KEY. - Set the Interactions Endpoint URL to
https://your-domain/discord/interactions. - Every interaction request is verified with Ed25519 signatures (
X-Signature-Ed25519overX-Signature-Timestamp + body).
The /gh slash command and the GitHub: 添加/编辑/删除评论 message commands are synced by the scheduled trigger (every 5 minutes): per-guild for instant availability, plus a global registration (24h dedup, ~1h propagation). The bot never connects to the Discord Gateway, so it shows as offline — messaging is unaffected (always REST).
Users run /gh login to link their GitHub account and can then comment on issues/PRs as themselves. See the README for the full command reference.
Custom Domain (Optional)
To use a custom domain instead of *.workers.dev:
- Go to your Cloudflare Worker settings
- Add a custom domain or route
- Update
BASE_URLto match
Docker
A Dockerfile is provided for containerized deployments (e.g., behind a reverse proxy):
docker build -t webhooker .
docker run -p 8787:8787 --env-file .env webhooker
Note: Docker mode runs without KV and other Cloudflare storage. Use Cloudflare deployment for full functionality.