diff options
author | Vitaly Takmazov | 2017-11-03 14:29:39 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2017-11-03 14:29:39 +0300 |
commit | 966af8fdd48fc0ea17d8893ec711d6d7419c48de (patch) | |
tree | 017a9a47be4857e45bea2e6cd7c997994e0475cb /juick-api/src/main/java | |
parent | 03667020ae95ba855e21cc12a501962095899449 (diff) |
api: fix NPE in telegram reply processing
Diffstat (limited to 'juick-api/src/main/java')
-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(), |