aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/juick/api/Main.java6
-rw-r--r--src/main/java/com/juick/api/TelegramBotHook.java12
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());
+ }
}
}