From c8156fc1361b7467306d731cd57f5a4f2a9b2006 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 13 May 2016 16:13:08 +0300 Subject: telegram login --- deps/com.juick.server | 2 +- src/main/java/com/juick/api/TelegramBotHook.java | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/deps/com.juick.server b/deps/com.juick.server index c95b63af..ea43e78c 160000 --- a/deps/com.juick.server +++ b/deps/com.juick.server @@ -1 +1 @@ -Subproject commit c95b63af82ed58c68876563692340d74ced156f2 +Subproject commit ea43e78cb8dc20c2f54a15e37dba638b963f65ec 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() { + 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() { @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; + } } -- cgit v1.2.3