A production-ready Telegram support relay bot. Every user who messages your bot gets their own Forum Topic in your private admin group β giving your support team a clean, organised inbox like a helpdesk.
User DMs Bot β Bot creates a Forum Topic in your group
Admin replies in Topic β Bot forwards reply back to User
- π¬ Two-way messaging β users DM the bot; admin replies from the group topic are forwarded back
- π Full media support β text, photos, videos, files, voice, audio, stickers, GIFs, video circles, location, contacts
- π« Ticket lifecycle β open, close, reopen sessions
- π« Ban / Unban β block spamming users instantly from within the topic
- π’ Broadcast β send an announcement to all active users at once
- π Stats dashboard β view session counts and daily activity
- β‘ Rate limiting β prevent message flooding (configurable)
- π Delivery receipts β emoji reaction confirms message was forwarded
- ποΈ SQLite persistence β all sessions, bans, and timestamps stored locally
- π Webhook-based β production-ready, no polling
- Prerequisites
- Step 1 β Create your Telegram Bot
- Step 2 β Set up the Support Group
- Step 3 β Get your IDs
- Step 4 β Deploy to Render (recommended)
- Step 5 β Configure Environment Variables
- Local Testing
- Commands Reference
- Troubleshooting
- A free Telegram account
- A free Render account (for hosting)
- Python 3.10+ (only needed for local testing)
- Open Telegram and search for @BotFather.
- Send
/newbotand follow the prompts:- Choose a name (e.g.
My Support Bot) - Choose a username ending in
bot(e.g.mysupport_bot)
- Choose a name (e.g.
- BotFather will reply with your Bot Token β copy and save it.
Example: 7463401204:AAEHXf_PD9evTlH9RMhPqeyDA4KSAmjuDGA
Important
Keep your Bot Token secret. Never share it or commit it to Git.
- Create a new private group in Telegram (e.g. "My Support Inbox").
- Enable Topics in the group:
- Open group β tap the group name β Edit β toggle Topics on.
- Add your bot to the group as an Administrator:
- Go to group β tap the group name β Administrators β Add Admin β search your bot.
- Enable the Manage Topics permission for it.
You need two IDs: Group ID and your personal Admin User ID.
- Forward any message from your support group to @userinfobot.
- It will reply with the group details. The ID will look like
-1002234879626.
- Message @userinfobot directly (no forwarding).
- It will show your personal ID (e.g.
7093051689).
If you have multiple admins, collect all their User IDs β you'll enter them comma-separated later.
Render offers a free tier that is perfect for this bot.
git clone https://github.com/Artemis43/telegram-support-bot.git
cd telegram-support-botPush it to your own GitHub account (Render deploys from GitHub).
-
Go to render.com and log in.
-
Click New β Web Service.
-
Connect your GitHub account and select your forked repository.
-
Fill in the following settings:
Setting Value Name telegram-support-bot(or any name you like)Region Choose one closest to you Branch mainRuntime Python 3Build Command pip install -r requirements.txtStart Command gunicorn main:flask_appInstance Type Free -
Click Create Web Service β Render will build and deploy the app.
-
Once deployed, copy your app's public URL from the top of the page:
https://your-app-name.onrender.com
In your Render service, go to Environment and add the following variables:
| Key | Value |
|---|---|
TELEGRAM_BOT_TOKEN |
Your bot token from BotFather |
TELEGRAM_GROUP_ID |
Your group ID (e.g. -1002234879626) |
TELEGRAM_ADMINS |
Your user ID(s), comma-separated (e.g. 111111,222222) |
WEBSITE_URL |
Your Render app URL (e.g. https://your-app-name.onrender.com) |
Click Save Changes β Render will automatically redeploy.
Note
After saving, watch the Logs tab. You should see:
Webhook set: https://your-app-name.onrender.com/webhook/...
PTB setup complete. Loop running forever.
That means the bot is live!
Open Telegram, go to your bot and send /start. You should get a welcome message, and a new topic should appear in your support group. π
All configuration is done through environment variables. Here is the full reference:
| Variable | Required | Default | Description |
|---|---|---|---|
TELEGRAM_BOT_TOKEN |
β | β | Bot token from @BotFather |
TELEGRAM_GROUP_ID |
β | β | Your forum-enabled group ID |
TELEGRAM_ADMINS |
β | β | Comma-separated admin user IDs |
WEBSITE_URL |
β | β | Your public HTTPS deployment URL |
PORT |
β | 8443 |
Flask server port |
DB_PATH |
β | bot_data.db |
Path to the SQLite database file |
RATE_LIMIT_MAX |
β | 5 |
Max messages a user can send per window |
RATE_LIMIT_WINDOW |
β | 10 |
Rate limit time window in seconds |
You can test the bot on your local machine without deploying.
git clone https://github.com/Artemis43/telegram-support-bot.git
cd telegram-support-bot
python -m venv venv
# Windows:
.\venv\Scripts\Activate.ps1
# macOS/Linux:
source venv/bin/activate
pip install -r requirements.txtcp .env.example .envOpen .env and fill in your values:
TELEGRAM_BOT_TOKEN=your_bot_token_here
TELEGRAM_GROUP_ID=-1002234879626
TELEGRAM_ADMINS=your_user_id_here
PORT=8443
WEBSITE_URL= # fill in after Step 3Telegram needs a public HTTPS URL to send updates. Use a free SSH tunnel:
In a new terminal window, run:
# Windows (use 127.0.0.1 explicitly to avoid IPv6 issues):
ssh -R 80:127.0.0.1:8443 localhost.run
# macOS/Linux:
ssh -R 80:localhost:8443 localhost.runIt will output a URL like:
https://4de96ba117e7a3.lhr.life tunneled with tls termination
Copy that URL and paste it into your .env:
WEBSITE_URL=https://4de96ba117e7a3.lhr.lifeWarning
Windows users: Always use 127.0.0.1 instead of localhost in the SSH command.
On Windows, localhost often resolves to the IPv6 address [::1], but Flask listens on IPv4 127.0.0.1, which causes the tunnel to silently drop all requests.
python main.pyYou should see:
Webhook set: https://4de96ba117e7a3.lhr.life/webhook/...
PTB setup complete. Loop running forever.
Starting Flask dev server on port 8443β¦
Keep both terminal windows open β closing the tunnel will stop webhook delivery.
| Command | Description |
|---|---|
/start |
Start a new support session (or resume an existing one) |
/help |
Show available commands |
Run these from inside the specific user's forum topic in your support group:
| Command | Description |
|---|---|
/close |
β Mark ticket as resolved β notifies the user and archives the topic |
/ban |
π« Ban the user β they can no longer send messages via the bot |
/unban |
β Lift the ban β user is notified and can open a new session |
Run these by DMing the bot directly (only works if your ID is in TELEGRAM_ADMINS):
| Command | Description |
|---|---|
/stats |
π Show total sessions, active sessions, banned users, today's activity |
/broadcast <message> |
π’ Send a message to all non-banned users |
Bot doesn't respond to /start
- Check that the webhook is registered: open
https://api.telegram.org/bot<YOUR_TOKEN>/getWebhookInfoin your browser. - Confirm
urlmatches your deployment URL and there is nolast_error_message. - For local testing: confirm your tunnel is still running and
WEBSITE_URLin.envmatches the tunnel URL.
Forum topic not created in the group
- Make sure your group has Topics enabled (Group Settings β Topics).
- Confirm the bot is an Administrator with the Manage Topics permission.
- Double-check
TELEGRAM_GROUP_IDβ it must start with-100....
Admin replies are not forwarded to the user
- Confirm your Telegram User ID is listed in
TELEGRAM_ADMINS. - Make sure you're replying inside the correct forum topic (not the General topic).
- Do not use
/commands β just send a plain message or media.
Local tunnel drops connection immediately (Windows)
Use 127.0.0.1 instead of localhost in the SSH command:
ssh -R 80:127.0.0.1:8443 localhost.runRender free tier goes to sleep
Render's free tier spins down after 15 minutes of inactivity. You can keep it alive by setting up an external uptime monitor (e.g. UptimeRobot) to ping your /keep_alive endpoint every 5 minutes:
https://your-app-name.onrender.com/keep_alive
ImportError: cannot import name 'ReactionTypeEmoji'
Your installed version of python-telegram-bot is older than 20.8. Run:
pip install -r requirements.txt --upgradeMIT β see LICENSE.