Check prerequisites
Before you begin, ensure you have:
- Python 3.10 or higher installed (Python 3.11+ recommended)
- A Telegram account
- Basic familiarity with terminal commands
Create your bot with BotFather
Open Telegram and start a chat with @BotFather:
- Send
/newbotto BotFather - Follow the prompts to choose a name and username for your bot
- Copy the bot token (format:
123456:ABCDEF_your_token_here)
Keep your bot token secure. Anyone with this token can control your bot.
Create an operator group
Your operators need a dedicated supergroup with forum topics enabled:
- Create a new supergroup in Telegram
- Go to Group Settings → Group Type → Enable Topics
- Add your bot to the group as an administrator
- Grant the bot these permissions:
- Manage Topics (required)
- Send Messages
- Get the group’s chat ID (usually starts with
-100...)
Install dependencies
The bot requires three core packages:This installs:
requirements.txt
- aiogram - Modern Telegram Bot API framework
- aiosqlite - Async SQLite database for message routing
- python-dotenv - Environment variable management
Configure environment variables
Create a Edit
.env file in the project root:.env with your actual values:.env
Your bot token from BotFather
The supergroup chat ID where operators will work (must start with
-100)Path to the SQLite database file for routing and reply mapping
Logging verbosity level (
DEBUG, INFO, WARNING, ERROR)Set to
1 to store message history in SQLite, or 0 to disable history loggingRun the bot
Start the bot with:You should see output similar to:
The bot is now running and ready to handle support requests!
Test with a message
Verify everything is working:
- Open a private chat with your bot in Telegram
- Send a test message: “Hello, I need support!”
- Check your operator group - a new forum topic should appear with your user’s name
- The topic will contain your message
- Reply to the message in the topic
- Check your private chat with the bot - you should receive the operator’s reply
The bot automatically creates one forum topic per user. All future messages from that user will appear in their dedicated topic.
What happens under the hood
When a user sends a message to your bot:- The bot receives the message in the private chat (handled in
support_bot/handlers/user.py) - The
TopicManagerchecks if a forum topic exists for this user - If no topic exists, one is created automatically with the user’s name
- The message is mirrored to the operator group topic
- SQLite stores the routing information and reply mapping
- The bot detects the reply in the operator group (handled in
support_bot/handlers/operator.py) - It looks up which user the topic belongs to
- The reply is sent back to the user’s private chat
- The reply mapping is stored for future reference
What’s next?
Configuration
Learn about all configuration options and advanced settings
Architecture
Understand how the bot routes messages and manages topics
Deployment
Deploy your bot to production with systemd or Docker
Troubleshooting
Common issues and how to resolve them