Skip to content

Instantly share code, notes, and snippets.

@alexandremucci
Created July 7, 2020 02:59
Show Gist options
  • Save alexandremucci/7a08a66be5b7e87a644f9bd90cfb54b9 to your computer and use it in GitHub Desktop.
Save alexandremucci/7a08a66be5b7e87a644f9bd90cfb54b9 to your computer and use it in GitHub Desktop.
Example of Telegram Bot class implementation
package com.alexandremucci.telegrambot.bots;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.meta.api.objects.Update;
@Component
public class ExampleBot extends TelegramLongPollingBot {
@Value("${bot.token}")
private String token;
@Value("${bot.username}")
private String username;
@Override
public void onUpdateReceived(Update update) {
// get text content and print
if (update.hasMessage()) {
System.out.println(update.getMessage().getText());
}
}
@Override
public String getBotUsername() {
return this.username;
}
@Override
public String getBotToken() {
return this.token;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment