Vibecoded prototype of Spring Boot-based Telegram bot that allows users to communicate with car owners using license plate numbers. Users can register their license plates, send predefined messages, and share contact information with other car owners.
- License Plate Registration: Users can register their car license plates linked to their Telegram ID
- Direct Messaging: Send predefined messages to other users by license plate
- Contact Sharing: Share your Telegram username with other car owners
- Plate Management: Register, view, and delete license plates
- Rate Limiting: Prevents spam with configurable message limits (default: 3 messages per hour)
- Database Storage: All data stored in PostgreSQL with Flyway migrations
- User Management: Automatic user creation and profile management
- Java 17
- Spring Boot 3.2.0
- Spring Data JPA
- PostgreSQL
- Telegram Bot API 6.9.7.1
- Flyway (Database Migrations)
- Maven
- Docker 20.10 or higher
- Docker Compose 2.0 or higher
- Telegram Bot Token (from @BotFather)
- Start a chat with @BotFather on Telegram
- Send
/newbotcommand - Follow the instructions to create your bot
- Note down the bot token and username
# Copy the example environment file
cp .env.example .env
# Edit .env file with your bot token and other preferences
nano .envUpdate the .env file with your values:
TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here
TELEGRAM_BOT_USERNAME=YourBotUsername# Clone the repository
git clone <repository-url>
cd carBlock
# Start all services (builds and runs)
docker-compose up --build
# Or run in background
docker-compose up -d --buildThe application will be available with:
- PostgreSQL database automatically created and configured
- Flyway migrations executed automatically
- Bot connected to Telegram and ready to receive messages
docker-compose downIf you prefer to run without Docker:
- Java 17 or higher
- PostgreSQL 12 or higher
- Maven 3.6 or higher
Create a PostgreSQL database:
CREATE DATABASE carblock_db;
CREATE USER carblock_admin WITH PASSWORD 'carblock_password';
GRANT ALL PRIVILEGES ON DATABASE carblock_db TO carblock_admin;Update src/main/resources/application.properties:
# Database Configuration
spring.datasource.url=jdbc:postgresql://localhost:5432/carblock_db
spring.datasource.username=carblock_admin
spring.datasource.password=carblock_password
# Telegram Bot Configuration
telegram.bot.token=YOUR_TELEGRAM_BOT_TOKEN_HERE
telegram.bot.username=YOUR_BOT_USERNAME_HERE
# Rate Limiting Configuration
app.rate-limit.max-messages-per-hour=3
app.rate-limit.window-size-minutes=60# Build the application
mvn clean install
# Run the application
mvn spring-boot:runAlternatively, you can run the JAR file directly:
java -jar target/telegram-bot-1.0.0.jar| Command | Description | Example |
|---|---|---|
/start |
Welcome message and introduction | /start |
/help |
Show all available commands | /help |
/register <plate> |
Register your license plate | /register ABC123 |
/plates |
View your registered plates | /plates |
/delete [number] |
Delete a registered license plate | /delete 1 |
/send <plate> |
Send message to plate owner | /send XYZ789 |
/contact <plate> |
Share your contact with plate owner | /contact XYZ789 |
/status |
Check your messaging status | /status |
The bot comes with 1 predefined message template:
- "Please move your car, it's blocking my exit."
Additional message templates can be added through the database or by modifying the migration scripts.
The application uses the following main tables:
- users: Stores Telegram user information
- car_plates: Links license plates to users
- message_templates: Predefined message templates
- messages: Stores sent messages
- rate_limits: Tracks user message limits
- Users can send a maximum of 3 messages per hour (configurable)
- Rate limit applies to both
/sendand/contactcommands - Rate limit is per user and resets automatically
- Users can check their remaining messages with
/status - Rate limit window is 60 minutes by default
| Property | Default | Description |
|---|---|---|
app.rate-limit.max-messages-per-hour |
3 | Maximum messages per user per hour |
app.rate-limit.window-size-minutes |
60 | Time window for rate limiting |
spring.jpa.hibernate.ddl-auto |
validate | Hibernate DDL mode |
spring.flyway.enabled |
true | Enable Flyway migrations |
spring.jpa.show-sql |
true | Show SQL statements in logs |
telegram.bot.token |
your_token_here | Telegram bot token |
telegram.bot.username |
CarBlockBot | Telegram bot username |
mvn testNew migrations should be added to src/main/resources/db/migration/ with the naming convention V{number}__Description.sql.
You can add new templates either:
- Via database migration scripts
- Directly in the database
Add new templates by inserting into the message_templates table:
INSERT INTO message_templates (template_text, description, is_active)
VALUES ('Your custom message here', 'Template description', true);- User Telegram IDs are stored securely in the database
- License plate information is only visible to users who know the plate number
- Contact sharing requires users to have a Telegram username
- Rate limiting prevents spam and abuse
- Input validation prevents SQL injection and other attacks
- Users cannot send messages or contact themselves
The application includes comprehensive logging:
- DEBUG level for detailed troubleshooting
- INFO level for general operation
- ERROR level for exceptions
- SQL logging enabled for database operations
Logs can be configured in application.properties:
logging.level.com.carblock=DEBUG
logging.level.org.springframework.web=INFO
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE- Bot doesn't respond: Check bot token and internet connection
- Database connection errors: Verify PostgreSQL is running and credentials are correct
- Migration failures: Check database permissions and Flyway configuration
- Contact sharing fails: Ensure you have a Telegram username set in your profile
- Rate limit exceeded: Wait for the reset time shown in
/statuscommand
The application exposes Spring Boot Actuator endpoints:
GET /actuator/health- Application health statusGET /actuator/info- Application information
Note: Actuator endpoints are available for monitoring but not exposed externally in Docker configuration.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
The application can be configured using environment variables in the .env file:
# Database Configuration
DATABASE_URL=jdbc:postgresql://postgres:5432/carblock_db
DATABASE_USERNAME=carblock_admin
DATABASE_PASSWORD=carblock_password
# Telegram Bot Configuration
TELEGRAM_BOT_TOKEN=your_telegram_bot_token
TELEGRAM_BOT_USERNAME=CarBlockBot
# Rate Limiting (Optional)
RATE_LIMIT_MAX_MESSAGES=3
RATE_LIMIT_WINDOW_MINUTES=60The Docker Compose setup includes two services:
-
postgres: PostgreSQL 15 database
- Persistent data stored in named volume
postgres_data - Default credentials:
carblock_admin/carblock_password - Database:
carblock_db
- Persistent data stored in named volume
-
carblock-bot: Spring Boot application
- Built with Maven using multi-stage Docker build
- Runs on OpenJDK 17 slim runtime
- Connects to PostgreSQL via internal Docker network
- Automatically runs Flyway migrations on startup
- Reads configuration from environment variables
# View logs
docker-compose logs -f carblock-bot
# View database logs
docker-compose logs -f postgres
# Execute commands in the bot container
docker-compose exec carblock-bot java -version
# Access PostgreSQL database
docker-compose exec postgres psql -U carblock_admin -d carblock_db
# Rebuild only the application
docker-compose up --build carblock-bot
# Remove all data (including database)
docker-compose down -vFor production deployment:
-
Security:
- Change default passwords in docker-compose.yml and .env file
- Use strong, unique passwords
- Consider using Docker secrets for sensitive data
- Never commit actual bot tokens to version control
-
Persistence:
- Database data is persisted in the
postgres_datavolume - Backup the volume regularly:
docker run --rm -v postgres_data:/data -v $(pwd):/backup ubuntu tar czf /backup/postgres-backup.tar.gz -C /data .
- Database data is persisted in the
-
Monitoring:
- Monitor container health:
docker-compose ps - Set up log aggregation for production monitoring
- Configure appropriate log levels for production (INFO instead of DEBUG)
- Monitor container health:
-
Performance:
- The application uses OpenJDK 17 slim runtime for optimal size
- Consider resource limits for containers in production
-
Build fails:
- Check Dockerfile syntax
- Verify Maven dependencies in pom.xml
- Ensure Java 17 compatibility
-
Database connection errors:
- Verify PostgreSQL container is running:
docker-compose ps - Check database logs:
docker-compose logs postgres - Ensure network connectivity between containers
- Verify PostgreSQL container is running:
-
Application won't start:
- Check application logs:
docker-compose logs carblock-bot - Verify environment variables are set correctly
- Ensure Telegram bot token is valid
- Check if PostgreSQL container is healthy before the bot starts
- Check application logs:
For issues and questions:
- Create an issue in the GitHub repository
- Check the logs for detailed error information
- Review the troubleshooting section above
- For Docker-specific issues, check container logs with
docker-compose logs - Verify bot commands using
/helpin the Telegram bot - Check your rate limit status with
/statusif messaging fails