Created
July 7, 2020 02:59
-
-
Save alexandremucci/7a08a66be5b7e87a644f9bd90cfb54b9 to your computer and use it in GitHub Desktop.
Example of Telegram Bot class implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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