Telegram bot to control the Sobornyi group.
- Conda (Miniconda or Anaconda)
- Telegram account
-
Create a bot through @BotFather and get your bot token.
-
Create a Telegram chat group for the bot to manage.
-
Create a Telegram channel for announcements.
-
Add your bot to both the group and channel as an admin with full rights.
-
Configure the project:
# Clone the repository git clone <repository-url> cd sobornyi-bot # Quick setup (creates environment, installs dependencies, generates config files) make setup
-
Update configuration files:
- Edit
config/settings.local.ymlwith your specific environment settings fordevandprod. - Add your bot token to
config/.secrets.local.yml.
- Edit
-
Activate the environment:
conda activate telegram-bot
-
Run the bot:
# Development mode with debug logging make debug # Production mode make run
Hint: To get the chat_id of a group, turn on "Show Peer IDs in Profile" in Telegram Desktop.
The bot offers various commands organized by function:
/topic [name]- Redirect discussion to a specific topic thread/offtop- Redirect off-topic discussions to the dedicated thread/calendar- Access the event calendar menu for creating, editing, and managing events/cancel- Cancel an ongoing conversation with the bot
/war- Enable war mode with morning minute of silence/war_off- Disable war mode notifications
/debug- Enable debug mode with verbose logging/debug_off- Disable debug mode and return to normal logging levels/info- Display information about the current chat, including chat ID and configuration details/upload- Start conversation to upload photos to the bot storage
- New Members - Bot automatically welcomes new members to the group
- Join Requests - Bot automatically processes join requests to the group
- Channel Posts - Bot manages cross-posting between the channel and group
Use these Makefile commands to maintain the bot:
# Backup data and logs
make backup
# Clean all generated files
make clean
# Clean only cache and logs (keeps data)
make clean-state
# Run tests
make test
# Run tests with coverage report
make test-cov
# Display code coverage in browser
make display-coverageWhen updating the model structure, you may need to migrate your persistent data. The bot includes a migration tool for this purpose:
# Run database migrations
make migrate
# Show migration help
make migrate-helpFor advanced migration options:
# Run with specific options
python tools/migration.py --source /path/to/old/data --target /path/to/new/data
# Migrate only specific data types
python tools/migration.py --bot-only
python tools/migration.py --chat-only
python tools/migration.py --user-only
# Other options
python tools/migration.py --no-backup # Skip creating backups
python tools/migration.py --verbose # Enable verbose loggingFor more information about the migration tool, see tools/README.md.
| Command | Description |
|---|---|
make |
ℹ️ Show this help message |
make setup |
🏗️ First-time setup: install dependencies and configure project |
make env |
📦 Create conda environment and install dependencies |
make init-dev |
🛠️ Setup development environment with pre-commit hooks |
make run |
🚀 Run bot in production mode |
make debug |
🐞 Run bot in debug mode |
make backup |
💾 Create backup of data and logs |
make migrate |
🔄 Run database migrations |
make migrate-help |
🚑 Show migration help |
make test |
🧪 Run all tests |
make test-unit |
🔬 Run unit tests only |
make test-integration |
🔌 Run integration tests only |
make test-cov |
📊 Run tests with coverage report |
make display-coverage |
📈 Open coverage report in browser |
make clean |
🧹 Remove all generated files |
make clean-state |
🧼 Clean cache and logs |
make clean-cache |
🗑️ Remove cache files |
make clean-logs |
📝 Remove log files |
make clean-data |
📁 Remove data files |
make clean-conversations |
💬 Remove conversation files |
make config |
🧰 Generate configuration files |
make version |
🏷️ Show the project version |
make docs |
📚 Generate project documentation |
make check-conda |
🐍 Check if conda is installed |
make check-deps |
✅ Check if required tools are installed |
For developers looking to contribute:
-
Set up the development environment:
make init-dev
-
This installs pre-commit hooks and development dependencies.
-
Before committing changes, run tests:
make test
Current version: Use make version to display.