Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.telegram.telegrambots.bots.TelegramLongPollingBot;
- import org.telegram.telegrambots.ApiContextInitializer;
- import org.telegram.telegrambots.meta.TelegramBotsApi;
- import org.telegram.telegrambots.meta.api.objects.Update;
- import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
- import org.telegram.telegrambots.meta.logging.BotLogger;
- import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
- import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
- public class TelegramBot extends TelegramLongPollingBot{
- public static void main(String[] args){
- ApiContextInitializer.init();
- TelegramBotsApi telegramBotsApi = new TelegramBotsApi();
- try {
- telegramBotsApi.registerBot(new TelegramBot());
- } catch (TelegramApiException e) {
- e.printStackTrace();
- }
- }
- public String getBotToken() {
- return "986923601:AAFBAV9yjKqohi7f2L2UYL2vosj8AJUxh3U";
- }
- public void onUpdateReceived(Update e){
- // We check if the update has a message and the message has text
- if (e.hasMessage() && e.getMessage().hasText()) {
- SendMessage message = new SendMessage();
- if(e.getMessage().getText().contains("/start")){
- message.setChatId(e.getMessage().getChatId())
- .setText("Hello!!");
- }
- else {
- message.setChatId(e.getMessage().getChatId())
- .setText(e.getMessage().getText());
- }
- try {
- execute(message); // Call method to send the message
- }
- catch(TelegramApiException ex){
- ex.printStackTrace();
- }
- }
- }
- public String getBotUsername() {
- return "SRS_BOT";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement