diff options
author | Vitaly Takmazov | 2016-05-12 22:27:41 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2016-05-12 22:27:41 +0300 |
commit | c58e021d8631fd8e1dd1d40546a4aabce27e2cdf (patch) | |
tree | 29b9e1cd5ff528f89123a0f8b49b0ebe73a4ce3e /src/main/java | |
parent | 70a6b6c49ee6e220942a43ae4328ce9dcd24232b (diff) |
parse update
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/com/juick/api/Main.java | 6 | ||||
-rw-r--r-- | src/main/java/com/juick/api/TelegramBotHook.java | 12 |
2 files changed, 15 insertions, 3 deletions
diff --git a/src/main/java/com/juick/api/Main.java b/src/main/java/com/juick/api/Main.java index 003b9aa3..7d5c8f1b 100644 --- a/src/main/java/com/juick/api/Main.java +++ b/src/main/java/com/juick/api/Main.java @@ -127,12 +127,16 @@ public class Main extends HttpServlet implements Stream.StreamListener { request.setCharacterEncoding("UTF-8"); } + String uri = request.getRequestURI(); + if (uri.equals("/tlgmbtwbhk")) { + tgb.doPost(request, response); + return; + } int vuid = Utils.getHttpAuthUID(jdbc, request); if (vuid == 0) { vuid = Utils.getVisitorQueryStringUID(jdbc, request); } - String uri = request.getRequestURI(); if (uri.equals("/home")) { if (vuid > 0) { messages.doGetHome(request, response, vuid); diff --git a/src/main/java/com/juick/api/TelegramBotHook.java b/src/main/java/com/juick/api/TelegramBotHook.java index 6d73fbfb..a502e846 100644 --- a/src/main/java/com/juick/api/TelegramBotHook.java +++ b/src/main/java/com/juick/api/TelegramBotHook.java @@ -1,10 +1,14 @@ package com.juick.api; +import com.pengrad.telegrambot.BotUtils; import com.pengrad.telegrambot.TelegramBot; import com.pengrad.telegrambot.TelegramBotAdapter; +import com.pengrad.telegrambot.model.Update; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.BufferedReader; +import java.io.IOException; import java.util.logging.Logger; /** @@ -23,7 +27,11 @@ public class TelegramBotHook { bot.setWebhook("https://api.juick.com/tlgmbtwbhk"); } - public void doPost(HttpServletRequest request, HttpServletResponse response) { - logger.info("got telegram msg: " + request); + public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { + StringBuilder sb = new StringBuilder(); + try (BufferedReader reader = request.getReader()) { + Update update = BotUtils.parseUpdate(reader); + logger.info("got telegram msg: " + update.message().toString()); + } } } |