From c27ce3a99a4fc7717462f35ce2e18ffcc05f1f16 Mon Sep 17 00:00:00 2001 From: ruben Date: Tue, 10 Jun 2025 23:08:17 +0100 Subject: [PATCH 01/16] Api Version 9.0 --- pom.xml | 2 +- telegrambots-abilities/pom.xml | 6 +- telegrambots-client-jetty-adapter/pom.xml | 2 +- .../client/AbstractTelegramClient.java | 10 ++ .../client/jetty/JettyTelegramClient.java | 37 ++++ .../client/TestTelegramClientIntegration.java | 54 +++++- .../client/TestTelegramMultipartBuilder.java | 6 +- telegrambots-client/pom.xml | 2 +- .../client/AbstractTelegramClient.java | 27 ++- .../client/okhttp/OkHttpTelegramClient.java | 35 ++++ .../client/TestTelegramClientIntegration.java | 41 ++++- .../client/TestTelegramMultipartBuilder.java | 2 +- telegrambots-extensions/README.md | 4 +- telegrambots-extensions/pom.xml | 6 +- telegrambots-longpolling/pom.xml | 2 +- telegrambots-meta/pom.xml | 2 +- .../business/DeleteBusinessMessages.java | 76 +++++++++ .../business/GetBusinessAccountGifts.java | 123 ++++++++++++++ .../GetBusinessAccountStarBalance.java | 60 +++++++ .../methods/business/ReadBusinessMessage.java | 69 ++++++++ .../RemoveBusinessAccountProfilePhoto.java | 65 +++++++ .../business/SetBusinessAccountBio.java | 64 +++++++ .../SetBusinessAccountGiftSettings.java | 69 ++++++++ .../business/SetBusinessAccountName.java | 77 +++++++++ .../SetBusinessAccountProfilePhoto.java | 80 +++++++++ .../business/SetBusinessAccountUsername.java | 63 +++++++ .../TransferBusinessAccountStars.java | 66 ++++++++ .../api/methods/gifts/ConvertGiftToStars.java | 68 ++++++++ .../gifts/GiftPremiumSubscription.java | 104 ++++++++++++ .../meta/api/methods/gifts/TransferGift.java | 89 ++++++++++ .../meta/api/methods/gifts/UpgradeGift.java | 89 ++++++++++ .../meta/api/methods/stories/DeleteStory.java | 62 +++++++ .../meta/api/methods/stories/EditStory.java | 124 ++++++++++++++ .../meta/api/methods/stories/PostStory.java | 159 ++++++++++++++++++ .../telegrambots/meta/api/objects/Audio.java | 1 + .../meta/api/objects/ChatLocation.java | 1 + .../meta/api/objects/ChatShared.java | 1 + .../meta/api/objects/Document.java | 1 + .../meta/api/objects/ExternalReplyInfo.java | 2 + .../meta/api/objects/InputFile.java | 9 +- .../meta/api/objects/UserProfilePhotos.java | 2 +- .../meta/api/objects/UserShared.java | 1 + .../telegrambots/meta/api/objects/Venue.java | 1 + .../telegrambots/meta/api/objects/Video.java | 1 + .../meta/api/objects/VideoNote.java | 1 + .../objects/business/BusinessBotRights.java | 130 ++++++++++++++ .../objects/business/BusinessConnection.java | 20 ++- .../objects/business/BusinessLocation.java | 2 +- .../meta/api/objects/chat/ChatFullInfo.java | 7 +- .../meta/api/objects/games/Animation.java | 2 +- .../meta/api/objects/games/Game.java | 2 +- .../api/objects/gifts/AcceptedGiftTypes.java | 56 ++++++ .../meta/api/objects/gifts/GiftInfo.java | 95 +++++++++++ .../meta/api/objects/gifts/UniqueGift.java | 74 ++++++++ .../api/objects/gifts/UniqueGiftBackdrop.java | 56 ++++++ .../gifts/UniqueGiftBackdropColors.java | 63 +++++++ .../api/objects/gifts/UniqueGiftInfo.java | 65 +++++++ .../api/objects/gifts/UniqueGiftModel.java | 55 ++++++ .../api/objects/gifts/UniqueGiftSymbol.java | 57 +++++++ .../api/objects/gifts/owned/OwnedGift.java | 79 +++++++++ .../objects/gifts/owned/OwnedGiftRegular.java | 107 ++++++++++++ .../objects/gifts/owned/OwnedGiftUnique.java | 68 ++++++++ .../api/objects/gifts/owned/OwnedGifts.java | 59 +++++++ .../inlinequery/ChosenInlineQuery.java | 2 +- .../api/objects/inlinequery/InlineQuery.java | 2 +- .../result/InlineQueryResultArticle.java | 8 - .../api/objects/{ => location}/Location.java | 2 +- .../api/objects/location/LocationAddress.java | 74 ++++++++ .../meta/api/objects/message/Message.java | 54 +++++- .../message/PaidMessagePriceChanged.java | 39 +++++ .../meta/api/objects/payments/Invoice.java | 2 +- .../payments/paidmedia/PaidMediaPhoto.java | 2 +- .../api/objects/payments/star/StarAmount.java | 67 ++++++++ .../TransactionPartnerUser.java | 58 ++++--- .../api/objects/{ => photo}/PhotoSize.java | 2 +- .../photo/input/InputProfilePhoto.java | 45 +++++ .../input/InputProfilePhotoAnimated.java | 61 +++++++ .../photo/input/InputProfilePhotoStatic.java | 53 ++++++ .../reactions/ReactionTypeCustomEmoji.java | 7 +- .../objects/reactions/ReactionTypeEmoji.java | 7 +- .../objects/reactions/ReactionTypePaid.java | 13 +- .../meta/api/objects/stickers/Sticker.java | 3 +- .../meta/api/objects/stickers/StickerSet.java | 2 +- .../meta/api/objects/stories/StoryArea.java | 55 ++++++ .../objects/stories/StoryAreaPosition.java | 85 ++++++++++ .../objects/stories/area/StoryAreaType.java | 48 ++++++ .../stories/area/StoryAreaTypeLink.java | 47 ++++++ .../stories/area/StoryAreaTypeLocation.java | 60 +++++++ .../area/StoryAreaTypeSuggestedReaction.java | 62 +++++++ .../stories/area/StoryAreaTypeUniqueGift.java | 47 ++++++ .../stories/area/StoryAreaTypeWeather.java | 63 +++++++ .../stories/input/InputStoryContent.java | 42 +++++ .../stories/input/InputStoryContentPhoto.java | 50 ++++++ .../stories/input/InputStoryContentVideo.java | 80 +++++++++ .../meta/generics/TelegramClient.java | 10 ++ .../business/TestReadBusinessMessage.java | 64 +++++++ ...TestRemoveBusinessAccountProfilePhoto.java | 56 ++++++ .../business/TestSetBusinessAccountName.java | 96 +++++++++++ .../TestSetBusinessAccountProfilePhoto.java | 94 +++++++++++ .../gifts/TestGiftPremiumSubscription.java | 92 ++++++++++ .../api/methods/gifts/TestTransferGift.java | 75 +++++++++ .../api/methods/stories/TestDeleteStory.java | 57 +++++++ .../api/methods/stories/TestEditStory.java | 132 +++++++++++++++ .../meta/api/objects/TestDocument.java | 1 + .../business/TestBusinessLocation.java | 61 +++++++ .../objects/gifts/TestUniqueGiftModel.java | 54 ++++++ .../api/objects/location/TestLocation.java | 67 ++++++++ .../objects/location/TestLocationAddress.java | 68 ++++++++ .../media/paid/TestInputPaidMedia.java | 78 +++++++++ .../payments/star/TestStarTransactions.java | 2 + .../meta/api/objects/photo/TestPhotoSize.java | 75 +++++++++ .../photo/input/TestInputProfilePhoto.java | 49 ++++++ .../input/TestInputProfilePhotoAnimated.java | 55 ++++++ .../input/TestInputProfilePhotoStatic.java | 68 ++++++++ .../stories/area/TestStoryAreaType.java | 54 ++++++ .../stories/area/TestStoryAreaTypeLink.java | 58 +++++++ .../area/TestStoryAreaTypeLocation.java | 71 ++++++++ .../TestStoryAreaTypeSuggestedReaction.java | 57 +++++++ .../area/TestStoryAreaTypeUniqueGift.java | 58 +++++++ .../area/TestStoryAreaTypeWeather.java | 66 ++++++++ .../input/TestInputStoryContentPhoto.java | 58 +++++++ .../input/TestInputStoryContentVideo.java | 83 +++++++++ .../pom.xml | 4 +- .../pom.xml | 4 +- telegrambots-test-reports/pom.xml | 2 +- telegrambots-webhook/pom.xml | 2 +- 126 files changed, 5565 insertions(+), 111 deletions(-) create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/DeleteBusinessMessages.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/GetBusinessAccountGifts.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/GetBusinessAccountStarBalance.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/ReadBusinessMessage.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/RemoveBusinessAccountProfilePhoto.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/SetBusinessAccountBio.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/SetBusinessAccountGiftSettings.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/SetBusinessAccountName.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/SetBusinessAccountProfilePhoto.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/SetBusinessAccountUsername.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/TransferBusinessAccountStars.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/gifts/ConvertGiftToStars.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/gifts/GiftPremiumSubscription.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/gifts/TransferGift.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/gifts/UpgradeGift.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stories/DeleteStory.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stories/EditStory.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stories/PostStory.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/business/BusinessBotRights.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/AcceptedGiftTypes.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/GiftInfo.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGift.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGiftBackdrop.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGiftBackdropColors.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGiftInfo.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGiftModel.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGiftSymbol.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/owned/OwnedGift.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/owned/OwnedGiftRegular.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/owned/OwnedGiftUnique.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/owned/OwnedGifts.java rename telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/{ => location}/Location.java (97%) create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/location/LocationAddress.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/message/PaidMessagePriceChanged.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/payments/star/StarAmount.java rename telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/{ => photo}/PhotoSize.java (97%) create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/photo/input/InputProfilePhoto.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/photo/input/InputProfilePhotoAnimated.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/photo/input/InputProfilePhotoStatic.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/StoryArea.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/StoryAreaPosition.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/area/StoryAreaType.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/area/StoryAreaTypeLink.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/area/StoryAreaTypeLocation.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/area/StoryAreaTypeSuggestedReaction.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/area/StoryAreaTypeUniqueGift.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/area/StoryAreaTypeWeather.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/input/InputStoryContent.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/input/InputStoryContentPhoto.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/input/InputStoryContentVideo.java create mode 100644 telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/business/TestReadBusinessMessage.java create mode 100644 telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/business/TestRemoveBusinessAccountProfilePhoto.java create mode 100644 telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/business/TestSetBusinessAccountName.java create mode 100644 telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/business/TestSetBusinessAccountProfilePhoto.java create mode 100644 telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/gifts/TestGiftPremiumSubscription.java create mode 100644 telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/gifts/TestTransferGift.java create mode 100644 telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/stories/TestDeleteStory.java create mode 100644 telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/stories/TestEditStory.java create mode 100644 telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/business/TestBusinessLocation.java create mode 100644 telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/gifts/TestUniqueGiftModel.java create mode 100644 telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/location/TestLocation.java create mode 100644 telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/location/TestLocationAddress.java create mode 100644 telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/media/paid/TestInputPaidMedia.java create mode 100644 telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/photo/TestPhotoSize.java create mode 100644 telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/photo/input/TestInputProfilePhoto.java create mode 100644 telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/photo/input/TestInputProfilePhotoAnimated.java create mode 100644 telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/photo/input/TestInputProfilePhotoStatic.java create mode 100644 telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/area/TestStoryAreaType.java create mode 100644 telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/area/TestStoryAreaTypeLink.java create mode 100644 telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/area/TestStoryAreaTypeLocation.java create mode 100644 telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/area/TestStoryAreaTypeSuggestedReaction.java create mode 100644 telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/area/TestStoryAreaTypeUniqueGift.java create mode 100644 telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/area/TestStoryAreaTypeWeather.java create mode 100644 telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/input/TestInputStoryContentPhoto.java create mode 100644 telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/input/TestInputStoryContentVideo.java diff --git a/pom.xml b/pom.xml index 7966d04b0..5de1ec2e8 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots pom - 8.3.0 + 9.0.0 telegrambots-meta diff --git a/telegrambots-abilities/pom.xml b/telegrambots-abilities/pom.xml index 138b30388..479a388c2 100644 --- a/telegrambots-abilities/pom.xml +++ b/telegrambots-abilities/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 8.3.0 + 9.0.0 telegrambots-abilities @@ -104,12 +104,12 @@ org.telegram telegrambots-webhook - 8.3.0 + 9.0.0 org.telegram telegrambots-longpolling - 8.3.0 + 9.0.0 diff --git a/telegrambots-client-jetty-adapter/pom.xml b/telegrambots-client-jetty-adapter/pom.xml index 62be30599..a67e7a4d3 100644 --- a/telegrambots-client-jetty-adapter/pom.xml +++ b/telegrambots-client-jetty-adapter/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 8.3.0 + 9.0.0 Telegram Bots Client Jetty HttpClient adapter diff --git a/telegrambots-client-jetty-adapter/src/main/java/org/telegram/telegrambots/client/AbstractTelegramClient.java b/telegrambots-client-jetty-adapter/src/main/java/org/telegram/telegrambots/client/AbstractTelegramClient.java index 6180d76ae..3c88b17b2 100644 --- a/telegrambots-client-jetty-adapter/src/main/java/org/telegram/telegrambots/client/AbstractTelegramClient.java +++ b/telegrambots-client-jetty-adapter/src/main/java/org/telegram/telegrambots/client/AbstractTelegramClient.java @@ -1,6 +1,7 @@ package org.telegram.telegrambots.client; import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethod; +import org.telegram.telegrambots.meta.api.methods.business.SetBusinessAccountProfilePhoto; import org.telegram.telegrambots.meta.api.methods.groupadministration.SetChatPhoto; import org.telegram.telegrambots.meta.api.methods.send.SendAnimation; import org.telegram.telegrambots.meta.api.methods.send.SendAudio; @@ -96,6 +97,15 @@ public Message execute(SendSticker sendSticker) throws TelegramApiException { } } + @Override + public Boolean execute(SetBusinessAccountProfilePhoto setBusinessAccountProfilePhoto) throws TelegramApiException { + try { + return executeAsync(setBusinessAccountProfilePhoto).get(); + } catch (Exception e) { + throw mapException(e, setBusinessAccountProfilePhoto.getMethod()); + } + } + @Override public Message execute(SendAudio sendAudio) throws TelegramApiException { try { diff --git a/telegrambots-client-jetty-adapter/src/main/java/org/telegram/telegrambots/client/jetty/JettyTelegramClient.java b/telegrambots-client-jetty-adapter/src/main/java/org/telegram/telegrambots/client/jetty/JettyTelegramClient.java index e33f04b14..df8ff0929 100644 --- a/telegrambots-client-jetty-adapter/src/main/java/org/telegram/telegrambots/client/jetty/JettyTelegramClient.java +++ b/telegrambots-client-jetty-adapter/src/main/java/org/telegram/telegrambots/client/jetty/JettyTelegramClient.java @@ -14,6 +14,7 @@ import org.telegram.telegrambots.meta.TelegramUrl; import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethod; import org.telegram.telegrambots.meta.api.methods.botapimethods.PartialBotApiMethod; +import org.telegram.telegrambots.meta.api.methods.business.SetBusinessAccountProfilePhoto; import org.telegram.telegrambots.meta.api.methods.groupadministration.SetChatPhoto; import org.telegram.telegrambots.meta.api.methods.send.SendAnimation; import org.telegram.telegrambots.meta.api.methods.send.SendAudio; @@ -42,6 +43,8 @@ import org.telegram.telegrambots.meta.api.objects.media.paid.InputPaidMedia; import org.telegram.telegrambots.meta.api.objects.media.paid.InputPaidMediaVideo; import org.telegram.telegrambots.meta.api.objects.message.Message; +import org.telegram.telegrambots.meta.api.objects.photo.input.InputProfilePhotoAnimated; +import org.telegram.telegrambots.meta.api.objects.photo.input.InputProfilePhotoStatic; import org.telegram.telegrambots.meta.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; @@ -141,6 +144,40 @@ public CompletableFuture executeAsync(SendPhoto sendPhoto) { .addJsonPart(SendPhoto.CAPTION_ENTITIES_FIELD, sendPhoto.getCaptionEntities())); } + @Override + public CompletableFuture executeAsync(SetBusinessAccountProfilePhoto setBusinessAccountProfilePhoto) { + try { + assertParamNotNull(setBusinessAccountProfilePhoto, "method"); + + setBusinessAccountProfilePhoto.validate(); + + URI url = buildUrl(setBusinessAccountProfilePhoto.getMethod()); + + JettyMultipartBuilder builder = new JettyMultipartBuilder(objectMapper); + + builder.addPart(SetBusinessAccountProfilePhoto.BUSINESS_CONNECTION_ID_FIELD, setBusinessAccountProfilePhoto.getBusinessConnectionId()) + .addPart(SetBusinessAccountProfilePhoto.IS_PUBLIC_FIELD, setBusinessAccountProfilePhoto.getIsPublic()); + + if (InputProfilePhotoStatic.TYPE.equals(setBusinessAccountProfilePhoto.getPhoto().getType())) { + InputProfilePhotoStatic photo = (InputProfilePhotoStatic) setBusinessAccountProfilePhoto.getPhoto(); + builder.addJsonPart(SetBusinessAccountProfilePhoto.PHOTO_FIELD, photo) + .addInputFile(InputProfilePhotoStatic.PHOTO_FIELD, photo.getPhoto(), false); + } else if (InputProfilePhotoAnimated.TYPE.equals(setBusinessAccountProfilePhoto.getPhoto().getType())) { + InputProfilePhotoAnimated photo = (InputProfilePhotoAnimated) setBusinessAccountProfilePhoto.getPhoto(); + builder.addJsonPart(SetBusinessAccountProfilePhoto.PHOTO_FIELD, photo) + .addInputFile(InputProfilePhotoAnimated.ANIMATION_FIELD, photo.getAnimation(), false); + } + + Request httpPost = client.POST(url).body(builder.build()); + + return sendRequest(setBusinessAccountProfilePhoto, httpPost); + } catch (TelegramApiException e) { + return CompletableFuture.failedFuture(e); + } catch (IOException e) { + return CompletableFuture.failedFuture(new TelegramApiException("Unable to execute " + setBusinessAccountProfilePhoto.getMethod(), e)); + } + } + @Override public CompletableFuture executeAsync(SetWebhook setWebhook) { try { diff --git a/telegrambots-client-jetty-adapter/src/test/java/org/telegram/telegrambots/client/TestTelegramClientIntegration.java b/telegrambots-client-jetty-adapter/src/test/java/org/telegram/telegrambots/client/TestTelegramClientIntegration.java index aeb2988ed..c6f17b1dd 100644 --- a/telegrambots-client-jetty-adapter/src/test/java/org/telegram/telegrambots/client/TestTelegramClientIntegration.java +++ b/telegrambots-client-jetty-adapter/src/test/java/org/telegram/telegrambots/client/TestTelegramClientIntegration.java @@ -14,9 +14,19 @@ import org.telegram.telegrambots.client.jetty.JettyTelegramClient; import org.telegram.telegrambots.meta.TelegramUrl; import org.telegram.telegrambots.meta.api.methods.botapimethods.PartialBotApiMethod; -import org.telegram.telegrambots.meta.api.methods.send.*; +import org.telegram.telegrambots.meta.api.methods.business.SetBusinessAccountProfilePhoto; +import org.telegram.telegrambots.meta.api.methods.send.SendAnimation; +import org.telegram.telegrambots.meta.api.methods.send.SendAudio; +import org.telegram.telegrambots.meta.api.methods.send.SendDocument; +import org.telegram.telegrambots.meta.api.methods.send.SendMessage; +import org.telegram.telegrambots.meta.api.methods.send.SendPhoto; +import org.telegram.telegrambots.meta.api.methods.send.SendSticker; +import org.telegram.telegrambots.meta.api.methods.send.SendVideo; +import org.telegram.telegrambots.meta.api.methods.send.SendVideoNote; +import org.telegram.telegrambots.meta.api.methods.send.SendVoice; import org.telegram.telegrambots.meta.api.objects.InputFile; import org.telegram.telegrambots.meta.api.objects.message.Message; +import org.telegram.telegrambots.meta.api.objects.photo.input.InputProfilePhotoStatic; import org.telegram.telegrambots.meta.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; @@ -25,7 +35,10 @@ import java.io.Serializable; import java.nio.charset.StandardCharsets; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TestTelegramClientIntegration { private MockWebServer webServer; @@ -261,6 +274,43 @@ void testSendAnimationException() { assertEquals(404, exception.getErrorCode()); } + @Test + void testSetBusinessAccountProfilePhoto() throws TelegramApiException { + InputFile inputFile = new InputFile(getTestFile()); + InputProfilePhotoStatic profilePhoto = InputProfilePhotoStatic.builder() + .photo(inputFile) + .build(); + + SetBusinessAccountProfilePhoto method = SetBusinessAccountProfilePhoto.builder() + .businessConnectionId("test-connection-id") + .photo(profilePhoto) + .isPublic(true) + .build(); + + mockMethod(method, Boolean.TRUE); + + assertTrue(client.execute(method)); + } + + @Test + void testSetBusinessAccountProfilePhotoException() { + InputFile inputFile = new InputFile(getTestFile()); + InputProfilePhotoStatic profilePhoto = InputProfilePhotoStatic.builder() + .photo(inputFile) + .build(); + + SetBusinessAccountProfilePhoto method = SetBusinessAccountProfilePhoto.builder() + .businessConnectionId("test-connection-id") + .photo(profilePhoto) + .isPublic(true) + .build(); + + mockErrorMethod(method); + + TelegramApiRequestException exception = Assertions.assertThrows(TelegramApiRequestException.class, () -> client.execute(method)); + assertEquals(404, exception.getErrorCode()); + } + @NotNull private File getTestFile() { ClassLoader classLoader = getClass().getClassLoader(); diff --git a/telegrambots-client-jetty-adapter/src/test/java/org/telegram/telegrambots/client/TestTelegramMultipartBuilder.java b/telegrambots-client-jetty-adapter/src/test/java/org/telegram/telegrambots/client/TestTelegramMultipartBuilder.java index 3bec5dae6..a7f940941 100644 --- a/telegrambots-client-jetty-adapter/src/test/java/org/telegram/telegrambots/client/TestTelegramMultipartBuilder.java +++ b/telegrambots-client-jetty-adapter/src/test/java/org/telegram/telegrambots/client/TestTelegramMultipartBuilder.java @@ -7,7 +7,7 @@ import org.junit.jupiter.api.Test; import org.telegram.telegrambots.client.jetty.JettyMultipartBuilder; import org.telegram.telegrambots.meta.api.objects.InputFile; -import org.telegram.telegrambots.meta.api.objects.Location; +import org.telegram.telegrambots.meta.api.objects.location.Location; import org.telegram.telegrambots.meta.api.objects.media.InputMediaDocument; import org.telegram.telegrambots.meta.api.objects.stickers.InputSticker; @@ -18,7 +18,9 @@ import java.util.ArrayDeque; import java.util.List; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; public class TestTelegramMultipartBuilder { private JettyMultipartBuilder multipartBuilder; diff --git a/telegrambots-client/pom.xml b/telegrambots-client/pom.xml index d187e5fc8..b56f5febb 100644 --- a/telegrambots-client/pom.xml +++ b/telegrambots-client/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 8.3.0 + 9.0.0 Telegram Bots Client diff --git a/telegrambots-client/src/main/java/org/telegram/telegrambots/client/AbstractTelegramClient.java b/telegrambots-client/src/main/java/org/telegram/telegrambots/client/AbstractTelegramClient.java index c7eced835..3c88b17b2 100644 --- a/telegrambots-client/src/main/java/org/telegram/telegrambots/client/AbstractTelegramClient.java +++ b/telegrambots-client/src/main/java/org/telegram/telegrambots/client/AbstractTelegramClient.java @@ -1,9 +1,23 @@ package org.telegram.telegrambots.client; import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethod; +import org.telegram.telegrambots.meta.api.methods.business.SetBusinessAccountProfilePhoto; import org.telegram.telegrambots.meta.api.methods.groupadministration.SetChatPhoto; -import org.telegram.telegrambots.meta.api.methods.send.*; -import org.telegram.telegrambots.meta.api.methods.stickers.*; +import org.telegram.telegrambots.meta.api.methods.send.SendAnimation; +import org.telegram.telegrambots.meta.api.methods.send.SendAudio; +import org.telegram.telegrambots.meta.api.methods.send.SendDocument; +import org.telegram.telegrambots.meta.api.methods.send.SendMediaGroup; +import org.telegram.telegrambots.meta.api.methods.send.SendPaidMedia; +import org.telegram.telegrambots.meta.api.methods.send.SendPhoto; +import org.telegram.telegrambots.meta.api.methods.send.SendSticker; +import org.telegram.telegrambots.meta.api.methods.send.SendVideo; +import org.telegram.telegrambots.meta.api.methods.send.SendVideoNote; +import org.telegram.telegrambots.meta.api.methods.send.SendVoice; +import org.telegram.telegrambots.meta.api.methods.stickers.AddStickerToSet; +import org.telegram.telegrambots.meta.api.methods.stickers.CreateNewStickerSet; +import org.telegram.telegrambots.meta.api.methods.stickers.ReplaceStickerInSet; +import org.telegram.telegrambots.meta.api.methods.stickers.SetStickerSetThumbnail; +import org.telegram.telegrambots.meta.api.methods.stickers.UploadStickerFile; import org.telegram.telegrambots.meta.api.methods.updates.SetWebhook; import org.telegram.telegrambots.meta.api.methods.updatingmessages.EditMessageMedia; import org.telegram.telegrambots.meta.api.objects.File; @@ -83,6 +97,15 @@ public Message execute(SendSticker sendSticker) throws TelegramApiException { } } + @Override + public Boolean execute(SetBusinessAccountProfilePhoto setBusinessAccountProfilePhoto) throws TelegramApiException { + try { + return executeAsync(setBusinessAccountProfilePhoto).get(); + } catch (Exception e) { + throw mapException(e, setBusinessAccountProfilePhoto.getMethod()); + } + } + @Override public Message execute(SendAudio sendAudio) throws TelegramApiException { try { diff --git a/telegrambots-client/src/main/java/org/telegram/telegrambots/client/okhttp/OkHttpTelegramClient.java b/telegrambots-client/src/main/java/org/telegram/telegrambots/client/okhttp/OkHttpTelegramClient.java index ed4f1b1ff..c772ee4bb 100644 --- a/telegrambots-client/src/main/java/org/telegram/telegrambots/client/okhttp/OkHttpTelegramClient.java +++ b/telegrambots-client/src/main/java/org/telegram/telegrambots/client/okhttp/OkHttpTelegramClient.java @@ -15,6 +15,7 @@ import org.telegram.telegrambots.meta.TelegramUrl; import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethod; import org.telegram.telegrambots.meta.api.methods.botapimethods.PartialBotApiMethod; +import org.telegram.telegrambots.meta.api.methods.business.SetBusinessAccountProfilePhoto; import org.telegram.telegrambots.meta.api.methods.groupadministration.SetChatPhoto; import org.telegram.telegrambots.meta.api.methods.send.SendAnimation; import org.telegram.telegrambots.meta.api.methods.send.SendAudio; @@ -43,6 +44,8 @@ import org.telegram.telegrambots.meta.api.objects.media.paid.InputPaidMedia; import org.telegram.telegrambots.meta.api.objects.media.paid.InputPaidMediaVideo; import org.telegram.telegrambots.meta.api.objects.message.Message; +import org.telegram.telegrambots.meta.api.objects.photo.input.InputProfilePhotoAnimated; +import org.telegram.telegrambots.meta.api.objects.photo.input.InputProfilePhotoStatic; import org.telegram.telegrambots.meta.exceptions.TelegramApiException; import java.io.IOException; @@ -108,6 +111,38 @@ public > CompletableFutur } } + @Override + public CompletableFuture executeAsync(SetBusinessAccountProfilePhoto setBusinessAccountProfilePhoto) { + try { + assertParamNotNull(setBusinessAccountProfilePhoto, "setBusinessAccountProfilePhoto"); + setBusinessAccountProfilePhoto.validate(); + + HttpUrl url = buildUrl(setBusinessAccountProfilePhoto.getMethod()); + + TelegramMultipartBuilder builder = new TelegramMultipartBuilder(objectMapper); + + builder.addPart(SetBusinessAccountProfilePhoto.BUSINESS_CONNECTION_ID_FIELD, setBusinessAccountProfilePhoto.getBusinessConnectionId()) + .addPart(SetBusinessAccountProfilePhoto.IS_PUBLIC_FIELD, setBusinessAccountProfilePhoto.getIsPublic()); + + if (InputProfilePhotoStatic.TYPE.equals(setBusinessAccountProfilePhoto.getPhoto().getType())) { + InputProfilePhotoStatic photo = (InputProfilePhotoStatic) setBusinessAccountProfilePhoto.getPhoto(); + builder.addJsonPart(SetBusinessAccountProfilePhoto.PHOTO_FIELD, photo) + .addInputFile(InputProfilePhotoStatic.PHOTO_FIELD, photo.getPhoto(), false); + } else if (InputProfilePhotoAnimated.TYPE.equals(setBusinessAccountProfilePhoto.getPhoto().getType())) { + InputProfilePhotoAnimated photo = (InputProfilePhotoAnimated) setBusinessAccountProfilePhoto.getPhoto(); + builder.addJsonPart(SetBusinessAccountProfilePhoto.PHOTO_FIELD, photo) + .addInputFile(InputProfilePhotoAnimated.ANIMATION_FIELD, photo.getAnimation(), false); + } + + Request httpPost = new Request.Builder().url(url).post(builder.build()).build(); + return sendRequest(setBusinessAccountProfilePhoto, httpPost); + } catch (TelegramApiException e) { + return CompletableFuture.failedFuture(e); + } catch (IOException e) { + return CompletableFuture.failedFuture(new TelegramApiException("Unable to execute " + setBusinessAccountProfilePhoto.getMethod(), e)); + } + } + @Override public CompletableFuture executeAsync(SendDocument sendDocument) { return executeMediaMethod(sendDocument, builder -> { diff --git a/telegrambots-client/src/test/java/org/telegram/telegrambots/client/TestTelegramClientIntegration.java b/telegrambots-client/src/test/java/org/telegram/telegrambots/client/TestTelegramClientIntegration.java index 031d1bba7..3330cffa2 100644 --- a/telegrambots-client/src/test/java/org/telegram/telegrambots/client/TestTelegramClientIntegration.java +++ b/telegrambots-client/src/test/java/org/telegram/telegrambots/client/TestTelegramClientIntegration.java @@ -14,6 +14,7 @@ import org.telegram.telegrambots.client.okhttp.OkHttpTelegramClient; import org.telegram.telegrambots.meta.TelegramUrl; import org.telegram.telegrambots.meta.api.methods.botapimethods.PartialBotApiMethod; +import org.telegram.telegrambots.meta.api.methods.business.SetBusinessAccountProfilePhoto; import org.telegram.telegrambots.meta.api.methods.commands.GetMyCommands; import org.telegram.telegrambots.meta.api.methods.description.GetMyDescription; import org.telegram.telegrambots.meta.api.methods.description.GetMyShortDescription; @@ -36,15 +37,16 @@ import org.telegram.telegrambots.meta.api.objects.description.BotShortDescription; import org.telegram.telegrambots.meta.api.objects.message.Message; import org.telegram.telegrambots.meta.api.objects.name.BotName; +import org.telegram.telegrambots.meta.api.objects.photo.input.InputProfilePhotoStatic; import org.telegram.telegrambots.meta.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; import java.io.File; import java.io.Serializable; import java.util.ArrayList; -import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; class TestTelegramClientIntegration { private MockWebServer webServer; @@ -349,6 +351,43 @@ void testSendAnimationException() { assertEquals(404, exception.getErrorCode()); } + @Test + void testSetBusinessAccountProfilePhoto() throws TelegramApiException { + InputFile inputFile = new InputFile(getTestFile()); + InputProfilePhotoStatic profilePhoto = InputProfilePhotoStatic.builder() + .photo(inputFile) + .build(); + + SetBusinessAccountProfilePhoto method = SetBusinessAccountProfilePhoto.builder() + .businessConnectionId("test-connection-id") + .photo(profilePhoto) + .isPublic(true) + .build(); + + mockMethod(method, Boolean.TRUE); + + assertTrue(client.execute(method)); + } + + @Test + void testSetBusinessAccountProfilePhotoException() { + InputFile inputFile = new InputFile(getTestFile()); + InputProfilePhotoStatic profilePhoto = InputProfilePhotoStatic.builder() + .photo(inputFile) + .build(); + + SetBusinessAccountProfilePhoto method = SetBusinessAccountProfilePhoto.builder() + .businessConnectionId("test-connection-id") + .photo(profilePhoto) + .isPublic(true) + .build(); + + mockErrorMethod(method); + + TelegramApiRequestException exception = Assertions.assertThrows(TelegramApiRequestException.class, () -> client.execute(method)); + assertEquals(404, exception.getErrorCode()); + } + @NotNull private File getTestFile() { ClassLoader classLoader = getClass().getClassLoader(); diff --git a/telegrambots-client/src/test/java/org/telegram/telegrambots/client/TestTelegramMultipartBuilder.java b/telegrambots-client/src/test/java/org/telegram/telegrambots/client/TestTelegramMultipartBuilder.java index a40572f93..b7ccaac92 100644 --- a/telegrambots-client/src/test/java/org/telegram/telegrambots/client/TestTelegramMultipartBuilder.java +++ b/telegrambots-client/src/test/java/org/telegram/telegrambots/client/TestTelegramMultipartBuilder.java @@ -5,7 +5,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.telegram.telegrambots.meta.api.objects.InputFile; -import org.telegram.telegrambots.meta.api.objects.Location; +import org.telegram.telegrambots.meta.api.objects.location.Location; import org.telegram.telegrambots.meta.api.objects.media.InputMediaDocument; import org.telegram.telegrambots.meta.api.objects.stickers.InputSticker; diff --git a/telegrambots-extensions/README.md b/telegrambots-extensions/README.md index c417c7b86..c0669ad7d 100644 --- a/telegrambots-extensions/README.md +++ b/telegrambots-extensions/README.md @@ -16,12 +16,12 @@ Just import add the library to your project with one of these options: org.telegram telegrambots-extensions - 8.3.0 + 9.0.0 ``` 2. Using Gradle: ```gradle - implementation 'org.telegram:telegrambots-extensions:8.3.0' + implementation 'org.telegram:telegrambots-extensions:9.0.0' ``` \ No newline at end of file diff --git a/telegrambots-extensions/pom.xml b/telegrambots-extensions/pom.xml index 9d2e020ec..bc816f693 100644 --- a/telegrambots-extensions/pom.xml +++ b/telegrambots-extensions/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 8.3.0 + 9.0.0 telegrambots-extensions @@ -89,12 +89,12 @@ org.telegram telegrambots-webhook - 8.3.0 + 9.0.0 org.telegram telegrambots-longpolling - 8.3.0 + 9.0.0 diff --git a/telegrambots-longpolling/pom.xml b/telegrambots-longpolling/pom.xml index 8c01250ea..f2b586194 100644 --- a/telegrambots-longpolling/pom.xml +++ b/telegrambots-longpolling/pom.xml @@ -6,7 +6,7 @@ org.telegram Bots - 8.3.0 + 9.0.0 telegrambots-longpolling diff --git a/telegrambots-meta/pom.xml b/telegrambots-meta/pom.xml index 4e95adc50..fcc5430f8 100644 --- a/telegrambots-meta/pom.xml +++ b/telegrambots-meta/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 8.3.0 + 9.0.0 telegrambots-meta diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/DeleteBusinessMessages.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/DeleteBusinessMessages.java new file mode 100644 index 000000000..6494060eb --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/DeleteBusinessMessages.java @@ -0,0 +1,76 @@ +package org.telegram.telegrambots.meta.api.methods.business; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.Setter; +import lombok.ToString; +import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +import java.util.List; + +/** + * @author Ruben Bermudez + * @version 9.0 + * + * Delete messages on behalf of a business account. + * Returns True on success. + * + * @apiNote Requires the can_delete_outgoing_messages business bot right to delete messages sent by the bot itself, + * or the can_delete_all_messages business bot right to delete any message. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class DeleteBusinessMessages extends BotApiMethodBoolean { + public static final String PATH = "deleteBusinessMessages"; + + private static final String BUSINESS_CONNECTION_ID_FIELD = "business_connection_id"; + private static final String MESSAGE_IDS_FIELD = "message_ids"; + + /** + * Unique identifier of the business connection on behalf of which to delete the messages + */ + @JsonProperty(BUSINESS_CONNECTION_ID_FIELD) + @NonNull + private String businessConnectionId; + /** + * A JSON-serialized list of 1-100 identifiers of messages to delete. + * All messages must be from the same chat. + */ + @JsonProperty(MESSAGE_IDS_FIELD) + @NonNull + private List messageIds; + + @Override + public String getMethod() { + return PATH; + } + + @Override + public void validate() throws TelegramApiValidationException { + if (businessConnectionId.isEmpty()) { + throw new TelegramApiValidationException("BusinessConnectionId parameter can't be empty string", this); + } + if (messageIds.isEmpty()) { + throw new TelegramApiValidationException("MessageIds parameter can't be empty", this); + } + if (messageIds.size() > 100) { + throw new TelegramApiValidationException("MessageIds parameter can't exceed 100 elements", this); + } + for (Integer messageId : messageIds) { + if (messageId == null) { + throw new TelegramApiValidationException("MessageIds parameter can't contain null elements", this); + } + } + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/GetBusinessAccountGifts.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/GetBusinessAccountGifts.java new file mode 100644 index 000000000..429eee81d --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/GetBusinessAccountGifts.java @@ -0,0 +1,123 @@ +package org.telegram.telegrambots.meta.api.methods.business; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.Setter; +import lombok.ToString; +import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethod; +import org.telegram.telegrambots.meta.api.objects.gifts.owned.OwnedGifts; +import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * @author Ruben Bermudez + * @version 9.0 + * + * Returns the gifts received and owned by a managed business account. + * Requires the can_view_gifts_and_stars business bot right. + * Returns OwnedGifts on success. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +@Builder +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class GetBusinessAccountGifts extends BotApiMethod { + public static final String PATH = "getBusinessAccountGifts"; + + private static final String BUSINESS_CONNECTION_ID_FIELD = "business_connection_id"; + private static final String EXCLUDE_UNSAVED_FIELD = "exclude_unsaved"; + private static final String EXCLUDE_SAVED_FIELD = "exclude_saved"; + private static final String EXCLUDE_UNLIMITED_FIELD = "exclude_unlimited"; + private static final String EXCLUDE_LIMITED_FIELD = "exclude_limited"; + private static final String EXCLUDE_UNIQUE_FIELD = "exclude_unique"; + private static final String SORT_BY_PRICE_FIELD = "sort_by_price"; + private static final String OFFSET_FIELD = "offset"; + private static final String LIMIT_FIELD = "limit"; + + /** + * Unique identifier of the business connection + */ + @JsonProperty(BUSINESS_CONNECTION_ID_FIELD) + @NonNull + private String businessConnectionId; + + /** + * Optional. Pass True to exclude gifts that aren't saved to the account's profile page + */ + @JsonProperty(EXCLUDE_UNSAVED_FIELD) + private Boolean excludeUnsaved; + + /** + * Optional. Pass True to exclude gifts that are saved to the account's profile page + */ + @JsonProperty(EXCLUDE_SAVED_FIELD) + private Boolean excludeSaved; + + /** + * Optional. Pass True to exclude gifts that can be purchased an unlimited number of times + */ + @JsonProperty(EXCLUDE_UNLIMITED_FIELD) + private Boolean excludeUnlimited; + + /** + * Optional. Pass True to exclude gifts that can be purchased a limited number of times + */ + @JsonProperty(EXCLUDE_LIMITED_FIELD) + private Boolean excludeLimited; + + /** + * Optional. Pass True to exclude unique gifts + */ + @JsonProperty(EXCLUDE_UNIQUE_FIELD) + private Boolean excludeUnique; + + /** + * Optional. Pass True to sort results by gift price instead of send date. Sorting is applied before pagination. + */ + @JsonProperty(SORT_BY_PRICE_FIELD) + private Boolean sortByPrice; + + /** + * Optional. Offset of the first entry to return as received from the previous request; use empty string to get the first chunk of results + */ + @JsonProperty(OFFSET_FIELD) + private String offset; + + /** + * Optional. The maximum number of gifts to be returned; 1-100. Defaults to 100 + */ + @JsonProperty(LIMIT_FIELD) + private Integer limit; + + @Override + public String getMethod() { + return PATH; + } + + @Override + public OwnedGifts deserializeResponse(String answer) throws TelegramApiRequestException { + return deserializeResponse(answer, OwnedGifts.class); + } + + @Override + public void validate() throws TelegramApiValidationException { + if (businessConnectionId.isEmpty()) { + throw new TelegramApiValidationException("BusinessConnectionId parameter can't be empty", this); + } + if (limit != null && (limit < 1 || limit > 100)) { + throw new TelegramApiValidationException("Limit parameter must be between 1 and 100", this); + } + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/GetBusinessAccountStarBalance.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/GetBusinessAccountStarBalance.java new file mode 100644 index 000000000..bc2cb4191 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/GetBusinessAccountStarBalance.java @@ -0,0 +1,60 @@ +package org.telegram.telegrambots.meta.api.methods.business; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.Setter; +import lombok.ToString; +import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethod; +import org.telegram.telegrambots.meta.api.objects.payments.star.StarAmount; +import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * @author Ruben Bermudez + * @version 9.0 + * + * Returns the amount of Telegram Stars owned by a managed business account. + * Requires the can_view_gifts_and_stars business bot right. + * Returns StarAmount on success. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class GetBusinessAccountStarBalance extends BotApiMethod { + public static final String PATH = "getBusinessAccountStarBalance"; + + private static final String BUSINESS_CONNECTION_ID_FIELD = "business_connection_id"; + + /** + * Unique identifier of the business connection + */ + @JsonProperty(BUSINESS_CONNECTION_ID_FIELD) + @NonNull + private String businessConnectionId; + + @Override + public String getMethod() { + return PATH; + } + + @Override + public StarAmount deserializeResponse(String answer) throws TelegramApiRequestException { + return deserializeResponse(answer, StarAmount.class); + } + + @Override + public void validate() throws TelegramApiValidationException { + if (businessConnectionId.isEmpty()) { + throw new TelegramApiValidationException("BusinessConnectionId parameter can't be empty", this); + } + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/ReadBusinessMessage.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/ReadBusinessMessage.java new file mode 100644 index 000000000..c70c368f7 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/ReadBusinessMessage.java @@ -0,0 +1,69 @@ +package org.telegram.telegrambots.meta.api.methods.business; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.Setter; +import lombok.ToString; +import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * @author Ruben Bermudez + * @version 9.0 + * + * Marks incoming message as read on behalf of a business account. + * Returns True on success. + * + * @apiNote Requires the can_read_messages business bot right. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class ReadBusinessMessage extends BotApiMethodBoolean { + public static final String PATH = "readBusinessMessage"; + + private static final String BUSINESS_CONNECTION_ID_FIELD = "business_connection_id"; + private static final String CHAT_ID_FIELD = "chat_id"; + private static final String MESSAGE_ID_FIELD = "message_id"; + + /** + * Unique identifier of the business connection on behalf of which to read the message + */ + @JsonProperty(BUSINESS_CONNECTION_ID_FIELD) + @NonNull + private String businessConnectionId; + /** + * Unique identifier of the chat in which the message was received. + * The chat must have been active in the last 24 hours. + */ + @JsonProperty(CHAT_ID_FIELD) + @NonNull + private Long chatId; + /** + *Unique identifier of the message to mark as read + */ + @JsonProperty(MESSAGE_ID_FIELD) + @NonNull + private Long messageId; + + @Override + public String getMethod() { + return PATH; + } + + @Override + public void validate() throws TelegramApiValidationException { + if (businessConnectionId.isEmpty()) { + throw new TelegramApiValidationException("BusinessConnectionId parameter can't be empty string", this); + } + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/RemoveBusinessAccountProfilePhoto.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/RemoveBusinessAccountProfilePhoto.java new file mode 100644 index 000000000..69dde3358 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/RemoveBusinessAccountProfilePhoto.java @@ -0,0 +1,65 @@ +package org.telegram.telegrambots.meta.api.methods.business; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * @author Ruben Bermudez + * @version 9.0 + * Removes the current profile photo of a managed business account. + * Returns True on success. + * + * @apiNote Requires the can_edit_profile_photo business bot right. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@RequiredArgsConstructor +@AllArgsConstructor +@Builder +public class RemoveBusinessAccountProfilePhoto extends BotApiMethodBoolean { + public static final String PATH = "removeBusinessAccountProfilePhoto"; + + private static final String BUSINESS_CONNECTION_ID_FIELD = "business_connection_id"; + private static final String IS_PUBLIC_FIELD = "is_public"; + + /** + * Unique identifier of the business connection + */ + @JsonProperty(BUSINESS_CONNECTION_ID_FIELD) + @NonNull + private String businessConnectionId; + /** + * Optional. + * Pass True to remove the public photo, which is visible even if the main photo is hidden + * by the business account's privacy settings. + * + * @apiNote After the main photo is removed, the previous profile photo (if present) becomes the main photo. + */ + @JsonProperty(IS_PUBLIC_FIELD) + private Boolean isPublic; + + @Override + public String getMethod() { + return PATH; + } + + @Override + public void validate() throws TelegramApiValidationException { + if (businessConnectionId.isEmpty()) { + throw new TelegramApiValidationException("BusinessConnectionId parameter can't be empty string", this); + } + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/SetBusinessAccountBio.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/SetBusinessAccountBio.java new file mode 100644 index 000000000..87c4cfc87 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/SetBusinessAccountBio.java @@ -0,0 +1,64 @@ +package org.telegram.telegrambots.meta.api.methods.business; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * @author Ruben Bermudez + * @version 9.0 + * Changes the bio of a managed business account. + * Returns True on success. + * + * @apiNote Requires the can_change_bio business bot right. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@RequiredArgsConstructor +@AllArgsConstructor +@Builder +public class SetBusinessAccountBio extends BotApiMethodBoolean { + public static final String PATH = "setBusinessAccountBio"; + + private static final String BUSINESS_CONNECTION_ID_FIELD = "business_connection_id"; + private static final String BIO_FIELD = "bio"; + + /** + * Unique identifier of the business connection + */ + @JsonProperty(BUSINESS_CONNECTION_ID_FIELD) + @NonNull + private String businessConnectionId; + /** + * The new value of the bio for the business account; 0-140 characters + */ + @JsonProperty(BIO_FIELD) + private String bio; + + @Override + public String getMethod() { + return PATH; + } + + @Override + public void validate() throws TelegramApiValidationException { + if (businessConnectionId.isEmpty()) { + throw new TelegramApiValidationException("BusinessConnectionId parameter can't be empty string", this); + } + if (bio != null && bio.length() > 140) { + throw new TelegramApiValidationException("Bio parameter can't exceed 140 characters", this); + } + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/SetBusinessAccountGiftSettings.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/SetBusinessAccountGiftSettings.java new file mode 100644 index 000000000..8cd492fe7 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/SetBusinessAccountGiftSettings.java @@ -0,0 +1,69 @@ +package org.telegram.telegrambots.meta.api.methods.business; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.Setter; +import lombok.ToString; +import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean; +import org.telegram.telegrambots.meta.api.objects.gifts.AcceptedGiftTypes; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * @author Ruben Bermudez + * @version 9.0 + * Changes the privacy settings pertaining to incoming gifts in a managed business account. + * Returns True on success. + * + * @apiNote Requires the can_change_gift_settings business bot right. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class SetBusinessAccountGiftSettings extends BotApiMethodBoolean { + public static final String PATH = "setBusinessAccountGiftSettings"; + + private static final String BUSINESS_CONNECTION_ID_FIELD = "business_connection_id"; + private static final String SHOW_GIFT_BUTTON_FIELD = "show_gift_button"; + private static final String ACCEPTED_GIFT_TYPES_FIELD = "accepted_gift_types"; + + /** + * Unique identifier of the business connection + */ + @JsonProperty(BUSINESS_CONNECTION_ID_FIELD) + @NonNull + private String businessConnectionId; + /** + * Pass True, if a button for sending a gift to the user or by the business account + * must always be shown in the input field + */ + @JsonProperty(SHOW_GIFT_BUTTON_FIELD) + @NonNull + private Boolean showGiftButton; + /** + * Types of gifts accepted by the business account + */ + @JsonProperty(ACCEPTED_GIFT_TYPES_FIELD) + @NonNull + private AcceptedGiftTypes acceptedGiftTypes; + + @Override + public String getMethod() { + return PATH; + } + + @Override + public void validate() throws TelegramApiValidationException { + if (businessConnectionId.isEmpty()) { + throw new TelegramApiValidationException("BusinessConnectionId parameter can't be empty string", this); + } + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/SetBusinessAccountName.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/SetBusinessAccountName.java new file mode 100644 index 000000000..4dc495b76 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/SetBusinessAccountName.java @@ -0,0 +1,77 @@ +package org.telegram.telegrambots.meta.api.methods.business; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * @author Ruben Bermudez + * @version 9.0 + * Changes the first and last name of a managed business account. + * Returns True on success. + * + * @apiNote Requires the can_change_name business bot right. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@RequiredArgsConstructor +@AllArgsConstructor +@Builder +public class SetBusinessAccountName extends BotApiMethodBoolean { + public static final String PATH = "setBusinessAccountName"; + + private static final String BUSINESS_CONNECTION_ID_FIELD = "business_connection_id"; + private static final String FIRST_NAME_FIELD = "first_name"; + private static final String LAST_NAME_FIELD = "last_name"; + + /** + * Unique identifier of the business connection + */ + @JsonProperty(BUSINESS_CONNECTION_ID_FIELD) + @NonNull + private String businessConnectionId; + /** + * The new value of the first name for the business account; 1-64 characters + */ + @JsonProperty(FIRST_NAME_FIELD) + @NonNull + private String firstName; + /** + * The new value of the last name for the business account; 0-64 characters + */ + @JsonProperty(LAST_NAME_FIELD) + private String lastName; + + @Override + public String getMethod() { + return PATH; + } + + @Override + public void validate() throws TelegramApiValidationException { + if (businessConnectionId.isEmpty()) { + throw new TelegramApiValidationException("BusinessConnectionId parameter can't be empty string", this); + } + if (firstName.isEmpty()) { + throw new TelegramApiValidationException("FirstName parameter can't be empty string", this); + } + if (firstName.length() > 64) { + throw new TelegramApiValidationException("FirstName parameter can't exceed 64 characters", this); + } + if (lastName != null && lastName.length() > 64) { + throw new TelegramApiValidationException("LastName parameter can't exceed 64 characters", this); + } + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/SetBusinessAccountProfilePhoto.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/SetBusinessAccountProfilePhoto.java new file mode 100644 index 000000000..193d5b8ce --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/SetBusinessAccountProfilePhoto.java @@ -0,0 +1,80 @@ +package org.telegram.telegrambots.meta.api.methods.business; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.telegram.telegrambots.meta.api.methods.botapimethods.PartialBotApiMethod; +import org.telegram.telegrambots.meta.api.objects.photo.input.InputProfilePhoto; +import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * @author Ruben Bermudez + * @version 9.0 + * Changes the profile photo of a managed business account. + * Returns True on success. + * + * @apiNote Requires the can_edit_profile_photo business bot right. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@RequiredArgsConstructor +@AllArgsConstructor +@Builder +public class SetBusinessAccountProfilePhoto extends PartialBotApiMethod { + public static final String PATH = "setBusinessAccountProfilePhoto"; + + public static final String BUSINESS_CONNECTION_ID_FIELD = "business_connection_id"; + public static final String PHOTO_FIELD = "photo"; + public static final String IS_PUBLIC_FIELD = "is_public"; + + /** + * Unique identifier of the business connection + */ + @JsonProperty(BUSINESS_CONNECTION_ID_FIELD) + @NonNull + private String businessConnectionId; + /** + * The new profile photo to set + */ + @JsonProperty(PHOTO_FIELD) + @NonNull + private InputProfilePhoto photo; + /** + * Optional. + * Pass True to set the public photo, which will be visible even if the main photo is hidden + * by the business account's privacy settings. + * + * @apiNote An account can have only one public photo. + */ + @JsonProperty(IS_PUBLIC_FIELD) + private Boolean isPublic; + + @Override + public Boolean deserializeResponse(String answer) throws TelegramApiRequestException { + return deserializeResponse(answer, Boolean.class); + } + + @Override + public String getMethod() { + return PATH; + } + + @Override + public void validate() throws TelegramApiValidationException { + if (businessConnectionId.isEmpty()) { + throw new TelegramApiValidationException("BusinessConnectionId parameter can't be empty string", this); + } + photo.validate(); + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/SetBusinessAccountUsername.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/SetBusinessAccountUsername.java new file mode 100644 index 000000000..c5c3c7b31 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/SetBusinessAccountUsername.java @@ -0,0 +1,63 @@ +package org.telegram.telegrambots.meta.api.methods.business; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.Setter; +import lombok.ToString; +import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * @author Ruben Bermudez + * @version 9.0 + * Changes the username of a managed business account. + * Returns True on success. + * + * @apiNote Requires the can_change_username business bot right. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class SetBusinessAccountUsername extends BotApiMethodBoolean { + public static final String PATH = "setBusinessAccountUsername"; + + private static final String BUSINESS_CONNECTION_ID_FIELD = "business_connection_id"; + private static final String USERNAME_FIELD = "username"; + + /** + * Unique identifier of the business connection + */ + @JsonProperty(BUSINESS_CONNECTION_ID_FIELD) + @NonNull + private String businessConnectionId; + /** + * The new value of the username for the business account; 0-32 characters + */ + @JsonProperty(USERNAME_FIELD) + @NonNull + private String username; + + @Override + public String getMethod() { + return PATH; + } + + @Override + public void validate() throws TelegramApiValidationException { + if (businessConnectionId.isEmpty()) { + throw new TelegramApiValidationException("BusinessConnectionId parameter can't be empty string", this); + } + if (!username.isEmpty() && username.length() > 32) { + throw new TelegramApiValidationException("Username parameter can't exceed 32 characters", this); + } + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/TransferBusinessAccountStars.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/TransferBusinessAccountStars.java new file mode 100644 index 000000000..68e39402d --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/business/TransferBusinessAccountStars.java @@ -0,0 +1,66 @@ +package org.telegram.telegrambots.meta.api.methods.business; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.Setter; +import lombok.ToString; +import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * @author Ruben Bermudez + * @version 9.0 + * + * Transfers Telegram Stars from the business account balance to the bot's balance. + * Returns True on success. + * + * @apiNote Requires the can_transfer_stars business bot right. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class TransferBusinessAccountStars extends BotApiMethodBoolean { + public static final String PATH = "transferBusinessAccountStars"; + + private static final String BUSINESS_CONNECTION_ID_FIELD = "business_connection_id"; + private static final String STAR_COUNT_FIELD = "star_count"; + + /** + * Unique identifier of the business connection + */ + @JsonProperty(BUSINESS_CONNECTION_ID_FIELD) + @NonNull + private String businessConnectionId; + + /** + * Number of Telegram Stars to transfer; 1-10000 + */ + @JsonProperty(STAR_COUNT_FIELD) + @NonNull + private Integer starCount; + + @Override + public String getMethod() { + return PATH; + } + + @Override + public void validate() throws TelegramApiValidationException { + if (businessConnectionId.isEmpty()) { + throw new TelegramApiValidationException("BusinessConnectionId parameter can't be empty", this); + } + + if (starCount < 1 || starCount > 10000) { + throw new TelegramApiValidationException("StarCount must be between 1 and 10000", this); + } + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/gifts/ConvertGiftToStars.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/gifts/ConvertGiftToStars.java new file mode 100644 index 000000000..3b788d5fd --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/gifts/ConvertGiftToStars.java @@ -0,0 +1,68 @@ +package org.telegram.telegrambots.meta.api.methods.gifts; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NonNull; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; +import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * @author Ruben Bermudez + * @version 9.0 + * + * Converts a given regular gift to Telegram Stars. + * Requires the can_convert_gifts_to_stars business bot right. + * Returns True on success. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@AllArgsConstructor +@SuperBuilder +@Jacksonized +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ConvertGiftToStars extends BotApiMethodBoolean { + public static final String PATH = "convertGiftToStars"; + + private static final String BUSINESS_CONNECTION_ID_FIELD = "business_connection_id"; + private static final String OWNED_GIFT_ID_FIELD = "owned_gift_id"; + + /** + * Unique identifier of the business connection + */ + @JsonProperty(BUSINESS_CONNECTION_ID_FIELD) + @NonNull + private String businessConnectionId; + + /** + * Unique identifier of the regular gift that should be converted to Telegram Stars + */ + @JsonProperty(OWNED_GIFT_ID_FIELD) + @NonNull + private String ownedGiftId; + + @Override + public void validate() throws TelegramApiValidationException { + if (businessConnectionId.isEmpty()) { + throw new TelegramApiValidationException("BusinessConnectionId can't be empty", this); + } + if (ownedGiftId.isEmpty()) { + throw new TelegramApiValidationException("OwnedGiftId can't be empty", this); + } + } + + @Override + public String getMethod() { + return PATH; + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/gifts/GiftPremiumSubscription.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/gifts/GiftPremiumSubscription.java new file mode 100644 index 000000000..0066d3c5b --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/gifts/GiftPremiumSubscription.java @@ -0,0 +1,104 @@ +package org.telegram.telegrambots.meta.api.methods.gifts; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.Singular; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; +import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean; +import org.telegram.telegrambots.meta.api.objects.MessageEntity; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; +import org.telegram.telegrambots.meta.util.Validations; + +import java.util.List; + +/** + * @author Ruben Bermudez + * @version 9.0 + * + * Gifts a Telegram Premium subscription to the given user. + * Returns True on success. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@RequiredArgsConstructor +@AllArgsConstructor +@SuperBuilder +@Jacksonized +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class GiftPremiumSubscription extends BotApiMethodBoolean { + public static final String PATH = "giftPremiumSubscription"; + + private static final String USER_ID_FIELD = "user_id"; + private static final String MONTH_COUNT_FIELD = "month_count"; + private static final String STAR_COUNT_FIELD = "star_count"; + private static final String TEXT_FIELD = "text"; + private static final String TEXT_PARSE_MODE_FIELD = "text_parse_mode"; + private static final String TEXT_ENTITIES_FIELD = "text_entities"; + + /** + * Unique identifier of the target user who will receive a Telegram Premium subscription + */ + @JsonProperty(USER_ID_FIELD) + @NonNull + private Long userId; + /** + * Number of months the Telegram Premium subscription will be active for the user; must be one of 3, 6, or 12 + */ + @JsonProperty(MONTH_COUNT_FIELD) + @NonNull + private Integer monthCount; + /** + * Number of Telegram Stars to pay for the Telegram Premium subscription; must be 1000 for 3 months, 1500 for 6 months, and 2500 for 12 months + */ + @JsonProperty(STAR_COUNT_FIELD) + @NonNull + private Integer starCount; + /** + * Optional + * Text that will be shown along with the service message about the subscription; 0-128 characters + */ + @JsonProperty(TEXT_FIELD) + private String text; + /** + * Optional + * Mode for parsing entities in the text. See formatting options for more details. + * + * @apiNote Entities other than “bold”, “italic”, “underline”, “strikethrough”, “spoiler”, and “custom_emoji” are ignored. + */ + @JsonProperty(TEXT_PARSE_MODE_FIELD) + private String textParseMode; + /** + * Optional + * A JSON-serialized list of special entities that appear in the gift text. + * It can be specified instead of text_parse_mode. + * @apiNote Entities other than “bold”, “italic”, “underline”, “strikethrough”, “spoiler”, and “custom_emoji” are ignored. + */ + @JsonProperty(TEXT_ENTITIES_FIELD) + @Singular + private List textEntities; + + @Override + public void validate() throws TelegramApiValidationException { + Validations.requiredUserId(userId, this); + if (text != null && (text.isEmpty() || text.length() > 128)) { + throw new TelegramApiValidationException("Text must be between 0 and 128 characters", this); + } + } + + @Override + public String getMethod() { + return PATH; + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/gifts/TransferGift.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/gifts/TransferGift.java new file mode 100644 index 000000000..d54d8c5e4 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/gifts/TransferGift.java @@ -0,0 +1,89 @@ +package org.telegram.telegrambots.meta.api.methods.gifts; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; +import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * @author Ruben Bermudez + * @version 9.0 + * + * Transfers an owned unique gift to another user. + * Requires the can_transfer_and_upgrade_gifts business bot right. + * Requires can_transfer_stars business bot right if the transfer is paid. + * Returns True on success. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@RequiredArgsConstructor +@AllArgsConstructor +@SuperBuilder +@Jacksonized +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class TransferGift extends BotApiMethodBoolean { + public static final String PATH = "transferGift"; + + private static final String BUSINESS_CONNECTION_ID_FIELD = "business_connection_id"; + private static final String OWNED_GIFT_ID_FIELD = "owned_gift_id"; + private static final String NEW_OWNER_CHAT_ID_FIELD = "new_owner_chat_id"; + private static final String STAR_COUNT_FIELD = "star_count"; + + /** + * Unique identifier of the business connection + */ + @JsonProperty(BUSINESS_CONNECTION_ID_FIELD) + @NonNull + private String businessConnectionId; + + /** + * Unique identifier of the regular gift that should be transferred + */ + @JsonProperty(OWNED_GIFT_ID_FIELD) + @NonNull + private String ownedGiftId; + + /** + * Unique identifier of the chat which will own the gift. + * The chat must be active in the last 24 hours. + */ + @JsonProperty(NEW_OWNER_CHAT_ID_FIELD) + @NonNull + private Long newOwnerChatId; + + /** + * Optional. + * The amount of Telegram Stars that will be paid for the transfer from the business account balance. + * If positive, then the can_transfer_stars business bot right is required. + */ + @JsonProperty(STAR_COUNT_FIELD) + private Integer starCount; + + @Override + public void validate() throws TelegramApiValidationException { + if (businessConnectionId.isEmpty()) { + throw new TelegramApiValidationException("BusinessConnectionId can't be empty", this); + } + if (ownedGiftId.isEmpty()) { + throw new TelegramApiValidationException("OwnedGiftId can't be empty", this); + } + } + + @Override + public String getMethod() { + return PATH; + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/gifts/UpgradeGift.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/gifts/UpgradeGift.java new file mode 100644 index 000000000..893b90b01 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/gifts/UpgradeGift.java @@ -0,0 +1,89 @@ +package org.telegram.telegrambots.meta.api.methods.gifts; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; +import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * @author Ruben Bermudez + * @version 9.0 + * + * Upgrades a given regular gift to a unique gift. + * Requires the can_transfer_and_upgrade_gifts business bot right. + * Additionally requires the can_transfer_stars business bot right if the upgrade is paid. + * Returns True on success. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@RequiredArgsConstructor +@AllArgsConstructor +@SuperBuilder +@Jacksonized +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class UpgradeGift extends BotApiMethodBoolean { + public static final String PATH = "upgradeGift"; + + private static final String BUSINESS_CONNECTION_ID_FIELD = "business_connection_id"; + private static final String OWNED_GIFT_ID_FIELD = "owned_gift_id"; + private static final String KEEP_ORIGINAL_DETAILS_FIELD = "keep_original_details"; + private static final String STAR_COUNT_FIELD = "star_count"; + + /** + * Unique identifier of the business connection + */ + @JsonProperty(BUSINESS_CONNECTION_ID_FIELD) + @NonNull + private String businessConnectionId; + + /** + * Unique identifier of the regular gift that should be upgraded to a unique one + */ + @JsonProperty(OWNED_GIFT_ID_FIELD) + @NonNull + private String ownedGiftId; + + /** + * Optional. + * Pass True to keep the original gift text, sender and receiver in the upgraded gift + */ + @JsonProperty(KEEP_ORIGINAL_DETAILS_FIELD) + private Boolean keepOriginalDetails; + + /** + * Optional. + * The amount of Telegram Stars that will be paid for the upgrade from the business account balance. + * If gift.prepaid_upgrade_star_count > 0, then pass 0, otherwise, the can_transfer_stars business bot right is required + * and gift.upgrade_star_count must be passed. + */ + @JsonProperty(STAR_COUNT_FIELD) + private Integer starCount; + + @Override + public void validate() throws TelegramApiValidationException { + if (businessConnectionId.isEmpty()) { + throw new TelegramApiValidationException("BusinessConnectionId can't be empty", this); + } + if (ownedGiftId.isEmpty()) { + throw new TelegramApiValidationException("OwnedGiftId can't be empty", this); + } + } + + @Override + public String getMethod() { + return PATH; + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stories/DeleteStory.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stories/DeleteStory.java new file mode 100644 index 000000000..410208bda --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stories/DeleteStory.java @@ -0,0 +1,62 @@ +package org.telegram.telegrambots.meta.api.methods.stories; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.Setter; +import lombok.ToString; +import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * @author Ruben Bermudez + * @version 9.0 + * + * Deletes a story previously posted by the bot on behalf of a managed business account. + * Returns True on success. + * + * @apiNote Requires the can_manage_stories business bot right. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class DeleteStory extends BotApiMethodBoolean { + public static final String PATH = "deleteStory"; + + private static final String BUSINESS_CONNECTION_ID_FIELD = "business_connection_id"; + private static final String STORY_ID_FIELD = "story_id"; + + /** + * Unique identifier of the business connection + */ + @JsonProperty(BUSINESS_CONNECTION_ID_FIELD) + @NonNull + private String businessConnectionId; + + /** + * Unique identifier of the story to delete + */ + @JsonProperty(STORY_ID_FIELD) + @NonNull + private Integer storyId; + + @Override + public String getMethod() { + return PATH; + } + + @Override + public void validate() throws TelegramApiValidationException { + if (businessConnectionId.isEmpty()) { + throw new TelegramApiValidationException("BusinessConnectionId parameter can't be empty", this); + } + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stories/EditStory.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stories/EditStory.java new file mode 100644 index 000000000..95e57471d --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stories/EditStory.java @@ -0,0 +1,124 @@ +package org.telegram.telegrambots.meta.api.methods.stories; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethod; +import org.telegram.telegrambots.meta.api.objects.MessageEntity; +import org.telegram.telegrambots.meta.api.objects.stories.Story; +import org.telegram.telegrambots.meta.api.objects.stories.StoryArea; +import org.telegram.telegrambots.meta.api.objects.stories.input.InputStoryContent; +import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +import java.util.List; + +/** + * @author Ruben Bermudez + * @version 9.0 + * + * Edits a story previously posted by the bot on behalf of a managed business account. + * Requires the can_manage_stories business bot right. + * Returns Story on success. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@RequiredArgsConstructor +@AllArgsConstructor +@Builder +public class EditStory extends BotApiMethod { + public static final String PATH = "editStory"; + + private static final String BUSINESS_CONNECTION_ID_FIELD = "business_connection_id"; + private static final String STORY_ID_FIELD = "story_id"; + private static final String CONTENT_FIELD = "content"; + private static final String CAPTION_FIELD = "caption"; + private static final String PARSE_MODE_FIELD = "parse_mode"; + private static final String CAPTION_ENTITIES_FIELD = "caption_entities"; + private static final String AREAS_FIELD = "areas"; + + /** + * Unique identifier of the business connection + */ + @JsonProperty(BUSINESS_CONNECTION_ID_FIELD) + @NonNull + private String businessConnectionId; + + /** + * Unique identifier of the story to edit + */ + @JsonProperty(STORY_ID_FIELD) + @NonNull + private Integer storyId; + + /** + * Content of the story + */ + @JsonProperty(CONTENT_FIELD) + @NonNull + private InputStoryContent content; + + /** + * Optional. Caption of the story, 0-2048 characters after entities parsing + */ + @JsonProperty(CAPTION_FIELD) + private String caption; + + /** + * Optional. Mode for parsing entities in the story caption. See formatting options for more details. + */ + @JsonProperty(PARSE_MODE_FIELD) + private String parseMode; + + /** + * Optional. A JSON-serialized list of special entities that appear in the caption, + * which can be specified instead of parse_mode + */ + @JsonProperty(CAPTION_ENTITIES_FIELD) + private List captionEntities; + + /** + * Optional. A JSON-serialized list of clickable areas to be shown on the story + */ + @JsonProperty(AREAS_FIELD) + private List areas; + + @Override + public String getMethod() { + return PATH; + } + + @Override + public Story deserializeResponse(String answer) throws TelegramApiRequestException { + return deserializeResponse(answer, Story.class); + } + + @Override + public void validate() throws TelegramApiValidationException { + if (businessConnectionId.isEmpty()) { + throw new TelegramApiValidationException("BusinessConnectionId parameter can't be empty", this); + } + + content.validate(); + + if (caption != null && caption.length() > 2048) { + throw new TelegramApiValidationException("Caption can't be longer than 2048 characters", this); + } + + if (areas != null) { + for (StoryArea area : areas) { + area.validate(); + } + } + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stories/PostStory.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stories/PostStory.java new file mode 100644 index 000000000..3e04813f9 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stories/PostStory.java @@ -0,0 +1,159 @@ +package org.telegram.telegrambots.meta.api.methods.stories; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.Tolerate; +import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethod; +import org.telegram.telegrambots.meta.api.objects.MessageEntity; +import org.telegram.telegrambots.meta.api.objects.stories.Story; +import org.telegram.telegrambots.meta.api.objects.stories.StoryArea; +import org.telegram.telegrambots.meta.api.objects.stories.input.InputStoryContent; +import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +import java.util.List; + +/** + * @author Ruben Bermudez + * @version 9.0 + * + * Posts a story on behalf of a managed business account. + * Requires the can_manage_stories business bot right. + * Returns Story on success. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@RequiredArgsConstructor +@AllArgsConstructor +@Builder +public class PostStory extends BotApiMethod { + public static final String PATH = "postStory"; + + private static final String BUSINESS_CONNECTION_ID_FIELD = "business_connection_id"; + private static final String CONTENT_FIELD = "content"; + private static final String ACTIVE_PERIOD_FIELD = "active_period"; + private static final String CAPTION_FIELD = "caption"; + private static final String PARSE_MODE_FIELD = "parse_mode"; + private static final String CAPTION_ENTITIES_FIELD = "caption_entities"; + private static final String AREAS_FIELD = "areas"; + private static final String POST_TO_CHAT_PAGE_FIELD = "post_to_chat_page"; + private static final String PROTECT_CONTENT_FIELD = "protect_content"; + + /** + * Unique identifier of the business connection + */ + @JsonProperty(BUSINESS_CONNECTION_ID_FIELD) + @NonNull + private String businessConnectionId; + + /** + * Content of the story + */ + @JsonProperty(CONTENT_FIELD) + @NonNull + private InputStoryContent content; + + /** + * Period after which the story is moved to the archive, in seconds; + * must be one of 6 * 3600, 12 * 3600, 86400, or 2 * 86400 + */ + @JsonProperty(ACTIVE_PERIOD_FIELD) + @NonNull + private Integer activePeriod; + + /** + * Optional. Caption of the story, 0-2048 characters after entities parsing + */ + @JsonProperty(CAPTION_FIELD) + private String caption; + + /** + * Optional. Mode for parsing entities in the story caption. See formatting options for more details. + */ + @JsonProperty(PARSE_MODE_FIELD) + private String parseMode; + + /** + * Optional. A JSON-serialized list of special entities that appear in the caption, + * which can be specified instead of parse_mode + */ + @JsonProperty(CAPTION_ENTITIES_FIELD) + private List captionEntities; + + /** + * Optional. A JSON-serialized list of clickable areas to be shown on the story + */ + @JsonProperty(AREAS_FIELD) + private List areas; + + /** + * Optional. Pass True to keep the story accessible after it expires + */ + @JsonProperty(POST_TO_CHAT_PAGE_FIELD) + private Boolean postToChatPage; + + /** + * Optional. Pass True if the content of the story must be protected from forwarding and screenshotting + */ + @JsonProperty(PROTECT_CONTENT_FIELD) + private Boolean protectContent; + + @Tolerate + public void setBusinessConnectionId(Long businessConnectionId) { + this.businessConnectionId = businessConnectionId.toString(); + } + + @Override + public String getMethod() { + return PATH; + } + + @Override + public Story deserializeResponse(String answer) throws TelegramApiRequestException { + return deserializeResponse(answer, Story.class); + } + + @Override + public void validate() throws TelegramApiValidationException { + if (businessConnectionId.isEmpty()) { + throw new TelegramApiValidationException("BusinessConnectionId parameter can't be empty", this); + } + + content.validate(); + + // Check that activePeriod is one of the allowed values + int sixHours = 6 * 3600; + int twelveHours = 12 * 3600; + int oneDay = 86400; + int twoDays = 2 * 86400; + + if (activePeriod != sixHours && activePeriod != twelveHours && + activePeriod != oneDay && activePeriod != twoDays) { + throw new TelegramApiValidationException( + "ActivePeriod must be one of: 6 hours (21600), 12 hours (43200), 24 hours (86400), or 48 hours (172800)", + this + ); + } + + if (caption != null && caption.length() > 2048) { + throw new TelegramApiValidationException("Caption can't be longer than 2048 characters", this); + } + + if (areas != null) { + for (StoryArea area : areas) { + area.validate(); + } + } + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Audio.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Audio.java index a142d5335..c7b36cc9b 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Audio.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Audio.java @@ -12,6 +12,7 @@ import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.objects.photo.PhotoSize; /** * This object represents an audio file diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatLocation.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatLocation.java index f6bf8788c..063b9dbbc 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatLocation.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatLocation.java @@ -12,6 +12,7 @@ import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.objects.location.Location; /** * Represents a location to which a chat is connected. diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatShared.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatShared.java index 82a8438d7..1c32ee2ba 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatShared.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatShared.java @@ -13,6 +13,7 @@ import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.objects.photo.PhotoSize; import java.util.List; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Document.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Document.java index 9f1385972..660015d74 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Document.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Document.java @@ -12,6 +12,7 @@ import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.objects.photo.PhotoSize; /** * This object represents a general file (as opposed to photos and audio files). diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ExternalReplyInfo.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ExternalReplyInfo.java index 634b048a9..29210ac23 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ExternalReplyInfo.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ExternalReplyInfo.java @@ -17,9 +17,11 @@ import org.telegram.telegrambots.meta.api.objects.games.Game; import org.telegram.telegrambots.meta.api.objects.giveaway.Giveaway; import org.telegram.telegrambots.meta.api.objects.giveaway.GiveawayWinners; +import org.telegram.telegrambots.meta.api.objects.location.Location; import org.telegram.telegrambots.meta.api.objects.messageorigin.MessageOrigin; import org.telegram.telegrambots.meta.api.objects.payments.Invoice; import org.telegram.telegrambots.meta.api.objects.payments.paidmedia.PaidMediaInfo; +import org.telegram.telegrambots.meta.api.objects.photo.PhotoSize; import org.telegram.telegrambots.meta.api.objects.polls.Poll; import org.telegram.telegrambots.meta.api.objects.stickers.Sticker; import org.telegram.telegrambots.meta.api.objects.stories.Story; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/InputFile.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/InputFile.java index 14642d24c..5a3071942 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/InputFile.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/InputFile.java @@ -19,6 +19,7 @@ * @author Ruben Bermudez * @version 4.0.0 */ +@Getter @SuppressWarnings({"WeakerAccess", "UnusedReturnValue"}) @JsonSerialize(using = InputFileSerializer.class, as = String.class) @EqualsAndHashCode(callSuper = false) @@ -27,25 +28,21 @@ @AllArgsConstructor public class InputFile implements Validable, BotApiObject { - @Getter private String attachName; /** * Name of the media to upload */ - @Getter @JsonIgnore private String mediaName; /** * New media file */ - @Getter @JsonIgnore private File newMediaFile; /** * New media stream */ - @Getter @JsonIgnore private InputStream newMediaStream; /** @@ -138,10 +135,6 @@ public InputFile setMedia(String attachName) { return this; } - public boolean isNew() { - return isNew; - } - @Override public void validate() throws TelegramApiValidationException { if (isNew) { diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/UserProfilePhotos.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/UserProfilePhotos.java index 8e0c1deb4..e31848cf6 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/UserProfilePhotos.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/UserProfilePhotos.java @@ -1,7 +1,6 @@ package org.telegram.telegrambots.meta.api.objects; import com.fasterxml.jackson.annotation.JsonProperty; - import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -9,6 +8,7 @@ import lombok.Setter; import lombok.ToString; import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.objects.photo.PhotoSize; import java.util.List; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/UserShared.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/UserShared.java index b9d9fd329..3f224d4c8 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/UserShared.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/UserShared.java @@ -13,6 +13,7 @@ import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.objects.photo.PhotoSize; import java.util.List; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Venue.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Venue.java index f1d67f398..969b53b66 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Venue.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Venue.java @@ -12,6 +12,7 @@ import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.objects.location.Location; /** * This object represents a venue. diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Video.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Video.java index 0486cbbad..7a3f7a73b 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Video.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Video.java @@ -12,6 +12,7 @@ import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.objects.photo.PhotoSize; import java.util.List; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/VideoNote.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/VideoNote.java index 38dabbecd..1df1bd48c 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/VideoNote.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/VideoNote.java @@ -12,6 +12,7 @@ import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.objects.photo.PhotoSize; /** * This object represents a video message (available in Telegram apps as of v.4.0). diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/business/BusinessBotRights.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/business/BusinessBotRights.java new file mode 100644 index 000000000..97be5d8ef --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/business/BusinessBotRights.java @@ -0,0 +1,130 @@ +package org.telegram.telegrambots.meta.api.objects.business; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; + +/** + * @author Ruben Bermudez + * @version 9.0 + * + * Represents the rights of a business bot. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +@SuperBuilder +@Jacksonized +@JsonIgnoreProperties(ignoreUnknown = true) +public class BusinessBotRights implements BotApiObject { + private static final String CAN_REPLY_FIELD = "can_reply"; + private static final String CAN_READ_MESSAGES_FIELD = "can_read_messages"; + private static final String CAN_DELETE_OUTGOING_MESSAGES_FIELD = "can_delete_outgoing_messages"; + private static final String CAN_DELETE_ALL_MESSAGES_FIELD = "can_delete_all_messages"; + private static final String CAN_EDIT_NAME_FIELD = "can_edit_name"; + private static final String CAN_EDIT_BIO_FIELD = "can_edit_bio"; + private static final String CAN_EDIT_PROFILE_PHOTO_FIELD = "can_edit_profile_photo"; + private static final String CAN_EDIT_USERNAME_FIELD = "can_edit_username"; + private static final String CAN_CHANGE_GIFT_SETTINGS_FIELD = "can_change_gift_settings"; + private static final String CAN_VIEW_GIFTS_AND_STARS_FIELD = "can_view_gifts_and_stars"; + private static final String CAN_CONVERT_GIFTS_TO_STARS_FIELD = "can_convert_gifts_to_stars"; + private static final String CAN_TRANSFER_AND_UPGRADE_GIFTS_FIELD = "can_transfer_and_upgrade_gifts"; + private static final String CAN_TRANSFER_STARS_FIELD = "can_transfer_stars"; + private static final String CAN_MANAGE_STORIES_FIELD = "can_manage_stories"; + + /** + * Optional. + * True, if the bot can send and edit messages in the private chats that had incoming messages in the last 24 hours + */ + @JsonProperty(CAN_REPLY_FIELD) + private Boolean canReply; + /** + * Optional. + * True, if the bot can mark incoming private messages as read + */ + @JsonProperty(CAN_READ_MESSAGES_FIELD) + private Boolean canReadMessages; + /** + * Optional. + * True, if the bot can delete messages sent by the bot + */ + @JsonProperty(CAN_DELETE_OUTGOING_MESSAGES_FIELD) + private Boolean canDeleteOutgoingMessages; + /** + * Optional. + * True, if the bot can delete all private messages in managed chats + */ + @JsonProperty(CAN_DELETE_ALL_MESSAGES_FIELD) + private Boolean canDeleteAllMessages; + /** + * Optional. + * True, if the bot can edit the first and last name of the business account + */ + @JsonProperty(CAN_EDIT_NAME_FIELD) + private Boolean canEditName; + /** + * Optional. + * True, if the bot can edit the bio of the business account + */ + @JsonProperty(CAN_EDIT_BIO_FIELD) + private Boolean canEditBio; + /** + * Optional. + * True, if the bot can edit the profile photo of the business account + */ + @JsonProperty(CAN_EDIT_PROFILE_PHOTO_FIELD) + private Boolean canEditProfilePhoto; + /** + * Optional. + * True, if the bot can edit the username of the business account + */ + @JsonProperty(CAN_EDIT_USERNAME_FIELD) + private Boolean canEditUsername; + /** + * Optional. + * True, if the bot can change the privacy settings pertaining to gifts for the business account + */ + @JsonProperty(CAN_CHANGE_GIFT_SETTINGS_FIELD) + private Boolean canChangeGiftSettings; + /** + * Optional. + * True, if the bot can view gifts and the amount of Telegram Stars owned by the business account + */ + @JsonProperty(CAN_VIEW_GIFTS_AND_STARS_FIELD) + private Boolean canViewGiftsAndStars; + /** + * Optional. + * True, if the bot can convert regular gifts owned by the business account to Telegram Stars + */ + @JsonProperty(CAN_CONVERT_GIFTS_TO_STARS_FIELD) + private Boolean canConvertGiftsToStars; + /** + * Optional. + * True, if the bot can transfer and upgrade gifts owned by the business account + */ + @JsonProperty(CAN_TRANSFER_AND_UPGRADE_GIFTS_FIELD) + private Boolean canTransferAndUpgradeGifts; + /** + * Optional. + * True, if the bot can transfer Telegram Stars received by the business account to its own account, or use them to upgrade and transfer gifts + */ + @JsonProperty(CAN_TRANSFER_STARS_FIELD) + private Boolean canTransferStars; + /** + * Optional. + * True, if the bot can post, edit and delete stories on behalf of the business account + */ + @JsonProperty(CAN_MANAGE_STORIES_FIELD) + private Boolean canManageStories; +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/business/BusinessConnection.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/business/BusinessConnection.java index 9072cc393..33bd1f9bb 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/business/BusinessConnection.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/business/BusinessConnection.java @@ -5,6 +5,7 @@ import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.NonNull; import lombok.RequiredArgsConstructor; import lombok.Setter; import lombok.ToString; @@ -16,6 +17,7 @@ /** * @author Ruben Bermudez * @version 7.2 + * * Describes the connection of the bot with a business account. */ @EqualsAndHashCode(callSuper = false) @@ -32,18 +34,20 @@ public class BusinessConnection implements BotApiObject { private static final String USER_FIELD = "user"; private static final String USER_CHAT_ID_FIELD = "user_chat_id"; private static final String DATE_FIELD = "date"; - private static final String CAN_REPLY_FIELD = "can_reply"; private static final String IS_ENABLED_FIELD = "is_enabled"; + private static final String RIGHTS_FIELD = "rights"; /** * Unique identifier of the business connection */ @JsonProperty(ID_FIELD) + @NonNull private String id; /** * Business account user that created the business connection */ @JsonProperty(USER_FIELD) + @NonNull private User user; /** * Identifier of a private chat with the user who created the business connection. @@ -51,20 +55,24 @@ public class BusinessConnection implements BotApiObject { * But it has at most 52 significant bits, so a 64-bit integer or double-precision float type are safe for storing this identifier. */ @JsonProperty(USER_CHAT_ID_FIELD) + @NonNull private Long userChatId; /** * Date the connection was established in Unix time */ @JsonProperty(DATE_FIELD) + @NonNull private Integer date; - /** - * True, if the bot can act on behalf of the business account in chats that were active in the last 24 hours - */ - @JsonProperty(CAN_REPLY_FIELD) - private Boolean canReply; /** * True, if the connection is active */ @JsonProperty(IS_ENABLED_FIELD) + @NonNull private Boolean isEnabled; + /** + * Optional. + * Rights of the business bot + */ + @JsonProperty(RIGHTS_FIELD) + private BusinessBotRights rights; } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/business/BusinessLocation.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/business/BusinessLocation.java index 1faf83a0c..13a7dd038 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/business/BusinessLocation.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/business/BusinessLocation.java @@ -12,7 +12,7 @@ import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; -import org.telegram.telegrambots.meta.api.objects.Location; +import org.telegram.telegrambots.meta.api.objects.location.Location; /** * @author Ruben Bermudez diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chat/ChatFullInfo.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chat/ChatFullInfo.java index 5e4f05e3c..27fefecd2 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chat/ChatFullInfo.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chat/ChatFullInfo.java @@ -17,6 +17,7 @@ import org.telegram.telegrambots.meta.api.objects.business.BusinessIntro; import org.telegram.telegrambots.meta.api.objects.business.BusinessLocation; import org.telegram.telegrambots.meta.api.objects.business.BusinessOpeningHours; +import org.telegram.telegrambots.meta.api.objects.gifts.AcceptedGiftTypes; import org.telegram.telegrambots.meta.api.objects.message.Message; import org.telegram.telegrambots.meta.api.objects.reactions.ReactionType; @@ -75,7 +76,7 @@ public class ChatFullInfo extends Chat { private static final String BUSINESS_OPENING_HOURS_FIELD = "business_opening_hours"; private static final String PERSONAL_CHAT_FIELD = "personal_chat"; private static final String CAN_SEND_PAID_MEDIA_FIELD = "can_send_paid_media"; - private static final String CAN_SEND_GIFT_FIELD = "can_send_gift"; + private static final String ACCEPTED_GIFT_TYPES_FIELD = "accepted_gift_types"; /** * Optional. @@ -333,6 +334,6 @@ public class ChatFullInfo extends Chat { * Optional. * True, if gifts can be sent to the chat */ - @JsonProperty(CAN_SEND_GIFT_FIELD) - private Boolean canSendGift; + @JsonProperty(ACCEPTED_GIFT_TYPES_FIELD) + private AcceptedGiftTypes acceptedGiftTypes; } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/games/Animation.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/games/Animation.java index 4e561676c..640cb7717 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/games/Animation.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/games/Animation.java @@ -28,7 +28,7 @@ import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; -import org.telegram.telegrambots.meta.api.objects.PhotoSize; +import org.telegram.telegrambots.meta.api.objects.photo.PhotoSize; /** * This object represents an animation file (GIF or H.264/MPEG-4 AVC video without sound). diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/games/Game.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/games/Game.java index 0cddd4c77..d4f7fb4f8 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/games/Game.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/games/Game.java @@ -29,7 +29,7 @@ import lombok.extern.jackson.Jacksonized; import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; import org.telegram.telegrambots.meta.api.objects.MessageEntity; -import org.telegram.telegrambots.meta.api.objects.PhotoSize; +import org.telegram.telegrambots.meta.api.objects.photo.PhotoSize; import java.util.List; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/AcceptedGiftTypes.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/AcceptedGiftTypes.java new file mode 100644 index 000000000..779f48307 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/AcceptedGiftTypes.java @@ -0,0 +1,56 @@ +package org.telegram.telegrambots.meta.api.objects.gifts; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; + +/** + * @author Ruben Bermudez + * @version 9.0 + * + * This object describes the types of gifts that can be gifted to a user or a chat. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@AllArgsConstructor +@SuperBuilder +@Jacksonized +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class AcceptedGiftTypes implements BotApiObject { + private static final String UNLIMITED_GIFTS_FIELD = "unlimited_gifts"; + private static final String LIMITED_GIFTS_FIELD = "limited_gifts"; + private static final String UNIQUE_GIFTS_FIELD = "unique_gifts"; + private static final String PREMIUM_SUBSCRIPTION_FIELD = "premium_subscription"; + + /** + * True, if unlimited regular gifts are accepted + */ + @JsonProperty(UNLIMITED_GIFTS_FIELD) + private Boolean unlimitedGifts; + /** + * True, if limited regular gifts are accepted + */ + @JsonProperty(LIMITED_GIFTS_FIELD) + private Boolean limitedGifts; + /** + * True, if unique gifts or gifts that can be upgraded to unique for free are accepted + */ + @JsonProperty(UNIQUE_GIFTS_FIELD) + private Boolean uniqueGifts; + /** + * True, if a Telegram Premium subscription is accepted + */ + @JsonProperty(PREMIUM_SUBSCRIPTION_FIELD) + private Boolean primalSubscription; +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/GiftInfo.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/GiftInfo.java new file mode 100644 index 000000000..80b9a8008 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/GiftInfo.java @@ -0,0 +1,95 @@ +package org.telegram.telegrambots.meta.api.objects.gifts; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.objects.MessageEntity; + +import java.util.List; + +/** + * @author Ruben Bermudez + * @version 9.0 + * + * Describes a service message about a regular gift that was sent or received. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@RequiredArgsConstructor +@AllArgsConstructor +@SuperBuilder +@Jacksonized +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class GiftInfo implements BotApiObject { + private static final String GIFT_FIELD = "gift"; + private static final String OWNED_GIFT_ID_FIELD = "owned_gift_id"; + private static final String CONVERT_STAR_COUNT_FIELD = "convert_star_count"; + private static final String PREPAID_UPGRADE_STAR_COUNT_FIELD = "prepaid_upgrade_star_count"; + private static final String CAN_BE_UPGRADED_FIELD = "can_be_upgraded"; + private static final String TEXT_FIELD = "text"; + private static final String ENTITIES_FIELD = "entities"; + private static final String IS_PRIVATE_FIELD = "is_private"; + + /** + * Information about the gift + */ + @JsonProperty(GIFT_FIELD) + @NonNull + private Gift gift; + /** + * Optional. + * Unique identifier of the received gift for the bot; only present for gifts received on behalf of business accounts + */ + @JsonProperty(OWNED_GIFT_ID_FIELD) + private String ownedGiftId; + /** + * Optional. + * Number of Telegram Stars that can be claimed by the receiver by converting the gift; omitted if conversion to Telegram Stars is impossible + */ + @JsonProperty(CONVERT_STAR_COUNT_FIELD) + @NonNull + private Integer convertStarCount; + /** + * Optional. + * Number of Telegram Stars that were prepaid by the sender for the ability to upgrade the gift + */ + @JsonProperty(PREPAID_UPGRADE_STAR_COUNT_FIELD) + private Integer prepaidUpgradeStarCount; + /** + * Optional. + * True, if the gift can be upgraded to a unique gift + */ + @JsonProperty(CAN_BE_UPGRADED_FIELD) + private Boolean canBeUpgraded; + /** + * Optional. + * Text of the message that was added to the gift + */ + @JsonProperty(TEXT_FIELD) + private String text; + /** + * Optional. + * Special entities that appear in the text + */ + @JsonProperty(ENTITIES_FIELD) + private List entities; + /** + * Optional. + * True, if the sender and gift text are shown only to the gift receiver; otherwise, everyone will be able to see them + */ + @JsonProperty(IS_PRIVATE_FIELD) + private Boolean isPrivate; +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGift.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGift.java new file mode 100644 index 000000000..4b00508b7 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGift.java @@ -0,0 +1,74 @@ +package org.telegram.telegrambots.meta.api.objects.gifts; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; + +/** + * @author Ruben Bermudez + * @version 9.0 + * + * This object describes a unique gift that was upgraded from a regular gift. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@RequiredArgsConstructor +@AllArgsConstructor +@SuperBuilder +@Jacksonized +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class UniqueGift implements BotApiObject { + private static final String BASE_NAME_FIELD = "base_name"; + private static final String NAME_FIELD = "name"; + private static final String NUMBER_FIELD = "number"; + private static final String MODEL_FIELD = "model"; + private static final String SYMBOL_FIELD = "symbol"; + private static final String BACKDROP_FIELD = "backdrop"; + + /** + * Human-readable name of the regular gift from which this unique gift was upgraded + */ + @JsonProperty(BASE_NAME_FIELD) + @NonNull + private String baseName; + /** + * Unique name of the gift. This name can be used in https://t.me/nft/... links and story areas + */ + @JsonProperty(NAME_FIELD) + @NonNull + private String name; + /** + * Unique number of the upgraded gift among gifts upgraded from the same regular gift + */ + @JsonProperty(NUMBER_FIELD) + @NonNull + private Integer number; + /** + * Model of the gift + */ + @JsonProperty(MODEL_FIELD) + private UniqueGiftModel model; + /** + * Symbol of the gift + */ + @JsonProperty(SYMBOL_FIELD) + private UniqueGiftSymbol symbol; + /** + * Backdrop of the gift + */ + @JsonProperty(BACKDROP_FIELD) + private UniqueGiftBackdrop backdrop; +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGiftBackdrop.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGiftBackdrop.java new file mode 100644 index 000000000..32eaaf45a --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGiftBackdrop.java @@ -0,0 +1,56 @@ +package org.telegram.telegrambots.meta.api.objects.gifts; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; + +/** + * @author Ruben Bermudez + * @version 9.0 + * + * This object describes the backdrop of a unique gift. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +@SuperBuilder +@Jacksonized +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class UniqueGiftBackdrop implements BotApiObject { + private static final String NAME_FIELD = "center_color"; + private static final String COLORS_FIELD = "edge_color"; + private static final String RARITY_PER_MILLE_FIELD = "symbol_color"; + + /** + * Name of the backdrop + */ + @JsonProperty(NAME_FIELD) + @NonNull + private String name; + /** + * Colors of the backdrop + */ + @JsonProperty(COLORS_FIELD) + @NonNull + private UniqueGiftBackdropColors colors; + /** + * The number of unique gifts that receive this backdrop for every 1000 gifts upgraded + */ + @JsonProperty(RARITY_PER_MILLE_FIELD) + @NonNull + private Integer rarityPerMille; +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGiftBackdropColors.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGiftBackdropColors.java new file mode 100644 index 000000000..57e02b3f7 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGiftBackdropColors.java @@ -0,0 +1,63 @@ +package org.telegram.telegrambots.meta.api.objects.gifts; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; + +/** + * @author Ruben Bermudez + * @version 9.0 + * + * This object describes the colors of the backdrop of a unique gift. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +@SuperBuilder +@Jacksonized +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class UniqueGiftBackdropColors implements BotApiObject { + private static final String CENTER_COLOR_FIELD = "center_color"; + private static final String EDGE_COLOR_FIELD = "edge_color"; + private static final String SYMBOL_COLOR_FIELD = "symbol_color"; + private static final String TEXT_COLOR_FIELD = "text_color"; + + /** + * The color in the center of the backdrop in RGB format + */ + @JsonProperty(CENTER_COLOR_FIELD) + @NonNull + private Integer centerColor; + /** + * The color on the edges of the backdrop in RGB format + */ + @JsonProperty(EDGE_COLOR_FIELD) + @NonNull + private Integer edgeColor; + /** + * The color to be applied to the symbol in RGB format + */ + @JsonProperty(SYMBOL_COLOR_FIELD) + @NonNull + private Integer symbolColor; + /** + * The color for the text on the backdrop in RGB format + */ + @JsonProperty(TEXT_COLOR_FIELD) + @NonNull + private Integer textColor; +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGiftInfo.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGiftInfo.java new file mode 100644 index 000000000..48b30e3c5 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGiftInfo.java @@ -0,0 +1,65 @@ +package org.telegram.telegrambots.meta.api.objects.gifts; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; + +/** + * @author Ruben Bermudez + * @version 9.0 + * + * Describes a service message about a unique gift that was sent or received. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@RequiredArgsConstructor +@AllArgsConstructor +@SuperBuilder +@Jacksonized +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class UniqueGiftInfo implements BotApiObject { + private static final String GIFT_FIELD = "gift"; + private static final String ORIGIN_FIELD = "origin"; + private static final String OWNED_GIFT_ID_FIELD = "owned_gift_id"; + private static final String TRANSFER_STAR_COUNT_FIELD = "transfer_star_count"; + + /** + * Information about the gift + */ + @JsonProperty(GIFT_FIELD) + @NonNull + private UniqueGift gift; + /** + * Origin of the gift. + * Currently, either “upgrade” or “transfer” + */ + @JsonProperty(ORIGIN_FIELD) + @NonNull + private String origin; + /** + * Optional. + * Unique identifier of the received gift for the bot; only present for gifts received on behalf of business accounts + */ + @JsonProperty(OWNED_GIFT_ID_FIELD) + private String ownedGiftId; + /** + * Optional. + * Number of Telegram Stars that must be paid to transfer the gift; omitted if the bot cannot transfer the gift + */ + @JsonProperty(TRANSFER_STAR_COUNT_FIELD) + @NonNull + private Integer transferStarCount; +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGiftModel.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGiftModel.java new file mode 100644 index 000000000..d5281b4e7 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGiftModel.java @@ -0,0 +1,55 @@ +package org.telegram.telegrambots.meta.api.objects.gifts; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NonNull; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.objects.stickers.Sticker; + +/** + * @author Ruben Bermudez + * @version 9.0 + * + * This object describes the model of a unique gift. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@AllArgsConstructor +@SuperBuilder +@Jacksonized +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class UniqueGiftModel implements BotApiObject { + private static final String NAME_FIELD = "name"; + private static final String STICKER_FIELD = "sticker"; + private static final String RARITY_PER_MILLE_FIELD = "rarity_per_mille"; + + /** + * Name of the model + */ + @JsonProperty(NAME_FIELD) + @NonNull + private String name; + /** + * The sticker that represents the unique gift + */ + @JsonProperty(STICKER_FIELD) + @NonNull + private Sticker sticker; + /** + * The number of unique gifts that receive this model for every 1000 gifts upgraded + */ + @JsonProperty(RARITY_PER_MILLE_FIELD) + @NonNull + private Integer rarityPerMille; +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGiftSymbol.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGiftSymbol.java new file mode 100644 index 000000000..7d89fce52 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGiftSymbol.java @@ -0,0 +1,57 @@ +package org.telegram.telegrambots.meta.api.objects.gifts; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.objects.stickers.Sticker; + +/** + * @author Ruben Bermudez + * @version 9.0 + * + * This object describes the symbol shown on the pattern of a unique gift. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +@SuperBuilder +@Jacksonized +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class UniqueGiftSymbol implements BotApiObject { + private static final String NAME_FIELD = "name"; + private static final String STICKER_FIELD = "sticker"; + private static final String RARITY_PER_MILLE_FIELD = "rarity_per_mille"; + + /** + * Name of the symbol + */ + @JsonProperty(NAME_FIELD) + @NonNull + private String name; + /** + * The sticker that represents the unique gift + */ + @JsonProperty(STICKER_FIELD) + @NonNull + private Sticker sticker; + /** + * The number of unique gifts that receive this model for every 1000 gifts upgraded + */ + @JsonProperty(RARITY_PER_MILLE_FIELD) + @NonNull + private Integer rarityPerMille; +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/owned/OwnedGift.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/owned/OwnedGift.java new file mode 100644 index 000000000..772972f6f --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/owned/OwnedGift.java @@ -0,0 +1,79 @@ +package org.telegram.telegrambots.meta.api.objects.gifts.owned; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.objects.User; + +/** + * @author Ruben Bermudez + * @version 9.0 + * + * This object describes a gift received and owned by a user or a chat. Currently, it can be one of + * OwnedGiftRegular + * OwnedGiftUnique + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@RequiredArgsConstructor +@AllArgsConstructor +@SuperBuilder +@JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, + include = JsonTypeInfo.As.EXISTING_PROPERTY, + property = "type", + defaultImpl = Void.class +) +@JsonSubTypes({ + @JsonSubTypes.Type(value = OwnedGiftRegular.class, name = "regular"), + @JsonSubTypes.Type(value = OwnedGiftUnique.class, name = "unique") +}) +public abstract class OwnedGift implements BotApiObject { + public static final String TYPE_FIELD = "type"; + public static final String OWNED_GIFT_ID_FIELD = "owned_gift_id"; + public static final String SENDER_USER_FIELD = "sender_user"; + public static final String SEND_DATE_FIELD = "send_date"; + public static final String IS_SAVED_FIELD = "is_saved"; + + /** + * Optional. Unique identifier of the gift for the bot; for gifts received on behalf of business accounts only + */ + @JsonProperty(OWNED_GIFT_ID_FIELD) + private String ownedGiftId; + + /** + * Optional. Sender of the gift if it is a known user + */ + @JsonProperty(SENDER_USER_FIELD) + private User senderUser; + + /** + * Date the gift was sent in Unix time + */ + @JsonProperty(SEND_DATE_FIELD) + @NonNull + private Integer sendDate; + + /** + * Optional. True, if the gift is displayed on the account's profile page; for gifts received on behalf of business accounts only + */ + @JsonProperty(IS_SAVED_FIELD) + private Boolean isSaved; + + @JsonProperty(TYPE_FIELD) + public abstract String getType(); +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/owned/OwnedGiftRegular.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/owned/OwnedGiftRegular.java new file mode 100644 index 000000000..9bebc418b --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/owned/OwnedGiftRegular.java @@ -0,0 +1,107 @@ +package org.telegram.telegrambots.meta.api.objects.gifts.owned; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; +import org.telegram.telegrambots.meta.api.objects.MessageEntity; +import org.telegram.telegrambots.meta.api.objects.gifts.Gift; + +import java.util.List; + +/** + * @author Ruben Bermudez + * @version 9.0 + * + * Describes a regular gift owned by a user or a chat. + */ +@SuppressWarnings("unused") +@EqualsAndHashCode(callSuper = true) +@Getter +@Setter +@ToString +@NoArgsConstructor +@RequiredArgsConstructor +@AllArgsConstructor +@Jacksonized +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +@SuperBuilder +public class OwnedGiftRegular extends OwnedGift { + private static final String TYPE = "regular"; + + private static final String GIFT_FIELD = "gift"; + private static final String TEXT_FIELD = "text"; + private static final String ENTITIES_FIELD = "entities"; + private static final String IS_PRIVATE_FIELD = "is_private"; + private static final String WAS_REFUNDED_FIELD = "was_refunded"; + private static final String CAN_BE_UPGRADED_FIELD = "can_be_upgraded"; + private static final String CONVERT_STAR_COUNT_FIELD = "convert_star_count"; + private static final String PREPAID_UPGRADE_STAR_COUNT_FIELD = "prepaid_upgrade_star_count"; + + /** + * Information about the regular gift + */ + @JsonProperty(GIFT_FIELD) + @NonNull + private Gift gift; + + /** + * Optional. Text of the message that was added to the gift + */ + @JsonProperty(TEXT_FIELD) + private String text; + + /** + * Optional. Special entities that appear in the text + */ + @JsonProperty(ENTITIES_FIELD) + private List entities; + + /** + * Optional. True, if the sender and gift text are shown only to the gift receiver; + * otherwise, everyone will be able to see them + */ + @JsonProperty(IS_PRIVATE_FIELD) + private Boolean isPrivate; + + /** + * Optional. True, if the gift was refunded and isn't available anymore + */ + @JsonProperty(WAS_REFUNDED_FIELD) + private Boolean wasRefunded; + + /** + * Optional. True, if the gift can be upgraded to a unique gift; + * for gifts received on behalf of business accounts only + */ + @JsonProperty(CAN_BE_UPGRADED_FIELD) + private Boolean canBeUpgraded; + + /** + * Optional. Number of Telegram Stars that can be claimed by the receiver instead of the gift; + * omitted if the gift cannot be converted to Telegram Stars + */ + @JsonProperty(CONVERT_STAR_COUNT_FIELD) + private Integer convertStarCount; + + /** + * Optional. Number of Telegram Stars that were paid by the sender for the ability to upgrade the gift + */ + @JsonProperty(PREPAID_UPGRADE_STAR_COUNT_FIELD) + private Integer prepaidUpgradeStarCount; + + @Override + public String getType() { + return TYPE; + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/owned/OwnedGiftUnique.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/owned/OwnedGiftUnique.java new file mode 100644 index 000000000..a67c5c8c5 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/owned/OwnedGiftUnique.java @@ -0,0 +1,68 @@ +package org.telegram.telegrambots.meta.api.objects.gifts.owned; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; +import org.telegram.telegrambots.meta.api.objects.gifts.UniqueGift; + +/** + * @author Ruben Bermudez + * @version 9.0 + * + * Describes a unique gift received and owned by a user or a chat. + */ +@SuppressWarnings("unused") +@EqualsAndHashCode(callSuper = true) +@Getter +@Setter +@ToString +@NoArgsConstructor +@RequiredArgsConstructor +@AllArgsConstructor +@Jacksonized +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +@SuperBuilder +public class OwnedGiftUnique extends OwnedGift { + private static final String TYPE = "unique"; + + private static final String GIFT_FIELD = "gift"; + private static final String CAN_BE_TRANSFERRED_FIELD = "can_be_transferred"; + private static final String TRANSFER_STAR_COUNT_FIELD = "transfer_star_count"; + + /** + * Information about the unique gift + */ + @JsonProperty(GIFT_FIELD) + @NonNull + private UniqueGift gift; + + /** + * Optional. True, if the gift can be transferred to another owner; + * for gifts received on behalf of business accounts only + */ + @JsonProperty(CAN_BE_TRANSFERRED_FIELD) + private Boolean canBeTransferred; + + /** + * Optional. Number of Telegram Stars that must be paid to transfer the gift; + * omitted if the bot cannot transfer the gift + */ + @JsonProperty(TRANSFER_STAR_COUNT_FIELD) + private Integer transferStarCount; + + @Override + public String getType() { + return TYPE; + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/owned/OwnedGifts.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/owned/OwnedGifts.java new file mode 100644 index 000000000..e0a34acba --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/owned/OwnedGifts.java @@ -0,0 +1,59 @@ +package org.telegram.telegrambots.meta.api.objects.gifts.owned; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; + +import java.util.List; + +/** + * @author Ruben Bermudez + * @version 9.0 + * + * Contains the list of gifts received and owned by a user or a chat. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@RequiredArgsConstructor +@AllArgsConstructor +@Builder +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class OwnedGifts implements BotApiObject { + private static final String TOTAL_COUNT_FIELD = "total_count"; + private static final String GIFTS_FIELD = "gifts"; + private static final String NEXT_OFFSET_FIELD = "next_offset"; + + /** + * The total number of gifts owned by the user or the chat + */ + @JsonProperty(TOTAL_COUNT_FIELD) + @NonNull + private Integer totalCount; + + /** + * The list of gifts + */ + @JsonProperty(GIFTS_FIELD) + @NonNull + private List gifts; + + /** + * Optional. Offset for the next request. If empty, then there are no more results + */ + @JsonProperty(NEXT_OFFSET_FIELD) + private String nextOffset; +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/ChosenInlineQuery.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/ChosenInlineQuery.java index d3edad28e..6b75781be 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/ChosenInlineQuery.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/ChosenInlineQuery.java @@ -12,8 +12,8 @@ import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; -import org.telegram.telegrambots.meta.api.objects.Location; import org.telegram.telegrambots.meta.api.objects.User; +import org.telegram.telegrambots.meta.api.objects.location.Location; /** * @author Ruben Bermudez diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/InlineQuery.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/InlineQuery.java index 1dfebdb52..76a76aab3 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/InlineQuery.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/InlineQuery.java @@ -12,8 +12,8 @@ import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; -import org.telegram.telegrambots.meta.api.objects.Location; import org.telegram.telegrambots.meta.api.objects.User; +import org.telegram.telegrambots.meta.api.objects.location.Location; /** * @author Ruben Bermudez diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/InlineQueryResultArticle.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/InlineQueryResultArticle.java index 4369e1d27..22265a1dd 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/InlineQueryResultArticle.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/InlineQueryResultArticle.java @@ -79,14 +79,6 @@ public class InlineQueryResultArticle implements InlineQueryResult { */ @JsonProperty(URL_FIELD) private String url; - /** - * @deprecated Pass an empty string as url instead. - * Optional. - * Pass True, if you don't want the URL to be shown in the message - */ - @Deprecated - @JsonProperty(HIDE_URL_FIELD) - private Boolean hideUrl; /** * Optional. * Short description of the result diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Location.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/location/Location.java similarity index 97% rename from telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Location.java rename to telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/location/Location.java index a26a8da7b..fd2291d4b 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Location.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/location/Location.java @@ -1,4 +1,4 @@ -package org.telegram.telegrambots.meta.api.objects; +package org.telegram.telegrambots.meta.api.objects.location; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/location/LocationAddress.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/location/LocationAddress.java new file mode 100644 index 000000000..5c6bd6585 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/location/LocationAddress.java @@ -0,0 +1,74 @@ +package org.telegram.telegrambots.meta.api.objects.location; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.interfaces.Validable; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * @author Ruben Bermudez + * @version 9.0 + * + * Describes the physical address of a location. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@RequiredArgsConstructor +@AllArgsConstructor +@Builder +@JsonIgnoreProperties(ignoreUnknown = true) +public class LocationAddress implements BotApiObject, Validable { + private static final String COUNTRY_CODE_FIELD = "country_code"; + private static final String STATE_FIELD = "state"; + private static final String CITY_FIELD = "city"; + private static final String STREET_FIELD = "street"; + + /** + * The two-letter ISO 3166-1 alpha-2 country code of the country where the location is located + */ + @JsonProperty(COUNTRY_CODE_FIELD) + @NonNull + private String countryCode; + + /** + * Optional. State of the location + */ + @JsonProperty(STATE_FIELD) + private String state; + + /** + * Optional. City of the location + */ + @JsonProperty(CITY_FIELD) + private String city; + + /** + * Optional. Street address of the location + */ + @JsonProperty(STREET_FIELD) + private String street; + + @Override + public void validate() throws TelegramApiValidationException { + if (countryCode.isEmpty()) { + throw new TelegramApiValidationException("Country code parameter can't be empty", this); + } + + if (countryCode.length() != 2) { + throw new TelegramApiValidationException("Country code must be a two-letter ISO 3166-1 alpha-2 code", this); + } + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/message/Message.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/message/Message.java index ec4907e18..94ce56ae3 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/message/Message.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/message/Message.java @@ -20,10 +20,8 @@ import org.telegram.telegrambots.meta.api.objects.EntityType; import org.telegram.telegrambots.meta.api.objects.ExternalReplyInfo; import org.telegram.telegrambots.meta.api.objects.LinkPreviewOptions; -import org.telegram.telegrambots.meta.api.objects.Location; import org.telegram.telegrambots.meta.api.objects.MessageAutoDeleteTimerChanged; import org.telegram.telegrambots.meta.api.objects.MessageEntity; -import org.telegram.telegrambots.meta.api.objects.PhotoSize; import org.telegram.telegrambots.meta.api.objects.ProximityAlertTriggered; import org.telegram.telegrambots.meta.api.objects.TextQuote; import org.telegram.telegrambots.meta.api.objects.User; @@ -45,16 +43,20 @@ import org.telegram.telegrambots.meta.api.objects.forum.GeneralForumTopicUnhidden; import org.telegram.telegrambots.meta.api.objects.games.Animation; import org.telegram.telegrambots.meta.api.objects.games.Game; +import org.telegram.telegrambots.meta.api.objects.gifts.GiftInfo; +import org.telegram.telegrambots.meta.api.objects.gifts.UniqueGiftInfo; import org.telegram.telegrambots.meta.api.objects.giveaway.Giveaway; import org.telegram.telegrambots.meta.api.objects.giveaway.GiveawayCompleted; import org.telegram.telegrambots.meta.api.objects.giveaway.GiveawayCreated; import org.telegram.telegrambots.meta.api.objects.giveaway.GiveawayWinners; +import org.telegram.telegrambots.meta.api.objects.location.Location; import org.telegram.telegrambots.meta.api.objects.messageorigin.MessageOrigin; import org.telegram.telegrambots.meta.api.objects.passport.PassportData; import org.telegram.telegrambots.meta.api.objects.payments.Invoice; import org.telegram.telegrambots.meta.api.objects.payments.RefundedPayment; import org.telegram.telegrambots.meta.api.objects.payments.SuccessfulPayment; import org.telegram.telegrambots.meta.api.objects.payments.paidmedia.PaidMediaInfo; +import org.telegram.telegrambots.meta.api.objects.photo.PhotoSize; import org.telegram.telegrambots.meta.api.objects.polls.Poll; import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup; import org.telegram.telegrambots.meta.api.objects.stickers.Sticker; @@ -176,6 +178,10 @@ public class Message implements MaybeInaccessibleMessage { private static final String SHOW_CAPTION_ABOVE_MEDIA_FIELD = "show_caption_above_media"; private static final String PAID_MEDIA_FIELD = "paid_media"; private static final String REFUNDED_PAYMENT_FIELD = "refunded_payment"; + private static final String GIFT_FIELD = "gift"; + private static final String UNIQUE_GIFT_FIELD = "unique_gift"; + private static final String PAID_MESSAGE_PRICE_CHANGED_FIELD = "paid_message_price_changed"; + private static final String PAID_STAR_COUNT_FIELD = "paid_star_count"; /** * Unique message identifier inside this chat. In specific instances (e.g., message containing a video sent to a big chat), @@ -757,6 +763,30 @@ public class Message implements MaybeInaccessibleMessage { */ @JsonProperty(REFUNDED_PAYMENT_FIELD) private RefundedPayment refundedPayment; + /** + * Optional. + * Service message: a regular gift was sent or received + */ + @JsonProperty(GIFT_FIELD) + private GiftInfo gift; + /** + * Optional. + * Service message: a unique gift was sent or received + */ + @JsonProperty(UNIQUE_GIFT_FIELD) + private UniqueGiftInfo uniqueGift; + /** + * Optional. + * Service message: the price for paid messages has changed in the chat + */ + @JsonProperty(PAID_MESSAGE_PRICE_CHANGED_FIELD) + private PaidMessagePriceChanged paidMessagePriceChanged; + /** + * Optional. + * The number of Telegram Stars that were paid by the sender of the message to send it + */ + @JsonProperty(PAID_STAR_COUNT_FIELD) + private Integer paidStarCount; public List getEntities() { if (entities != null) { @@ -1013,4 +1043,24 @@ public boolean hasPaidMedia() { public boolean hasCaption() { return caption != null; } + + @JsonIgnore + public boolean hasGift() { + return gift != null; + } + + @JsonIgnore + public boolean hasUniqueGift() { + return uniqueGift != null; + } + + @JsonIgnore + public boolean hasPaidMessagePriceChanged() { + return paidMessagePriceChanged != null; + } + + @JsonIgnore + public boolean hasPaidStarCount() { + return paidStarCount != null; + } } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/message/PaidMessagePriceChanged.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/message/PaidMessagePriceChanged.java new file mode 100644 index 000000000..e33cfb3f5 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/message/PaidMessagePriceChanged.java @@ -0,0 +1,39 @@ +package org.telegram.telegrambots.meta.api.objects.message; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NonNull; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; + +/** + * @author Ruben Bermudez + * @version 9.0 + * + * Describes a service message about a change in the price of paid messages within a chat. + */ +@SuppressWarnings("WeakerAccess") +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@AllArgsConstructor +@SuperBuilder +@Jacksonized +@JsonIgnoreProperties(ignoreUnknown = true) +public class PaidMessagePriceChanged implements BotApiObject { + private static final String PAID_MESSAGE_STAR_COUNT_FIELD = "paid_message_star_count"; + + /** + * The new number of Telegram Stars that must be paid by non-administrator users of the supergroup chat for each sent message + */ + @JsonProperty(PAID_MESSAGE_STAR_COUNT_FIELD) + @NonNull + private Integer paidMessageStarCount; +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/payments/Invoice.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/payments/Invoice.java index 1890fc18c..82c168f8d 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/payments/Invoice.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/payments/Invoice.java @@ -12,7 +12,7 @@ import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; -import org.telegram.telegrambots.meta.api.objects.PhotoSize; +import org.telegram.telegrambots.meta.api.objects.photo.PhotoSize; /** * @author Ruben Bermudez diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/payments/paidmedia/PaidMediaPhoto.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/payments/paidmedia/PaidMediaPhoto.java index 060ad408d..eccdb85ae 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/payments/paidmedia/PaidMediaPhoto.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/payments/paidmedia/PaidMediaPhoto.java @@ -11,7 +11,7 @@ import lombok.ToString; import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; -import org.telegram.telegrambots.meta.api.objects.PhotoSize; +import org.telegram.telegrambots.meta.api.objects.photo.PhotoSize; import java.util.List; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/payments/star/StarAmount.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/payments/star/StarAmount.java new file mode 100644 index 000000000..97597ad0c --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/payments/star/StarAmount.java @@ -0,0 +1,67 @@ +package org.telegram.telegrambots.meta.api.objects.payments.star; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.interfaces.Validable; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * @author Ruben Bermudez + * @version 9.0 + * + * Describes an amount of Telegram Stars. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@RequiredArgsConstructor +@AllArgsConstructor +@Builder +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class StarAmount implements BotApiObject, Validable { + private static final String AMOUNT_FIELD = "amount"; + private static final String NANOSTAR_AMOUNT_FIELD = "nanostar_amount"; + + /** + * Integer amount of Telegram Stars, rounded to 0; can be negative + */ + @JsonProperty(AMOUNT_FIELD) + @NonNull + private Integer amount; + + /** + * Optional. + * The number of 1/1000000000 shares of Telegram Stars; from -999999999 to 999999999; + * can be negative if and only if amount is non-positive + */ + @JsonProperty(NANOSTAR_AMOUNT_FIELD) + private Integer nanostarAmount; + + @Override + public void validate() throws TelegramApiValidationException { + if (nanostarAmount != null) { + if (nanostarAmount < -999999999 || nanostarAmount > 999999999) { + throw new TelegramApiValidationException("NanostarAmount must be between -999999999 and 999999999", this); + } + + // Check if nanostarAmount is negative only when the amount is non-positive + if (nanostarAmount < 0 && amount > 0) { + throw new TelegramApiValidationException("NanostarAmount can be negative only if amount is non-positive", this); + } + } + } +} \ No newline at end of file diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/payments/transactionpartner/TransactionPartnerUser.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/payments/transactionpartner/TransactionPartnerUser.java index 420ac2e48..222603dfd 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/payments/transactionpartner/TransactionPartnerUser.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/payments/transactionpartner/TransactionPartnerUser.java @@ -12,6 +12,7 @@ import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; import org.telegram.telegrambots.meta.api.objects.User; +import org.telegram.telegrambots.meta.api.objects.gifts.Gift; import org.telegram.telegrambots.meta.api.objects.payments.paidmedia.PaidMedia; import java.util.List; @@ -22,7 +23,6 @@ * * Describes a transaction with a user. */ - @EqualsAndHashCode(callSuper = false) @Getter @Setter @@ -34,19 +34,31 @@ @JsonInclude(JsonInclude.Include.NON_NULL) public class TransactionPartnerUser implements TransactionPartner { private static final String TYPE_FIELD = "type"; + private static final String TRANSACTION_TYPE_FIELD = "transaction_type"; private static final String USER_FIELD = "user"; + private static final String AFFILIATE_FIELD = "affiliate"; private static final String INVOICE_PAYLOAD_FIELD = "invoice_payload"; + private static final String SUBSCRIPTION_PERIOD_FIELD = "subscription_period"; private static final String PAID_MEDIA_FIELD = "paid_media"; private static final String PAID_MEDIA_PAYLOAD_FIELD = "paid_media_payload"; private static final String GIFT_FIELD = "gift"; - private static final String SUBSCRIPTION_PERIOD_FIELD = "subscription_period"; - private static final String AFFILIATE_FIELD = "affiliate"; + private static final String PREMIUM_SUBSCRIPTION_DURATION_FIELD = "premium_subscription_duration"; /** * Type of the transaction partner, always “user” */ @JsonProperty(TYPE_FIELD) + @NonNull private final String type = "user"; + /** + * Type of the transaction, currently one of “invoice_payment” for payments via invoices, “paid_media_payment” + * for payments for paid media, “gift_purchase” for gifts sent by the bot, “premium_purchase” + * for Telegram Premium subscriptions gifted by the bot, “business_account_transfer” + * for direct transfers from managed business accounts + */ + @JsonProperty(TRANSACTION_TYPE_FIELD) + @NonNull + private String transactionType; /** * Information about the user */ @@ -55,41 +67,47 @@ public class TransactionPartnerUser implements TransactionPartner { private User user; /** * Optional. - * Bot-specified invoice payload + * Information about the affiliate that received a commission via this transaction. + * Can be available only for “invoice_payment” and “paid_media_payment” transactions. + */ + @JsonProperty(AFFILIATE_FIELD) + private AffiliateInfo affiliate; + /** + * Optional. + * Bot-specified invoice payload. Can be available only for “invoice_payment” transactions. */ @JsonProperty(INVOICE_PAYLOAD_FIELD) private String invoicePayload; /** * Optional. - * Information about the paid media bought by the user + * The duration of the paid subscription. + * Can be available only for “invoice_payment” transactions. + */ + @JsonProperty(SUBSCRIPTION_PERIOD_FIELD) + private Integer subscriptionPeriod; + /** + * Optional. + * Information about the paid media bought by the user; for “paid_media_payment” transactions only */ @JsonProperty(PAID_MEDIA_FIELD) private List paidMedia; - /** * Optional. - * Bot-specified paid media payload + * Bot-specified paid media payload. Can be available only for “paid_media_payment” transactions. */ @JsonProperty(PAID_MEDIA_PAYLOAD_FIELD) private String paidMediaPayload; - /** * Optional. - * The gift sent to the user by the bot + * The gift sent to the user by the bot; for “gift_purchase” transactions only */ @JsonProperty(GIFT_FIELD) - private String gift; - + private Gift gift; /** * Optional. - * The duration of the paid subscription + * Number of months the gifted Telegram Premium subscription will be active for; for “premium_purchase” transactions only */ - @JsonProperty(SUBSCRIPTION_PERIOD_FIELD) - private Integer subscriptionPeriod; - /** - * Optional. - * Information about the affiliate that received a commission via this transaction - */ - @JsonProperty(AFFILIATE_FIELD) - private AffiliateInfo affiliate; + @JsonProperty(PREMIUM_SUBSCRIPTION_DURATION_FIELD) + private Integer premiumSubscriptionDuration; + } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/PhotoSize.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/photo/PhotoSize.java similarity index 97% rename from telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/PhotoSize.java rename to telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/photo/PhotoSize.java index f820013b1..8ff826d28 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/PhotoSize.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/photo/PhotoSize.java @@ -1,4 +1,4 @@ -package org.telegram.telegrambots.meta.api.objects; +package org.telegram.telegrambots.meta.api.objects.photo; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/photo/input/InputProfilePhoto.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/photo/input/InputProfilePhoto.java new file mode 100644 index 000000000..652c99945 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/photo/input/InputProfilePhoto.java @@ -0,0 +1,45 @@ +package org.telegram.telegrambots.meta.api.objects.photo.input; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import lombok.AccessLevel; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.interfaces.Validable; + +/** + * @author Ruben Bermudez + * @version 9.0 + * + * This object describes a profile photo to set. Currently, it can be one of + * InputProfilePhotoStatic + * InputProfilePhotoAnimated + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@SuperBuilder +@JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, + include = JsonTypeInfo.As.EXISTING_PROPERTY, + property = "type", + defaultImpl = Void.class +) +@JsonSubTypes({ + @JsonSubTypes.Type(value = InputProfilePhotoStatic.class, name = "static"), + @JsonSubTypes.Type(value = InputProfilePhotoAnimated.class, name = "animated") +}) +public abstract class InputProfilePhoto implements Validable, BotApiObject { + public static final String TYPE_FIELD = "type"; + + @JsonProperty(TYPE_FIELD) + public abstract String getType(); +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/photo/input/InputProfilePhotoAnimated.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/photo/input/InputProfilePhotoAnimated.java new file mode 100644 index 000000000..a6888eb1d --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/photo/input/InputProfilePhotoAnimated.java @@ -0,0 +1,61 @@ +package org.telegram.telegrambots.meta.api.objects.photo.input; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import org.telegram.telegrambots.meta.api.objects.InputFile; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * @author Ruben Bermudez + * @version 9.0 + * + * An animated profile photo in the MPEG4 format. + */ +@EqualsAndHashCode(callSuper = true) +@Getter +@Setter +@ToString +@NoArgsConstructor +@RequiredArgsConstructor +@AllArgsConstructor +@SuperBuilder +public class InputProfilePhotoAnimated extends InputProfilePhoto { + public static final String TYPE = "animated"; + public static final String ANIMATION_FIELD = "animation"; + public static final String MAIN_FRAME_TIMESTAMP_FIELD = "main_frame_timestamp"; + + /** + * The animated profile photo. Profile photos can't be reused and can only be uploaded as a new file, + * so you can pass "attach://<file_attach_name>" if the photo was uploaded using multipart/form-data + * under <file_attach_name>. + */ + @JsonProperty(ANIMATION_FIELD) + @NonNull + private InputFile animation; + /** + * Optional. + * Timestamp in seconds of the frame that will be used as the static profile photo. + * Defaults to 0.0. + */ + @JsonProperty(MAIN_FRAME_TIMESTAMP_FIELD) + private Float mainFrameTimestamp; + + @Override + public void validate() throws TelegramApiValidationException { + super.validate(); + animation.validate(); + } + + @Override + public String getType() { + return TYPE; + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/photo/input/InputProfilePhotoStatic.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/photo/input/InputProfilePhotoStatic.java new file mode 100644 index 000000000..4915b42a1 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/photo/input/InputProfilePhotoStatic.java @@ -0,0 +1,53 @@ +package org.telegram.telegrambots.meta.api.objects.photo.input; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import org.telegram.telegrambots.meta.api.objects.InputFile; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * @author Ruben Bermudez + * @version 9.0 + * + * An animated profile photo in the MPEG4 format. + */ +@EqualsAndHashCode(callSuper = true) +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +@SuperBuilder +public class InputProfilePhotoStatic extends InputProfilePhoto { + public static final String TYPE = "static"; + public static final String PHOTO_FIELD = "photo"; + + /** + * The static profile photo. + * Profile photos can't be reused and can only be uploaded as a new file, + * so you can pass “attach://” + * if the photo was uploaded using multipart/form-data under . + */ + @JsonProperty(PHOTO_FIELD) + @NonNull + private InputFile photo; + + @Override + public void validate() throws TelegramApiValidationException { + super.validate(); + + photo.validate(); + } + + @Override + public String getType() { + return TYPE; + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/reactions/ReactionTypeCustomEmoji.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/reactions/ReactionTypeCustomEmoji.java index 26678965a..543cb3b5c 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/reactions/ReactionTypeCustomEmoji.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/reactions/ReactionTypeCustomEmoji.java @@ -2,7 +2,6 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.Builder; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NonNull; @@ -36,8 +35,7 @@ public class ReactionTypeCustomEmoji implements ReactionType { */ @JsonProperty(TYPE_FIELD) @NonNull - @Builder.Default - private String type = ReactionType.CUSTOM_EMOJI_TYPE; + private final String type = ReactionType.CUSTOM_EMOJI_TYPE; /** * Custom emoji identifier */ @@ -50,8 +48,5 @@ public void validate() throws TelegramApiValidationException { if (customEmojiId.isEmpty()) { throw new TelegramApiValidationException("CustomEmojiId parameter can't be empty", this); } - if (!ReactionType.CUSTOM_EMOJI_TYPE.equals(type)) { - throw new TelegramApiValidationException("Type must be \"custom_emoji\"", this); - } } } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/reactions/ReactionTypeEmoji.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/reactions/ReactionTypeEmoji.java index 7cebf9730..345fdeccd 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/reactions/ReactionTypeEmoji.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/reactions/ReactionTypeEmoji.java @@ -3,7 +3,6 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.Builder; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NonNull; @@ -38,8 +37,7 @@ public class ReactionTypeEmoji implements ReactionType { */ @JsonProperty(TYPE_FIELD) @NonNull - @Builder.Default - private String type = ReactionType.EMOJI_TYPE; + private final String type = ReactionType.EMOJI_TYPE; /** * Reaction emoji. Currently, it can be one of "👍", "👎", "❤", "🔥", "🥰", "👏", "😁", "🤔", "🤯", "😱", "🤬", * "😢", "🎉", "🤩", "🤮", "💩", "🙏", "👌", "🕊", "🤡", "🥱", "🥴", "😍", "🐳", "❤‍🔥", "🌚", "🌭", "💯", "🤣", @@ -56,8 +54,5 @@ public void validate() throws TelegramApiValidationException { if (emoji.isEmpty()) { throw new TelegramApiValidationException("Emoji parameter can't be empty", this); } - if (!ReactionType.EMOJI_TYPE.equals(type)) { - throw new TelegramApiValidationException("Type must be \"emoji\"", this); - } } } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/reactions/ReactionTypePaid.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/reactions/ReactionTypePaid.java index 937479035..db949ff87 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/reactions/ReactionTypePaid.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/reactions/ReactionTypePaid.java @@ -3,7 +3,6 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.Builder; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NonNull; @@ -12,7 +11,6 @@ import lombok.ToString; import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; -import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; /** * @author Ruben Bermudez @@ -37,14 +35,5 @@ public class ReactionTypePaid implements ReactionType { */ @JsonProperty(TYPE_FIELD) @NonNull - @Builder.Default - private String type = ReactionType.PAID_TYPE; - - - @Override - public void validate() throws TelegramApiValidationException { - if (!ReactionType.PAID_TYPE.equals(type)) { - throw new TelegramApiValidationException("Type must be \"paid\"", this); - } - } + private final String type = ReactionType.PAID_TYPE; } 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 4560d6dc9..089209543 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 @@ -5,7 +5,6 @@ import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; import lombok.Getter; -import lombok.NoArgsConstructor; import lombok.RequiredArgsConstructor; import lombok.Setter; import lombok.ToString; @@ -13,7 +12,7 @@ import lombok.extern.jackson.Jacksonized; import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; import org.telegram.telegrambots.meta.api.objects.File; -import org.telegram.telegrambots.meta.api.objects.PhotoSize; +import org.telegram.telegrambots.meta.api.objects.photo.PhotoSize; /** * This object represents a sticker. 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 fec249503..434a5c633 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 @@ -10,7 +10,7 @@ import lombok.Setter; import lombok.ToString; import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; -import org.telegram.telegrambots.meta.api.objects.PhotoSize; +import org.telegram.telegrambots.meta.api.objects.photo.PhotoSize; import java.util.List; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/StoryArea.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/StoryArea.java new file mode 100644 index 000000000..26ae90f7a --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/StoryArea.java @@ -0,0 +1,55 @@ +package org.telegram.telegrambots.meta.api.objects.stories; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.Setter; +import lombok.ToString; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.interfaces.Validable; +import org.telegram.telegrambots.meta.api.objects.stories.area.StoryAreaType; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * @author Ruben Bermudez + * @version 9.0 + * + * Describes a clickable area on a story media. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +@Builder +@JsonIgnoreProperties(ignoreUnknown = true) +public class StoryArea implements BotApiObject, Validable { + private static final String POSITION_FIELD = "position"; + private static final String TYPE_FIELD = "type"; + + /** + * Position of the area + */ + @JsonProperty(POSITION_FIELD) + @NonNull + private StoryAreaPosition position; + + /** + * Type of the area + */ + @JsonProperty(TYPE_FIELD) + @NonNull + private StoryAreaType type; + + @Override + public void validate() throws TelegramApiValidationException { + position.validate(); + type.validate(); + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/StoryAreaPosition.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/StoryAreaPosition.java new file mode 100644 index 000000000..e734f467a --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/StoryAreaPosition.java @@ -0,0 +1,85 @@ +package org.telegram.telegrambots.meta.api.objects.stories; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.Setter; +import lombok.ToString; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.interfaces.Validable; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * @author Ruben Bermudez + * @version 9.0 + * + * Describes the position of a clickable area within a story. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class StoryAreaPosition implements BotApiObject, Validable { + private static final String X_PERCENTAGE_FIELD = "x_percentage"; + private static final String Y_PERCENTAGE_FIELD = "y_percentage"; + private static final String WIDTH_PERCENTAGE_FIELD = "width_percentage"; + private static final String HEIGHT_PERCENTAGE_FIELD = "height_percentage"; + private static final String ROTATION_ANGLE_FIELD = "rotation_angle"; + private static final String CORNER_RADIUS_PERCENTAGE_FIELD = "corner_radius_percentage"; + + /** + * The abscissa of the area's center, as a percentage of the media width + */ + @JsonProperty(X_PERCENTAGE_FIELD) + @NonNull + private Float xPercentage; + + /** + * The ordinate of the area's center, as a percentage of the media height + */ + @JsonProperty(Y_PERCENTAGE_FIELD) + @NonNull + private Float yPercentage; + + /** + * The width of the area's rectangle, as a percentage of the media width + */ + @JsonProperty(WIDTH_PERCENTAGE_FIELD) + @NonNull + private Float widthPercentage; + + /** + * The height of the area's rectangle, as a percentage of the media height + */ + @JsonProperty(HEIGHT_PERCENTAGE_FIELD) + @NonNull + private Float heightPercentage; + + /** + * The clockwise rotation angle of the rectangle, in degrees; 0-360 + */ + @JsonProperty(ROTATION_ANGLE_FIELD) + @NonNull + private Float rotationAngle; + + /** + * The radius of the rectangle corner rounding, as a percentage of the media width + */ + @JsonProperty(CORNER_RADIUS_PERCENTAGE_FIELD) + @NonNull + private Float cornerRadiusPercentage; + + @Override + public void validate() throws TelegramApiValidationException { + if (rotationAngle < 0 || rotationAngle > 360) { + throw new TelegramApiValidationException("RotationAngle must be between 0 and 360 degrees", this); + } + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/area/StoryAreaType.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/area/StoryAreaType.java new file mode 100644 index 000000000..ae4367fd8 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/area/StoryAreaType.java @@ -0,0 +1,48 @@ +package org.telegram.telegrambots.meta.api.objects.stories.area; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import lombok.AccessLevel; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.interfaces.Validable; + +/** + * Describes the type of a clickable area on a story. Currently, it can be one of + * StoryAreaTypeLocation + * StoryAreaTypeSuggestedReaction + * StoryAreaTypeLink + * StoryAreaTypeWeather + * StoryAreaTypeUniqueGift + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@SuperBuilder +@JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, + include = JsonTypeInfo.As.EXISTING_PROPERTY, + property = "type", + defaultImpl = Void.class +) +@JsonSubTypes({ + @JsonSubTypes.Type(value = StoryAreaTypeLocation.class, name = "location"), + @JsonSubTypes.Type(value = StoryAreaTypeSuggestedReaction.class, name = "suggested_reaction"), + @JsonSubTypes.Type(value = StoryAreaTypeLink.class, name = "link"), + @JsonSubTypes.Type(value = StoryAreaTypeWeather.class, name = "weather"), + @JsonSubTypes.Type(value = StoryAreaTypeUniqueGift.class, name = "unique_gift") +}) +public abstract class StoryAreaType implements Validable, BotApiObject { + public static final String TYPE_FIELD = "type"; + + @JsonProperty(TYPE_FIELD) + public abstract String getType(); +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/area/StoryAreaTypeLink.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/area/StoryAreaTypeLink.java new file mode 100644 index 000000000..555bf62c7 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/area/StoryAreaTypeLink.java @@ -0,0 +1,47 @@ +package org.telegram.telegrambots.meta.api.objects.stories.area; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * Describes a story area pointing to an HTTP or tg:// link. + * Currently, a story can have up to 3 link areas. + */ +@EqualsAndHashCode(callSuper = true) +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +@SuperBuilder +public class StoryAreaTypeLink extends StoryAreaType { + private static final String TYPE = "link"; + private static final String URL_FIELD = "url"; + + /** + * HTTP or tg:// URL to be opened when the area is clicked + */ + @JsonProperty(URL_FIELD) + @NonNull + private String url; + + @Override + public void validate() throws TelegramApiValidationException { + if (url.isEmpty()) { + throw new TelegramApiValidationException("URL parameter can't be empty", this); + } + } + + @Override + public String getType() { + return TYPE; + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/area/StoryAreaTypeLocation.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/area/StoryAreaTypeLocation.java new file mode 100644 index 000000000..e14713851 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/area/StoryAreaTypeLocation.java @@ -0,0 +1,60 @@ +package org.telegram.telegrambots.meta.api.objects.stories.area; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NonNull; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import org.telegram.telegrambots.meta.api.objects.location.LocationAddress; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * Describes a story area pointing to a location. + * Currently, a story can have up to 10 location areas. + */ +@EqualsAndHashCode(callSuper = true) +@Getter +@Setter +@ToString +@AllArgsConstructor +@SuperBuilder +public class StoryAreaTypeLocation extends StoryAreaType { + private static final String TYPE = "location"; + private static final String LATITUDE_FIELD = "latitude"; + private static final String LONGITUDE_FIELD = "longitude"; + private static final String ADDRESS_FIELD = "address"; + + /** + * Location latitude in degrees + */ + @JsonProperty(LATITUDE_FIELD) + @NonNull + private Float latitude; + + /** + * Location longitude in degrees + */ + @JsonProperty(LONGITUDE_FIELD) + @NonNull + private Float longitude; + + /** + * Optional. Address of the location + */ + @JsonProperty(ADDRESS_FIELD) + @NonNull + private LocationAddress address; + + @Override + public void validate() throws TelegramApiValidationException { + address.validate(); + } + + @Override + public String getType() { + return TYPE; + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/area/StoryAreaTypeSuggestedReaction.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/area/StoryAreaTypeSuggestedReaction.java new file mode 100644 index 000000000..225e8b4f2 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/area/StoryAreaTypeSuggestedReaction.java @@ -0,0 +1,62 @@ +package org.telegram.telegrambots.meta.api.objects.stories.area; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import org.telegram.telegrambots.meta.api.objects.reactions.ReactionType; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * Describes a story area pointing to a suggested reaction. + * Currently, a story can have up to 5 suggested reaction areas. + */ +@EqualsAndHashCode(callSuper = true) +@Getter +@Setter +@ToString +@NoArgsConstructor +@RequiredArgsConstructor +@AllArgsConstructor +@SuperBuilder +public class StoryAreaTypeSuggestedReaction extends StoryAreaType { + private static final String TYPE = "suggested_reaction"; + private static final String REACTION_TYPE_FIELD = "reaction_type"; + private static final String IS_DARK_FIELD = "is_dark"; + private static final String IS_FLIPPED_FIELD = "is_flipped"; + + /** + * Type of the reaction + */ + @JsonProperty(REACTION_TYPE_FIELD) + @NonNull + private ReactionType reactionType; + + /** + * Optional. Pass True if the reaction area has a dark background + */ + @JsonProperty(IS_DARK_FIELD) + private Boolean isDark; + + /** + * Optional. Pass True if reaction area corner is flipped + */ + @JsonProperty(IS_FLIPPED_FIELD) + private Boolean isFlipped; + + @Override + public void validate() throws TelegramApiValidationException { + reactionType.validate(); + } + + @Override + public String getType() { + return TYPE; + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/area/StoryAreaTypeUniqueGift.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/area/StoryAreaTypeUniqueGift.java new file mode 100644 index 000000000..a5f3af3fc --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/area/StoryAreaTypeUniqueGift.java @@ -0,0 +1,47 @@ +package org.telegram.telegrambots.meta.api.objects.stories.area; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * Describes a story area pointing to a unique gift. + * Currently, a story can have at most 1 unique gift area. + */ +@EqualsAndHashCode(callSuper = true) +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +@SuperBuilder +public class StoryAreaTypeUniqueGift extends StoryAreaType { + private static final String TYPE = "unique_gift"; + private static final String NAME_FIELD = "name"; + + /** + * Unique name of the gift + */ + @JsonProperty(NAME_FIELD) + @NonNull + private String name; + + @Override + public void validate() throws TelegramApiValidationException { + if (name.isEmpty()) { + throw new TelegramApiValidationException("Name parameter can't be empty", this); + } + } + + @Override + public String getType() { + return TYPE; + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/area/StoryAreaTypeWeather.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/area/StoryAreaTypeWeather.java new file mode 100644 index 000000000..317cb2af7 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/area/StoryAreaTypeWeather.java @@ -0,0 +1,63 @@ +package org.telegram.telegrambots.meta.api.objects.stories.area; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * Describes a story area containing weather information. + * Currently, a story can have up to 3 weather areas. + */ +@EqualsAndHashCode(callSuper = true) +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +@SuperBuilder +public class StoryAreaTypeWeather extends StoryAreaType { + private static final String TYPE = "weather"; + private static final String TEMPERATURE_FIELD = "temperature"; + private static final String EMOJI_FIELD = "emoji"; + private static final String BACKGROUND_COLOR_FIELD = "background_color"; + + /** + * Temperature, in degree Celsius + */ + @JsonProperty(TEMPERATURE_FIELD) + @NonNull + private Float temperature; + + /** + * Emoji representing the weather + */ + @JsonProperty(EMOJI_FIELD) + @NonNull + private String emoji; + + /** + * A color of the area background in the ARGB format + */ + @JsonProperty(BACKGROUND_COLOR_FIELD) + @NonNull + private Integer backgroundColor; + + @Override + public void validate() throws TelegramApiValidationException { + if (emoji.isEmpty()) { + throw new TelegramApiValidationException("Emoji parameter can't be empty", this); + } + } + + @Override + public String getType() { + return TYPE; + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/input/InputStoryContent.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/input/InputStoryContent.java new file mode 100644 index 000000000..1872f51b3 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/input/InputStoryContent.java @@ -0,0 +1,42 @@ +package org.telegram.telegrambots.meta.api.objects.stories.input; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import lombok.AccessLevel; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.interfaces.Validable; + +/** + * This object describes the content of a story to post. Currently, it can be one of + * InputStoryContentPhoto + * InputStoryContentVideo + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@SuperBuilder +@JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, + include = JsonTypeInfo.As.EXISTING_PROPERTY, + property = "type", + defaultImpl = Void.class +) +@JsonSubTypes({ + @JsonSubTypes.Type(value = InputStoryContentPhoto.class, name = "photo"), + @JsonSubTypes.Type(value = InputStoryContentVideo.class, name = "video") +}) +public abstract class InputStoryContent implements Validable, BotApiObject { + public static final String TYPE_FIELD = "type"; + + @JsonProperty(TYPE_FIELD) + public abstract String getType(); +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/input/InputStoryContentPhoto.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/input/InputStoryContentPhoto.java new file mode 100644 index 000000000..1e63fa396 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/input/InputStoryContentPhoto.java @@ -0,0 +1,50 @@ +package org.telegram.telegrambots.meta.api.objects.stories.input; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * Describes a photo to post as a story. + * The photo must be of the size 1080x1920 and must not exceed 10 MB. + * The photo can't be reused and can only be uploaded as a new file. + */ +@EqualsAndHashCode(callSuper = true) +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +@SuperBuilder +public class InputStoryContentPhoto extends InputStoryContent { + private static final String TYPE = "photo"; + private static final String PHOTO_FIELD = "photo"; + + /** + * The photo to post as a story. The photo must be of the size 1080x1920 and must not exceed 10 MB. + * The photo can't be reused and can only be uploaded as a new file, so you can pass "attach://<file_attach_name>" + * if the photo was uploaded using multipart/form-data under <file_attach_name>. + */ + @JsonProperty(PHOTO_FIELD) + @NonNull + private String photo; + + @Override + public void validate() throws TelegramApiValidationException { + if (photo.isEmpty()) { + throw new TelegramApiValidationException("Photo can't be empty", this); + } + } + + @Override + public String getType() { + return TYPE; + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/input/InputStoryContentVideo.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/input/InputStoryContentVideo.java new file mode 100644 index 000000000..adb2d897b --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stories/input/InputStoryContentVideo.java @@ -0,0 +1,80 @@ +package org.telegram.telegrambots.meta.api.objects.stories.input; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * Describes a video to post as a story. + * The video must be of the size 720x1280, streamable, encoded with H.265 codec, + * with key frames added each second in the MPEG4 format, and must not exceed 30 MB. + * The video can't be reused and can only be uploaded as a new file. + */ +@EqualsAndHashCode(callSuper = true) +@Getter +@Setter +@ToString +@NoArgsConstructor +@RequiredArgsConstructor +@AllArgsConstructor +@SuperBuilder +public class InputStoryContentVideo extends InputStoryContent { + private static final String TYPE = "video"; + private static final String VIDEO_FIELD = "video"; + private static final String DURATION_FIELD = "duration"; + private static final String COVER_FRAME_TIMESTAMP_FIELD = "cover_frame_timestamp"; + private static final String IS_ANIMATION_FIELD = "is_animation"; + + /** + * The video to post as a story. The video must be of the size 720x1280, streamable, encoded with H.265 codec, + * with key frames added each second in the MPEG4 format, and must not exceed 30 MB. + * The video can't be reused and can only be uploaded as a new file, so you can pass "attach://<file_attach_name>" + * if the video was uploaded using multipart/form-data under <file_attach_name>. + */ + @JsonProperty(VIDEO_FIELD) + @NonNull + private String video; + + /** + * Optional. Precise duration of the video in seconds; 0-60 + */ + @JsonProperty(DURATION_FIELD) + private Float duration; + + /** + * Optional. Timestamp in seconds of the frame that will be used as the static cover for the story. + * Defaults to 0.0. + */ + @JsonProperty(COVER_FRAME_TIMESTAMP_FIELD) + private Float coverFrameTimestamp; + + /** + * Optional. Pass True if the video has no sound + */ + @JsonProperty(IS_ANIMATION_FIELD) + private Boolean isAnimation; + + @Override + public void validate() throws TelegramApiValidationException { + if (video.isEmpty()) { + throw new TelegramApiValidationException("Video can't be empty", this); + } + + if (duration != null && (duration < 0 || duration > 60)) { + throw new TelegramApiValidationException("Duration must be between 0 and 60 seconds", this); + } + } + + @Override + public String getType() { + return TYPE; + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/generics/TelegramClient.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/generics/TelegramClient.java index 74495b8e7..57ccfe594 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/generics/TelegramClient.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/generics/TelegramClient.java @@ -1,6 +1,7 @@ package org.telegram.telegrambots.meta.generics; import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethod; +import org.telegram.telegrambots.meta.api.methods.business.SetBusinessAccountProfilePhoto; import org.telegram.telegrambots.meta.api.methods.groupadministration.SetChatPhoto; import org.telegram.telegrambots.meta.api.methods.send.SendAnimation; import org.telegram.telegrambots.meta.api.methods.send.SendAudio; @@ -47,6 +48,8 @@ public interface TelegramClient { Message execute(SendSticker sendSticker) throws TelegramApiException; + Boolean execute(SetBusinessAccountProfilePhoto setBusinessAccountProfilePhoto) throws TelegramApiException; + /** * Sends a file using Send Audio method * @param sendAudio Information to send @@ -269,6 +272,13 @@ default InputStream downloadFileAsStream(String filePath) throws TelegramApiExce */ CompletableFuture executeAsync(SendAnimation sendAnimation); + /** + * Set Business Account Profile Photo + * @param setBusinessAccountProfilePhoto Information of the animation + * @return True on success + */ + CompletableFuture executeAsync(SetBusinessAccountProfilePhoto setBusinessAccountProfilePhoto); + CompletableFuture downloadFileAsync(File file); @SuppressWarnings("unused") diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/business/TestReadBusinessMessage.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/business/TestReadBusinessMessage.java new file mode 100644 index 000000000..a4b346f4e --- /dev/null +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/business/TestReadBusinessMessage.java @@ -0,0 +1,64 @@ +package org.telegram.telegrambots.meta.api.methods.business; + +import org.junit.jupiter.api.Test; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; + +/** + * @author Ruben Bermudez + * @version 9.0 + */ +public class TestReadBusinessMessage { + + @Test + public void testReadBusinessMessageGetPath() { + ReadBusinessMessage readBusinessMessage = ReadBusinessMessage.builder() + .businessConnectionId("test-connection-id") + .chatId(123456789L) + .messageId(987654321L) + .build(); + + assertEquals("readBusinessMessage", readBusinessMessage.getMethod()); + } + + @Test + public void testReadBusinessMessageValidation() { + ReadBusinessMessage readBusinessMessage = ReadBusinessMessage.builder() + .businessConnectionId("test-connection-id") + .chatId(123456789L) + .messageId(987654321L) + .build(); + + // Should not throw an exception + try { + readBusinessMessage.validate(); + } catch (TelegramApiValidationException e) { + fail(); + } + + // Test with empty business connection ID + ReadBusinessMessage invalidReadBusinessMessage = ReadBusinessMessage.builder() + .businessConnectionId("") + .chatId(123456789L) + .messageId(987654321L) + .build(); + + assertThrows(TelegramApiValidationException.class, invalidReadBusinessMessage::validate); + } + + @Test + public void testReadBusinessMessageGetters() { + ReadBusinessMessage readBusinessMessage = ReadBusinessMessage.builder() + .businessConnectionId("test-connection-id") + .chatId(123456789L) + .messageId(987654321L) + .build(); + + assertEquals("test-connection-id", readBusinessMessage.getBusinessConnectionId()); + assertEquals(Long.valueOf(123456789L), readBusinessMessage.getChatId()); + assertEquals(Long.valueOf(987654321L), readBusinessMessage.getMessageId()); + } +} diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/business/TestRemoveBusinessAccountProfilePhoto.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/business/TestRemoveBusinessAccountProfilePhoto.java new file mode 100644 index 000000000..6979bc30d --- /dev/null +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/business/TestRemoveBusinessAccountProfilePhoto.java @@ -0,0 +1,56 @@ +package org.telegram.telegrambots.meta.api.methods.business; + +import org.junit.jupiter.api.Test; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; + +/** + * @author Ruben Bermudez + * @version 9.0 + */ +public class TestRemoveBusinessAccountProfilePhoto { + + @Test + public void testRemoveBusinessAccountProfilePhotoGetPath() { + RemoveBusinessAccountProfilePhoto removeBusinessAccountProfilePhoto = RemoveBusinessAccountProfilePhoto.builder() + .businessConnectionId("test-connection-id") + .build(); + + assertEquals("removeBusinessAccountProfilePhoto", removeBusinessAccountProfilePhoto.getMethod()); + } + + @Test + public void testRemoveBusinessAccountProfilePhotoValidation() { + RemoveBusinessAccountProfilePhoto removeBusinessAccountProfilePhoto = RemoveBusinessAccountProfilePhoto.builder() + .businessConnectionId("test-connection-id") + .build(); + + // Should not throw an exception + try { + removeBusinessAccountProfilePhoto.validate(); + } catch (TelegramApiValidationException e) { + fail(); + } + + // Test with empty business connection ID + RemoveBusinessAccountProfilePhoto invalidRemoveBusinessAccountProfilePhoto = RemoveBusinessAccountProfilePhoto.builder() + .businessConnectionId("") + .build(); + + assertThrows(TelegramApiValidationException.class, invalidRemoveBusinessAccountProfilePhoto::validate); + } + + @Test + public void testRemoveBusinessAccountProfilePhotoWithIsPublic() { + RemoveBusinessAccountProfilePhoto removeBusinessAccountProfilePhoto = RemoveBusinessAccountProfilePhoto.builder() + .businessConnectionId("test-connection-id") + .isPublic(true) + .build(); + + assertEquals(true, removeBusinessAccountProfilePhoto.getIsPublic()); + assertEquals("test-connection-id", removeBusinessAccountProfilePhoto.getBusinessConnectionId()); + } +} diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/business/TestSetBusinessAccountName.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/business/TestSetBusinessAccountName.java new file mode 100644 index 000000000..1e593a0f2 --- /dev/null +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/business/TestSetBusinessAccountName.java @@ -0,0 +1,96 @@ +package org.telegram.telegrambots.meta.api.methods.business; + +import org.junit.jupiter.api.Test; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; + +/** + * @author Ruben Bermudez + * @version 9.0 + */ +public class TestSetBusinessAccountName { + + @Test + public void testSetBusinessAccountNameGetPath() { + SetBusinessAccountName setBusinessAccountName = SetBusinessAccountName.builder() + .businessConnectionId("test-connection-id") + .firstName("Test First Name") + .build(); + + assertEquals("setBusinessAccountName", setBusinessAccountName.getMethod()); + } + + @Test + public void testSetBusinessAccountNameValidation() { + SetBusinessAccountName setBusinessAccountName = SetBusinessAccountName.builder() + .businessConnectionId("test-connection-id") + .firstName("Test First Name") + .build(); + + // Should not throw an exception + try { + setBusinessAccountName.validate(); + } catch (TelegramApiValidationException e) { + fail(); + } + + // Test with empty business connection ID + SetBusinessAccountName emptyConnectionId = SetBusinessAccountName.builder() + .businessConnectionId("") + .firstName("Test First Name") + .build(); + + assertThrows(TelegramApiValidationException.class, emptyConnectionId::validate); + + // Test with empty first name + SetBusinessAccountName emptyFirstName = SetBusinessAccountName.builder() + .businessConnectionId("test-connection-id") + .firstName("") + .build(); + + assertThrows(TelegramApiValidationException.class, emptyFirstName::validate); + + // Test with first name exceeding max length + StringBuilder longFirstName = new StringBuilder(); + for (int i = 0; i < 65; i++) { + longFirstName.append("a"); + } + + SetBusinessAccountName longFirstNameObj = SetBusinessAccountName.builder() + .businessConnectionId("test-connection-id") + .firstName(longFirstName.toString()) + .build(); + + assertThrows(TelegramApiValidationException.class, longFirstNameObj::validate); + + // Test with last name exceeding max length + StringBuilder longLastName = new StringBuilder(); + for (int i = 0; i < 65; i++) { + longLastName.append("a"); + } + + SetBusinessAccountName longLastNameObj = SetBusinessAccountName.builder() + .businessConnectionId("test-connection-id") + .firstName("Test First Name") + .lastName(longLastName.toString()) + .build(); + + assertThrows(TelegramApiValidationException.class, longLastNameObj::validate); + } + + @Test + public void testSetBusinessAccountNameWithLastName() { + SetBusinessAccountName setBusinessAccountName = SetBusinessAccountName.builder() + .businessConnectionId("test-connection-id") + .firstName("Test First Name") + .lastName("Test Last Name") + .build(); + + assertEquals("test-connection-id", setBusinessAccountName.getBusinessConnectionId()); + assertEquals("Test First Name", setBusinessAccountName.getFirstName()); + assertEquals("Test Last Name", setBusinessAccountName.getLastName()); + } +} diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/business/TestSetBusinessAccountProfilePhoto.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/business/TestSetBusinessAccountProfilePhoto.java new file mode 100644 index 000000000..b19d6fe70 --- /dev/null +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/business/TestSetBusinessAccountProfilePhoto.java @@ -0,0 +1,94 @@ +package org.telegram.telegrambots.meta.api.methods.business; + +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.objects.InputFile; +import org.telegram.telegrambots.meta.api.objects.photo.input.InputProfilePhoto; +import org.telegram.telegrambots.meta.api.objects.photo.input.InputProfilePhotoStatic; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; + +/** + * @author Ruben Bermudez + * @version 9.0 + */ +public class TestSetBusinessAccountProfilePhoto { + + @Test + public void testSetBusinessAccountProfilePhotoGetPath() { + InputProfilePhoto photo = InputProfilePhotoStatic.builder() + .photo(new InputFile("test-photo-id")) + .build(); + + SetBusinessAccountProfilePhoto setBusinessAccountProfilePhoto = SetBusinessAccountProfilePhoto.builder() + .businessConnectionId("test-connection-id") + .photo(photo) + .build(); + + assertEquals("setBusinessAccountProfilePhoto", setBusinessAccountProfilePhoto.getMethod()); + } + + @Test + public void testSetBusinessAccountProfilePhotoValidation() { + InputProfilePhoto photo = InputProfilePhotoStatic.builder() + .photo(new InputFile("test-photo-id")) + .build(); + + SetBusinessAccountProfilePhoto setBusinessAccountProfilePhoto = SetBusinessAccountProfilePhoto.builder() + .businessConnectionId("test-connection-id") + .photo(photo) + .build(); + + // Should not throw an exception + try { + setBusinessAccountProfilePhoto.validate(); + } catch (TelegramApiValidationException e) { + fail(); + } + + // Test with empty business connection ID + SetBusinessAccountProfilePhoto invalidSetBusinessAccountProfilePhoto = SetBusinessAccountProfilePhoto.builder() + .businessConnectionId("") + .photo(photo) + .build(); + + assertThrows(TelegramApiValidationException.class, invalidSetBusinessAccountProfilePhoto::validate); + + // Test with invalid photo + InputProfilePhoto invalidPhoto = Mockito.mock(InputProfilePhoto.class); + try { + Mockito.doThrow(new TelegramApiValidationException("Invalid photo", (BotApiObject) null)) + .when(invalidPhoto).validate(); + } catch (TelegramApiValidationException e) { + fail(); + } + + SetBusinessAccountProfilePhoto withInvalidPhoto = SetBusinessAccountProfilePhoto.builder() + .businessConnectionId("test-connection-id") + .photo(invalidPhoto) + .build(); + + assertThrows(TelegramApiValidationException.class, withInvalidPhoto::validate); + } + + @Test + public void testSetBusinessAccountProfilePhotoWithIsPublic() { + InputProfilePhoto photo = InputProfilePhotoStatic.builder() + .photo(new InputFile("test-photo-id")) + .build(); + + SetBusinessAccountProfilePhoto setBusinessAccountProfilePhoto = SetBusinessAccountProfilePhoto.builder() + .businessConnectionId("test-connection-id") + .photo(photo) + .isPublic(true) + .build(); + + assertEquals(true, setBusinessAccountProfilePhoto.getIsPublic()); + assertEquals("test-connection-id", setBusinessAccountProfilePhoto.getBusinessConnectionId()); + assertEquals(photo, setBusinessAccountProfilePhoto.getPhoto()); + } +} diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/gifts/TestGiftPremiumSubscription.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/gifts/TestGiftPremiumSubscription.java new file mode 100644 index 000000000..229bf2406 --- /dev/null +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/gifts/TestGiftPremiumSubscription.java @@ -0,0 +1,92 @@ +package org.telegram.telegrambots.meta.api.methods.gifts; + +import org.junit.jupiter.api.Test; +import org.telegram.telegrambots.meta.api.objects.MessageEntity; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; + +/** + * @author Ruben Bermudez + * @version 9.0 + */ +public class TestGiftPremiumSubscription { + + @Test + public void testGiftPremiumSubscriptionGetPath() { + GiftPremiumSubscription giftPremiumSubscription = GiftPremiumSubscription.builder() + .userId(123456789L) + .monthCount(3) + .starCount(1000) + .build(); + + assertEquals("giftPremiumSubscription", giftPremiumSubscription.getMethod()); + } + + @Test + public void testGiftPremiumSubscriptionValidation() { + GiftPremiumSubscription giftPremiumSubscription = GiftPremiumSubscription.builder() + .userId(123456789L) + .monthCount(3) + .starCount(1000) + .build(); + + // Should not throw an exception + try { + giftPremiumSubscription.validate(); + } catch (TelegramApiValidationException e) { + fail(); + } + + // Test with long text + StringBuilder longText = new StringBuilder(); + for (int i = 0; i < 129; i++) { + longText.append("a"); + } + + GiftPremiumSubscription withLongText = GiftPremiumSubscription.builder() + .userId(123456789L) + .monthCount(3) + .starCount(1000) + .text(longText.toString()) + .build(); + + assertThrows(TelegramApiValidationException.class, withLongText::validate); + + // Test with empty text + GiftPremiumSubscription withEmptyText = GiftPremiumSubscription.builder() + .userId(123456789L) + .monthCount(3) + .starCount(1000) + .text("") + .build(); + + assertThrows(TelegramApiValidationException.class, withEmptyText::validate); + } + + @Test + public void testGiftPremiumSubscriptionWithOptionalParams() { + List entities = new ArrayList<>(); + + GiftPremiumSubscription giftPremiumSubscription = GiftPremiumSubscription.builder() + .userId(123456789L) + .monthCount(3) + .starCount(1000) + .text("Gift message") + .textParseMode("Markdown") + .textEntities(entities) + .build(); + + assertEquals(123456789L, giftPremiumSubscription.getUserId()); + assertEquals(Integer.valueOf(3), giftPremiumSubscription.getMonthCount()); + assertEquals(Integer.valueOf(1000), giftPremiumSubscription.getStarCount()); + assertEquals("Gift message", giftPremiumSubscription.getText()); + assertEquals("Markdown", giftPremiumSubscription.getTextParseMode()); + assertEquals(entities, giftPremiumSubscription.getTextEntities()); + } +} diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/gifts/TestTransferGift.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/gifts/TestTransferGift.java new file mode 100644 index 000000000..12a1cffc9 --- /dev/null +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/gifts/TestTransferGift.java @@ -0,0 +1,75 @@ +package org.telegram.telegrambots.meta.api.methods.gifts; + +import org.junit.jupiter.api.Test; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; + +/** + * @author Ruben Bermudez + * @version 9.0 + */ +public class TestTransferGift { + + @Test + public void testTransferGiftGetPath() { + TransferGift transferGift = TransferGift.builder() + .businessConnectionId("test-connection-id") + .ownedGiftId("test-gift-id") + .newOwnerChatId(123456789L) + .build(); + + assertEquals("transferGift", transferGift.getMethod()); + } + + @Test + public void testTransferGiftValidation() { + TransferGift transferGift = TransferGift.builder() + .businessConnectionId("test-connection-id") + .ownedGiftId("test-gift-id") + .newOwnerChatId(123456789L) + .build(); + + // Should not throw an exception + try { + transferGift.validate(); + } catch (TelegramApiValidationException e) { + fail(); + } + + // Test with empty business connection ID + TransferGift emptyBusinessConnectionId = TransferGift.builder() + .businessConnectionId("") + .ownedGiftId("test-gift-id") + .newOwnerChatId(123456789L) + .build(); + + assertThrows(TelegramApiValidationException.class, emptyBusinessConnectionId::validate); + + // Test with empty owned gift ID + TransferGift emptyOwnedGiftId = TransferGift.builder() + .businessConnectionId("test-connection-id") + .ownedGiftId("") + .newOwnerChatId(123456789L) + .build(); + + assertThrows(TelegramApiValidationException.class, emptyOwnedGiftId::validate); + } + + @Test + public void testTransferGiftWithStarCount() { + TransferGift transferGift = TransferGift.builder() + .businessConnectionId("test-connection-id") + .ownedGiftId("test-gift-id") + .newOwnerChatId(123456789L) + .starCount(100) + .build(); + + assertEquals("test-connection-id", transferGift.getBusinessConnectionId()); + assertEquals("test-gift-id", transferGift.getOwnedGiftId()); + assertEquals(Long.valueOf(123456789L), transferGift.getNewOwnerChatId()); + assertEquals(Integer.valueOf(100), transferGift.getStarCount()); + } +} diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/stories/TestDeleteStory.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/stories/TestDeleteStory.java new file mode 100644 index 000000000..86d614266 --- /dev/null +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/stories/TestDeleteStory.java @@ -0,0 +1,57 @@ +package org.telegram.telegrambots.meta.api.methods.stories; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; + +/** + * @author Ruben Bermudez + * @version 9.0 + */ +public class TestDeleteStory { + private final ObjectMapper mapper = new ObjectMapper(); + + @Test + public void testJsonSerialization() { + try { + String expectedJson = "{\"business_connection_id\":\"12345\",\"story_id\":67890,\"method\":\"deleteStory\"}"; + + DeleteStory deleteStory = DeleteStory.builder() + .businessConnectionId("12345") + .storyId(67890) + .build(); + + String json = mapper.writeValueAsString(deleteStory); + assertEquals(expectedJson, json); + } catch (Exception e) { + fail(e); + } + } + + @Test + public void testValidation() { + // Valid case + try { + DeleteStory validMethod = DeleteStory.builder() + .businessConnectionId("12345") + .storyId(67890) + .build(); + validMethod.validate(); + } catch (TelegramApiValidationException e) { + fail("Validation should not fail for valid method"); + } + + // Invalid case - empty businessConnectionId + assertThrows(TelegramApiValidationException.class, () -> { + DeleteStory invalidMethod = DeleteStory.builder() + .businessConnectionId("") + .storyId(67890) + .build(); + invalidMethod.validate(); + }); + } +} diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/stories/TestEditStory.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/stories/TestEditStory.java new file mode 100644 index 000000000..2c0f97c18 --- /dev/null +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/stories/TestEditStory.java @@ -0,0 +1,132 @@ +package org.telegram.telegrambots.meta.api.methods.stories; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; +import org.telegram.telegrambots.meta.api.objects.MessageEntity; +import org.telegram.telegrambots.meta.api.objects.stories.StoryArea; +import org.telegram.telegrambots.meta.api.objects.stories.StoryAreaPosition; +import org.telegram.telegrambots.meta.api.objects.stories.area.StoryAreaTypeLink; +import org.telegram.telegrambots.meta.api.objects.stories.input.InputStoryContentPhoto; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +import java.util.Collections; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; + +/** + * @author Ruben Bermudez + * @version 9.0 + */ +public class TestEditStory { + private final ObjectMapper mapper = new ObjectMapper(); + + @Test + public void testJsonSerialization() { + try { + InputStoryContentPhoto content = InputStoryContentPhoto.builder() + .photo("test_photo.jpg") + .build(); + + MessageEntity entity = new MessageEntity("bold", 0, 4); + + StoryArea area = StoryArea + .builder() + .type(new StoryAreaTypeLink("https://t.me/test")) + .position(StoryAreaPosition + .builder() + .xPercentage(0.1f) + .yPercentage(0.2f) + .widthPercentage(0.3f) + .heightPercentage(0.4f) + .rotationAngle(0.0f) + .cornerRadiusPercentage(0.0f) + .build()) + .build(); + + String expectedJson = "{\"business_connection_id\":\"12345\",\"story_id\":67890,\"content\":{\"photo\":" + + "\"test_photo.jpg\",\"type\":\"photo\"},\"caption\":\"Test Caption\",\"parse_mode\":\"HTML\"," + + "\"caption_entities\":[{\"type\":\"bold\",\"offset\":0,\"length\":4}],\"areas\":[{\"position\":" + + "{\"x_percentage\":0.1,\"y_percentage\":0.2,\"width_percentage\":0.3,\"height_percentage\":0.4," + + "\"rotation_angle\":0.0,\"corner_radius_percentage\":0.0},\"type\":{\"url\":\"https://t.me/test\"," + + "\"type\":\"link\"}}],\"method\":\"editStory\"}"; + + EditStory editStory = EditStory.builder() + .businessConnectionId("12345") + .storyId(67890) + .content(content) + .caption("Test Caption") + .parseMode("HTML") + .captionEntities(Collections.singletonList(entity)) + .areas(Collections.singletonList(area)) + .build(); + + String json = mapper.writeValueAsString(editStory); + assertEquals(expectedJson, json); + } catch (Exception e) { + fail(e); + } + } + + @Test + public void testValidation() { + InputStoryContentPhoto validContent = InputStoryContentPhoto.builder() + .photo("test_photo.jpg") + .build(); + + StoryArea validArea = StoryArea + .builder() + .type(new StoryAreaTypeLink("https://t.me/test")) + .position(StoryAreaPosition + .builder() + .xPercentage(0.1f) + .yPercentage(0.2f) + .widthPercentage(0.3f) + .heightPercentage(0.4f) + .rotationAngle(0.0f) + .cornerRadiusPercentage(0.0f) + .build()) + .build(); + + // Valid case + try { + EditStory validMethod = EditStory.builder() + .businessConnectionId("12345") + .storyId(67890) + .content(validContent) + .caption("Test Caption") + .areas(Collections.singletonList(validArea)) + .build(); + validMethod.validate(); + } catch (TelegramApiValidationException e) { + fail("Validation should not fail for valid method"); + } + + // Invalid case - empty businessConnectionId + assertThrows(TelegramApiValidationException.class, () -> { + EditStory invalidMethod = EditStory.builder() + .businessConnectionId("") + .storyId(67890) + .content(validContent) + .build(); + invalidMethod.validate(); + }); + + // Invalid case - caption too long + assertThrows(TelegramApiValidationException.class, () -> { + StringBuilder longCaption = new StringBuilder(); + for (int i = 0; i < 2049; i++) { + longCaption.append("a"); + } + + EditStory invalidMethod = EditStory.builder() + .businessConnectionId("12345") + .storyId(67890) + .content(validContent) + .caption(longCaption.toString()) + .build(); + invalidMethod.validate(); + }); + } +} diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/TestDocument.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/TestDocument.java index fa0e76099..19c9d6320 100644 --- a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/TestDocument.java +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/TestDocument.java @@ -3,6 +3,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.telegram.telegrambots.meta.api.objects.photo.PhotoSize; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/business/TestBusinessLocation.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/business/TestBusinessLocation.java new file mode 100644 index 000000000..457859d54 --- /dev/null +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/business/TestBusinessLocation.java @@ -0,0 +1,61 @@ +package org.telegram.telegrambots.meta.api.objects.business; + +import org.junit.jupiter.api.Test; +import org.telegram.telegrambots.meta.api.objects.location.Location; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; + +/** + * @author Ruben Bermudez + * @version 9.0 + */ +public class TestBusinessLocation { + + @Test + public void testBusinessLocationConstructor() { + Location location = mock(Location.class); + + BusinessLocation businessLocation = BusinessLocation.builder() + .location(location) + .address("123 Main St, New York, NY 10001") + .build(); + + assertEquals(location, businessLocation.getLocation()); + assertEquals("123 Main St, New York, NY 10001", businessLocation.getAddress()); + } + + @Test + public void testBusinessLocationWithAllFields() { + Location location = mock(Location.class); + + BusinessLocation businessLocation = BusinessLocation.builder() + .location(location) + .address("123 Main St, New York, NY 10001") + .build(); + + assertEquals(location, businessLocation.getLocation()); + assertEquals("123 Main St, New York, NY 10001", businessLocation.getAddress()); + } + + @Test + public void testBusinessLocationSettersAndGetters() { + Location location1 = mock(Location.class); + Location location2 = mock(Location.class); + + BusinessLocation businessLocation = BusinessLocation.builder() + .location(location1) + .address("Initial Address") + .build(); + + assertEquals(location1, businessLocation.getLocation()); + assertEquals("Initial Address", businessLocation.getAddress()); + + // Test setters + businessLocation.setLocation(location2); + businessLocation.setAddress("Updated Address"); + + assertEquals(location2, businessLocation.getLocation()); + assertEquals("Updated Address", businessLocation.getAddress()); + } +} diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/gifts/TestUniqueGiftModel.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/gifts/TestUniqueGiftModel.java new file mode 100644 index 000000000..f735bc5ad --- /dev/null +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/gifts/TestUniqueGiftModel.java @@ -0,0 +1,54 @@ +package org.telegram.telegrambots.meta.api.objects.gifts; + +import org.junit.jupiter.api.Test; +import org.telegram.telegrambots.meta.api.objects.stickers.Sticker; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; + +/** + * @author Ruben Bermudez + * @version 9.0 + */ +public class TestUniqueGiftModel { + + @Test + public void testUniqueGiftModelConstructor() { + Sticker sticker = mock(Sticker.class); + + UniqueGiftModel uniqueGiftModel = UniqueGiftModel.builder() + .name("Test Gift Model") + .sticker(sticker) + .rarityPerMille(100) + .build(); + + assertEquals("Test Gift Model", uniqueGiftModel.getName()); + assertEquals(sticker, uniqueGiftModel.getSticker()); + assertEquals(Integer.valueOf(100), uniqueGiftModel.getRarityPerMille()); + } + + @Test + public void testUniqueGiftModelSettersAndGetters() { + Sticker sticker1 = mock(Sticker.class); + Sticker sticker2 = mock(Sticker.class); + + UniqueGiftModel uniqueGiftModel = UniqueGiftModel.builder() + .name("Initial Name") + .sticker(sticker1) + .rarityPerMille(100) + .build(); + + assertEquals("Initial Name", uniqueGiftModel.getName()); + assertEquals(sticker1, uniqueGiftModel.getSticker()); + assertEquals(Integer.valueOf(100), uniqueGiftModel.getRarityPerMille()); + + // Test setters + uniqueGiftModel.setName("Updated Name"); + uniqueGiftModel.setSticker(sticker2); + uniqueGiftModel.setRarityPerMille(200); + + assertEquals("Updated Name", uniqueGiftModel.getName()); + assertEquals(sticker2, uniqueGiftModel.getSticker()); + assertEquals(Integer.valueOf(200), uniqueGiftModel.getRarityPerMille()); + } +} diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/location/TestLocation.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/location/TestLocation.java new file mode 100644 index 000000000..240e6cdec --- /dev/null +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/location/TestLocation.java @@ -0,0 +1,67 @@ +package org.telegram.telegrambots.meta.api.objects.location; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +/** + * @author Ruben Bermudez + * @version 9.0 + */ +public class TestLocation { + + @Test + public void testLocationConstructor() { + Location location = Location.builder() + .latitude(40.7128d) + .longitude(-74.0060d) + .build(); + + assertEquals(40.7128d, location.getLatitude()); + assertEquals(-74.0060d, location.getLongitude()); + assertNull(location.getHorizontalAccuracy()); + assertNull(location.getLivePeriod()); + assertNull(location.getHeading()); + assertNull(location.getProximityAlertRadius()); + } + + @Test + public void testLocationWithAllFields() { + Location location = Location.builder() + .latitude(40.7128d) + .longitude(-74.0060d) + .horizontalAccuracy(50.0d) + .livePeriod(300) + .heading(90) + .proximityAlertRadius(200) + .build(); + + assertEquals(40.7128d, location.getLatitude()); + assertEquals(-74.0060d, location.getLongitude()); + assertEquals(50.0f, location.getHorizontalAccuracy()); + assertEquals(300, location.getLivePeriod()); + assertEquals(90, location.getHeading()); + assertEquals(200, location.getProximityAlertRadius()); + } + + @Test + public void testLocationSettersAndGetters() { + Location location = Location.builder() + .latitude(40.7128d) + .longitude(-74.0060d) + .build(); + + location.setHorizontalAccuracy(50.0d); + location.setLivePeriod(300); + location.setHeading(90); + location.setProximityAlertRadius(200); + + assertEquals(40.7128d, location.getLatitude()); + assertEquals(-74.0060d, location.getLongitude()); + assertEquals(50.0f, location.getHorizontalAccuracy()); + assertEquals(300, location.getLivePeriod()); + assertEquals(90, location.getHeading()); + assertEquals(200, location.getProximityAlertRadius()); + } +} diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/location/TestLocationAddress.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/location/TestLocationAddress.java new file mode 100644 index 000000000..45d2106a4 --- /dev/null +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/location/TestLocationAddress.java @@ -0,0 +1,68 @@ +package org.telegram.telegrambots.meta.api.objects.location; + +import org.junit.jupiter.api.Test; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; + +/** + * @author Ruben Bermudez + * @version 9.0 + */ +public class TestLocationAddress { + + @Test + public void testLocationAddressConstructor() { + LocationAddress locationAddress = LocationAddress.builder() + .street("123 Main St") + .city("New York") + .countryCode("US") + .build(); + + assertEquals("123 Main St", locationAddress.getStreet()); + assertEquals("New York", locationAddress.getCity()); + assertEquals("US", locationAddress.getCountryCode()); + } + + @Test + public void testLocationAddressWithAllFields() { + LocationAddress locationAddress = LocationAddress.builder() + .street("123 Main St") + .city("New York") + .state("NY") + .countryCode("US") + .build(); + + assertEquals("123 Main St", locationAddress.getStreet()); + assertEquals("New York", locationAddress.getCity()); + assertEquals("NY", locationAddress.getState()); + assertEquals("US", locationAddress.getCountryCode()); + } + + @Test + public void testLocationAddressValidation() { + LocationAddress locationAddress = LocationAddress.builder() + .street("123 Main St") + .city("New York") + .countryCode("US") + .build(); + + // Should not throw an exception + try { + locationAddress.validate(); + } catch (TelegramApiValidationException e) { + fail(); + } + + // Test with empty country code + LocationAddress emptyCountryCode = LocationAddress.builder() + .street("123 Main St") + .city("New York") + .countryCode("") + .build(); + + assertThrows(TelegramApiValidationException.class, emptyCountryCode::validate); + } +} diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/media/paid/TestInputPaidMedia.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/media/paid/TestInputPaidMedia.java new file mode 100644 index 000000000..a70983a1d --- /dev/null +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/media/paid/TestInputPaidMedia.java @@ -0,0 +1,78 @@ +package org.telegram.telegrambots.meta.api.objects.media.paid; + +import org.junit.jupiter.api.Test; +import org.telegram.telegrambots.meta.api.objects.InputFile; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +/** + * @author Ruben Bermudez + * @version 7.5 + */ +public class TestInputPaidMedia { + + @Test + public void testInputPaidMediaPhotoType() { + InputPaidMediaPhoto inputPaidMediaPhoto = new InputPaidMediaPhoto("test-media-id"); + assertEquals("photo", inputPaidMediaPhoto.getType()); + } + + @Test + public void testInputPaidMediaPhotoConstructor() { + InputPaidMediaPhoto inputPaidMediaPhoto = new InputPaidMediaPhoto("test-media-id"); + assertEquals("test-media-id", inputPaidMediaPhoto.getMedia()); + } + + @Test + public void testInputPaidMediaVideoType() { + InputPaidMediaVideo inputPaidMediaVideo = new InputPaidMediaVideo("test-media-id"); + assertEquals("photo", inputPaidMediaVideo.getType()); + } + + @Test + public void testInputPaidMediaVideoConstructor() { + InputPaidMediaVideo inputPaidMediaVideo = new InputPaidMediaVideo("test-media-id"); + assertEquals("test-media-id", inputPaidMediaVideo.getMedia()); + } + + @Test + public void testInputPaidMediaVideoWithOptionalParams() { + InputFile thumbnail = new InputFile("thumbnail-id"); + InputFile cover = new InputFile("cover-id"); + + InputPaidMediaVideo inputPaidMediaVideo = InputPaidMediaVideo.builder() + .media("test-media-id") + .width(640) + .height(480) + .duration(30) + .supportsStreaming(true) + .thumbnail(thumbnail) + .startTimestamp(5) + .cover(cover) + .build(); + + assertEquals("test-media-id", inputPaidMediaVideo.getMedia()); + assertEquals(Integer.valueOf(640), inputPaidMediaVideo.getWidth()); + assertEquals(Integer.valueOf(480), inputPaidMediaVideo.getHeight()); + assertEquals(Integer.valueOf(30), inputPaidMediaVideo.getDuration()); + assertEquals(Boolean.TRUE, inputPaidMediaVideo.getSupportsStreaming()); + assertEquals(thumbnail, inputPaidMediaVideo.getThumbnail()); + assertEquals(Integer.valueOf(5), inputPaidMediaVideo.getStartTimestamp()); + assertEquals(cover, inputPaidMediaVideo.getCover()); + } + + @Test + public void testInputPaidMediaVideoWithoutOptionalParams() { + InputPaidMediaVideo inputPaidMediaVideo = new InputPaidMediaVideo("test-media-id"); + + assertEquals("test-media-id", inputPaidMediaVideo.getMedia()); + assertNull(inputPaidMediaVideo.getWidth()); + assertNull(inputPaidMediaVideo.getHeight()); + assertNull(inputPaidMediaVideo.getDuration()); + assertNull(inputPaidMediaVideo.getSupportsStreaming()); + assertNull(inputPaidMediaVideo.getThumbnail()); + assertNull(inputPaidMediaVideo.getStartTimestamp()); + assertNull(inputPaidMediaVideo.getCover()); + } +} diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/payments/star/TestStarTransactions.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/payments/star/TestStarTransactions.java index fd7ec1bbb..9afe96089 100644 --- a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/payments/star/TestStarTransactions.java +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/payments/star/TestStarTransactions.java @@ -68,6 +68,7 @@ public void testTransactionPartner() { .amount(100) .source(TransactionPartnerUser .builder() + .transactionType("gift_purchase") .user(User .builder() .id(1L) @@ -77,6 +78,7 @@ public void testTransactionPartner() { .build()) .receiver(TransactionPartnerUser .builder() + .transactionType("gift_purchase") .user(User .builder() .id(1L) diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/photo/TestPhotoSize.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/photo/TestPhotoSize.java new file mode 100644 index 000000000..25036fcb7 --- /dev/null +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/photo/TestPhotoSize.java @@ -0,0 +1,75 @@ +package org.telegram.telegrambots.meta.api.objects.photo; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +/** + * @author Ruben Bermudez + * @version 9.0 + */ +public class TestPhotoSize { + + @Test + public void testPhotoSizeConstructor() { + PhotoSize photoSize = PhotoSize.builder() + .fileId("test-file-id") + .fileUniqueId("test-file-unique-id") + .width(800) + .height(600) + .build(); + + assertEquals("test-file-id", photoSize.getFileId()); + assertEquals("test-file-unique-id", photoSize.getFileUniqueId()); + assertEquals(800, photoSize.getWidth()); + assertEquals(600, photoSize.getHeight()); + assertNull(photoSize.getFileSize()); + } + + @Test + public void testPhotoSizeWithAllFields() { + PhotoSize photoSize = PhotoSize.builder() + .fileId("test-file-id") + .fileUniqueId("test-file-unique-id") + .width(800) + .height(600) + .fileSize(1024) + .build(); + + assertEquals("test-file-id", photoSize.getFileId()); + assertEquals("test-file-unique-id", photoSize.getFileUniqueId()); + assertEquals(800, photoSize.getWidth()); + assertEquals(600, photoSize.getHeight()); + assertEquals(1024, photoSize.getFileSize()); + } + + @Test + public void testPhotoSizeSettersAndGetters() { + PhotoSize photoSize = PhotoSize.builder() + .fileId("initial-file-id") + .fileUniqueId("initial-file-unique-id") + .width(800) + .height(600) + .build(); + + assertEquals("initial-file-id", photoSize.getFileId()); + assertEquals("initial-file-unique-id", photoSize.getFileUniqueId()); + assertEquals(800, photoSize.getWidth()); + assertEquals(600, photoSize.getHeight()); + assertNull(photoSize.getFileSize()); + + // Test setters + photoSize.setFileId("updated-file-id"); + photoSize.setFileUniqueId("updated-file-unique-id"); + photoSize.setWidth(1024); + photoSize.setHeight(768); + photoSize.setFileSize(2048); + + assertEquals("updated-file-id", photoSize.getFileId()); + assertEquals("updated-file-unique-id", photoSize.getFileUniqueId()); + assertEquals(1024, photoSize.getWidth()); + assertEquals(768, photoSize.getHeight()); + assertEquals(2048, photoSize.getFileSize()); + } +} diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/photo/input/TestInputProfilePhoto.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/photo/input/TestInputProfilePhoto.java new file mode 100644 index 000000000..b79bb002f --- /dev/null +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/photo/input/TestInputProfilePhoto.java @@ -0,0 +1,49 @@ +package org.telegram.telegrambots.meta.api.objects.photo.input; + +import org.junit.jupiter.api.Test; +import org.telegram.telegrambots.meta.api.objects.InputFile; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; + +/** + * @author Ruben Bermudez + * @version 9.0 + */ +public class TestInputProfilePhoto { + + @Test + public void testInputProfilePhotoStaticType() { + InputFile inputFile = new InputFile("test-photo-id"); + InputProfilePhotoStatic profilePhoto = InputProfilePhotoStatic.builder() + .photo(inputFile) + .build(); + + assertEquals("static", profilePhoto.getType()); + } + + @Test + public void testInputProfilePhotoStaticValidation() { + InputFile inputFile = new InputFile("test-photo-id"); + InputProfilePhotoStatic profilePhoto = InputProfilePhotoStatic.builder() + .photo(inputFile) + .build(); + + // Should not throw an exception + try { + profilePhoto.validate(); + } catch (TelegramApiValidationException e) { + fail(); + } + + // Test with empty photo ID + InputFile invalidInputFile = new InputFile(""); + InputProfilePhotoStatic invalidProfilePhoto = InputProfilePhotoStatic.builder() + .photo(invalidInputFile) + .build(); + + assertThrows(TelegramApiValidationException.class, invalidProfilePhoto::validate); + } +} diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/photo/input/TestInputProfilePhotoAnimated.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/photo/input/TestInputProfilePhotoAnimated.java new file mode 100644 index 000000000..5e488eff7 --- /dev/null +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/photo/input/TestInputProfilePhotoAnimated.java @@ -0,0 +1,55 @@ +package org.telegram.telegrambots.meta.api.objects.photo.input; + +import org.junit.jupiter.api.Test; +import org.telegram.telegrambots.meta.api.objects.InputFile; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; + +/** + * @author Ruben Bermudez + * @version 9.0 + */ +public class TestInputProfilePhotoAnimated { + + @Test + public void testInputProfilePhotoAnimatedType() { + InputProfilePhotoAnimated profilePhoto = InputProfilePhotoAnimated.builder() + .animation(new InputFile("test-photo-id")) + .build(); + + assertEquals("animated", profilePhoto.getType()); + } + + @Test + public void testInputProfilePhotoAnimatedValidation() { + InputProfilePhotoAnimated profilePhoto = InputProfilePhotoAnimated.builder() + .animation(new InputFile("test-photo-id")) + .build(); + + // Should not throw an exception + try { + profilePhoto.validate(); + } catch (TelegramApiValidationException e) { + fail(); + } + + // Test with empty file ID + InputProfilePhotoAnimated invalidProfilePhoto = InputProfilePhotoAnimated.builder() + .animation(new InputFile("")) + .build(); + + assertThrows(TelegramApiValidationException.class, invalidProfilePhoto::validate); + } + + @Test + public void testInputProfilePhotoAnimatedGetters() { + InputProfilePhotoAnimated profilePhoto = InputProfilePhotoAnimated.builder() + .animation(new InputFile("test-file-id")) + .build(); + + assertEquals("test-file-id", profilePhoto.getAnimation().getAttachName()); + } +} diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/photo/input/TestInputProfilePhotoStatic.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/photo/input/TestInputProfilePhotoStatic.java new file mode 100644 index 000000000..ad7aa19ef --- /dev/null +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/photo/input/TestInputProfilePhotoStatic.java @@ -0,0 +1,68 @@ +package org.telegram.telegrambots.meta.api.objects.photo.input; + +import org.junit.jupiter.api.Test; +import org.telegram.telegrambots.meta.api.objects.InputFile; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; + +/** + * @author Ruben Bermudez + * @version 9.0 + */ +public class TestInputProfilePhotoStatic { + + @Test + public void testInputProfilePhotoStaticType() { + InputProfilePhotoStatic profilePhoto = InputProfilePhotoStatic.builder() + .photo(new InputFile("test-photo-id")) + .build(); + + assertEquals("static", profilePhoto.getType()); + } + + @Test + public void testInputProfilePhotoStaticValidation() { + InputProfilePhotoStatic profilePhoto = InputProfilePhotoStatic.builder() + .photo(new InputFile("test-photo-id")) + .build(); + + // Should not throw an exception + try { + profilePhoto.validate(); + } catch (TelegramApiValidationException e) { + fail(); + } + + // Test with empty photo ID + InputProfilePhotoStatic invalidProfilePhoto = InputProfilePhotoStatic.builder() + .photo(new InputFile("")) + .build(); + + assertThrows(TelegramApiValidationException.class, invalidProfilePhoto::validate); + } + + @Test + public void testInputProfilePhotoStaticGetters() { + InputProfilePhotoStatic profilePhoto = InputProfilePhotoStatic.builder() + .photo(new InputFile("test-photo-id")) + .build(); + + assertEquals("test-photo-id", profilePhoto.getPhoto().getAttachName()); + } + + @Test + public void testInputProfilePhotoStaticSetters() { + InputProfilePhotoStatic profilePhoto = InputProfilePhotoStatic.builder() + .photo(new InputFile("initial-photo-id")) + .build(); + + assertEquals("initial-photo-id", profilePhoto.getPhoto().getAttachName()); + + // Test setter + profilePhoto.setPhoto(new InputFile("updated-photo-id")); + assertEquals("updated-photo-id", profilePhoto.getPhoto().getAttachName()); + } +} diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/area/TestStoryAreaType.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/area/TestStoryAreaType.java new file mode 100644 index 000000000..e9773aabc --- /dev/null +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/area/TestStoryAreaType.java @@ -0,0 +1,54 @@ +package org.telegram.telegrambots.meta.api.objects.stories.area; + +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; +import static org.mockito.Mockito.mock; + +/** + * @author Ruben Bermudez + * @version 9.0 + */ +public class TestStoryAreaType { + + @Test + public void testStoryAreaTypeSubclasses() { + // Create a mock implementation of StoryAreaType for testing + StoryAreaType mockStoryAreaType = mock(StoryAreaType.class, Mockito.CALLS_REAL_METHODS); + + // Setup the mock to return a specific type when getType is called + Mockito.when(mockStoryAreaType.getType()).thenReturn("test-type"); + + assertEquals("test-type", mockStoryAreaType.getType()); + } + + @Test + public void testStoryAreaTypeValidation() { + // Create a mock implementation that will throw an exception during validation + StoryAreaType mockStoryAreaType = mock(StoryAreaType.class, Mockito.CALLS_REAL_METHODS); + + try { + Mockito.doThrow(new TelegramApiValidationException("Test validation error", (BotApiObject) null)) + .when(mockStoryAreaType).validate(); + } catch (TelegramApiValidationException e) { + fail(); + } + + assertThrows(TelegramApiValidationException.class, mockStoryAreaType::validate); + + // Create a mock implementation that will pass validation + StoryAreaType validMockStoryAreaType = mock(StoryAreaType.class, Mockito.CALLS_REAL_METHODS); + + try { + Mockito.doNothing().when(validMockStoryAreaType).validate(); + validMockStoryAreaType.validate(); + } catch (TelegramApiValidationException e) { + fail(); + } + } +} diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/area/TestStoryAreaTypeLink.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/area/TestStoryAreaTypeLink.java new file mode 100644 index 000000000..5dedb5c84 --- /dev/null +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/area/TestStoryAreaTypeLink.java @@ -0,0 +1,58 @@ +package org.telegram.telegrambots.meta.api.objects.stories.area; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; + +/** + * @author Ruben Bermudez + * @version 9.0 + */ +public class TestStoryAreaTypeLink { + private final ObjectMapper mapper = new ObjectMapper(); + + @Test + public void testJsonSerialization() { + try { + String expectedJson = "{\"url\":\"https://t.me/test\",\"type\":\"link\"}"; + + StoryAreaTypeLink storyAreaTypeLink = StoryAreaTypeLink.builder() + .url("https://t.me/test") + .build(); + + String json = mapper.writeValueAsString(storyAreaTypeLink); + assertEquals(expectedJson, json); + + StoryAreaTypeLink deserialized = mapper.readValue(json, StoryAreaTypeLink.class); + assertEquals(storyAreaTypeLink.getUrl(), deserialized.getUrl()); + assertEquals(storyAreaTypeLink.getType(), deserialized.getType()); + } catch (Exception e) { + fail(e); + } + } + + @Test + public void testValidation() { + // Valid case + try { + StoryAreaTypeLink validArea = StoryAreaTypeLink.builder() + .url("https://t.me/valid") + .build(); + validArea.validate(); + } catch (TelegramApiValidationException e) { + fail("Validation should not fail for valid area"); + } + + // Invalid case - empty URL + assertThrows(TelegramApiValidationException.class, () -> { + StoryAreaTypeLink invalidArea = StoryAreaTypeLink.builder() + .url("") + .build(); + invalidArea.validate(); + }); + } +} diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/area/TestStoryAreaTypeLocation.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/area/TestStoryAreaTypeLocation.java new file mode 100644 index 000000000..1ab9227e7 --- /dev/null +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/area/TestStoryAreaTypeLocation.java @@ -0,0 +1,71 @@ +package org.telegram.telegrambots.meta.api.objects.stories.area; + +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.objects.location.LocationAddress; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; + +/** + * @author Ruben Bermudez + * @version 9.0 + */ +public class TestStoryAreaTypeLocation { + + @Test + public void testStoryAreaTypeLocationType() { + LocationAddress address = Mockito.mock(LocationAddress.class); + + StoryAreaTypeLocation storyAreaTypeLocation = StoryAreaTypeLocation.builder() + .latitude(55.7558f) + .longitude(37.6173f) + .address(address) + .build(); + + assertEquals("location", storyAreaTypeLocation.getType()); + } + + @Test + public void testStoryAreaTypeLocationValidation() { + LocationAddress address = Mockito.mock(LocationAddress.class); + + StoryAreaTypeLocation storyAreaTypeLocation = StoryAreaTypeLocation.builder() + .latitude(55.7558f) + .longitude(37.6173f) + .address(address) + .build(); + + // Should not throw an exception when address validation passes + try { + Mockito.doNothing().when(address).validate(); + storyAreaTypeLocation.validate(); + + // Should throw exception when address validation fails + Mockito.doThrow(new TelegramApiValidationException("Invalid address", (BotApiObject) null)) + .when(address).validate(); + } catch (TelegramApiValidationException e) { + fail(); + } + + assertThrows(TelegramApiValidationException.class, storyAreaTypeLocation::validate); + } + + @Test + public void testStoryAreaTypeLocationGetters() { + LocationAddress address = Mockito.mock(LocationAddress.class); + + StoryAreaTypeLocation storyAreaTypeLocation = StoryAreaTypeLocation.builder() + .latitude(55.7558f) + .longitude(37.6173f) + .address(address) + .build(); + + assertEquals(Float.valueOf(55.7558f), storyAreaTypeLocation.getLatitude()); + assertEquals(Float.valueOf(37.6173f), storyAreaTypeLocation.getLongitude()); + assertEquals(address, storyAreaTypeLocation.getAddress()); + } +} diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/area/TestStoryAreaTypeSuggestedReaction.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/area/TestStoryAreaTypeSuggestedReaction.java new file mode 100644 index 000000000..0aea8b74e --- /dev/null +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/area/TestStoryAreaTypeSuggestedReaction.java @@ -0,0 +1,57 @@ +package org.telegram.telegrambots.meta.api.objects.stories.area; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; +import org.telegram.telegrambots.meta.api.objects.reactions.ReactionType; +import org.telegram.telegrambots.meta.api.objects.reactions.ReactionTypeEmoji; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + +/** + * @author Ruben Bermudez + * @version 9.0 + */ +public class TestStoryAreaTypeSuggestedReaction { + private final ObjectMapper mapper = new ObjectMapper(); + + @Test + public void testJsonSerialization() { + try { + String expectedJson = "{\"reaction_type\":{\"type\":\"emoji\",\"emoji\":\"👍\"},\"is_dark\":true,\"is_flipped\":true,\"type\":\"suggested_reaction\"}"; + + ReactionType reactionType = new ReactionTypeEmoji("👍"); + StoryAreaTypeSuggestedReaction storyAreaTypeSuggestedReaction = StoryAreaTypeSuggestedReaction.builder() + .reactionType(reactionType) + .isDark(true) + .isFlipped(true) + .build(); + + String json = mapper.writeValueAsString(storyAreaTypeSuggestedReaction); + assertEquals(expectedJson, json); + + StoryAreaTypeSuggestedReaction deserialized = mapper.readValue(json, StoryAreaTypeSuggestedReaction.class); + assertEquals(storyAreaTypeSuggestedReaction.getReactionType().getType(), deserialized.getReactionType().getType()); + assertEquals(storyAreaTypeSuggestedReaction.getIsDark(), deserialized.getIsDark()); + assertEquals(storyAreaTypeSuggestedReaction.getIsFlipped(), deserialized.getIsFlipped()); + assertEquals(storyAreaTypeSuggestedReaction.getType(), deserialized.getType()); + } catch (Exception e) { + fail(e); + } + } + + @Test + public void testValidation() { + // Valid case + try { + ReactionType reactionType = new ReactionTypeEmoji("👍"); + StoryAreaTypeSuggestedReaction validArea = StoryAreaTypeSuggestedReaction.builder() + .reactionType(reactionType) + .build(); + validArea.validate(); + } catch (TelegramApiValidationException e) { + fail("Validation should not fail for valid area"); + } + } +} diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/area/TestStoryAreaTypeUniqueGift.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/area/TestStoryAreaTypeUniqueGift.java new file mode 100644 index 000000000..c8cfba1c4 --- /dev/null +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/area/TestStoryAreaTypeUniqueGift.java @@ -0,0 +1,58 @@ +package org.telegram.telegrambots.meta.api.objects.stories.area; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; + +/** + * @author Ruben Bermudez + * @version 9.0 + */ +public class TestStoryAreaTypeUniqueGift { + private final ObjectMapper mapper = new ObjectMapper(); + + @Test + public void testJsonSerialization() { + try { + String expectedJson = "{\"name\":\"unique_gift_name\",\"type\":\"unique_gift\"}"; + + StoryAreaTypeUniqueGift storyAreaTypeUniqueGift = StoryAreaTypeUniqueGift.builder() + .name("unique_gift_name") + .build(); + + String json = mapper.writeValueAsString(storyAreaTypeUniqueGift); + assertEquals(expectedJson, json); + + StoryAreaTypeUniqueGift deserialized = mapper.readValue(json, StoryAreaTypeUniqueGift.class); + assertEquals(storyAreaTypeUniqueGift.getName(), deserialized.getName()); + assertEquals(storyAreaTypeUniqueGift.getType(), deserialized.getType()); + } catch (Exception e) { + fail(e); + } + } + + @Test + public void testValidation() { + // Valid case + try { + StoryAreaTypeUniqueGift validArea = StoryAreaTypeUniqueGift.builder() + .name("valid_gift_name") + .build(); + validArea.validate(); + } catch (TelegramApiValidationException e) { + fail("Validation should not fail for valid area"); + } + + // Invalid case - empty name + assertThrows(TelegramApiValidationException.class, () -> { + StoryAreaTypeUniqueGift invalidArea = StoryAreaTypeUniqueGift.builder() + .name("") + .build(); + invalidArea.validate(); + }); + } +} diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/area/TestStoryAreaTypeWeather.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/area/TestStoryAreaTypeWeather.java new file mode 100644 index 000000000..dbda68c29 --- /dev/null +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/area/TestStoryAreaTypeWeather.java @@ -0,0 +1,66 @@ +package org.telegram.telegrambots.meta.api.objects.stories.area; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; + +/** + * @author Ruben Bermudez + * @version 9.0 + */ +public class TestStoryAreaTypeWeather { + private final ObjectMapper mapper = new ObjectMapper(); + + @Test + public void testJsonSerialization() { + try { + String expectedJson = "{\"temperature\":25.5,\"emoji\":\"☀️\",\"background_color\":16777215,\"type\":\"weather\"}"; + + StoryAreaTypeWeather storyAreaTypeWeather = StoryAreaTypeWeather.builder() + .temperature(25.5f) + .emoji("☀️") + .backgroundColor(16777215) // White color in integer + .build(); + + String json = mapper.writeValueAsString(storyAreaTypeWeather); + assertEquals(expectedJson, json); + + StoryAreaTypeWeather deserialized = mapper.readValue(json, StoryAreaTypeWeather.class); + assertEquals(storyAreaTypeWeather.getTemperature(), deserialized.getTemperature()); + assertEquals(storyAreaTypeWeather.getEmoji(), deserialized.getEmoji()); + assertEquals(storyAreaTypeWeather.getBackgroundColor(), deserialized.getBackgroundColor()); + assertEquals(storyAreaTypeWeather.getType(), deserialized.getType()); + } catch (Exception e) { + fail(e); + } + } + + @Test + public void testValidation() { + // Valid case + try { + StoryAreaTypeWeather validArea = StoryAreaTypeWeather.builder() + .temperature(25.5f) + .emoji("☀️") + .backgroundColor(16777215) + .build(); + validArea.validate(); + } catch (TelegramApiValidationException e) { + fail("Validation should not fail for valid area"); + } + + // Invalid case - empty emoji + assertThrows(TelegramApiValidationException.class, () -> { + StoryAreaTypeWeather invalidArea = StoryAreaTypeWeather.builder() + .temperature(25.5f) + .emoji("") + .backgroundColor(16777215) + .build(); + invalidArea.validate(); + }); + } +} diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/input/TestInputStoryContentPhoto.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/input/TestInputStoryContentPhoto.java new file mode 100644 index 000000000..9739e4982 --- /dev/null +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/input/TestInputStoryContentPhoto.java @@ -0,0 +1,58 @@ +package org.telegram.telegrambots.meta.api.objects.stories.input; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; + +/** + * @author Ruben Bermudez + * @version 9.0 + */ +public class TestInputStoryContentPhoto { + private final ObjectMapper mapper = new ObjectMapper(); + + @Test + public void testJsonSerialization() { + try { + String expectedJson = "{\"photo\":\"test_photo.jpg\",\"type\":\"photo\"}"; + + InputStoryContentPhoto inputStoryContentPhoto = InputStoryContentPhoto.builder() + .photo("test_photo.jpg") + .build(); + + String json = mapper.writeValueAsString(inputStoryContentPhoto); + assertEquals(expectedJson, json); + + InputStoryContentPhoto deserialized = mapper.readValue(json, InputStoryContentPhoto.class); + assertEquals(inputStoryContentPhoto.getPhoto(), deserialized.getPhoto()); + assertEquals(inputStoryContentPhoto.getType(), deserialized.getType()); + } catch (Exception e) { + fail(e); + } + } + + @Test + public void testValidation() { + // Valid case + try { + InputStoryContentPhoto validContent = InputStoryContentPhoto.builder() + .photo("valid_photo.jpg") + .build(); + validContent.validate(); + } catch (TelegramApiValidationException e) { + fail("Validation should not fail for valid content"); + } + + // Invalid case - empty photo + assertThrows(TelegramApiValidationException.class, () -> { + InputStoryContentPhoto invalidContent = InputStoryContentPhoto.builder() + .photo("") + .build(); + invalidContent.validate(); + }); + } +} diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/input/TestInputStoryContentVideo.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/input/TestInputStoryContentVideo.java new file mode 100644 index 000000000..7c4b8b678 --- /dev/null +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/input/TestInputStoryContentVideo.java @@ -0,0 +1,83 @@ +package org.telegram.telegrambots.meta.api.objects.stories.input; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; + +/** + * @author Ruben Bermudez + * @version 9.0 + */ +public class TestInputStoryContentVideo { + private final ObjectMapper mapper = new ObjectMapper(); + + @Test + public void testJsonSerialization() { + try { + String expectedJson = "{\"video\":\"test_video.mp4\",\"duration\":30.5,\"cover_frame_timestamp\":10.5,\"is_animation\":true,\"type\":\"video\"}"; + + InputStoryContentVideo inputStoryContentVideo = InputStoryContentVideo.builder() + .video("test_video.mp4") + .duration(30.5f) + .coverFrameTimestamp(10.5f) + .isAnimation(true) + .build(); + + String json = mapper.writeValueAsString(inputStoryContentVideo); + assertEquals(expectedJson, json); + + InputStoryContentVideo deserialized = mapper.readValue(json, InputStoryContentVideo.class); + assertEquals(inputStoryContentVideo.getVideo(), deserialized.getVideo()); + assertEquals(inputStoryContentVideo.getDuration(), deserialized.getDuration()); + assertEquals(inputStoryContentVideo.getCoverFrameTimestamp(), deserialized.getCoverFrameTimestamp()); + assertEquals(inputStoryContentVideo.getIsAnimation(), deserialized.getIsAnimation()); + assertEquals(inputStoryContentVideo.getType(), deserialized.getType()); + } catch (Exception e) { + fail(e); + } + } + + @Test + public void testValidation() { + // Valid case + try { + InputStoryContentVideo validContent = InputStoryContentVideo.builder() + .video("valid_video.mp4") + .duration(30.0f) + .build(); + validContent.validate(); + } catch (TelegramApiValidationException e) { + fail("Validation should not fail for valid content"); + } + + // Invalid case - empty video + assertThrows(TelegramApiValidationException.class, () -> { + InputStoryContentVideo invalidContent = InputStoryContentVideo.builder() + .video("") + .build(); + invalidContent.validate(); + }); + + // Invalid case - duration out of range (negative) + assertThrows(TelegramApiValidationException.class, () -> { + InputStoryContentVideo invalidContent = InputStoryContentVideo.builder() + .video("valid_video.mp4") + .duration(-1.0f) + .build(); + invalidContent.validate(); + }); + + // Invalid case - duration out of range (too high) + assertThrows(TelegramApiValidationException.class, () -> { + InputStoryContentVideo invalidContent = InputStoryContentVideo.builder() + .video("valid_video.mp4") + .duration(61.0f) + .build(); + invalidContent.validate(); + }); + } +} diff --git a/telegrambots-springboot-longpolling-starter/pom.xml b/telegrambots-springboot-longpolling-starter/pom.xml index 0db66f5aa..d6f0c1c4c 100644 --- a/telegrambots-springboot-longpolling-starter/pom.xml +++ b/telegrambots-springboot-longpolling-starter/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 8.3.0 + 9.0.0 telegrambots-springboot-longpolling-starter @@ -71,7 +71,7 @@ UTF-8 UTF-8 - 8.3.0 + 9.0.0 3.2.3 diff --git a/telegrambots-springboot-webhook-starter/pom.xml b/telegrambots-springboot-webhook-starter/pom.xml index 8bc11f541..e582ca12d 100644 --- a/telegrambots-springboot-webhook-starter/pom.xml +++ b/telegrambots-springboot-webhook-starter/pom.xml @@ -6,7 +6,7 @@ org.telegram Bots - 8.3.0 + 9.0.0 telegrambots-springboot-webhook-starter @@ -71,7 +71,7 @@ UTF-8 UTF-8 - 8.3.0 + 9.0.0 3.2.3 2.17.2 diff --git a/telegrambots-test-reports/pom.xml b/telegrambots-test-reports/pom.xml index 77fdb6f4c..d31743b5e 100644 --- a/telegrambots-test-reports/pom.xml +++ b/telegrambots-test-reports/pom.xml @@ -6,7 +6,7 @@ org.telegram Bots - 8.3.0 + 9.0.0 telegrambots-test-reports diff --git a/telegrambots-webhook/pom.xml b/telegrambots-webhook/pom.xml index 7ecbdea5e..d136139e2 100644 --- a/telegrambots-webhook/pom.xml +++ b/telegrambots-webhook/pom.xml @@ -6,7 +6,7 @@ org.telegram Bots - 8.3.0 + 9.0.0 telegrambots-webhook From 8eed278cb693a31ec58c5d2581e07defc493878e Mon Sep 17 00:00:00 2001 From: mykhaj <72294841+mykhaj@users.noreply.github.com> Date: Thu, 10 Jul 2025 11:50:23 +0300 Subject: [PATCH 02/16] Update JettyTelegramClient.java --- .../telegrambots/client/jetty/JettyTelegramClient.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/telegrambots-client-jetty-adapter/src/main/java/org/telegram/telegrambots/client/jetty/JettyTelegramClient.java b/telegrambots-client-jetty-adapter/src/main/java/org/telegram/telegrambots/client/jetty/JettyTelegramClient.java index df8ff0929..067aa87d2 100644 --- a/telegrambots-client-jetty-adapter/src/main/java/org/telegram/telegrambots/client/jetty/JettyTelegramClient.java +++ b/telegrambots-client-jetty-adapter/src/main/java/org/telegram/telegrambots/client/jetty/JettyTelegramClient.java @@ -147,7 +147,7 @@ public CompletableFuture executeAsync(SendPhoto sendPhoto) { @Override public CompletableFuture executeAsync(SetBusinessAccountProfilePhoto setBusinessAccountProfilePhoto) { try { - assertParamNotNull(setBusinessAccountProfilePhoto, "method"); + assertParamNotNull(setBusinessAccountProfilePhoto, "setBusinessAccountProfilePhoto"); setBusinessAccountProfilePhoto.validate(); @@ -181,7 +181,7 @@ public CompletableFuture executeAsync(SetBusinessAccountProfilePhoto se @Override public CompletableFuture executeAsync(SetWebhook setWebhook) { try { - assertParamNotNull(setWebhook, "method"); + assertParamNotNull(setWebhook, "setWebhook"); setWebhook.validate(); From c37e06f5af64252d8b3085781833df9094b92aba Mon Sep 17 00:00:00 2001 From: Evgenii Komrakov Date: Sat, 2 Aug 2025 16:23:46 +0500 Subject: [PATCH 03/16] Fixes #1463 AbilityBot: Could not retrieve originating user from update (ChatBoostUpdated and ChatBoostRemoved) --- .../telegrambots/abilitybots/api/objects/Flag.java | 4 +++- .../telegrambots/abilitybots/api/util/AbilityUtils.java | 6 +++++- .../telegram/telegrambots/meta/api/objects/Update.java | 8 ++++++++ .../meta/api/objects/boost/ChatBoostSource.java | 3 +++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/telegrambots-abilities/src/main/java/org/telegram/telegrambots/abilitybots/api/objects/Flag.java b/telegrambots-abilities/src/main/java/org/telegram/telegrambots/abilitybots/api/objects/Flag.java index dd30c31ca..183c50f0e 100644 --- a/telegrambots-abilities/src/main/java/org/telegram/telegrambots/abilitybots/api/objects/Flag.java +++ b/telegrambots-abilities/src/main/java/org/telegram/telegrambots/abilitybots/api/objects/Flag.java @@ -9,7 +9,7 @@ import static java.util.Objects.nonNull; /** - * Flags are an conditions that are applied on an {@link Update}. + * Flags are a conditions that are applied on an {@link Update}. *

* They can be used on {@link AbilityBuilder#flag(Predicate[])} and on the post conditions in {@link AbilityBuilder#reply(BiConsumer, Predicate[])}. * @@ -37,6 +37,8 @@ public enum Flag implements Predicate { HAS_EDITED_BUSINESS_MESSAGE(Update::hasEditedBusinessMessage), HAS_DELETED_BUSINESS_MESSAGE(Update::hasDeletedBusinessMessage), HAS_PAID_MEDIA_PURCHASED(Update::hasPaidMediaPurchased), + HAS_CHAT_BOOST(Update::hasChatBoost), + HAS_REMOVED_CHAT_BOOST(Update::hasRemovedChatBoost), // Message Flags diff --git a/telegrambots-abilities/src/main/java/org/telegram/telegrambots/abilitybots/api/util/AbilityUtils.java b/telegrambots-abilities/src/main/java/org/telegram/telegrambots/abilitybots/api/util/AbilityUtils.java index 59ede736a..7917fb126 100644 --- a/telegrambots-abilities/src/main/java/org/telegram/telegrambots/abilitybots/api/util/AbilityUtils.java +++ b/telegrambots-abilities/src/main/java/org/telegram/telegrambots/abilitybots/api/util/AbilityUtils.java @@ -100,6 +100,10 @@ private static User getUserElseThrow(Update update) { return update.getPaidMediaPurchased().getUser(); } else if (Flag.POLL.test(update)) { return EMPTY_USER; + } else if (Flag.HAS_CHAT_BOOST.test(update)) { + return update.getChatBoost().getBoost().getSource().getUser(); + } else if (Flag.HAS_REMOVED_CHAT_BOOST.test(update)) { + return update.getRemovedChatBoost().getSource().getUser(); } else { throw new IllegalStateException("Could not retrieve originating user from update"); } @@ -202,7 +206,7 @@ public static Long getChatId(Update update) { /** * @param update a Telegram {@link Update} - * @return true if the update contains contains a private user message + * @return true if the update contains a private user message */ public static boolean isUserMessage(Update update) { if (Flag.MESSAGE.test(update)) { diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Update.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Update.java index 59e4b8aaf..cd0881e2f 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Update.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Update.java @@ -285,4 +285,12 @@ public boolean hasDeletedBusinessMessage() { public boolean hasPaidMediaPurchased() { return paidMediaPurchased != null; } + + public boolean hasChatBoost() { + return chatBoost != null; + } + + public boolean hasRemovedChatBoost() { + return removedChatBoost != null; + } } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/boost/ChatBoostSource.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/boost/ChatBoostSource.java index c42fe575d..c67620f80 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/boost/ChatBoostSource.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/boost/ChatBoostSource.java @@ -3,6 +3,7 @@ import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.objects.User; /** * @author Ruben Bermudez @@ -24,4 +25,6 @@ public interface ChatBoostSource extends BotApiObject { String PREMIUM_TYPE = "premium"; String GIFT_CODE_TYPE = "gift_code"; String GIVEAWAY_TYPE = "giveaway"; + + User getUser(); } From f325d691664c471a82cfa6ab18e615fc22c5a8bd Mon Sep 17 00:00:00 2001 From: Evgenii Komrakov Date: Mon, 25 Aug 2025 14:31:47 +0500 Subject: [PATCH 04/16] Fixes #1463 AbilityBot: Could not retrieve originating user from update (ChatBoostUpdated and ChatBoostRemoved) --- .../org/telegram/telegrambots/abilitybots/api/objects/Flag.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telegrambots-abilities/src/main/java/org/telegram/telegrambots/abilitybots/api/objects/Flag.java b/telegrambots-abilities/src/main/java/org/telegram/telegrambots/abilitybots/api/objects/Flag.java index 183c50f0e..2e1a56497 100644 --- a/telegrambots-abilities/src/main/java/org/telegram/telegrambots/abilitybots/api/objects/Flag.java +++ b/telegrambots-abilities/src/main/java/org/telegram/telegrambots/abilitybots/api/objects/Flag.java @@ -9,7 +9,7 @@ import static java.util.Objects.nonNull; /** - * Flags are a conditions that are applied on an {@link Update}. + * Flags are conditions that are applied on an {@link Update}. *

* They can be used on {@link AbilityBuilder#flag(Predicate[])} and on the post conditions in {@link AbilityBuilder#reply(BiConsumer, Predicate[])}. * From f35deed0ca675485a58df8a96cdec4931102b7e2 Mon Sep 17 00:00:00 2001 From: ruben Date: Sun, 7 Sep 2025 20:00:31 +0100 Subject: [PATCH 05/16] Api Version 9.1 --- pom.xml | 2 +- telegrambots-abilities/pom.xml | 6 +- telegrambots-client-jetty-adapter/pom.xml | 2 +- telegrambots-client/pom.xml | 2 +- telegrambots-extensions/README.md | 4 +- telegrambots-extensions/pom.xml | 6 +- telegrambots-longpolling/pom.xml | 2 +- telegrambots-meta/pom.xml | 2 +- .../meta/api/methods/GetMyStarBalance.java | 51 +++++++ .../checklist/EditMessageChecklist.java | 114 ++++++++++++++ .../api/methods/checklist/SendChecklist.java | 139 ++++++++++++++++++ .../PromoteChatMember.java | 14 +- .../meta/api/methods/polls/SendPoll.java | 8 +- .../meta/api/objects/ChatPermissions.java | 2 +- .../meta/api/objects/ExternalReplyInfo.java | 13 ++ .../adminrights/ChatAdministratorRights.java | 9 +- .../chatmember/ChatMemberAdministrator.java | 10 +- .../chatmember/ChatMemberRestricted.java | 2 +- .../meta/api/objects/checklist/Checklist.java | 76 ++++++++++ .../api/objects/checklist/ChecklistTask.java | 77 ++++++++++ .../checklist/ChecklistTasksAdded.java | 54 +++++++ .../objects/checklist/ChecklistTasksDone.java | 59 ++++++++ .../api/objects/checklist/InputChecklist.java | 106 +++++++++++++ .../objects/checklist/InputChecklistTask.java | 85 +++++++++++ .../api/objects/gifts/UniqueGiftInfo.java | 16 ++ .../objects/gifts/owned/OwnedGiftUnique.java | 9 ++ .../meta/api/objects/message/Message.java | 52 +++++++ .../payments/DirectMessagePriceChanged.java | 53 +++++++ .../pom.xml | 4 +- .../pom.xml | 4 +- telegrambots-test-reports/pom.xml | 2 +- telegrambots-webhook/pom.xml | 2 +- 32 files changed, 948 insertions(+), 39 deletions(-) create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/GetMyStarBalance.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/checklist/EditMessageChecklist.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/checklist/SendChecklist.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/checklist/Checklist.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/checklist/ChecklistTask.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/checklist/ChecklistTasksAdded.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/checklist/ChecklistTasksDone.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/checklist/InputChecklist.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/checklist/InputChecklistTask.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/payments/DirectMessagePriceChanged.java diff --git a/pom.xml b/pom.xml index 5de1ec2e8..1aba37eef 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots pom - 9.0.0 + 9.1.0 telegrambots-meta diff --git a/telegrambots-abilities/pom.xml b/telegrambots-abilities/pom.xml index 479a388c2..5a73d277e 100644 --- a/telegrambots-abilities/pom.xml +++ b/telegrambots-abilities/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 9.0.0 + 9.1.0 telegrambots-abilities @@ -104,12 +104,12 @@ org.telegram telegrambots-webhook - 9.0.0 + 9.1.0 org.telegram telegrambots-longpolling - 9.0.0 + 9.1.0 diff --git a/telegrambots-client-jetty-adapter/pom.xml b/telegrambots-client-jetty-adapter/pom.xml index a67e7a4d3..9c160d953 100644 --- a/telegrambots-client-jetty-adapter/pom.xml +++ b/telegrambots-client-jetty-adapter/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 9.0.0 + 9.1.0 Telegram Bots Client Jetty HttpClient adapter diff --git a/telegrambots-client/pom.xml b/telegrambots-client/pom.xml index b56f5febb..8c2f7cbc0 100644 --- a/telegrambots-client/pom.xml +++ b/telegrambots-client/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 9.0.0 + 9.1.0 Telegram Bots Client diff --git a/telegrambots-extensions/README.md b/telegrambots-extensions/README.md index c0669ad7d..e8f927dd5 100644 --- a/telegrambots-extensions/README.md +++ b/telegrambots-extensions/README.md @@ -16,12 +16,12 @@ Just import add the library to your project with one of these options: org.telegram telegrambots-extensions - 9.0.0 + 9.1.0 ``` 2. Using Gradle: ```gradle - implementation 'org.telegram:telegrambots-extensions:9.0.0' + implementation 'org.telegram:telegrambots-extensions:9.1.0' ``` \ No newline at end of file diff --git a/telegrambots-extensions/pom.xml b/telegrambots-extensions/pom.xml index bc816f693..1439ccb3e 100644 --- a/telegrambots-extensions/pom.xml +++ b/telegrambots-extensions/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 9.0.0 + 9.1.0 telegrambots-extensions @@ -89,12 +89,12 @@ org.telegram telegrambots-webhook - 9.0.0 + 9.1.0 org.telegram telegrambots-longpolling - 9.0.0 + 9.1.0 diff --git a/telegrambots-longpolling/pom.xml b/telegrambots-longpolling/pom.xml index f2b586194..93ea78e25 100644 --- a/telegrambots-longpolling/pom.xml +++ b/telegrambots-longpolling/pom.xml @@ -6,7 +6,7 @@ org.telegram Bots - 9.0.0 + 9.1.0 telegrambots-longpolling diff --git a/telegrambots-meta/pom.xml b/telegrambots-meta/pom.xml index fcc5430f8..f5d0f1b75 100644 --- a/telegrambots-meta/pom.xml +++ b/telegrambots-meta/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 9.0.0 + 9.1.0 telegrambots-meta diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/GetMyStarBalance.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/GetMyStarBalance.java new file mode 100644 index 000000000..0c641babf --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/GetMyStarBalance.java @@ -0,0 +1,51 @@ +package org.telegram.telegrambots.meta.api.methods; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; +import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethod; +import org.telegram.telegrambots.meta.api.objects.payments.star.StarAmount; +import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * @author JetBrains + * @version 7.0 + * + * A method to get the current Telegram Stars balance of the bot. + * Requires no parameters. + * On success, returns a StarAmount object. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@SuperBuilder +@Jacksonized +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class GetMyStarBalance extends BotApiMethod { + public static final String PATH = "getMyStarBalance"; + + @Override + public StarAmount deserializeResponse(String answer) throws TelegramApiRequestException { + return deserializeResponse(answer, StarAmount.class); + } + + @Override + public String getMethod() { + return PATH; + } + + @Override + public void validate() throws TelegramApiValidationException { + // No parameters to validate + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/checklist/EditMessageChecklist.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/checklist/EditMessageChecklist.java new file mode 100644 index 000000000..c3aa5706a --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/checklist/EditMessageChecklist.java @@ -0,0 +1,114 @@ +package org.telegram.telegrambots.meta.api.methods.checklist; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import lombok.experimental.Tolerate; +import lombok.extern.jackson.Jacksonized; +import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodMessage; +import org.telegram.telegrambots.meta.api.objects.checklist.InputChecklist; +import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; +import org.telegram.telegrambots.meta.util.Validations; + +/** + * @author JetBrains + * @version 7.0 + * Use this method to edit a checklist on behalf of a connected business account. + * On success, the edited Message is returned. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@RequiredArgsConstructor +@AllArgsConstructor +@SuperBuilder +@Jacksonized +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class EditMessageChecklist extends BotApiMethodMessage { + public static final String PATH = "editMessageChecklist"; + + private static final String BUSINESS_CONNECTION_ID_FIELD = "business_connection_id"; + private static final String CHAT_ID_FIELD = "chat_id"; + private static final String MESSAGE_ID_FIELD = "message_id"; + private static final String CHECKLIST_FIELD = "checklist"; + private static final String REPLY_MARKUP_FIELD = "reply_markup"; + + /** + * Unique identifier of the business connection on behalf of which the message will be sent + */ + @JsonProperty(BUSINESS_CONNECTION_ID_FIELD) + @NonNull + private String businessConnectionId; + + /** + * Unique identifier for the target chat + */ + @JsonProperty(CHAT_ID_FIELD) + @NonNull + private String chatId; + + /** + * Unique identifier for the target message + */ + @JsonProperty(MESSAGE_ID_FIELD) + @NonNull + private Integer messageId; + + /** + * A JSON-serialized object for the new checklist + */ + @JsonProperty(CHECKLIST_FIELD) + @NonNull + private InputChecklist checklist; + + /** + * Optional. A JSON-serialized object for the new inline keyboard for the message + */ + @JsonProperty(REPLY_MARKUP_FIELD) + private InlineKeyboardMarkup replyMarkup; + + @Tolerate + public void setChatId(@NonNull Long chatId) { + this.chatId = chatId.toString(); + } + + @Override + public String getMethod() { + return PATH; + } + + @Override + public void validate() throws TelegramApiValidationException { + if (businessConnectionId.isEmpty()) { + throw new TelegramApiValidationException("BusinessConnectionId parameter can't be empty", this); + } + Validations.requiredChatId(chatId, this); + checklist.validate(); + + if (replyMarkup != null) { + replyMarkup.validate(); + } + } + + public static abstract class EditMessageChecklistBuilder> extends BotApiMethodMessageBuilder { + @Tolerate + public EditMessageChecklistBuilder chatId(@NonNull Long chatId) { + this.chatId = chatId.toString(); + return this; + } + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/checklist/SendChecklist.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/checklist/SendChecklist.java new file mode 100644 index 000000000..2cc85ff05 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/checklist/SendChecklist.java @@ -0,0 +1,139 @@ +package org.telegram.telegrambots.meta.api.methods.checklist; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import lombok.experimental.Tolerate; +import lombok.extern.jackson.Jacksonized; +import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodMessage; +import org.telegram.telegrambots.meta.api.objects.ReplyParameters; +import org.telegram.telegrambots.meta.api.objects.checklist.InputChecklist; +import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; +import org.telegram.telegrambots.meta.util.Validations; + +/** + * @author JetBrains + * @version 7.0 + * Use this method to send a checklist on behalf of a connected business account. + * On success, the sent Message is returned. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@RequiredArgsConstructor +@AllArgsConstructor +@SuperBuilder +@Jacksonized +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class SendChecklist extends BotApiMethodMessage { + public static final String PATH = "sendChecklist"; + + private static final String BUSINESS_CONNECTION_ID_FIELD = "business_connection_id"; + private static final String CHAT_ID_FIELD = "chat_id"; + private static final String CHECKLIST_FIELD = "checklist"; + private static final String DISABLE_NOTIFICATION_FIELD = "disable_notification"; + private static final String PROTECT_CONTENT_FIELD = "protect_content"; + private static final String MESSAGE_EFFECT_ID_FIELD = "message_effect_id"; + private static final String REPLY_PARAMETERS_FIELD = "reply_parameters"; + private static final String REPLY_MARKUP_FIELD = "reply_markup"; + + /** + * Unique identifier of the business connection on behalf of which the message will be sent + */ + @JsonProperty(BUSINESS_CONNECTION_ID_FIELD) + @NonNull + private String businessConnectionId; + + /** + * Unique identifier for the target chat + */ + @JsonProperty(CHAT_ID_FIELD) + @NonNull + private String chatId; + + /** + * A JSON-serialized object for the checklist to send + */ + @JsonProperty(CHECKLIST_FIELD) + @NonNull + private InputChecklist checklist; + + /** + * Optional. Sends the message silently. Users will receive a notification with no sound. + */ + @JsonProperty(DISABLE_NOTIFICATION_FIELD) + private Boolean disableNotification; + + /** + * Optional. Protects the contents of the sent message from forwarding and saving + */ + @JsonProperty(PROTECT_CONTENT_FIELD) + private Boolean protectContent; + + /** + * Optional. Unique identifier of the message effect to be added to the message + */ + @JsonProperty(MESSAGE_EFFECT_ID_FIELD) + private String messageEffectId; + + /** + * Optional. A JSON-serialized object for description of the message to reply to + */ + @JsonProperty(REPLY_PARAMETERS_FIELD) + private ReplyParameters replyParameters; + + /** + * Optional. A JSON-serialized object for an inline keyboard + */ + @JsonProperty(REPLY_MARKUP_FIELD) + private InlineKeyboardMarkup replyMarkup; + + @Tolerate + public void setChatId(@NonNull Long chatId) { + this.chatId = chatId.toString(); + } + + @Override + public String getMethod() { + return PATH; + } + + @Override + public void validate() throws TelegramApiValidationException { + if (businessConnectionId.isEmpty()) { + throw new TelegramApiValidationException("BusinessConnectionId parameter can't be empty", this); + } + Validations.requiredChatId(chatId, this); + checklist.validate(); + + if (replyMarkup != null) { + replyMarkup.validate(); + } + + if (replyParameters != null) { + replyParameters.validate(); + } + } + + public static abstract class SendChecklistBuilder> extends BotApiMethodMessageBuilder { + @Tolerate + public SendChecklistBuilder chatId(@NonNull Long chatId) { + this.chatId = chatId.toString(); + return this; + } + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/PromoteChatMember.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/PromoteChatMember.java index ef55b5411..4655230b8 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/PromoteChatMember.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/PromoteChatMember.java @@ -64,8 +64,13 @@ public class PromoteChatMember extends BotApiMethodBoolean { private Long userId; ///< Required. Unique identifier of the target user @JsonProperty(CANCHANGEINFORMATION_FIELD) private Boolean canChangeInformation; ///< Optional. Pass True, if the administrator can change chat title, photo and other settings + /** + * Optional. + * Pass True if the administrator can post messages in the channel, approve suggested posts, + * or access channel statistics; for channels only + */ @JsonProperty(CANPOSTMESSAGES_FIELD) - private Boolean canPostMessages; ///< Optional. Pass True, if the administrator can create channel posts, channels only + private Boolean canPostMessages; @JsonProperty(CANEDITMESSAGES_FIELD) private Boolean canEditMessages; ///< Optional. Pass True, if the administrator can edit messages of other users, channels only @JsonProperty(CANDELETEMESSAGES_FIELD) @@ -83,10 +88,9 @@ public class PromoteChatMember extends BotApiMethodBoolean { /** * Optional * - * Pass True, if the administrator can access the chat event log, chat statistics, message statistics in channels, - * see channel members, see anonymous administrators in supergoups and ignore slow mode. - * - * Implied by any other administrator privilege + * Pass True if the administrator can access the chat event log, get boost list, see hidden supergroup + * and channel members, report spam messages, ignore slow mode, and send messages to the chat + * without paying Telegram Stars. Implied by any other administrator privilege. */ @JsonProperty(CAN_MANAGE_CHAT_FIELD) private Boolean canManageChat; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/polls/SendPoll.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/polls/SendPoll.java index e950d9c9d..d870e9f65 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/polls/SendPoll.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/polls/SendPoll.java @@ -48,7 +48,7 @@ public class SendPoll extends BotApiMethodMessage { private static final String CHAT_ID_FIELD = "chat_id"; private static final String MESSAGE_THREAD_ID_FIELD = "message_thread_id"; private static final String QUESTION_FIELD = "question"; - private static final String OPTIONS_FIELD = "options"; // TODO + private static final String OPTIONS_FIELD = "options"; private static final String IS_ANONYMOUS_FIELD = "is_anonymous"; private static final String TYPE_FIELD = "type"; private static final String ALLOW_MULTIPLE_ANSWERS_FIELD = "allows_multiple_answers"; @@ -91,7 +91,7 @@ public class SendPoll extends BotApiMethodMessage { @NonNull private String question; /** - * A JSON-serialized list of 2-10 answer options + * A JSON-serialized list of 2-12 answer options */ @JsonProperty(OPTIONS_FIELD) @Singular @@ -268,8 +268,8 @@ public void validate() throws TelegramApiValidationException { if (explanation != null && explanation.length() > 200) { throw new TelegramApiValidationException("Explanation can only have up to 200 characters", this); } - if (options.size() < 2 || options.size() > 10) { - throw new TelegramApiValidationException("Options parameter must be between 2 and 10 item", this); + if (options.size() < 2 || options.size() > 12) { + throw new TelegramApiValidationException("Options parameter must be between 2 and 12 item", this); } for (InputPollOption option : options) { option.validate(); diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatPermissions.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatPermissions.java index 2f6f23c7d..6d117dcca 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatPermissions.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatPermissions.java @@ -86,7 +86,7 @@ public class ChatPermissions implements BotApiObject { private Boolean canSendVoiceNotes; /** * Optional. - * True, if the user is allowed to send polls, implies can_send_messages + * True, if the user is allowed to send polls and checklists */ @JsonProperty(CAN_SEND_POLLS_FIELD) private Boolean canSendPolls; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ExternalReplyInfo.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ExternalReplyInfo.java index 29210ac23..1ad1808d4 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ExternalReplyInfo.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ExternalReplyInfo.java @@ -13,6 +13,7 @@ import lombok.extern.jackson.Jacksonized; import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; import org.telegram.telegrambots.meta.api.objects.chat.Chat; +import org.telegram.telegrambots.meta.api.objects.checklist.Checklist; import org.telegram.telegrambots.meta.api.objects.games.Animation; import org.telegram.telegrambots.meta.api.objects.games.Game; import org.telegram.telegrambots.meta.api.objects.giveaway.Giveaway; @@ -67,6 +68,7 @@ public class ExternalReplyInfo implements BotApiObject { private static final String POLL_FIELD = "poll"; private static final String VENUE_FIELD = "venue"; private static final String PAID_MEDIA_FIELD = "paid_media"; + private static final String CHECKLIST_FIELD = "checklist"; /** * Origin of the message replied to by the given message @@ -211,6 +213,12 @@ public class ExternalReplyInfo implements BotApiObject { */ @JsonProperty(PAID_MEDIA_FIELD) private PaidMediaInfo paidMedia; + /** + * Optional. + * Message is a checklist + */ + @JsonProperty(CHECKLIST_FIELD) + private Checklist checklist; @JsonIgnore @@ -312,4 +320,9 @@ public boolean hasDice() { private boolean hasStory() { return story != null; } + + @JsonIgnore + public boolean hasChecklist() { + return checklist != null; + } } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/adminrights/ChatAdministratorRights.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/adminrights/ChatAdministratorRights.java index c026bc42f..0693cfd2b 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/adminrights/ChatAdministratorRights.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/adminrights/ChatAdministratorRights.java @@ -53,9 +53,9 @@ public class ChatAdministratorRights implements BotApiObject, Validable { @NonNull private Boolean isAnonymous; /** - * True, if the administrator can access the chat event log, get boost list, - * see hidden supergroup and channel members, report spam messages and ignore slow mode. - * Implied by any other administrator privilege. + * True, if the administrator can access the chat event log, get boost list, see hidden supergroup + * and channel members, report spam messages, ignore slow mode, and send messages to the chat + * without paying Telegram Stars. Implied by any other administrator privilege. */ @JsonProperty(CAN_MANAGE_CHAT_FIELD) @NonNull @@ -100,7 +100,8 @@ public class ChatAdministratorRights implements BotApiObject, Validable { private Boolean canInviteUsers; /** * Optional. - * True, if the administrator can post messages in the channel; channels only + * True, if the administrator can post messages in the channel, approve suggested posts, + * or access channel statistics; for channels only */ @JsonProperty(CANPOSTMESSAGES_FIELD) private Boolean canPostMessages; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMemberAdministrator.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMemberAdministrator.java index 1482a9c80..634282cbe 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMemberAdministrator.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMemberAdministrator.java @@ -76,15 +76,15 @@ public class ChatMemberAdministrator implements ChatMember { @JsonProperty(ISANONYMOUS_FIELD) private Boolean isAnonymous; /** - * True, if the administrator can access the chat event log, get boost list, - * see hidden supergroup and channel members, report spam messages and ignore slow mode. - * - * Implied by any other administrator privilege. + * True, if the administrator can access the chat event log, get boost list, see hidden supergroup + * and channel members, report spam messages, ignore slow mode, and send messages to the chat + * without paying Telegram Stars. Implied by any other administrator privilege. */ @JsonProperty(CAN_MANAGE_CHAT_FIELD) private Boolean canManageChat; /** - * True, if the administrator can post messages in the channel; channels only + * True, if the administrator can post messages in the channel, approve suggested posts, + * or access channel statistics; for channels only */ @JsonProperty(CANPOSTMESSAGES_FIELD) private Boolean canPostMessages; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMemberRestricted.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMemberRestricted.java index a3d608de9..2721d6fd2 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMemberRestricted.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMemberRestricted.java @@ -102,7 +102,7 @@ public class ChatMemberRestricted implements ChatMember { @JsonProperty(CANSENDVOICENOTES_FIELD) private Boolean canSendVoiceNotes; /** - * True, if the user is allowed to send polls + * True, if the user is allowed to send polls and checklists */ @JsonProperty(CANSENDPOLLS_FIELD) private Boolean canSendPolls; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/checklist/Checklist.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/checklist/Checklist.java new file mode 100644 index 000000000..a23bf761e --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/checklist/Checklist.java @@ -0,0 +1,76 @@ +package org.telegram.telegrambots.meta.api.objects.checklist; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.objects.MessageEntity; + +import java.util.List; + +/** + * @author JetBrains + * @version 7.0 + * + * Describes a checklist. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@RequiredArgsConstructor +@AllArgsConstructor +@SuperBuilder +@Jacksonized +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Checklist implements BotApiObject { + private static final String TITLE_FIELD = "title"; + private static final String TITLE_ENTITIES_FIELD = "title_entities"; + private static final String TASKS_FIELD = "tasks"; + private static final String OTHERS_CAN_ADD_TASKS_FIELD = "others_can_add_tasks"; + private static final String OTHERS_CAN_MARK_TASKS_AS_DONE_FIELD = "others_can_mark_tasks_as_done"; + + /** + * Title of the checklist + */ + @JsonProperty(TITLE_FIELD) + @NonNull + private String title; + + /** + * Optional. Special entities that appear in the checklist title + */ + @JsonProperty(TITLE_ENTITIES_FIELD) + private List titleEntities; + + /** + * List of tasks in the checklist + */ + @JsonProperty(TASKS_FIELD) + @NonNull + private List tasks; + + /** + * Optional. True, if users other than the creator of the list can add tasks to the list + */ + @JsonProperty(OTHERS_CAN_ADD_TASKS_FIELD) + private Boolean othersCanAddTasks; + + /** + * Optional. True, if users other than the creator of the list can mark tasks as done or not done + */ + @JsonProperty(OTHERS_CAN_MARK_TASKS_AS_DONE_FIELD) + private Boolean othersCanMarkTasksAsDone; +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/checklist/ChecklistTask.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/checklist/ChecklistTask.java new file mode 100644 index 000000000..1d30dc766 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/checklist/ChecklistTask.java @@ -0,0 +1,77 @@ +package org.telegram.telegrambots.meta.api.objects.checklist; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.objects.MessageEntity; +import org.telegram.telegrambots.meta.api.objects.User; + +import java.util.List; + +/** + * @author JetBrains + * @version 7.0 + * + * Describes a task in a checklist. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@RequiredArgsConstructor +@AllArgsConstructor +@SuperBuilder +@Jacksonized +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ChecklistTask implements BotApiObject { + private static final String ID_FIELD = "id"; + private static final String TEXT_FIELD = "text"; + private static final String TEXT_ENTITIES_FIELD = "text_entities"; + private static final String COMPLETED_BY_USER_FIELD = "completed_by_user"; + private static final String COMPLETION_DATE_FIELD = "completion_date"; + + /** + * Unique identifier of the task + */ + @JsonProperty(ID_FIELD) + @NonNull + private Integer id; + + /** + * Text of the task + */ + @JsonProperty(TEXT_FIELD) + @NonNull + private String text; + + /** + * Optional. Special entities that appear in the task text + */ + @JsonProperty(TEXT_ENTITIES_FIELD) + private List textEntities; + + /** + * Optional. User that completed the task; omitted if the task wasn't completed + */ + @JsonProperty(COMPLETED_BY_USER_FIELD) + private User completedByUser; + + /** + * Optional. Point in time (Unix timestamp) when the task was completed; 0 if the task wasn't completed + */ + @JsonProperty(COMPLETION_DATE_FIELD) + private Integer completionDate; +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/checklist/ChecklistTasksAdded.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/checklist/ChecklistTasksAdded.java new file mode 100644 index 000000000..163f89018 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/checklist/ChecklistTasksAdded.java @@ -0,0 +1,54 @@ +package org.telegram.telegrambots.meta.api.objects.checklist; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.objects.message.Message; + +import java.util.List; + +/** + * @author JetBrains + * @version 7.0 + * + * Describes a service message about tasks added to a checklist. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +@SuperBuilder +@Jacksonized +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ChecklistTasksAdded implements BotApiObject { + private static final String CHECKLIST_MESSAGE_FIELD = "checklist_message"; + private static final String TASKS_FIELD = "tasks"; + + /** + * Optional. Message containing the checklist to which the tasks were added. + * Note that the Message object in this field will not contain the reply_to_message field + * even if it itself is a reply. + */ + @JsonProperty(CHECKLIST_MESSAGE_FIELD) + private Message checklistMessage; + + /** + * List of tasks added to the checklist + */ + @JsonProperty(TASKS_FIELD) + @NonNull + private List tasks; +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/checklist/ChecklistTasksDone.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/checklist/ChecklistTasksDone.java new file mode 100644 index 000000000..958d37196 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/checklist/ChecklistTasksDone.java @@ -0,0 +1,59 @@ +package org.telegram.telegrambots.meta.api.objects.checklist; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.objects.message.Message; + +import java.util.List; + +/** + * @author JetBrains + * @version 7.0 + * + * Describes a service message about checklist tasks marked as done or not done. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +@SuperBuilder +@Jacksonized +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ChecklistTasksDone implements BotApiObject { + private static final String CHECKLIST_MESSAGE_FIELD = "checklist_message"; + private static final String MARKED_AS_DONE_TASK_IDS_FIELD = "marked_as_done_task_ids"; + private static final String MARKED_AS_NOT_DONE_TASK_IDS_FIELD = "marked_as_not_done_task_ids"; + + /** + * Optional. Message containing the checklist whose tasks were marked as done or not done. + * Note that the Message object in this field will not contain the reply_to_message field + * even if it itself is a reply. + */ + @JsonProperty(CHECKLIST_MESSAGE_FIELD) + private Message checklistMessage; + + /** + * Optional. Identifiers of the tasks that were marked as done + */ + @JsonProperty(MARKED_AS_DONE_TASK_IDS_FIELD) + private List markedAsDoneTaskIds; + + /** + * Optional. Identifiers of the tasks that were marked as not done + */ + @JsonProperty(MARKED_AS_NOT_DONE_TASK_IDS_FIELD) + private List markedAsNotDoneTaskIds; +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/checklist/InputChecklist.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/checklist/InputChecklist.java new file mode 100644 index 000000000..bf7f105ac --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/checklist/InputChecklist.java @@ -0,0 +1,106 @@ +package org.telegram.telegrambots.meta.api.objects.checklist; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.interfaces.Validable; +import org.telegram.telegrambots.meta.api.objects.MessageEntity; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +import java.util.List; + +/** + * @author JetBrains + * @version 7.0 + * + * Describes a checklist to create. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@RequiredArgsConstructor +@AllArgsConstructor +@SuperBuilder +@Jacksonized +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class InputChecklist implements BotApiObject, Validable { + private static final String TITLE_FIELD = "title"; + private static final String PARSE_MODE_FIELD = "parse_mode"; + private static final String TITLE_ENTITIES_FIELD = "title_entities"; + private static final String TASKS_FIELD = "tasks"; + private static final String OTHERS_CAN_ADD_TASKS_FIELD = "others_can_add_tasks"; + private static final String OTHERS_CAN_MARK_TASKS_AS_DONE_FIELD = "others_can_mark_tasks_as_done"; + + /** + * Title of the checklist; 1-255 characters after entities parsing + */ + @JsonProperty(TITLE_FIELD) + @NonNull + private String title; + + /** + * Optional. Mode for parsing entities in the title. See formatting options for more details. + */ + @JsonProperty(PARSE_MODE_FIELD) + private String parseMode; + + /** + * Optional. List of special entities that appear in the title, which can be specified instead of parse_mode. + * Currently, only bold, italic, underline, strikethrough, spoiler, and custom_emoji entities are allowed. + */ + @JsonProperty(TITLE_ENTITIES_FIELD) + private List titleEntities; + + /** + * List of 1-30 tasks in the checklist + */ + @JsonProperty(TASKS_FIELD) + @NonNull + private List tasks; + + /** + * Optional. Pass True if other users can add tasks to the checklist + */ + @JsonProperty(OTHERS_CAN_ADD_TASKS_FIELD) + private Boolean othersCanAddTasks; + + /** + * Optional. Pass True if other users can mark tasks as done or not done in the checklist + */ + @JsonProperty(OTHERS_CAN_MARK_TASKS_AS_DONE_FIELD) + private Boolean othersCanMarkTasksAsDone; + + @Override + public void validate() throws TelegramApiValidationException { + if (title == null || title.isEmpty()) { + throw new TelegramApiValidationException("Checklist title can't be empty", this); + } + if (title.length() > 255) { + throw new TelegramApiValidationException("Checklist title can't be longer than 255 characters", this); + } + if (tasks == null || tasks.isEmpty()) { + throw new TelegramApiValidationException("Checklist tasks can't be empty", this); + } + if (tasks.size() > 30) { + throw new TelegramApiValidationException("Checklist can't have more than 30 tasks", this); + } + + for (InputChecklistTask task : tasks) { + task.validate(); + } + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/checklist/InputChecklistTask.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/checklist/InputChecklistTask.java new file mode 100644 index 000000000..f89fb57b2 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/checklist/InputChecklistTask.java @@ -0,0 +1,85 @@ +package org.telegram.telegrambots.meta.api.objects.checklist; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.interfaces.Validable; +import org.telegram.telegrambots.meta.api.objects.MessageEntity; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +import java.util.List; + +/** + * @author JetBrains + * @version 7.0 + * + * Describes a task to add to a checklist. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@RequiredArgsConstructor +@AllArgsConstructor +@SuperBuilder +@Jacksonized +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class InputChecklistTask implements BotApiObject, Validable { + private static final String ID_FIELD = "id"; + private static final String TEXT_FIELD = "text"; + private static final String PARSE_MODE_FIELD = "parse_mode"; + private static final String TEXT_ENTITIES_FIELD = "text_entities"; + + /** + * Unique identifier of the task; must be positive and unique among all task identifiers currently present in the checklist + */ + @JsonProperty(ID_FIELD) + @NonNull + private Integer id; + + /** + * Text of the task; 1-100 characters after entities parsing + */ + @JsonProperty(TEXT_FIELD) + @NonNull + private String text; + + /** + * Optional. Mode for parsing entities in the text. See formatting options for more details. + */ + @JsonProperty(PARSE_MODE_FIELD) + private String parseMode; + + /** + * Optional. List of special entities that appear in the text, which can be specified instead of parse_mode. + * Currently, only bold, italic, underline, strikethrough, spoiler, and custom_emoji entities are allowed. + */ + @JsonProperty(TEXT_ENTITIES_FIELD) + private List textEntities; + + @Override + public void validate() throws TelegramApiValidationException { + if (id == null || id <= 0) { + throw new TelegramApiValidationException("Task id must be positive", this); + } + if (text == null || text.isEmpty()) { + throw new TelegramApiValidationException("Task text can't be empty", this); + } + if (text.length() > 100) { + throw new TelegramApiValidationException("Task text can't be longer than 100 characters", this); + } + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGiftInfo.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGiftInfo.java index 48b30e3c5..0efe02157 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGiftInfo.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGiftInfo.java @@ -35,6 +35,8 @@ public class UniqueGiftInfo implements BotApiObject { private static final String ORIGIN_FIELD = "origin"; private static final String OWNED_GIFT_ID_FIELD = "owned_gift_id"; private static final String TRANSFER_STAR_COUNT_FIELD = "transfer_star_count"; + private static final String LAST_RESALE_STAR_COUNT_FIELD = "last_resale_star_count"; + private static final String NEXT_TRANSFER_DATE_FIELD = "next_transfer_date"; /** * Information about the gift @@ -62,4 +64,18 @@ public class UniqueGiftInfo implements BotApiObject { @JsonProperty(TRANSFER_STAR_COUNT_FIELD) @NonNull private Integer transferStarCount; + + /** + * Optional. + * For gifts bought from other users, the price paid for the gift + */ + @JsonProperty(LAST_RESALE_STAR_COUNT_FIELD) + private Integer lastResaleStarCount; + + /** + * Optional. + * Point in time (Unix timestamp) when the gift can be transferred. If it is in the past, then the gift can be transferred now + */ + @JsonProperty(NEXT_TRANSFER_DATE_FIELD) + private String nextTransferDate; } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/owned/OwnedGiftUnique.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/owned/OwnedGiftUnique.java index a67c5c8c5..e3d07c3ce 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/owned/OwnedGiftUnique.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/owned/OwnedGiftUnique.java @@ -39,6 +39,7 @@ public class OwnedGiftUnique extends OwnedGift { private static final String GIFT_FIELD = "gift"; private static final String CAN_BE_TRANSFERRED_FIELD = "can_be_transferred"; private static final String TRANSFER_STAR_COUNT_FIELD = "transfer_star_count"; + private static final String NEXT_TRANSFER_DATE_FIELD = "next_transfer_date"; /** * Information about the unique gift @@ -61,6 +62,14 @@ public class OwnedGiftUnique extends OwnedGift { @JsonProperty(TRANSFER_STAR_COUNT_FIELD) private Integer transferStarCount; + /** + * Optional. + * Point in time (Unix timestamp) when the gift can be transferred. + * If it is in the past, then the gift can be transferred now + */ + @JsonProperty(NEXT_TRANSFER_DATE_FIELD) + private String nextTransferDate; + @Override public String getType() { return TYPE; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/message/Message.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/message/Message.java index 94ce56ae3..fa0801c74 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/message/Message.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/message/Message.java @@ -35,6 +35,9 @@ import org.telegram.telegrambots.meta.api.objects.boost.ChatBoostAdded; import org.telegram.telegrambots.meta.api.objects.chat.Chat; import org.telegram.telegrambots.meta.api.objects.chat.background.ChatBackground; +import org.telegram.telegrambots.meta.api.objects.checklist.Checklist; +import org.telegram.telegrambots.meta.api.objects.checklist.ChecklistTasksAdded; +import org.telegram.telegrambots.meta.api.objects.checklist.ChecklistTasksDone; import org.telegram.telegrambots.meta.api.objects.forum.ForumTopicClosed; import org.telegram.telegrambots.meta.api.objects.forum.ForumTopicCreated; import org.telegram.telegrambots.meta.api.objects.forum.ForumTopicEdited; @@ -52,6 +55,7 @@ import org.telegram.telegrambots.meta.api.objects.location.Location; import org.telegram.telegrambots.meta.api.objects.messageorigin.MessageOrigin; import org.telegram.telegrambots.meta.api.objects.passport.PassportData; +import org.telegram.telegrambots.meta.api.objects.payments.DirectMessagePriceChanged; import org.telegram.telegrambots.meta.api.objects.payments.Invoice; import org.telegram.telegrambots.meta.api.objects.payments.RefundedPayment; import org.telegram.telegrambots.meta.api.objects.payments.SuccessfulPayment; @@ -182,6 +186,10 @@ public class Message implements MaybeInaccessibleMessage { private static final String UNIQUE_GIFT_FIELD = "unique_gift"; private static final String PAID_MESSAGE_PRICE_CHANGED_FIELD = "paid_message_price_changed"; private static final String PAID_STAR_COUNT_FIELD = "paid_star_count"; + private static final String DIRECT_MESSAGE_PRICE_CHANGED_FIELD = "direct_message_price_changed"; + private static final String CHECKLIST_FIELD = "checklist"; + private static final String CHECKLIST_TASKS_DONE_FIELD = "checklist_tasks_done"; + private static final String CHECKLIST_TASKS_ADDED_FIELD = "checklist_tasks_added"; /** * Unique message identifier inside this chat. In specific instances (e.g., message containing a video sent to a big chat), @@ -787,6 +795,30 @@ public class Message implements MaybeInaccessibleMessage { */ @JsonProperty(PAID_STAR_COUNT_FIELD) private Integer paidStarCount; + /** + * Optional. + * Service message: the price for paid messages in the corresponding direct messages chat of a channel has changed + */ + @JsonProperty(DIRECT_MESSAGE_PRICE_CHANGED_FIELD) + private DirectMessagePriceChanged directMessagePriceChanged; + /** + * Optional. + * Message is a checklist + */ + @JsonProperty(CHECKLIST_FIELD) + private Checklist checklist; + /** + * Optional. + * Service message: some tasks in a checklist were marked as done or not done + */ + @JsonProperty(CHECKLIST_TASKS_DONE_FIELD) + private ChecklistTasksDone checklistTasksDone; + /** + * Optional. + * Service message: tasks were added to a checklist + */ + @JsonProperty(CHECKLIST_TASKS_ADDED_FIELD) + private ChecklistTasksAdded checklistTasksAdded; public List getEntities() { if (entities != null) { @@ -1063,4 +1095,24 @@ public boolean hasPaidMessagePriceChanged() { public boolean hasPaidStarCount() { return paidStarCount != null; } + + @JsonIgnore + public boolean hasDirectMessagePriceChanged() { + return directMessagePriceChanged != null; + } + + @JsonIgnore + public boolean hasChecklist() { + return checklist != null; + } + + @JsonIgnore + public boolean hasChecklistTasksDone() { + return checklistTasksDone != null; + } + + @JsonIgnore + public boolean hasChecklistTasksAdded() { + return checklistTasksAdded != null; + } } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/payments/DirectMessagePriceChanged.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/payments/DirectMessagePriceChanged.java new file mode 100644 index 000000000..67dacd964 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/payments/DirectMessagePriceChanged.java @@ -0,0 +1,53 @@ +package org.telegram.telegrambots.meta.api.objects.payments; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; + +/** + * @author JetBrains + * @version 7.0 + * + * Describes a service message about a change in the price of direct messages sent to a channel chat. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@RequiredArgsConstructor +@AllArgsConstructor +@SuperBuilder +@Jacksonized +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class DirectMessagePriceChanged implements BotApiObject { + private static final String ARE_DIRECT_MESSAGES_ENABLED_FIELD = "are_direct_messages_enabled"; + private static final String DIRECT_MESSAGE_STAR_COUNT_FIELD = "direct_message_star_count"; + + /** + * True, if direct messages are enabled for the channel chat; false otherwise + */ + @JsonProperty(ARE_DIRECT_MESSAGES_ENABLED_FIELD) + @NonNull + private Boolean areDirectMessagesEnabled; + + /** + * Optional. The new number of Telegram Stars that must be paid by users for each direct message sent to the channel. + * Does not apply to users who have been exempted by administrators. Defaults to 0. + */ + @JsonProperty(DIRECT_MESSAGE_STAR_COUNT_FIELD) + private Integer directMessageStarCount; +} diff --git a/telegrambots-springboot-longpolling-starter/pom.xml b/telegrambots-springboot-longpolling-starter/pom.xml index d6f0c1c4c..9f5ddcac7 100644 --- a/telegrambots-springboot-longpolling-starter/pom.xml +++ b/telegrambots-springboot-longpolling-starter/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 9.0.0 + 9.1.0 telegrambots-springboot-longpolling-starter @@ -71,7 +71,7 @@ UTF-8 UTF-8 - 9.0.0 + 9.1.0 3.2.3 diff --git a/telegrambots-springboot-webhook-starter/pom.xml b/telegrambots-springboot-webhook-starter/pom.xml index e582ca12d..6b4ee1064 100644 --- a/telegrambots-springboot-webhook-starter/pom.xml +++ b/telegrambots-springboot-webhook-starter/pom.xml @@ -6,7 +6,7 @@ org.telegram Bots - 9.0.0 + 9.1.0 telegrambots-springboot-webhook-starter @@ -71,7 +71,7 @@ UTF-8 UTF-8 - 9.0.0 + 9.1.0 3.2.3 2.17.2 diff --git a/telegrambots-test-reports/pom.xml b/telegrambots-test-reports/pom.xml index d31743b5e..ccd6b57c3 100644 --- a/telegrambots-test-reports/pom.xml +++ b/telegrambots-test-reports/pom.xml @@ -6,7 +6,7 @@ org.telegram Bots - 9.0.0 + 9.1.0 telegrambots-test-reports diff --git a/telegrambots-webhook/pom.xml b/telegrambots-webhook/pom.xml index d136139e2..eaf743032 100644 --- a/telegrambots-webhook/pom.xml +++ b/telegrambots-webhook/pom.xml @@ -6,7 +6,7 @@ org.telegram Bots - 9.0.0 + 9.1.0 telegrambots-webhook From 92039128d9db550ae069d801ef20aa9f334c0c62 Mon Sep 17 00:00:00 2001 From: ruben Date: Sun, 7 Sep 2025 23:34:19 +0100 Subject: [PATCH 06/16] Api Version 9.2 --- pom.xml | 6 +- telegrambots-abilities/pom.xml | 6 +- telegrambots-client-jetty-adapter/pom.xml | 2 +- .../client/jetty/JettyTelegramClient.java | 3 + telegrambots-client/pom.xml | 2 +- .../client/okhttp/OkHttpTelegramClient.java | 3 + telegrambots-extensions/README.md | 4 +- telegrambots-extensions/pom.xml | 6 +- telegrambots-longpolling/pom.xml | 4 +- telegrambots-meta/pom.xml | 2 +- .../meta/api/methods/CopyMessage.java | 18 +++ .../meta/api/methods/CopyMessages.java | 8 ++ .../meta/api/methods/ForwardMessage.java | 18 +++ .../meta/api/methods/ForwardMessages.java | 8 ++ .../groupadministration/LeaveChat.java | 3 +- .../PromoteChatMember.java | 8 ++ .../pinnedmessages/PinChatMessage.java | 10 +- .../pinnedmessages/UnpinAllChatMessages.java | 9 +- .../pinnedmessages/UnpinChatMessage.java | 11 +- .../meta/api/methods/polls/SendPoll.java | 2 + .../meta/api/methods/send/SendAnimation.java | 14 +++ .../meta/api/methods/send/SendAudio.java | 14 +++ .../meta/api/methods/send/SendChatAction.java | 3 +- .../meta/api/methods/send/SendContact.java | 18 +++ .../meta/api/methods/send/SendDice.java | 18 +++ .../meta/api/methods/send/SendDocument.java | 14 +++ .../meta/api/methods/send/SendGame.java | 11 +- .../meta/api/methods/send/SendLocation.java | 18 +++ .../api/methods/send/SendMediaBotMethod.java | 7 ++ .../meta/api/methods/send/SendMediaGroup.java | 7 ++ .../meta/api/methods/send/SendMessage.java | 18 +++ .../meta/api/methods/send/SendPaidMedia.java | 16 +++ .../meta/api/methods/send/SendPhoto.java | 14 +++ .../meta/api/methods/send/SendSticker.java | 14 +++ .../meta/api/methods/send/SendVenue.java | 18 +++ .../meta/api/methods/send/SendVideo.java | 14 +++ .../meta/api/methods/send/SendVideoNote.java | 14 +++ .../meta/api/methods/send/SendVoice.java | 14 +++ .../suggestedPost/ApproveSuggestedPost.java | 95 ++++++++++++++ .../suggestedPost/DeclineSuggestedPost.java | 90 ++++++++++++++ .../updatingmessages/DeleteMessage.java | 8 +- .../api/methods/verification/VerifyChat.java | 3 +- .../meta/api/objects/ReplyParameters.java | 10 +- .../adminrights/ChatAdministratorRights.java | 8 ++ .../meta/api/objects/chat/ChatFullInfo.java | 16 +++ .../chatmember/ChatMemberAdministrator.java | 8 ++ .../commands/scope/BotCommandScopeChat.java | 3 +- .../BotCommandScopeChatAdministrators.java | 3 +- .../scope/BotCommandScopeChatMember.java | 3 +- .../meta/api/objects/gifts/Gift.java | 9 ++ .../meta/api/objects/gifts/UniqueGift.java | 9 ++ .../objects/message/DirectMessagesTopic.java | 46 +++++++ .../meta/api/objects/message/Message.java | 116 ++++++++++++++++++ .../SuggestedPostApprovalFailed.java | 53 ++++++++ .../suggestedpost/SuggestedPostApproved.java | 60 +++++++++ .../suggestedpost/SuggestedPostDeclined.java | 49 ++++++++ .../suggestedpost/SuggestedPostInfo.java | 59 +++++++++ .../suggestedpost/SuggestedPostPaid.java | 70 +++++++++++ .../SuggestedPostParameters.java | 49 ++++++++ .../suggestedpost/SuggestedPostPrice.java | 50 ++++++++ .../suggestedpost/SuggestedPostRefunded.java | 54 ++++++++ .../pom.xml | 6 +- .../pom.xml | 6 +- telegrambots-test-reports/pom.xml | 2 +- telegrambots-webhook/pom.xml | 6 +- 65 files changed, 1219 insertions(+), 51 deletions(-) create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/suggestedPost/ApproveSuggestedPost.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/suggestedPost/DeclineSuggestedPost.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/message/DirectMessagesTopic.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/suggestedpost/SuggestedPostApprovalFailed.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/suggestedpost/SuggestedPostApproved.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/suggestedpost/SuggestedPostDeclined.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/suggestedpost/SuggestedPostInfo.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/suggestedpost/SuggestedPostPaid.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/suggestedpost/SuggestedPostParameters.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/suggestedpost/SuggestedPostPrice.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/suggestedpost/SuggestedPostRefunded.java diff --git a/pom.xml b/pom.xml index 16af90335..737f5d241 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots pom - 9.1.0 + 9.2.0 telegrambots-meta @@ -67,11 +67,11 @@ 2.0.12 1.18.34 33.2.1-jre - 3.14.0 + 3.18.0 2.16.1 4.12.0 - 5.10.3 + 5.12.2 5.12.0 5.12.0 4.2.1 diff --git a/telegrambots-abilities/pom.xml b/telegrambots-abilities/pom.xml index f2c38c393..08aefc10d 100644 --- a/telegrambots-abilities/pom.xml +++ b/telegrambots-abilities/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 9.1.0 + 9.2.0 telegrambots-abilities @@ -93,12 +93,12 @@ org.telegram telegrambots-webhook - 9.1.0 + 9.2.0 org.telegram telegrambots-longpolling - 9.1.0 + 9.2.0 diff --git a/telegrambots-client-jetty-adapter/pom.xml b/telegrambots-client-jetty-adapter/pom.xml index 9c160d953..ca72d4245 100644 --- a/telegrambots-client-jetty-adapter/pom.xml +++ b/telegrambots-client-jetty-adapter/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 9.1.0 + 9.2.0 Telegram Bots Client Jetty HttpClient adapter diff --git a/telegrambots-client-jetty-adapter/src/main/java/org/telegram/telegrambots/client/jetty/JettyTelegramClient.java b/telegrambots-client-jetty-adapter/src/main/java/org/telegram/telegrambots/client/jetty/JettyTelegramClient.java index 067aa87d2..87dbe1301 100644 --- a/telegrambots-client-jetty-adapter/src/main/java/org/telegram/telegrambots/client/jetty/JettyTelegramClient.java +++ b/telegrambots-client-jetty-adapter/src/main/java/org/telegram/telegrambots/client/jetty/JettyTelegramClient.java @@ -349,6 +349,7 @@ public CompletableFuture> executeAsync(SendMediaGroup sendMediaGro .addPart(SendMediaGroup.BUSINESS_CONNECTION_ID_FIELD, sendMediaGroup.getBusinessConnectionId()) .addPart(SendMediaGroup.MESSAGE_EFFECT_ID_FIELD, sendMediaGroup.getMessageEffectId()) .addPart(SendMediaGroup.ALLOW_PAID_BROADCAST_FIELD, sendMediaGroup.getAllowSendingWithoutReply()) + .addPart(SendMediaGroup.DIRECT_MESSAGES_TOPIC_ID_FIELD, sendMediaGroup.getDirectMessagesTopicId()) .addJsonPart(SendMediaGroup.REPLY_MARKUP_FIELD, sendMediaGroup.getReplyMarkup()) .addJsonPart(SendMediaGroup.REPLY_PARAMETERS_FIELD, sendMediaGroup.getReplyParameters()); @@ -639,6 +640,8 @@ private > Completab .addPart(SendMediaBotMethod.PROTECT_CONTENT_FIELD, method.getProtectContent()) .addPart(SendMediaBotMethod.ALLOW_SENDING_WITHOUT_REPLY_FIELD, method.getAllowSendingWithoutReply()) .addPart(SendMediaBotMethod.MESSAGE_EFFECT_ID_FIELD, method.getMessageEffectId()) + .addPart(SendMediaBotMethod.DIRECT_MESSAGES_TOPIC_ID_FIELD, method.getDirectMessagesTopicId()) + .addPart(SendMediaBotMethod.SUGGESTED_POST_PARAMETERS_FIELD, method.getSuggestedPostParameters()) .addJsonPart(SendMediaBotMethod.REPLY_PARAMETERS_FIELD, method.getReplyParameters()) .addJsonPart(SendMediaBotMethod.REPLY_MARKUP_FIELD, method.getReplyMarkup()); diff --git a/telegrambots-client/pom.xml b/telegrambots-client/pom.xml index 8c2f7cbc0..c0aa93f4d 100644 --- a/telegrambots-client/pom.xml +++ b/telegrambots-client/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 9.1.0 + 9.2.0 Telegram Bots Client diff --git a/telegrambots-client/src/main/java/org/telegram/telegrambots/client/okhttp/OkHttpTelegramClient.java b/telegrambots-client/src/main/java/org/telegram/telegrambots/client/okhttp/OkHttpTelegramClient.java index c772ee4bb..dc81e8509 100644 --- a/telegrambots-client/src/main/java/org/telegram/telegrambots/client/okhttp/OkHttpTelegramClient.java +++ b/telegrambots-client/src/main/java/org/telegram/telegrambots/client/okhttp/OkHttpTelegramClient.java @@ -341,6 +341,7 @@ public CompletableFuture> executeAsync(SendMediaGroup sendMediaGro .addPart(SendMediaGroup.BUSINESS_CONNECTION_ID_FIELD, sendMediaGroup.getBusinessConnectionId()) .addPart(SendMediaGroup.MESSAGE_EFFECT_ID_FIELD, sendMediaGroup.getMessageEffectId()) .addPart(SendMediaGroup.ALLOW_PAID_BROADCAST_FIELD, sendMediaGroup.getAllowSendingWithoutReply()) + .addPart(SendMediaGroup.DIRECT_MESSAGES_TOPIC_ID_FIELD, sendMediaGroup.getDirectMessagesTopicId()) .addJsonPart(SendMediaGroup.REPLY_MARKUP_FIELD, sendMediaGroup.getReplyMarkup()) .addJsonPart(SendMediaGroup.REPLY_PARAMETERS_FIELD, sendMediaGroup.getReplyParameters()); @@ -632,6 +633,8 @@ private > Completab .addPart(SendMediaBotMethod.ALLOW_SENDING_WITHOUT_REPLY_FIELD, method.getAllowSendingWithoutReply()) .addPart(SendMediaBotMethod.MESSAGE_EFFECT_ID_FIELD, method.getMessageEffectId()) .addPart(SendMediaBotMethod.ALLOW_PAID_BROADCAST_FIELD, method.getAllowPaidBroadcast()) + .addPart(SendMediaBotMethod.DIRECT_MESSAGES_TOPIC_ID_FIELD, method.getDirectMessagesTopicId()) + .addPart(SendMediaBotMethod.SUGGESTED_POST_PARAMETERS_FIELD, method.getSuggestedPostParameters()) .addJsonPart(SendMediaBotMethod.REPLY_PARAMETERS_FIELD, method.getReplyParameters()) .addJsonPart(SendMediaBotMethod.REPLY_MARKUP_FIELD, method.getReplyMarkup()); diff --git a/telegrambots-extensions/README.md b/telegrambots-extensions/README.md index e8f927dd5..905f9faf0 100644 --- a/telegrambots-extensions/README.md +++ b/telegrambots-extensions/README.md @@ -16,12 +16,12 @@ Just import add the library to your project with one of these options: org.telegram telegrambots-extensions - 9.1.0 + 9.2.0 ``` 2. Using Gradle: ```gradle - implementation 'org.telegram:telegrambots-extensions:9.1.0' + implementation 'org.telegram:telegrambots-extensions:9.2.0' ``` \ No newline at end of file diff --git a/telegrambots-extensions/pom.xml b/telegrambots-extensions/pom.xml index b941c3a16..6a105ffd8 100644 --- a/telegrambots-extensions/pom.xml +++ b/telegrambots-extensions/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 9.1.0 + 9.2.0 telegrambots-extensions @@ -78,12 +78,12 @@ org.telegram telegrambots-webhook - 9.1.0 + 9.2.0 org.telegram telegrambots-longpolling - 9.1.0 + 9.2.0 diff --git a/telegrambots-longpolling/pom.xml b/telegrambots-longpolling/pom.xml index f1f4a7303..5d7acb324 100644 --- a/telegrambots-longpolling/pom.xml +++ b/telegrambots-longpolling/pom.xml @@ -6,7 +6,7 @@ org.telegram Bots - 9.1.0 + 9.2.0 telegrambots-longpolling @@ -89,7 +89,7 @@ ch.qos.logback logback-classic - 1.5.0 + 1.5.18 test diff --git a/telegrambots-meta/pom.xml b/telegrambots-meta/pom.xml index 342192644..c688fba52 100644 --- a/telegrambots-meta/pom.xml +++ b/telegrambots-meta/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 9.1.0 + 9.2.0 telegrambots-meta 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 7d2fefd5f..b29acc8f3 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 @@ -18,6 +18,7 @@ import org.telegram.telegrambots.meta.api.objects.MessageId; import org.telegram.telegrambots.meta.api.objects.ReplyParameters; import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard; +import org.telegram.telegrambots.meta.api.objects.suggestedpost.SuggestedPostParameters; import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; import org.telegram.telegrambots.meta.util.Validations; @@ -50,6 +51,7 @@ public class CopyMessage extends BotApiMethod { private static final String CHAT_ID_FIELD = "chat_id"; private static final String MESSAGE_THREAD_ID_FIELD = "message_thread_id"; + private static final String DIRECT_MESSAGES_TOPIC_ID_FIELD = "direct_messages_topic_id"; private static final String FROM_CHAT_ID_FIELD = "from_chat_id"; private static final String MESSAGE_ID_FIELD = "message_id"; private static final String CAPTION_FIELD = "caption"; @@ -64,6 +66,7 @@ public class CopyMessage extends BotApiMethod { private static final String SHOW_CAPTION_ABOVE_MEDIA_FIELD = "show_caption_above_media"; private static final String ALLOW_PAID_BROADCAST_FIELD = "allow_paid_broadcast"; private static final String VIDEO_START_TIMESTAMP_FIELD = "video_start_timestamp"; + private static final String SUGGESTED_POST_PARAMETERS_FIELD = "suggested_post_parameters"; @JsonProperty(CHAT_ID_FIELD) @NonNull @@ -74,6 +77,13 @@ public class CopyMessage extends BotApiMethod { */ @JsonProperty(MESSAGE_THREAD_ID_FIELD) private Integer messageThreadId; + /** + * Optional. + * Identifier of the direct messages topic to which the message will be sent; + * required if the message is sent to a direct messages chat + */ + @JsonProperty(DIRECT_MESSAGES_TOPIC_ID_FIELD) + private Integer directMessagesTopicId; @JsonProperty(FROM_CHAT_ID_FIELD) @NonNull private String fromChatId; ///< Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername) @@ -128,6 +138,14 @@ public class CopyMessage extends BotApiMethod { @JsonProperty(VIDEO_START_TIMESTAMP_FIELD) private Boolean videoStartTimestamp; + /** + * Optional + * A JSON-serialized object containing the parameters of the suggested post to send; + * for direct messages chats only + */ + @JsonProperty(SUGGESTED_POST_PARAMETERS_FIELD) + private SuggestedPostParameters suggestedPostParameters; + @Tolerate public void setChatId(@NonNull Long chatId) { this.chatId = chatId.toString(); diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/CopyMessages.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/CopyMessages.java index 7179df972..dd03ff8db 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/CopyMessages.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/CopyMessages.java @@ -52,6 +52,7 @@ public class CopyMessages extends BotApiMethod> { private static final String CHAT_ID_FIELD = "chat_id"; private static final String MESSAGE_THREAD_ID_FIELD = "message_thread_id"; + private static final String DIRECT_MESSAGES_TOPIC_ID_FIELD = "direct_messages_topic_id"; private static final String FROM_CHAT_ID_FIELD = "from_chat_id"; private static final String MESSAGE_IDS_FIELD = "message_ids"; private static final String DISABLE_NOTIFICATION_FIELD = "disable_notification"; @@ -70,6 +71,13 @@ public class CopyMessages extends BotApiMethod> { */ @JsonProperty(MESSAGE_THREAD_ID_FIELD) private Integer messageThreadId; + /** + * Optional. + * Identifier of the direct messages topic to which the messages will be sent; + * required if the messages are sent to a direct messages chat + */ + @JsonProperty(DIRECT_MESSAGES_TOPIC_ID_FIELD) + private Integer directMessagesTopicId; /** * Unique identifier for the chat where the original messages were sent (or channel username in the format @channelusername) */ diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/ForwardMessage.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/ForwardMessage.java index 0a091c09a..573f1f89f 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/ForwardMessage.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/ForwardMessage.java @@ -14,6 +14,7 @@ import lombok.experimental.Tolerate; import lombok.extern.jackson.Jacksonized; import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodMessage; +import org.telegram.telegrambots.meta.api.objects.suggestedpost.SuggestedPostParameters; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; import org.telegram.telegrambots.meta.util.Validations; @@ -40,11 +41,13 @@ public class ForwardMessage extends BotApiMethodMessage { private static final String CHAT_ID_FIELD = "chat_id"; private static final String MESSAGE_THREAD_ID_FIELD = "message_thread_id"; + private static final String DIRECT_MESSAGES_TOPIC_ID_FIELD = "direct_messages_topic_id"; private static final String FROM_CHAT_ID_FIELD = "from_chat_id"; private static final String MESSAGE_ID_FIELD = "message_id"; private static final String DISABLE_NOTIFICATION_FIELD = "disable_notification"; private static final String PROTECT_CONTENT_FIELD = "protect_content"; private static final String VIDEO_START_TIMESTAMP_FIELD = "video_start_timestamp"; + private static final String SUGGESTED_POST_PARAMETERS_FIELD = "suggested_post_parameters"; @JsonProperty(CHAT_ID_FIELD) @NonNull @@ -55,6 +58,13 @@ public class ForwardMessage extends BotApiMethodMessage { */ @JsonProperty(MESSAGE_THREAD_ID_FIELD) private Integer messageThreadId; + /** + * Optional. + * Identifier of the direct messages topic to which the message will be forwarded; + * required if the message is forwarded to a direct messages chat + */ + @JsonProperty(DIRECT_MESSAGES_TOPIC_ID_FIELD) + private Integer directMessagesTopicId; @JsonProperty(FROM_CHAT_ID_FIELD) @NonNull private String fromChatId; ///< Unique identifier for the chat where the original message was sent — User or GroupChat id @@ -78,6 +88,14 @@ public class ForwardMessage extends BotApiMethodMessage { @JsonProperty(VIDEO_START_TIMESTAMP_FIELD) private Boolean videoStartTimestamp; + /** + * Optional + * A JSON-serialized object containing the parameters of the suggested post to send; + * for direct messages chats only + */ + @JsonProperty(SUGGESTED_POST_PARAMETERS_FIELD) + private SuggestedPostParameters suggestedPostParameters; + @Tolerate public void setChatId(@NonNull Long chatId) { this.chatId = chatId.toString(); diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/ForwardMessages.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/ForwardMessages.java index 9c4c249f5..73a02f228 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/ForwardMessages.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/ForwardMessages.java @@ -48,6 +48,7 @@ public class ForwardMessages extends BotApiMethod> { private static final String CHAT_ID_FIELD = "chat_id"; private static final String MESSAGE_THREAD_ID_FIELD = "message_thread_id"; + private static final String DIRECT_MESSAGES_TOPIC_ID_FIELD = "direct_messages_topic_id"; private static final String FROM_CHAT_ID_FIELD = "from_chat_id"; private static final String MESSAGE_IDS_FIELD = "message_ids"; private static final String DISABLE_NOTIFICATION_FIELD = "disable_notification"; @@ -65,6 +66,13 @@ public class ForwardMessages extends BotApiMethod> { */ @JsonProperty(MESSAGE_THREAD_ID_FIELD) private Integer messageThreadId; + /** + * Optional. + * Identifier of the direct messages topic to which the messages will be forwarded; + * required if the messages are forwarded to a direct messages chat + */ + @JsonProperty(DIRECT_MESSAGES_TOPIC_ID_FIELD) + private Integer directMessagesTopicId; /** * Unique identifier for the chat where the original messages were sent (or channel username in the format @channelusername) */ diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/LeaveChat.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/LeaveChat.java index 192b5a288..df2c4b1b3 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/LeaveChat.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/LeaveChat.java @@ -20,6 +20,7 @@ * @author Ruben Bermudez * @version 1.0 * Use this method for your bot to leave a group, supergroup or channel. Returns True on success. + * Channel direct messages chats aren't supported; leave the corresponding channel instead. */ @EqualsAndHashCode(callSuper = false) @Getter @@ -37,7 +38,7 @@ public class LeaveChat extends BotApiMethodBoolean { @JsonProperty(CHATID_FIELD) @NonNull - private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels) + private String chatId; ///< Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername). Channel direct messages chats aren't supported; leave the corresponding channel instead. @Tolerate public void setChatId(@NonNull Long chatId) { diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/PromoteChatMember.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/PromoteChatMember.java index 4655230b8..bdd779b73 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/PromoteChatMember.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/PromoteChatMember.java @@ -55,6 +55,7 @@ public class PromoteChatMember extends BotApiMethodBoolean { private static final String CAN_POST_STORIES_FIELD = "can_post_stories"; private static final String CAN_EDIT_STORIES_FIELD = "can_edit_stories"; private static final String CAN_DELETE_STORIES_FIELD = "can_delete_stories"; + private static final String CAN_MANAGE_DIRECT_MESSAGES_FIELD = "can_manage_direct_messages"; @JsonProperty(CHATID_FIELD) @NonNull @@ -126,6 +127,13 @@ public class PromoteChatMember extends BotApiMethodBoolean { @JsonProperty(CAN_DELETE_STORIES_FIELD) private Boolean canDeleteStories; + /** + * Optional + * Pass True if the administrator can manage direct messages within the channel and decline suggested posts; for channels only + */ + @JsonProperty(CAN_MANAGE_DIRECT_MESSAGES_FIELD) + private Boolean canManageDirectMessages; + @Tolerate public void setChatId(@NonNull Long chatId) { this.chatId = chatId.toString(); diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/pinnedmessages/PinChatMessage.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/pinnedmessages/PinChatMessage.java index debc73a2b..1047c5a26 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/pinnedmessages/PinChatMessage.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/pinnedmessages/PinChatMessage.java @@ -21,10 +21,10 @@ * @author Ruben Bermudez * @version 3.1 * Use this method to add a message to the list of pinned messages in a chat. + * In private chats and channel direct messages chats, all non-service messages can be pinned. + * Conversely, the bot must be an administrator with the 'can_pin_messages' right or the 'can_edit_messages' right + * to pin messages in groups and channels respectively. * Returns True on success. - * - * @apiNote If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must - * have the 'can_pin_messages' admin right in a supergroup or 'can_edit_messages' admin right in a channel. */ @EqualsAndHashCode(callSuper = false) @Getter @@ -46,7 +46,9 @@ public class PinChatMessage extends BotApiMethodBoolean { /** * Required. - * Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * Unique identifier for the target chat or username of the target channel (in the format @channelusername). + * In private chats and channel direct messages chats, all non-service messages can be pinned. + * In groups and channels, the bot must be an administrator with appropriate rights. */ @JsonProperty(CHAT_ID_FIELD) @NonNull diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/pinnedmessages/UnpinAllChatMessages.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/pinnedmessages/UnpinAllChatMessages.java index 685f002b3..57c67833a 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/pinnedmessages/UnpinAllChatMessages.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/pinnedmessages/UnpinAllChatMessages.java @@ -20,11 +20,10 @@ * @author Ruben Bermudez * @version 3.1 * Use this method to clear the list of pinned messages in a chat. + * In private chats and channel direct messages chats, no additional rights are required to unpin all pinned messages. + * Conversely, the bot must be an administrator with the 'can_pin_messages' right or the 'can_edit_messages' right + * to unpin all pinned messages in groups and channels respectively. * Returns True on success. - * - * @apiNote If the chat is not a private chat, the bot must be an administrator in the chat for this to - * work and must have the 'can_pin_messages' admin right in a supergroup or 'can_edit_messages' admin - * right in a channel. */ @EqualsAndHashCode(callSuper = false) @Getter @@ -42,7 +41,7 @@ public class UnpinAllChatMessages extends BotApiMethodBoolean { @JsonProperty(CHATID_FIELD) @NonNull - private String chatId; ///< Required. Unique identifier for the target chat or username of the target channel (in the format @channelusername) + private String chatId; ///< Required. Unique identifier for the target chat or username of the target channel (in the format @channelusername). In private chats and channel direct messages chats, no additional rights are required. @Tolerate public void setChatId(@NonNull Long chatId) { diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/pinnedmessages/UnpinChatMessage.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/pinnedmessages/UnpinChatMessage.java index cc014420a..a0be6e0fb 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/pinnedmessages/UnpinChatMessage.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/pinnedmessages/UnpinChatMessage.java @@ -21,11 +21,10 @@ * @author Ruben Bermudez * @version 3.1 * Use this method to remove a message from the list of pinned messages in a chat. + * In private chats and channel direct messages chats, all messages can be unpinned. + * Conversely, the bot must be an administrator with the 'can_pin_messages' right or the 'can_edit_messages' right + * to unpin messages in groups and channels respectively. * Returns True on success. - * - * @apiNote If the chat is not a private chat, the bot must be an administrator in the chat for this to work - * and must have the 'can_pin_messages' admin right in a supergroup or 'can_edit_messages' - * admin right in a channel. */ @EqualsAndHashCode(callSuper = false) @Getter @@ -46,7 +45,9 @@ public class UnpinChatMessage extends BotApiMethodBoolean { /** * Required. - * Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * Unique identifier for the target chat or username of the target channel (in the format @channelusername). + * In private chats and channel direct messages chats, all messages can be unpinned. + * In groups and channels, the bot must be an administrator with appropriate rights. */ @JsonProperty(CHAT_ID_FIELD) @NonNull diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/polls/SendPoll.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/polls/SendPoll.java index d870e9f65..12310d585 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/polls/SendPoll.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/polls/SendPoll.java @@ -29,6 +29,7 @@ * @version 1.0 * Use this method to send a native poll. * A native poll can't be sent to a private chat. + * Polls can't be sent to channel direct messages chats. *

* On success, the sent Message is returned. */ @@ -74,6 +75,7 @@ public class SendPoll extends BotApiMethodMessage { /** * Unique identifier for the target chat or username of the target channel (in the format @channelusername). * A native poll can't be sent to a private chat. + * Polls can't be sent to channel direct messages chats. */ @JsonProperty(CHAT_ID_FIELD) @NonNull 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 df7db32a6..1fdfb425a 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 @@ -18,6 +18,7 @@ import org.telegram.telegrambots.meta.api.objects.ReplyParameters; import org.telegram.telegrambots.meta.api.objects.message.Message; import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard; +import org.telegram.telegrambots.meta.api.objects.suggestedpost.SuggestedPostParameters; import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; import org.telegram.telegrambots.meta.util.Validations; @@ -67,6 +68,12 @@ public class SendAnimation extends SendMediaBotMethod { * for forum supergroups only */ private Integer messageThreadId; + /** + * Optional. + * Identifier of the direct messages topic to which the message will be sent; + * required if the message is sent to a direct messages chat + */ + private Integer directMessagesTopicId; /** * Animation to send. Pass a file_id as String to send an animation that exists on the @@ -174,6 +181,13 @@ public class SendAnimation extends SendMediaBotMethod { */ private Boolean allowPaidBroadcast; + /** + * Optional + * A JSON-serialized object containing the parameters of the suggested post to send; + * for direct messages chats only + */ + private SuggestedPostParameters suggestedPostParameters; + @Tolerate public void setChatId(@NonNull Long chatId) { this.chatId = chatId.toString(); diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendAudio.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendAudio.java index ea07c523d..9fa4d4e55 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendAudio.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendAudio.java @@ -18,6 +18,7 @@ import org.telegram.telegrambots.meta.api.objects.ReplyParameters; import org.telegram.telegrambots.meta.api.objects.message.Message; import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard; +import org.telegram.telegrambots.meta.api.objects.suggestedpost.SuggestedPostParameters; import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; import org.telegram.telegrambots.meta.util.Validations; @@ -63,6 +64,12 @@ public class SendAudio extends SendMediaBotMethod { * for forum supergroups only */ private Integer messageThreadId; + /** + * Optional. + * Identifier of the direct messages topic to which the message will be sent; + * required if the message is sent to a direct messages chat + */ + private Integer directMessagesTopicId; @NonNull private InputFile audio; ///< Audio file to send. file_id as String to resend an audio that is already on the Telegram servers or Url to upload it private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message @@ -114,6 +121,13 @@ public class SendAudio extends SendMediaBotMethod { */ private Boolean allowPaidBroadcast; + /** + * Optional + * A JSON-serialized object containing the parameters of the suggested post to send; + * for direct messages chats only + */ + private SuggestedPostParameters suggestedPostParameters; + @Tolerate public void setChatId(@NonNull Long chatId) { this.chatId = chatId.toString(); diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendChatAction.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendChatAction.java index 283b2788d..1af6a6f5c 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendChatAction.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendChatAction.java @@ -24,6 +24,7 @@ * Use this method when you need to tell the user that something is happening on the bot's * side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram * clients clear its typing status). + * Channel chats and channel direct messages chats aren't supported. */ @EqualsAndHashCode(callSuper = false) @Getter @@ -45,7 +46,7 @@ public class SendChatAction extends BotApiMethodBoolean { @JsonProperty(CHAT_ID_FIELD) @NonNull - private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels) + private String chatId; ///< Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername). Channel chats and channel direct messages chats aren't supported. /** * Type of action to broadcast. Choose one, depending on what the user is about to receive: * typing for text messages diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendContact.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendContact.java index 16a126a48..1618dee8c 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendContact.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendContact.java @@ -16,6 +16,7 @@ import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodMessage; import org.telegram.telegrambots.meta.api.objects.ReplyParameters; import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard; +import org.telegram.telegrambots.meta.api.objects.suggestedpost.SuggestedPostParameters; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; import org.telegram.telegrambots.meta.util.Validations; @@ -40,6 +41,7 @@ public class SendContact extends BotApiMethodMessage { private static final String CHAT_ID_FIELD = "chat_id"; private static final String MESSAGE_THREAD_ID_FIELD = "message_thread_id"; + private static final String DIRECT_MESSAGES_TOPIC_ID_FIELD = "direct_messages_topic_id"; private static final String PHONE_NUMBER_FIELD = "phone_number"; private static final String FIRST_NAME_FIELD = "first_name"; private static final String LAST_NAME_FIELD = "last_name"; @@ -53,6 +55,7 @@ public class SendContact extends BotApiMethodMessage { private static final String BUSINESS_CONNECTION_ID_FIELD = "business_connection_id"; private static final String MESSAGE_EFFECT_ID_FIELD = "message_effect_id"; private static final String ALLOW_PAID_BROADCAST_FIELD = "allow_paid_broadcast"; + private static final String SUGGESTED_POST_PARAMETERS_FIELD = "suggested_post_parameters"; @JsonProperty(CHAT_ID_FIELD) @NonNull @@ -63,6 +66,13 @@ public class SendContact extends BotApiMethodMessage { */ @JsonProperty(MESSAGE_THREAD_ID_FIELD) private Integer messageThreadId; + /** + * Optional. + * Identifier of the direct messages topic to which the message will be sent; + * required if the message is sent to a direct messages chat + */ + @JsonProperty(DIRECT_MESSAGES_TOPIC_ID_FIELD) + private Integer directMessagesTopicId; @JsonProperty(PHONE_NUMBER_FIELD) @NonNull private String phoneNumber; ///< User's phone number @@ -115,6 +125,14 @@ public class SendContact extends BotApiMethodMessage { @JsonProperty(ALLOW_PAID_BROADCAST_FIELD) private Boolean allowPaidBroadcast; + /** + * Optional + * A JSON-serialized object containing the parameters of the suggested post to send; + * for direct messages chats only + */ + @JsonProperty(SUGGESTED_POST_PARAMETERS_FIELD) + private SuggestedPostParameters suggestedPostParameters; + @Tolerate public void setChatId(@NonNull Long chatId) { this.chatId = chatId.toString(); diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendDice.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendDice.java index 59ec60610..f4048745d 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendDice.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendDice.java @@ -16,6 +16,7 @@ import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodMessage; import org.telegram.telegrambots.meta.api.objects.ReplyParameters; import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard; +import org.telegram.telegrambots.meta.api.objects.suggestedpost.SuggestedPostParameters; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; import org.telegram.telegrambots.meta.util.Validations; @@ -45,6 +46,7 @@ public class SendDice extends BotApiMethodMessage { private static final String CHAT_ID_FIELD = "chat_id"; private static final String MESSAGE_THREAD_ID_FIELD = "message_thread_id"; + private static final String DIRECT_MESSAGES_TOPIC_ID_FIELD = "direct_messages_topic_id"; private static final String EMOJI_FIELD = "emoji"; private static final String DISABLE_NOTIFICATION_FIELD = "disable_notification"; private static final String REPLY_TO_MESSAGE_ID_FIELD = "reply_to_message_id"; @@ -55,6 +57,7 @@ public class SendDice extends BotApiMethodMessage { private static final String BUSINESS_CONNECTION_ID_FIELD = "business_connection_id"; private static final String MESSAGE_EFFECT_ID_FIELD = "message_effect_id"; private static final String ALLOW_PAID_BROADCAST_FIELD = "allow_paid_broadcast"; + private static final String SUGGESTED_POST_PARAMETERS_FIELD = "suggested_post_parameters"; /** * Unique identifier for the target chat or username of the target channel (in the format @channelusername) @@ -68,6 +71,13 @@ public class SendDice extends BotApiMethodMessage { */ @JsonProperty(MESSAGE_THREAD_ID_FIELD) private Integer messageThreadId; + /** + * Optional. + * Identifier of the direct messages topic to which the message will be sent; + * required if the message is sent to a direct messages chat + */ + @JsonProperty(DIRECT_MESSAGES_TOPIC_ID_FIELD) + private Integer directMessagesTopicId; /** * Optional. * Emoji on which the dice throw animation is based. @@ -119,6 +129,14 @@ public class SendDice extends BotApiMethodMessage { @JsonProperty(ALLOW_PAID_BROADCAST_FIELD) private Boolean allowPaidBroadcast; + /** + * Optional + * A JSON-serialized object containing the parameters of the suggested post to send; + * for direct messages chats only + */ + @JsonProperty(SUGGESTED_POST_PARAMETERS_FIELD) + private SuggestedPostParameters suggestedPostParameters; + @Tolerate public void setChatId(@NonNull Long chatId) { this.chatId = chatId.toString(); diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendDocument.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendDocument.java index bab4cad5d..333867bff 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendDocument.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendDocument.java @@ -18,6 +18,7 @@ import org.telegram.telegrambots.meta.api.objects.ReplyParameters; import org.telegram.telegrambots.meta.api.objects.message.Message; import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard; +import org.telegram.telegrambots.meta.api.objects.suggestedpost.SuggestedPostParameters; import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; import org.telegram.telegrambots.meta.util.Validations; @@ -57,6 +58,12 @@ public class SendDocument extends SendMediaBotMethod { * for forum supergroups only */ private Integer messageThreadId; + /** + * Optional. + * Identifier of the direct messages topic to which the message will be sent; + * required if the message is sent to a direct messages chat + */ + private Integer directMessagesTopicId; @NonNull private InputFile document; ///< File file to send. file_id as String to resend a file that is already on the Telegram servers or Url to upload it private String caption; ///< Optional. Document caption (may also be used when resending documents by file_id), 0-200 characters @@ -106,6 +113,13 @@ public class SendDocument extends SendMediaBotMethod { */ private Boolean allowPaidBroadcast; + /** + * Optional + * A JSON-serialized object containing the parameters of the suggested post to send; + * for direct messages chats only + */ + private SuggestedPostParameters suggestedPostParameters; + @Tolerate public void setChatId(@NonNull Long chatId) { this.chatId = chatId.toString(); diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendGame.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendGame.java index d7f67b437..551075066 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendGame.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendGame.java @@ -40,6 +40,7 @@ * @author Ruben Bermudez * @version 1.0 * Use this method to send a game. On success, the sent Message is returned. + * Games can't be sent to channel direct messages chats and channel chats. */ @EqualsAndHashCode(callSuper = false) @Getter @@ -56,6 +57,7 @@ public class SendGame extends BotApiMethodMessage { private static final String CHAT_ID_FIELD = "chat_id"; private static final String MESSAGE_THREAD_ID_FIELD = "message_thread_id"; + private static final String DIRECT_MESSAGES_TOPIC_ID_FIELD = "direct_messages_topic_id"; private static final String GAME_SHORT_NAME_FIELD = "game_short_name"; private static final String DISABLE_NOTIFICATION_FIELD = "disable_notification"; private static final String REPLY_TO_MESSAGE_ID_FIELD = "reply_to_message_id"; @@ -69,13 +71,20 @@ public class SendGame extends BotApiMethodMessage { @JsonProperty(CHAT_ID_FIELD) @NonNull - private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels) + private String chatId; ///< Unique identifier for the target chat. Games can't be sent to channel direct messages chats and channel chats. /** * Unique identifier for the target message thread (topic) of the forum; * for forum supergroups only */ @JsonProperty(MESSAGE_THREAD_ID_FIELD) private Integer messageThreadId; + /** + * Optional. + * Identifier of the direct messages topic to which the message will be sent; + * required if the message is sent to a direct messages chat + */ + @JsonProperty(DIRECT_MESSAGES_TOPIC_ID_FIELD) + private Integer directMessagesTopicId; @JsonProperty(GAME_SHORT_NAME_FIELD) @NonNull private String gameShortName; ///< Short name of the game diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendLocation.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendLocation.java index 002bc9520..bdeccbbae 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendLocation.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendLocation.java @@ -16,6 +16,7 @@ import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodMessage; import org.telegram.telegrambots.meta.api.objects.ReplyParameters; import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard; +import org.telegram.telegrambots.meta.api.objects.suggestedpost.SuggestedPostParameters; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; import org.telegram.telegrambots.meta.util.Validations; @@ -39,6 +40,7 @@ public class SendLocation extends BotApiMethodMessage { private static final String CHATID_FIELD = "chat_id"; private static final String MESSAGETHREADID_FIELD = "message_thread_id"; + private static final String DIRECT_MESSAGES_TOPIC_ID_FIELD = "direct_messages_topic_id"; private static final String LATITUDE_FIELD = "latitude"; private static final String LONGITUDE_FIELD = "longitude"; @@ -54,6 +56,7 @@ public class SendLocation extends BotApiMethodMessage { private static final String REPLY_PARAMETERS_FIELD = "reply_parameters"; private static final String BUSINESS_CONNECTION_ID_FIELD = "business_connection_id"; private static final String ALLOW_PAID_BROADCAST_FIELD = "allow_paid_broadcast"; + private static final String SUGGESTED_POST_PARAMETERS_FIELD = "suggested_post_parameters"; @JsonProperty(CHATID_FIELD) @NonNull @@ -64,6 +67,13 @@ public class SendLocation extends BotApiMethodMessage { */ @JsonProperty(MESSAGETHREADID_FIELD) private Integer messageThreadId; + /** + * Optional. + * Identifier of the direct messages topic to which the message will be sent; + * required if the message is sent to a direct messages chat + */ + @JsonProperty(DIRECT_MESSAGES_TOPIC_ID_FIELD) + private Integer directMessagesTopicId; @JsonProperty(LATITUDE_FIELD) @NonNull private Double latitude; ///< Latitude of location @@ -138,6 +148,14 @@ public class SendLocation extends BotApiMethodMessage { @JsonProperty(ALLOW_PAID_BROADCAST_FIELD) private Boolean allowPaidBroadcast; + /** + * Optional + * A JSON-serialized object containing the parameters of the suggested post to send; + * for direct messages chats only + */ + @JsonProperty(SUGGESTED_POST_PARAMETERS_FIELD) + private SuggestedPostParameters suggestedPostParameters; + @Tolerate public void setChatId(@NonNull Long chatId) { this.chatId = chatId.toString(); diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendMediaBotMethod.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendMediaBotMethod.java index ed39190b6..03d3e47c8 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendMediaBotMethod.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendMediaBotMethod.java @@ -7,6 +7,7 @@ import org.telegram.telegrambots.meta.api.objects.InputFile; import org.telegram.telegrambots.meta.api.objects.ReplyParameters; import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard; +import org.telegram.telegrambots.meta.api.objects.suggestedpost.SuggestedPostParameters; import java.io.Serializable; @@ -15,6 +16,7 @@ public abstract class SendMediaBotMethod extends PartialBotApiMethod { public static final String CHAT_ID_FIELD = "chat_id"; public static final String MESSAGE_THREAD_ID_FIELD = "message_thread_id"; + public static final String DIRECT_MESSAGES_TOPIC_ID_FIELD = "direct_messages_topic_id"; public static final String REPLY_TO_MESSAGE_ID_FIELD = "reply_to_message_id"; public static final String DISABLE_NOTIFICATION_FIELD = "disable_notification"; public static final String PROTECT_CONTENT_FIELD = "protect_content"; @@ -23,11 +25,14 @@ public abstract class SendMediaBotMethod extends Partial public static final String REPLY_MARKUP_FIELD = "reply_markup"; public static final String MESSAGE_EFFECT_ID_FIELD = "message_effect_id"; public static final String ALLOW_PAID_BROADCAST_FIELD = "allow_paid_broadcast"; + public static final String SUGGESTED_POST_PARAMETERS_FIELD = "suggested_post_parameters"; public abstract String getChatId(); public abstract Integer getMessageThreadId(); + public abstract Integer getDirectMessagesTopicId(); + public abstract Integer getReplyToMessageId(); public abstract Boolean getDisableNotification(); @@ -48,6 +53,8 @@ public abstract class SendMediaBotMethod extends Partial public abstract Boolean getAllowPaidBroadcast(); + public abstract SuggestedPostParameters getSuggestedPostParameters(); + public static abstract class SendMediaBotMethodBuilder, B extends SendMediaBotMethodBuilder> extends PartialBotApiMethodBuilder { } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendMediaGroup.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendMediaGroup.java index 66c10d595..84614b58f 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendMediaGroup.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendMediaGroup.java @@ -52,6 +52,7 @@ public class SendMediaGroup extends PartialBotApiMethod> { public static final String CHAT_ID_FIELD = "chat_id"; public static final String MESSAGE_THREAD_ID_FIELD = "message_thread_id"; + public static final String DIRECT_MESSAGES_TOPIC_ID_FIELD = "direct_messages_topic_id"; public static final String MEDIA_FIELD = "media"; public static final String REPLY_TO_MESSAGE_ID_FIELD = "reply_to_message_id"; public static final String DISABLE_NOTIFICATION_FIELD = "disable_notification"; @@ -73,6 +74,12 @@ public class SendMediaGroup extends PartialBotApiMethod> { * for forum supergroups only */ private Integer messageThreadId; + /** + * Optional. + * Identifier of the direct messages topic to which the messages will be sent; + * required if the messages are sent to a direct messages chat + */ + private Integer directMessagesTopicId; /** * A JSON-serialized array describing photos and videos to be sent, must include 2–10 items */ diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendMessage.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendMessage.java index 6eb383de7..6b6c09fc5 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendMessage.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendMessage.java @@ -19,6 +19,7 @@ import org.telegram.telegrambots.meta.api.objects.MessageEntity; import org.telegram.telegrambots.meta.api.objects.ReplyParameters; import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard; +import org.telegram.telegrambots.meta.api.objects.suggestedpost.SuggestedPostParameters; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; import org.telegram.telegrambots.meta.util.Validations; @@ -45,6 +46,7 @@ public class SendMessage extends BotApiMethodMessage { private static final String CHAT_ID_FIELD = "chat_id"; private static final String MESSAGE_THREAD_ID_FIELD = "message_thread_id"; + private static final String DIRECT_MESSAGES_TOPIC_ID_FIELD = "direct_messages_topic_id"; private static final String TEXT_FIELD = "text"; private static final String PARSE_MODE_FIELD = "parse_mode"; private static final String DISABLE_WEB_PAGE_PREVIEW_FIELD = "disable_web_page_preview"; @@ -59,6 +61,7 @@ public class SendMessage extends BotApiMethodMessage { private static final String BUSINESS_CONNECTION_ID_FIELD = "business_connection_id"; private static final String MESSAGE_EFFECT_ID_FIELD = "message_effect_id"; private static final String ALLOW_PAID_BROADCAST_FIELD = "allow_paid_broadcast"; + private static final String SUGGESTED_POST_PARAMETERS_FIELD = "suggested_post_parameters"; @JsonProperty(CHAT_ID_FIELD) @NonNull @@ -69,6 +72,13 @@ public class SendMessage extends BotApiMethodMessage { */ @JsonProperty(MESSAGE_THREAD_ID_FIELD) private Integer messageThreadId; + /** + * Optional. + * Identifier of the direct messages topic to which the message will be sent; + * required if the message is sent to a direct messages chat + */ + @JsonProperty(DIRECT_MESSAGES_TOPIC_ID_FIELD) + private Integer directMessagesTopicId; @JsonProperty(TEXT_FIELD) @NonNull private String text; ///< Text of the message to be sent @@ -126,6 +136,14 @@ public class SendMessage extends BotApiMethodMessage { @JsonProperty(ALLOW_PAID_BROADCAST_FIELD) private Boolean allowPaidBroadcast; + /** + * Optional + * A JSON-serialized object containing the parameters of the suggested post to send; + * for direct messages chats only + */ + @JsonProperty(SUGGESTED_POST_PARAMETERS_FIELD) + private SuggestedPostParameters suggestedPostParameters; + @Tolerate public void setChatId(@NonNull Long chatId) { this.chatId = chatId.toString(); diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendPaidMedia.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendPaidMedia.java index 5af840fcb..24e721828 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendPaidMedia.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendPaidMedia.java @@ -18,6 +18,7 @@ import org.telegram.telegrambots.meta.api.objects.media.paid.InputPaidMedia; import org.telegram.telegrambots.meta.api.objects.message.Message; import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard; +import org.telegram.telegrambots.meta.api.objects.suggestedpost.SuggestedPostParameters; import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; import org.telegram.telegrambots.meta.util.Validations; @@ -59,6 +60,8 @@ public class SendPaidMedia extends PartialBotApiMethod> { public static final String BUSINESS_CONNECTION_ID_FIELD = "business_connection_id"; public static final String PAYLOAD_FIELD = "payload"; public static final String ALLOW_PAID_BROADCAST_FIELD = "allow_paid_broadcast"; + public static final String DIRECT_MESSAGES_TOPIC_ID_FIELD = "direct_messages_topic_id"; + public static final String SUGGESTED_POST_PARAMETERS_FIELD = "suggested_post_parameters"; /** * Unique identifier for the target chat or username of the target channel (in the format @channelusername). @@ -67,6 +70,12 @@ public class SendPaidMedia extends PartialBotApiMethod> { */ @NonNull private String chatId; + /** + * Optional. + * Identifier of the direct messages topic to which the message will be sent; + * required if the message is sent to a direct messages chat + */ + private Integer directMessagesTopicId; /** * The number of Telegram Stars that must be paid to buy access to the media */ @@ -137,6 +146,13 @@ public class SendPaidMedia extends PartialBotApiMethod> { */ private Boolean allowPaidBroadcast; + /** + * Optional + * A JSON-serialized object containing the parameters of the suggested post to send; + * for direct messages chats only + */ + private SuggestedPostParameters suggestedPostParameters; + @Tolerate public void setChatId(@NonNull Long chatId) { this.chatId = chatId.toString(); diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendPhoto.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendPhoto.java index 924119630..ecc7ea5f3 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendPhoto.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendPhoto.java @@ -18,6 +18,7 @@ import org.telegram.telegrambots.meta.api.objects.ReplyParameters; import org.telegram.telegrambots.meta.api.objects.message.Message; import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard; +import org.telegram.telegrambots.meta.api.objects.suggestedpost.SuggestedPostParameters; import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; import org.telegram.telegrambots.meta.util.Validations; @@ -61,6 +62,12 @@ public class SendPhoto extends SendMediaBotMethod { * for forum supergroups only */ private Integer messageThreadId; + /** + * Optional. + * Identifier of the direct messages topic to which the message will be sent; + * required if the message is sent to a direct messages chat + */ + private Integer directMessagesTopicId; /** * Photo to send. file_id as String to resend a photo that is already on the Telegram servers or URL to upload it */ @@ -141,6 +148,13 @@ public class SendPhoto extends SendMediaBotMethod { */ private Boolean allowPaidBroadcast; + /** + * Optional + * A JSON-serialized object containing the parameters of the suggested post to send; + * for direct messages chats only + */ + private SuggestedPostParameters suggestedPostParameters; + @Tolerate public void setChatId(@NonNull Long chatId) { this.chatId = chatId.toString(); diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendSticker.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendSticker.java index f321cf8f6..6e72e603d 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendSticker.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendSticker.java @@ -16,6 +16,7 @@ import org.telegram.telegrambots.meta.api.objects.ReplyParameters; import org.telegram.telegrambots.meta.api.objects.message.Message; import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard; +import org.telegram.telegrambots.meta.api.objects.suggestedpost.SuggestedPostParameters; import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; import org.telegram.telegrambots.meta.util.Validations; @@ -53,6 +54,12 @@ public class SendSticker extends SendMediaBotMethod { * for forum supergroups only */ private Integer messageThreadId; + /** + * Optional. + * Identifier of the direct messages topic to which the message will be sent; + * required if the message is sent to a direct messages chat + */ + private Integer directMessagesTopicId; /** * Sticker to send. * Pass a file_id as String to send a file that exists on the Telegram servers (recommended), @@ -116,6 +123,13 @@ public class SendSticker extends SendMediaBotMethod { */ private Boolean allowPaidBroadcast; + /** + * Optional + * A JSON-serialized object containing the parameters of the suggested post to send; + * for direct messages chats only + */ + private SuggestedPostParameters suggestedPostParameters; + @Tolerate public void setChatId(@NonNull Long chatId) { this.chatId = chatId.toString(); diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendVenue.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendVenue.java index 56df4a9a7..50addf33d 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendVenue.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendVenue.java @@ -16,6 +16,7 @@ import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodMessage; import org.telegram.telegrambots.meta.api.objects.ReplyParameters; import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard; +import org.telegram.telegrambots.meta.api.objects.suggestedpost.SuggestedPostParameters; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; import org.telegram.telegrambots.meta.util.Validations; @@ -40,6 +41,7 @@ public class SendVenue extends BotApiMethodMessage { private static final String CHAT_ID_FIELD = "chat_id"; private static final String MESSAGE_THREAD_ID_FIELD = "message_thread_id"; + private static final String DIRECT_MESSAGES_TOPIC_ID_FIELD = "direct_messages_topic_id"; private static final String LATITUDE_FIELD = "latitude"; private static final String LONGITUDE_FIELD = "longitude"; private static final String TITLE_FIELD = "title"; @@ -57,6 +59,7 @@ public class SendVenue extends BotApiMethodMessage { private static final String BUSINESS_CONNECTION_ID_FIELD = "business_connection_id"; private static final String MESSAGE_EFFECT_ID_FIELD = "message_effect_id"; private static final String ALLOW_PAID_BROADCAST_FIELD = "allow_paid_broadcast"; + private static final String SUGGESTED_POST_PARAMETERS_FIELD = "suggested_post_parameters"; @JsonProperty(CHAT_ID_FIELD) @NonNull @@ -67,6 +70,13 @@ public class SendVenue extends BotApiMethodMessage { */ @JsonProperty(MESSAGE_THREAD_ID_FIELD) private Integer messageThreadId; + /** + * Optional. + * Identifier of the direct messages topic to which the message will be sent; + * required if the message is sent to a direct messages chat + */ + @JsonProperty(DIRECT_MESSAGES_TOPIC_ID_FIELD) + private Integer directMessagesTopicId; @JsonProperty(LATITUDE_FIELD) @NonNull private Double latitude; ///< Latitude of venue location @@ -129,6 +139,14 @@ public class SendVenue extends BotApiMethodMessage { @JsonProperty(ALLOW_PAID_BROADCAST_FIELD) private Boolean allowPaidBroadcast; + /** + * Optional + * A JSON-serialized object containing the parameters of the suggested post to send; + * for direct messages chats only + */ + @JsonProperty(SUGGESTED_POST_PARAMETERS_FIELD) + private SuggestedPostParameters suggestedPostParameters; + @Tolerate public void setChatId(@NonNull Long chatId) { this.chatId = chatId.toString(); diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendVideo.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendVideo.java index dd50e728e..2ea1e02e3 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendVideo.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendVideo.java @@ -18,6 +18,7 @@ import org.telegram.telegrambots.meta.api.objects.ReplyParameters; import org.telegram.telegrambots.meta.api.objects.message.Message; import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard; +import org.telegram.telegrambots.meta.api.objects.suggestedpost.SuggestedPostParameters; import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; import org.telegram.telegrambots.meta.util.Validations; @@ -65,6 +66,12 @@ public class SendVideo extends SendMediaBotMethod { * for forum supergroups only */ private Integer messageThreadId; + /** + * Optional. + * Identifier of the direct messages topic to which the message will be sent; + * required if the message is sent to a direct messages chat + */ + private Integer directMessagesTopicId; @NonNull private InputFile video; ///< Video to send. file_id as String to resend a video that is already on the Telegram servers or URL to upload it private Integer duration; ///< Optional. Duration of sent video in seconds @@ -140,6 +147,13 @@ public class SendVideo extends SendMediaBotMethod { */ private Integer startTimestamp; + /** + * Optional + * A JSON-serialized object containing the parameters of the suggested post to send; + * for direct messages chats only + */ + private SuggestedPostParameters suggestedPostParameters; + @Tolerate public void setChatId(@NonNull Long chatId) { this.chatId = chatId.toString(); diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendVideoNote.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendVideoNote.java index bd0e74859..09d307cdc 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendVideoNote.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendVideoNote.java @@ -16,6 +16,7 @@ import org.telegram.telegrambots.meta.api.objects.ReplyParameters; import org.telegram.telegrambots.meta.api.objects.message.Message; import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard; +import org.telegram.telegrambots.meta.api.objects.suggestedpost.SuggestedPostParameters; import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; import org.telegram.telegrambots.meta.util.Validations; @@ -53,6 +54,12 @@ public class SendVideoNote extends SendMediaBotMethod { * for forum supergroups only */ private Integer messageThreadId; + /** + * Optional. + * Identifier of the direct messages topic to which the message will be sent; + * required if the message is sent to a direct messages chat + */ + private Integer directMessagesTopicId; @NonNull private InputFile videoNote; ///< Videonote to send. file_id as String to resend a video that is already on the Telegram servers. private Integer duration; ///< Optional. Duration of sent video in seconds @@ -98,6 +105,13 @@ public class SendVideoNote extends SendMediaBotMethod { */ private Boolean allowPaidBroadcast; + /** + * Optional + * A JSON-serialized object containing the parameters of the suggested post to send; + * for direct messages chats only + */ + private SuggestedPostParameters suggestedPostParameters; + @Tolerate public void setChatId(@NonNull Long chatId) { this.chatId = chatId.toString(); diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendVoice.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendVoice.java index efc5bbd1e..2e3d29365 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendVoice.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendVoice.java @@ -18,6 +18,7 @@ import org.telegram.telegrambots.meta.api.objects.ReplyParameters; import org.telegram.telegrambots.meta.api.objects.message.Message; import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard; +import org.telegram.telegrambots.meta.api.objects.suggestedpost.SuggestedPostParameters; import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; import org.telegram.telegrambots.meta.util.Validations; @@ -64,6 +65,12 @@ public class SendVoice extends SendMediaBotMethod { * for forum supergroups only */ private Integer messageThreadId; + /** + * Optional. + * Identifier of the direct messages topic to which the message will be sent; + * required if the message is sent to a direct messages chat + */ + private Integer directMessagesTopicId; /** * Audio file to send. You can either pass a file_id as String to resend an audio that is already on the Telegram servers, * or upload a new audio file using multipart/form-data. @@ -145,6 +152,13 @@ public class SendVoice extends SendMediaBotMethod { */ private Boolean allowPaidBroadcast; + /** + * Optional + * A JSON-serialized object containing the parameters of the suggested post to send; + * for direct messages chats only + */ + private SuggestedPostParameters suggestedPostParameters; + @Tolerate public void setChatId(@NonNull Long chatId) { this.chatId = chatId.toString(); diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/suggestedPost/ApproveSuggestedPost.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/suggestedPost/ApproveSuggestedPost.java new file mode 100644 index 000000000..4d3ac005d --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/suggestedPost/ApproveSuggestedPost.java @@ -0,0 +1,95 @@ +package org.telegram.telegrambots.meta.api.methods.suggestedpost; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; +import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethod; +import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * @author Ruben Bermudez + * @version 7.5 + * + * Use this method to approve a suggested post in a direct messages chat. + * The bot must have the 'can_post_messages' administrator right in the corresponding channel chat. + * Returns True on success. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@RequiredArgsConstructor +@AllArgsConstructor +@SuperBuilder +@Jacksonized +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ApproveSuggestedPost extends BotApiMethod { + public static final String PATH = "approveSuggestedPost"; + + private static final String CHAT_ID_FIELD = "chat_id"; + private static final String MESSAGE_ID_FIELD = "message_id"; + private static final String SEND_DATE_FIELD = "send_date"; + + /** + * Unique identifier for the target direct messages chat + */ + @JsonProperty(CHAT_ID_FIELD) + @NonNull + private Integer chatId; + + /** + * Identifier of a suggested post message to approve + */ + @JsonProperty(MESSAGE_ID_FIELD) + @NonNull + private Integer messageId; + + /** + * Optional + * Point in time (Unix timestamp) when the post is expected to be published; + * omit if the date has already been specified when the suggested post was created. + * If specified, then the date must be not more than 2678400 seconds (30 days) in the future + */ + @JsonProperty(SEND_DATE_FIELD) + private Integer sendDate; + + @Override + public Boolean deserializeResponse(String answer) throws TelegramApiRequestException { + return deserializeResponse(answer, Boolean.class); + } + + @Override + public String getMethod() { + return PATH; + } + + @Override + public void validate() throws TelegramApiValidationException { + if (chatId == null) { + throw new TelegramApiValidationException("ChatId parameter can't be empty", this); + } + if (messageId == null) { + throw new TelegramApiValidationException("MessageId parameter can't be empty", this); + } + if (sendDate != null) { + long currentTime = System.currentTimeMillis() / 1000; + if (sendDate > currentTime + 2678400) { + throw new TelegramApiValidationException("SendDate can't be more than 30 days in the future", this); + } + } + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/suggestedPost/DeclineSuggestedPost.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/suggestedPost/DeclineSuggestedPost.java new file mode 100644 index 000000000..849c2f78d --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/suggestedPost/DeclineSuggestedPost.java @@ -0,0 +1,90 @@ +package org.telegram.telegrambots.meta.api.methods.suggestedpost; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; +import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethod; +import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * @author Ruben Bermudez + * @version 7.5 + * + * Use this method to decline a suggested post in a direct messages chat. + * The bot must have the 'can_manage_direct_messages' administrator right in the corresponding channel chat. + * Returns True on success. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@RequiredArgsConstructor +@AllArgsConstructor +@SuperBuilder +@Jacksonized +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class DeclineSuggestedPost extends BotApiMethod { + public static final String PATH = "declineSuggestedPost"; + + private static final String CHAT_ID_FIELD = "chat_id"; + private static final String MESSAGE_ID_FIELD = "message_id"; + private static final String COMMENT_FIELD = "comment"; + + /** + * Unique identifier for the target direct messages chat + */ + @JsonProperty(CHAT_ID_FIELD) + @NonNull + private Integer chatId; + + /** + * Identifier of a suggested post message to decline + */ + @JsonProperty(MESSAGE_ID_FIELD) + @NonNull + private Integer messageId; + + /** + * Optional + * Comment for the creator of the suggested post; 0-128 characters + */ + @JsonProperty(COMMENT_FIELD) + private String comment; + + @Override + public Boolean deserializeResponse(String answer) throws TelegramApiRequestException { + return deserializeResponse(answer, Boolean.class); + } + + @Override + public String getMethod() { + return PATH; + } + + @Override + public void validate() throws TelegramApiValidationException { + if (chatId == null) { + throw new TelegramApiValidationException("ChatId parameter can't be empty", this); + } + if (messageId == null) { + throw new TelegramApiValidationException("MessageId parameter can't be empty", this); + } + if (comment != null && comment.length() > 128) { + throw new TelegramApiValidationException("Comment cannot be longer than 128 characters", this); + } + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/DeleteMessage.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/DeleteMessage.java index aafdcf793..57c38872f 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/DeleteMessage.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/DeleteMessage.java @@ -22,12 +22,14 @@ * * Use this method to delete a message, including service messages, with the following limitations: * - A message can only be deleted if it was sent less than 48 hours ago. + * - Service messages about a supergroup, channel, or forum topic creation can't be deleted. + * - A dice message in a private chat can only be deleted if it was sent more than 24 hours ago. * - Bots can delete outgoing messages in private chats, groups, and supergroups. * - Bots can delete incoming messages in private chats. * - Bots granted can_post_messages permissions can delete outgoing messages in channels. * - If the bot is an administrator of a group, it can delete any message there. - * - If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there. - * - Service messages about a supergroup, channel, or forum topic creation can't be deleted + * - If the bot has can_delete_messages administrator right in a supergroup or a channel, it can delete any message there. + * - If the bot has can_manage_direct_messages administrator right in a channel, it can delete any message in the corresponding direct messages chat. * Returns True on success. */ @EqualsAndHashCode(callSuper = false) @@ -46,7 +48,7 @@ public class DeleteMessage extends BotApiMethodBoolean { private static final String MESSAGEID_FIELD = "message_id"; /** - * Unique identifier for the chat to send the message to (Or username for channels) + * Unique identifier for the target chat or username of the target channel (in the format @channelusername) */ @JsonProperty(CHATID_FIELD) @NonNull diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/verification/VerifyChat.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/verification/VerifyChat.java index 1dcc41abe..93f94d79f 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/verification/VerifyChat.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/verification/VerifyChat.java @@ -41,7 +41,8 @@ public class VerifyChat extends BotApiMethodBoolean { private static final String CUSTOM_DESCRIPTION_FIELD = "custom_description"; /** - * Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * Unique identifier for the target chat or username of the target channel (in the format @channelusername). + * Channel direct messages chats can't be verified. */ @JsonProperty(CHAT_ID_FIELD) @NonNull diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ReplyParameters.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ReplyParameters.java index 0aa45b561..3eb5eaff9 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ReplyParameters.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ReplyParameters.java @@ -39,6 +39,7 @@ public class ReplyParameters implements BotApiObject, Validable { private static final String QUOTE_FIELD = "quote"; private static final String QUOTE_ENTITIES_FIELD = "quote_entities"; private static final String QUOTE_POSITION_FIELD = "quote_position"; + private static final String CHECKLIST_TASK_ID_FIELD = "checklist_task_id"; /** * Identifier of the message that will be replied to in the current chat, or in the chat chat_id if it is specified @@ -49,11 +50,18 @@ public class ReplyParameters implements BotApiObject, Validable { /** * Optional. * If the message to be replied to is from a different chat, unique identifier for the chat or username of the channel (in the format @channelusername) - * @apiNote Not supported for messages sent on behalf of a business account. + * @apiNote Not supported for messages sent on behalf of a business account and messages from channel direct messages chats. */ @JsonProperty(CHAT_ID_FIELD) private String chatId; + /** + * Optional. + * Identifier of the specific checklist task to be replied to + */ + @JsonProperty(CHECKLIST_TASK_ID_FIELD) + private Integer checklistTaskId; + /** * Optional. * Pass True if the message should be sent even if the specified message to be replied to is not found; can be used only for replies in the same chat and forum topic. diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/adminrights/ChatAdministratorRights.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/adminrights/ChatAdministratorRights.java index 0693cfd2b..fb0d16460 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/adminrights/ChatAdministratorRights.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/adminrights/ChatAdministratorRights.java @@ -45,6 +45,7 @@ public class ChatAdministratorRights implements BotApiObject, Validable { private static final String CAN_POST_STORIES_FIELD = "can_post_stories"; private static final String CAN_EDIT_STORIES_FIELD = "can_edit_stories"; private static final String CAN_DELETE_STORIES_FIELD = "can_delete_stories"; + private static final String CAN_MANAGE_DIRECT_MESSAGES_FIELD = "can_manage_direct_messages"; /** * True, if the user's presence in the chat is hidden @@ -142,4 +143,11 @@ public class ChatAdministratorRights implements BotApiObject, Validable { */ @JsonProperty(CAN_DELETE_STORIES_FIELD) private Boolean canDeleteStories; + + /** + * Optional. + * True, if the administrator can manage direct messages of the channel and decline suggested posts; for channels only + */ + @JsonProperty(CAN_MANAGE_DIRECT_MESSAGES_FIELD) + private Boolean canManageDirectMessages; } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chat/ChatFullInfo.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chat/ChatFullInfo.java index 27fefecd2..c633d2a57 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chat/ChatFullInfo.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chat/ChatFullInfo.java @@ -77,6 +77,8 @@ public class ChatFullInfo extends Chat { private static final String PERSONAL_CHAT_FIELD = "personal_chat"; private static final String CAN_SEND_PAID_MEDIA_FIELD = "can_send_paid_media"; private static final String ACCEPTED_GIFT_TYPES_FIELD = "accepted_gift_types"; + private static final String IS_DIRECT_MESSAGES_FIELD = "is_direct_messages"; + private static final String PARENT_CHAT_FIELD = "parent_chat"; /** * Optional. @@ -336,4 +338,18 @@ public class ChatFullInfo extends Chat { */ @JsonProperty(ACCEPTED_GIFT_TYPES_FIELD) private AcceptedGiftTypes acceptedGiftTypes; + + /** + * Optional. + * True, if the chat is the direct messages chat of a channel + */ + @JsonProperty(IS_DIRECT_MESSAGES_FIELD) + private Boolean isDirectMessages; + + /** + * Optional. + * Information about the corresponding channel chat; for direct messages chats only + */ + @JsonProperty(PARENT_CHAT_FIELD) + private Chat parentChat; } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMemberAdministrator.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMemberAdministrator.java index 634282cbe..2d5856f26 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMemberAdministrator.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMemberAdministrator.java @@ -49,6 +49,7 @@ public class ChatMemberAdministrator implements ChatMember { private static final String CAN_POST_STORIES_FIELD = "can_post_stories"; private static final String CAN_EDIT_STORIES_FIELD = "can_edit_stories"; private static final String CAN_DELETE_STORIES_FIELD = "can_delete_stories"; + private static final String CAN_MANAGE_DIRECT_MESSAGES_FIELD = "can_manage_direct_messages"; /** * The member's status in the chat, always “administrator” @@ -155,4 +156,11 @@ public class ChatMemberAdministrator implements ChatMember { */ @JsonProperty(CAN_DELETE_STORIES_FIELD) private Boolean canDeleteStories; + + /** + * Optional. + * True, if the administrator can manage direct messages of the channel and decline suggested posts; for channels only + */ + @JsonProperty(CAN_MANAGE_DIRECT_MESSAGES_FIELD) + private Boolean canManageDirectMessages; } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/commands/scope/BotCommandScopeChat.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/commands/scope/BotCommandScopeChat.java index 5c7dbe17f..015be74f6 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/commands/scope/BotCommandScopeChat.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/commands/scope/BotCommandScopeChat.java @@ -40,7 +40,8 @@ public class BotCommandScopeChat implements BotCommandScope { @JsonProperty(TYPE_FIELD) private final String type = "chat"; /** - * Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) + * Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername). + * Channel direct messages chats and channel chats aren't supported. */ @JsonProperty(CHATID_FIELD) @NonNull diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/commands/scope/BotCommandScopeChatAdministrators.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/commands/scope/BotCommandScopeChatAdministrators.java index 292c754ea..e80f1b5cb 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/commands/scope/BotCommandScopeChatAdministrators.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/commands/scope/BotCommandScopeChatAdministrators.java @@ -38,7 +38,8 @@ public class BotCommandScopeChatAdministrators implements BotCommandScope { @JsonProperty(TYPE_FIELD) private final String type = "chat_administrators"; /** - * Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) + * Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername). + * Channel direct messages chats and channel chats aren't supported. */ @JsonProperty(CHATID_FIELD) @NonNull diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/commands/scope/BotCommandScopeChatMember.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/commands/scope/BotCommandScopeChatMember.java index 69d7429a0..fafbc2eae 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/commands/scope/BotCommandScopeChatMember.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/commands/scope/BotCommandScopeChatMember.java @@ -39,7 +39,8 @@ public class BotCommandScopeChatMember implements BotCommandScope { @JsonProperty(TYPE_FIELD) private final String type = "chat_member"; /** - * Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) + * Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername). + * Channel direct messages chats and channel chats aren't supported. */ @JsonProperty(CHATID_FIELD) @NonNull diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/Gift.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/Gift.java index 1350af0f7..eeb673193 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/Gift.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/Gift.java @@ -13,6 +13,7 @@ import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.objects.chat.Chat; import org.telegram.telegrambots.meta.api.objects.stickers.Sticker; /** @@ -38,6 +39,7 @@ public class Gift implements BotApiObject { private static final String TOTAL_COUNT_FIELD = "total_count"; private static final String REMAINING_COUNT_FIELD = "remaining_count"; private static final String UPGRADE_STAR_COUNT_FIELD = "upgrade_star_count"; + private static final String PUBLISHER_CHAT_FIELD = "publisher_chat"; /** * Unique identifier of the gift @@ -75,4 +77,11 @@ public class Gift implements BotApiObject { */ @JsonProperty(UPGRADE_STAR_COUNT_FIELD) private Integer upgradeStarCount; + + /** + * Optional. + * Information about the chat that published the gift + */ + @JsonProperty(PUBLISHER_CHAT_FIELD) + private Chat publisherChat; } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGift.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGift.java index 4b00508b7..e5a604839 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGift.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGift.java @@ -13,6 +13,7 @@ import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.objects.chat.Chat; /** * @author Ruben Bermudez @@ -37,6 +38,7 @@ public class UniqueGift implements BotApiObject { private static final String MODEL_FIELD = "model"; private static final String SYMBOL_FIELD = "symbol"; private static final String BACKDROP_FIELD = "backdrop"; + private static final String PUBLISHER_CHAT_FIELD = "publisher_chat"; /** * Human-readable name of the regular gift from which this unique gift was upgraded @@ -71,4 +73,11 @@ public class UniqueGift implements BotApiObject { */ @JsonProperty(BACKDROP_FIELD) private UniqueGiftBackdrop backdrop; + + /** + * Optional. + * Information about the chat that published the gift + */ + @JsonProperty(PUBLISHER_CHAT_FIELD) + private Chat publisherChat; } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/message/DirectMessagesTopic.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/message/DirectMessagesTopic.java new file mode 100644 index 000000000..52920d5a1 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/message/DirectMessagesTopic.java @@ -0,0 +1,46 @@ +package org.telegram.telegrambots.meta.api.objects.message; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.objects.User; + +/** + * This object represents a topic of a direct messages chat. + * @author Generated based on Telegram Bot API + * @version 9.0 + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@RequiredArgsConstructor +@AllArgsConstructor +public class DirectMessagesTopic implements BotApiObject { + private static final String TOPIC_ID_FIELD = "topic_id"; + private static final String USER_FIELD = "user"; + + /** + * Unique identifier of the topic + */ + @JsonProperty(TOPIC_ID_FIELD) + @NonNull + private Integer topicId; + + /** + * Optional. + * Information about the user that created the topic. + * Currently, it is always present + */ + @JsonProperty(USER_FIELD) + private User user; +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/message/Message.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/message/Message.java index fa0801c74..9a8f6967b 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/message/Message.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/message/Message.java @@ -65,6 +65,12 @@ import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup; import org.telegram.telegrambots.meta.api.objects.stickers.Sticker; import org.telegram.telegrambots.meta.api.objects.stories.Story; +import org.telegram.telegrambots.meta.api.objects.suggestedpost.SuggestedPostApprovalFailed; +import org.telegram.telegrambots.meta.api.objects.suggestedpost.SuggestedPostApproved; +import org.telegram.telegrambots.meta.api.objects.suggestedpost.SuggestedPostDeclined; +import org.telegram.telegrambots.meta.api.objects.suggestedpost.SuggestedPostInfo; +import org.telegram.telegrambots.meta.api.objects.suggestedpost.SuggestedPostPaid; +import org.telegram.telegrambots.meta.api.objects.suggestedpost.SuggestedPostRefunded; import org.telegram.telegrambots.meta.api.objects.videochat.VideoChatEnded; import org.telegram.telegrambots.meta.api.objects.videochat.VideoChatParticipantsInvited; import org.telegram.telegrambots.meta.api.objects.videochat.VideoChatScheduled; @@ -190,6 +196,15 @@ public class Message implements MaybeInaccessibleMessage { private static final String CHECKLIST_FIELD = "checklist"; private static final String CHECKLIST_TASKS_DONE_FIELD = "checklist_tasks_done"; private static final String CHECKLIST_TASKS_ADDED_FIELD = "checklist_tasks_added"; + private static final String REPLY_TO_CHECKLIST_TASK_ID_FIELD = "reply_to_checklist_task_id"; + private static final String IS_PAID_POST_FIELD = "is_paid_post"; + private static final String DIRECT_MESSAGES_TOPIC_FIELD = "direct_messages_topic"; + private static final String SUGGESTED_POST_INFO_FIELD = "suggested_post_info"; + private static final String SUGGESTED_POST_APPROVED_FIELD = "suggested_post_approved"; + private static final String SUGGESTED_POST_APPROVAL_FAILED_FIELD = "suggested_post_approval_failed"; + private static final String SUGGESTED_POST_DECLINED_FIELD = "suggested_post_declined"; + private static final String SUGGESTED_POST_PAID_FIELD = "suggested_post_paid"; + private static final String SUGGESTED_POST_REFUNDED_FIELD = "suggested_post_refunded"; /** * Unique message identifier inside this chat. In specific instances (e.g., message containing a video sent to a big chat), @@ -819,6 +834,62 @@ public class Message implements MaybeInaccessibleMessage { */ @JsonProperty(CHECKLIST_TASKS_ADDED_FIELD) private ChecklistTasksAdded checklistTasksAdded; + /** + * Optional. + * Identifier of the specific checklist task that is being replied to + */ + @JsonProperty(REPLY_TO_CHECKLIST_TASK_ID_FIELD) + private Integer replyToChecklistTaskId; + /** + * Optional. + * True, if the message is a paid post. Note that such posts must not be deleted for 24 hours + * to receive the payment and can't be edited. + */ + @JsonProperty(IS_PAID_POST_FIELD) + private Boolean isPaidPost; + /** + * Optional. + * Information about the direct messages chat topic that contains the message + */ + @JsonProperty(DIRECT_MESSAGES_TOPIC_FIELD) + private DirectMessagesTopic directMessagesTopic; + /** + * Optional. + * Information about suggested post parameters if the message is a suggested post in a channel direct messages chat. + * If the message is an approved or declined suggested post, then it can't be edited. + */ + @JsonProperty(SUGGESTED_POST_INFO_FIELD) + private SuggestedPostInfo suggestedPostInfo; + /** + * Optional. + * Service message: a suggested post was approved + */ + @JsonProperty(SUGGESTED_POST_APPROVED_FIELD) + private SuggestedPostApproved suggestedPostApproved; + /** + * Optional. + * Service message: approval of a suggested post has failed + */ + @JsonProperty(SUGGESTED_POST_APPROVAL_FAILED_FIELD) + private SuggestedPostApprovalFailed suggestedPostApprovalFailed; + /** + * Optional. + * Service message: a suggested post was declined + */ + @JsonProperty(SUGGESTED_POST_DECLINED_FIELD) + private SuggestedPostDeclined suggestedPostDeclined; + /** + * Optional. + * Service message: payment for a suggested post was received + */ + @JsonProperty(SUGGESTED_POST_PAID_FIELD) + private SuggestedPostPaid suggestedPostPaid; + /** + * Optional. + * Service message: payment for a suggested post was refunded + */ + @JsonProperty(SUGGESTED_POST_REFUNDED_FIELD) + private SuggestedPostRefunded suggestedPostRefunded; public List getEntities() { if (entities != null) { @@ -1115,4 +1186,49 @@ public boolean hasChecklistTasksDone() { public boolean hasChecklistTasksAdded() { return checklistTasksAdded != null; } + + @JsonIgnore + public boolean hasReplyToChecklistTaskId() { + return replyToChecklistTaskId != null; + } + + @JsonIgnore + public boolean isPaidPost() { + return isPaidPost != null && isPaidPost; + } + + @JsonIgnore + public boolean hasDirectMessagesTopic() { + return directMessagesTopic != null; + } + + @JsonIgnore + public boolean hasSuggestedPostInfo() { + return suggestedPostInfo != null; + } + + @JsonIgnore + public boolean hasSuggestedPostApproved() { + return suggestedPostApproved != null; + } + + @JsonIgnore + public boolean hasSuggestedPostApprovalFailed() { + return suggestedPostApprovalFailed != null; + } + + @JsonIgnore + public boolean hasSuggestedPostDeclined() { + return suggestedPostDeclined != null; + } + + @JsonIgnore + public boolean hasSuggestedPostPaid() { + return suggestedPostPaid != null; + } + + @JsonIgnore + public boolean hasSuggestedPostRefunded() { + return suggestedPostRefunded != null; + } } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/suggestedpost/SuggestedPostApprovalFailed.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/suggestedpost/SuggestedPostApprovalFailed.java new file mode 100644 index 000000000..1fe644347 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/suggestedpost/SuggestedPostApprovalFailed.java @@ -0,0 +1,53 @@ +package org.telegram.telegrambots.meta.api.objects.suggestedpost; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.objects.message.Message; + +/** + * Describes a service message about the failed approval of a suggested post. + * Currently, only caused by insufficient user funds at the time of approval. + * @author Generated using AI assistance + * @version 9.0 + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@RequiredArgsConstructor +@AllArgsConstructor +@Builder +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class SuggestedPostApprovalFailed implements BotApiObject { + private static final String SUGGESTED_POST_MESSAGE_FIELD = "suggested_post_message"; + private static final String PRICE_FIELD = "price"; + + /** + * Optional. + * Message containing the suggested post whose approval has failed. Note that the Message object + * in this field will not contain the reply_to_message field even if it itself is a reply. + */ + @JsonProperty(SUGGESTED_POST_MESSAGE_FIELD) + private Message suggestedPostMessage; + + /** + * Expected price of the post + */ + @JsonProperty(PRICE_FIELD) + @NonNull + private SuggestedPostPrice price; +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/suggestedpost/SuggestedPostApproved.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/suggestedpost/SuggestedPostApproved.java new file mode 100644 index 000000000..5e2e5ed24 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/suggestedpost/SuggestedPostApproved.java @@ -0,0 +1,60 @@ +package org.telegram.telegrambots.meta.api.objects.suggestedpost; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.objects.message.Message; + +/** + * Describes a service message about the approval of a suggested post. + * @author Generated using AI assistance + * @version 9.0 + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@RequiredArgsConstructor +@AllArgsConstructor +@Builder +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class SuggestedPostApproved implements BotApiObject { + private static final String SUGGESTED_POST_MESSAGE_FIELD = "suggested_post_message"; + private static final String PRICE_FIELD = "price"; + private static final String SEND_DATE_FIELD = "send_date"; + + /** + * Optional. + * Message containing the suggested post. Note that the Message object in this field will not contain + * the reply_to_message field even if it itself is a reply. + */ + @JsonProperty(SUGGESTED_POST_MESSAGE_FIELD) + private Message suggestedPostMessage; + + /** + * Optional. + * Amount paid for the post + */ + @JsonProperty(PRICE_FIELD) + private SuggestedPostPrice price; + + /** + * Date when the post will be published + */ + @JsonProperty(SEND_DATE_FIELD) + @NonNull + private Integer sendDate; +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/suggestedpost/SuggestedPostDeclined.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/suggestedpost/SuggestedPostDeclined.java new file mode 100644 index 000000000..6189a83e8 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/suggestedpost/SuggestedPostDeclined.java @@ -0,0 +1,49 @@ +package org.telegram.telegrambots.meta.api.objects.suggestedpost; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.objects.message.Message; + +/** + * Describes a service message about the rejection of a suggested post. + * @author Generated using AI assistance + * @version 9.0 + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +@Builder +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class SuggestedPostDeclined implements BotApiObject { + private static final String SUGGESTED_POST_MESSAGE_FIELD = "suggested_post_message"; + private static final String COMMENT_FIELD = "comment"; + + /** + * Optional. + * Message containing the suggested post. Note that the Message object in this field will not contain + * the reply_to_message field even if it itself is a reply. + */ + @JsonProperty(SUGGESTED_POST_MESSAGE_FIELD) + private Message suggestedPostMessage; + + /** + * Optional. + * Comment with which the post was declined + */ + @JsonProperty(COMMENT_FIELD) + private String comment; +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/suggestedpost/SuggestedPostInfo.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/suggestedpost/SuggestedPostInfo.java new file mode 100644 index 000000000..bd9b631ca --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/suggestedpost/SuggestedPostInfo.java @@ -0,0 +1,59 @@ +package org.telegram.telegrambots.meta.api.objects.suggestedpost; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; + +/** + * Contains information about a suggested post. + * @author Generated using AI assistance + * @version 9.0 + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@RequiredArgsConstructor +@AllArgsConstructor +@Builder +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class SuggestedPostInfo implements BotApiObject { + private static final String STATE_FIELD = "state"; + private static final String PRICE_FIELD = "price"; + private static final String SEND_DATE_FIELD = "send_date"; + + /** + * State of the suggested post. Currently, it can be one of "pending", "approved", "declined". + */ + @JsonProperty(STATE_FIELD) + @NonNull + private String state; + + /** + * Optional. + * Proposed price of the post. If the field is omitted, then the post is unpaid. + */ + @JsonProperty(PRICE_FIELD) + private SuggestedPostPrice price; + + /** + * Optional. + * Proposed send date of the post. If the field is omitted, then the post can be published at any time + * within 30 days at the sole discretion of the user or administrator who approves it. + */ + @JsonProperty(SEND_DATE_FIELD) + private Integer sendDate; +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/suggestedpost/SuggestedPostPaid.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/suggestedpost/SuggestedPostPaid.java new file mode 100644 index 000000000..265abbeaf --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/suggestedpost/SuggestedPostPaid.java @@ -0,0 +1,70 @@ +package org.telegram.telegrambots.meta.api.objects.suggestedpost; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.objects.message.Message; +import org.telegram.telegrambots.meta.api.objects.payments.star.StarAmount; + +/** + * Describes a service message about a successful payment for a suggested post. + * @author Generated using AI assistance + * @version 9.0 + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@RequiredArgsConstructor +@AllArgsConstructor +@Builder +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class SuggestedPostPaid implements BotApiObject { + private static final String SUGGESTED_POST_MESSAGE_FIELD = "suggested_post_message"; + private static final String CURRENCY_FIELD = "currency"; + private static final String AMOUNT_FIELD = "amount"; + private static final String STAR_AMOUNT_FIELD = "star_amount"; + + /** + * Optional. + * Message containing the suggested post. Note that the Message object in this field will not contain + * the reply_to_message field even if it itself is a reply. + */ + @JsonProperty(SUGGESTED_POST_MESSAGE_FIELD) + private Message suggestedPostMessage; + + /** + * Currency in which the payment was made. Currently, one of "XTR" for Telegram Stars + * or "TON" for toncoins + */ + @JsonProperty(CURRENCY_FIELD) + @NonNull + private String currency; + + /** + * Optional. + * The amount of the currency that was received by the channel in nanotoncoins; for payments in toncoins only + */ + @JsonProperty(AMOUNT_FIELD) + private Integer amount; + + /** + * Optional. + * The amount of Telegram Stars that was received by the channel; for payments in Telegram Stars only + */ + @JsonProperty(STAR_AMOUNT_FIELD) + private StarAmount starAmount; +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/suggestedpost/SuggestedPostParameters.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/suggestedpost/SuggestedPostParameters.java new file mode 100644 index 000000000..f3c0887bd --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/suggestedpost/SuggestedPostParameters.java @@ -0,0 +1,49 @@ +package org.telegram.telegrambots.meta.api.objects.suggestedpost; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; + +/** + * Contains parameters of a post that is being suggested by the bot. + * @author Generated using AI assistance + * @version 9.0 + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +@Builder +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class SuggestedPostParameters implements BotApiObject { + private static final String PRICE_FIELD = "price"; + private static final String SEND_DATE_FIELD = "send_date"; + + /** + * Optional. + * Proposed price for the post. If the field is omitted, then the post is unpaid. + */ + @JsonProperty(PRICE_FIELD) + private SuggestedPostPrice price; + + /** + * Optional. + * Proposed send date of the post. If specified, then the date must be between 300 second + * and 2678400 seconds (30 days) in the future. If the field is omitted, then the post + * can be published at any time within 30 days at the sole discretion of the user who approves it. + */ + @JsonProperty(SEND_DATE_FIELD) + private Integer sendDate; +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/suggestedpost/SuggestedPostPrice.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/suggestedpost/SuggestedPostPrice.java new file mode 100644 index 000000000..78ce10109 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/suggestedpost/SuggestedPostPrice.java @@ -0,0 +1,50 @@ +package org.telegram.telegrambots.meta.api.objects.suggestedpost; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.Setter; +import lombok.ToString; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; + +/** + * Describes price of a suggested post. + * @author Generated using AI assistance + * @version 9.0 + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +@Builder +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class SuggestedPostPrice implements BotApiObject { + private static final String CURRENCY_FIELD = "currency"; + private static final String AMOUNT_FIELD = "amount"; + + /** + * Currency in which the post will be paid. Currently, must be one of "XTR" for Telegram Stars or "TON" for toncoins + */ + @JsonProperty(CURRENCY_FIELD) + @NonNull + private String currency; + + /** + * The amount of the currency that will be paid for the post in the smallest units of the currency, + * i.e. Telegram Stars or nanotoncoins. Currently, price in Telegram Stars must be between 5 and 100000, + * and price in nanotoncoins must be between 10000000 and 10000000000000. + */ + @JsonProperty(AMOUNT_FIELD) + @NonNull + private Integer amount; +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/suggestedpost/SuggestedPostRefunded.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/suggestedpost/SuggestedPostRefunded.java new file mode 100644 index 000000000..aed0c154b --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/suggestedpost/SuggestedPostRefunded.java @@ -0,0 +1,54 @@ +package org.telegram.telegrambots.meta.api.objects.suggestedpost; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.objects.message.Message; + +/** + * Describes a service message about a payment refund for a suggested post. + * @author Generated using AI assistance + * @version 9.0 + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@RequiredArgsConstructor +@AllArgsConstructor +@Builder +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class SuggestedPostRefunded implements BotApiObject { + private static final String SUGGESTED_POST_MESSAGE_FIELD = "suggested_post_message"; + private static final String REASON_FIELD = "reason"; + + /** + * Optional. + * Message containing the suggested post. Note that the Message object in this field will not contain + * the reply_to_message field even if it itself is a reply. + */ + @JsonProperty(SUGGESTED_POST_MESSAGE_FIELD) + private Message suggestedPostMessage; + + /** + * Reason for the refund. Currently, one of "post_deleted" if the post was deleted within 24 hours + * of being posted or removed from scheduled messages without being posted, or "payment_refunded" + * if the payer refunded their payment. + */ + @JsonProperty(REASON_FIELD) + @NonNull + private String reason; +} diff --git a/telegrambots-springboot-longpolling-starter/pom.xml b/telegrambots-springboot-longpolling-starter/pom.xml index c15938035..bb3daaeee 100644 --- a/telegrambots-springboot-longpolling-starter/pom.xml +++ b/telegrambots-springboot-longpolling-starter/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 9.1.0 + 9.2.0 telegrambots-springboot-longpolling-starter @@ -60,8 +60,8 @@ UTF-8 UTF-8 - 9.1.0 - 3.2.3 + 9.2.0 + 3.5.5 diff --git a/telegrambots-springboot-webhook-starter/pom.xml b/telegrambots-springboot-webhook-starter/pom.xml index 5542cd1ac..bb314193c 100644 --- a/telegrambots-springboot-webhook-starter/pom.xml +++ b/telegrambots-springboot-webhook-starter/pom.xml @@ -6,7 +6,7 @@ org.telegram Bots - 9.1.0 + 9.2.0 telegrambots-springboot-webhook-starter @@ -59,8 +59,8 @@ UTF-8 UTF-8 - 9.1.0 - 3.2.3 + 9.2.0 + 3.5.5 2.17.2 diff --git a/telegrambots-test-reports/pom.xml b/telegrambots-test-reports/pom.xml index ccd6b57c3..4e1b2ab1f 100644 --- a/telegrambots-test-reports/pom.xml +++ b/telegrambots-test-reports/pom.xml @@ -6,7 +6,7 @@ org.telegram Bots - 9.1.0 + 9.2.0 telegrambots-test-reports diff --git a/telegrambots-webhook/pom.xml b/telegrambots-webhook/pom.xml index d3c8f780f..755af9b94 100644 --- a/telegrambots-webhook/pom.xml +++ b/telegrambots-webhook/pom.xml @@ -6,7 +6,7 @@ org.telegram Bots - 9.1.0 + 9.2.0 telegrambots-webhook @@ -47,7 +47,7 @@ UTF-8 UTF-8 - 6.1.3 + 6.7.0 2.18.0 @@ -117,7 +117,7 @@ ch.qos.logback logback-classic - 1.5.0 + 1.5.18 test From ce62f0e16899237c8149d049f31c634d17e12148 Mon Sep 17 00:00:00 2001 From: Dzianis Klebanovich <92529516+denisklebanovich@users.noreply.github.com> Date: Sun, 12 Oct 2025 19:54:48 +0300 Subject: [PATCH 07/16] Fix UniqueGiftBackdrop json fields (#1541) * Fix UniqueGiftBackdrop NAME_FIELD * Fix UniqueGiftBackdrop COLORS_FIELD and RARITY_PER_MILLE_FIELD --- .../meta/api/objects/gifts/UniqueGiftBackdrop.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGiftBackdrop.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGiftBackdrop.java index 32eaaf45a..71d7fe212 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGiftBackdrop.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/gifts/UniqueGiftBackdrop.java @@ -31,9 +31,9 @@ @JsonIgnoreProperties(ignoreUnknown = true) @JsonInclude(JsonInclude.Include.NON_NULL) public class UniqueGiftBackdrop implements BotApiObject { - private static final String NAME_FIELD = "center_color"; - private static final String COLORS_FIELD = "edge_color"; - private static final String RARITY_PER_MILLE_FIELD = "symbol_color"; + private static final String NAME_FIELD = "name"; + private static final String COLORS_FIELD = "colors"; + private static final String RARITY_PER_MILLE_FIELD = "rarity_per_mille"; /** * Name of the backdrop From 84d0f06a22d72836144368c57b1e5cbcc51d2d59 Mon Sep 17 00:00:00 2001 From: Victor Melnik Date: Fri, 2 Jan 2026 17:28:03 +0200 Subject: [PATCH 08/16] Fix videoStartTimestamp type from Boolean to Integer --- .../org/telegram/telegrambots/meta/api/methods/CopyMessage.java | 2 +- .../telegram/telegrambots/meta/api/methods/ForwardMessage.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 b29acc8f3..a8e9bc2ed 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 @@ -136,7 +136,7 @@ public class CopyMessage extends BotApiMethod { * New start timestamp for the copied video in the message */ @JsonProperty(VIDEO_START_TIMESTAMP_FIELD) - private Boolean videoStartTimestamp; + private Integer videoStartTimestamp; /** * Optional diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/ForwardMessage.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/ForwardMessage.java index 573f1f89f..7de8cf069 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/ForwardMessage.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/ForwardMessage.java @@ -86,7 +86,7 @@ public class ForwardMessage extends BotApiMethodMessage { * New start timestamp for the copied video in the message */ @JsonProperty(VIDEO_START_TIMESTAMP_FIELD) - private Boolean videoStartTimestamp; + private Integer videoStartTimestamp; /** * Optional From afca84b941aa2b8ccc0903c5061746683a5bf86c Mon Sep 17 00:00:00 2001 From: Victor Melnik Date: Sat, 3 Jan 2026 17:50:47 +0200 Subject: [PATCH 09/16] Add missing fields from API 9.2 to SendInvoice --- .../meta/api/methods/invoices/SendInvoice.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/invoices/SendInvoice.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/invoices/SendInvoice.java index 56da69d87..3c7be406a 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/invoices/SendInvoice.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/invoices/SendInvoice.java @@ -19,6 +19,7 @@ import org.telegram.telegrambots.meta.api.objects.ReplyParameters; import org.telegram.telegrambots.meta.api.objects.payments.LabeledPrice; import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup; +import org.telegram.telegrambots.meta.api.objects.suggestedpost.SuggestedPostParameters; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; import org.telegram.telegrambots.meta.util.Validations; @@ -44,6 +45,7 @@ public class SendInvoice extends BotApiMethodMessage { private static final String CHAT_ID_FIELD = "chat_id"; private static final String MESSAGE_THREAD_ID_FIELD = "message_thread_id"; + private static final String DIRECT_MESSAGES_TOPIC_ID_FIELD = "direct_messages_topic_id"; private static final String TITLE_FIELD = "title"; private static final String DESCRIPTION_FIELD = "description"; private static final String PAYLOAD_FIELD = "payload"; @@ -73,6 +75,7 @@ public class SendInvoice extends BotApiMethodMessage { private static final String REPLY_PARAMETERS_FIELD = "reply_parameters"; private static final String MESSAGE_EFFECT_ID_FIELD = "message_effect_id"; private static final String ALLOW_PAID_BROADCAST_FIELD = "allow_paid_broadcast"; + private static final String SUGGESTED_POST_PARAMETERS_FIELD = "suggested_post_parameters"; /** * Unique identifier for the target chat or username of the target channel (in the format @channelusername) @@ -86,6 +89,13 @@ public class SendInvoice extends BotApiMethodMessage { */ @JsonProperty(MESSAGE_THREAD_ID_FIELD) private Integer messageThreadId; + /** + * Optional. + * Identifier of the direct messages topic to which the message will be sent; + * required if the message is sent to a direct messages chat + */ + @JsonProperty(DIRECT_MESSAGES_TOPIC_ID_FIELD) + private Integer directMessagesTopicId; /** * Product name */ @@ -285,6 +295,13 @@ public class SendInvoice extends BotApiMethodMessage { */ @JsonProperty(ALLOW_PAID_BROADCAST_FIELD) private Boolean allowPaidBroadcast; + /** + * Optional + * A JSON-serialized object containing the parameters of the suggested post to send; + * for direct messages chats only + */ + @JsonProperty(SUGGESTED_POST_PARAMETERS_FIELD) + private SuggestedPostParameters suggestedPostParameters; @Tolerate public void setChatId(@NonNull Long chatId) { From db1b1359289fc9b309a396cf9c1d6fcb5348d5c2 Mon Sep 17 00:00:00 2001 From: ruben Date: Sat, 3 Jan 2026 21:07:13 +0100 Subject: [PATCH 10/16] Fix merge conflict --- .../telegrambots/meta/api/methods/CopyMessage.java | 8 -------- .../telegrambots/meta/api/methods/ForwardMessage.java | 8 -------- 2 files changed, 16 deletions(-) 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 c80a9fbca..a8e9bc2ed 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 @@ -146,14 +146,6 @@ public class CopyMessage extends BotApiMethod { @JsonProperty(SUGGESTED_POST_PARAMETERS_FIELD) private SuggestedPostParameters suggestedPostParameters; - /** - * Optional - * A JSON-serialized object containing the parameters of the suggested post to send; - * for direct messages chats only - */ - @JsonProperty(SUGGESTED_POST_PARAMETERS_FIELD) - private SuggestedPostParameters suggestedPostParameters; - @Tolerate public void setChatId(@NonNull Long chatId) { this.chatId = chatId.toString(); diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/ForwardMessage.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/ForwardMessage.java index e14423a15..7de8cf069 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/ForwardMessage.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/ForwardMessage.java @@ -96,14 +96,6 @@ public class ForwardMessage extends BotApiMethodMessage { @JsonProperty(SUGGESTED_POST_PARAMETERS_FIELD) private SuggestedPostParameters suggestedPostParameters; - /** - * Optional - * A JSON-serialized object containing the parameters of the suggested post to send; - * for direct messages chats only - */ - @JsonProperty(SUGGESTED_POST_PARAMETERS_FIELD) - private SuggestedPostParameters suggestedPostParameters; - @Tolerate public void setChatId(@NonNull Long chatId) { this.chatId = chatId.toString(); From 464ecfd4fd44f7e332569661babfe9769d6d2c77 Mon Sep 17 00:00:00 2001 From: Anton Prokopev Date: Wed, 5 Nov 2025 14:28:38 +0300 Subject: [PATCH 11/16] Fix topicId type Fixes: https://github.com/rubenlagus/TelegramBots/issues/1544 --- .../meta/api/objects/message/DirectMessagesTopic.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/message/DirectMessagesTopic.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/message/DirectMessagesTopic.java index 52920d5a1..4520a2eab 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/message/DirectMessagesTopic.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/message/DirectMessagesTopic.java @@ -34,7 +34,7 @@ public class DirectMessagesTopic implements BotApiObject { */ @JsonProperty(TOPIC_ID_FIELD) @NonNull - private Integer topicId; + private Long topicId; /** * Optional. From 1bc4481ac1ba2b7892556b83f73b7e2a6c49f72f Mon Sep 17 00:00:00 2001 From: Anthony Xu Date: Wed, 12 Nov 2025 22:58:40 -0600 Subject: [PATCH 12/16] change TestDeleteStory to deterministic implementation --- .../meta/api/methods/stories/TestDeleteStory.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/stories/TestDeleteStory.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/stories/TestDeleteStory.java index 86d614266..b8d5e0d52 100644 --- a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/stories/TestDeleteStory.java +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/stories/TestDeleteStory.java @@ -1,5 +1,7 @@ package org.telegram.telegrambots.meta.api.methods.stories; +import com.fasterxml.jackson.databind.json.JsonMapper; +import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.Test; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; @@ -13,12 +15,14 @@ * @version 9.0 */ public class TestDeleteStory { - private final ObjectMapper mapper = new ObjectMapper(); + private final ObjectMapper mapper = JsonMapper.builder() + .enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY) + .build(); @Test public void testJsonSerialization() { try { - String expectedJson = "{\"business_connection_id\":\"12345\",\"story_id\":67890,\"method\":\"deleteStory\"}"; + String expectedJson = "{\"business_connection_id\":\"12345\",\"method\":\"deleteStory\",\"story_id\":67890}"; DeleteStory deleteStory = DeleteStory.builder() .businessConnectionId("12345") From cec7ca2a2b7addd909fd11834b52c883bc6dceab Mon Sep 17 00:00:00 2001 From: Anthony Xu Date: Wed, 3 Dec 2025 17:18:24 -0600 Subject: [PATCH 13/16] change json serialization unit tests to deterministic impl --- .../meta/api/methods/TestGetUpdates.java | 8 ++++++-- .../meta/api/methods/TestSetGameScore.java | 8 ++++++-- .../api/methods/send/TestSendMediaGroup.java | 10 +++++++--- .../api/methods/stories/TestEditStory.java | 19 ++++++++++++------- .../meta/api/objects/TestDocument.java | 8 ++++++-- .../TestStoryAreaTypeSuggestedReaction.java | 8 ++++++-- .../area/TestStoryAreaTypeWeather.java | 8 ++++++-- .../input/TestInputStoryContentVideo.java | 8 ++++++-- .../meta/test/TestSerialization.java | 14 ++++++++++---- 9 files changed, 65 insertions(+), 26 deletions(-) diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/TestGetUpdates.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/TestGetUpdates.java index 4baabe3de..180e32dfb 100644 --- a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/TestGetUpdates.java +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/TestGetUpdates.java @@ -1,7 +1,9 @@ package org.telegram.telegrambots.meta.api.methods; +import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.json.JsonMapper; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.telegram.telegrambots.meta.api.methods.updates.GetUpdates; @@ -20,7 +22,9 @@ class TestGetUpdates { private GetUpdates getUpdates; - private ObjectMapper mapper = new ObjectMapper(); + private ObjectMapper mapper = JsonMapper.builder() + .enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY) + .build(); @BeforeEach void setUp() { @@ -34,7 +38,7 @@ void setUp() { void testGetUpdatesMustBeSerializable() throws Exception { String json = mapper.writeValueAsString(getUpdates); assertNotNull(json); - assertEquals("{\"offset\":15,\"limit\":100,\"timeout\":50,\"method\":\"getupdates\"}", json); + assertEquals("{\"limit\":100,\"method\":\"getupdates\",\"offset\":15,\"timeout\":50}", json); } @Test diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/TestSetGameScore.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/TestSetGameScore.java index 38b85031a..a7e7afbe3 100644 --- a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/TestSetGameScore.java +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/TestSetGameScore.java @@ -1,6 +1,8 @@ package org.telegram.telegrambots.meta.api.methods; +import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.json.JsonMapper; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.telegram.telegrambots.meta.api.methods.games.SetGameScore; @@ -20,7 +22,9 @@ class TestSetGameScore { private SetGameScore setGameScore; - private ObjectMapper mapper = new ObjectMapper(); + private ObjectMapper mapper = JsonMapper.builder() + .enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY) + .build(); @BeforeEach void setUp() { @@ -34,7 +38,7 @@ void setUp() { void TestGetUpdatesMustBeSerializable() throws Exception { String json = mapper.writeValueAsString(setGameScore); assertNotNull(json); - assertEquals("{\"chat_id\":\"12345\",\"message_id\":54321,\"disable_edit_message\":true,\"user_id\":98765,\"score\":12,\"method\":\"setGameScore\"}", json); + assertEquals("{\"chat_id\":\"12345\",\"disable_edit_message\":true,\"message_id\":54321,\"method\":\"setGameScore\",\"score\":12,\"user_id\":98765}", json); } @Test diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/send/TestSendMediaGroup.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/send/TestSendMediaGroup.java index 352f4510e..5825a552b 100644 --- a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/send/TestSendMediaGroup.java +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/send/TestSendMediaGroup.java @@ -1,6 +1,8 @@ package org.telegram.telegrambots.meta.api.methods.send; +import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.json.JsonMapper; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.telegram.telegrambots.meta.api.objects.media.InputMediaPhoto; @@ -16,14 +18,16 @@ public class TestSendMediaGroup { @BeforeEach void setUp() { - mapper = new ObjectMapper(); + mapper = JsonMapper.builder() + .enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY) + .build(); } @Test public void test() { try { - String expectedJson = "{\"chatId\":\"12345\",\"medias\":[{\"media\":\"attach://321.png\",\"caption_entities\":[],\"type\":\"photo\"}," + - "{\"media\":\"attach://123.png\",\"caption_entities\":[],\"type\":\"photo\"}]," + + String expectedJson = "{\"chatId\":\"12345\",\"medias\":[{\"caption_entities\":[],\"media\":\"attach://321.png\",\"type\":\"photo\"}," + + "{\"caption_entities\":[],\"media\":\"attach://123.png\",\"type\":\"photo\"}]," + "\"method\":\"sendMediaGroup\"}"; InputStream is = new ByteArrayInputStream("RandomFileContent".getBytes()); InputStream is2 = new ByteArrayInputStream("RandomFileContent2".getBytes()); diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/stories/TestEditStory.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/stories/TestEditStory.java index 2c0f97c18..901fc1092 100644 --- a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/stories/TestEditStory.java +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/stories/TestEditStory.java @@ -1,6 +1,8 @@ package org.telegram.telegrambots.meta.api.methods.stories; +import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.json.JsonMapper; import org.junit.jupiter.api.Test; import org.telegram.telegrambots.meta.api.objects.MessageEntity; import org.telegram.telegrambots.meta.api.objects.stories.StoryArea; @@ -20,7 +22,9 @@ * @version 9.0 */ public class TestEditStory { - private final ObjectMapper mapper = new ObjectMapper(); + private final ObjectMapper mapper = JsonMapper.builder() + .enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY) + .build(); @Test public void testJsonSerialization() { @@ -45,12 +49,13 @@ public void testJsonSerialization() { .build()) .build(); - String expectedJson = "{\"business_connection_id\":\"12345\",\"story_id\":67890,\"content\":{\"photo\":" + - "\"test_photo.jpg\",\"type\":\"photo\"},\"caption\":\"Test Caption\",\"parse_mode\":\"HTML\"," + - "\"caption_entities\":[{\"type\":\"bold\",\"offset\":0,\"length\":4}],\"areas\":[{\"position\":" + - "{\"x_percentage\":0.1,\"y_percentage\":0.2,\"width_percentage\":0.3,\"height_percentage\":0.4," + - "\"rotation_angle\":0.0,\"corner_radius_percentage\":0.0},\"type\":{\"url\":\"https://t.me/test\"," + - "\"type\":\"link\"}}],\"method\":\"editStory\"}"; + String expectedJson = "{\"areas\":[{\"position\":{\"corner_radius_percentage\":0.0," + + "\"height_percentage\":0.4,\"rotation_angle\":0.0,\"width_percentage\":0.3," + + "\"x_percentage\":0.1,\"y_percentage\":0.2},\"type\":{\"type\":\"link\",\"url\":" + + "\"https://t.me/test\"}}],\"business_connection_id\":\"12345\",\"caption\":\"Test Caption\"," + + "\"caption_entities\":[{\"length\":4,\"offset\":0,\"type\":\"bold\"}],\"content\":" + + "{\"photo\":\"test_photo.jpg\",\"type\":\"photo\"},\"method\":\"editStory\"," + + "\"parse_mode\":\"HTML\",\"story_id\":67890}"; EditStory editStory = EditStory.builder() .businessConnectionId("12345") diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/TestDocument.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/TestDocument.java index 19c9d6320..8e449cbab 100644 --- a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/TestDocument.java +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/TestDocument.java @@ -1,6 +1,8 @@ package org.telegram.telegrambots.meta.api.objects; +import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.json.JsonMapper; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.telegram.telegrambots.meta.api.objects.photo.PhotoSize; @@ -13,7 +15,9 @@ public class TestDocument { @BeforeEach void setUp() { - mapper = new ObjectMapper(); + mapper = JsonMapper.builder() + .enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY) + .build(); } @Test @@ -21,7 +25,7 @@ public void testSerialization() { String expected = "{" + "\"file_id\":\"docFileId\"," + "\"file_unique_id\":\"docFileUniqueId\"," + - "\"thumbnail\":{\"file_id\":\"fileId\",\"file_unique_id\":\"fileUniqueId\",\"width\":200,\"height\":100,\"file_size\":150}" + + "\"thumbnail\":{\"file_id\":\"fileId\",\"file_size\":150,\"file_unique_id\":\"fileUniqueId\",\"height\":100,\"width\":200}" + "}"; Document document = Document .builder() diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/area/TestStoryAreaTypeSuggestedReaction.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/area/TestStoryAreaTypeSuggestedReaction.java index 0aea8b74e..b8f4599a3 100644 --- a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/area/TestStoryAreaTypeSuggestedReaction.java +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/area/TestStoryAreaTypeSuggestedReaction.java @@ -1,6 +1,8 @@ package org.telegram.telegrambots.meta.api.objects.stories.area; +import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.json.JsonMapper; import org.junit.jupiter.api.Test; import org.telegram.telegrambots.meta.api.objects.reactions.ReactionType; import org.telegram.telegrambots.meta.api.objects.reactions.ReactionTypeEmoji; @@ -14,12 +16,14 @@ * @version 9.0 */ public class TestStoryAreaTypeSuggestedReaction { - private final ObjectMapper mapper = new ObjectMapper(); + private final ObjectMapper mapper = JsonMapper.builder() + .enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY) + .build(); @Test public void testJsonSerialization() { try { - String expectedJson = "{\"reaction_type\":{\"type\":\"emoji\",\"emoji\":\"👍\"},\"is_dark\":true,\"is_flipped\":true,\"type\":\"suggested_reaction\"}"; + String expectedJson = "{\"is_dark\":true,\"is_flipped\":true,\"reaction_type\":{\"emoji\":\"👍\",\"type\":\"emoji\"},\"type\":\"suggested_reaction\"}"; ReactionType reactionType = new ReactionTypeEmoji("👍"); StoryAreaTypeSuggestedReaction storyAreaTypeSuggestedReaction = StoryAreaTypeSuggestedReaction.builder() diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/area/TestStoryAreaTypeWeather.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/area/TestStoryAreaTypeWeather.java index dbda68c29..ddc9c5437 100644 --- a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/area/TestStoryAreaTypeWeather.java +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/area/TestStoryAreaTypeWeather.java @@ -1,6 +1,8 @@ package org.telegram.telegrambots.meta.api.objects.stories.area; +import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.json.JsonMapper; import org.junit.jupiter.api.Test; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; @@ -13,12 +15,14 @@ * @version 9.0 */ public class TestStoryAreaTypeWeather { - private final ObjectMapper mapper = new ObjectMapper(); + private final ObjectMapper mapper = JsonMapper.builder() + .enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY) + .build(); @Test public void testJsonSerialization() { try { - String expectedJson = "{\"temperature\":25.5,\"emoji\":\"☀️\",\"background_color\":16777215,\"type\":\"weather\"}"; + String expectedJson = "{\"background_color\":16777215,\"emoji\":\"☀️\",\"temperature\":25.5,\"type\":\"weather\"}"; StoryAreaTypeWeather storyAreaTypeWeather = StoryAreaTypeWeather.builder() .temperature(25.5f) diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/input/TestInputStoryContentVideo.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/input/TestInputStoryContentVideo.java index 7c4b8b678..7d17262f3 100644 --- a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/input/TestInputStoryContentVideo.java +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/stories/input/TestInputStoryContentVideo.java @@ -1,6 +1,8 @@ package org.telegram.telegrambots.meta.api.objects.stories.input; +import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.json.JsonMapper; import org.junit.jupiter.api.Test; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; @@ -13,12 +15,14 @@ * @version 9.0 */ public class TestInputStoryContentVideo { - private final ObjectMapper mapper = new ObjectMapper(); + private final ObjectMapper mapper = JsonMapper.builder() + .enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY) + .build(); @Test public void testJsonSerialization() { try { - String expectedJson = "{\"video\":\"test_video.mp4\",\"duration\":30.5,\"cover_frame_timestamp\":10.5,\"is_animation\":true,\"type\":\"video\"}"; + String expectedJson = "{\"cover_frame_timestamp\":10.5,\"duration\":30.5,\"is_animation\":true,\"type\":\"video\",\"video\":\"test_video.mp4\"}"; InputStoryContentVideo inputStoryContentVideo = InputStoryContentVideo.builder() .video("test_video.mp4") diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/test/TestSerialization.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/test/TestSerialization.java index f07b3260a..c387593c3 100644 --- a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/test/TestSerialization.java +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/test/TestSerialization.java @@ -1,7 +1,9 @@ package org.telegram.telegrambots.meta.test; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.json.JsonMapper; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import lombok.Data; import org.junit.jupiter.api.Test; @@ -22,7 +24,9 @@ * @version 1.0 */ public class TestSerialization { - private ObjectMapper mapper = new ObjectMapper(); + private ObjectMapper mapper = JsonMapper.builder() + .enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY) + .build(); static { System.setProperty("user.timezone", "EST"); @@ -47,7 +51,9 @@ public void test() throws JsonProcessingException { //@BeforeEach void setUp() { - mapper = new ObjectMapper(); + mapper = JsonMapper.builder() + .enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY) + .build(); } @Test @@ -69,7 +75,7 @@ void testSendLocation() throws JsonProcessingException { String json = mapper.writeValueAsString(location); assertNotNull(json); - assertEquals("{\"chat_id\":\"12345\",\"latitude\":20.758069,\"longitude\":-0.005702,\"disable_notification\":true,\"reply_to_message_id\":1,\"live_period\":100,\"allow_sending_without_reply\":true,\"horizontal_accuracy\":65.0,\"heading\":125,\"proximity_alert_radius\":100,\"method\":\"sendlocation\"}", + assertEquals("{\"allow_sending_without_reply\":true,\"chat_id\":\"12345\",\"disable_notification\":true,\"heading\":125,\"horizontal_accuracy\":65.0,\"latitude\":20.758069,\"live_period\":100,\"longitude\":-0.005702,\"method\":\"sendlocation\",\"proximity_alert_radius\":100,\"reply_to_message_id\":1}", json); } @@ -103,7 +109,7 @@ void testAnswerInlineLocation() throws JsonProcessingException { String json = mapper.writeValueAsString(inlineQuery); assertNotNull(json); - assertEquals("{\"inline_query_id\":\"12345\",\"results\":[{\"type\":\"article\",\"id\":\"1\",\"title\":\"Title\",\"input_message_content\":{\"latitude\":20.758069,\"longitude\":-0.005702,\"horizontal_accuracy\":65.0}}],\"cache_time\":1,\"is_personal\":true,\"next_offset\":\"2\",\"button\":{\"text\":\"switch\",\"start_parameter\":\"parameter\"},\"method\":\"answerInlineQuery\"}", + assertEquals("{\"button\":{\"start_parameter\":\"parameter\",\"text\":\"switch\"},\"cache_time\":1,\"inline_query_id\":\"12345\",\"is_personal\":true,\"method\":\"answerInlineQuery\",\"next_offset\":\"2\",\"results\":[{\"id\":\"1\",\"input_message_content\":{\"horizontal_accuracy\":65.0,\"latitude\":20.758069,\"longitude\":-0.005702},\"title\":\"Title\",\"type\":\"article\"}]}", json); } } From cada4990e742aa1cb740a13ad9080460bf652106 Mon Sep 17 00:00:00 2001 From: kotopyos Date: Mon, 22 Dec 2025 17:17:10 +0300 Subject: [PATCH 14/16] Fix AbilityBot channel updates: logic moved to AbilityUtils, added privacy checks (Fixes #1531) --- .../abilitybots/api/bot/BaseAbilityBot.java | 6 +- .../abilitybots/api/util/AbilityUtils.java | 19 ++++ .../api/bot/TestAbilityBotChannel.java | 107 ++++++++++++++++++ 3 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 telegrambots-abilities/src/test/java/org/telegram/telegrambots/abilitybots/api/bot/TestAbilityBotChannel.java diff --git a/telegrambots-abilities/src/main/java/org/telegram/telegrambots/abilitybots/api/bot/BaseAbilityBot.java b/telegrambots-abilities/src/main/java/org/telegram/telegrambots/abilitybots/api/bot/BaseAbilityBot.java index b03c9050c..70e455227 100644 --- a/telegrambots-abilities/src/main/java/org/telegram/telegrambots/abilitybots/api/bot/BaseAbilityBot.java +++ b/telegrambots-abilities/src/main/java/org/telegram/telegrambots/abilitybots/api/bot/BaseAbilityBot.java @@ -210,6 +210,7 @@ public void consume(Update update) { public Privacy getPrivacy(Update update, long id) { return isCreator(id) ? Privacy.CREATOR : isAdmin(id) ? + Privacy.ADMIN : (update.hasChannelPost() || update.hasEditedChannelPost()) ? Privacy.ADMIN : (isGroupUpdate(update) || isSuperGroupUpdate(update)) && isGroupAdmin(update, id) ? Privacy.GROUP_ADMIN : Privacy.PUBLIC; } @@ -541,8 +542,8 @@ boolean validateAbility(Trio trio) { Trio getAbility(Update update) { // Handle updates without messages // Passing through this function means that the global flags have passed - Message msg = update.getMessage(); - if (!update.hasMessage() || !msg.hasText()) + Message msg = AbilityUtils.getMessage(update); + if (msg == null || !msg.hasText()) return Trio.of(update, abilities.get(DEFAULT), new String[]{}); Ability ability; @@ -602,6 +603,7 @@ Update addUser(Update update) { private boolean hasUser(Update update) { // Valid updates without users should return an empty user // Updates that are not recognized by the getUser method will throw an exception + if (update.hasChannelPost() || update.hasEditedChannelPost()) return true; return !AbilityUtils.getUser(update).equals(EMPTY_USER); } diff --git a/telegrambots-abilities/src/main/java/org/telegram/telegrambots/abilitybots/api/util/AbilityUtils.java b/telegrambots-abilities/src/main/java/org/telegram/telegrambots/abilitybots/api/util/AbilityUtils.java index 59ede736a..e9eb63bec 100644 --- a/telegrambots-abilities/src/main/java/org/telegram/telegrambots/abilitybots/api/util/AbilityUtils.java +++ b/telegrambots-abilities/src/main/java/org/telegram/telegrambots/abilitybots/api/util/AbilityUtils.java @@ -6,6 +6,7 @@ import org.telegram.telegrambots.abilitybots.api.objects.Flag; import org.telegram.telegrambots.meta.api.objects.Update; import org.telegram.telegrambots.meta.api.objects.User; +import org.telegram.telegrambots.meta.api.objects.message.Message; import java.text.MessageFormat; import java.util.Locale; @@ -326,4 +327,22 @@ public static boolean isValidCommandName(String commandName){ if (commandName == null || commandName.length() > 31) return false; return commandName.matches("[A-Za-z_0-9]+"); } + + /** + * Extracts the Message from the Update regardless of the type (Message, ChannelPost, etc). + * @param update Telegram {@link Update} + * @return Message object or null if not found + */ + public static Message getMessage(Update update){ + if (Flag.MESSAGE.test(update)) { + return update.getMessage(); + } else if (Flag.EDITED_MESSAGE.test(update)) { + return update.getEditedMessage(); + } else if (Flag.CHANNEL_POST.test(update)){ + return update.getChannelPost(); + } else if (Flag.EDITED_CHANNEL_POST.test(update)) { + return update.getEditedChannelPost(); + } + return null; + } } diff --git a/telegrambots-abilities/src/test/java/org/telegram/telegrambots/abilitybots/api/bot/TestAbilityBotChannel.java b/telegrambots-abilities/src/test/java/org/telegram/telegrambots/abilitybots/api/bot/TestAbilityBotChannel.java new file mode 100644 index 000000000..57a1e5532 --- /dev/null +++ b/telegrambots-abilities/src/test/java/org/telegram/telegrambots/abilitybots/api/bot/TestAbilityBotChannel.java @@ -0,0 +1,107 @@ +package org.telegram.telegrambots.abilitybots.api.bot; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.telegram.telegrambots.abilitybots.api.db.DBContext; +import org.telegram.telegrambots.abilitybots.api.objects.Ability; +import org.telegram.telegrambots.abilitybots.api.objects.Locality; +import org.telegram.telegrambots.abilitybots.api.objects.Privacy; +import org.telegram.telegrambots.abilitybots.api.sender.SilentSender; +import org.telegram.telegrambots.meta.api.objects.message.Message; +import org.telegram.telegrambots.meta.api.objects.Update; +import org.telegram.telegrambots.meta.generics.TelegramClient; + +import java.io.IOException; + +import org.telegram.telegrambots.abilitybots.api.toggle.BareboneToggle; + +import static org.apache.commons.lang3.StringUtils.EMPTY; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.telegram.telegrambots.abilitybots.api.db.MapDBContext.offlineInstance; + +public class TestAbilityBotChannel { + private ChannelAbilityBot bot; + private DBContext db; + private TelegramClient telegramClient; + private SilentSender silent; + + @BeforeEach + void setUp() { + telegramClient = mock(TelegramClient.class); + silent = spy(new SilentSender(telegramClient)); + + db = offlineInstance("db"); + bot = new ChannelAbilityBot(telegramClient, EMPTY, db); + bot.silent = silent; + bot.onRegister(); + } + + @AfterEach + void tearDown() throws IOException { + db.clear(); + db.close(); + } + + @Test + void canTriggerAbilityInChannel() { + Update update = mock(Update.class); + Message message = mock(Message.class); + + when(update.hasChannelPost()).thenReturn(true); + when(update.getChannelPost()).thenReturn(message); + when(message.getChatId()).thenReturn(12345L); + when(message.hasText()).thenReturn(true); + when(message.getText()).thenReturn("/channel_msg_test"); + when(message.getFrom()).thenReturn(null); // Channel posts dosent have user + + bot.consume(update); + + verify(silent, times(1)).send("testtt", 12345L); + } + + @Test + void canTriggerAbilityInEditedChannelPost() { + Update update = mock(Update.class); + Message message = mock(Message.class); + + when(update.hasChannelPost()).thenReturn(false); + when(update.hasEditedChannelPost()).thenReturn(true); + when(update.getEditedChannelPost()).thenReturn(message); + + when(message.getChatId()).thenReturn(12345L); + when(message.hasText()).thenReturn(true); + when(message.getText()).thenReturn("/channel_msg_test"); + when(message.getFrom()).thenReturn(null); + + bot.consume(update); + + verify(silent, times(1)).send("testtt", 12345L); + } + + private static class ChannelAbilityBot extends BaseAbilityBot { + public ChannelAbilityBot(TelegramClient telegramClient, String botUsername, DBContext db) { + super(telegramClient, botUsername, db, new BareboneToggle()); + } + + @Override + public long creatorId() { + return 228322L; + } + + public Ability test() { + return Ability.builder() + .name("channel_msg_test") + .privacy(Privacy.PUBLIC) + .locality(Locality.ALL) + .action(ctx -> { + silent.send("testtt", ctx.chatId()); + }) + .build(); + } + } +} \ No newline at end of file From efeeca502cda48382596b3607002a55c12a9b0e1 Mon Sep 17 00:00:00 2001 From: kotopyos Date: Thu, 25 Dec 2025 17:30:34 +0300 Subject: [PATCH 15/16] Added: validate method to ReplyFlowBuilder --- .../abilitybots/api/objects/ReplyFlow.java | 47 +++++++++- .../abilitybots/api/bot/TestReplyFlow.java | 94 +++++++++++++++++++ 2 files changed, 136 insertions(+), 5 deletions(-) diff --git a/telegrambots-abilities/src/main/java/org/telegram/telegrambots/abilitybots/api/objects/ReplyFlow.java b/telegrambots-abilities/src/main/java/org/telegram/telegrambots/abilitybots/api/objects/ReplyFlow.java index 578934357..1f2b834d8 100644 --- a/telegrambots-abilities/src/main/java/org/telegram/telegrambots/abilitybots/api/objects/ReplyFlow.java +++ b/telegrambots-abilities/src/main/java/org/telegram/telegrambots/abilitybots/api/objects/ReplyFlow.java @@ -52,6 +52,8 @@ public static class ReplyFlowBuilder { private BiConsumer action; private Set nextReplies; private String name; + private Predicate validator; + private BiConsumer failureAction; private ReplyFlowBuilder(DBContext db, int id) { conds = new ArrayList<>(); @@ -69,6 +71,30 @@ public ReplyFlowBuilder action(BiConsumer action) { return this; } + /** + * This is validation step of the flow + *

+ * Executes by the folloiwng steps {@code onlyIf} -> {@code validate} -> {@code action} + *

+ *

+ * Behavior: + *

    + *
  • If {@code validator} returns {@code true}: flow proceeds normally (executes main action, updates state).
  • + *
  • If {@code validator} returns {@code false}: The {@code failureAction} is executed, the main action is skipped, + * and the user's state remains unchanged (it is NOT updated to the new state ID).
  • + *
+ *

+ * + * @param validator a predicate to check the update (like verifying a password). + * @param failureAction the callback to execute if validation fails (like sending an error message to the user). + * @return current {@link ReplyFlowBuilder} instance for chaining + */ + public ReplyFlowBuilder validate(Predicate validator, BiConsumer failureAction) { + this.validator = validator; + this.failureAction = failureAction; + return this; + } + public ReplyFlowBuilder enableStats(String name) { this.name = name; return this; @@ -103,19 +129,30 @@ public ReplyFlow build() { if (action == null) action = (bot, upd) -> {}; - BiConsumer statefulAction; + BiConsumer stateTransition; if (nextReplies.size() > 0) { - statefulAction = action.andThen((bot, upd) -> { + stateTransition = (bot, upd) -> { Long chatId = AbilityUtils.getChatId(upd); db.getMap(STATES).put(chatId, id); - }); + }; } else { - statefulAction = action.andThen((bot, upd) -> { + stateTransition = (bot, upd) -> { Long chatId = AbilityUtils.getChatId(upd); db.getMap(STATES).remove(chatId); - }); + }; } + BiConsumer statefulAction = (bot, upd) -> { + if (validator == null || validator.test(upd)) { + action.accept(bot, upd); + stateTransition.accept(bot, upd); + } else { + if (failureAction != null) { + failureAction.accept(bot, upd); + } + } + }; + return new ReplyFlow(conds, statefulAction, nextReplies, name); } diff --git a/telegrambots-abilities/src/test/java/org/telegram/telegrambots/abilitybots/api/bot/TestReplyFlow.java b/telegrambots-abilities/src/test/java/org/telegram/telegrambots/abilitybots/api/bot/TestReplyFlow.java index a69545386..061fc6edd 100644 --- a/telegrambots-abilities/src/test/java/org/telegram/telegrambots/abilitybots/api/bot/TestReplyFlow.java +++ b/telegrambots-abilities/src/test/java/org/telegram/telegrambots/abilitybots/api/bot/TestReplyFlow.java @@ -18,6 +18,7 @@ import org.telegram.telegrambots.meta.generics.TelegramClient; import java.io.IOException; +import java.util.Map; import java.util.Set; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -159,6 +160,85 @@ void replyFlowsPertainNames() { assertTrue(replyNames.containsAll(newHashSet("FIRST", "SECOND"))); } + @Test + void testValidationFailPreventsStateChange() { + Reply dummyReply = Reply.of((b, u) -> {}, upd -> false); + ReplyFlow flow = ReplyFlow.builder(db, 1) + .action((bot, upd) -> silent.send("Message is good, lets go further", getChatId(upd))) + .validate( + upd -> false, + (bot, upd) -> silent.send("Validation Failed", getChatId(upd)) + ) + .next(dummyReply) + .build(); + + Update update = TestUtils.mockFullUpdate(bot, TestUtils.USER, "bad message puk kek"); + long chatId = getChatId(update); + + flow.actOn(bot, update); + + verify(silent).send("Validation Failed", chatId); + verify(silent, never()).send("Message is good, lets go further", chatId); + + assertFalse(db.getMap(ReplyFlow.ReplyFlowBuilder.STATES).containsKey(chatId), + "State should NOT be updated if validation fails"); + } + + @Test + void testValidationPassChangesState() { + Reply dummyReply = Reply.of((b, u) -> {}, upd -> false); + ReplyFlow flow = ReplyFlow.builder(db, 1) + .action((bot, upd) -> silent.send("Message is good, lets go further", getChatId(upd))) + .validate( + upd -> true, + (bot, upd) -> silent.send("Validation Failed", getChatId(upd)) + ) + .next(dummyReply) + .build(); + + Update update = TestUtils.mockFullUpdate(bot, TestUtils.USER, "good message mheh kek"); + long chatId = getChatId(update); + + flow.actOn(bot, update); + + verify(silent).send("Message is good, lets go further", chatId); + verify(silent, never()).send("Validation Failed", chatId); + + Map states = db.getMap(ReplyFlow.ReplyFlowBuilder.STATES); + assertTrue(states.containsKey(chatId), "State should be present after successful validation"); + assertEquals(1, states.get(chatId), "User should be in state 1"); + } + + @Test + void testIntegratedValidationFailPreventsStateChange() { + Update upd = TestUtils.mockFullUpdate(bot, TestUtils.USER, "validate me right now >:)"); + long chatId = getChatId(upd); + + // filterReply returns false coz ReplyFlow ate upd + assertFalse(bot.filterReply(upd)); + + verify(silent, never()).send("Validated", chatId); + + Map states = db.getMap(ReplyFlow.ReplyFlowBuilder.STATES); + assertFalse(states.containsKey(chatId), + "State should NOT be updated if validation fails"); + } + + @Test + void testIntegratedValidationPassChangesState() { + Update upd = TestUtils.mockFullUpdate(bot, TestUtils.USER, "validate meee pleaseeee"); + long chatId = getChatId(upd); + + assertFalse(bot.filterReply(upd)); + + verify(silent).send("Validated", chatId); + verify(silent, never()).send("Say magic word :P", chatId); + + Map states = db.getMap(ReplyFlow.ReplyFlowBuilder.STATES); + assertTrue(states.containsKey(chatId), "State should be present after successful validation"); + assertEquals(3, states.get(chatId), "User should be in state 3"); + } + public static class ReplyFlowBot extends AbilityBot { private ReplyFlowBot(TelegramClient telegramClient, String botUsername, DBContext db) { @@ -200,6 +280,20 @@ public Reply errantReply() { }); } + public ReplyFlow validationFlow() { + Reply nextStep = Reply.of((b, u) -> {}, hasMessageWith("bomboclot")); + + return ReplyFlow.builder(db, 3) + .action((bot, upd) -> silent.send("Validated", getChatId(upd))) + .onlyIf(upd -> Flag.MESSAGE.test(upd) && upd.getMessage().getText().toLowerCase().startsWith("validate me")) + .validate( + update -> update.getMessage().getText().toLowerCase().contains("please"), + (bot, upd) -> silent.send("Say magic word :P", getChatId(upd)) + ) + .next(nextStep) + .build(); + } + public Ability replyFlowsWithAbility() { Reply replyWithVk = ReplyFlow.builder(db, 2) .enableStats("SECOND") From b60cb94ea121bbc1c4ebdc22d46792df0ea3e112 Mon Sep 17 00:00:00 2001 From: kotopyos <115741086+kotopyos@users.noreply.github.com> Date: Wed, 31 Dec 2025 18:12:53 +0300 Subject: [PATCH 16/16] Feature: added protected hooks for handling Input, Locality and Privacy ability restrictions --- .../abilitybots/api/bot/BaseAbilityBot.java | 84 +++++++++++++++---- 1 file changed, 67 insertions(+), 17 deletions(-) diff --git a/telegrambots-abilities/src/main/java/org/telegram/telegrambots/abilitybots/api/bot/BaseAbilityBot.java b/telegrambots-abilities/src/main/java/org/telegram/telegrambots/abilitybots/api/bot/BaseAbilityBot.java index 70e455227..7dd079836 100644 --- a/telegrambots-abilities/src/main/java/org/telegram/telegrambots/abilitybots/api/bot/BaseAbilityBot.java +++ b/telegrambots-abilities/src/main/java/org/telegram/telegrambots/abilitybots/api/bot/BaseAbilityBot.java @@ -490,15 +490,32 @@ boolean checkInput(Trio trio) { boolean isOk = abilityTokens == 0 || (tokens.length > 0 && tokens.length == abilityTokens); if (!isOk) - silent.send( - getLocalizedMessage( - CHECK_INPUT_FAIL, - AbilityUtils.getUser(trio.a()).getLanguageCode(), - abilityTokens, abilityTokens == 1 ? "input" : "inputs"), - getChatId(trio.a())); + onInputViolation(trio.a(), trio.b()); return isOk; } + /** + * Called when user input doesn't match the required number of arguments for the ability. + *

+ * Deafult implementation sends localized + * {@link org.telegram.telegrambots.abilitybots.api.util.AbilityMessageCodes#CHECK_INPUT_FAIL} + * message to the user. + *

+ * Override this method to custom handle input errors (e.g. send usage example or do nothing). + * + * @param update update that caused the violation + * @param ability ability that was attempted to be executed + */ + protected void onInputViolation(Update update, Ability ability) { + int abilityTokens = ability.tokens(); + silent.send( + getLocalizedMessage( + CHECK_INPUT_FAIL, + AbilityUtils.getUser(update).getLanguageCode(), + abilityTokens, abilityTokens == 1 ? "input" : "inputs"), + getChatId(update)); + } + boolean checkLocality(Trio trio) { Update update = trio.a(); Locality locality = isUserMessage(update) ? Locality.USER : Locality.GROUP; @@ -507,15 +524,32 @@ boolean checkLocality(Trio trio) { boolean isOk = abilityLocality == Locality.ALL || locality == abilityLocality; if (!isOk) - silent.send( - getLocalizedMessage( - CHECK_LOCALITY_FAIL, - AbilityUtils.getUser(trio.a()).getLanguageCode(), - abilityLocality.toString().toLowerCase()), - getChatId(trio.a())); + onLocalityViolation(trio.a(), trio.b()); return isOk; } + /** + * Called when the user tries to use ability in locality that isn't allowed + * (e.g. using {@link Locality#GROUP} ability in private chat). + *

+ * Deafult implementation sends localized + * {@link org.telegram.telegrambots.abilitybots.api.util.AbilityMessageCodes#CHECK_LOCALITY_FAIL} + * message to the user. + *

+ * Override this method to custom handle locality errors (e.g. silent ignore in groups). + * + * @param update update that caused the violation + * @param ability ability that was attempted to be executed + */ + protected void onLocalityViolation(Update update, Ability ability) { + silent.send( + getLocalizedMessage( + CHECK_LOCALITY_FAIL, + AbilityUtils.getUser(update).getLanguageCode(), + ability.locality().toString().toLowerCase()), + getChatId(update)); + } + boolean checkPrivacy(Trio trio) { Update update = trio.a(); User user = AbilityUtils.getUser(update); @@ -527,14 +561,30 @@ boolean checkPrivacy(Trio trio) { boolean isOk = privacy.compareTo(trio.b().privacy()) >= 0; if (!isOk) - silent.send( - getLocalizedMessage( - CHECK_PRIVACY_FAIL, - AbilityUtils.getUser(trio.a()).getLanguageCode()), - getChatId(trio.a())); + onPrivacyViolation(trio.a(), trio.b()); return isOk; } + /** + * Called when the user doesn't have required {@link Privacy} level to execute the ability. + *

+ * Deafult implementation sends localized + * {@link org.telegram.telegrambots.abilitybots.api.util.AbilityMessageCodes#CHECK_PRIVACY_FAIL} + * message to the user. + *

+ * Override this method to custom handle privacy errors (e.g. log the attempt or ban the user). + * + * @param update update that caused the violation + * @param ability ability that was attempted to be executed + */ + protected void onPrivacyViolation(Update update, Ability ability) { + silent.send( + getLocalizedMessage( + CHECK_PRIVACY_FAIL, + AbilityUtils.getUser(update).getLanguageCode()), + getChatId(update)); + } + boolean validateAbility(Trio trio) { return trio.b() != null; }