aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-05-12 19:25:26 +0300
committerGravatar Vitaly Takmazov2016-05-12 19:25:26 +0300
commit70a6b6c49ee6e220942a43ae4328ce9dcd24232b (patch)
treef83067a7787cb214add9091d835a2c7c0544b060 /src/main
parent846d0b67d11ba9444a8a32ee173bb431683fa572 (diff)
initial telegram bot
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/juick/api/Main.java13
-rw-r--r--src/main/java/com/juick/api/TelegramBotHook.java29
2 files changed, 38 insertions, 4 deletions
diff --git a/src/main/java/com/juick/api/Main.java b/src/main/java/com/juick/api/Main.java
index c43804d7..003b9aa3 100644
--- a/src/main/java/com/juick/api/Main.java
+++ b/src/main/java/com/juick/api/Main.java
@@ -19,7 +19,10 @@ package com.juick.api;
import com.juick.Tag;
import com.juick.json.MessageSerializer;
-import com.juick.server.*;
+import com.juick.server.MessagesQueries;
+import com.juick.server.SubscriptionsQueries;
+import com.juick.server.TagQueries;
+import com.juick.server.UserQueries;
import com.juick.xmpp.JID;
import com.juick.xmpp.Message;
import com.juick.xmpp.Stream;
@@ -40,8 +43,6 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.URL;
-import java.net.URLEncoder;
-import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
@@ -63,6 +64,7 @@ public class Main extends HttpServlet implements Stream.StreamListener {
Users users;
PM pm;
Others others;
+ TelegramBotHook tgb;
@Override
public void init() throws ServletException {
@@ -79,7 +81,7 @@ public class Main extends HttpServlet implements Stream.StreamListener {
users = new Users(jdbc);
pm = new PM(jdbc);
others = new Others(jdbc);
-
+ tgb = new TelegramBotHook(conf.getProperty("telegram_token", ""));
setupXmppComponent(conf.getProperty("xmpp_host", "localhost"), Integer.parseInt(conf.getProperty("xmpp_port", "5347")),
conf.getProperty("xmpp_jid", "api.localhost"), conf.getProperty("xmpp_password"));
@@ -209,6 +211,9 @@ public class Main extends HttpServlet implements Stream.StreamListener {
case "/pm":
pm.doPostPM(request, response, xmpp, vuid);
break;
+ case "/tlgmbtwbhk":
+ tgb.doPost(request, response);
+ break;
default:
response.sendError(405);
break;
diff --git a/src/main/java/com/juick/api/TelegramBotHook.java b/src/main/java/com/juick/api/TelegramBotHook.java
new file mode 100644
index 00000000..6d73fbfb
--- /dev/null
+++ b/src/main/java/com/juick/api/TelegramBotHook.java
@@ -0,0 +1,29 @@
+package com.juick.api;
+
+import com.pengrad.telegrambot.TelegramBot;
+import com.pengrad.telegrambot.TelegramBotAdapter;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.logging.Logger;
+
+/**
+ * Created by vt on 12/05/16.
+ */
+public class TelegramBotHook {
+ private static final Logger logger = Logger.getLogger(TelegramBotHook.class.getName());
+
+ private String token;
+ TelegramBot bot;
+
+
+ public TelegramBotHook(String token) {
+ this.token = token;
+ bot = TelegramBotAdapter.build(token);
+ bot.setWebhook("https://api.juick.com/tlgmbtwbhk");
+ }
+
+ public void doPost(HttpServletRequest request, HttpServletResponse response) {
+ logger.info("got telegram msg: " + request);
+ }
+}