A powerful (Non-Official) Telegram bot that transforms your Cloudflare management into a real-time control panel with analytics, security controls, DNS management, and instant cache operations - all from your phone.
- Traffic Overview: Requests, bandwidth, and visits with timeseries data
- Colo Performance: Top data centers by request volume
- Security Events: WAF actions and mitigated threats
- Cache Status: Hit/miss ratios and origin load
- IP Access Rules: Allow/block/challenge IPs and CIDRs
- Custom Firewall: Create rules with Cloudflare Expressions
- WAF Bypass: Skip WAF for specific paths/conditions
- Bot Protection: Toggle Bot Fight Mode & Super BFM instantly
- Full CRUD: Create, read, update, delete DNS records
- Bulk Operations: List and manage multiple records
- Proxy Toggle: Orange-cloud proxy on/off per record
- Cache Purge: Everything or selective URL purging
- Instant Actions: Sub-second rule deployment
- Adaptive Analytics: Uses Cloudflare's latest GraphQL schema
- Traffic Anomalies: Unusual request patterns
- Security Thresholds: High mitigation volumes
- Origin Health: Cache effectiveness monitoring
- Cloudflare Status: Real-time monitoring of Cloudflare status page for new incidents
- Origin Monitoring: Track origin server health and get alerts on 5xx errors
- Origin Served Alerts: Monitor cache misses and alert on low request volumes
- Python 3.8+
- Cloudflare zone with API access
- Telegram bot token from @BotFather
Use the automated setup script for the easiest installation:
Linux/macOS:
git clone https://github.com/sarat1kyan/cloudflare-telegram-bot.git
cd cloudflare-telegram-bot
chmod +x setup.sh
./setup.shWindows:
git clone https://github.com/sarat1kyan/cloudflare-telegram-bot.git
cd cloudflare-telegram-bot
setup.batThe setup script will:
- Check Python installation
- Install all dependencies automatically
- Guide you through configuration with a beautiful UI
- Validate all inputs (tokens, IDs, etc.)
- Test your configuration against Telegram and Cloudflare APIs
- Create a
.envfile with your settings - Optionally create a systemd service file (Linux)
Alternative: Manual Installation
- Clone & Install Dependencies
git clone https://github.com/sarat1kyan/cloudflare-telegram-bot.git
cd cloudflare-telegram-bot
pip install -r requirements.txt- Run Installation Script
python install.pyThe script will:
- Guide you through configuration with a beautiful UI
- Validate all inputs (tokens, IDs, etc.)
- Test your configuration against Telegram and Cloudflare APIs
- Create a
.envfile with your settings
If you prefer to configure manually:
- Clone & Install
git clone https://github.com/sarat1kyan/cloudflare-telegram-bot.git
cd cloudflare-telegram-bot
pip install -r requirements.txt- Create
.envfile
# Telegram
TELEGRAM_BOT_TOKEN=your_bot_token_here
ADMIN_USER_IDS=123456789,987654321 # Your Telegram user IDs
ALERT_CHAT_ID=-1001234567890 # Optional: group chat for alarms
# Cloudflare
CLOUDFLARE_API_TOKEN=your_api_token_here
CLOUDFLARE_ZONE_ID=your_zone_id_here- Cloudflare API Token Create token with these permissions:
- Zone.Zone - Read
- Zone.Analytics - Read
- Zone.DNS - Edit
- Zone.Firewall Services - Edit
- Zone.Cache Purge - Purge
- Under "Zone Resources", select "Include - Specific zone"
- Select your zone from the dropdown
- "Read all resources" alone is NOT sufficient - you need specific zone scope
📖 See API_TOKEN_SETUP.md for detailed step-by-step instructions
4.1 Run the Bot | Verbose Debug Mode
nohup python bot.py > output.log 2>&1 &4.2 For Production run the bot as a service
| Command | Description | Example |
|---|---|---|
/start |
Main menu with inline keyboard | /start |
/status |
Zone overview & plan details | /status |
/verify |
Data accuracy check | /verify 24 |
/whoami |
Show current chat context | /whoami |
| Command | Description | Example |
|---|---|---|
/ip_list |
List access rules | /ip_list block |
/ip_allow |
Whitelist IP/CIDR | /ip_allow 192.168.1.1 trusted-vpn |
/ip_block |
Block IP/CIDR | /ip_block 10.0.0.0/8 bad-actor |
/ip_delete |
Remove rule by ID/IP | /ip_delete 10.0.0.0/8 |
/rule_block |
Block with expression | /rule_block (http.request.uri.path contains "/wp-admin") -- block wp-admin |
/rule_bypass_waf |
Skip WAF for matches | /rule_bypass_waf (http.request.uri.path contains "/api/") -- bypass api |
/rules |
List firewall rules | /rules |
| Command | Description | Example |
|---|---|---|
/dns_list |
List all records | /dns_list api |
/dns_add |
Create record | /dns_add A subdomain 192.168.1.1 300 true |
/dns_upd |
Update record | /dns_upd rec123 content=192.168.1.2 proxied=false |
/dns_del |
Delete record | /dns_del rec123 |
| Command | Description | Example |
|---|---|---|
/cache_purge |
Purge cache | /cache_purge all |
/cache_purge |
Purge URLs | /cache_purge https://site.com/page1 |
/toggle_bfm |
Bot Fight Mode | /toggle_bfm on |
/toggle_sbfm |
Super BFM | /toggle_sbfm off |
| Command | Description | Example |
|---|---|---|
/alarms_on |
Enable monitoring | /alarms_on |
/alarms_off |
Disable monitoring | /alarms_off |
| Command | Description | Example |
|---|---|---|
/origin_add |
Add origin URL to monitor | /origin_add https://example.com/api/health 60 10 |
/origin_remove |
Remove origin from monitoring | /origin_remove https://example.com/api/health |
/origin_list |
List all monitored origins | /origin_list |
/origin_check |
Manually check origin health | /origin_check https://example.com/api/health |
Origin Monitoring Features:
- ✅ Full URL support - Monitor specific paths (e.g.,
https://example.com/api/health) - ✅ Smart error detection - Ignores non-critical 404s (favicon, robots.txt, etc.)
- ✅ Configurable intervals - Set custom check intervals per origin
- ✅ Failure tracking - Tracks consecutive failures and success rates
- ✅ Automatic alerts - Sends Telegram alerts on critical errors
- ✅ Statistics - Shows success rate and check history
Examples:
# Monitor homepage
/origin_add https://example.com
# Monitor API endpoint
/origin_add https://example.com/api/health 120 15
# Monitor specific admin path
/origin_add https://example.com/payment/admin 60 10
# Check status manually
/origin_check https://example.com/api/healthNote: Only 5xx server errors trigger alerts. 4xx client errors (404, 403, etc.) are ignored as they indicate client-side issues, not server problems.
The bot can monitor requests served by origin (cache misses) and alert when they drop below configured thresholds. This helps detect:
- Unusually high cache hit rates (good!)
- Reduced traffic patterns
- Potential origin server issues
Setup:
# Set thresholds for different time periods
/origin_alert_set 30m 1000 # Alert if < 1000 requests in last 30 minutes
/origin_alert_set 6h 5000 # Alert if < 5000 requests in last 6 hours
/origin_alert_set 24h 20000 # Alert if < 20000 requests in last 24 hours
# Enable alerts
/origin_alert_enable
# Check current status
/origin_alert_status
# Manually check against thresholds
/origin_alert_checkFeatures:
- ✅ Configurable thresholds for 30m, 6h, and 24h periods
- ✅ Automatic alerts when requests drop below threshold
- ✅ Recovery notifications when requests return to normal
- ✅ Interactive button menu for easy management
- ✅ Persistent state across bot restarts
Access via UI: Click the "🔔 Origin Alerts" button in the main menu to access the interactive management interface.
The bot automatically monitors the Cloudflare status page (https://www.cloudflarestatus.com/) and sends alerts when new incidents are posted. No configuration needed - it works automatically once the bot is running!
/ip_block 45.155.205.233 bruteforce-attempt/rule_bypass_waf (http.request.uri.path contains "/api/") -- bypass api paths/dns_add CNAME cdn mysite.workers.dev 1 true/cache_purge all# Monitor homepage (default: 60s interval, 10s timeout)
/origin_add https://example.com
# Monitor API endpoint with custom settings
/origin_add https://example.com/api/health 120 15
# Monitor specific admin path
/origin_add https://example.com/payment/admin 60 10
# Check status manually
/origin_check https://example.com/api/health
# List all monitored origins with statistics
/origin_list
# Remove origin from monitoring
/origin_remove https://example.com/api/healthSmart Error Handling:
- ✅ 404 errors for
/favicon.ico,/robots.txtare automatically ignored - ✅ Only critical errors (5xx, connection failures) trigger alerts
- ✅ Success rate tracking shows reliability over time
The bot can monitor requests served by origin (cache misses) and alert when they drop below configured thresholds. This helps detect:
- Unusually high cache hit rates (good!)
- Reduced traffic patterns
- Potential origin server issues
Setup:
# Set thresholds for different time periods
/origin_alert_set 30m 1000 # Alert if < 1000 requests in last 30 minutes
/origin_alert_set 6h 5000 # Alert if < 5000 requests in last 6 hours
/origin_alert_set 24h 20000 # Alert if < 20000 requests in last 24 hours
# Enable alerts
/origin_alert_enable
# Check current status
/origin_alert_status
# Manually check against thresholds
/origin_alert_checkFeatures:
- ✅ Configurable thresholds for 30m, 6h, and 24h periods
- ✅ Automatic alerts when requests drop below threshold
- ✅ Recovery notifications when requests return to normal
- ✅ Interactive button menu for easy management
- ✅ Persistent state across bot restarts
Access via UI: Click the "🔔 Origin Alerts" button in the main menu to access the interactive management interface.
┌──────────────────┐ ┌────────────────────┐ ┌─────────────────┐
│ Telegram │ │ PocketCF │ │ Cloudflare │
│ -------- │ │ -------- │ │ ---------- │
│ Commands │ ◄──► │ bot.py │◄──►│ REST API │
│ Callbacks │ │ - Handlers │ │ - DNS │
│ Inline UI │ │ - Admin gate │ │ - Firewall │
└──────────────────┘ │ - Analytics │ │ - Analytics │
│ │ │ │
│ cloudflare_api.py │ │ GraphQL API │
│ - REST wrapper │ │ - Adaptive │
│ - GraphQL client │ │ - Real-time │
└────────────────────┘ └─────────────────┘
Edit config.py to support multiple zones:
ZONES = {
"production": "zone_id_1",
"staging": "zone_id_2"
}# In bot.py - modify these constants
MITIGATIONS_24H_THRESHOLD = 50_000 # Alert if > 50k mitigations
ORIGIN_SERVED_24H_MIN = 1_000_000 # Alert if < 1M origin requestsLocal Development
python bot.pyDocker
FROM python:3.9-slim
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
CMD ["python", "bot.py"]Systemd Service
[Unit]
Description=Cloudflare Telegram Bot
After=network.target
[Service]
Type=simple
User=ubuntu
WorkingDirectory=/opt/cloudflare-bot
ExecStart=/usr/bin/python3 bot.py
Restart=always
[Install]
WantedBy=multi-user.target- Admin-Only: Write commands require
ADMIN_USER_IDSauthorization - API Scoping: Cloudflare tokens use principle of least privilege
- Input Validation: All user inputs are sanitized before API calls
- No Data Storage: The bot doesn't persist any sensitive information
Bot doesn't start
- Check
TELEGRAM_BOT_TOKENformat - Verify Python version >= 3.8
- Ensure all dependencies installed
API calls fail
- Validate
CLOUDFLARE_API_TOKENpermissions - Check
CLOUDFLARE_ZONE_IDformat - Verify zone exists in account
No analytics data
- Ensure zone has traffic
- Check token has Analytics read permissions
- Wait a few minutes after zone creation
Enable verbose logging:
import logging
logging.basicConfig(level=logging.DEBUG)- Fork the repository
- Create feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push branch (
git push origin feature/amazing-feature) - Open Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
This is a non-official, community-created project
| Aspect | Status |
|---|---|
| Official Cloudflare Product | ❌ No |
| Created by Cloudflare | ❌ No |
| Supported by Cloudflare | ❌ No |
| Community Project | ✅ Yes |
| Open Source | ✅ Yes |
| Use at Your Own Risk | ✅ Yes |
This Telegram bot is my personal project that I built to manage my own Cloudflare zones more efficiently. I'm sharing the code publicly in case others find it useful, but please understand:
- NOT developed, endorsed, or supported by Cloudflare
- NOT an official Cloudflare product or service
- NOT affiliated with Cloudflare, Inc. in any way
- Built for my own use cases and specific workflows
- Shared as-is for educational and community purposes
- No guarantees of functionality, security, or maintenance
- No SLA or official support channels
- Test thoroughly before using in production
- Review all code for security and compatibility
- Monitor carefully when making configuration changes
- You are responsible for any changes made to your Cloudflare account
For official Cloudflare tools and services, please visit:
This project has no official support. For issues:
- 📋 Create a GitHub Issue
- 🔍 Search existing discussions
- 📖 Review the code and documentation
For official Cloudflare support:
- 🎫 Contact Cloudflare Support
- 💬 Join Cloudflare Community
This project is maintained by an individual developer in their spare time. Cloudflare® is a registered trademark of Cloudflare, Inc. This project is not affiliated with Cloudflare, Inc.
⭐ Star this repo if you found it helpful!
Note: Always test management commands in staging before production use. The bot has immediate effect on your Cloudflare configuration.