Open-source Telegram bot that connects users to 10+ AI models through OpenRouter. Real-time streaming, multi-chat sessions, bilingual UI, admin panel — ready to deploy in minutes.
Features · Quick Start · Tech Stack · Architecture · Commands
Most Telegram AI bots lock you into a single model. Temaprint AI gives your users instant access to GPT-4o, Claude, Gemini, Llama, Mistral, and more — with per-chat model switching, streaming responses that edit in real time, and a full admin panel for user management.
- Streaming AI responses — messages update live in Telegram as the model generates text
- 10+ models via OpenRouter — GPT-4o, Claude, Gemini, Llama, Mistral, Qwen, and more
- Multiple chat sessions — each user can run several independent conversations
- Per-chat model switching — change the AI model without losing context
- Custom system prompts — personalize AI behavior per chat
- Stop generation — cancel a response mid-stream with one tap
- Telegram-based access control — whitelist users by Telegram ID
- Admin commands —
/approve,/revoke,/usersto manage access - Usage statistics — track tokens, messages, and costs per user
- Rate limiting — in-memory sliding window (configurable)
- Bilingual UI — English / Russian with in-app language switcher
- Inline keyboards — model picker, settings, chat list — no typing needed
- Persistent history — all chats stored in PostgreSQL, survives restarts
- Docker-ready — multi-stage Dockerfile,
docker compose up -dand you're live - Health check endpoint —
/healthmonitors app + database connectivity - Environment-based config — all secrets via
.env, zero hardcoded credentials
| Layer | Technology |
|---|---|
| Runtime | Python 3.12, async/await throughout |
| Bot Framework | aiogram 3.x (async Telegram Bot API) |
| Web Framework | FastAPI + Uvicorn |
| AI Gateway | OpenRouter API (unified multi-model access) |
| Database | PostgreSQL 16 + SQLAlchemy 2.0 async |
| Containerization | Docker multi-stage build |
| Config | pydantic-settings from .env |
- Docker & Docker Compose
- Telegram Bot Token (@BotFather)
- OpenRouter API Key (openrouter.ai)
# 1. Clone the repo
git clone https://github.com/YOUR_USERNAME/ai.temaprint.com.git
cd ai.temaprint.com
# 2. Configure environment
cp .env.example .env
# Edit .env — fill in BOT_TOKEN, OPENROUTER_API_KEY, your Telegram ID
# 3. Launch
docker compose up -d
# 4. Open Telegram and send /start to your botThat's it. Your AI chatbot is live.
app/
main.py # FastAPI app + bot polling entry point
config.py # pydantic-settings (reads .env)
bot.py # aiogram Dispatcher & router registration
database/
models.py # SQLAlchemy models — User, Chat, Message, UsageLog
session.py # async engine + sessionmaker
services/
openrouter.py # streaming client for OpenRouter API
chat.py # chat & message CRUD, usage stats
auth.py # user resolution & access control
handlers/
start.py # /start /new /clear /model /help /menu
message.py # streaming message handler + FSM for prompts
callbacks.py # all inline keyboard callbacks
admin.py # /approve /revoke /users /admin
keyboards/
inline.py # inline keyboards + model list builder
utils/
i18n.py # en/ru translations + t() helper
text.py # message splitting utilities
users.py # shared user resolution
rate_limit.py # sliding-window rate limiter
| Command | Description |
|---|---|
/start |
Welcome screen + authorization check |
/new |
Create a new chat session |
/clear |
Clear current chat history |
/model |
Switch AI model for current chat |
/menu |
Show main menu |
/help |
Help & usage instructions |
/admin |
Admin panel (admins only) |
/approve <id> |
Grant access to a user |
/revoke <id> |
Revoke user access |
/users |
List all registered users |
New users are denied by default. The approval flow:
- User sends
/start→ bot shows their Telegram ID - Admin sends
/approve 123456789 - User sends
/startagain → access granted
Only users in ALLOWED_TELEGRAM_IDS get instant access on first /start.
All settings are managed through .env (see .env.example):
| Variable | Required | Description |
|---|---|---|
BOT_TOKEN |
Yes | Telegram Bot Token from @BotFather |
OPENROUTER_API_KEY |
Yes | API key from openrouter.ai |
DATABASE_URL |
No | PostgreSQL connection string |
ALLOWED_TELEGRAM_IDS |
No | Comma-separated Telegram IDs with instant access |
ADMIN_IDS |
No | Comma-separated admin Telegram IDs |
DEFAULT_MODEL |
No | Default AI model (default: openai/gpt-4o-mini) |
Contributions are welcome! Feel free to open issues or submit pull requests.
Private project. All rights reserved.