к каталогу

📦 java-telegram-bot-api/ pengrad

Telegram Bot API for Java

Открыть на GitHubобновлён 2мес назад
Звёзды
2.0k
Форки
385
За неделю
За месяц
Рост %
Язык
Java

Установка и запуск

Download

Gradle:

implementation 'com.github.pengrad:java-telegram-bot-api:10.1.0'

Maven:

<dependency>
  <groupId>com.github.pengrad</groupId>
  <artifactId>java-telegram-bot-api</artifactId>
  <version>10.1.0</version>
</dependency>

JAR with all dependencies on release page

Usage

// Create your bot passing the token received from @BotFather
TelegramBot bot = new TelegramBot("BOT_TOKEN");

// Register for updates
bot.setUpdatesListener(updates -> {
    // ... process updates
    // return id of last processed update or confirm them all
    return UpdatesListener.CONFIRMED_UPDATES_ALL;
// Create Exception Handler
}, e -> {
    if (e.response() != null) {
        // got bad response from telegram
        e.response().errorCode();
        e.response().description();
    } else {
        // probably network error
        e.printStackTrace();
    }
});

// Send messages
long chatId = update.message().chat().id();
SendResponse response = bot.execute(new SendMessage(chatId, "Hello!"));

Из README репозитория · полный README на GitHub

Категории

Теги

bottelegramtelegram-apitelegram-bottelegram-bot-api