AI chatbot for Telegram with streaming + vision — 155+ models via TokenMix
Project description
tg-ai-bot
Your own AI chatbot on Telegram. One file, one command, 155+ models.
Supports any OpenAI-compatible API. Streams responses in real time. Send photos and the bot can see them (vision). Switch models mid-conversation.
Setup
Two things you need:
- Telegram bot token — message @BotFather, type
/newbot, follow the steps - LLM API key — from TokenMix.ai ($1 free credit, 155+ models) or any OpenAI-compatible provider
Deploy with Docker (recommended)
git clone https://github.com/diaoyulao9657/tg-ai-bot
cd tg-ai-bot
cp .env.example .env
# edit .env — fill in BOT_TOKEN and API_KEY
docker compose up -d
Done. Open your bot on Telegram and say hi.
Run without Docker
git clone https://github.com/diaoyulao9657/tg-ai-bot
cd tg-ai-bot
pip install -r requirements.txt
cp .env.example .env
# edit .env
python bot.py
Features
- Streaming — responses appear word-by-word, not after a long wait
- Vision — send a photo with a question, the bot understands it
- Voice messages — send a voice note, it gets transcribed and answered
- Markdown — code blocks, bold, and other formatting render properly
- Group chat — in groups, responds only when @mentioned or replied to
- Model switching —
/model gpt-4oto try a different model anytime - Conversation memory — keeps context across messages (configurable depth)
- Long replies — responses over 4096 chars are split across multiple messages
- Access control — optionally restrict to specific Telegram user IDs
Commands
/model <name> — switch to a different model
/clear — wipe conversation history
/help — show commands
Configuration
Everything is in .env:
| Variable | Required | Default | |
|---|---|---|---|
BOT_TOKEN |
yes | — | From @BotFather |
API_KEY |
yes | — | LLM API key |
BASE_URL |
no | https://api.tokenmix.ai/v1 |
API endpoint |
MODEL |
no | gpt-4o-mini |
Default model |
MAX_HISTORY |
no | 20 |
Messages kept in context |
ALLOWED_USERS |
no | (everyone) | Comma-separated user IDs |
SYSTEM_PROMPT |
no | You are a helpful assistant. |
System prompt |
Find your Telegram user ID by messaging @userinfobot.
How it works
It's one Python file. The bot receives messages via Telegram's API, forwards them to an LLM through the OpenAI-compatible chat completions endpoint, and streams the response back by editing the message as tokens arrive. Photos are base64-encoded and sent as vision inputs.
Conversation history is stored in memory (resets when the bot restarts). For most use cases this is fine — if you need persistence, a database would be straightforward to add.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tokenmix_tg_bot-0.1.0.tar.gz.
File metadata
- Download URL: tokenmix_tg_bot-0.1.0.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
38062539bddaa0f763855093b9de728225eb40963507022b83134ed3833cd83a
|
|
| MD5 |
5b6a87c023cf00eb5bb5a98328872210
|
|
| BLAKE2b-256 |
dbbf154d3af33415f34b822f5c341666bc41111ce485d6470023c7ad4344075d
|
File details
Details for the file tokenmix_tg_bot-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tokenmix_tg_bot-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2af1f4659a1185f12d64bbd0e24c7835945dc734a0110310eeaa73619fcd2974
|
|
| MD5 |
cc824f6e886290e7861cc4974ec15cdd
|
|
| BLAKE2b-256 |
32be7799e3eb883ded7397f7a04a47da6b1e84731ef1afc27638c1a8abf455db
|