From c0f51040bb42aa4609399d060c2cec29a66bd093 Mon Sep 17 00:00:00 2001 From: Ruben Date: Mon, 15 Aug 2022 01:42:50 +0100 Subject: [PATCH] Api Version 6.2 --- .../meta/api/methods/CopyMessage.java | 2 +- .../api/methods/games/GetGameHighScores.java | 6 +- .../methods/stickers/CreateNewStickerSet.java | 61 ++++++++++++++++++- .../stickers/GetCustomEmojiStickers.java | 57 +++++++++++++++++ .../telegrambots/meta/api/objects/Chat.java | 8 +++ .../meta/api/objects/MessageEntity.java | 9 +++ .../meta/api/objects/stickers/Sticker.java | 11 ++++ .../meta/api/objects/stickers/StickerSet.java | 22 ++++++- .../telegrambots/bots/DefaultAbsSender.java | 2 +- .../test/BotApiMethodHelperFactory.java | 2 +- .../test/TelegramFileDownloaderTest.java | 4 +- .../test/TelegramLongPollingBotTest.java | 2 +- .../telegrambots/test/TestRestApi.java | 4 +- 13 files changed, 177 insertions(+), 13 deletions(-) create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stickers/GetCustomEmojiStickers.java diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/CopyMessage.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/CopyMessage.java index 6bff8f47..bb6b7711 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/CopyMessage.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/CopyMessage.java @@ -25,7 +25,7 @@ import java.util.List; * @version 1.0 * Use this method to copy messages of any kind. * Service messages and invoice messages can't be copied. - * + * A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. * The method is analogous to the method forwardMessage, but the copied message doesn't have a link to the original message. * Returns the MessageId of the sent message on success. */ diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/games/GetGameHighScores.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/games/GetGameHighScores.java index a1a2ecf9..6fbb016a 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/games/GetGameHighScores.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/games/GetGameHighScores.java @@ -64,11 +64,11 @@ public class GetGameHighScores extends BotApiMethod> { private static final String USER_ID_FIELD = "user_id"; @JsonProperty(CHATID_FIELD) - private String chatId; ///< Optional Required if inline_message_id is not specified. Unique identifier for the target chat (or username of the target channel in the format @channelusername) + private String chatId; ///< Optional. Required if inline_message_id is not specified. Unique identifier for the target chat (or username of the target channel in the format @channelusername) @JsonProperty(MESSAGEID_FIELD) - private Integer messageId; ///< Optional Required if inline_message_id is not specified. Unique identifier of the sent message + private Integer messageId; ///< Optional. Required if inline_message_id is not specified. Unique identifier of the sent message @JsonProperty(INLINE_MESSAGE_ID_FIELD) - private String inlineMessageId; ///< Optional Required if chat_id and message_id are not specified. Identifier of the inline message + private String inlineMessageId; ///< Optional. Required if chat_id and message_id are not specified. Identifier of the inline message @JsonProperty(USER_ID_FIELD) @NonNull private Long userId; /// { public static final String USERID_FIELD = "user_id"; public static final String NAME_FIELD = "name"; + public static final String STICKERTYPE_FIELD = "sticker_type"; + public static final String TITLE_FIELD = "title"; public static final String PNGSTICKER_FIELD = "png_sticker"; public static final String TGSSTICKER_FIELD = "tgs_sticker"; @@ -46,6 +53,13 @@ public class CreateNewStickerSet extends PartialBotApiMethod { @NonNull private Long userId; ///< User identifier of created sticker set owner + /** + * Type of stickers in the set, pass “regular” or “mask”. + * Custom emoji sticker sets can't be created via the Bot API at the moment. + * By default, a regular sticker set is created. + */ + @Builder.Default + private String stickerType = "regular"; /** * Name of sticker set, to be used in t.me/addstickers/ URLs. * Can contain only english letters, digits and underscores. @@ -58,7 +72,6 @@ public class CreateNewStickerSet extends PartialBotApiMethod { private String title; ///< User identifier of created sticker set owner @NonNull private String emojis; ///< One or more emoji corresponding to the sticker - private Boolean containsMasks; ///< Optional. Pass True, if a set of mask stickers should be created private MaskPosition maskPosition; ///< Optional. Position where the mask should be placed on faces /** * Optional. @@ -84,6 +97,33 @@ public class CreateNewStickerSet extends PartialBotApiMethod { */ private InputFile webmSticker; + /** + * @deprecated Use {@link #setStickerType(String)} + */ + @Deprecated + public void setContainsMasks(boolean containsMasks) { + if (containsMasks) { + this.stickerType = "mask"; + } else { + this.stickerType = "regular"; + } + } + + /** + * @deprecated Use {@link #getStickerType()} or {@link #isMask()} + */ + @Deprecated + public Boolean getContainsMasks() { + return isMask(); + } + + public boolean isRegularSticker() { + return "regular".equals(stickerType); + } + public boolean isMask() { + return "mask".equals(stickerType); + } + @Override public Boolean deserializeResponse(String answer) throws TelegramApiRequestException { return deserializeResponse(answer, Boolean.class); @@ -94,6 +134,9 @@ public class CreateNewStickerSet extends PartialBotApiMethod { if (userId <= 0) { throw new TelegramApiValidationException("userId can't be empty", this); } + if (!Arrays.asList("regular", "mask").contains(stickerType)) { + throw new TelegramApiValidationException("Stickertype must be 'regular' or 'mask'", this); + } if (name.isEmpty()) { throw new TelegramApiValidationException("name can't be empty", this); } @@ -129,4 +172,20 @@ public class CreateNewStickerSet extends PartialBotApiMethod { maskPosition.validate(); } } + + public static class CreateNewStickerSetBuilder { + /** + * @deprecated Use {@link #stickerType(String)} or {@link #setStickerType(String)} + */ + @Tolerate + @Deprecated + public CreateNewStickerSet.CreateNewStickerSetBuilder containsMasks(@NonNull Boolean containsMasks) { + if (containsMasks) { + this.stickerType("mask"); + } else { + this.stickerType("regular"); + } + return this; + } + } } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stickers/GetCustomEmojiStickers.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stickers/GetCustomEmojiStickers.java new file mode 100644 index 00000000..8980eeb7 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stickers/GetCustomEmojiStickers.java @@ -0,0 +1,57 @@ +package org.telegram.telegrambots.meta.api.methods.stickers; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; +import org.telegram.telegrambots.meta.api.methods.BotApiMethod; +import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean; +import org.telegram.telegrambots.meta.api.objects.games.GameHighScore; +import org.telegram.telegrambots.meta.api.objects.stickers.Sticker; +import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Ruben Bermudez + * @version 6.2 + * Use this method to get information about emoji stickers by their identifiers. + * Returns an Array of Sticker on success. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class GetCustomEmojiStickers extends BotApiMethod> { + private static final String PATH = "getCustomEmojiStickers"; + + private static final String CUSTOMEMOJIID_FIELD = "custom_emoji_ids"; + + /** + * List of custom emoji identifiers. + * At most 200 custom emoji identifiers can be specified. + */ + @Singular + @JsonProperty(CUSTOMEMOJIID_FIELD) + private List customEmojiIds; + + @Override + public void validate() throws TelegramApiValidationException { + if (customEmojiIds == null || customEmojiIds.isEmpty() || customEmojiIds.size() > 200) { + throw new TelegramApiValidationException("CustomEmojiIds must be between 1 and 200", this); + } + } + + @Override + public String getMethod() { + return PATH; + } + + @Override + public ArrayList deserializeResponse(String answer) throws TelegramApiRequestException { + return deserializeResponseArray(answer, Sticker.class); + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Chat.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Chat.java index 84ed0a15..e9ba311b 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Chat.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Chat.java @@ -49,6 +49,7 @@ public class Chat implements BotApiObject { private static final String HASPROTECTEDCONTENT_FIELD = "has_protected_content"; private static final String JOINTOSENDMESSAGES_FIELD = "join_to_send_messages"; private static final String JOINBYREQUEST_FIELD = "join_by_request"; + private static final String HASRESTRICTEDVOICEANDVIDEOMESSAGES_FIELD = "has_restricted_voice_and_video_messages"; private static final String USERCHATTYPE = "private"; private static final String GROUPCHATTYPE = "group"; @@ -142,6 +143,13 @@ public class Chat implements BotApiObject { */ @JsonProperty(JOINBYREQUEST_FIELD) private Boolean joinByRequest; + /** + * Optional. + * True, if the privacy settings of the other party restrict sending voice and video note messages in the private chat. + * Returned only in getChat. + */ + @JsonProperty(HASRESTRICTEDVOICEANDVIDEOMESSAGES_FIELD) + private Boolean hasRestrictedVoiceAndVideoMessages; @JsonIgnore public Boolean isGroupChat() { diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/MessageEntity.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/MessageEntity.java index 33eeb9de..3a8442f7 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/MessageEntity.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/MessageEntity.java @@ -35,6 +35,7 @@ public class MessageEntity implements BotApiObject { private static final String URL_FIELD = "url"; private static final String USER_FIELD = "user"; private static final String LANGUAGE_FIELD = "language"; + private static final String CUSTOMEMOJI_FIELD = "custom_emoji_id"; /** * Type of the entity. * Currently, can be: @@ -54,6 +55,7 @@ public class MessageEntity implements BotApiObject { * - “pre” (monowidth block) * - “text_link” (for clickable text URLs) * - “text_mention” (for users without usernames) + * - "custom_emoji" (for inline custom emoji stickers) */ @JsonProperty(TYPE_FIELD) @NonNull @@ -70,6 +72,13 @@ public class MessageEntity implements BotApiObject { private User user; ///< Optional. For “text_mention” only, the mentioned user @JsonProperty(LANGUAGE_FIELD) private String language; ///< Optional. For “pre” only, the programming language of the entity text + /** + * Optional. + * For “custom_emoji” only, unique identifier of the custom emoji. + * Use getCustomEmojiStickers to get full information about the sticker + */ + @JsonProperty(CUSTOMEMOJI_FIELD) + private String customEmojiId; @JsonIgnore private String text; ///< Text present in the entity. Computed from offset and length diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stickers/Sticker.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stickers/Sticker.java index 8265bf8a..a4377364 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stickers/Sticker.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stickers/Sticker.java @@ -26,6 +26,7 @@ public class Sticker implements BotApiObject { private static final String FILEID_FIELD = "file_id"; private static final String FILEUNIQUEID_FIELD = "file_unique_id"; + private static final String TYPE_FIELD = "type"; private static final String WIDTH_FIELD = "width"; private static final String HEIGHT_FIELD = "height"; private static final String THUMB_FIELD = "thumb"; @@ -36,6 +37,7 @@ public class Sticker implements BotApiObject { private static final String ISANIMATED_FIELD = "is_animated"; private static final String ISVIDEO_FIELD = "is_video"; private static final String PREMIUMANIMATION_FIELD = "premium_animation"; + private static final String CUSTOMEMOJIID_FIELD = "custom_emoji_id"; @JsonProperty(FILEID_FIELD) private String fileId; ///< Identifier for this file, which can be used to download or reuse the file @@ -45,6 +47,12 @@ public class Sticker implements BotApiObject { */ @JsonProperty(FILEUNIQUEID_FIELD) private String fileUniqueId; + /** + * Type of the sticker, currently one of “regular”, “mask”, “custom_emoji”. + * The type of the sticker is independent of its format, which is determined by the fields is_animated and is_video. + */ + @JsonProperty(TYPE_FIELD) + private String type; @JsonProperty(WIDTH_FIELD) private Integer width; ///< Sticker width @JsonProperty(HEIGHT_FIELD) @@ -65,4 +73,7 @@ public class Sticker implements BotApiObject { private Boolean isVideo; ///< True, if the sticker is a video sticker @JsonProperty(PREMIUMANIMATION_FIELD) private File premiumAnimation; ///< Optional. Premium animation for the sticker, if the sticker is premium + @JsonProperty(CUSTOMEMOJIID_FIELD) + private String customEmojiId; ///< Optional. For custom emoji stickers, unique identifier of the custom emoji + } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stickers/StickerSet.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stickers/StickerSet.java index a144f359..9f904601 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stickers/StickerSet.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stickers/StickerSet.java @@ -24,6 +24,7 @@ import java.util.List; @NoArgsConstructor @AllArgsConstructor public class StickerSet implements BotApiObject { + private static final String STICKERTYPE_FIELD = "sticker_type"; private static final String NAME_FIELD = "name"; private static final String TITLE_FIELD = "title"; private static final String CONTAINSMASKS_FIELD = "contains_masks"; @@ -32,12 +33,20 @@ public class StickerSet implements BotApiObject { private static final String ISVIDEO_FIELD = "is_video"; private static final String THUMB_FIELD = "thumb"; + @JsonProperty(STICKERS_FIELD) + private String stickerType; ///< Type of stickers in the set, currently one of “regular”, “mask”, “custom_emoji” @JsonProperty(NAME_FIELD) private String name; ///< Sticker set name @JsonProperty(TITLE_FIELD) private String title; ///< Sticker set title + /** + * True, if the sticker set contains animated stickers + * + * @deprecated Use {@link #getStickerType()} or {@link #isMask()} + */ @JsonProperty(CONTAINSMASKS_FIELD) - private Boolean containsMasks; ///< True, if the sticker set contains animated stickers + @Deprecated + private Boolean containsMasks; @JsonProperty(STICKERS_FIELD) private List stickers; ///< True, if the sticker set contains masks @JsonProperty(ISANIMATED_FIELD) @@ -46,4 +55,15 @@ public class StickerSet implements BotApiObject { private Boolean isVideo; ///< True, if the sticker set contains video stickers @JsonProperty(THUMB_FIELD) private PhotoSize thumb; ///< Optional. Sticker set thumbnail in the .WEBP, .TGS, or .WEBM format + + public boolean isRegularSticker() { + return "regular".equals(stickerType); + } + public boolean isMask() { + return "mask".equals(stickerType); + } + + public boolean isCustomEmoji() { + return "custom_emoji".equals(stickerType); + } } 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 2564e4fc..eca30757 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java @@ -669,7 +669,7 @@ public abstract class DefaultAbsSender extends AbsSender { builder.addTextBody(CreateNewStickerSet.NAME_FIELD, createNewStickerSet.getName(), TEXT_PLAIN_CONTENT_TYPE); builder.addTextBody(CreateNewStickerSet.TITLE_FIELD, createNewStickerSet.getTitle(), TEXT_PLAIN_CONTENT_TYPE); builder.addTextBody(CreateNewStickerSet.EMOJIS_FIELD, createNewStickerSet.getEmojis(), TEXT_PLAIN_CONTENT_TYPE); - builder.addTextBody(CreateNewStickerSet.CONTAINSMASKS_FIELD, createNewStickerSet.getContainsMasks().toString(), TEXT_PLAIN_CONTENT_TYPE); + builder.addTextBody(CreateNewStickerSet.STICKERTYPE_FIELD, createNewStickerSet.getStickerType(), TEXT_PLAIN_CONTENT_TYPE); if (createNewStickerSet.getPngSticker() != null) { addInputFile(builder, createNewStickerSet.getPngSticker(), CreateNewStickerSet.PNGSTICKER_FIELD, true); } else if (createNewStickerSet.getTgsSticker() != null) { diff --git a/telegrambots/src/test/java/org/telegram/telegrambots/test/BotApiMethodHelperFactory.java b/telegrambots/src/test/java/org/telegram/telegrambots/test/BotApiMethodHelperFactory.java index a11d6feb..56501d96 100644 --- a/telegrambots/src/test/java/org/telegram/telegrambots/test/BotApiMethodHelperFactory.java +++ b/telegrambots/src/test/java/org/telegram/telegrambots/test/BotApiMethodHelperFactory.java @@ -18,10 +18,10 @@ import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatMem import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatMemberCount; import org.telegram.telegrambots.meta.api.methods.groupadministration.LeaveChat; import org.telegram.telegrambots.meta.api.methods.groupadministration.UnbanChatMember; +import org.telegram.telegrambots.meta.api.methods.invoices.SendInvoice; import org.telegram.telegrambots.meta.api.methods.send.SendChatAction; import org.telegram.telegrambots.meta.api.methods.send.SendContact; import org.telegram.telegrambots.meta.api.methods.send.SendGame; -import org.telegram.telegrambots.meta.api.methods.send.SendInvoice; import org.telegram.telegrambots.meta.api.methods.send.SendLocation; import org.telegram.telegrambots.meta.api.methods.send.SendMessage; import org.telegram.telegrambots.meta.api.methods.send.SendVenue; diff --git a/telegrambots/src/test/java/org/telegram/telegrambots/test/TelegramFileDownloaderTest.java b/telegrambots/src/test/java/org/telegram/telegrambots/test/TelegramFileDownloaderTest.java index e6f9366e..db30ffea 100644 --- a/telegrambots/src/test/java/org/telegram/telegrambots/test/TelegramFileDownloaderTest.java +++ b/telegrambots/src/test/java/org/telegram/telegrambots/test/TelegramFileDownloaderTest.java @@ -26,9 +26,9 @@ import static java.nio.charset.Charset.defaultCharset; import static org.apache.commons.io.FileUtils.readFileToString; import static org.apache.commons.io.IOUtils.toInputStream; import static org.apache.http.HttpVersion.HTTP_1_1; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsInstanceOf.instanceOf; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; diff --git a/telegrambots/src/test/java/org/telegram/telegrambots/test/TelegramLongPollingBotTest.java b/telegrambots/src/test/java/org/telegram/telegrambots/test/TelegramLongPollingBotTest.java index b86fd390..1a617772 100644 --- a/telegrambots/src/test/java/org/telegram/telegrambots/test/TelegramLongPollingBotTest.java +++ b/telegrambots/src/test/java/org/telegram/telegrambots/test/TelegramLongPollingBotTest.java @@ -12,7 +12,7 @@ import java.util.concurrent.TimeUnit; import static java.util.Arrays.asList; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.ArgumentMatchers.any; public class TelegramLongPollingBotTest { diff --git a/telegrambots/src/test/java/org/telegram/telegrambots/test/TestRestApi.java b/telegrambots/src/test/java/org/telegram/telegrambots/test/TestRestApi.java index 6fd94a1a..5cea6854 100644 --- a/telegrambots/src/test/java/org/telegram/telegrambots/test/TestRestApi.java +++ b/telegrambots/src/test/java/org/telegram/telegrambots/test/TestRestApi.java @@ -23,10 +23,10 @@ import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatMem import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatMemberCount; import org.telegram.telegrambots.meta.api.methods.groupadministration.LeaveChat; import org.telegram.telegrambots.meta.api.methods.groupadministration.UnbanChatMember; +import org.telegram.telegrambots.meta.api.methods.invoices.SendInvoice; import org.telegram.telegrambots.meta.api.methods.send.SendChatAction; import org.telegram.telegrambots.meta.api.methods.send.SendContact; import org.telegram.telegrambots.meta.api.methods.send.SendGame; -import org.telegram.telegrambots.meta.api.methods.send.SendInvoice; import org.telegram.telegrambots.meta.api.methods.send.SendLocation; import org.telegram.telegrambots.meta.api.methods.send.SendMessage; import org.telegram.telegrambots.meta.api.methods.send.SendVenue; @@ -62,7 +62,7 @@ import static org.junit.Assert.fail; */ public class TestRestApi extends JerseyTest { - private FakeWebhook webhookBot = new FakeWebhook(); + private final FakeWebhook webhookBot = new FakeWebhook(); private RestApi restApi; @Override