diff options
author | 2018-08-14 21:31:09 +0300 | |
---|---|---|
committer | 2018-08-14 21:50:39 +0300 | |
commit | d521327847864742286ca50207d73454006cd792 (patch) | |
tree | 1b0fce683b0f9de242c50bb82178abfe3038c2d3 /juick-server/src/main/java/com/juick/server/TelegramBotManager.java | |
parent | 2c1bfab10903895ece9644bc095597aaef2a75e8 (diff) |
Telegram: debug mode without webhook
Diffstat (limited to 'juick-server/src/main/java/com/juick/server/TelegramBotManager.java')
-rw-r--r-- | juick-server/src/main/java/com/juick/server/TelegramBotManager.java | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/juick-server/src/main/java/com/juick/server/TelegramBotManager.java b/juick-server/src/main/java/com/juick/server/TelegramBotManager.java index 3c3fbc9f..012a3e38 100644 --- a/juick-server/src/main/java/com/juick/server/TelegramBotManager.java +++ b/juick-server/src/main/java/com/juick/server/TelegramBotManager.java @@ -29,6 +29,7 @@ import com.juick.util.MessageUtils; import com.pengrad.telegrambot.BotUtils; import com.pengrad.telegrambot.Callback; import com.pengrad.telegrambot.TelegramBot; +import com.pengrad.telegrambot.UpdatesListener; import com.pengrad.telegrambot.model.Message; import com.pengrad.telegrambot.model.MessageEntity; import com.pengrad.telegrambot.model.PhotoSize; @@ -69,6 +70,8 @@ public class TelegramBotManager implements NotificationListener { @Value("${telegram_token:12345678}") private String telegramToken; + @Value("${telegram_debug:false}") + private boolean telegramDebug; @Inject private TelegramService telegramService; @Inject @@ -91,19 +94,24 @@ public class TelegramBotManager implements NotificationListener { return; } bot = new TelegramBot(telegramToken); - try { - SetWebhook webhook = new SetWebhook().url("https://api.juick.com/tlgmbtwbhk"); - if (!bot.execute(webhook).isOk()) { - logger.error("error setting webhook"); + if (!telegramDebug) { + try { + SetWebhook webhook = new SetWebhook().url("https://api.juick.com/tlgmbtwbhk"); + if (!bot.execute(webhook).isOk()) { + logger.error("error setting webhook"); + } + } catch (Exception e) { + logger.warn("couldn't initialize telegram bot", e); } - } catch (Exception e) { - logger.warn("couldn't initialize telegram bot", e); + } else { + bot.setUpdatesListener(updates -> { + updates.forEach(this::processUpdate); + return UpdatesListener.CONFIRMED_UPDATES_ALL; + }); } } - public void processUpdate(String data) { - logger.info("Telegram update: {}", data); - Update update = BotUtils.parseUpdate(data); + public void processUpdate(Update update) { Message message = update.message(); if (update.message() == null) { message = update.editedMessage(); |