Created
February 3, 2016 19:26
-
-
Save rubenlagus/b13b3690c3f04ad0b229 to your computer and use it in GitHub Desktop.
Echo bot
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 org.telegram.updateshandlers; | |
import org.telegram.services.BotLogger; | |
import org.telegram.telegrambots.TelegramApiException; | |
import org.telegram.telegrambots.api.methods.SendMessage; | |
import org.telegram.telegrambots.api.objects.Message; | |
import org.telegram.telegrambots.api.objects.Update; | |
import org.telegram.telegrambots.bots.TelegramLongPollingBot; | |
public class EchoHandlers extends TelegramLongPollingBot { | |
private static final String LOGTAG = "ECHOHANDLERS"; | |
@Override | |
public void onUpdateReceived(Update update) { | |
Message message = update.getMessage(); | |
if (message != null && message.hasText()) { | |
try { | |
SendMessage sendMessageRequest = new SendMessage(); | |
sendMessageRequest.setChatId(message.getChatId() + ""); | |
sendMessageRequest.setText(message.getText()); | |
sendMessage(sendMessageRequest); | |
} catch (TelegramApiException e) { | |
BotLogger.severe(LOGTAG, e); | |
} | |
} | |
} | |
@Override | |
public String getBotToken() { | |
return "<bot-token>"; | |
} | |
@Override | |
public String getBotUsername() { | |
return "<bot-username>"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment