diff options
Diffstat (limited to 'juick-api/src')
-rw-r--r-- | juick-api/src/main/java/com/juick/api/controllers/TelegramWebhook.java | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/juick-api/src/main/java/com/juick/api/controllers/TelegramWebhook.java b/juick-api/src/main/java/com/juick/api/controllers/TelegramWebhook.java index 94cb81cc..5e253e3c 100644 --- a/juick-api/src/main/java/com/juick/api/controllers/TelegramWebhook.java +++ b/juick-api/src/main/java/com/juick/api/controllers/TelegramWebhook.java @@ -129,28 +129,33 @@ public class TelegramWebhook { } else { Message replyMessage = message.replyToMessage(); if (replyMessage != null) { - Optional<MessageEntity> juickLink = Arrays.stream(replyMessage.entities()) - .filter(this::isJuickLink) - .findFirst(); - if (juickLink.isPresent()) { - if (StringUtils.isNotEmpty(juickLink.get().url())) { - UriComponents uriComponents = UriComponentsBuilder.fromUriString( - juickLink.get().url()).build(); - String path = uriComponents.getPath(); - if (StringUtils.isNotEmpty(path) && path.length() > 1) { - int mid = Integer.valueOf(path.substring(1)); - String prefix = String.format("#%d ", mid); - if (StringUtils.isNotEmpty(uriComponents.getFragment())) { - int rid = Integer.valueOf(uriComponents.getFragment()); - prefix = String.format("#%d/%d ", mid, rid); + if (replyMessage.entities() != null) { + Optional<MessageEntity> juickLink = Arrays.stream(replyMessage.entities()) + .filter(this::isJuickLink) + .findFirst(); + if (juickLink.isPresent()) { + if (StringUtils.isNotEmpty(juickLink.get().url())) { + UriComponents uriComponents = UriComponentsBuilder.fromUriString( + juickLink.get().url()).build(); + String path = uriComponents.getPath(); + if (StringUtils.isNotEmpty(path) && path.length() > 1) { + int mid = Integer.valueOf(path.substring(1)); + String prefix = String.format("#%d ", mid); + if (StringUtils.isNotEmpty(uriComponents.getFragment())) { + int rid = Integer.valueOf(uriComponents.getFragment()); + prefix = String.format("#%d/%d ", mid, rid); + } + apiServer.processMessage(user_from, prefix + text, attachment); + telegramBotManager.telegramNotify(message.from().id().longValue(), "Reply sent"); + } else { + logger.warn("invalid path: {}", path); } - apiServer.processMessage(user_from, prefix + text, attachment); - telegramBotManager.telegramNotify(message.from().id().longValue(), "Reply sent"); } else { - logger.warn("invalid path: {}", path); + logger.warn("invalid entity: {}", juickLink); } } else { - logger.warn("invalid entity: {}", juickLink); + telegramBotManager.telegramNotify(message.from().id().longValue(), + "Can not reply to this message", message.messageId()); } } else { telegramBotManager.telegramNotify(message.from().id().longValue(), |