Overview
The TelegrmBot API uses environment variables for all configuration. This approach follows the Twelve-Factor App methodology, ensuring secure and flexible deployments across different environments.All environment variables are loaded from a
.env file in the project root. The application reads this file automatically using Spring Boot’s configuration import feature.Quick Start
Copy the example file and configure your values:.env with your actual credentials.
Configuration Reference
Database Configuration
PostgreSQL database connection settings.PostgreSQL username for database authentication.Default:
postgresExample:For production, create a dedicated user instead of using the default
postgres superuser.PostgreSQL password for database authentication.Default: None (must be set)Example:
JDBC connection URL for PostgreSQL database.Default (Docker):
jdbc:postgresql://db:5432/telegrmdbDefault (Local): Must be set manuallyExamples:When using Docker Compose,
db resolves to the PostgreSQL container. For local development, use localhost.Telegram Configuration
Telegram Bot API integration settings.Authentication token for your Telegram bot.Default: None (must be obtained from BotFather)Example:How to obtain:
- Open Telegram and search for @BotFather
- Send
/newbotcommand - Follow instructions to create your bot
- Copy the token provided by BotFather
AI Configuration (OpenRouter)
AI response generation using OpenRouter API.API key for OpenRouter service.Default: None (must be obtained from OpenRouter)Example:How to obtain:
- Visit openrouter.ai
- Sign up or log in
- Navigate to API Keys section
- Generate a new API key
OpenRouter provides access to multiple AI models through a unified API. The application uses the
tngtech/deepseek-r1t2-chimera:free model by default.System prompt that defines the AI’s personality and behavior.Default:
"Eres una IA demente..."Example:The system prompt significantly affects AI responses. Customize it to match your bot’s intended personality and use case.
Controls randomness in AI responses. Higher values (e.g., 1.4) produce more creative/random outputs, while lower values (e.g., 0.2) produce more focused/deterministic responses.Default:
1.4Range: 0.0 to 2.0Examples:A temperature of 1.0 is neutral. Values above 1.0 increase randomness, while values below 1.0 make responses more deterministic.
Maximum number of tokens (words/characters) in AI responses.Default:
200Range: 1 to 4096 (model-dependent)Examples:Security Configuration
JWT token generation and authentication settings.Secret key used to sign and verify JWT tokens.Default: None (must be generated)Example:How to generate:
Environment-Specific Configuration
Development Environment
Recommended settings for local development:Use separate Telegram bots and API keys for development to avoid affecting production data and rate limits.
Production Environment
Recommended settings for production:Docker Compose Environment
When using Docker Compose, theDB_URL is automatically configured:
Docker Compose automatically sets
DB_URL=jdbc:postgresql://db:5432/telegrmdb in the application container, connecting to the db service.Configuration Validation
Required Variables Check
Ensure all required variables are set before starting:Application Startup Validation
Spring Boot will fail to start if required variables are missing:This fail-fast behavior prevents the application from starting with misconfigured settings.
Security Best Practices
Secret Management
Use secret management tools
For production, use:
- AWS Secrets Manager
- HashiCorp Vault
- Azure Key Vault
- Google Secret Manager
Rotate secrets regularly
Implement a secret rotation policy:
- JWT secrets: Every 90 days
- Database passwords: Every 180 days
- API keys: When compromised or annually
Environment File Permissions
Restrict access to the.env file:
Audit and Monitoring
- Enable audit logging for configuration changes
- Monitor for unauthorized access attempts
- Set up alerts for configuration errors
- Regular security reviews of environment configuration
Troubleshooting
Variable Not Found
Error:- Verify variable name matches exactly (case-sensitive)
- Check
.envfile exists in project root - Ensure no spaces around
=sign - Restart application after changes
Invalid Database URL
Error:- Check PostgreSQL is running:
pg_isready - Verify port 5432 is accessible
- For Docker: Use
dbinstead oflocalhost - For local: Use
localhostinstead ofdb
JWT Token Issues
Error:- Verify
JWT_SECREThasn’t changed - Clear existing tokens and re-authenticate
- Check secret length (minimum 32 characters)
Next Steps
Docker Deployment
Deploy with Docker Compose
Local Development
Set up local development environment