A friendly Telegram bot that creates digest summaries of group chats using the OpenAI API.
Perfect for when you’ve missed long conversations with friends and don’t want to scroll through hundreds of messages.
- Stores group messages locally in SQLite (no cloud storage).
- Generates easy-to-read digests with OpenAI API (hierarchical summarization).
- Keeps nicknames/mentions unchanged (
@usernamestays as-is). - Delivers digests privately to the user’s DM (with a fallback to the group).
- Automatic retention (old messages are purged after
RETENTION_DAYS). - Noise filtering (removes tiny “ok/LOL/emoji”-style replies).
The bot ships with two prompt variants:
- Russian (default) — tuned for casual Russian chats.
- English (optional) — ready to switch.
To switch to English, open main.py and in the “PROMPTS” section uncomment:
# PROMPT_CHUNK = PROMPT_CHUNK_EN
# PROMPT_FINAL = PROMPT_FINAL_EN…and comment the RU lines if desired:
# PROMPT_CHUNK = PROMPT_CHUNK_RU
# PROMPT_FINAL = PROMPT_FINAL_RUNo other changes are needed.
git clone https://github.com/yourname/buddysummarizer.git
cd buddysummarizer
python -m venv .venv
# Linux/macOS:
source .venv/bin/activate
# Windows (cmd):
.venv\Scripts\activate
pip install -r requirements.txtCreate a .env file:
BOT_TOKEN=123456:ABC-your-telegram-bot-token
OPENAI_API_KEY=sk-your-openai-key
MODEL=gpt-5-mini
# Optional
LOG_LEVEL=INFO
RETENTION_DAYS=30
SUMMARY_PARSE_MODE=plain # plain | markdown_v2 | html
CHUNK_MAX_CHARS=6000
INPUT_MAX_CHARS=180000
MIN_TEXT_LEN=5BOT_TOKEN– from BotFather.OPENAI_API_KEY– from OpenAI.RETENTION_DAYS– how long to keep messages in the DB.
Telegram setup tips
- Disable Privacy Mode in BotFather so the bot can see group messages.
- To receive DMs from the bot, start a private chat with it and press Start.
python main.pyThe bot runs in polling mode. Add it to your group and try:
/catchup— digest since last time/catchup 12hor/catchup 2d— time-bounded digest/catchup since YYYY-MM-DD [HH:MM]— from a date/mentions— your recent mentions/stats— DB diagnostics
See requirements.txt:
python-telegram-bot==21.4
openai>=1.40.0
python-dotenv>=1.0.1
Python 3.10+ is recommended.
- Messages are stored locally in
bot.db(SQLite). - No external storage.
- Automatic cleanup of old messages after
RETENTION_DAYS.
- Basic message capture and local SQLite storage
- Digest generation via OpenAI Responses API
- DM delivery of summaries (private to the requesting user)
- Noise filtering (short "ok/emoji" messages ignored)
- Automatic DB retention cleanup
- Hierarchical summarization (map → reduce)
- Support for two prompt languages (RU default, EN optional)
- Add Dockerfile for containerized deployment
- Webhook mode (FastAPI/Flask) instead of polling
- Optional message encryption (SQLite with SQLCipher)
- Admin commands (/debug, /vacuum, /backup)
- Configurable summary length (short/long)
- Chunk-level caching to avoid re-summarizing identical fragments and save tokens in LLM subscription
MIT © 2025 Mike Yastrebtsov