aboutsummaryrefslogtreecommitdiff
path: root/juick-api/src/main/java/com/juick/api/controllers/TelegramWebhook.java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-api/src/main/java/com/juick/api/controllers/TelegramWebhook.java')
-rw-r--r--juick-api/src/main/java/com/juick/api/controllers/TelegramWebhook.java32
1 files changed, 27 insertions, 5 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 e14d226d..ef2456b5 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;
@@ -38,6 +39,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.util.UriComponents;
+import org.springframework.web.util.UriComponentsBuilder;
import springfox.documentation.annotations.ApiIgnore;
import javax.inject.Inject;
@@ -122,12 +125,31 @@ public class TelegramWebhook {
String msg = String.format("Hi, %s!\nTap to log in", user_from.getName());
String msgUrl = "http://juick.com/login?" + usersService.getHashByUID(user_from.getUid());
telegramBotManager.telegramNotify(message.from().id().longValue(), msg, msgUrl);
- } else if (text.toLowerCase().startsWith("/post ")) {
- apiServer.processMessage(user_from, text.substring(6), attachment);
- telegramBotManager.telegramNotify(message.from().id().longValue(), "message sent", null);
} else {
- telegramBotManager.telegramNotify(message.from().id().longValue(),
- "You can send messages and images to Juick with /post command", null);
+ Message replyMessage = message.replyToMessage();
+ if (replyMessage != null) {
+ String finalText = text;
+ 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", null);
+ }
+ });
+ } else {
+ apiServer.processMessage(user_from, text, attachment);
+ telegramBotManager.telegramNotify(message.from().id().longValue(), "message sent", null);
+ }
}
}
}