Telegram bot that collects recent messages from configured group chats, summarizes them with OpenAI, and sends the summary to approved Telegram users.
This repository is a maintained derivative of Georgiy Manuilov's MIT-licensed Telegram chat summarizer. The current version adds environment overrides, rate limiting, chunked summaries, and operational logging.
- Monitors one or more Telegram group chats.
- Summarizes recent text messages with a configurable prompt.
- Sends summaries through a Telegram bot.
- Supports approved summary receivers and chat context switching.
- Splits large histories into chunks before summarization.
- Uses environment variables to override sensitive configuration fields.
- Python 3.10+
- Telegram API credentials (
api_id,api_hash) - Telegram bot token
- OpenAI API key
git clone https://github.com/DoctorYanmar/Summarizer.git
cd Summarizer
python -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txt
cp config.example.json config.jsonEdit config.json, then run:
python app.py config.jsonOn first Telegram client login, Telethon may ask for a phone/code/password and create a local .session file. Session files are ignored by Git.
config.example.json contains placeholders:
{
"telegram_api_id": 123456,
"telegram_api_hash": "replace-with-telegram-api-hash",
"telegram_bot_auth_token": "replace-with-bot-token",
"bot_username": "replace-with-bot-username",
"openai_api_key": "replace-with-openai-api-key",
"chats_to_summarize": [
{
"id": "example_group_or_chat_id",
"summarization_prompt_path": "prompts/example_summarization_prompt.txt"
}
],
"telegram_summary_receivers": [123456789]
}Sensitive values can also be supplied through environment variables:
TELEGRAM_API_IDTELEGRAM_API_HASHTELEGRAM_BOT_AUTH_TOKENBOT_USERNAMEOPENAI_API_KEYCHATS_TO_SUMMARIZETELEGRAM_SUMMARY_RECEIVERSMESSAGE_LIMIT
Do not commit config.json, .env, .session files, or logs.
.
├── app.py # Entrypoint
├── config.example.json # Safe configuration template
├── requirements.txt
├── prompts/example_summarization_prompt.txt
└── src/
├── main.py # Application orchestration
├── group_chat_scrapper.py # Telegram history collection
├── summarization.py # OpenAI summarization
├── envoy_bot.py / bot_core.py # Telegram bot interface
├── bot_handlers.py # Commands and callbacks
├── config.py # Config/env loading
└── user_management.py # Receiver verification/context
Original implementation by Georgiy Manuilov, MIT License, with documentation published on Habr: https://habr.com/ru/articles/804111/
MIT License. See LICENSE.