aboutsummaryrefslogtreecommitdiff
path: root/juick-api/src/main/java/com/juick/api/controllers
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-11-03 13:06:31 +0300
committerGravatar Vitaly Takmazov2017-11-03 13:06:31 +0300
commit80f6a6eb734fa8f07dbc1e89d4bde8b1db11d07d (patch)
tree27e8adc6cb7ff9cddcc4d471a6f4e8e3d84bed8c /juick-api/src/main/java/com/juick/api/controllers
parentb0df6b0f4776d8a21459cab265c8a729f63ae2e6 (diff)
api: clean up telegram reply parsing
Diffstat (limited to 'juick-api/src/main/java/com/juick/api/controllers')
-rw-r--r--juick-api/src/main/java/com/juick/api/controllers/TelegramWebhook.java29
1 files changed, 17 insertions, 12 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 236e4064..137e1a59 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
@@ -25,6 +25,7 @@ import com.juick.service.TelegramService;
import com.juick.service.UserService;
import com.pengrad.telegrambot.BotUtils;
import com.pengrad.telegrambot.model.Message;
+import com.pengrad.telegrambot.model.MessageEntity;
import com.pengrad.telegrambot.model.PhotoSize;
import com.pengrad.telegrambot.model.Update;
import com.pengrad.telegrambot.request.GetFile;
@@ -131,19 +132,20 @@ public class TelegramWebhook {
String finalAttachment = attachment;
Message finalMessage = message;
Arrays.stream(replyMessage.entities())
- .filter(e -> e.offset() == 0).findFirst().ifPresent(e -> {
- if (StringUtils.isNotEmpty(e.url())) {
- UriComponents uriComponents = UriComponentsBuilder.fromUriString(e.url()).build();
- int mid = Integer.valueOf(uriComponents.getPath().substring(1));
- String prefix = String.format("#%d ", mid);
- int rid = 0;
- if (StringUtils.isNotEmpty(uriComponents.getFragment())) {
- rid = Integer.valueOf(uriComponents.getFragment());
- prefix = String.format("#%d/%d ", mid, rid);
- }
- apiServer.processMessage(user_from, prefix + finalText, finalAttachment);
- telegramBotManager.telegramNotify(finalMessage.from().id().longValue(), "reply sent");
+ .filter(this::isJuickLink)
+ .findFirst().ifPresent(e -> {
+ if (StringUtils.isNotEmpty(e.url())) {
+ UriComponents uriComponents = UriComponentsBuilder.fromUriString(e.url()).build();
+ int mid = Integer.valueOf(uriComponents.getPath().substring(1));
+ String prefix = String.format("#%d ", mid);
+ int rid = 0;
+ if (StringUtils.isNotEmpty(uriComponents.getFragment())) {
+ rid = Integer.valueOf(uriComponents.getFragment());
+ prefix = String.format("#%d/%d ", mid, rid);
}
+ apiServer.processMessage(user_from, prefix + finalText, finalAttachment);
+ telegramBotManager.telegramNotify(finalMessage.from().id().longValue(), "reply sent");
+ }
});
} else {
apiServer.processMessage(user_from, text, attachment);
@@ -154,4 +156,7 @@ public class TelegramWebhook {
}
}
}
+ boolean isJuickLink(MessageEntity e) {
+ return e.offset() == 0 && e.type().equals(MessageEntity.Type.text_link) && e.length() == 2;
+ }
}