diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendAnimation.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendAnimation.java index cb943c3d..d5a7fb37 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendAnimation.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendAnimation.java @@ -52,7 +52,7 @@ public class SendAnimation extends PartialBotApiMethod { private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound. private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard - private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. + private String parseMode; ///< Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. /** * Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size. * A thumbnail‘s width and height should not exceed 90. diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/bots/AbsSender.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/bots/AbsSender.java index f3a82ebf..b83122a4 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/bots/AbsSender.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/bots/AbsSender.java @@ -150,6 +150,14 @@ public abstract class AbsSender { */ public abstract Serializable execute(EditMessageMedia editMessageMedia) throws TelegramApiException; + /** + * Send animation + * @param sendAnimation Information of the animation + * @return Sent message + * @throws TelegramApiException If there is any error sending animation + */ + public abstract Message execute(SendAnimation sendAnimation) throws TelegramApiException; + // Simplified methods protected abstract , Callback extends SentCallback> void sendApiMethodAsync(Method method, Callback callback); diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java b/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java index c79ff378..2a4e2d80 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java @@ -636,6 +636,57 @@ public abstract class DefaultAbsSender extends AbsSender { } } + @Override + public Message execute(SendAnimation sendAnimation) throws TelegramApiException { + assertParamNotNull(sendAnimation, "sendAnimation"); + sendAnimation.validate(); + try { + String url = getBaseUrl() + SendVoice.PATH; + HttpPost httppost = configuredHttpPost(url); + MultipartEntityBuilder builder = MultipartEntityBuilder.create(); + builder.setLaxMode(); + builder.setCharset(StandardCharsets.UTF_8); + builder.addTextBody(SendAnimation.CHATID_FIELD, sendAnimation.getChatId(), TEXT_PLAIN_CONTENT_TYPE); + addInputFile(builder, sendAnimation.getAnimation(), SendAnimation.ANIMATION_FIELD, true); + + if (sendAnimation.getReplyMarkup() != null) { + builder.addTextBody(SendAnimation.REPLYMARKUP_FIELD, objectMapper.writeValueAsString(sendAnimation.getReplyMarkup()), TEXT_PLAIN_CONTENT_TYPE); + } + if (sendAnimation.getReplyToMessageId() != null) { + builder.addTextBody(SendAnimation.REPLYTOMESSAGEID_FIELD, sendAnimation.getReplyToMessageId().toString(), TEXT_PLAIN_CONTENT_TYPE); + } + if (sendAnimation.getDisableNotification() != null) { + builder.addTextBody(SendAnimation.DISABLENOTIFICATION_FIELD, sendAnimation.getDisableNotification().toString(), TEXT_PLAIN_CONTENT_TYPE); + } + if (sendAnimation.getDuration() != null) { + builder.addTextBody(SendAnimation.DURATION_FIELD, sendAnimation.getDuration().toString(), TEXT_PLAIN_CONTENT_TYPE); + } + if (sendAnimation.getWidth() != null) { + builder.addTextBody(SendAnimation.WIDTH_FIELD, sendAnimation.getWidth().toString(), TEXT_PLAIN_CONTENT_TYPE); + } + if (sendAnimation.getHeight() != null) { + builder.addTextBody(SendAnimation.HEIGHT_FIELD, sendAnimation.getHeight().toString(), TEXT_PLAIN_CONTENT_TYPE); + } + if (sendAnimation.getThumb() != null) { + addInputFile(builder, sendAnimation.getThumb(), SendAnimation.THUMB_FIELD, false); + builder.addTextBody(SendAnimation.THUMB_FIELD, sendAnimation.getThumb().getAttachName(), TEXT_PLAIN_CONTENT_TYPE); + } + + if (sendAnimation.getCaption() != null) { + builder.addTextBody(SendAnimation.CAPTION_FIELD, sendAnimation.getCaption(), TEXT_PLAIN_CONTENT_TYPE); + if (sendAnimation.getParseMode() != null) { + builder.addTextBody(SendAnimation.PARSEMODE_FIELD, sendAnimation.getParseMode(), TEXT_PLAIN_CONTENT_TYPE); + } + } + HttpEntity multipart = builder.build(); + httppost.setEntity(multipart); + + return sendAnimation.deserializeResponse(sendHttpPostRequest(httppost)); + } catch (IOException e) { + throw new TelegramApiException("Unable to edit message media", e); + } + } + // Simplified methods @Override