From c013950b6824788a152b4d4a03feb1d54ce608e3 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 8 Jan 2023 05:44:19 +0300 Subject: Telegram: use correct domain in urls --- src/main/java/com/juick/TelegramBotManager.java | 28 ++++++++++++++----------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/juick/TelegramBotManager.java b/src/main/java/com/juick/TelegramBotManager.java index 8064fc58..b68658ae 100644 --- a/src/main/java/com/juick/TelegramBotManager.java +++ b/src/main/java/com/juick/TelegramBotManager.java @@ -76,6 +76,8 @@ public class TelegramBotManager implements NotificationListener { private String apiUrl; @Value("${telegram_file_api_url:}") private String fileApiUrl; + @Value("${web_domain:localhost}") + private String webDomain; @Value("${telegram_webhook_url:}") private String webhookUrl; @Value("${telegram_token:12345678}") @@ -195,10 +197,12 @@ public class TelegramBotManager implements NotificationListener { || text.equalsIgnoreCase("/logout") || text.equalsIgnoreCase("/start") || text.equalsIgnoreCase("/help")) { - String msgUrl = "http://juick.com/login?hash=" + userService.getHashByUID(user_from.getUid()); - String msg = String.format("Hi, %s!\nYou can post messages and images to Juick there.\n" + - "Tap to [log into website](%s) to get more info", user_from.getName(), msgUrl); - telegramNotify(message.from().id().longValue(), msg, new com.juick.model.Message()); + String msgUrl = String.format("https://%s/login?hash=%s", webDomain, userService.getHashByUID(user_from.getUid())); + String msg = String.format(""" + Hi, %s! + You can post messages and images to Juick there. + Tap to [log into website](%s) to get more info""", user_from.getName(), msgUrl); + telegramNotify(message.from().id(), msg, new com.juick.model.Message()); } else { Message replyMessage = message.replyToMessage(); if (replyMessage != null) { @@ -228,7 +232,7 @@ public class TelegramBotManager implements NotificationListener { int rid = Integer.parseInt(uriComponents.getFragment()); prefix = String.format("#%d/%d ", mid, rid); } - executeCommand(message.messageId(), message.from().id().longValue(), + executeCommand(message.messageId(), message.from().id(), user_from, prefix + text, attachment); } else { logger.warn("invalid path: {}", path); @@ -237,15 +241,15 @@ public class TelegramBotManager implements NotificationListener { logger.warn("invalid entity: {}", juickLink); } } else { - telegramNotify(message.from().id().longValue(), + telegramNotify(message.from().id(), "Can not reply to this message", replyMessage.messageId(), new com.juick.model.Message()); } } else { - telegramNotify(message.from().id().longValue(), + telegramNotify(message.from().id(), "Can not reply to this message", replyMessage.messageId(), new com.juick.model.Message()); } } else { - executeCommand(message.messageId(), message.from().id().longValue(), + executeCommand(message.messageId(), message.from().id(), user_from, text, attachment); } } @@ -257,7 +261,7 @@ public class TelegramBotManager implements NotificationListener { logger.info("added chat with {}", username); telegramService.createTelegramUser(message.from().id(), username); } - telegramSignupNotify(message.from().id().longValue(), userService.getSignUpHashByTelegramID(message.from().id().longValue(), username)); + telegramSignupNotify(message.from().id(), userService.getSignUpHashByTelegramID(message.from().id(), username)); } } } @@ -393,8 +397,8 @@ public class TelegramBotManager implements NotificationListener { public void telegramSignupNotify(Long telegramId, String hash) { bot.execute(new SendMessage(telegramId, String.format("You are subscribed to all Juick messages. " + - "[Create or link](http://juick.com/signup?type=durov&hash=%s) " + - "an existing Juick account to get your subscriptions and ability to post messages", hash)) + "[Create or link](https://%s/signup?type=durov&hash=%s) " + + "an existing Juick account to get your subscriptions and ability to post messages", webDomain, hash)) .parseMode(ParseMode.Markdown), new Callback<>() { @Override public void onResponse(SendMessage request, SendResponse response) { @@ -436,7 +440,7 @@ public class TelegramBotManager implements NotificationListener { telegramService.getTelegramIdentifiers(Collections.singletonList(jmsg.getTo())) .forEach(c -> telegramNotify(c, formatPost(jmsg, true), jmsg)); } else if (MessageUtils.isReply(jmsg)) { - String fmsg = String.format("[%s](%s) %s", MSG_LINK, msgUrl, formatPost(jmsg, true)); + String fmsg = formatTelegramMessage(jmsg); telegramService.getTelegramIdentifiers( subscribedUsers ).forEach(c -> telegramNotify(c, fmsg, jmsg)); -- cgit v1.2.3