Telegram bot for LLM-based processing, analyzing and answering messages using FastAPI and PostgreSQL.
- Telegram Integration: Real-time message processing using Telethon
- LLM Processing: Integration with Nebius AI Studio for intelligent responses
- Database Storage: PostgreSQL with Alembic migrations for data persistence
- Cloud Ready: Optimized for deployment on Render with automatic database creation
- Health Monitoring: Built-in health check endpoints
-
Open in Dev Container
- Use VS Code with Dev Containers extension
- The project includes
.devcontainerconfiguration
-
Start the Application
uvicorn app:app --host 0.0.0.0 --port 5000 --reload
-
Install Dependencies
pip install -r requirements.txt
-
Set Environment Variables Create a
.envfile:DATABASE_URL=postgresql+asyncpg://postgres:postgres@localhost:5432/telegram TELEGRAM_API_ID=your_api_id TELEGRAM_API_HASH=your_api_hash TELETHON_SESSION=autonomia NEBIUS_STUDIO_API_KEY=your_nebius_key
-
Run the Application
poetry run uvicorn app:app --host 0.0.0.0 --port 5000 --reload
Note: The application will automatically create the database if it doesn't exist during startup.
-
Connect Repository
- Go to render.com
- Create a new Web Service
- Connect your GitHub repository
-
Configure Environment Variables
TELEGRAM_API_ID=your_api_id TELEGRAM_API_HASH=your_api_hash TELETHON_SESSION=autonomia TELETHON_SESSION_STRING=your_string_session NEBIUS_STUDIO_API_KEY=your_nebius_key
-
Service Settings
- Build Command:
poetry install --no-dev --no-interaction --no-ansi - Start Command:
uvicorn app:app --host 0.0.0.0 --port $PORT - Health Check Path:
/api/v1/health
- Build Command:
The PostgreSQL database is automatically created and configured through Render's database service.
For cloud deployment, you need to use StringSession instead of session files:
-
Create StringSession
python convert_session.py
-
Follow the prompts to authenticate with Telegram
-
Add the generated string to
TELETHON_SESSION_STRINGenvironment variable in Render
GET /api/v1/health- Service health check- Additional endpoints for message processing and analysis
├── alembic/ # Database migrations
├── api/ # API endpoints
│ └── v1/ # Version 1 API
├── jobs/ # Background tasks
├── models/ # SQLAlchemy models
├── repositories/ # Database repositories
├── storage/ # File storage (S3 support)
├── external/ # External service integrations
├── app.py # Main application
├── dependency.py # Dependency injection
├── render.yaml # Render configuration
└── pyproject.toml # Poetry configuration and dependencies
Event- Telegram message eventsChatConfig- Chat configuration settings
- Telegram Client - Handles Telegram API communication
- Nebius AI - LLM processing for message analysis
- Database - PostgreSQL with automatic migration support
- Automatic Database Creation - Creates database if it doesn't exist
- StringSession Support - Secure session management for cloud
- Health Monitoring - Built-in health checks
- Background Jobs - Automated message processing
- Python 3.11+
- PostgreSQL
- Telegram API credentials
- Nebius AI Studio API key
The project uses environment variables for configuration. See the .env example above for required variables.
The project uses RUFF for linting and formatting:
# Check and fix linting issues
poetry run ruff check --fix .
# Format code
poetry run ruff format .
# Run tests
poetry run pytestMigrations are handled automatically by Alembic during application startup.
- Application automatically adapts to the
$PORTvariable - Health check endpoint for monitoring
- Secure Telegram client initialization
- Optimized Dockerfile for production
- Automatic database creation if it doesn't exist