This project is a Telegram Bot built using Java 21 and Spring Boot 3.5.7.
The bot uses Long Polling to receive messages from Telegram servers and respond to them automatically.
It also supports Proxy (SOCKS/HTTP) connections for restricted or filtered network environments.
Key Features:
- Receive and reply to user text messages
- Proxy support for internet restrictions
- Full logging with SLF4J
- Spring Boot structure with Dependency Injection
- Easy to extend with new commands and logic
- Java 21 or higher
- Maven or Gradle for building the project
- Spring Boot
- Telegram Bot Token (from BotFather)
- (Optional) Proxy for filtered network environments
src/main/java ├── com.bot.bot │ └── TelegramBot.java # Main bot class ├── com.bot.config │ └── TelegramConfig.java # Bot and Proxy configuration └── resources └── application.properties # Bot and Proxy settings
bot.name=Milad_Java_Assistant_bot bot.token=YOUR_BOT_TOKEN_HERE
proxy.host=127.0.0.1 proxy.port=1080 proxy.type=SOCKS
Spring Boot starts the application.
TelegramConfig creates and registers the TelegramBot bean.
If a Proxy is configured, the bot connects via Proxy.
The bot receives messages from Telegram using Long Polling.
Messages are processed in onUpdateReceived.
Responses are sent with execute(new SendMessage(...)).
All messages and errors are logged for debugging.
Long Polling: Fetch messages continuously without using a webhook
Dependency Injection: Bot name, token, and options are injected via Spring
Proxy Handling: Supports SOCKS or HTTP for filtered internet environments
Logging: SLF4J logs all incoming messages and errors
Error Handling: Handles message sending errors gracefully
Command Function /start Sends a welcome message Any other text Echoes back the text with "You said: " prefix
Add new commands using switch-case in onUpdateReceived
Support images, files, stickers
Connect to external APIs for smart responses
Handle network and Telegram API errors using retries and timeouts
Port 8080 already in use?
Change the server port in application.properties:
server.port=8081
Unable to connect to Telegram in filtered networks?
Enable Proxy:
proxy.host=127.0.0.1 proxy.port=1080 proxy.type=SOCKS
Telegram API Timeout errors?
Ensure internet connection is stable and Proxy works properly.
Consider using Psiphon or another VPN/proxy tool.
- Clone the project:
git clone https://github.com/miladrostami-devjava/Java-Telegram-Bot-.git
cd MiladJavaTelegramBot
🔹 Contact
Developer: Milad Rostami
Email: miladrostami24@gmail.com