From d521327847864742286ca50207d73454006cd792 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 14 Aug 2018 21:31:09 +0300 Subject: Telegram: debug mode without webhook --- .../java/com/juick/server/api/webhooks/TelegramWebhook.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'juick-server/src/main/java/com/juick/server/api/webhooks') diff --git a/juick-server/src/main/java/com/juick/server/api/webhooks/TelegramWebhook.java b/juick-server/src/main/java/com/juick/server/api/webhooks/TelegramWebhook.java index 10fd1ab3..8497cff1 100644 --- a/juick-server/src/main/java/com/juick/server/api/webhooks/TelegramWebhook.java +++ b/juick-server/src/main/java/com/juick/server/api/webhooks/TelegramWebhook.java @@ -18,7 +18,11 @@ package com.juick.server.api.webhooks; import com.juick.server.TelegramBotManager; +import com.pengrad.telegrambot.BotUtils; +import com.pengrad.telegrambot.model.Update; import org.apache.commons.io.IOUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.RequestMapping; @@ -36,8 +40,9 @@ import java.nio.charset.StandardCharsets; */ @ApiIgnore @RestController -@ConditionalOnProperty(name = "telegram_token") +@ConditionalOnProperty({"telegram_token", "telegram_debug"}) public class TelegramWebhook { + private static final Logger logger = LoggerFactory.getLogger(TelegramWebhook.class); @Inject private TelegramBotManager telegramBotManager; @@ -45,6 +50,8 @@ public class TelegramWebhook { @ResponseStatus(value = HttpStatus.OK) public void processUpdate(InputStream body) throws Exception { String data = IOUtils.toString(body, StandardCharsets.UTF_8); - telegramBotManager.processUpdate(data); + logger.info("Telegram update: {}", data); + Update update = BotUtils.parseUpdate(data); + telegramBotManager.processUpdate(update); } } -- cgit v1.2.3