Environment Variables & Configuration
Relevant source files
The following files were used as context for generating this wiki page:
The GentelmeN-CorE system relies heavily on environment variables to manage sensitive credentials, external API integrations, and database connectivity. This configuration approach ensures that the application remains portable across different environments while keeping secrets out of the source code. The bot utilizes these variables to initialize core clients for Telegram, Groq AI, KuCoin exchange, and Brave Search.
The application is designed to "fail fast" if critical configuration is missing, specifically regarding the Telegram and Groq AI credentials. Other integrations, such as the database and exchange services, include fallback mechanisms or graceful degradation if their respective variables are not provided.
Sources: core/bot.py:14-25, core/database.py:5-10
Core Service Configuration
The primary functionality of the bot is driven by several mandatory and optional environment variables. These variables are loaded at runtime using the os.environ module.
Mandatory Variables
If these variables are missing, the application will raise a RuntimeError during the initialization phase in core/bot.py.
- TELEGRAM_TOKEN: The unique token provided by BotFather to authenticate the bot with the Telegram API.
- GROQ_KEY: The API key required to interact with the Groq AI platform for generating chat responses and transcriptions.
Optional Integrations
Other variables enable specific features like search, image generation, and cryptocurrency management. If these are absent, the associated commands will return an error message to the user rather than crashing the bot.
Sources: core/bot.py:14-25, core/commands.py:15-16, core/integrations.py:6-7
| Variable Name | Purpose | Default/Fallback |
|---|---|---|
DATABASE_URL | Connection string for PostgreSQL database. | None (Falls back to in-memory cache) |
ADMIN_ID | Telegram user ID authorized for administrative commands. | 0 |
OWNER_USER_ID | Specific ID for wallet/balance authorization. | Username-based check (GentelmeN_CorE) |
BRAVE_API_KEY | Key for Brave Search API integration. | None (Disables /szukaj) |
HF_TOKEN | Hugging Face token for image generation (FLUX.1). | None (Disables /rysuj) |
GITHUB_TOKEN | Optional token for higher GitHub API rate limits. | None (Uses unauthenticated requests) |
KUCOIN_API_KEY | Public key for KuCoin exchange API. | None (Disables balance/alerts) |
KUCOIN_SECRET | Secret key for KuCoin exchange API. | None |
KUCOIN_PASSWORD | API passphrase for KuCoin. | None |
Sources: core/bot.py:27-33, core/commands.py:15-16, core/commands.py:121-125, core/database.py:5-7, core/integrations.py:6-7
Data Persistence Configuration
The bot uses the DATABASE_URL variable to establish a connection to a PostgreSQL database via psycopg2. This database stores user preferences (language and model selection) and price alerts.
Configuration Logic
The system implements a dual-layer storage strategy. It maintains local dictionaries (user_prefs and user_models) as a cache. If DATABASE_URL is present, it synchronizes these settings with the database. If absent, the bot continues to function using only the in-memory cache, though data will not persist across restarts.
The diagram above illustrates how the DATABASE_URL environment variable determines the persistence strategy during startup and runtime.
Sources: core/database.py:5-30, core/database.py:64-70
Security and Authorization
Authorization levels are controlled through environment variables to prevent unauthorized access to sensitive financial data or administrative tools.
- Admin Access: The
ADMIN_IDvariable is used to restrict commands like/alertand/alerty. - Wallet Security: The
/balancecommand uses a hierarchical check. It first looks forOWNER_USER_ID. If that is not set, it defaults to checking if the message sender's username matches "GentelmeN_CorE".
Deployment Configuration
The repository contains a railway.json file which configures the deployment environment on the Railway platform.
- Start Command:
python bot.py - Restart Policy: Set to
ON_FAILUREwith a maximum of 10 retries. - Startup Delay: The bot includes a hardcoded 15-second sleep (
time.sleep(15)) at startup to allow previous processes to terminate before starting the Telegram polling loop.
Sources: railway.json:7-14, core/bot.py:90-93
Summary
Configuration in GentelmeN-CorE is managed through a robust set of environment variables that enable or disable features based on their availability. While TELEGRAM_TOKEN and GROQ_KEY are strictly required for the bot to run, the architecture allows for optional modules like cryptocurrency tracking and web searching to be configured independently via their respective API keys. This modular configuration simplifies local development and production deployment.