简体中文 | English
This is a two-way private messaging Telegram bot based on Cloudflare Worker / Vercel that can be easily deployed without requiring a server, database, or your own domain name.
Users can send messages to you through your bot, and you can reply directly to these messages, enabling two-way communication.
- 🔄 Two-Way Communication - Easily receive and reply to messages from users
- 💾 No Database Required - Completely stateless design, zero storage costs
- 🌐 No Personal Domain Required - Use the free domain provided by Cloudflare Worker
- 🚀 Lightweight Deployment - Complete setup within minutes
- 💰 Zero Running Cost - Operates within Cloudflare's free plan limits
- 🔒 Secure and Reliable - Uses official Telegram API and secure tokens
- 🔌 Multiple Bot Support - Register multiple private chat bots with a single deployment
- 🛠️ Multiple Deployment Options - GitHub one-click deploy, Vercel one-click deploy, Wrangler CLI, and Dashboard deployment
- Cloudflare account
- Telegram account
Note
You need to know your Telegram user ID (UID), which is a string of numbers used to forward messages to you.
You can get it by:
- Sending any message to @userinfobot, which will tell you your UID
Note down your numeric ID (e.g., 123456789).
- Search for and open @BotFather in Telegram
- Send the
/newbotcommand - Follow the prompts to set your bot's name and username (username must end with
bot) - Upon success, BotFather will send you a Bot API Token (format similar to:
000000000:ABCDEFGhijklmnopqrstuvwxyz) - Securely save this Bot API Token
This is the simplest deployment method, requiring no local development environment.
- Fork or clone this repository to your GitHub account
- Log in to the Cloudflare Dashboard
- Navigate to the Workers & Pages section
- Click Create Application
- Select Connect to Git
- Authorize Cloudflare to access your GitHub and select your forked repository
- Configure deployment settings:
- Project name: Set your project name (e.g.,
open-wegram-bot) - Production branch: Select your main branch (usually
master) - Keep other settings as default
- Project name: Set your project name (e.g.,
- Configure environment variables:
- Click on Environment Variables
- Add
PREFIX(e.g.,public) - Add
SECRET_TOKEN(must contain uppercase and lowercase letters and numbers, at least 16 characters long), and mark it as Encrypted
- Click Save and Deploy to complete the deployment
The advantage of this method is that when you update your GitHub repository, Cloudflare will automatically redeploy your Worker.
Vercel provides another simple deployment option, also supporting automatic deployments from GitHub.
- Click the "Deploy with Vercel" button below:
- Follow Vercel's prompts to complete the deployment process
- Configure environment variables:
PREFIX: Set to your desired URL prefix (e.g.,public)SECRET_TOKEN: Set a secure token (must contain uppercase and lowercase letters and numbers, at least 16 characters long)
- After deployment, Vercel will provide a domain like
your-project.vercel.app
The advantages of Vercel deployment are simplicity, automatic updates, and built-in HTTPS.
If you're comfortable with command-line tools, you can use the Wrangler CLI for deployment.
- Ensure you have Node.js and npm installed
- Clone this repository:
git clone https://github.com/wozulong/open-wegram-bot.git cd open-wegram-bot - Install dependencies:
npm install
- Deploy the Worker:
npx wrangler deploy
- Set your Secret Token:
npx wrangler secret put SECRET_TOKEN
If you prefer not to use GitHub or command-line tools, you can create the Worker directly in the Cloudflare Dashboard.
- Log in to the Cloudflare Dashboard
- Navigate to the Workers & Pages section
- Click Create Worker
- Delete the default code and paste the code from this project's
src/worker.jsandsrc/core.js - Click Save and Deploy
- Add environment variables in the Worker settings:
PREFIX(e.g.,public)SECRET_TOKEN(must contain uppercase and lowercase letters and numbers, at least 16 characters long)
Deno provides another simple deployment method, which also supports automatic deployment from GitHub repositories.
- Fork this repository to your GitHub account
- Log in to Deno Deploy and click New Project
- Select your authorized GitHub account and choose your forked repository
- Under Project Configuration -> Entrypoint, select
deno/server.js - Click the Deploy Project button and wait for the deployment to complete
- Click the Add environment variables button at the bottom of the page to add environment variables:
PREFIX: URL prefix, for examplepublicSECRET_TOKEN: Encryption token, must include uppercase and lowercase letters and numbers, with a minimum length of 16 characters
- After clicking the Save (2 new) button to save the environment variables, the deployment is complete. The domain name provided by Deno is above the environment variables, such as
project-name.deno.dev
Netlify provides another simple deployment method, which also supports automatic deployment from GitHub repositories.
- Fork this repository to your GitHub account
- Log in to Netlify and click Add new site -> Add new site -> Import an existing project
- Select your authorized GitHub account and choose your forked repository
- Fill in the Site name and add environment variables:
- Click Add environment variables -> Add key/value pairs
NETLIFY_PREFIX: URL prefix, for examplepublicSECRET_TOKEN: Encryption token, must include uppercase and lowercase letters and numbers, with a minimum length of 16 characters
- Click the Deploy xxx button, and after the deployment is complete, you can see the Netlify-provided domain name under the site name, such as
site-name.netlify.app
EdgeOne provides another simple deployment method, which also supports automatic deployment from GitHub repositories.
- Fork this repository to your GitHub account
- Log in to EdgeOne Pages and click Create Project -> Import Git Repository
- Select the authorized GitHub account and choose your forked repository
- Add environment variables:
EDGEONE_PREFIX: URL prefix, for examplepublicSECRET_TOKEN: Encryption token, must include uppercase and lowercase letters and numbers, with a minimum length of 16 characters
- Click the Start Deployment button, and after the deployment is complete, go to Project Settings -> Domain Management to add a custom domain. The default domain
project-name.edgeone.apponly supports preview, and its validity period is only 3 hours!
Tip
Binding a custom domain to your Worker provides more convenient access!
Cloudflare allows you to bind your own domain to your Worker, enabling you to access the Worker through your domain.
- In your Cloudflare dashboard, add your domain
- In the Workers & Pages section, select your worker
- Click on Triggers and then Add Custom Domain
- Follow the instructions to bind your domain
After binding, you can use addresses like https://your-domain.com/YOUR_PREFIX/install/... to register/uninstall bots.
After deploying the Worker, you'll get a URL like:
- GitHub integration:
https://your-project-name.username.workers.dev - Vercel deployment:
https://your-project.vercel.app - Wrangler/Dashboard:
https://your-worker-name.your-subdomain.workers.dev - Deno deployment:
https://project-name.deno.dev - Netlify deployment:
https://site-name.netlify.app - EdgeOne deployment:
https://your.custom.domain
Now you need to register your Bot:
- Visit the following URL in your browser to register your Bot (replace the parameters accordingly):
https://your-worker-url/YOUR_PREFIX/install/YOUR_TELEGRAM_UID/BOT_API_TOKEN
For example:
https://open-wegram-bot.username.workers.dev/public/install/123456789/000000000:ABCDEFGhijklmnopqrstuvwxyz
- If you see a success message, your Bot has been successfully registered
Note
One Worker instance can register multiple different Bots! Just repeat the above registration steps using different Bot API Tokens.
Once set up, any messages sent to your Bot will be forwarded to your Telegram account, with sender information displayed below the message.
To reply to a user's message:
- Find the forwarded message you want to reply to in Telegram
- Reply directly to that message (using Telegram's reply function)
- Your reply will be automatically sent to the original sender
If you want to uninstall the Bot, visit the following URL (replace with your parameters):
https://your-worker-url/YOUR_PREFIX/uninstall/BOT_API_TOKEN
Important
Please keep your Bot API Token and Secret Token secure, as they are crucial to your service's security.
Warning
Do not change your Secret Token once it's set! After changing, all registered bots will stop working properly as they cannot match the original token. If you need to change it, all bots will need to be re-registered.
- Choose a secure and memorable Secret Token during initial setup
- Avoid using simple or common prefix names
- Do not share sensitive information with others
Note
Cloudflare Worker's free plan has a limit of 100,000 requests per day.
For a personal private chat bot, this limit is usually generous enough. Even if you register multiple bots, you're unlikely to reach this limit unless your bots are extremely active.
If you anticipate higher usage, consider upgrading to Cloudflare's paid plan.
- Messages not forwarded: Ensure the Bot is correctly registered and check the Worker logs
- Cannot access registration URL: Try using a custom domain to solve access issues
- Reply message fails: Check if you're correctly using Telegram's reply function
- Registration fails: Ensure your
SECRET_TOKENmeets the requirements (contains uppercase and lowercase letters and numbers, at least 16 characters long) - GitHub deployment fails: Check if your environment variables are correctly set and repository permissions are correct
- Worker deployment fails: Check your Wrangler configuration and ensure you're logged in to Cloudflare
If you have any questions, suggestions, or want to contribute code, please submit an Issue/PR or contact me at:
- GPL v3, hoping you'll improve and continue to open source rather than rebranding and closing the source. Thank you.
Hope this tool makes your Telegram private messaging experience more convenient! 🎉 If you just want to use it directly, please visit @WegramBot