Skip to content

A simple java library to create telegram bots.

License

Notifications You must be signed in to change notification settings

ClasherKasten/TeleBot

 
 

Repository files navigation

TeleBot TeleBot TestsRelease

A simple java library to create telegram bots. Work in progress.

Get it

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.ClasherKasten</groupId>
    <artifactId>TeleBot</artifactId>
    <version>0.1.3</version>
</dependency>

How to use this library

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:

Since 0.1.0 (introduction of new datatypes)

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
  }
}

Before 0.1.0

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
  }
}

About

A simple java library to create telegram bots.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%