Telebof is easy and modern Java library for building Telegram bots using the Telegram Bot API.
Supports integrating with SpringBoot through telebof-spring module, and both synchronous and asynchronous request.
Add the following dependency to your pom.xml:
<dependency>
<groupId>io.github.natanimn</groupId>
<artifactId>telebof</artifactId>
<version>2.0.0</version>
</dependency>Add the following to your build.gradle:
implementation 'io.github.natanimn:telebof:2.0.0'import io.github.natanimn.telebof.BotClient;
public class MyFirstEchoBot {
static final String TOKEN = "YOUR_BOT_TOKEN_HERE"; // Get from @BotFather
public static void main(String[] args) {
final BotClient bot = new BotClient(TOKEN);
// Handle /start command
bot.onMessage(filter -> filter.commands("start"), (context, message) -> {
context.sendMessage(message.getChat().getId(), "Welcome to my echo bot! π").exec();
});
// Echo any text message
bot.onMessage(filter -> filter.text(), (context, message) -> {
context.sendMessage(message.getChat().getId(), "You said: " + message.getText()).exec();
});
bot.startPolling(); // Start the bot
}
}import io.github.natanimn.telebof.annotations.MessageHandler;
import io.github.natanimn.telebof.BotContext;
import io.github.natanimn.telebof.types.Message;
import io.github.natanimn.telebof.enums.MessageType;
import io.github.natanimn.telebof.BotClient;
public class MyFirstEchoBot {
static final String TOKEN = "YOUR_BOT_TOKEN_HERE"; // Get from @BotFather
public static void main(String[] args) {
final BotClient bot = new BotClient(TOKEN);
bot.addHandler(new MyFirstEchoBot());
bot.startPolling();
}
@MessageHandler(commands = "start")
void start(BotContext context, Message message){
context.sendMessage(message.getChat().getId(), "Welcome to my echo bot! π").exec();
}
@MessageHandler(type = MessageType.TEXT, priority = 1)
void echo(BotContext context, Message message){
context.sendMessage(message.getChat().getId(), "You said: " + message.getText()).exec();
}
} Using .await() method
import io.github.natanimn.telebof.annotations.MessageHandler;
import io.github.natanimn.telebof.BotContext;
import io.github.natanimn.telebof.types.Message;
import io.github.natanimn.telebof.enums.MessageType;
import io.github.natanimn.telebof.BotClient;
import io.github.natanimn.telebof.async.AsyncCallback;
public class MyFirstEchoBot {
static final String TOKEN = "YOUR_BOT_TOKEN_HERE"; // Get from @BotFather
public static void main(String[] args) {
final BotClient bot = new BotClient(TOKEN);
bot.addHandler(new MyFirstEchoBot());
bot.startPolling();
}
@MessageHandler(commands = "start")
void start(BotContext context, Message message){
context.sendMessage(message.getChat().getId(), "Welcome to my echo bot! π").await();
}
@MessageHandler(type = MessageType.TEXT, priority = 1)
void echo(BotContext context, Message message){
context.sendMessage(message.getChat().getId(), "You said: " + message.getText())
.await(
new AsyncCallback<>(){
public void onSuccess(Message msg){
System.out.println("Echoed successfully");
}
public void onFailure(Exception e){
System.err.println("Failed to echo due to: " + e.getMessage());
}
}
);
}
} To get started:
- Create a bot with @BotFather on Telegram
- Replace
YOUR_BOT_TOKEN_HEREwith your actual bot token - Run the code and send a message to your bot!
No manual or complex configuration needed. Just install additional module telebof-spring and pass bot.token inside application.properties
Maven
<dependency>
<groupId>io.github.natanimn</groupId>
<artifactId>telebof-spring</artifactId>
<version>2.0.0</version>
</dependency>Gradle
implementation 'io.github.natanimn:telebof-spring:2.0.0'import io.github.natanimn.telebof.BotContext;
import io.github.natanimn.telebof.spring.Bot;
import io.github.natanimn.telebof.annotations.MessageHandler;
import io.github.natanimn.telebof.enums.MessageType;
import io.github.natanimn.telebof.types.updates.Message;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@Bot
public class SpringExampleApplication {
@MessageHandler(commands = "start")
public void start(BotContext context, Message message){
context.sendMessage(message.getChat().getId(), "Hello, I am echo bot").exec();
}
@MessageHandler(type = MessageType.TEXT, priority = 1)
public void echo(BotContext context, Message message){
context.sendMessage(message.getChat().getId(), message.getText()).exec();
}
public static void main(String[] args){
SpringApplication.run(SpringExampleApplication.class, args);
}
}Visit our comprehensive documentation at:
https://natanimn.github.io/telebof
Detailed API reference available at:
https://natanimn.github.io/telebof-api
import io.github.natanimn.telebof.BotClient;
import io.github.natanimn.telebof.types.keyboard.InlineKeyboardButton;
import io.github.natanimn.telebof.types.keyboard.InlineKeyboardMarkup;
public class AdvancedBot {
public static void main(String[] args) {
final BotClient bot = new BotClient(TOKEN);
bot.onMessage(filter -> filter.commands("start"), (context, message) -> {
var keyboard = new InlineKeyboardMarkup();
keyboard.addKeyboard(new InlineKeyboardButton("Option 1", "opt1"));
keyboard.addKeyboard(new InlineKeyboardButton("Option 2", "opt2"));
context.sendMessage(message.getChat().getId(), "Choose an option:")
.replyMarkup(keyboard)
.exec();
});
bot.onCallback(filter -> filter.callbackData("opt1", "opt2"), (context, callback) -> {
context.answerCallbackQuery(callback.getId(), "Option selected!").exec();
});
bot.startPolling();
}
}- Support Group: Join our Telegram group for help and discussions
- News Channel: Follow our channel for updates and announcements
- Documentation: Check our comprehensive docs first
- GitHub Discussions: Ask questions in our community forum
- Issue Tracker: Report bugs or request features
Want your bot to be listed here?
Requirements: Public source code
How to submit: Make a pull request with your bot implementation!
We welcome contributions from the community! Here's how you can help:
- Code Contributions: Implement new features or fix bugs
- Documentation: Improve documentation and examples
- Testing: Help test new features and report issues
- Examples: Create and share example bots
This project is licensed under the MIT License - see the LICENSE file for details.
If you find Telebof useful, please consider:
- β Star the repository on GitHub
- π Report issues and help improve the library
- π¬ Join our community and help other developers
- π’ Share with others who might find it useful