.env file to configure its behavior. This guide explains each configuration option and how it’s used in the code.
Creating your configuration file
Configuration variables
BOT_TOKEN (required)
Your Telegram bot token obtained from @BotFather
<bot_id>:<token> (e.g., 123456:ABCDEF_your_token_here)
How it’s used:
The bot token is loaded and validated in config.py:17-19:
support_bot/config.py
main.py:33-36:
support_bot/main.py
OPERATOR_GROUP_ID (required)
The chat ID of your operator supergroup (must have Forum/Topics enabled)
-100 (e.g., -1001234567890)
How it’s used:
The operator group ID is validated and parsed in config.py:21-28:
support_bot/config.py
- Initialize the TopicManager in
main.py:39 - Filter operator messages in
main.py:47
support_bot/main.py
The group ID must be from a supergroup with Forum/Topics enabled. Regular groups won’t work. See Telegram Setup for instructions.
DB_PATH (optional)
Path to the SQLite database file for storing routing and message history
./support_bot.sqlite3 if not specified (config.py:30):
support_bot/config.py
main.py:29-31:
support_bot/main.py
- User-to-topic routing information
- Reply mappings between user messages and operator replies
- Optional message history (if
LOG_MESSAGES=1)
LOG_LEVEL (optional)
Logging level for the bot’s output
DEBUG, INFO, WARNING, ERROR, CRITICAL
How it’s used:
The log level is configured in config.py:31 and applied in main.py:23:
support_bot/config.py
support_bot/main.py
- DEBUG - Detailed information for troubleshooting (verbose)
- INFO - General operational information (recommended for production)
- WARNING - Only warnings and errors
- ERROR - Only errors and critical issues
LOG_MESSAGES (optional)
Whether to store message history in the SQLite database
1 to enable, 0 to disable
How it’s used:
The setting is parsed in config.py:32 and passed to the dispatcher in main.py:43:
support_bot/config.py
support_bot/main.py
LOG_MESSAGES=1- All messages are stored in SQLite for history trackingLOG_MESSAGES=0- Only routing and reply mappings are stored (minimal storage)
Configuration validation
The bot validates configuration on startup. If validation fails, you’ll see one of these errors:Missing BOT_TOKEN env var
Missing BOT_TOKEN env var
Cause: The
BOT_TOKEN variable is not set in your .env file.Solution: Add your bot token from @BotFather:Missing OPERATOR_GROUP_ID env var
Missing OPERATOR_GROUP_ID env var
Cause: The See Getting the group ID for instructions.
OPERATOR_GROUP_ID variable is not set in your .env file.Solution: Add your operator group ID:OPERATOR_GROUP_ID must be an integer
OPERATOR_GROUP_ID must be an integer
Cause: The group ID contains non-numeric characters or is incorrectly formatted.Solution: Ensure the group ID is a valid negative integer:
Complete example
Here’s a complete.env configuration example:
Troubleshooting
Bot doesn't start after configuration
Bot doesn't start after configuration
- Check that your
.envfile is in the same directory assupport_bot/ - Verify all required variables (
BOT_TOKEN,OPERATOR_GROUP_ID) are set - Ensure there are no extra spaces or quotes around values
- Run with
LOG_LEVEL=DEBUGto see detailed error messages
Database connection errors
Database connection errors
- Check that the directory for
DB_PATHexists - Ensure you have write permissions in the database directory
- Try using an absolute path instead of a relative path
- Verify the database file isn’t locked by another process
Bot can't access operator group
Bot can't access operator group
- Verify the
OPERATOR_GROUP_IDis correct (should start with-100) - Ensure the bot is added to the operator group as an administrator
- Check that the bot has “Manage Topics” permission
- Confirm the group has Forum/Topics enabled