Installation Guide
This guide covers everything you need to install and run TelegrmBot API in both production (Docker) and development (local) environments.Prerequisites
Required Software
Java Development Kit 21
TelegrmBot API requires JDK 21 or higher.Verify installation:Expected output:Installation:
Apache Maven 3.9+
Maven is used for dependency management and building the application.Verify installation:Expected output:Installation:
Docker & Docker Compose
Required for containerized deployment (recommended) and integration tests.Verify installation:Installation:
- Linux: Follow Docker’s official installation guide
- macOS: Install Docker Desktop for Mac
- Windows: Install Docker Desktop for Windows
Optional Tools
| Tool | Purpose | Installation |
|---|---|---|
| IntelliJ IDEA | Recommended IDE | Download Community Edition |
| Postman/Bruno | API testing | Bruno or Postman |
| Git | Version control | apt install git / brew install git |
The project includes a Bruno collection for API testing. Bruno is an open-source alternative to Postman with Git-friendly storage.
Installation Methods
Choose the installation method that fits your needs:Docker (Recommended)
Best for: Production deployment, quick testing, consistent environmentsPros:
- Zero configuration
- Automatic database setup
- Isolated environment
- Fast deployment
Local Development
Best for: Active development, debugging, IDE integrationPros:
- Hot reload support
- Full debugging capabilities
- Direct database access
- Faster iteration
Method 1: Docker Installation (Recommended)
Step 1: Clone the Repository
Step 2: Configure Environment
Create a.env file from the example:
.env with your configuration:
.env
Step 3: Review Docker Configuration
Thedocker-compose.yml defines two services:
docker-compose.yml
Step 4: Build and Launch
Start all services:First Build: Maven downloads dependencies and compiles the application. This takes 2-4 minutes.Subsequent Builds: Much faster as dependencies are cached.
Step 5: Verify Installation
Access Swagger UI
Open http://localhost:8080/swagger-ui.html in your browser.You should see the interactive API documentation.
Managing Docker Services
Method 2: Local Development Setup
Step 1: Clone Repository
Step 2: Set Up PostgreSQL Database
Create the database and user:Step 3: Configure Application
Set environment variables (choose your method):Step 4: Build the Application
- Download all dependencies
- Compile the source code
- Run unit tests
- Package the application as a JAR
First build takes 1-2 minutes. Maven caches dependencies for faster subsequent builds.
Step 5: Run the Application
Step 6: Enable Hot Reload (Optional)
Spring Boot DevTools enables automatic restart on code changes. It’s already included inpom.xml:
pom.xml
- Go to Settings → Build, Execution, Deployment → Compiler
- Enable “Build project automatically”
- Press
Ctrl+Shift+A→ search for “Registry” - Enable
compiler.automake.allow.when.app.running
Database Migrations with Flyway
The application uses Flyway for version-controlled database schema management.Migration Files
Located insrc/main/resources/db/migration/:
How Migrations Work
On Application Startup
Flyway automatically:
- Checks the current database schema version
- Compares it with migration files
- Applies any pending migrations in order
- Records applied migrations in
flyway_schema_historytable
Configuration
Flyway is configured inapplication.yaml:
application.yaml
Running Tests
The project includes comprehensive tests using JUnit 5, Mockito, and Testcontainers.Run All Tests
Testcontainers automatically spins up PostgreSQL in Docker for integration tests. Ensure Docker is running!
Run Unit Tests Only
Run Specific Test Class
Test Structure
Troubleshooting
Port 8080 already in use
Port 8080 already in use
Solution 1: Change the port in Solution 2: Kill the process using port 8080:
application.yaml:Database connection refused
Database connection refused
Symptoms:Solutions:
- Verify PostgreSQL is running:
- Check connection parameters in environment variables
- Test connection manually:
- Verify firewall allows port 5432
Flyway migration failures
Flyway migration failures
Symptoms:Solutions:
- Development: Drop and recreate the database:
- Production: Repair Flyway:
- Never modify applied migration files
Maven dependency download issues
Maven dependency download issues
Symptoms:Solutions:
- Clear Maven cache:
- Check internet connection
- Try a different Maven repository mirror
Telegram bot not responding
Telegram bot not responding
Symptoms: Bot doesn’t reply to messagesSolutions:
- Check logs for polling errors:
- Verify
TELEGRAM_BOT_TOKENis correct - Ensure only one instance is running (polling conflict)
- Check that you sent
/startor any message to the bot first - Verify bot is not blocked by the user
OutOfMemoryError during build
OutOfMemoryError during build
Symptoms:Solutions:
- Increase Maven memory:
- For IntelliJ IDEA: Increase heap size in Help → Edit Custom VM Options
JWT token validation fails
JWT token validation fails
Symptoms:Solutions:
- Ensure
JWT_SECRETis at least 32 characters - Generate a proper secret:
openssl rand -base64 32 - Verify token format:
Authorization: Bearer <token> - Check token hasn’t expired (24-hour validity)
- Obtain a fresh token via
/auth/login
IDE Setup
IntelliJ IDEA (Recommended)
Import Project
- File → Open → Select
pom.xml - Choose “Open as Project”
- Wait for Maven to import dependencies
Enable Annotation Processing
Settings → Build, Execution, Deployment → Compiler → Annotation Processors✅ Enable annotation processing
VS Code
Install Extensions
Required extensions:
- Extension Pack for Java
- Spring Boot Extension Pack
- Lombok Annotations Support
Production Deployment Checklist
Security
- Use strong, unique passwords for all services
- Rotate
JWT_SECRETregularly - Enable HTTPS with valid SSL certificate
- Configure firewall to restrict database access
- Never expose
.envfile publicly
Database
- Set up automated backups
- Configure connection pooling
- Enable SSL for database connections
- Monitor database performance
Application
- Set appropriate
AI_MAX_TOKENSto control costs - Configure logging (use external log aggregation)
- Set up health check monitoring
- Configure restart policies in Docker
Next Steps
Quick Start Guide
Get the bot running and test the API endpoints
API Documentation
Explore available endpoints in Swagger UI at http://localhost:8080/swagger-ui.html
Architecture Deep Dive
Learn about the hexagonal architecture implementation
Configuration Reference
See
application.yaml for all configuration optionsAdditional Resources
- Source Code: https://github.com/acamus79/TlgrmBot
- Spring Boot Documentation: https://spring.io/projects/spring-boot
- Telegram Bot API: https://core.telegram.org/bots/api
- OpenRouter Documentation: https://openrouter.ai/docs
- Flyway Documentation: https://flywaydb.org/documentation