Skip to content

Latest commit

 

History

History
83 lines (67 loc) · 1.99 KB

README.md

File metadata and controls

83 lines (67 loc) · 1.99 KB

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