Eagle-Bot is a multi-function Telegram bot designed for the E-Agle TRT team. It simplifies task management, interaction with external databases, and monitoring of lab attendance, acting as a digital assistant for the team.
- Main Features
- Architecture
- Project Structure
- Prerequisites
- Installation and Startup
- Configuration
- Usage
- Technical Details
- Agenda Management (ODG): Add, remove, view, and reset a shared task list for each chat or thread.
- NocoDB Integration: Retrieve information about members, areas, workgroups, and projects via REST API.
- Interaction with E-Agle API: Monitor who is present in the lab and view the monthly hours of each member.
- Mention Notifications: By mentioning a tag (e.g.,
@sw), the bot responds with the list of associated members, facilitating communication. - Quiz Management: Create and manage interactive quizzes for team training and engagement.
- QR Code Generation: Create QR codes from any text or URL.
- Detailed Logging: Records operations to files and console with colored log levels for easy debugging.
The bot is built on a modular architecture that separates responsibilities into distinct components:
- Core (
main.py): This is the application's entry point. It manages the bot's lifecycle, initializes clients for external APIs, and registers command and mention handlers based on the configuration. - Command Handlers (
/commands): Each file in this directory implements the logic for a specific command (e.g.,/odg,/inlab). This approach keeps the code organized and easy to extend. - Modules (
/modules): Contains clients and wrappers for interacting with external services and the local database.nocodb.py: Client for NocoDB APIs.api_client.py: Client for E-Agle's internal APIs.database.py: Manager for the local database (SQLite with Pony ORM).quiz.py: Logic for quiz management.scheduler.py: For running scheduled tasks.
- Persistent Data (
/data): A directory mounted as a Docker volume to store the SQLite database, log files, and configuration. - Configuration (
config.ini): A central configuration file that allows enabling or disabling features (feature flags) and customizing bot settings without modifying the code.
.
├── commands/ # Bot command handlers
│ ├── odg.py
│ ├── inlab.py
│ └── ...
├── data/ # Persistent data (database, logs)
├── modules/ # Reusable modules (API clients, DB)
│ ├── nocodb.py
│ ├── api_client.py
│ ├── database.py
│ └── ...
├── main.py # Application entrypoint
├── requirements.txt # Python dependencies
├── Dockerfile # Instructions to build the Docker image
├── config.ini.example # Example configuration file
└── README.md # This documentation
- Python 3.9+
- Docker and Docker Compose (for running in a container)
- Access to NocoDB and E-Agle APIs
-
Clone the repository:
git clone https://github.com/eagletrt/eagle-bot.git cd eagle-bot -
Create a virtual environment and install dependencies:
python -m venv myenv source myenv/bin/activate pip install -r requirements.txt -
Configure the bot: Create a copy of the
config.ini.examplefile, rename it toconfig.ini, and move it to thedata/folder. Modify the values inside according to your needs. -
Export the required environment variables: API keys and tokens should not be placed in the configuration file but exported as environment variables for security.
export TELEGRAM_BOT_TOKEN="your_token" export NOCO_API_KEY="your_api_key" export SHLINK_API_KEY="your_api_key" export CONFIG_PATH="data/config.ini"
-
Start the bot:
python main.py
The recommended way to run the bot in production is via Docker, to ensure an isolated environment and simplified management.
-
Create the configuration file: Create the
datafolder if it doesn't exist, then create thedata/config.inifile fromconfig.ini.exampleand customize it. -
Create a
.envfile: Create a.envfile in the project root for environment variables. Docker Compose will automatically use it to populate them in the container.TELEGRAM_BOT_TOKEN=... NOCO_API_KEY=... SHLINK_API_KEY=... CONFIG_PATH=...
-
Start the container:
docker compose up --build -d
The bot's configuration is managed through the data/config.ini file, which allows you to customize the bot's behavior without modifying the source code.
The following environment variables are mandatory for authentication with external services:
| Variable | Description |
|---|---|
TELEGRAM_BOT_TOKEN |
Authentication token for the Telegram bot. |
NOCO_API_KEY |
API key for authentication with NocoDB. |
SHLINK_API_KEY |
API key for authentication with Shlink. |
This file is divided into sections:
[Settings]: Contains general settings like API URLs, log levels, and quiz areas.[Paths]: Defines the paths for log files and the database.[Features]: Allows you to enable or disable bot features (e.g.,ODGCommand,FSQuiz). Setting a value tofalsewill prevent the corresponding command or feature from being loaded.
| Command | Description | Example |
|---|---|---|
/start |
Shows a welcome message. | /start |
/odg |
Manages the Agenda (ODG). | /odg, /odg <task>, /odg reset |
/tags |
Shows available tags (areas, projects, etc.). | /tags |
/inlab |
Shows who is currently in the lab. | /inlab |
/ore |
Shows the monthly hours for each member. | /ore |
/quiz |
Starts or manages a quiz. | /quiz <id> |
/quizzes |
Lists all available quizzes. | /quizzes |
/question |
Sends a random question from a specific area. | /question <area> |
/answer |
Allows answering an open-ended question. | /answer <text> |
/qr |
Generates a QR code from the provided text. | /qr https://example.com |
/events |
Shows upcoming events. | /events |
/id |
Shows the current chat ID and your user ID. | /id |
You can mention a tag (previously configured in NocoDB) to notify all associated members.
- Syntax:
@<tag_name> - Example:
@swwill mention all members of the "Software" group. - Special Mentions:
@inlab: Mentions all users currently in the lab.
The logging system is configurable via the config.ini file:
ConsoleLogLevel: Sets the log level for console output (e.g.,INFO,DEBUG). Console logs are colored for better readability.FileLogLevel: Sets the log level for saving to a file (e.g.,WARNING,ERROR).LogFilePath: Specifies the path to the log file (e.g.,data/bot.log).
- The bot uses an SQLite database (
/data/eagletrtbot.db) for persisting data related to the agenda and quizzes. - Interaction with the database is handled via Pony ORM, which abstracts SQL queries and simplifies entity management.
- The database file is created automatically on the first run.