Local Extractive Summarizer
Relevant source files
The following files were used as context for generating this wiki page:
The Local Extractive Summarizer is a dependency-light component that generates short summaries of Telegram chat messages. It extracts the first few sentences from provided text or historical chat logs without requiring external AI API keys.
This module operates within the bot.py script and supports both direct command-line input and historical context analysis. It captures incoming text messages from Telegram groups or private chats and maintains a rolling window of recent messages for summary generation.
Sources: README.md:14-16, bot.py:1-5
System Architecture and Logic
The summarizer uses a rule-based approach to process text. It splits input into sentences based on punctuation markers and rejoins a configurable number of starting sentences to form the summary.
Message Processing Flow
The system processes messages in two ways:
- Collection: It stores incoming non-command text in a
dequefor each chat. - Extraction: It triggers the summarization logic when a user sends the
/summarycommand.
The diagram shows the decision logic for handling incoming updates and routing them to the summarizer.
Sources: bot.py:108-132
Summarization Algorithm
The summarize_text function performs the following steps:
- Cleans whitespace from the input string.
- Replaces "!" and "?" with "." to standardize sentence boundaries.
- Splits the text by "." into a list of strings.
- Filters out empty strings and joins the first
SUMMARY_SENTENCEStogether.
Sources: bot.py:79-96
Configuration Parameters
The behavior of the summarizer is controlled by environment variables loaded via python-dotenv.
| Variable | Default | Description |
|---|---|---|
MAX_STORED_MESSAGES | 100 | Maximum number of recent messages retained per chat in the chat_messages buffer. |
SUMMARY_SENTENCES | 5 | The number of sentences extracted from the beginning of the text to create the summary. |
LOG_LEVEL | INFO | The verbosity of the system logs. |
Sources: bot.py:24-26, README.md:43-47
Data Structures
The system uses Python's collections module to manage chat history in-memory.
chat_messages: dict[int, deque[str]] = defaultdict(lambda: deque(maxlen=MAX_STORED_MESSAGES))
Sources: bot.py:34-35
defaultdict: Automatically creates a new entry when a uniquechat_idis encountered.deque: A thread-safe double-ended queue with amaxlenattribute that automatically discards the oldest messages when the limit is reached.
Command Interface
The summarizer interacts with users through specific command patterns.
| Command | Action |
|---|---|
/summary <text> | Processes the explicitly provided <text> immediately. |
/summary | Concatenates all messages stored in chat_messages[chat_id] and summarizes them. |
Sources: bot.py:122-129, README.md:10-12
Component Sequence
The following sequence diagram illustrates the interaction between the Telegram API, the bot, and the local summarization logic.
The diagram illustrates the loop of receiving updates and the conditional execution of summarization.
Sources: bot.py:79-142
Summary
The Local Extractive Summarizer provides a lightweight, privacy-focused method for condensing chat history. By relying on basic string manipulation rather than external LLM services, it ensures high performance and zero operational costs for simple text extraction tasks.
Sources: README.md:14-16, bot.py:79-96