Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. import org.telegram.telegrambots.bots.TelegramLongPollingBot;
  2. import org.telegram.telegrambots.ApiContextInitializer;
  3. import org.telegram.telegrambots.meta.TelegramBotsApi;
  4. import org.telegram.telegrambots.meta.api.objects.Update;
  5. import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
  6. import org.telegram.telegrambots.meta.logging.BotLogger;
  7. import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
  8. import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
  9.  
  10. public class TelegramBot extends TelegramLongPollingBot{
  11.  
  12. public static void main(String[] args){
  13. ApiContextInitializer.init();
  14.  
  15. TelegramBotsApi telegramBotsApi = new TelegramBotsApi();
  16. try {
  17. telegramBotsApi.registerBot(new TelegramBot());
  18. } catch (TelegramApiException e) {
  19. e.printStackTrace();
  20. }
  21. }
  22.  
  23. public String getBotToken() {
  24. return "986923601:AAFBAV9yjKqohi7f2L2UYL2vosj8AJUxh3U";
  25. }
  26.  
  27. public void onUpdateReceived(Update e){
  28. // We check if the update has a message and the message has text
  29. if (e.hasMessage() && e.getMessage().hasText()) {
  30. SendMessage message = new SendMessage();
  31. if(e.getMessage().getText().contains("/start")){
  32. message.setChatId(e.getMessage().getChatId())
  33. .setText("Hello!!");
  34. }
  35. else {
  36. message.setChatId(e.getMessage().getChatId())
  37. .setText(e.getMessage().getText());
  38. }
  39. try {
  40. execute(message); // Call method to send the message
  41. }
  42. catch(TelegramApiException ex){
  43. ex.printStackTrace();
  44. }
  45. }
  46. }
  47.  
  48. public String getBotUsername() {
  49. return "SRS_BOT";
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement