Skip to content

Instantly share code, notes, and snippets.

@rubenlagus
Created February 3, 2016 19:26
Show Gist options
  • Save rubenlagus/b13b3690c3f04ad0b229 to your computer and use it in GitHub Desktop.
Save rubenlagus/b13b3690c3f04ad0b229 to your computer and use it in GitHub Desktop.
Echo bot
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