Environment Configuration
Relevant source files
The following files were used as context for generating this wiki page:
- README.md
- bot.py
- requirements.txt
- .env.example (referenced via README instructions)
- docker-compose.yml (referenced via Docker deployment instructions)
The Environment Configuration defines the operational parameters for the Telegram Summary Bot. It uses environment variables to manage sensitive credentials, adjust bot behavior, and configure networking timeouts. This configuration allows the bot to run across various environments including local development, Docker containers, and cloud worker platforms.
Sources: README.md:27-50, bot.py:22-35
Core Variable Definitions
The bot uses the python-dotenv library to load settings from a .env file into the process environment. The following table details the primary configuration options available.
| Variable | Required | Default | Description |
|---|---|---|---|
TELEGRAM_BOT_TOKEN | Yes | None | Authentication token obtained from @BotFather. |
LOG_LEVEL | No | INFO | The granularity of Python logging (e.g., DEBUG, INFO, WARNING). |
POLL_TIMEOUT | No | 30 | Duration in seconds for Telegram long-polling requests. |
MAX_STORED_MESSAGES | No | 100 | The number of recent messages kept in memory per chat for summarization. |
SUMMARY_SENTENCES | No | 5 | The maximum number of sentences included in a generated summary. |
Sources: README.md:37-43, bot.py:22-26, requirements.txt:4
Configuration Loading Flow
The bot initializes its configuration during startup. It performs the following sequence to establish its operating context:
The system uses urllib3 for API communication and relies on os.getenv to retrieve values. If TELEGRAM_BOT_TOKEN is missing, the telegram_api function raises a RuntimeError when the first request is attempted.
Sources: bot.py:20-45
Deployment Environment Methods
The environment configuration supports three distinct deployment strategies.
Local Development
You create a .env file by copying .env.example. The bot reads this file directly when executed via the Python interpreter.
Sources: README.md:27-31
Docker Containerization
Environment variables are passed into the container using the --env-file .env flag during the docker run command. This maps host environment files to the containerized process.
Sources: README.md:45-50
Cloud Worker Platforms
Platforms like Render or Railway require variables to be set through their respective dashboard interfaces. The bot functions as a background service/worker rather than a web service.
Sources: README.md:52-59
Application Constants and State
The bot maintains internal state influenced by the environment configuration using specific data structures.
The chat_messages object is a defaultdict using a deque with a maxlen attribute derived from MAX_STORED_MESSAGES. This ensures the memory footprint remains predictable even as message volume increases.
Sources: bot.py:25-35
Summary of Impact
Environment configuration directly dictates the bot's summarization depth and memory usage. By adjusting SUMMARY_SENTENCES and MAX_STORED_MESSAGES, you control the balance between summary detail and system resource consumption. The POLL_TIMEOUT setting specifically affects the responsiveness and network overhead of the long-polling loop.
Sources: bot.py:65-79, bot.py:99-109