diff options
author | Vitaly Takmazov | 2016-05-13 16:13:08 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2016-05-13 16:13:08 +0300 |
commit | c8156fc1361b7467306d731cd57f5a4f2a9b2006 (patch) | |
tree | 22f93a45ef9603e4ecb4e7897b92a332a00b7cd4 /src/main/java/com/juick/api | |
parent | d7b8c7307b09a0dad102c37863bd03d551b5c8a9 (diff) |
telegram login
Diffstat (limited to 'src/main/java/com/juick/api')
-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; + } } |