A production-ready, personality-driven AI Telegram bot powered by NVIDIA Nemotron via OpenRouter API. Features a customizable soul/personality system, per-user conversation memory, rate limiting, streaming responses, and comprehensive error handling.
| Feature | Description |
|---|---|
| π§ Soul System | Customizable personality via SOUL.md and system prompt |
| π¬ Conversation Memory | Per-user chat history with configurable depth |
| β‘ Streaming Responses | Real-time token streaming for fast feedback |
| π¦ Rate Limiting | Per-user rate limiting with reset timers |
| π Auto-Retry | Exponential backoff on transient API failures |
| π Logging | File + console logging with full stack traces |
| π³ Docker Ready | Dockerfile + docker-compose for easy deployment |
| π Secure Config | Environment variables for all secrets |
| π‘οΈ Error Handling | Comprehensive error handling at every layer |
| π± Telegram Native | Typing indicators, message chunking, command system |
- Python 3.9+
- Telegram Bot Token from @BotFather
- OpenRouter API Key
git clone https://github.com/yourusername/vader-gem-bot.git
cd vader-gem-bot# Create virtual environment
python -m venv .venv
# Activate it
# Windows:
.venv\Scripts\activate
# Linux/Mac:
source .venv/bin/activate
# Install dependencies
pip install -r requirements.txt# Copy example config
cp .env.example .env
# Edit with your credentials
# Windows: notepad .env
# Linux/Mac: nano .envSet these values in .env:
OPENROUTER_API_KEY=sk-or-v1-your-key-here
TELEGRAM_BOT_TOKEN=your-telegram-bot-token
BOT_NAME=VADER-GEMpython nvidia_api_chat.pyOr use the batch script (Windows):
START_BOT.batOr use Docker:
docker-compose up -d# Build and start
docker-compose up -d
# View logs
docker-compose logs -f
# Stop
docker-compose down# Build
docker build -t vader-gem-bot .
# Run
docker run -d --name vader-gem \
--env-file .env \
--restart unless-stopped \
vader-gem-bot| Command | Description |
|---|---|
/start |
Initialize bot, show welcome & capabilities |
/help |
Full help guide with examples |
/status |
System diagnostics & session info |
/clear |
Wipe conversation memory |
/whoami |
Bot identity & technical details |
| Any text | Send message to AI |
The bot's personality is defined in two files:
Defines the bot's identity, personality traits, communication style, and core directives. This is the reference document for the bot's character.
Session & system configuration: the actual system prompt template injected into every API call, conversation memory design, and environment variable reference.
- Edit
SOUL.mdto define your bot's character - Update the
SYSTEM_PROMPTinnvidia_api_chat.pyto match - Change
BOT_NAMEin.env - Restart the bot
The system prompt is sent as the first message in every API call, ensuring consistent personality across all interactions.
| Variable | Description | Default | Required |
|---|---|---|---|
OPENROUTER_API_KEY |
OpenRouter API key | β | β |
TELEGRAM_BOT_TOKEN |
Telegram bot token | β | β |
BOT_NAME |
Bot display name | VADER-GEM |
β |
Edit these constants in nvidia_api_chat.py:
MODEL_NAME = "nvidia/nemotron-3-nano-30b-a3b:free" # AI model
REQUEST_TIMEOUT = 30 # API timeout (seconds)
MAX_RETRIES = 3 # Retry attempts on failure
RATE_LIMIT_REQUESTS = 10 # Requests per window per user
RATE_LIMIT_WINDOW = 60 # Rate limit window (seconds)
MAX_CONVERSATION_HISTORY = 20 # Messages to keep per user
MAX_MESSAGE_LENGTH = 4096 # Telegram message limitβββββββββββββββββββββββββββββββββββββββ
β Telegram User β
ββββββββββββ¬βββββββββββββββββββββββββββ
β (Message)
β
βββββββββββββββββββββββββββββββββββββββ
β Telegram Bot API β
β ββ Command Handlers β
β ββ Message Handler β
β ββ Rate Limiter β
β ββ Error Handler β
ββββββββββββ¬βββββββββββββββββββββββββββ
β
β
βββββββββββββββββββββββββββββββββββββββ
β Conversation Memory β
β ββ Per-user history β
β ββ System prompt injection β
β ββ Auto-pruning β
ββββββββββββ¬βββββββββββββββββββββββββββ
β
β (HTTP with retries + streaming)
βββββββββββββββββββββββββββββββββββββββ
β OpenRouter API β
β (nvidia/nemotron-3-nano-30b-a3b) β
βββββββββββββββββββββββββββββββββββββββ
TelegramBot/
βββ nvidia_api_chat.py # Main bot application
βββ SOUL.md # Bot personality definition
βββ SES.md # Session & system config docs
βββ .env # Environment variables (secrets - gitignored)
βββ .env.example # Example environment config
βββ .gitignore # Git ignore rules
βββ requirements.txt # Python dependencies
βββ Dockerfile # Docker container config
βββ docker-compose.yml # Docker Compose config
βββ START_BOT.bat # Windows quick-start script
βββ LICENSE # MIT License
βββ README.md # This file
βββ CONTRIBUTING.md # Contribution guidelines
βββ TELEGRAM_BOT_GUIDE.md # Detailed usage guide
βββ ADVANCED_FEATURES.md # Advanced features documentation
βββ telegram_bot.log # Log file (auto-created)
The bot handles errors at every layer:
| Layer | Errors Handled |
|---|---|
| Network | Timeout, DNS, connection failures |
| API | 401 (auth), 429 (rate limit), 500+ (server) |
| Validation | Empty messages, oversized input, missing API key |
| Telegram | Send failures, network errors, API limits |
| Application | Uncaught exceptions with graceful recovery |
All errors are:
- Logged to
telegram_bot.logwith full stack traces - Reported to the user with clear, actionable messages
- Automatically retried (for transient failures)
All events are logged to telegram_bot.log:
2025-02-13 10:15:32 - INFO - OpenRouterAPIClient initialized β VADER-GEM online
2025-02-13 10:15:45 - INFO - User 123456789 (John) started the bot
2025-02-13 10:16:02 - INFO - Message from 123456789: What is AI?...
2025-02-13 10:16:32 - INFO - Response received from OpenRouter API
2025-02-13 10:16:32 - INFO - Response sent to user 123456789
Log Levels: INFO (normal), WARNING (rate limits), ERROR (handled errors), CRITICAL (system failures)
| Issue | Solution |
|---|---|
| Bot doesn't start | Check TELEGRAM_BOT_TOKEN in .env |
| "API key not configured" | Set OPENROUTER_API_KEY in .env |
| Timeout errors | Try shorter messages, increase REQUEST_TIMEOUT |
| Rate limited | Wait 60 seconds, or adjust RATE_LIMIT_REQUESTS |
| Empty responses | Check API key validity, try /clear |
| Docker won't build | Ensure Docker is installed and running |
- VPS/Cloud: Deploy on AWS EC2, DigitalOcean, Railway, or Render
- Docker: Use
docker-composefor easy management - Process Manager: Use
systemdor Docker's restart policy - Monitoring: Check
telegram_bot.logregularly - Backups: Keep
.envbacked up securely
[Unit]
Description=VADER-GEM Telegram Bot
After=network.target
[Service]
Type=simple
User=botuser
WorkingDirectory=/opt/vader-gem-bot
ExecStart=/opt/vader-gem-bot/.venv/bin/python nvidia_api_chat.py
Restart=always
RestartSec=10
EnvironmentFile=/opt/vader-gem-bot/.env
[Install]
WantedBy=multi-user.target- Never commit
.envto git - Use strong, unique API keys
- Restrict bot access if needed (add allowed user IDs)
- Monitor logs for abuse
- Keep dependencies updated
This project is licensed under the MIT License β see LICENSE for details.
Contributions are welcome! See CONTRIBUTING.md for guidelines.
Built with π by VADER-GEM