aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
m---------deps/com.juick.server10
-rw-r--r--src/main/java/com/juick/api/TelegramBotHook.java17
2 files changed, 21 insertions, 6 deletions
diff --git a/deps/com.juick.server b/deps/com.juick.server
-Subproject c95b63af82ed58c68876563692340d74ced156f
+Subproject ea43e78cb8dc20c2f54a15e37dba638b963f65e
diff --git a/src/main/java/com/juick/api/TelegramBotHook.java b/src/main/java/com/juick/api/TelegramBotHook.java
index cf0979cd..9b75a4ae 100644
--- a/src/main/java/com/juick/api/TelegramBotHook.java
+++ b/src/main/java/com/juick/api/TelegramBotHook.java
@@ -1,6 +1,7 @@
package com.juick.api;
import com.juick.json.MessageSerializer;
+import com.juick.server.UserQueries;
import com.neovisionaries.ws.client.*;
import com.pengrad.telegrambot.BotUtils;
import com.pengrad.telegrambot.Callback;
@@ -19,6 +20,7 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.util.List;
import java.util.Map;
+import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -106,7 +108,16 @@ public class TelegramBotHook {
if (!chats.contains(message.chat().id())) {
addChat(message.chat().id());
logger.info("added chat with " + message.from().firstName());
- bot.execute(new SendMessage(message.chat().id(), "Subscribed!"), new Callback<SendMessage, SendResponse>() {
+ createTelegramUser(message.from().id(), message.from().username());
+ bot.execute(new SendMessage(message.chat().id(),
+ "You are subscribed to all Juick messages. " +
+ "Create or link an existing Juick account to control " +
+ "what do you want to receive").replyMarkup(
+ new InlineKeyboardMarkup(
+ new InlineKeyboardButton[]{
+ new InlineKeyboardButton("LOGIN").url("http://juick.com/signup?type=d&hash=" +
+ UserQueries.getSignUpHashByTelegramID(jdbc, message.from().id().longValue()))
+ })), new Callback<SendMessage, SendResponse>() {
@Override
public void onResponse(SendMessage request, SendResponse response) {
logger.info("got response: " + response.message().toString());
@@ -120,4 +131,8 @@ public class TelegramBotHook {
}
}
}
+ private boolean createTelegramUser(long tgID, String tgName) {
+ return jdbc.update("INSERT INTO telegram(tg_ig, tg_name, loginhash) VALUES(?,?,?)",
+ tgID, tgName, UUID.randomUUID().toString()) > 0;
+ }
}