aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/TelegramBotManager.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2023-01-08 05:44:19 +0300
committerGravatar Vitaly Takmazov2023-01-08 06:11:28 +0300
commitc013950b6824788a152b4d4a03feb1d54ce608e3 (patch)
tree2a25db72336068217719cb5d41ea2e26fbefec61 /src/main/java/com/juick/TelegramBotManager.java
parentdcd080bc2c864ac5efdb81809cb73ea987f3fead (diff)
Telegram: use correct domain in urls
Diffstat (limited to 'src/main/java/com/juick/TelegramBotManager.java')
-rw-r--r--src/main/java/com/juick/TelegramBotManager.java28
1 files 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));