A simple java library to create telegram bots. Work in progress.
Just add TeleBot to your dependencies using jitpack:
Maven:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.github.EXH3Y</groupId>
<artifactId>TeleBot</artifactId>
<version>0.1.0</version>
</dependency>
Creating a simple telegram bot responding to text commands is quite easy using TeleBot! Just start by creating a TeleBot object and register your actions to react to the corresponding commands:
Main class:
TeleBot bot = new TeleBot("yourTokenHere");
bot.registerCommandAction("/test", new TestAction(bot));
bot.start();
TestAction (implementing TelegramActionHandler):
private TeleBot bot;
public TestAction(TeleBot bot) {
this.bot = bot;
}
@Override
public void onMessageReceive(TelegramMessage message) {
try {
bot.sendMessage(message.getChat().getId(), "Responding to 'test'");
} catch (JSONException | UnirestException e) {
// Catch the error
}
}
Main class:
TeleBot bot = new TeleBot("yourTokenHere");
bot.registerCommandAction("/test", new TestAction(bot));
bot.start();
TestAction (implementing TelegramActionHandler):
private TeleBot bot;
public TestAction(TeleBot bot) {
this.bot = bot;
}
@Override
public void onCommandReceive(int chatId, JSONObject responseObject) {
try {
bot.sendMessage(chatId, "Responding to 'test'");
} catch (JSONException | UnirestException e) {
// Catch the error
}
}