GitHub Bot
Deploy GitHub bot as webhook handler on Cloudflare Workers. GitHub App setup, PAT token, webhook secret, PR/issue integration.
GitHub Bot
Back to: Cloudflare Deploy
TL;DR (3 mins)
GitHub App → PAT/webhook secret → bun scripts/config.ts github → bun run deploy:github → @duyetbot hi!
Quick Steps
- Developer Settings → New GitHub App
- Configure permissions: Issues/PRs read/write
bun scripts/config.ts github(PAT + webhook secret)bun run deploy:github- Install app on repository
- Test: Comment
@duyetbot hello→ Bot responds!
Quick Checklist
- GitHub App created
- Permissions: Issues/PRs read/write
-
bun scripts/config.ts github -
bun run deploy:github - App installed on repository
- Test:
@duyetbot hiresponds
Full Guide
GitHub Bot Deployment
Back to: Deployment Overview
Deploy the GitHub Bot as a serverless webhook handler on Cloudflare Workers with Durable Objects for session persistence.
Overview
The GitHub bot provides:
- Webhook handler for @mentions and PR reviews
- AI agent powered by OpenRouter/Anthropic via Cloudflare Workers
- Session persistence via Durable Objects
- Built with Hono + Cloudflare Agents SDK
Recommended Approach: For the most robust and scalable bot, register a GitHub App. You specify the webhook URL and subscribe to specific events during the registration process. This approach supports multiple installations and repositories.
Prerequisites
- Cloudflare account with Workers enabled
- GitHub account for creating GitHub App
- LLM API key (OpenRouter or Anthropic)
Step 1: Configure Environment
All environment variables are configured in a single .env.local file at the project root.
Edit .env.local with your values:
Getting API Keys
GitHub Token:
- Go to https://github.com/settings/tokens
- Generate new token (classic) with scopes:
repo,issues:write,pull_requests:write
OpenRouter API Key:
- Go to https://openrouter.ai/keys
- Create new key
Anthropic API Key:
- Go to https://console.anthropic.com/settings/keys
- Create new key
Step 2: Deploy to Cloudflare Workers
This command will:
- Build the GitHub bot package
- Deploy to Cloudflare Workers
- Set all secrets from
.env.localviawrangler secret put
Note the deployed URL:
Step 3: Register GitHub App
Now that you have your webhook URL, register a GitHub App:
-
Fill in basic info:
- GitHub App name:
duyetbot(or your preferred name) - Homepage URL:
https://github.com/your-username/duyetbot-agent
- GitHub App name:
-
Configure webhook:
- Webhook URL:
https://duyetbot-github.<your-subdomain>.workers.dev/webhook - Webhook secret: Same value as
GITHUB_WEBHOOK_SECRETin.env.local - Check Active
- Webhook URL:
-
Set permissions:
- Repository permissions:
- Issues: Read & Write
- Pull requests: Read & Write
- Contents: Read
- Organization permissions: None required
- Repository permissions:
-
Subscribe to events:
- Issue comment
- Issues
- Pull request
- Pull request review comment
-
Where can this GitHub App be installed?
- Select Only on this account for personal use
- Select Any account if you want others to install it
-
Click Create GitHub App
Step 4: Install GitHub App
After creating the app:
- Go to your GitHub App settings page
- Click Install App in the left sidebar
- Select your account
- Choose repositories:
- All repositories or
- Only select repositories (recommended for testing)
- Click Install
Step 5: Test the Bot
- Go to an installed repository
- Create a new issue or open an existing one
- Comment:
@duyetbot hello - The bot should respond within seconds
Verify Webhook Delivery
- Go to your GitHub App settings -> Advanced -> Recent Deliveries
- Check that deliveries show green checkmarks
- If red X, click to see error details
Environment Variables
| Variable | Required | Description |
|---|---|---|
GITHUB_TOKEN | Yes | GitHub personal access token |
OPENROUTER_API_KEY | Yes* | OpenRouter API key |
ANTHROPIC_API_KEY | Yes* | Anthropic API key |
MODEL | No | Model name (default: x-ai/grok-4.1-fast) |
GITHUB_WEBHOOK_SECRET | No | Secret for webhook verification |
*At least one LLM provider API key is required.
Monitoring & Logs
Troubleshooting
Webhook not received
- Check GitHub App settings -> Advanced -> Recent Deliveries
- Verify webhook URL matches your deployed Worker URL
- Verify webhook secret matches
GITHUB_WEBHOOK_SECRET - Ensure webhook is marked as Active
Bot not responding
- Check logs:
npx wrangler tail --name duyetbot-github - Verify
GITHUB_TOKENhas correct permissions - Verify LLM API key is set (
OPENROUTER_API_KEYorANTHROPIC_API_KEY) - Ensure bot is installed on the repository
401 Unauthorized
- Webhook secret mismatch - ensure
GITHUB_WEBHOOK_SECRETmatches the secret in GitHub App settings - Re-run
bun run deploy:githubto update secrets
LLM errors
- Check your API key is valid and has credits
- Verify
MODELis supported by your provider - Check Cloudflare Worker logs for detailed errors
Security Best Practices
- Never commit secrets - Use
.env.localwhich is gitignored - Use webhook secrets - Prevents unauthorized webhook calls
- Rotate tokens periodically - Update in
.env.localand redeploy - Limit app permissions - Only request necessary scopes
- Monitor webhook deliveries - Check for failed deliveries
Alternative Deployments
For Docker-based deployments (Railway, Fly.io, Render, AWS), see the legacy documentation. Cloudflare Workers is recommended for:
- Lower latency (edge deployment)
- Built-in Durable Objects for state
- Generous free tier
- Simpler deployment
Updating the Bot
To update after code changes:
This will rebuild and redeploy. Secrets are preserved.
Next Steps
- Telegram Bot Deployment - Deploy the Telegram bot
- Memory MCP Deployment - Add session persistence
- Deployment Overview - All components