Skip to content

Kernel Telegram Bot. A modular Telegram bot powered by python-telegram-bot. This bot is designed for scalability, maintainability, and follows clean architecture principles.

License

Notifications You must be signed in to change notification settings

LoboGuardian/kernel-telegram-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ› οΈ Kernel Telegram Bot

A modular Telegram bot powered by python-telegram-bot.
This bot is designed for scalability, maintainability, and follows clean architecture principles.

πŸš€ Features

  • Uses python-telegram-bot for handling Telegram interactions.
  • Structured with SOLID principles for modularity.
  • Poetry-based dependency management (previously Pipenv).
  • Built-in error handling and logging.
  • Uses environment variables (.env) to store sensitive data.

πŸ“Œ Upcoming Enhancements & Next Steps

We are actively improving the kernel to be more reusable, scalable, and efficient. The following enhancements are planned:

  • Short-Term Goals

    • Support for Webhooks: Implement run_webhook() to allow event-driven execution.
    • Testing with SQLite: Create unit tests using pytest for config_loader.py, database.py, and handlers.
    • Verify PostgreSQL Integration: Ensure database compatibility with PostgreSQL.
  • Mid-Term Goals

    • Plugin System for Dynamic Modules: Load new commands automatically from bot/plugins/.
    • Multi-language Support (i18n): Implement a translation system with JSON-based locales.
    • Message Middleware: Filter messages before they reach command handlers.
  • Long-Term Goals

    • Redis Caching for Performance Optimization: Store user sessions in memory for faster responses.
    • External API Integration: Create api_client.py for connecting with third-party services.
    • WebSockets for Real-Time Events: Enable instant notifications and live event handling.
    • Admin Dashboard with FastAPI: Develop an API to manage and monitor the bot remotely.

πŸ“¦ Installation & Setup

1️⃣ Install Poetry

Poetry is used to manage dependencies and virtual environments:

pip install poetry

2️⃣ Install Project Dependencies

poetry install

3️⃣ Configure Environment Variables

Create a .env file in the project root and add your Telegram Bot Token:

# TOKEN
TELEGRAM_BOT_TOKEN=your_actual_bot_token_here
# Add Telegram user IDs separated by commas
AUTHORIZED_USERS=12345678,98765432

# Change as needed
# LOG_LEVEL=DEBUG # Shows detailed information for debugging.
# LOG_LEVEL=INFO # Shows general information about program operation.
LOG_LEVEL=WARNING # Shows warnings about potential problems.
# LOG_LEVEL=ERROR # Shows errors that prevent correct operation.

DEBUG_MODE=False

# Options: DATABASE_TYPE sqlite or postgres

# If using SQLite:
DATABASE_TYPE=sqlite

# If using PostgreSQL: (Upcoming)
# DATABASE_TYPE=postgres  

# Only required if using PostgreSQL
# DATABASE_URL=postgresql://user:password@localhost:5432/mydatabase

DATABASE_FILE=bot_database.db

▢️ Running the Bot

You can start the bot in two ways:

1️⃣ Using Poetry

poetry run python bot/main.py

2️⃣ Using the run.sh Script

Make sure run.sh is executable:

chmod +x run.sh
./run.sh

3️⃣ Using Webhooks (Coming Soon)

poetry run python bot/main.py --webhook

πŸ› οΈ Project Structure

kernel-telegram-bot/
│── bot/                      # Main application logic
β”‚   β”œβ”€β”€ __init__.py           # Package init file
β”‚   β”œβ”€β”€ main.py               # Entry point of the bot
β”‚   β”‚
β”‚   β”œβ”€β”€ handlers/             # Telegram command handlers
β”‚   β”‚   β”œβ”€β”€ __init__.py       # Package init file
β”‚   β”‚   β”œβ”€β”€ start.py          # /start command
β”‚   β”‚   β”œβ”€β”€ help.py           # /help command
β”‚   β”‚   β”œβ”€β”€ unknown.py        # Unknown command handler
β”‚   β”‚   β”œβ”€β”€ errors.py         # Error handling
β”‚   β”‚
β”‚   β”œβ”€β”€ services/             # Business logic (auth, db, etc.)
β”‚   β”‚   β”œβ”€β”€ __init__.py       # Package init file
β”‚   β”‚   β”œβ”€β”€ auth.py           # Manages user authentication & permissions.
β”‚   β”‚   β”œβ”€β”€ database.py       # Handles data storage (SQLite/PostgreSQL).
β”‚   β”‚   β”œβ”€β”€ cache.py          # (Upcoming) Redis-based caching (for faster performance)
β”‚   β”‚   β”œβ”€β”€ api_client.py     # (Upcoming) Handles API integrations (with external APIs)
β”‚   β”‚
β”‚   β”œβ”€β”€ utils/                # Utility functions (config, logging)
β”‚   β”‚   β”œβ”€β”€ __init__.py       # Package init file
β”‚   β”‚   β”œβ”€β”€ config_loader.py  # Load config files or .env
β”‚   β”‚   β”œβ”€β”€ logger.py         # Logging setup
β”‚   β”‚   β”œβ”€β”€ middleware.py     # (Upcoming) Preprocess messages before reaching handlers (spam filtering, normalization)
β”‚   β”‚
β”‚   β”œβ”€β”€ plugins/              # (Upcoming) Dynamic plugin modules)
β”‚   β”œβ”€β”€ locales/              # (Upcoming) Multi-language support
β”‚   β”œβ”€β”€ dashboard/            # (Upcoming) FastAPI-based admin panel
β”‚   β”œβ”€β”€ config.py             # Main bot configuration
β”‚
β”œβ”€β”€ tests/                    # Unit and integration tests
β”‚   β”œβ”€β”€ test_config.py        # Tests for config loader
β”‚   β”œβ”€β”€ test_database.py      # Tests for database functionality
β”‚   β”œβ”€β”€ test_handlers.py      # Tests for bot command handlers
β”‚
β”œβ”€β”€ docs/                     # Documentation files
β”‚   β”œβ”€β”€ SETUP.md              # Setup guide
β”‚   β”œβ”€β”€ TESTING.md            # Testing guide
β”‚   β”œβ”€β”€ DEPLOYMENT.md         # Deployment instructions
β”‚
β”œβ”€β”€ .gitignore                # Git ignore rules
β”œβ”€β”€ .env                      # Environment variables
β”œβ”€β”€ LICENSE                   # License file
β”œβ”€β”€ README.md                 # Project documentation
β”œβ”€β”€ CODE_OF_CONDUCT.md        # Code of conduct for contributors
β”œβ”€β”€ AUTHORS.md                # List of contributors
β”œβ”€β”€ CONTRIBUTING.md           # Contribution guidelines
β”œβ”€β”€ pyproject.toml            # Poetry configuration
β”œβ”€β”€ poetry.lock               # Poetry dependencies
└── run.sh                    # Script to run the bot

**πŸ§ͺ Running Tests

To run unit tests:

poetry run pytest

**πŸ› οΈ Development & Contribution

Fork this repository.

Clone your fork:

git clone https://github.com/LoboGuardian/kernel-telegram-bot.git

Install dependencies:

poetry install

Create a feature branch:

git checkout -b feature/new-feature

Make changes and commit:

git commit -m "Added a new feature"
Push and create a pull request.

βš–οΈ License

This project is licensed under the GPL-3.0 License. See the LICENSE file for details.

🀝 Credits & Contact


πŸš€ Contribution & Future Development

We welcome contributions! Our current focus areas include:

  • Expanding testing coverage.

  • Optimizing database performance.

  • Enhancing real-time event handling with WebSockets.

  • If you want to contribute, fork the repo and submit a PR.

Feel free to discuss improvements via GitHub Issues.

About

Kernel Telegram Bot. A modular Telegram bot powered by python-telegram-bot. This bot is designed for scalability, maintainability, and follows clean architecture principles.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published