diff options
Diffstat (limited to 'src/main/java/com')
-rw-r--r-- | src/main/java/com/juick/api/TelegramBotHook.java | 17 |
1 files changed, 16 insertions, 1 deletions
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; + } } |