Skip to content

temaprint/ai.temaprint.com

Repository files navigation

Temaprint AI — Telegram Bot Screenshot

Temaprint AI

Multi-Model AI Chatbot for Telegram with Streaming Responses

Python 3.12 FastAPI aiogram 3 PostgreSQL Docker License: Private

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


Why Temaprint AI?

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.

✨ Features

Chat

  • 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

Admin & Access

  • Telegram-based access control — whitelist users by Telegram ID
  • Admin commands/approve, /revoke, /users to manage access
  • Usage statistics — track tokens, messages, and costs per user
  • Rate limiting — in-memory sliding window (configurable)

UX

  • 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

DevOps

  • Docker-ready — multi-stage Dockerfile, docker compose up -d and you're live
  • Health check endpoint/health monitors app + database connectivity
  • Environment-based config — all secrets via .env, zero hardcoded credentials

Tech Stack

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

Quick Start

Prerequisites

Run

# 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 bot

That's it. Your AI chatbot is live.

Architecture

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

Commands

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

Adding Users

New users are denied by default. The approval flow:

  1. User sends /start → bot shows their Telegram ID
  2. Admin sends /approve 123456789
  3. User sends /start again → access granted

Only users in ALLOWED_TELEGRAM_IDS get instant access on first /start.

Configuration

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)

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests.

License

Private project. All rights reserved.

About

Chat with the world’s best models — GPT-4o, Claude, Gemini — without leaving your favorite messenger. Private. Fast. Yours.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

No contributors