diff --git a/README.md b/README.md index e40fa14d..4b0ab7c3 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Telegram Bot Java Library [![Telegram](/TelegramBots.svg)](https://telegram.me/JavaBotsApi) - +[![Build Status](https://telegrambots.teamcity.com/app/rest/builds/buildType:(id:TelegramBots_TelegramBotsBuild)/statusIcon.svg)](https://telegrambots.teamcity.com/viewType.html?buildTypeId=TelegramBots_TelegramBotsBuild) [![Build Status](https://travis-ci.org/rubenlagus/TelegramBots.svg?branch=master)](https://travis-ci.org/rubenlagus/TelegramBots) [![Jitpack](https://jitpack.io/v/rubenlagus/TelegramBots.svg)](https://jitpack.io/#rubenlagus/TelegramBots) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.telegram/telegrambots/badge.svg)](http://mvnrepository.com/artifact/org.telegram/telegrambots) @@ -27,18 +27,18 @@ Just import add the library to your project with one of these options: org.telegram telegrambots - 5.1.1 + 5.2.0 ``` 2. Using Gradle: ```gradle - implementation 'org.telegram:telegrambots:5.1.1' + implementation 'org.telegram:telegrambots:5.2.0' ``` - 3. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/5.1.1) - 4. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/5.1.1) + 3. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/5.2.0) + 4. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/5.2.0) In order to use Long Polling mode, just create your own bot extending `org.telegram.telegrambots.bots.TelegramLongPollingBot`. diff --git a/TelegramBots.wiki/Changelog.md b/TelegramBots.wiki/Changelog.md index 40f4336e..3e38a7ee 100644 --- a/TelegramBots.wiki/Changelog.md +++ b/TelegramBots.wiki/Changelog.md @@ -1,3 +1,9 @@ +### 5.2.0 ### +1. Update Api version [5.2](https://core.telegram.org/bots/api#april-26-2021) +2. Allow custom BackOff implementations +3. Spring version 2.4.5 in spring module +4. Bug fixing: #869, #888 and #892 + ### 5.1.1 ### 1. Bug fixing: #874 diff --git a/TelegramBots.wiki/Getting-Started.md b/TelegramBots.wiki/Getting-Started.md index 6551e769..d82cad76 100644 --- a/TelegramBots.wiki/Getting-Started.md +++ b/TelegramBots.wiki/Getting-Started.md @@ -11,13 +11,13 @@ First you need ot get the library and add it to your project. There are few poss org.telegram telegrambots - 5.1.1 + 5.2.0 ``` * With **Gradle**: ```gradle - implementation 'org.telegram:telegrambots:5.1.1' + implementation 'org.telegram:telegrambots:5.2.0' ``` 2. Don't like **Maven Central Repository**? It can also be taken from [Jitpack](https://jitpack.io/#rubenlagus/TelegramBots). diff --git a/TelegramBots.wiki/abilities/Simple-Example.md b/TelegramBots.wiki/abilities/Simple-Example.md index 3f1ebfff..e808c44a 100644 --- a/TelegramBots.wiki/abilities/Simple-Example.md +++ b/TelegramBots.wiki/abilities/Simple-Example.md @@ -9,12 +9,12 @@ As with any Java project, you will need to set your dependencies. org.telegram telegrambots-abilities - 5.1.1 + 5.2.0 ``` * **Gradle** ```gradle - implementation 'org.telegram:telegrambots-abilities:5.1.1' + implementation 'org.telegram:telegrambots-abilities:5.2.0' ``` * [JitPack](https://jitpack.io/#rubenlagus/TelegramBots) diff --git a/pom.xml b/pom.xml index 4f48691c..e2890c22 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots pom - 5.1.1 + 5.2.0 telegrambots diff --git a/telegrambots-abilities/README.md b/telegrambots-abilities/README.md index b3b67375..a6197a0f 100644 --- a/telegrambots-abilities/README.md +++ b/telegrambots-abilities/README.md @@ -18,14 +18,14 @@ Usage org.telegram telegrambots-abilities - 5.1.1 + 5.2.0 ``` **Gradle** ```gradle - implementation 'org.telegram:telegrambots-abilities:5.1.1' + implementation 'org.telegram:telegrambots-abilities:5.2.0' ``` **JitPack** - [JitPack](https://jitpack.io/#rubenlagus/TelegramBots/v5.0.1) diff --git a/telegrambots-abilities/pom.xml b/telegrambots-abilities/pom.xml index 99945f87..33cfa100 100644 --- a/telegrambots-abilities/pom.xml +++ b/telegrambots-abilities/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 5.1.1 + 5.2.0 telegrambots-abilities @@ -84,7 +84,7 @@ org.telegram telegrambots - 5.1.1 + 5.2.0 org.apache.commons diff --git a/telegrambots-chat-session-bot/README.md b/telegrambots-chat-session-bot/README.md index 108d80dc..3ca0356a 100644 --- a/telegrambots-chat-session-bot/README.md +++ b/telegrambots-chat-session-bot/README.md @@ -15,14 +15,14 @@ Usage org.telegram telegrambots-chat-session-bot - 5.1.1 + 5.2.0 ``` **Gradle** ```gradle - implementation 'org.telegram:telegrambots-chat-session-bot:5.1.1' + implementation 'org.telegram:telegrambots-chat-session-bot:5.2.0' ``` Motivation diff --git a/telegrambots-chat-session-bot/pom.xml b/telegrambots-chat-session-bot/pom.xml index 30cd601a..202920b5 100644 --- a/telegrambots-chat-session-bot/pom.xml +++ b/telegrambots-chat-session-bot/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 5.1.1 + 5.2.0 telegrambots-chat-session-bot @@ -84,7 +84,7 @@ org.telegram telegrambots - 5.1.1 + 5.2.0 diff --git a/telegrambots-extensions/README.md b/telegrambots-extensions/README.md index 33f1642e..4379b212 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 telegrambotsextensions - 5.1.1 + 5.2.0 ``` 2. Using Gradle: ```gradle - implementation 'org.telegram:telegrambotsextensions:5.1.1' + implementation 'org.telegram:telegrambotsextensions:5.2.0' ``` \ No newline at end of file diff --git a/telegrambots-extensions/pom.xml b/telegrambots-extensions/pom.xml index e35b6cae..5d9488d9 100644 --- a/telegrambots-extensions/pom.xml +++ b/telegrambots-extensions/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 5.1.1 + 5.2.0 telegrambotsextensions @@ -75,7 +75,7 @@ org.telegram telegrambots - 5.1.1 + 5.2.0 diff --git a/telegrambots-meta/pom.xml b/telegrambots-meta/pom.xml index 2e54389b..a39ea50b 100644 --- a/telegrambots-meta/pom.xml +++ b/telegrambots-meta/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 5.1.1 + 5.2.0 telegrambots-meta diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/ActionType.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/ActionType.java index 6b16949c..6f85078c 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/ActionType.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/ActionType.java @@ -3,22 +3,31 @@ package org.telegram.telegrambots.meta.api.methods; /** * @author Ruben Bermudez * @version 1.0 - * @brief Types of actions for SendChatAction method. - * @date 20 of June of 2016 + * Types of actions for SendChatAction method. */ public enum ActionType { TYPING("typing"), RECORDVIDEO("record_video"), RECORDVIDEONOTE("record_video_note"), + /** + * @deprecated Use {@link #RECORDVOICE} instead + */ + @Deprecated RECORDAUDIO("record_audio"), + RECORDVOICE("record_voice"), UPLOADPHOTO("upload_photo"), UPLOADVIDEO("upload_video"), UPLOADVIDEONOTE("upload_video_note"), + /** + * @deprecated Use {@link #UPLOADVOICE} instead + */ + @Deprecated UPLOADAUDIO("upload_audio"), + UPLOADVOICE("upload_voice"), UPLOADDOCUMENT("upload_document"), FINDLOCATION("find_location"); - private String text; + private final String text; ActionType(String text) { this.text = text; @@ -41,7 +50,8 @@ public enum ActionType { case "record_video_note": return RECORDVIDEONOTE; case "record_audio": - return RECORDAUDIO; + case "record_voice": + return RECORDVOICE; case "upload_photo": return UPLOADPHOTO; case "upload_video": @@ -49,7 +59,8 @@ public enum ActionType { case "upload_video_note": return UPLOADVIDEONOTE; case "upload_audio": - return UPLOADAUDIO; + case "upload_voice": + return UPLOADVOICE; case "upload_document": return UPLOADDOCUMENT; case "find_location": 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 4f2fef63..f5898f6a 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/CopyMessage.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/CopyMessage.java @@ -25,8 +25,10 @@ import java.util.List; /** * @author Ruben Bermudez * @version 1.0 - * Use this method to copy messages of any kind. The method is analogous to the method forwardMessages, - * but the copied message doesn't have a link to the original message. + * Use this method to copy messages of any kind. + * Service messages and invoice messages can't be copied. + * + * The method is analogous to the method forwardMessage, but the copied message doesn't have a link to the original message. * Returns the MessageId of the sent message on success. */ @SuppressWarnings("unused") @@ -138,7 +140,7 @@ public class CopyMessage extends BotApiMethod { @Override public void validate() throws TelegramApiValidationException { - if (chatId == null) { + if (chatId == null || chatId.isEmpty()) { throw new TelegramApiValidationException("ChatId parameter can't be empty", this); } if (fromChatId == null) { 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 dfb76e4e..a43f72fe 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 @@ -21,7 +21,10 @@ import java.io.IOException; /** * @author Ruben Bermudez * @version 1.0 - * Use this method to send text messages. On success, the sent Message is returned. + * Use this method to forward messages of any kind. + * Service messages can't be forwarded. + * + * On success, the sent Message is returned. */ @EqualsAndHashCode(callSuper = false) @Getter diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/StopMessageLiveLocation.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/StopMessageLiveLocation.java index bbddfcb1..0144b135 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/StopMessageLiveLocation.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/StopMessageLiveLocation.java @@ -93,7 +93,7 @@ public class StopMessageLiveLocation extends BotApiMethod { @Override public void validate() throws TelegramApiValidationException { if (inlineMessageId == null) { - if (chatId == null) { + if (chatId == null || chatId.isEmpty()) { throw new TelegramApiValidationException("ChatId parameter can't be empty if inlineMessageId is not present", this); } if (messageId == null) { diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/games/GetGameHighScores.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/games/GetGameHighScores.java index ea117134..0d8e32d1 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/games/GetGameHighScores.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/games/GetGameHighScores.java @@ -102,7 +102,7 @@ public class GetGameHighScores extends BotApiMethod> { throw new TelegramApiValidationException("UserId parameter can't be empty", this); } if (inlineMessageId == null) { - if (chatId == null) { + if (chatId == null || chatId.isEmpty()) { throw new TelegramApiValidationException("ChatId parameter can't be empty if inlineMessageId is not present", this); } if (messageId == null) { diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/games/SetGameScore.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/games/SetGameScore.java index 3421a335..d1733b4b 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/games/SetGameScore.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/games/SetGameScore.java @@ -124,7 +124,7 @@ public class SetGameScore extends BotApiMethod { throw new TelegramApiValidationException("Score parameter can't be empty", this); } if (inlineMessageId == null) { - if (chatId == null) { + if (chatId == null || chatId.isEmpty()) { throw new TelegramApiValidationException("ChatId parameter can't be empty if inlineMessageId is not present", this); } if (messageId == null) { diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/DeleteChatPhoto.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/DeleteChatPhoto.java index 4b17550c..c897b3ba 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/DeleteChatPhoto.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/DeleteChatPhoto.java @@ -64,7 +64,7 @@ public class DeleteChatPhoto extends BotApiMethod { @Override public void validate() throws TelegramApiValidationException { - if (chatId == null) { + if (chatId == null || chatId.isEmpty()) { throw new TelegramApiValidationException("ChatId can't be null", this); } } 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 6c3af88f..e48cb442 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 @@ -137,7 +137,7 @@ public class SendPoll extends BotApiMethod { @Override public void validate() throws TelegramApiValidationException { - if (chatId == null) { + if (chatId == null || chatId.isEmpty()) { throw new TelegramApiValidationException("ChatId parameter can't be empty", this); } if (question == null || question.isEmpty()) { diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/polls/StopPoll.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/polls/StopPoll.java index 457c852b..bb93ccf2 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/polls/StopPoll.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/polls/StopPoll.java @@ -67,7 +67,7 @@ public class StopPoll extends BotApiMethod { @Override public void validate() throws TelegramApiValidationException { - if (chatId == null) { + if (chatId == null || chatId.isEmpty()) { throw new TelegramApiValidationException("ChatId parameter can't be empty", this); } if (messageId == null || messageId == 0) { 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 6d847a68..2e078eaa 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 @@ -111,7 +111,7 @@ public class SendAnimation extends PartialBotApiMethod { @Override public void validate() throws TelegramApiValidationException { - if (chatId == null) { + if (chatId == null || chatId.isEmpty()) { throw new TelegramApiValidationException("ChatId parameter can't be empty", this); } 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 3517fdda..1cc8fd0a 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 @@ -107,7 +107,7 @@ public class SendAudio extends PartialBotApiMethod { @Override public void validate() throws TelegramApiValidationException { - if (chatId == null) { + if (chatId == null || chatId.isEmpty()) { throw new TelegramApiValidationException("ChatId parameter can't be empty", this); } 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 f1eef0b3..a821cd65 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 @@ -85,7 +85,7 @@ public class SendChatAction extends BotApiMethod { @Override public void validate() throws TelegramApiValidationException { - if (chatId == null) { + if (chatId == null || chatId.isEmpty()) { throw new TelegramApiValidationException("ChatId parameter can't be empty", this); } if (action == null) { 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 a81b2000..352672ee 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 @@ -99,7 +99,7 @@ public class SendContact extends BotApiMethod { @Override public void validate() throws TelegramApiValidationException { - if (chatId == null) { + if (chatId == null || chatId.isEmpty()) { throw new TelegramApiValidationException("ChatId parameter can't be empty", this); } if (phoneNumber == null) { 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 fbc86a1e..967a08be 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 @@ -103,7 +103,7 @@ public class SendDice extends BotApiMethod { @Override public void validate() throws TelegramApiValidationException { - if (chatId == null) { + if (chatId == null || chatId.isEmpty()) { throw new TelegramApiValidationException("ChatId parameter can't be empty", this); } if (emoji != null && !VALIDEMOJIS.contains(emoji)) { 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 c3ca2343..77c8c135 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 @@ -99,7 +99,7 @@ public class SendDocument extends PartialBotApiMethod { @Override public void validate() throws TelegramApiValidationException { - if (chatId == null) { + if (chatId == null || chatId.isEmpty()) { throw new TelegramApiValidationException("ChatId parameter can't be empty", this); } 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 898fbc09..08dce18c 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 @@ -105,7 +105,7 @@ public class SendGame extends BotApiMethod { @Override public void validate() throws TelegramApiValidationException { - if (chatId == null) { + if (chatId == null || chatId.isEmpty()) { throw new TelegramApiValidationException("ChatId parameter can't be empty", this); } if (gameShortName == null || gameShortName.isEmpty()) { diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendInvoice.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendInvoice.java index 0e0da430..d47d07f3 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendInvoice.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendInvoice.java @@ -2,6 +2,7 @@ package org.telegram.telegrambots.meta.api.methods.send; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.type.TypeReference; +import com.google.common.base.Strings; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.EqualsAndHashCode; @@ -10,6 +11,7 @@ import lombok.NoArgsConstructor; import lombok.NonNull; import lombok.RequiredArgsConstructor; import lombok.Setter; +import lombok.Singular; import lombok.ToString; import org.telegram.telegrambots.meta.api.methods.BotApiMethod; import org.telegram.telegrambots.meta.api.objects.ApiResponse; @@ -62,10 +64,12 @@ public class SendInvoice extends BotApiMethod { private static final String REPLY_MARKUP_FIELD = "reply_markup"; private static final String PROVIDER_DATA_FIELD = "provider_data"; private static final String ALLOWSENDINGWITHOUTREPLY_FIELD = "allow_sending_without_reply"; + private static final String MAXTIPAMOUNT_FIELD = "max_tip_amount"; + private static final String SUGGESTEDTIPAMOUNTS_FIELD = "suggested_tip_amounts"; @JsonProperty(CHATID_FIELD) @NonNull - private Integer chatId; ///< Unique identifier for the target private chat + private String chatId; ///< Unique identifier for the target chat or username of the target channel (in the format @channelusername) @JsonProperty(TITLE_FIELD) @NonNull private String title; ///< Product name @@ -78,14 +82,22 @@ public class SendInvoice extends BotApiMethod { @JsonProperty(PROVIDER_TOKEN_FIELD) @NonNull private String providerToken; ///< Payments provider token, obtained via Botfather + /** + * Optional + * Unique deep-linking parameter. If left empty, forwarded copies of the sent message will have a Pay button, + * allowing multiple users to pay directly from the forwarded message, using the same invoice. + * If non-empty, forwarded copies of the sent message will have a URL button with a deep link to the bot (instead of a Pay button), + * with the value used as the start parameter + */ @JsonProperty(START_PARAMETER_FIELD) @NonNull - private String startParameter; ///< Unique deep-linking parameter that can be used to generate this invoice when used as a start parameter. + private String startParameter; @JsonProperty(CURRENCY_FIELD) @NonNull private String currency; ///< 3-letter ISO 4217 currency code @JsonProperty(PRICES_FIELD) @NonNull + @Singular private List prices; ///< Price breakdown, a list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.) /** * Optional. URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service. @@ -134,6 +146,21 @@ public class SendInvoice extends BotApiMethod { private String providerData; @JsonProperty(ALLOWSENDINGWITHOUTREPLY_FIELD) private Boolean allowSendingWithoutReply; ///< Optional Pass True, if the message should be sent even if the specified replied-to message is not found + /** + * The maximum accepted amount for tips in the smallest units of the currency (integer, not float/double). + * For example, for a maximum tip of US$ 1.45 pass max_tip_amount = 145. + * Defaults to 0 + */ + @JsonProperty(MAXTIPAMOUNT_FIELD) + private Integer maxTipAmount; + /** + * A JSON-serialized array of suggested amounts of tips in the smallest units of the currency (integer, not float/double). + * At most 4 suggested tip amounts can be specified. + * The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed max_tip_amount. + */ + @JsonProperty(SUGGESTEDTIPAMOUNTS_FIELD) + @Singular + private List suggestedTipAmounts; @Override public String getMethod() { @@ -157,25 +184,25 @@ public class SendInvoice extends BotApiMethod { @Override public void validate() throws TelegramApiValidationException { - if (chatId == null) { + if (Strings.isNullOrEmpty(chatId)) { throw new TelegramApiValidationException("ChatId parameter can't be empty", this); } - if (title == null || title.isEmpty()) { + if (Strings.isNullOrEmpty(title)) { throw new TelegramApiValidationException("Title parameter can't be empty", this); } - if (description == null || description.isEmpty()) { + if (Strings.isNullOrEmpty(description)) { throw new TelegramApiValidationException("Description parameter can't be empty", this); } - if (payload == null || payload.isEmpty()) { + if (Strings.isNullOrEmpty(payload)) { throw new TelegramApiValidationException("Payload parameter can't be empty", this); } - if (providerToken == null || providerToken.isEmpty()) { + if (Strings.isNullOrEmpty(providerToken)) { throw new TelegramApiValidationException("ProviderToken parameter can't be empty", this); } - if (startParameter == null || startParameter.isEmpty()) { + if (Strings.isNullOrEmpty(startParameter)) { throw new TelegramApiValidationException("StartParameter parameter can't be empty", this); } - if (currency == null || currency.isEmpty()) { + if (Strings.isNullOrEmpty(currency)) { throw new TelegramApiValidationException("Currency parameter can't be empty", this); } if (prices == null || prices.isEmpty()) { @@ -185,6 +212,9 @@ public class SendInvoice extends BotApiMethod { price.validate(); } } + if (suggestedTipAmounts != null && !suggestedTipAmounts.isEmpty() && suggestedTipAmounts.size() > 4) { + throw new TelegramApiValidationException("No more that 4 suggested tips allowed", this); + } if (replyMarkup != null) { replyMarkup.validate(); } 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 29f621fd..e00372c2 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 @@ -118,7 +118,7 @@ public class SendLocation extends BotApiMethod { @Override public void validate() throws TelegramApiValidationException { - if (chatId == null) { + if (chatId == null || chatId.isEmpty()) { throw new TelegramApiValidationException("ChatId parameter can't be empty", this); } if (latitude == null) { 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 25494265..4720efd6 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 @@ -90,7 +90,7 @@ public class SendMediaGroup extends PartialBotApiMethod> { @Override public void validate() throws TelegramApiValidationException { - if (chatId == null) { + if (chatId == null || chatId.isEmpty()) { throw new TelegramApiValidationException("ChatId parameter can't be empty", this); } 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 337c22e0..b9cfda50 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 @@ -135,7 +135,7 @@ public class SendMessage extends BotApiMethod { @Override public void validate() throws TelegramApiValidationException { - if (chatId == null) { + if (chatId == null || chatId.isEmpty()) { throw new TelegramApiValidationException("ChatId parameter can't be empty", this); } if (text == null || text.isEmpty()) { 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 6a643f05..3dd4a91f 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 @@ -93,7 +93,7 @@ public class SendPhoto extends PartialBotApiMethod { @Override public void validate() throws TelegramApiValidationException { - if (chatId == null) { + if (chatId == null || chatId.isEmpty()) { throw new TelegramApiValidationException("ChatId parameter can't be empty", this); } 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 9796bc1e..591517ff 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 @@ -81,7 +81,7 @@ public class SendSticker extends PartialBotApiMethod { @Override public void validate() throws TelegramApiValidationException { - if (chatId == null) { + if (chatId == null || chatId.isEmpty()) { throw new TelegramApiValidationException("ChatId parameter can't be empty", this); } 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 574166b4..61711a78 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 @@ -113,7 +113,7 @@ public class SendVenue extends BotApiMethod { @Override public void validate() throws TelegramApiValidationException { - if (chatId == null) { + if (chatId == null || chatId.isEmpty()) { throw new TelegramApiValidationException("ChatId parameter can't be empty", this); } if (longitude == null) { 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 4aa91dab..abc90b05 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 @@ -106,7 +106,7 @@ public class SendVideo extends PartialBotApiMethod { @Override public void validate() throws TelegramApiValidationException { - if (chatId == null) { + if (chatId == null || chatId.isEmpty()) { throw new TelegramApiValidationException("ChatId parameter can't be empty", this); } 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 0fba958d..7839b074 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 @@ -92,7 +92,7 @@ public class SendVideoNote extends PartialBotApiMethod { @Override public void validate() throws TelegramApiValidationException { - if (chatId == null) { + if (chatId == null || chatId.isEmpty()) { throw new TelegramApiValidationException("ChatId parameter can't be empty", this); } 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 61347bbd..cea1a7c6 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 @@ -91,7 +91,7 @@ public class SendVoice extends PartialBotApiMethod { @Override public void validate() throws TelegramApiValidationException { - if (chatId == null) { + if (chatId == null || chatId.isEmpty()) { throw new TelegramApiValidationException("ChatId parameter can't be empty", 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 5a482899..1c77e3a3 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 @@ -79,7 +79,7 @@ public class DeleteMessage extends BotApiMethod { @Override public void validate() throws TelegramApiValidationException { - if (chatId == null) { + if (chatId == null || chatId.isEmpty()) { throw new TelegramApiValidationException("ChatId parameter can't be empty", this); } if (messageId == null) { diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageCaption.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageCaption.java index 0ffb267c..14e4c504 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageCaption.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageCaption.java @@ -106,7 +106,7 @@ public class EditMessageCaption extends BotApiMethod { @Override public void validate() throws TelegramApiValidationException { if (inlineMessageId == null) { - if (chatId == null) { + if (chatId == null || chatId.isEmpty()) { throw new TelegramApiValidationException("ChatId parameter can't be empty if inlineMessageId is not present", this); } if (messageId == null) { diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageLiveLocation.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageLiveLocation.java index 80bb4b39..e91006c6 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageLiveLocation.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageLiveLocation.java @@ -127,7 +127,7 @@ public class EditMessageLiveLocation extends BotApiMethod { @Override public void validate() throws TelegramApiValidationException { if (inlineMessageId == null) { - if (chatId == null) { + if (chatId == null || chatId.isEmpty()) { throw new TelegramApiValidationException("ChatId parameter can't be empty if inlineMessageId is not present", this); } if (messageId == null) { diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageMedia.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageMedia.java index 1bd2348d..c6ad262c 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageMedia.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageMedia.java @@ -104,7 +104,7 @@ public class EditMessageMedia extends PartialBotApiMethod { @Override public void validate() throws TelegramApiValidationException { if (inlineMessageId == null) { - if (chatId == null) { + if (chatId == null || chatId.isEmpty()) { throw new TelegramApiValidationException("ChatId parameter can't be empty if inlineMessageId is not present", this); } if (messageId == null) { diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageReplyMarkup.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageReplyMarkup.java index ffa5bc0a..fb26f6c3 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageReplyMarkup.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageReplyMarkup.java @@ -94,7 +94,7 @@ public class EditMessageReplyMarkup extends BotApiMethod { @Override public void validate() throws TelegramApiValidationException { if (inlineMessageId == null) { - if (chatId == null) { + if (chatId == null || chatId.isEmpty()) { throw new TelegramApiValidationException("ChatId parameter can't be empty if inlineMessageId is not present", this); } if (messageId == null) { diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageText.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageText.java index a268347a..f3a6ea06 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageText.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageText.java @@ -144,7 +144,7 @@ public class EditMessageText extends BotApiMethod { @Override public void validate() throws TelegramApiValidationException { if (inlineMessageId == null) { - if (chatId == null) { + if (chatId == null || chatId.isEmpty()) { throw new TelegramApiValidationException("ChatId parameter can't be empty if inlineMessageId is not present", this); } if (messageId == null) { diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Message.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Message.java index 3d4566e4..df518fdf 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Message.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Message.java @@ -19,6 +19,7 @@ import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMa import org.telegram.telegrambots.meta.api.objects.stickers.Sticker; import org.telegram.telegrambots.meta.api.objects.voicechat.VoiceChatEnded; import org.telegram.telegrambots.meta.api.objects.voicechat.VoiceChatParticipantsInvited; +import org.telegram.telegrambots.meta.api.objects.voicechat.VoiceChatScheduled; import org.telegram.telegrambots.meta.api.objects.voicechat.VoiceChatStarted; import java.util.ArrayList; @@ -91,6 +92,7 @@ public class Message implements BotApiObject { private static final String VOICECHATSTARTED_FIELD = "voice_chat_started"; private static final String VOICECHATENDED_FIELD = "voice_chat_ended"; private static final String VOICECHATPARTICIPANTSINVITED_FIELD = "voice_chat_participants_invited"; + private static final String VOICECHATSCHEDULED_FIELD = "voice_chat_scheduled"; @JsonProperty(MESSAGEID_FIELD) private Integer messageId; ///< Integer Unique message identifier @@ -266,7 +268,8 @@ public class Message implements BotApiObject { private VoiceChatEnded voiceChatEnded; ///< Optional. Service message: voice chat ended @JsonProperty(VOICECHATPARTICIPANTSINVITED_FIELD) private VoiceChatParticipantsInvited voiceChatParticipantsInvited; ///< Optional. Service message: new members invited to a voice chat - + @JsonProperty(VOICECHATSCHEDULED_FIELD) + private VoiceChatScheduled voiceChatScheduled; ///< Optional. Service message: voice chat scheduled public List getEntities() { if (entities != null) { @@ -445,6 +448,11 @@ public class Message implements BotApiObject { return voiceChatEnded != null; } + @JsonIgnore + private boolean hasVoiceChatScheduled() { + return voiceChatScheduled != null; + } + @JsonIgnore private boolean hasVoiceChatParticipantsInvited() { return voiceChatParticipantsInvited != null; 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 8ef0bb7e..ff96ed46 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 @@ -34,6 +34,7 @@ public class InlineQuery implements BotApiObject { private static final String LOCATION_FIELD = "location"; private static final String QUERY_FIELD = "query"; private static final String OFFSET_FIELD = "offset"; + private static final String CHATTYPE_FIELD = "chat_type"; @JsonProperty(ID_FIELD) @NonNull @@ -49,5 +50,13 @@ public class InlineQuery implements BotApiObject { @JsonProperty(OFFSET_FIELD) @NonNull private String offset; ///< Offset of the results to be returned, can be controlled by the bot + /** + * Optional. Type of the chat, from which the inline query was sent. + * Can be either “sender” for a private chat with the inline query sender, “private”, “group”, “supergroup”, or “channel”. + * The chat type should be always known for requests sent from official clients and most third-party clients, + * unless the request was sent from a secret chat + */ + @JsonProperty(CHATTYPE_FIELD) + private String chatType; } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/inputmessagecontent/InputInvoiceMessageContent.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/inputmessagecontent/InputInvoiceMessageContent.java new file mode 100644 index 00000000..cc614769 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/inputmessagecontent/InputInvoiceMessageContent.java @@ -0,0 +1,165 @@ +package org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.google.common.base.Strings; +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.Singular; +import lombok.ToString; +import org.telegram.telegrambots.meta.api.objects.payments.LabeledPrice; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +import java.util.List; + +/** + * @author Ruben Bermudez + * @version 1.0 + * Represents the content of a text message to be sent as the result of an inline query. + */ +@JsonDeserialize +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@RequiredArgsConstructor +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class InputInvoiceMessageContent implements InputMessageContent { + + private static final String TITLE_FIELD = "title"; + private static final String DESCRIPTION_FIELD = "description"; + private static final String PAYLOAD_FIELD = "payload"; + private static final String PROVIDERTOKEN_FIELD = "provider_token"; + private static final String CURRENCY_FIELD = "currency"; + private static final String PRICES_FIELD = "prices"; + private static final String MAXTIPAMOUNT_FIELD = "max_tip_amount"; + private static final String SUGGESTEDTIPAMOUNTS_FIELD = "suggested_tip_amounts"; + private static final String PROVIDERDATA_FIELD = "provider_data"; + private static final String PHOTOURL_FIELD = "photo_url"; + private static final String PHOTOSIZE_FIELD = "photo_size"; + private static final String PHOTOWIDTH_FIELD = "photo_width"; + private static final String PHOTOHEIGHT_FIELD = "photo_height"; + private static final String NEEDNAME_FIELD = "need_name"; + private static final String NEEDPHONENUMBER_FIELD = "need_phone_number"; + private static final String NEEDEMAIL_FIELD = "need_email"; + private static final String NEEDSHIPPINGADDRESS_FIELD = "need_shipping_address"; + private static final String SENDPHONENUMBERTOPROVIDER_FIELD = "send_phone_number_to_provider"; + private static final String SENDEMAILTOPROVIDER_FIELD = "send_email_to_provider"; + private static final String ISFLEXIBLE_FIELD = "is_flexible"; + + @JsonProperty(TITLE_FIELD) + @NonNull + private String title; ///< Product name, 1-32 characters + @JsonProperty(DESCRIPTION_FIELD) + @NonNull + private String description; ///< Product description, 1-255 characters + /** + * Bot-defined invoice payload, 1-128 bytes. + * This will not be displayed to the user, use for your internal processes. + */ + @JsonProperty(PAYLOAD_FIELD) + @NonNull + private String payload; + @JsonProperty(PROVIDERTOKEN_FIELD) + @NonNull + private String providerToken; ///< Payment provider token, obtained via Botfather + @JsonProperty(CURRENCY_FIELD) + @NonNull + private String currency; ///< Three-letter ISO 4217 currency code, see more on currencies + /** + * Price breakdown, a JSON-serialized list of components + * (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.) + */ + @JsonProperty(PRICES_FIELD) + @NonNull + @Singular + private List prices; + /** + * Optional. + * The maximum accepted amount for tips in the smallest units of the currency (integer, not float/double). + * For example, for a maximum tip of US$ 1.45 pass max_tip_amount = 145. + * Defaults to 0 + */ + @JsonProperty(MAXTIPAMOUNT_FIELD) + private Integer maxTipAmount; + /** + * Optional. + * A JSON-serialized array of suggested amounts of tip in the smallest units of the currency (integer, not float/double). + * At most 4 suggested tip amounts can be specified. + * The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed max_tip_amount. + */ + @JsonProperty(SUGGESTEDTIPAMOUNTS_FIELD) + @Singular + private List suggestedTipAmounts; + /** + * Optional. + * A JSON-serialized object for data about the invoice, which will be shared with the payment provider. + * A detailed description of the required fields should be provided by the payment provider. + */ + @JsonProperty(PROVIDERDATA_FIELD) + private String providerData; + /** + * Optional. + * URL of the product photo for the invoice. + * Can be a photo of the goods or a marketing image for a service. + * People like it better when they see what they are paying for. + */ + @JsonProperty(PHOTOURL_FIELD) + private String photoUrl; + @JsonProperty(PHOTOSIZE_FIELD) + private Integer photoSize; ///< Optional. Photo size + @JsonProperty(PHOTOWIDTH_FIELD) + private Integer photoWidth; ///< Optional. Photo width + @JsonProperty(PHOTOHEIGHT_FIELD) + private Integer photoHeight; ///< Optional. Photo height + @JsonProperty(NEEDNAME_FIELD) + private Boolean needName; ///< Optional. Pass True, if you require the user's full name to complete the order + @JsonProperty(NEEDPHONENUMBER_FIELD) + private Boolean needPhoneNumber; ///< Optional. Pass True, if you require the user's phone number to complete the order + @JsonProperty(NEEDEMAIL_FIELD) + private Boolean needEmail; ///< Optional. Pass True, if you require the user's email address to complete the order + @JsonProperty(NEEDSHIPPINGADDRESS_FIELD) + private Boolean needShippingAddress; ///< Optional. Pass True, if you require the user's shipping address to complete the order + @JsonProperty(SENDPHONENUMBERTOPROVIDER_FIELD) + private Boolean sendPhoneNumberToProvider; ///< Optional. Pass True, if user's phone number should be sent to provider + @JsonProperty(SENDEMAILTOPROVIDER_FIELD) + private Boolean sendEmailToProvider; ///< Optional. Pass True, if user's email address should be sent to provider + @JsonProperty(ISFLEXIBLE_FIELD) + private Boolean isFlexible; ///< Optional. Pass True, if the final price depends on the shipping method + + @Override + public void validate() throws TelegramApiValidationException { + if (Strings.isNullOrEmpty(title) || title.length() > 32) { + throw new TelegramApiValidationException("Title parameter must be between 1 and 32 characters", this); + } + if (Strings.isNullOrEmpty(description) || description.length() > 32) { + throw new TelegramApiValidationException("Description parameter must be between 1 and 255 characters", this); + } + if (Strings.isNullOrEmpty(payload) || payload.length() > 32) { + throw new TelegramApiValidationException("Payload parameter must be between 1 and 128 characters", this); + } + if (Strings.isNullOrEmpty(providerToken)) { + throw new TelegramApiValidationException("ProviderToken parameter must not be empty", this); + } + if (Strings.isNullOrEmpty(currency)) { + throw new TelegramApiValidationException("Currency parameter must not be empty", this); + } + if (prices == null || prices.isEmpty()) { + throw new TelegramApiValidationException("Prices parameter must not be empty", this); + } + for (LabeledPrice price : prices) { + price.validate(); + } + if (suggestedTipAmounts != null && !suggestedTipAmounts.isEmpty() && suggestedTipAmounts.size() > 4) { + throw new TelegramApiValidationException("Only up to 4 suggested tip amounts are allowed", this); + } + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/inputmessagecontent/serialization/InputMessageContentDeserializer.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/inputmessagecontent/serialization/InputMessageContentDeserializer.java index 5d684f68..5ca9b51e 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/inputmessagecontent/serialization/InputMessageContentDeserializer.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/inputmessagecontent/serialization/InputMessageContentDeserializer.java @@ -52,6 +52,11 @@ public class InputMessageContentDeserializer extends StdDeserializer(){}); } + if (node.has("provider_token")) { + return objectMapper.readValue(node.toString(), + new com.fasterxml.jackson.core.type.TypeReference(){}); + } + return null; } } 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 488f8b87..0f55d7ca 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 @@ -34,8 +34,11 @@ public class Invoice implements BotApiObject { private String title; ///< Product name @JsonProperty(DESCRIPTION_FIELD) private String description; ///< Product description + /** + * Unique bot deep-linking parameter that can be used to generate this invoice; may be empty + */ @JsonProperty(START_PARAMETER_FIELD) - private String startParameter; ///< Unique bot deep-linking parameter for generation of this invoice + private String startParameter; @JsonProperty(CURRENCY_FIELD) private String currency; ///< Three-letter ISO 4217 currency code /** diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/payments/LabeledPrice.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/payments/LabeledPrice.java index a193d5b8..904bde8e 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/payments/LabeledPrice.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/payments/LabeledPrice.java @@ -2,9 +2,11 @@ package org.telegram.telegrambots.meta.api.objects.payments; 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; @@ -22,17 +24,20 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; @ToString @NoArgsConstructor @AllArgsConstructor +@Builder public class LabeledPrice implements Validable, BotApiObject { private static final String LABEL_FIELD = "label"; private static final String AMOUNT_FIELD = "amount"; @JsonProperty(LABEL_FIELD) + @NonNull private String label; ///< Portion label /** * Price of the product in the smallest units of the currency (integer, not float/double). * For example, for a price of US$ 1.45 pass amount = 145. */ @JsonProperty(AMOUNT_FIELD) + @NonNull private Integer amount; @Override diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/voicechat/VoiceChatScheduled.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/voicechat/VoiceChatScheduled.java new file mode 100644 index 00000000..83de59e1 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/voicechat/VoiceChatScheduled.java @@ -0,0 +1,31 @@ +package org.telegram.telegrambots.meta.api.objects.voicechat; + +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 org.telegram.telegrambots.meta.api.interfaces.BotApiObject; + +/** + * @author Ruben Bermudez + * @version 5.2 + * + * This object represents a service message about a voice chat scheduled in the chat. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +public class VoiceChatScheduled implements BotApiObject { + private static final String STARTDATE_FIELD = "start_date"; + + @JsonProperty(STARTDATE_FIELD) + @NonNull + private Integer startDate; ///< Point in time (Unix timestamp) when the voice chat is supposed to be started by a chat administrator +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/exceptions/TelegramApiRequestException.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/exceptions/TelegramApiRequestException.java index 53280d10..d2f69e60 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/exceptions/TelegramApiRequestException.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/exceptions/TelegramApiRequestException.java @@ -92,16 +92,16 @@ public class TelegramApiRequestException extends TelegramApiException { @Override public String getMessage() { if (apiResponse == null) { - return super.toString(); + return super.getMessage(); } else if (errorCode == null) { - return super.toString() + ": " + apiResponse; + return super.getMessage() + ": " + apiResponse; } else { - return super.toString() + ": [" + errorCode + "] " + apiResponse; + return super.getMessage() + ": [" + errorCode + "] " + apiResponse; } } /** - * Just left as backward compatibility if anybody used this in version 5.1.1 or older. + * Just left as backward compatibility if anybody used this in version 5.2.0 or older. * * @return the getMessage string */ diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/TestUtils.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/TestUtils.java new file mode 100644 index 00000000..18407ffc --- /dev/null +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/TestUtils.java @@ -0,0 +1,19 @@ +package org.telegram.telegrambots.meta; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.util.Arrays; + +/** + * @author Ruben Bermudez + * @version 1.0 + */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class TestUtils { + public static String getTextOfSize(int n) { + char[] text = new char[33]; + Arrays.fill(text, 'A'); + return new String(text); + } +} diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/send/SendInvoiceTest.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/send/SendInvoiceTest.java new file mode 100644 index 00000000..39e497fd --- /dev/null +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/send/SendInvoiceTest.java @@ -0,0 +1,138 @@ +package org.telegram.telegrambots.meta.api.methods.send; + +import org.junit.jupiter.api.Test; +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.replykeyboard.buttons.InlineKeyboardButton; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +/** + * @author Ruben Bermudez + * @version 5.2 + */ +public class SendInvoiceTest { + @Test + public void validObjectMustNotThrow() { + SendInvoice sendInvoice = createSendInvoiceObject(); + assertDoesNotThrow(sendInvoice::validate); + sendInvoice.setSuggestedTipAmounts(new ArrayList<>()); + assertDoesNotThrow(sendInvoice::validate); + } + + @Test + public void chatIdCantBeEmpty() { + SendInvoice sendInvoice = createSendInvoiceObject(); + sendInvoice.setChatId(""); + Throwable thrown = assertThrows(TelegramApiValidationException.class, sendInvoice::validate); + assertEquals("ChatId parameter can't be empty", thrown.getMessage()); + } + + @Test + public void titleCantBeEmpty() { + SendInvoice sendInvoice = createSendInvoiceObject(); + sendInvoice.setTitle(""); + Throwable thrown = assertThrows(TelegramApiValidationException.class, sendInvoice::validate); + assertEquals("Title parameter can't be empty", thrown.getMessage()); + } + + @Test + public void descriptionCantBeEmpty() { + SendInvoice sendInvoice = createSendInvoiceObject(); + sendInvoice.setDescription(""); + Throwable thrown = assertThrows(TelegramApiValidationException.class, sendInvoice::validate); + assertEquals("Description parameter can't be empty", thrown.getMessage()); + } + + @Test + public void payloadCantBeEmpty() { + SendInvoice sendInvoice = createSendInvoiceObject(); + sendInvoice.setPayload(""); + Throwable thrown = assertThrows(TelegramApiValidationException.class, sendInvoice::validate); + assertEquals("Payload parameter can't be empty", thrown.getMessage()); + } + + @Test + public void providerTokenCantBeEmpty() { + SendInvoice sendInvoice = createSendInvoiceObject(); + sendInvoice.setProviderToken(""); + Throwable thrown = assertThrows(TelegramApiValidationException.class, sendInvoice::validate); + assertEquals("ProviderToken parameter can't be empty", thrown.getMessage()); + } + + @Test + public void startParameterCantBeEmpty() { + SendInvoice sendInvoice = createSendInvoiceObject(); + sendInvoice.setStartParameter(""); + Throwable thrown = assertThrows(TelegramApiValidationException.class, sendInvoice::validate); + assertEquals("StartParameter parameter can't be empty", thrown.getMessage()); + } + + @Test + public void currencyCantBeEmpty() { + SendInvoice sendInvoice = createSendInvoiceObject(); + sendInvoice.setCurrency(""); + Throwable thrown = assertThrows(TelegramApiValidationException.class, sendInvoice::validate); + assertEquals("Currency parameter can't be empty", thrown.getMessage()); + } + + @Test + public void pricesMustBeValidated() { + SendInvoice sendInvoice = createSendInvoiceObject(); + sendInvoice.setPrices(Collections.singletonList(LabeledPrice.builder().label("").amount(1).build())); + Throwable thrown = assertThrows(TelegramApiValidationException.class, sendInvoice::validate); + assertEquals("Label parameter can't be empty", thrown.getMessage()); + } + + @Test + public void pricesCantBeEmpty() { + SendInvoice sendInvoice = createSendInvoiceObject(); + sendInvoice.setPrices(new ArrayList<>()); + Throwable thrown = assertThrows(TelegramApiValidationException.class, sendInvoice::validate); + assertEquals("Prices parameter can't be empty", thrown.getMessage()); + sendInvoice.setPrices(Collections.singletonList(LabeledPrice.builder().label("").amount(1).build())); + thrown = assertThrows(TelegramApiValidationException.class, sendInvoice::validate); + assertEquals("Label parameter can't be empty", thrown.getMessage()); + } + + @Test + public void suggestedTipAmountsMustNotHaveMoreThan4Elements() { + SendInvoice sendInvoice = createSendInvoiceObject(); + sendInvoice.setSuggestedTipAmounts(Arrays.asList(1,2,3,4,5)); + Throwable thrown = assertThrows(TelegramApiValidationException.class, sendInvoice::validate); + assertEquals("No more that 4 suggested tips allowed", thrown.getMessage()); + } + + @Test + public void replyMarkupMustBeValidated() { + SendInvoice sendInvoice = createSendInvoiceObject(); + sendInvoice.setReplyMarkup(InlineKeyboardMarkup.builder().keyboardRow(Collections.singletonList(InlineKeyboardButton.builder().text("").build())).build()); + Throwable thrown = assertThrows(TelegramApiValidationException.class, sendInvoice::validate); + assertEquals("Text parameter can't be empty", thrown.getMessage()); + } + + private SendInvoice createSendInvoiceObject() { + return SendInvoice.builder() + .chatId("123456") + .title("Title") + .description("Description") + .payload("Payload") + .providerToken("ProviderToken") + .startParameter("StartParameter") + .currency("Currency") + .price(LabeledPrice.builder().label("Label").amount(1).build()) + .suggestedTipAmount(1) + .suggestedTipAmount(2) + .suggestedTipAmount(3) + .suggestedTipAmount(4) + .replyMarkup(InlineKeyboardMarkup.builder().keyboardRow(Collections.singletonList(InlineKeyboardButton.builder().text("Hello").build())).build()) + .build(); + } +} diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/inlinequery/inputmessagecontent/InputInvoiceMessageContentTest.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/inlinequery/inputmessagecontent/InputInvoiceMessageContentTest.java new file mode 100644 index 00000000..efab4eec --- /dev/null +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/inlinequery/inputmessagecontent/InputInvoiceMessageContentTest.java @@ -0,0 +1,133 @@ +package org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent; + +import org.junit.jupiter.api.Test; +import org.telegram.telegrambots.meta.TestUtils; +import org.telegram.telegrambots.meta.api.objects.payments.LabeledPrice; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +/** + * @author Ruben Bermudez + * @version 1.0 + */ +public class InputInvoiceMessageContentTest { + + @Test + public void validObjectMustNotThrow() { + InputInvoiceMessageContent sendInvoice = createSendInvoiceObject(); + assertDoesNotThrow(sendInvoice::validate); + } + + @Test + public void titleCantBeEmpty() { + InputInvoiceMessageContent sendInvoice = createSendInvoiceObject(); + sendInvoice.setTitle(""); + Throwable thrown = assertThrows(TelegramApiValidationException.class, sendInvoice::validate); + assertEquals("Title parameter must be between 1 and 32 characters", thrown.getMessage()); + } + + @Test + public void titleCantBeLongerThan32() { + InputInvoiceMessageContent sendInvoice = createSendInvoiceObject(); + sendInvoice.setTitle(TestUtils.getTextOfSize(33)); + Throwable thrown = assertThrows(TelegramApiValidationException.class, sendInvoice::validate); + assertEquals("Title parameter must be between 1 and 32 characters", thrown.getMessage()); + } + + @Test + public void descriptionCantBeEmpty() { + InputInvoiceMessageContent sendInvoice = createSendInvoiceObject(); + sendInvoice.setDescription(""); + Throwable thrown = assertThrows(TelegramApiValidationException.class, sendInvoice::validate); + assertEquals("Description parameter must be between 1 and 255 characters", thrown.getMessage()); + } + + @Test + public void descriptionCantBeLongerThan255() { + InputInvoiceMessageContent sendInvoice = createSendInvoiceObject(); + sendInvoice.setDescription(TestUtils.getTextOfSize(256)); + Throwable thrown = assertThrows(TelegramApiValidationException.class, sendInvoice::validate); + assertEquals("Description parameter must be between 1 and 255 characters", thrown.getMessage()); + } + + @Test + public void payloadCantBeEmpty() { + InputInvoiceMessageContent sendInvoice = createSendInvoiceObject(); + sendInvoice.setPayload(""); + Throwable thrown = assertThrows(TelegramApiValidationException.class, sendInvoice::validate); + assertEquals("Payload parameter must be between 1 and 128 characters", thrown.getMessage()); + } + + @Test + public void payloadCantBeLongerThan128() { + InputInvoiceMessageContent sendInvoice = createSendInvoiceObject(); + sendInvoice.setPayload(TestUtils.getTextOfSize(129)); + Throwable thrown = assertThrows(TelegramApiValidationException.class, sendInvoice::validate); + assertEquals("Payload parameter must be between 1 and 128 characters", thrown.getMessage()); + } + + @Test + public void providerTokenCantBeEmpty() { + InputInvoiceMessageContent sendInvoice = createSendInvoiceObject(); + sendInvoice.setProviderToken(""); + Throwable thrown = assertThrows(TelegramApiValidationException.class, sendInvoice::validate); + assertEquals("ProviderToken parameter must not be empty", thrown.getMessage()); + } + + @Test + public void currencyCantBeEmpty() { + InputInvoiceMessageContent sendInvoice = createSendInvoiceObject(); + sendInvoice.setCurrency(""); + Throwable thrown = assertThrows(TelegramApiValidationException.class, sendInvoice::validate); + assertEquals("Currency parameter must not be empty", thrown.getMessage()); + } + + @Test + public void pricesMustBeValidated() { + InputInvoiceMessageContent sendInvoice = createSendInvoiceObject(); + sendInvoice.setPrices(Collections.singletonList(LabeledPrice.builder().label("").amount(1).build())); + Throwable thrown = assertThrows(TelegramApiValidationException.class, sendInvoice::validate); + assertEquals("Label parameter can't be empty", thrown.getMessage()); + } + + @Test + public void pricesCantBeEmpty() { + InputInvoiceMessageContent sendInvoice = createSendInvoiceObject(); + sendInvoice.setPrices(new ArrayList<>()); + Throwable thrown = assertThrows(TelegramApiValidationException.class, sendInvoice::validate); + assertEquals("Prices parameter must not be empty", thrown.getMessage()); + sendInvoice.setPrices(Collections.singletonList(LabeledPrice.builder().label("").amount(1).build())); + thrown = assertThrows(TelegramApiValidationException.class, sendInvoice::validate); + assertEquals("Label parameter can't be empty", thrown.getMessage()); + } + + @Test + public void suggestedTipAmountsMustNotHaveMoreThan4Elements() { + InputInvoiceMessageContent sendInvoice = createSendInvoiceObject(); + sendInvoice.setSuggestedTipAmounts(Arrays.asList(1,2,3,4,5)); + Throwable thrown = assertThrows(TelegramApiValidationException.class, sendInvoice::validate); + assertEquals("Only up to 4 suggested tip amounts are allowed", thrown.getMessage()); + } + + private InputInvoiceMessageContent createSendInvoiceObject() { + return InputInvoiceMessageContent.builder() + .title("Title") + .description("Description") + .payload("Payload") + .providerToken("ProviderToken") + .currency("Currency") + .price(LabeledPrice.builder().label("Label").amount(1).build()) + .suggestedTipAmount(1) + .suggestedTipAmount(2) + .suggestedTipAmount(3) + .suggestedTipAmount(4) + .build(); + } +} diff --git a/telegrambots-spring-boot-starter/README.md b/telegrambots-spring-boot-starter/README.md index da25197c..7648a44f 100644 --- a/telegrambots-spring-boot-starter/README.md +++ b/telegrambots-spring-boot-starter/README.md @@ -18,14 +18,14 @@ Usage org.telegram telegrambots-spring-boot-starter - 5.1.1 + 5.2.0 ``` **Gradle** ```gradle - implementation 'org.telegram:telegrambots-spring-boot-starter:5.1.1' + implementation 'org.telegram:telegrambots-spring-boot-starter:5.2.0' ``` Motivation diff --git a/telegrambots-spring-boot-starter/pom.xml b/telegrambots-spring-boot-starter/pom.xml index c81f590b..a0b5a270 100644 --- a/telegrambots-spring-boot-starter/pom.xml +++ b/telegrambots-spring-boot-starter/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 5.1.1 + 5.2.0 telegrambots-spring-boot-starter @@ -70,7 +70,7 @@ UTF-8 UTF-8 - 5.1.1 + 5.2.0 2.4.5 1.6 diff --git a/telegrambots/pom.xml b/telegrambots/pom.xml index 6b0569db..8a0250c3 100644 --- a/telegrambots/pom.xml +++ b/telegrambots/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 5.1.1 + 5.2.0 telegrambots @@ -92,7 +92,7 @@ org.telegram telegrambots-meta - 5.1.1 + 5.2.0 org.projectlombok diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/RestApi.java b/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/RestApi.java index 622adecf..2a764778 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/RestApi.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/RestApi.java @@ -1,7 +1,6 @@ package org.telegram.telegrambots.updatesreceivers; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; import org.telegram.telegrambots.Constants; import org.telegram.telegrambots.meta.api.methods.BotApiMethod; import org.telegram.telegrambots.meta.api.objects.Update; @@ -24,9 +23,8 @@ import java.util.concurrent.ConcurrentHashMap; * Rest api to for webhook callback function */ @Path(Constants.WEBHOOK_URL_PATH) +@Slf4j public class RestApi { - private static final Logger log = LoggerFactory.getLogger(RestApi.class); - private final ConcurrentHashMap callbacks = new ConcurrentHashMap<>(); public RestApi() { diff --git a/telegrambots/src/test/java/org/telegram/telegrambots/test/BotApiMethodHelperFactory.java b/telegrambots/src/test/java/org/telegram/telegrambots/test/BotApiMethodHelperFactory.java index e993fe45..e3c7e364 100644 --- a/telegrambots/src/test/java/org/telegram/telegrambots/test/BotApiMethodHelperFactory.java +++ b/telegrambots/src/test/java/org/telegram/telegrambots/test/BotApiMethodHelperFactory.java @@ -71,7 +71,7 @@ public final class BotApiMethodHelperFactory { .text("Hithere") .replyToMessageId(12) .parseMode(ParseMode.HTML) - .replyMarkup(new ForceReplyKeyboard()) + .replyMarkup(ForceReplyKeyboard.builder().forceReply(true).build()) .build(); } @@ -362,12 +362,16 @@ public final class BotApiMethodHelperFactory { return SendInvoice .builder() - .chatId(12345) + .chatId("12345") .title("Random title") .description("Random description") .payload("Random Payload") .providerToken("Random provider token") .startParameter("STARTPARAM") + .maxTipAmount(100) + .suggestedTipAmount(10) + .suggestedTipAmount(50) + .suggestedTipAmount(75) .currency("EUR") .prices(prices) .build(); diff --git a/telegrambots/src/test/java/org/telegram/telegrambots/test/TelegramLongPollingBotTest.java b/telegrambots/src/test/java/org/telegram/telegrambots/test/TelegramLongPollingBotTest.java index fdef3699..b86fd390 100644 --- a/telegrambots/src/test/java/org/telegram/telegrambots/test/TelegramLongPollingBotTest.java +++ b/telegrambots/src/test/java/org/telegram/telegrambots/test/TelegramLongPollingBotTest.java @@ -22,7 +22,9 @@ public class TelegramLongPollingBotTest { TelegramLongPollingBot bot = Mockito.mock(TelegramLongPollingBot.class); Mockito.doCallRealMethod().when(bot).onUpdatesReceived(any()); Update update1 = new Update(); + update1.setUpdateId(1); Update update2 = new Update(); + update2.setUpdateId(2); bot.onUpdatesReceived(asList(update1, update2)); Mockito.verify(bot).onUpdateReceived(update1); Mockito.verify(bot).onUpdateReceived(update2); diff --git a/telegrambots/src/test/java/org/telegram/telegrambots/test/TestRestApi.java b/telegrambots/src/test/java/org/telegram/telegrambots/test/TestRestApi.java index c1d43a92..f9bf6523 100644 --- a/telegrambots/src/test/java/org/telegram/telegrambots/test/TestRestApi.java +++ b/telegrambots/src/test/java/org/telegram/telegrambots/test/TestRestApi.java @@ -113,7 +113,8 @@ public class TestRestApi extends JerseyTest { .request(MediaType.APPLICATION_JSON) .post(entity, AnswerInlineQuery.class); - assertEquals("{\"personal\":true,\"inline_query_id\":\"id\",\"results\":[{\"type\":\"article\",\"id\":\"0\",\"title\":\"Title\",\"input_message_content\":{\"message_text\":\"Text\",\"parse_mode\":\"Markdown\"},\"reply_markup\":{\"inline_keyboard\":[[{\"text\":\"Button1\",\"callback_data\":\"Callback\"}]]},\"url\":\"Url\",\"hide_url\":false,\"description\":\"Description\",\"thumb_url\":\"ThumbUrl\",\"thumb_width\":10,\"thumb_height\":20},{\"type\":\"photo\",\"id\":\"1\",\"photo_url\":\"PhotoUrl\",\"mime_type\":\"image/jpg\",\"photo_width\":10,\"photo_height\":20,\"thumb_url\":\"ThumbUrl\",\"title\":\"Title\",\"description\":\"Description\",\"caption\":\"Caption\",\"input_message_content\":{\"message_text\":\"Text\",\"parse_mode\":\"Markdown\"},\"reply_markup\":{\"inline_keyboard\":[[{\"text\":\"Button1\",\"callback_data\":\"Callback\"}]]}}],\"cache_time\":100,\"is_personal\":true,\"next_offset\":\"3\",\"switch_pm_text\":\"pmText\",\"switch_pm_parameter\":\"PmParameter\",\"method\":\"answerInlineQuery\"}", map(result)); + assertEquals("{\"inline_query_id\":\"id\",\"results\":[{\"type\":\"article\",\"id\":\"0\",\"title\":\"Title\",\"input_message_content\":{\"message_text\":\"Text\",\"parse_mode\":\"Markdown\"},\"reply_markup\":{\"inline_keyboard\":[[{\"text\":\"Button1\",\"callback_data\":\"Callback\"}]]},\"url\":\"Url\",\"hide_url\":false,\"description\":\"Description\",\"thumb_url\":\"ThumbUrl\",\"thumb_width\":10,\"thumb_height\":20},{\"type\":\"photo\",\"id\":\"1\",\"photo_url\":\"PhotoUrl\",\"mime_type\":\"image/jpg\",\"photo_width\":10,\"photo_height\":20,\"thumb_url\":\"ThumbUrl\",\"title\":\"Title\",\"description\":\"Description\",\"caption\":\"Caption\",\"input_message_content\":{\"message_text\":\"Text\",\"parse_mode\":\"Markdown\"},\"reply_markup\":{\"inline_keyboard\":[[{\"text\":\"Button1\",\"callback_data\":\"Callback\"}]]},\"caption_entities\":[]}],\"cache_time\":100,\"is_personal\":true,\"next_offset\":\"3\",\"switch_pm_text\":\"pmText\",\"switch_pm_parameter\":\"PmParameter\",\"method\":\"answerInlineQuery\"}", + map(result)); } @Test @@ -127,9 +128,8 @@ public class TestRestApi extends JerseyTest { .post(entity, EditMessageCaption.class); assertEquals("{\"chat_id\":\"ChatId\",\"message_id\":1,\"caption\":\"Caption\"," + - "\"reply_markup\":{\"inline_keyboard\":[[{" + - "\"text\":\"Button1\",\"callback_data\":\"Callback\"}]]},\"method\":" + - "\"editmessagecaption\"}", map(result)); + "\"reply_markup\":{\"inline_keyboard\":[[{\"text\":\"Button1\",\"callback_data\":\"Callback\"}]]}," + + "\"caption_entities\":[],\"method\":\"editmessagecaption\"}", map(result)); } @Test @@ -422,10 +422,10 @@ public class TestRestApi extends JerseyTest { .request(MediaType.APPLICATION_JSON) .post(entity, SendInvoice.class); - assertEquals("{\"chat_id\":12345,\"title\":\"Random title\",\"description\":\"Random description\"" + - ",\"payload\":\"Random Payload\",\"provider_token\":\"Random provider token\",\"start_parameter\":" + - "\"STARTPARAM\",\"currency\":\"EUR\",\"prices\":[{\"label\":\"LABEL\"," + - "\"amount\":1000}],\"method\":\"sendinvoice\"}", map(result)); + assertEquals("{\"chat_id\":\"12345\",\"title\":\"Random title\",\"description\":\"Random description\"," + + "\"payload\":\"Random Payload\",\"provider_token\":\"Random provider token\",\"start_parameter\":\"STARTPARAM\"," + + "\"currency\":\"EUR\",\"prices\":[{\"label\":\"LABEL\",\"amount\":1000}],\"max_tip_amount\":100," + + "\"suggested_tip_amounts\":[10,50,75],\"method\":\"sendinvoice\"}", map(result)); } private Update getUpdate() {