Channel & Group Management
Relevant source files
The following files were used as context for generating this wiki page:
Channel & Group Management enables automated monitoring and content summarization for Telegram conversations. The system tracks incoming text messages within specific chat environments and provides tools for summarizing recent activity or specific text inputs.
The module operates as a long-running worker that interfaces with the Telegram Bot API. It maintains local state for recent messages to support group-wide summaries without requiring external database dependencies.
Sources: README.md:3-12, bot.py:1-7
Message Tracking and Storage
The bot tracks recent text messages for every chat it belongs to. It uses a thread-safe dictionary to map chat IDs to a fixed-size queue of message strings. This allows the bot to retain context for summarization even in high-activity groups.
The diagram above shows the lifecycle of a message update as it enters the local storage system.
Sources: bot.py:31-31, bot.py:98-112
Configuration Parameters
The behavior of message storage is controlled by environment variables defined in the deployment environment.
| Variable | Type | Default | Description |
|---|---|---|---|
MAX_STORED_MESSAGES | Integer | 100 | The number of recent messages retained per chat for summary generation. |
POLL_TIMEOUT | Integer | 30 | Long-polling timeout for the Telegram API. |
LOG_LEVEL | String | INFO | The verbosity of the system logs. |
Sources: README.md:43-51, bot.py:21-29
Command Processing Logic
The system distinguishes between administrative health checks, help requests, and summarization tasks. Commands are identified by specific prefixes within the incoming text stream.
Request Flow
When a user sends a command, the bot determines the source of the text (either the command arguments or the historical message buffer) before processing.
The sequence diagram illustrates how the bot handles the /summary command depending on whether additional text was provided by the user.
Sources: bot.py:105-112, bot.py:117-127
Summarization Engine
The summarization logic employs a local, dependency-light extractive approach. It does not require external AI API keys. The engine cleans the input text, splits it into constituent sentences based on punctuation, and returns a condensed version based on the SUMMARY_SENTENCES configuration.
def summarize_text(text: str) -> str:
cleaned = " ".join(text.split())
if not cleaned:
return "No text found to summarize."
sentences = [
sentence.strip()
for sentence in cleaned.replace("!", ".").replace("?", ".").split(".")
if sentence.strip()
]
if not sentences:
return cleaned[:1000]
summary = ". ".join(sentences[:SUMMARY_SENTENCES])
return f"{summary}."
Sources: bot.py:72-88, README.md:14-15
Security and Privacy Requirements
For successful group management, specific bot permissions and privacy settings are required:
- Privacy Mode: You must disable privacy mode via @BotFather using
/setprivacyto allow the bot to read messages in groups. - Token Security: The
TELEGRAM_BOT_TOKENmust be stored in a.envfile or environment variable and never committed to version control. - Instance Control: Only one instance of the bot should run per token to prevent long-polling conflicts.
Sources: README.md:21-25, README.md:104-106, bot.py:35-37
Deployment Architecture
The system is designed to run as a background worker. It can be containerized using the provided Docker configuration or managed as a systemd service on a VPS.
The diagram outlines the structure of the runtime environment, including how environment variables and signal handlers integrate with the main execution loop.
Sources: bot.py:130-136, README.md:83-95, Dockerfile
Channel & Group Management provides a streamlined way to maintain oversight of chat activity through local summarization. By managing message buffers per chat ID and offering configurable extractive summaries, it serves as a lightweight alternative to complex AI-integrated managers.