aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/server
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/server')
-rw-r--r--src/main/java/com/juick/server/TelegramBotManager.java36
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);
}
});