This is a Telegram bot built with Cloudflare Workers and Node.js that allows users to upload photos and videos. The bot forwards the received media to a specified target user while rejecting non-media messages.
- ✅ Handles photos & videos only (rejects other message types)
- ✅ Forwards media to a specific Telegram user with a sender mention
- ✅ Supports captions and attaches them to forwarded media
- ✅ Runs on Cloudflare Workers for serverless deployment
- ✅ Logs received messages & bot events for debugging
- Cloudflare Workers (serverless execution)
- Telegram Bot API
- Node.js (ES Modules)
- Wrangler (for deployment)
- Environment Variables (for security)
- Open Telegram and start a chat with BotFather.
- Use
/newbot
to create a new bot and get your BOT_TOKEN. - Save the bot token for later.
git clone https://github.com/your-username/telegram-bot-cloudflare.git
cd telegram-bot-cloudflare
Rename .env.example
to .env
and fill in your bot credentials:
TELEGRAM_BOT_TOKEN=your-bot-token
TARGET_USER_ID=your-telegram-user-id
TELEGRAM_API_URL=https://api.telegram.org
- Install Cloudflare Wrangler CLI:
npm install -g wrangler
- Authenticate with Cloudflare:
wrangler login
- Deploy the worker:
wrangler publish
- Set the Telegram webhook:
curl -X POST "https://api.telegram.org/botYOUR_TELEGRAM_BOT_TOKEN/setWebhook?url=YOUR_WORKER_URL"
- Send a photo or video to the bot → It forwards it to the target user.
- Send anything else → The bot rejects it with a message.
- Use
/start
command → The bot sends a greeting message.
View real-time logs with:
wrangler tail
If the bot is not responding, check your webhook:
curl -X GET "https://api.telegram.org/botYOUR_TELEGRAM_BOT_TOKEN/getWebhookInfo"
This project is open-source under the MIT License.