TelegramBots Starter is a Spring Boot starter library designed to simplify the development of Telegram bot applications.
Instead of manually creating message objects, copying chatIds, and managing message dispatch logic, this library allows you to focus solely on the core logic of your bot.
- Easy-to-use API
- Faster development of Telegram bots with Spring Boot
- Automatic management of
Messagebeans - Automatic extraction of data from
Updateobjects - Automatic message sending after logic execution
- Built-in support for virtual threads (Java 21+ required)
Note: This library requires the telegrambots dependency.
First, add the Telegram Bots dependency:
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>6.9.7.0</version>
</dependency>Then, add this starter library:
<dependency>
<groupId>uz.sonic</groupId>
<artifactId>spring-boot-starter-telegrambots</artifactId>
<version>0.0.2</version>
</dependency>Add the following properties to your application.yml (or application.properties):
telegram:
bot:
username: ${BOT_USERNAME}
token: ${BOT_TOKEN}Extend AbstractTelegramBot and annotate the class with @Component:
@Component
public class MyBot extends AbstractTelegramBot {
protected MyBot(DefaultBotOptions options, TelegramBotProperties properties, BotService service) {
super(options, properties, service);
}
}Create a class that implements BotService and annotate it with @Component:
@Component
@Slf4j
public class MyBotService implements BotService {
@Override
public void onUpdateReceived(Update update) {
log.info("Received update: {}", update.getUpdateId());
}
}You can inject AutoSendMessage (which extends SendMessage) and use it directly:
@Component
@Slf4j
public class MyBotService implements BotService {
private final AutoSendMessage sendMessage;
public MyBotService(AutoSendMessage sendMessage) {
this.sendMessage = sendMessage;
}
@Override
public void onUpdateReceived(Update update) {
sendMessage.setText("Hello, this is a test message from MyBotService!");
log.info("Received update: {}", update.getUpdateId());
}
}This library will automatically send the message when
AutoSendMessageis configured properly.
Java 21 or higher (required for virtual thread support)
Find the full source code on GitHub: telegrambots-sample
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.
See CONTRIBUTING.md for details.
This project is licensed under the Apache 2.0 License – see the LICENSE file for details.