diff options
author | alx | 2019-03-16 23:55:55 +0300 |
---|---|---|
committer | alx | 2019-03-16 23:55:55 +0300 |
commit | 3ea4cd1942fa4e763034da11c5fa429407b67829 (patch) | |
tree | 7d34be94cd343c0d819340039359255225a999ee /src/main/java/com/juick | |
parent | 4fb7a3522e6fde6cb7bbdd36fa9be8be9c9379ee (diff) |
Send large image caption as separated message via telegram
Diffstat (limited to 'src/main/java/com/juick')
-rw-r--r-- | src/main/java/com/juick/server/TelegramBotManager.java | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/src/main/java/com/juick/server/TelegramBotManager.java b/src/main/java/com/juick/server/TelegramBotManager.java index 8a0c45dc..56b5b4f9 100644 --- a/src/main/java/com/juick/server/TelegramBotManager.java +++ b/src/main/java/com/juick/server/TelegramBotManager.java @@ -257,39 +257,43 @@ public class TelegramBotManager implements NotificationListener { public void telegramNotify(Long chatId, String msg, Integer replyTo, @Nonnull com.juick.Message source) { String attachment = MessageUtils.attachmentUrl(source); - if (StringUtils.isEmpty(attachment)) { - SendMessage telegramMessage = new SendMessage(chatId, msg); + boolean isSendTxt = true; + if (!StringUtils.isEmpty(attachment)) { + SendPhoto telegramPhoto = new SendPhoto(chatId, attachment); if (replyTo > 0) { - telegramMessage.replyToMessageId(replyTo); + telegramPhoto.replyToMessageId(replyTo); } - telegramMessage.parseMode(ParseMode.Markdown).disableWebPagePreview(true); - bot.execute(telegramMessage, new Callback<SendMessage, SendResponse>() { + telegramPhoto.parseMode(ParseMode.Markdown); + if(msg.length() < 1024) { + telegramPhoto.caption(msg); + isSendTxt = false; + } + bot.execute(telegramPhoto, new Callback<SendPhoto, SendResponse>() { @Override - public void onResponse(SendMessage request, SendResponse response) { + public void onResponse(SendPhoto request, SendResponse response) { processTelegramResponse(chatId, response, source); } @Override - public void onFailure(SendMessage request, IOException e) { + public void onFailure(SendPhoto request, IOException e) { logger.warn("telegram failure", e); } }); - } else { - SendPhoto telegramPhoto = new SendPhoto(chatId, attachment); - String trimmedPost = msg.length() > 1024 ? msg.substring(0, 1023) + "..." : msg; - telegramPhoto.caption(trimmedPost); + } + if (isSendTxt){ + SendMessage telegramMessage = new SendMessage(chatId, msg); if (replyTo > 0) { - telegramPhoto.replyToMessageId(replyTo); + telegramMessage.replyToMessageId(replyTo); } - telegramPhoto.parseMode(ParseMode.Markdown); - bot.execute(telegramPhoto, new Callback<SendPhoto, SendResponse>() { + telegramMessage.parseMode(ParseMode.Markdown).disableWebPagePreview(true); + bot.execute(telegramMessage, new Callback<SendMessage, SendResponse>() { @Override - public void onResponse(SendPhoto request, SendResponse response) { + public void onResponse(SendMessage request, SendResponse response) { processTelegramResponse(chatId, response, source); } @Override - public void onFailure(SendPhoto request, IOException e) { + public void onFailure(SendMessage request, IOException e) { logger.warn("telegram failure", e); } }); |