Local Development Setup
Relevant source files
The following files were used as context for generating this wiki page:
The Local Development Setup provides a minimal environment to run the Telegram Summary Bot on a local machine. This configuration supports a Python-based bot that uses long-polling to interact with the Telegram Bot API, summarizes text messages locally, and manages recent chat history without external database dependencies.
The system requires a Telegram Bot token and a Python 3 environment. It facilitates immediate testing of commands like /start, /help, and /summary through a simple extractive summarization logic implemented in the core script.
Sources: README.md:3-11, bot.py:1-20
Environment Configuration
The bot relies on environment variables for authentication and behavioral tuning. You must create a .env file in the root directory based on the provided example to store these values securely.
Configuration Variables
| Variable | Required | Default | Description |
|---|---|---|---|
TELEGRAM_BOT_TOKEN | Yes | None | The authentication token obtained from @BotFather. |
LOG_LEVEL | No | INFO | The verbosity of the Python logger (e.g., DEBUG, INFO, ERROR). |
POLL_TIMEOUT | No | 30 | Time in seconds for Telegram long-polling requests. |
MAX_STORED_MESSAGES | No | 100 | Number of recent messages kept in memory per chat. |
SUMMARY_SENTENCES | No | 5 | The limit of sentences included in a generated summary. |
Sources: README.md:33-39, bot.py:22-33, .env.example
Installation Procedure
To set up the development environment, follow these steps to isolate dependencies and configure the runtime.
- Initialize Virtual Environment: Create a Python virtual environment to manage dependencies locally.
python3 -m venv .venv source .venv/bin/activate - Install Dependencies: Use the project's requirement file to install necessary libraries including
urllib3for API requests andpython-dotenvfor configuration management.pip install -r requirements.txt - Configure Secrets: Copy the template environment file and insert your
TELEGRAM_BOT_TOKEN.cp .env.example .env - Execute Bot: Run the main script to start the long-polling loop.
python bot.py
Sources: README.md:21-31, requirements.txt:1-6
Architecture and Data Flow
The bot operates as a single-threaded application using the urllib3 library to communicate with the Telegram Bot API. It maintains an in-memory chat_messages dictionary to store recent message history for summarization.
System Flow Diagram
The following diagram illustrates how the bot polls for updates and processes commands from a user.
Sources: bot.py:53-128, README.md:52-54
Summarization Logic
The local summarizer performs extractive summarization without external AI APIs. It cleans the input text, splits it into sentences based on punctuation, and returns a subset defined by SUMMARY_SENTENCES.
Sources: bot.py:75-92, README.md:11-13
Local Execution Components
The development environment consists of several key functional components within bot.py:
telegram_api(method, payload): Handles raw POST requests to the Telegram API usingurllib3.PoolManager. It manages timeouts and validates the "ok" status of responses.chat_messages: Adefaultdictusingdequewith a fixedmaxlento store message history perchat_id. This prevents memory exhaustion during local testing.handle_shutdown: A signal handler forSIGINTandSIGTERMthat ensures the polling loop terminates gracefully.
Sources: bot.py:35-51, bot.py:44, bot.py:125-127
Summary of Setup
Setting up the Telegram Summary Bot locally requires configuring a .env file and running the Python script. This setup enables a lightweight, dependency-light summarization service suitable for private chats and groups where privacy mode is disabled. The project is structured to transition easily from local development to containerized deployment or worker-based cloud hosting via the included Dockerfile and Procfile.
Sources: README.md:41-60, Procfile:1