Environment Configuration
The TelegramBot API uses environment variables for configuration. This guide covers all required and optional variables.Getting Started
Required Variables
These variables must be configured for the application to work properly.Database Configuration
DB_USER
DB_USER
Type: String
Default:
Description: PostgreSQL database username.
Default:
postgresDescription: PostgreSQL database username.
The default value
postgres typically works with standard PostgreSQL installations.DB_PASSWORD
DB_PASSWORD
Type: String
Required: Yes
Description: Password for the PostgreSQL database user.
Required: Yes
Description: Password for the PostgreSQL database user.
DB_URL (Development Only)
DB_URL (Development Only)
Type: JDBC URL
Required: Only for local development without Docker
Description: Full JDBC connection URL for PostgreSQL.
Required: Only for local development without Docker
Description: Full JDBC connection URL for PostgreSQL.
This variable is only needed when running locally without Docker. Docker Compose automatically sets this.
Telegram Configuration
TELEGRAM_BOT_TOKEN
TELEGRAM_BOT_TOKEN
Type: String
Required: Yes
Description: Authentication token for your Telegram bot.How to obtain:
Required: Yes
Description: Authentication token for your Telegram bot.
- Open Telegram and search for
@BotFather - Send
/newbotcommand - Follow the prompts to create your bot
- Copy the token provided by BotFather
AI Configuration (OpenRouter)
OPENROUTE_KEY
OPENROUTE_KEY
Type: String
Required: Yes
Description: API key for accessing AI models through OpenRouter.How to obtain:
Required: Yes
Description: API key for accessing AI models through OpenRouter.
- Visit OpenRouter.ai
- Create an account or sign in
- Navigate to the “Keys” section
- Generate a new API key
- Copy the key to your
.envfile
Security Configuration
JWT_SECRET
JWT_SECRET
Type: String
Required: Yes
Description: Secret key used to sign and verify JWT authentication tokens.How to generate:
Required: Yes
Description: Secret key used to sign and verify JWT authentication tokens.
The JWT token expires after 24 hours by default (configurable in
application.yaml).Optional Variables
These variables have default values but can be customized for your use case.AI Behavior Configuration
AI_SYSTEM_PROMPT
AI_SYSTEM_PROMPT
Type: String
Default:
Description: System prompt that defines the AI bot’s personality and behavior.
Default:
"IA caótica en español sin lógica, patos espaciales, humor cambiante (no agresivo), sin ser útil."Description: System prompt that defines the AI bot’s personality and behavior.
AI_TEMPERATURE
AI_TEMPERATURE
Type: Float (0.0 - 2.0)
Default:
Description: Controls AI response creativity and randomness.Guidelines:
Default:
1.2Description: Controls AI response creativity and randomness.
0.1 - 0.5: Very predictable and conservative0.6 - 1.0: Balanced responses1.1 - 1.5: Creative and varied1.6 - 2.0: Highly random and chaotic
Higher values produce more creative but less predictable responses.
AI_MAX_TOKENS
AI_MAX_TOKENS
Type: Integer
Default:
Description: Maximum length of AI-generated responses.
Default:
150Description: Maximum length of AI-generated responses.
Higher values allow longer responses but consume more API credits.
Configuration File Reference
Complete .env.example
Application Properties Mapping
The environment variables map to Spring Boot application properties as follows:| Environment Variable | Application Property | Location |
|---|---|---|
DB_USER | spring.datasource.username | application.yaml:8 |
DB_PASSWORD | spring.datasource.password | application.yaml:9 |
DB_URL | spring.datasource.url | application.yaml:7 |
TELEGRAM_BOT_TOKEN | telegram.bot-token | application.yaml:24 |
OPENROUTE_KEY | openrouter.api-key | application.yaml:27 |
AI_SYSTEM_PROMPT | openrouter.system-prompt | application.yaml:30 |
AI_TEMPERATURE | openrouter.temperature | application.yaml:31 |
AI_MAX_TOKENS | openrouter.max-tokens | application.yaml:32 |
JWT_SECRET | jwt.secret | application.yaml:35 |
Validation and Troubleshooting
Verifying Configuration
You can verify your configuration is loaded correctly by checking the application startup logs:- Database connection
- Flyway migrations
- Telegram bot polling
- OpenRouter AI adapter
Security Best Practices
Use different secrets per environment
Development, staging, and production should have unique
JWT_SECRET values.Rotate secrets regularly
Change
JWT_SECRET and OPENROUTE_KEY periodically, especially after team changes.Next Steps
Telegram Setup
Learn how to create and configure your Telegram bot
AI Configuration
Configure AI behavior and model selection
Development Guide
Set up your local development environment
Authentication
Understand the JWT authentication flow