Deploying the Telegram Bot to Cloudflare Workers
Prerequisites
- Node.js v18+
- A Cloudflare account
- A Telegram bot token from @BotFather
1. Clone and Install Dependencies
git clone https://github.com/Ludho0/telegram-anonymous-to-channel-cloudflare.git
cd telegram-anonymous-to-channel-cloudflare
npm install
2. Authenticate with Cloudflare
npx wrangler login
This opens a browser window to authorize Wrangler with your Cloudflare account.
3. Create the D1 Database
npx wrangler d1 create telegram-bot-db
This outputs a database_id. Copy it and replace the value in wrangler.toml:
[[d1_databases]]
binding = "DB"
database_name = "telegram-bot-db"
database_id = "paste-your-database-id-here"
4. Apply the Database Schema
npm run db:init:remote
This runs migrations/0001_init.sql against your remote D1 database, creating the users and messages tables.
5. Get Your Bot Info
Open this URL in your browser (replace <TOKEN> with your bot token):
https://api.telegram.org/bot<TOKEN>/getMe
Copy the JSON object inside the "result" field. It looks like this:
{"id":123456789,"is_bot":true,"first_name":"MyBot","username":"MyBot","can_join_groups":true,"can_read_all_group_messages":false,"supports_inline_queries":true}
6. Set Secrets
npx wrangler secret put BOT_TOKEN
# Paste your bot token when prompted
npx wrangler secret put BOT_INFO
# Paste the JSON from step 5 when prompted
7. Configure Environment Variables
Edit wrangler.toml and update the [vars] section with your values. See the Configuration Reference for details on each variable.
8. Deploy
npx wrangler deploy
Wrangler prints the worker URL, e.g.:
https://telegram-bot.your-subdomain.workers.dev
9. Register the Webhook
Open this URL in your browser (or use curl):
https://telegram-bot.your-subdomain.workers.dev/setup
You should see a JSON response with "ok": true. This tells Telegram to send all updates to your worker.
10. Verify
Send /start to your bot on Telegram. It should respond with the welcome message.
Cron Trigger
The worker includes a cron trigger (*/1 * * * *) that runs every minute to notify users when their cooldown has expired. This is configured automatically in wrangler.toml and activates on deploy — no extra setup needed.
You can monitor cron executions in the Cloudflare dashboard under Workers & Pages > your worker > Triggers > Cron Triggers.
Updating
After making code changes:
npx wrangler deploy
The webhook URL stays the same — no need to re-register it.