aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.gradle2
-rw-r--r--src/main/java/com/juick/api/Main.java13
-rw-r--r--src/main/java/com/juick/api/TelegramBotHook.java29
3 files changed, 39 insertions, 5 deletions
diff --git a/build.gradle b/build.gradle
index b76df16a..f6b37262 100644
--- a/build.gradle
+++ b/build.gradle
@@ -54,7 +54,7 @@ dependencies {
compile xmpp
compile json
compile "org.apache.commons:commons-lang3:3.4"
- compile "org.springframework:spring-jdbc:4.2.4.RELEASE"
+ compile 'com.github.pengrad:java-telegram-bot-api:2.0.1'
providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
def tomcatVersion = '7.0.+'
tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
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);
+ }
+}