aboutsummaryrefslogtreecommitdiff
path: root/juick-api/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'juick-api/src/main')
-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;
+ }
}