diff --git a/README.md b/README.md index 6d9be4c4..30a50ce2 100644 --- a/README.md +++ b/README.md @@ -27,18 +27,18 @@ Just import add the library to your project with one of these options: org.telegram telegrambots - 6.4.0 + 6.5.0 ``` 2. Using Gradle: ```gradle - implementation 'org.telegram:telegrambots:6.4.0' + implementation 'org.telegram:telegrambots:6.5.0' ``` - 3. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/6.4.0) - 4. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/6.4.0) + 3. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/6.5.0) + 4. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/6.5.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 138f2352..56ab80f3 100644 --- a/TelegramBots.wiki/Changelog.md +++ b/TelegramBots.wiki/Changelog.md @@ -1,3 +1,6 @@ +### 6.4.0 ### +1. Update Api version [6.5](https://core.telegram.org/bots/api-changelog#february-3-2023) + ### 6.4.0 ### 1. Update Api version [6.4](https://core.telegram.org/bots/api-changelog#december-30-2022) 2. Bug fixing: #1159 diff --git a/TelegramBots.wiki/Getting-Started.md b/TelegramBots.wiki/Getting-Started.md index 6f19de41..cab5cdb7 100644 --- a/TelegramBots.wiki/Getting-Started.md +++ b/TelegramBots.wiki/Getting-Started.md @@ -11,13 +11,13 @@ First you need to acquire the library and add it to your project. There are seve org.telegram telegrambots - 6.4.0 + 6.5.0 ``` * With **Gradle**: ```gradle - implementation 'org.telegram:telegrambots:6.4.0' + implementation 'org.telegram:telegrambots:6.5.0' ``` 2. Don't like the **Maven Central Repository**? It can also be grabbed from [Jitpack](https://jitpack.io/#rubenlagus/TelegramBots). diff --git a/TelegramBots.wiki/abilities/Simple-Example.md b/TelegramBots.wiki/abilities/Simple-Example.md index 87cf3d8f..c5d46c78 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 - 6.4.0 + 6.5.0 ``` * **Gradle** ```gradle - implementation 'org.telegram:telegrambots-abilities:6.4.0' + implementation 'org.telegram:telegrambots-abilities:6.5.0' ``` * [JitPack](https://jitpack.io/#rubenlagus/TelegramBots) diff --git a/pom.xml b/pom.xml index ef19c086..29fa0b0e 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots pom - 6.4.0 + 6.5.0 telegrambots @@ -76,6 +76,7 @@ 2.1.1 1.18.24 31.1-jre + 3.12.0 @@ -134,6 +135,12 @@ slf4j-api ${slf4j.version} + + org.apache.commons + commons-lang3 + ${commons.version} + + jakarta.annotation diff --git a/telegrambots-abilities/README.md b/telegrambots-abilities/README.md index a9e1cfca..c2c5d439 100644 --- a/telegrambots-abilities/README.md +++ b/telegrambots-abilities/README.md @@ -18,14 +18,14 @@ Usage org.telegram telegrambots-abilities - 6.4.0 + 6.5.0 ``` **Gradle** ```gradle - implementation 'org.telegram:telegrambots-abilities:6.4.0' + implementation 'org.telegram:telegrambots-abilities:6.5.0' ``` **JitPack** - [JitPack](https://jitpack.io/#rubenlagus/TelegramBots/v5.0.1) diff --git a/telegrambots-abilities/pom.xml b/telegrambots-abilities/pom.xml index ae02b2e2..6e2a7c8e 100644 --- a/telegrambots-abilities/pom.xml +++ b/telegrambots-abilities/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 6.4.0 + 6.5.0 telegrambots-abilities @@ -84,12 +84,16 @@ org.telegram telegrambots - 6.4.0 + 6.5.0 org.apache.commons commons-lang3 ${commonslang.version} + + + com.google.guava + guava org.mapdb diff --git a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/BaseAbilityBot.java b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/BaseAbilityBot.java index 876fb5f2..ef74a500 100644 --- a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/BaseAbilityBot.java +++ b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/BaseAbilityBot.java @@ -127,8 +127,7 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability // Ability toggle private final AbilityToggle toggle; - // Bot token and username - private final String botToken; + // Bot username private final String botUsername; // Ability registry @@ -142,9 +141,8 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability public abstract long creatorId(); protected BaseAbilityBot(String botToken, String botUsername, DBContext db, AbilityToggle toggle, DefaultBotOptions botOptions) { - super(botOptions); + super(botOptions, botToken); - this.botToken = botToken; this.botUsername = botUsername; this.db = db; this.toggle = toggle; @@ -264,10 +262,6 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability log.info(format("[%s] Processing of update [%s] ended at %s%n---> Processing time: [%d ms] <---%n", botUsername, update.getUpdateId(), now(), processingTime)); } - public String getBotToken() { - return botToken; - } - public String getBotUsername() { return botUsername; } diff --git a/telegrambots-chat-session-bot/README.md b/telegrambots-chat-session-bot/README.md index 45dd93ed..debf98e8 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 - 6.4.0 + 6.5.0 ``` **Gradle** ```gradle - implementation 'org.telegram:telegrambots-chat-session-bot:6.4.0' + implementation 'org.telegram:telegrambots-chat-session-bot:6.5.0' ``` Motivation diff --git a/telegrambots-chat-session-bot/pom.xml b/telegrambots-chat-session-bot/pom.xml index 7bc8a742..78f085d8 100644 --- a/telegrambots-chat-session-bot/pom.xml +++ b/telegrambots-chat-session-bot/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 6.4.0 + 6.5.0 telegrambots-chat-session-bot @@ -84,7 +84,7 @@ org.telegram telegrambots - 6.4.0 + 6.5.0 diff --git a/telegrambots-chat-session-bot/src/main/java/org/telegram/telegrambots/session/TelegramLongPollingSessionBot.java b/telegrambots-chat-session-bot/src/main/java/org/telegram/telegrambots/session/TelegramLongPollingSessionBot.java index 3f33fba7..35317b90 100644 --- a/telegrambots-chat-session-bot/src/main/java/org/telegram/telegrambots/session/TelegramLongPollingSessionBot.java +++ b/telegrambots-chat-session-bot/src/main/java/org/telegram/telegrambots/session/TelegramLongPollingSessionBot.java @@ -6,9 +6,9 @@ import org.apache.shiro.session.mgt.DefaultSessionManager; import org.apache.shiro.session.mgt.SessionContext; import org.apache.shiro.session.mgt.eis.AbstractSessionDAO; import org.telegram.telegrambots.bots.DefaultBotOptions; +import org.telegram.telegrambots.bots.TelegramLongPollingBot; import org.telegram.telegrambots.meta.api.objects.Message; import org.telegram.telegrambots.meta.api.objects.Update; -import org.telegram.telegrambots.bots.TelegramLongPollingBot; import java.util.Optional; @@ -17,23 +17,50 @@ public abstract class TelegramLongPollingSessionBot extends TelegramLongPollingB DefaultSessionManager sessionManager; ChatIdConverter chatIdConverter; - + /** + * If this is used getBotToken has to be overridden in order to return the bot token! + * @deprecated Overwriting the getBotToken() method is deprecated. Use the constructor instead + */ + @Deprecated public TelegramLongPollingSessionBot(){ this(new DefaultChatIdConverter()); } + /** + * If this is used getBotToken has to be overridden in order to return the bot token! + * @deprecated Overwriting the getBotToken() method is deprecated. Use the constructor instead + */ + @Deprecated public TelegramLongPollingSessionBot(ChatIdConverter chatIdConverter){ this(chatIdConverter, new DefaultBotOptions()); } + /** + * If this is used getBotToken has to be overridden in order to return the bot token! + * @deprecated Overwriting the getBotToken() method is deprecated. Use the constructor instead + */ + @Deprecated public TelegramLongPollingSessionBot(ChatIdConverter chatIdConverter, DefaultBotOptions defaultBotOptions){ - super(defaultBotOptions); + this(chatIdConverter, defaultBotOptions, null); + } + + public TelegramLongPollingSessionBot(String botToken){ + this(new DefaultChatIdConverter(), botToken); + } + + public TelegramLongPollingSessionBot(ChatIdConverter chatIdConverter, String botToken){ + this(chatIdConverter, new DefaultBotOptions(), botToken); + } + + public TelegramLongPollingSessionBot(ChatIdConverter chatIdConverter, DefaultBotOptions defaultBotOptions, String botToken){ + super(defaultBotOptions, botToken); this.setSessionManager(new DefaultSessionManager()); this.setChatIdConverter(chatIdConverter); AbstractSessionDAO sessionDAO = (AbstractSessionDAO) sessionManager.getSessionDAO(); sessionDAO.setSessionIdGenerator(chatIdConverter); } + public void setSessionManager(DefaultSessionManager sessionManager) { this.sessionManager = sessionManager; } diff --git a/telegrambots-extensions/README.md b/telegrambots-extensions/README.md index cec60de3..3c3a33a2 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 - 6.4.0 + 6.5.0 ``` 2. Using Gradle: ```gradle - implementation 'org.telegram:telegrambotsextensions:6.4.0' + implementation 'org.telegram:telegrambotsextensions:6.5.0' ``` \ No newline at end of file diff --git a/telegrambots-extensions/pom.xml b/telegrambots-extensions/pom.xml index ba68eca5..36f88e59 100644 --- a/telegrambots-extensions/pom.xml +++ b/telegrambots-extensions/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 6.4.0 + 6.5.0 telegrambotsextensions @@ -75,7 +75,7 @@ org.telegram telegrambots - 6.4.0 + 6.5.0 diff --git a/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/commandbot/TelegramWebhookCommandBot.java b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/commandbot/TelegramWebhookCommandBot.java index dcc37380..9d466b3d 100644 --- a/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/commandbot/TelegramWebhookCommandBot.java +++ b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/commandbot/TelegramWebhookCommandBot.java @@ -27,7 +27,9 @@ public abstract class TelegramWebhookCommandBot extends TelegramWebhookBot imple * Creates a TelegramWebhookCommandBot using default options * Use ICommandRegistry's methods on this bot to register commands * + * @deprecated Overwriting the getBotToken() method is deprecated. Use the constructor instead */ + @Deprecated public TelegramWebhookCommandBot() { this(new DefaultBotOptions()); } @@ -37,12 +39,53 @@ public abstract class TelegramWebhookCommandBot extends TelegramWebhookBot imple * usernames * Use ICommandRegistry's methods on this bot to register commands * + * @deprecated Overwriting the getBotToken() method is deprecated. Use the constructor instead + * * @param options Bot options */ + @Deprecated public TelegramWebhookCommandBot(DefaultBotOptions options) { this(options, true); } + /** + * Creates a TelegramWebhookCommandBot + * Use ICommandRegistry's methods on this bot to register commands + * + * @deprecated Overwriting the getBotToken() method is deprecated. Use the constructor instead + * + * @param options Bot options + * @param allowCommandsWithUsername true to allow commands with parameters (default), + * false otherwise + */ + @Deprecated + public TelegramWebhookCommandBot(DefaultBotOptions options, boolean allowCommandsWithUsername) { + super(options); + this.commandRegistry = new CommandRegistry(allowCommandsWithUsername, this::getBotUsername); + } + + /** + * Creates a TelegramWebhookCommandBot using default options + * Use ICommandRegistry's methods on this bot to register commands + * + * @param botToken the telegram api token + */ + public TelegramWebhookCommandBot(String botToken) { + this(new DefaultBotOptions(), botToken); + } + + /** + * Creates a TelegramWebhookCommandBot with custom options and allowing commands with + * usernames + * Use ICommandRegistry's methods on this bot to register commands + * + * @param options Bot options + * @param botToken the telegram api token + */ + public TelegramWebhookCommandBot(DefaultBotOptions options, String botToken) { + this(options, true, botToken); + } + /** * Creates a TelegramWebhookCommandBot * Use ICommandRegistry's methods on this bot to register commands @@ -50,9 +93,10 @@ public abstract class TelegramWebhookCommandBot extends TelegramWebhookBot imple * @param options Bot options * @param allowCommandsWithUsername true to allow commands with parameters (default), * false otherwise + * @param botToken the telegram api token */ - public TelegramWebhookCommandBot(DefaultBotOptions options, boolean allowCommandsWithUsername) { - super(options); + public TelegramWebhookCommandBot(DefaultBotOptions options, boolean allowCommandsWithUsername, String botToken) { + super(options, botToken); this.commandRegistry = new CommandRegistry(allowCommandsWithUsername, this::getBotUsername); } diff --git a/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/timedbot/TimedSendLongPollingBot.java b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/timedbot/TimedSendLongPollingBot.java index 97ee169c..415a2ff5 100644 --- a/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/timedbot/TimedSendLongPollingBot.java +++ b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/timedbot/TimedSendLongPollingBot.java @@ -132,8 +132,20 @@ public abstract class TimedSendLongPollingBot extends TelegramLongPollingBot } //Constructor + + /** + * @deprecated Overwriting the getBotToken() method is deprecated. Use the constructor instead + */ + @Deprecated protected TimedSendLongPollingBot() { + super(); + mSendTimer.schedule(new MessageSenderTask(), MANY_CHATS_SEND_INTERVAL, MANY_CHATS_SEND_INTERVAL); + } + + protected TimedSendLongPollingBot(String botToken) + { + super(botToken); mSendTimer.schedule(new MessageSenderTask(), MANY_CHATS_SEND_INTERVAL, MANY_CHATS_SEND_INTERVAL); } diff --git a/telegrambots-meta/pom.xml b/telegrambots-meta/pom.xml index 426db1b6..a12be905 100644 --- a/telegrambots-meta/pom.xml +++ b/telegrambots-meta/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 6.4.0 + 6.5.0 telegrambots-meta @@ -87,15 +87,14 @@ jackson-annotations - com.google.guava - guava + org.apache.commons + commons-lang3 org.projectlombok lombok provided - diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/TelegramBotsApi.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/TelegramBotsApi.java index b5e72591..0a88c573 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/TelegramBotsApi.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/TelegramBotsApi.java @@ -1,6 +1,6 @@ package org.telegram.telegrambots.meta; -import com.google.common.base.Strings; +import org.apache.commons.lang3.StringUtils; import org.telegram.telegrambots.meta.api.methods.updates.SetWebhook; import org.telegram.telegrambots.meta.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.generics.BotSession; @@ -106,7 +106,7 @@ public class TelegramBotsApi { * @return False if username or token are empty or null, true otherwise */ private boolean validateBotUsernameAndToken(TelegramBot telegramBot) { - return !Strings.isNullOrEmpty(telegramBot.getBotToken()) && - !Strings.isNullOrEmpty(telegramBot.getBotUsername()); + return StringUtils.isNotEmpty(telegramBot.getBotToken()) && + StringUtils.isNotEmpty(telegramBot.getBotUsername()); } } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/BotApiMethod.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/BotApiMethod.java index 620f7bf2..6ca13881 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/BotApiMethod.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/BotApiMethod.java @@ -2,7 +2,6 @@ package org.telegram.telegrambots.meta.api.methods; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; import java.io.Serializable; @@ -17,10 +16,4 @@ import java.io.Serializable; public abstract class BotApiMethod extends PartialBotApiMethod { protected static final String METHOD_FIELD = "method"; - /** - * Getter for method path (that is the same as method name) - * @return Method path - */ - @JsonProperty(METHOD_FIELD) - public abstract String getMethod(); } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/PartialBotApiMethod.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/PartialBotApiMethod.java index 9251e867..a1e9d1f1 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/PartialBotApiMethod.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/PartialBotApiMethod.java @@ -1,6 +1,7 @@ package org.telegram.telegrambots.meta.api.methods; import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.type.CollectionType; @@ -56,4 +57,11 @@ public abstract class PartialBotApiMethod implements Val throw new TelegramApiRequestException("Unable to deserialize response", e); } } + + /** + * Getter for method path (that is the same as method name) + * @return Method path + */ + @JsonProperty(BotApiMethod.METHOD_FIELD) + public abstract String getMethod(); } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/EditChatInviteLink.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/EditChatInviteLink.java index e7e874cc..3683bd3a 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/EditChatInviteLink.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/EditChatInviteLink.java @@ -1,7 +1,6 @@ package org.telegram.telegrambots.meta.api.methods.groupadministration; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.base.Strings; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.EqualsAndHashCode; @@ -12,6 +11,7 @@ import lombok.RequiredArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Tolerate; +import org.apache.commons.lang3.StringUtils; import org.telegram.telegrambots.meta.api.methods.BotApiMethod; import org.telegram.telegrambots.meta.api.objects.ChatInviteLink; import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; @@ -88,10 +88,10 @@ public class EditChatInviteLink extends BotApiMethod { @Override public void validate() throws TelegramApiValidationException { - if (Strings.isNullOrEmpty(chatId)) { + if (StringUtils.isEmpty(chatId)) { throw new TelegramApiValidationException("ChatId can't be empty", this); } - if (Strings.isNullOrEmpty(inviteLink)) { + if (StringUtils.isEmpty(inviteLink)) { throw new TelegramApiValidationException("InviteLink can't be empty", this); } if (name != null && name.length() > 32) { diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/RestrictChatMember.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/RestrictChatMember.java index f7f6b6a7..0983d526 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/RestrictChatMember.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/RestrictChatMember.java @@ -48,13 +48,20 @@ public class RestrictChatMember extends BotApiMethodBoolean { private static final String CANSENDOTHERMESSAGES_FIELD = "can_send_other_messages"; private static final String CANADDWEBPAGEPREVIEWS_FIELD = "can_add_web_page_previews"; private static final String PERMISSIONS_FIELD = "permissions"; + private static final String USEINDEPENDENTCHATPERMISSIONS_FIELD = "use_independent_chat_permissions"; + /** + * Required. Unique identifier for the chat to send the message to (Or username for channels) + */ @JsonProperty(CHATID_FIELD) @NonNull - private String chatId; ///< Required. Unique identifier for the chat to send the message to (Or username for channels) + private String chatId; + /** + * Required. Unique identifier of the target user + */ @JsonProperty(USER_ID_FIELD) @NonNull - private Long userId; ///< Required. Unique identifier of the target user + private Long userId; /** * Optional * Date when restrictions will be lifted for the user, unix time. @@ -64,8 +71,22 @@ public class RestrictChatMember extends BotApiMethodBoolean { @JsonProperty(PERMISSIONS_FIELD) @NonNull private ChatPermissions permissions; + /** + * Optional. + * Date when restrictions will be lifted for the user, unix time. + * If user is restricted for more than 366 days or less than 30 seconds from the current time, they are considered to be banned forever + */ @JsonProperty(UNTILDATE_FIELD) - private Integer untilDate; ///< Optional. Date when restrictions will be lifted for the user, unix time. If user is restricted for more than 366 days or less than 30 seconds from the current time, they are considered to be banned forever + private Integer untilDate; + /** + * Optional. + * Pass True if chat permissions are set independently. + * Otherwise, the can_send_other_messages and can_add_web_page_previews permissions + * will imply the can_send_messages, can_send_audios, can_send_documents, can_send_photos, can_send_videos, can_send_video_notes, + * and can_send_voice_notes permissions; the can_send_polls permission will imply the can_send_messages permission. + */ + @JsonProperty(USEINDEPENDENTCHATPERMISSIONS_FIELD) + private Boolean useIndependentChatPermissions; @Tolerate public void setChatId(@NonNull Long chatId) { diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/RevokeChatInviteLink.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/RevokeChatInviteLink.java index aa59a121..8fddc94c 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/RevokeChatInviteLink.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/RevokeChatInviteLink.java @@ -1,7 +1,6 @@ package org.telegram.telegrambots.meta.api.methods.groupadministration; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.base.Strings; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.EqualsAndHashCode; @@ -11,6 +10,7 @@ import lombok.NonNull; import lombok.Setter; import lombok.ToString; import lombok.experimental.Tolerate; +import org.apache.commons.lang3.StringUtils; import org.telegram.telegrambots.meta.api.methods.BotApiMethod; import org.telegram.telegrambots.meta.api.objects.ChatInviteLink; import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; @@ -65,10 +65,10 @@ public class RevokeChatInviteLink extends BotApiMethod { @Override public void validate() throws TelegramApiValidationException { - if (Strings.isNullOrEmpty(chatId)) { + if (StringUtils.isEmpty(chatId)) { throw new TelegramApiValidationException("ChatId can't be empty", this); } - if (Strings.isNullOrEmpty(inviteLink)) { + if (StringUtils.isEmpty(inviteLink)) { throw new TelegramApiValidationException("InviteLink can't be empty", this); } } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/SetChatPermissions.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/SetChatPermissions.java index 1d22210b..1b3cf57c 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/SetChatPermissions.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/SetChatPermissions.java @@ -33,13 +33,29 @@ public class SetChatPermissions extends BotApiMethodBoolean { private static final String CHAT_ID_FIELD = "chat_id"; private static final String PERMISSIONS_FIELD = "permissions"; + private static final String USEINDEPENDENTCHATPERMISSIONS_FIELD = "use_independent_chat_permissions"; + /** + * Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) + */ @JsonProperty(CHAT_ID_FIELD) @NonNull - private String chatId; ///< Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) + private String chatId; + /** + * New default chat permissions + */ @JsonProperty(PERMISSIONS_FIELD) @NonNull - private ChatPermissions permissions; ///< New default chat permissions + private ChatPermissions permissions; + /** + * Optional. + * Pass True if chat permissions are set independently. + * Otherwise, the can_send_other_messages and can_add_web_page_previews permissions + * will imply the can_send_messages, can_send_audios, can_send_documents, can_send_photos, can_send_videos, can_send_video_notes, + * and can_send_voice_notes permissions; the can_send_polls permission will imply the can_send_messages permission. + */ + @JsonProperty(USEINDEPENDENTCHATPERMISSIONS_FIELD) + private Boolean useIndependentChatPermissions; @Tolerate public void setChatId(@NonNull Long chatId) { diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/SetChatPhoto.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/SetChatPhoto.java index 69db04ec..cc63c7e3 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/SetChatPhoto.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/SetChatPhoto.java @@ -46,6 +46,11 @@ public class SetChatPhoto extends PartialBotApiMethod { this.chatId = chatId.toString(); } + @Override + public String getMethod() { + return PATH; + } + @Override public Boolean deserializeResponse(String answer) throws TelegramApiRequestException { return deserializeResponse(answer, Boolean.class); diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/invoices/CreateInvoiceLink.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/invoices/CreateInvoiceLink.java index 0c63c4a9..4db139cf 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/invoices/CreateInvoiceLink.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/invoices/CreateInvoiceLink.java @@ -1,7 +1,6 @@ package org.telegram.telegrambots.meta.api.methods.invoices; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.base.Strings; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.EqualsAndHashCode; @@ -12,6 +11,7 @@ import lombok.RequiredArgsConstructor; import lombok.Setter; import lombok.Singular; import lombok.ToString; +import org.apache.commons.lang3.StringUtils; import org.telegram.telegrambots.meta.api.methods.BotApiMethod; import org.telegram.telegrambots.meta.api.objects.payments.LabeledPrice; import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; @@ -134,19 +134,19 @@ public class CreateInvoiceLink extends BotApiMethod { @Override public void validate() throws TelegramApiValidationException { - if (Strings.isNullOrEmpty(title) || title.length() > 32) { + if (StringUtils.isEmpty(title) || title.length() > 32) { throw new TelegramApiValidationException("Title parameter can't be empty or longer than 32 chars", this); } - if (Strings.isNullOrEmpty(description) || description.length() > 255) { + if (StringUtils.isEmpty(description) || description.length() > 255) { throw new TelegramApiValidationException("Description parameter can't be empty or longer than 255 chars", this); } - if (Strings.isNullOrEmpty(payload)) { + if (StringUtils.isEmpty(payload)) { throw new TelegramApiValidationException("Payload parameter can't be empty", this); } - if (Strings.isNullOrEmpty(providerToken)) { + if (StringUtils.isEmpty(providerToken)) { throw new TelegramApiValidationException("ProviderToken parameter can't be empty", this); } - if (Strings.isNullOrEmpty(currency)) { + if (StringUtils.isEmpty(currency)) { throw new TelegramApiValidationException("Currency parameter can't be empty", this); } if (prices.isEmpty()) { 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 ce7421ad..599d9c65 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 @@ -1,7 +1,6 @@ package org.telegram.telegrambots.meta.api.methods.invoices; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.base.Strings; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.EqualsAndHashCode; @@ -13,6 +12,7 @@ import lombok.Setter; import lombok.Singular; import lombok.ToString; import lombok.experimental.Tolerate; +import org.apache.commons.lang3.StringUtils; import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodMessage; import org.telegram.telegrambots.meta.api.objects.payments.LabeledPrice; import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup; @@ -180,22 +180,22 @@ public class SendInvoice extends BotApiMethodMessage { @Override public void validate() throws TelegramApiValidationException { - if (Strings.isNullOrEmpty(chatId)) { + if (StringUtils.isEmpty(chatId)) { throw new TelegramApiValidationException("ChatId parameter can't be empty", this); } - if (Strings.isNullOrEmpty(title) || title.length() > 32) { + if (StringUtils.isEmpty(title) || title.length() > 32) { throw new TelegramApiValidationException("Title parameter can't be empty or longer than 32 chars", this); } - if (Strings.isNullOrEmpty(description) || description.length() > 255) { + if (StringUtils.isEmpty(description) || description.length() > 255) { throw new TelegramApiValidationException("Description parameter can't be empty or longer than 255 chars", this); } - if (Strings.isNullOrEmpty(payload)) { + if (StringUtils.isEmpty(payload)) { throw new TelegramApiValidationException("Payload parameter can't be empty", this); } - if (Strings.isNullOrEmpty(providerToken)) { + if (StringUtils.isEmpty(providerToken)) { throw new TelegramApiValidationException("ProviderToken parameter can't be empty", this); } - if (Strings.isNullOrEmpty(currency)) { + if (StringUtils.isEmpty(currency)) { throw new TelegramApiValidationException("Currency parameter can't be empty", this); } if (prices.isEmpty()) { 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 6e636a82..106064a7 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 @@ -11,7 +11,6 @@ import lombok.Setter; import lombok.Singular; import lombok.ToString; import lombok.experimental.Tolerate; -import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod; import org.telegram.telegrambots.meta.api.objects.InputFile; import org.telegram.telegrambots.meta.api.objects.Message; import org.telegram.telegrambots.meta.api.objects.MessageEntity; @@ -37,7 +36,7 @@ import java.util.List; @NoArgsConstructor @AllArgsConstructor @Builder -public class SendAnimation extends PartialBotApiMethod { +public class SendAnimation extends SendMediaBotMethod { public static final String PATH = "sendAnimation"; public static final String CHATID_FIELD = "chat_id"; @@ -59,6 +58,8 @@ public class SendAnimation extends PartialBotApiMethod { @NonNull private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels) + private Integer messageThreadId; + /** * Animation to send. Pass a file_id as String to send an animation that exists on the * Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get an animation @@ -68,7 +69,6 @@ public class SendAnimation extends PartialBotApiMethod { * Unique identifier for the target message thread (topic) of the forum; * for forum supergroups only */ - private Integer messageThreadId; @NonNull private InputFile animation; private Integer duration; ///< Optional. Duration of sent animation in seconds @@ -136,6 +136,21 @@ public class SendAnimation extends PartialBotApiMethod { } } + @Override + public String getMethod() { + return PATH; + } + + @Override + public InputFile getFile() { + return animation; + } + + @Override + public String getFileField() { + return ANIMATION_FIELD; + } + public static class SendAnimationBuilder { @Tolerate 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 bee6f1d5..33c52d10 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 @@ -11,7 +11,6 @@ import lombok.Setter; import lombok.Singular; import lombok.ToString; import lombok.experimental.Tolerate; -import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod; import org.telegram.telegrambots.meta.api.objects.InputFile; import org.telegram.telegrambots.meta.api.objects.Message; import org.telegram.telegrambots.meta.api.objects.MessageEntity; @@ -38,7 +37,7 @@ import java.util.List; @NoArgsConstructor @AllArgsConstructor @Builder -public class SendAudio extends PartialBotApiMethod { +public class SendAudio extends SendMediaBotMethod { public static final String PATH = "sendaudio"; public static final String DURATION_FIELD = "duration"; @@ -127,6 +126,21 @@ public class SendAudio extends PartialBotApiMethod { } } + @Override + public String getMethod() { + return PATH; + } + + @Override + public InputFile getFile() { + return audio; + } + + @Override + public String getFileField() { + return AUDIO_FIELD; + } + public static class SendAudioBuilder { @Tolerate 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 75e4a4f0..c25acea0 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 @@ -11,7 +11,6 @@ import lombok.Setter; import lombok.Singular; import lombok.ToString; import lombok.experimental.Tolerate; -import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod; import org.telegram.telegrambots.meta.api.objects.InputFile; import org.telegram.telegrambots.meta.api.objects.Message; import org.telegram.telegrambots.meta.api.objects.MessageEntity; @@ -34,7 +33,7 @@ import java.util.List; @NoArgsConstructor @AllArgsConstructor @Builder -public class SendDocument extends PartialBotApiMethod { +public class SendDocument extends SendMediaBotMethod { public static final String PATH = "senddocument"; public static final String CHATID_FIELD = "chat_id"; @@ -97,6 +96,7 @@ public class SendDocument extends PartialBotApiMethod { public Message deserializeResponse(String answer) throws TelegramApiRequestException { return deserializeResponse(answer, Message.class); } + @Override public void validate() throws TelegramApiValidationException { if (chatId.isEmpty()) { @@ -118,6 +118,21 @@ public class SendDocument extends PartialBotApiMethod { } } + @Override + public InputFile getFile() { + return document; + } + + @Override + public String getFileField() { + return DOCUMENT_FIELD; + } + + @Override + public String getMethod() { + return PATH; + } + public static class SendDocumentBuilder { @Tolerate 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 df6f7cdb..36556f6d 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 @@ -1,7 +1,6 @@ package org.telegram.telegrambots.meta.api.methods.send; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.base.Strings; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.EqualsAndHashCode; @@ -13,6 +12,7 @@ import lombok.Setter; import lombok.Singular; import lombok.ToString; import lombok.experimental.Tolerate; +import org.apache.commons.lang3.StringUtils; import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodMessage; import org.telegram.telegrambots.meta.api.objects.payments.LabeledPrice; import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup; @@ -176,22 +176,22 @@ public class SendInvoice extends BotApiMethodMessage { @Override public void validate() throws TelegramApiValidationException { - if (Strings.isNullOrEmpty(chatId)) { + if (StringUtils.isEmpty(chatId)) { throw new TelegramApiValidationException("ChatId parameter can't be empty", this); } - if (Strings.isNullOrEmpty(title)) { + if (StringUtils.isEmpty(title)) { throw new TelegramApiValidationException("Title parameter can't be empty", this); } - if (Strings.isNullOrEmpty(description)) { + if (StringUtils.isEmpty(description)) { throw new TelegramApiValidationException("Description parameter can't be empty", this); } - if (Strings.isNullOrEmpty(payload)) { + if (StringUtils.isEmpty(payload)) { throw new TelegramApiValidationException("Payload parameter can't be empty", this); } - if (Strings.isNullOrEmpty(providerToken)) { + if (StringUtils.isEmpty(providerToken)) { throw new TelegramApiValidationException("ProviderToken parameter can't be empty", this); } - if (Strings.isNullOrEmpty(currency)) { + if (StringUtils.isEmpty(currency)) { throw new TelegramApiValidationException("Currency parameter can't be empty", this); } if (prices.isEmpty()) { 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 new file mode 100644 index 00000000..14b9f3ee --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendMediaBotMethod.java @@ -0,0 +1,24 @@ +package org.telegram.telegrambots.meta.api.methods.send; + +import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod; +import org.telegram.telegrambots.meta.api.objects.InputFile; + +import java.io.Serializable; + +public abstract class SendMediaBotMethod extends PartialBotApiMethod { + public static String CHATID_FIELD = "chat_id"; + public static String MESSAGETHREADID_FIELD = "message_thread_id"; + public static String REPLYTOMESSAGEID_FIELD = "reply_to_message_id"; + public static String DISABLENOTIFICATION_FIELD = "disable_notification"; + public static String PROTECTCONTENT_FIELD = "protect_content"; + public static String ALLOWSENDINGWITHOUTREPLY_FIELD = "allow_sending_without_reply"; + + public abstract String getChatId(); + public abstract Integer getMessageThreadId(); + public abstract Integer getReplyToMessageId(); + public abstract Boolean getDisableNotification(); + public abstract Boolean getAllowSendingWithoutReply(); + public abstract Boolean getProtectContent(); + public abstract InputFile getFile(); + public abstract String getFileField(); +} 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 b262ca77..cf0984cc 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 @@ -115,6 +115,11 @@ public class SendMediaGroup extends PartialBotApiMethod> { } } + @Override + public String getMethod() { + return PATH; + } + public static class SendMediaGroupBuilder { @Tolerate 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 9ac59020..0ecd7877 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 @@ -11,7 +11,6 @@ import lombok.Setter; import lombok.Singular; import lombok.ToString; import lombok.experimental.Tolerate; -import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod; import org.telegram.telegrambots.meta.api.objects.InputFile; import org.telegram.telegrambots.meta.api.objects.Message; import org.telegram.telegrambots.meta.api.objects.MessageEntity; @@ -35,7 +34,7 @@ import java.util.Objects; @NoArgsConstructor @AllArgsConstructor @Builder -public class SendPhoto extends PartialBotApiMethod { +public class SendPhoto extends SendMediaBotMethod { public static final String PATH = "sendphoto"; public static final String CHATID_FIELD = "chat_id"; @@ -113,8 +112,22 @@ public class SendPhoto extends PartialBotApiMethod { } } + @Override + public InputFile getFile() { + return photo; + } + + @Override + public String getFileField() { + return PHOTO_FIELD; + } + @Override + public String getMethod() { + return PATH; + } public static class SendPhotoBuilder { + @Tolerate public SendPhotoBuilder chatId(@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 85adf9ad..f37fad72 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 @@ -10,7 +10,6 @@ import lombok.RequiredArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Tolerate; -import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod; import org.telegram.telegrambots.meta.api.objects.InputFile; import org.telegram.telegrambots.meta.api.objects.Message; import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard; @@ -31,7 +30,7 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; @NoArgsConstructor @AllArgsConstructor @Builder -public class SendSticker extends PartialBotApiMethod { +public class SendSticker extends SendMediaBotMethod { public static final String PATH = "sendsticker"; public static final String CHATID_FIELD = "chat_id"; @@ -93,6 +92,22 @@ public class SendSticker extends PartialBotApiMethod { } } + @Override + public String getMethod() { + return PATH; + } + + @Override + public InputFile getFile() { + return sticker; + } + + @Override + public String getFileField() { + return STICKER_FIELD; + } + + public static class SendStickerBuilder { @Tolerate 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 bb830cd2..ef03bd1a 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 @@ -11,7 +11,6 @@ import lombok.Setter; import lombok.Singular; import lombok.ToString; import lombok.experimental.Tolerate; -import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod; import org.telegram.telegrambots.meta.api.objects.InputFile; import org.telegram.telegrambots.meta.api.objects.Message; import org.telegram.telegrambots.meta.api.objects.MessageEntity; @@ -35,7 +34,7 @@ import java.util.List; @NoArgsConstructor @AllArgsConstructor @Builder -public class SendVideo extends PartialBotApiMethod { +public class SendVideo extends SendMediaBotMethod { public static final String PATH = "sendvideo"; public static final String CHATID_FIELD = "chat_id"; @@ -131,6 +130,21 @@ public class SendVideo extends PartialBotApiMethod { } } + @Override + public String getMethod() { + return PATH; + } + + @Override + public InputFile getFile() { + return video; + } + + @Override + public String getFileField() { + return VIDEO_FIELD; + } + public static class SendVideoBuilder { @Tolerate 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 43e0a5b7..337300bd 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 @@ -10,7 +10,6 @@ import lombok.RequiredArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Tolerate; -import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod; import org.telegram.telegrambots.meta.api.objects.InputFile; import org.telegram.telegrambots.meta.api.objects.Message; import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard; @@ -32,7 +31,7 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; @NoArgsConstructor @AllArgsConstructor @Builder -public class SendVideoNote extends PartialBotApiMethod { +public class SendVideoNote extends SendMediaBotMethod { public static final String PATH = "sendvideonote"; public static final String CHATID_FIELD = "chat_id"; @@ -106,6 +105,21 @@ public class SendVideoNote extends PartialBotApiMethod { } } + @Override + public String getMethod() { + return PATH; + } + + @Override + public InputFile getFile() { + return videoNote; + } + + @Override + public String getFileField() { + return VIDEONOTE_FIELD; + } + public static class SendVideoNoteBuilder { @Tolerate 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 7c64ff1f..0936f81f 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 @@ -11,7 +11,6 @@ import lombok.Setter; import lombok.Singular; import lombok.ToString; import lombok.experimental.Tolerate; -import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod; import org.telegram.telegrambots.meta.api.objects.InputFile; import org.telegram.telegrambots.meta.api.objects.Message; import org.telegram.telegrambots.meta.api.objects.MessageEntity; @@ -36,7 +35,7 @@ import java.util.List; @NoArgsConstructor @AllArgsConstructor @Builder -public class SendVoice extends PartialBotApiMethod { +public class SendVoice extends SendMediaBotMethod { public static final String PATH = "sendvoice"; public static final String CHATID_FIELD = "chat_id"; @@ -106,6 +105,21 @@ public class SendVoice extends PartialBotApiMethod { } } + @Override + public String getMethod() { + return PATH; + } + + @Override + public InputFile getFile() { + return voice; + } + + @Override + public String getFileField() { + return VOICE_FIELD; + } + public static class SendVoiceBuilder { @Tolerate diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stickers/AddStickerToSet.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stickers/AddStickerToSet.java index 80f1f0dd..1dd41b30 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stickers/AddStickerToSet.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stickers/AddStickerToSet.java @@ -76,6 +76,11 @@ public class AddStickerToSet extends PartialBotApiMethod { return deserializeResponse(answer, Boolean.class); } + @Override + public String getMethod() { + return PATH; + } + @Override public void validate() throws TelegramApiValidationException { if (userId <= 0) { diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stickers/CreateNewStickerSet.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stickers/CreateNewStickerSet.java index af7351f2..c2ea8ad5 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stickers/CreateNewStickerSet.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stickers/CreateNewStickerSet.java @@ -10,7 +10,6 @@ import lombok.RequiredArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Tolerate; -import org.telegram.telegrambots.meta.api.methods.CopyMessage; import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod; import org.telegram.telegrambots.meta.api.objects.InputFile; import org.telegram.telegrambots.meta.api.objects.stickers.MaskPosition; @@ -18,7 +17,6 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; import java.util.Arrays; -import java.util.List; /** * @author Ruben Bermudez @@ -124,6 +122,11 @@ public class CreateNewStickerSet extends PartialBotApiMethod { return "mask".equals(stickerType); } + @Override + public String getMethod() { + return PATH; + } + @Override public Boolean deserializeResponse(String answer) throws TelegramApiRequestException { return deserializeResponse(answer, Boolean.class); diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stickers/UploadStickerFile.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stickers/UploadStickerFile.java index 840b3959..8954fd21 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stickers/UploadStickerFile.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stickers/UploadStickerFile.java @@ -42,6 +42,11 @@ public class UploadStickerFile extends PartialBotApiMethod { @NonNull private InputFile pngSticker; ///< New sticker file + @Override + public String getMethod() { + return PATH; + } + @Override public File deserializeResponse(String answer) throws TelegramApiRequestException { return deserializeResponse(answer, File.class); 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 44745131..0b1ceb05 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 @@ -81,6 +81,11 @@ public class EditMessageMedia extends PartialBotApiMethod { this.chatId = chatId == null ? null : chatId.toString(); } + @Override + public String getMethod() { + return PATH; + } + @Override public Serializable deserializeResponse(String answer) throws TelegramApiRequestException { try { diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatJoinRequest.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatJoinRequest.java index 1537c9b7..330786b1 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatJoinRequest.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatJoinRequest.java @@ -21,6 +21,7 @@ public class ChatJoinRequest implements BotApiObject { private static final String DATE_FIELD = "date"; private static final String BIO_FIELD = "bio"; private static final String INVITELINK_FIELD = "invite_link"; + private static final String USERCHATID_FIELD = "user_chat_id"; /** * Chat to which the request was sent @@ -49,4 +50,12 @@ public class ChatJoinRequest implements BotApiObject { */ @JsonProperty(INVITELINK_FIELD) private ChatInviteLink inviteLink; + /** + * Identifier of a private chat with the user who sent the join request. + * This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. + * But it has at most 52 significant bits, so a 64-bit integer or double-precision float type are safe for storing this identifier. + * @apiNote The bot can use this identifier for 24 hours to send messages until the join request is processed, assuming no other administrator contacted the user. + */ + @JsonProperty(USERCHATID_FIELD) + private Long userChatId; } 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 7fcccbbc..bcede8f2 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 @@ -26,13 +26,21 @@ import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; @Builder public class ChatPermissions implements BotApiObject { private static final String CAN_SEND_MESSAGES_FIELD = "can_send_messages"; - private static final String CAN_SEND_MEDIA_MESSAGES_FIELD = "can_send_media_messages"; + private static final String CANSENDAUDIOS_FIELD = "can_send_audios"; + private static final String CANSENDDOCUMENTS_FIELD = "can_send_documents"; + private static final String CANSENDPHOTOS_FIELD = "can_send_photos"; + private static final String CANSENDVIDEOS_FIELD = "can_send_videos"; + private static final String CANSENDVIDEONOTES_FIELD = "can_send_video_notes"; + private static final String CANSENDVOICENOTES_FIELD = "can_send_voice_notes"; private static final String CAN_SEND_POLLS_FIELD = "can_send_polls"; private static final String CAN_SEND_OTHER_MESSAGES_FIELD = "can_send_other_messages"; private static final String CAN_ADD_WEB_PAGE_PREVIEWS_FIELD = "can_add_web_page_previews"; private static final String CAN_CHANGE_INFO_FIELD = "can_change_info"; private static final String CAN_INVITE_USERS_FIELD = "can_invite_users"; private static final String CAN_PIN_MESSAGES_FIELD = "can_pin_messages"; + private static final String CANMANAGETOPICS_FIELD = "can_manage_topics"; + + private static final String CAN_SEND_MEDIA_MESSAGES_FIELD = "can_send_media_messages"; /** * Optional. @@ -41,11 +49,35 @@ public class ChatPermissions implements BotApiObject { @JsonProperty(CAN_SEND_MESSAGES_FIELD) private Boolean canSendMessages; /** - * Optional. - * True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes, implies can_send_messages + * True, if the user is allowed to send audios */ - @JsonProperty(CAN_SEND_MEDIA_MESSAGES_FIELD) - private Boolean canSendMediaMessages; + @JsonProperty(CANSENDAUDIOS_FIELD) + private Boolean canSendAudios; + /** + * True, if the user is allowed to send documents + */ + @JsonProperty(CANSENDDOCUMENTS_FIELD) + private Boolean canSendDocuments; + /** + * True, if the user is allowed to send photos + */ + @JsonProperty(CANSENDPHOTOS_FIELD) + private Boolean canSendPhotos; + /** + * True, if the user is allowed to send videos + */ + @JsonProperty(CANSENDVIDEOS_FIELD) + private Boolean canSendVideos; + /** + * True, if the user is allowed to send video notes + */ + @JsonProperty(CANSENDVIDEONOTES_FIELD) + private Boolean canSendVideoNotes; + /** + * Optional. True, if the user is allowed to send voice notes + */ + @JsonProperty(CANSENDVOICENOTES_FIELD) + private Boolean canSendVoiceNotes; /** * Optional. * True, if the user is allowed to send polls, implies can_send_messages @@ -82,4 +114,19 @@ public class ChatPermissions implements BotApiObject { */ @JsonProperty(CAN_PIN_MESSAGES_FIELD) private Boolean canPinMessages; + /** + * Optional. True, if the user is allowed to create forum topics. + * If omitted defaults to the value of can_pin_messages + */ + @JsonProperty(CANMANAGETOPICS_FIELD) + private Boolean canManageTopics; + + /** + * Optional. + * True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes, implies can_send_messages + * @deprecated Use individual permissions + */ + @JsonProperty(CAN_SEND_MEDIA_MESSAGES_FIELD) + @Deprecated + private Boolean canSendMediaMessages; } 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 new file mode 100644 index 00000000..1aa7d3ba --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatShared.java @@ -0,0 +1,41 @@ +package org.telegram.telegrambots.meta.api.objects; + +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 org.telegram.telegrambots.meta.api.interfaces.BotApiObject; + +/** + * This object contains information about the chat whose identifier was shared with the bot using a KeyboardButtonRequestChat button. + * @author Ruben Bermudez + * @version 6.5 + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +public class ChatShared implements BotApiObject { + + private static final String REQUESTID_FIELD = "request_id"; + private static final String CHATID_FIELD = "chat_id"; + + /** + * Identifier of the request + */ + @JsonProperty(REQUESTID_FIELD) + private String requestId; + /** + * Identifier of the shared chat. + * This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. + * But it has at most 52 significant bits, so a 64-bit integer or double-precision float type are safe for storing this identifier. + * @apiNote The bot may not have access to the user and could be unable to use this identifier, unless the user is already known to the bot by some other means. + */ + @JsonProperty(CHATID_FIELD) + private Long chatId; +} 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 7356cfe5..f1cdc0dd 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 @@ -113,6 +113,8 @@ public class Message implements BotApiObject { private static final String GENERALFORUMTOPICUNHIDDEN_FIELD = "general_forum_topic_unhidden"; private static final String WRITEACCESSALLOWED_FIELD = "write_access_allowed"; private static final String HASMEDIASPOILER_FIELD = "has_media_spoiler"; + private static final String USERSHARED_FIELD = "user_shared"; + private static final String CHATSHARED_FIELD = "chat_shared"; /** * Integer Unique message identifier @@ -541,6 +543,18 @@ public class Message implements BotApiObject { */ @JsonProperty(HASMEDIASPOILER_FIELD) private Boolean hasMediaSpoiler; + /** + * Optional. + * Service message: a user was shared with the bot + */ + @JsonProperty(USERSHARED_FIELD) + private UserShared userShared; + /** + * Optional. + * Service message: a chat was shared with the bot + */ + @JsonProperty(CHATSHARED_FIELD) + private ChatShared chatShared; public List getEntities() { if (entities != null) { @@ -753,4 +767,14 @@ public class Message implements BotApiObject { private boolean hasForumTopicReopened() { return forumTopicReopened != null; } + + @JsonIgnore + private boolean hasUserShared() { + return userShared != null; + } + + @JsonIgnore + private boolean hasChatShared() { + return chatShared != null; + } } 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 new file mode 100644 index 00000000..b9781a5b --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/UserShared.java @@ -0,0 +1,41 @@ +package org.telegram.telegrambots.meta.api.objects; + +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 org.telegram.telegrambots.meta.api.interfaces.BotApiObject; + +/** + * This object contains information about the user whose identifier was shared with the bot using a KeyboardButtonRequestUser button. + * @author Ruben Bermudez + * @version 6.5 + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +public class UserShared implements BotApiObject { + + private static final String REQUESTID_FIELD = "request_id"; + private static final String USERID_FIELD = "user_id"; + + /** + * Identifier of the request + */ + @JsonProperty(REQUESTID_FIELD) + private String requestId; + /** + * Identifier of the shared user. + * This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. + * But it has at most 52 significant bits, so a 64-bit integer or double-precision float type are safe for storing this identifier. + * @apiNote The bot may not have access to the user and could be unable to use this identifier, unless the user is already known to the bot by some other means. + */ + @JsonProperty(USERID_FIELD) + private Long userId; +} 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 a01c1162..80c4cd03 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 @@ -3,6 +3,7 @@ package org.telegram.telegrambots.meta.api.objects.adminrights; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.*; import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.interfaces.Validable; /** * Represents rights of an administrator in a chat. @@ -16,7 +17,7 @@ import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; @NoArgsConstructor @AllArgsConstructor @Builder -public class ChatAdministratorRights implements BotApiObject { +public class ChatAdministratorRights implements BotApiObject, Validable { private static final String ISANONYMOUS_FIELD = "is_anonymous"; private static final String CANMANAGECHAT_FIELD = "can_manage_chat"; @@ -35,6 +36,7 @@ public class ChatAdministratorRights implements BotApiObject { * True, if the user's presence in the chat is hidden */ @JsonProperty(ISANONYMOUS_FIELD) + @NonNull private Boolean isAnonymous; /** * True, if the administrator can access the chat event log, chat statistics, @@ -43,21 +45,25 @@ public class ChatAdministratorRights implements BotApiObject { * Implied by any other administrator privilege */ @JsonProperty(CANMANAGECHAT_FIELD) + @NonNull private Boolean canManageChat; /** * True, if the administrator can delete messages of other users */ @JsonProperty(CANDELETEMESSAGES_FIELD) + @NonNull private Boolean canDeleteMessages; /** * True, if the administrator can manage video chats */ @JsonProperty(CANMANAGEVIDEOCHATS_FIELD) + @NonNull private Boolean canManageVideoChats; /** * True, if the administrator can restrict, ban or unban chat members */ @JsonProperty(CANRESTRICTMEMBERS_FIELD) + @NonNull private Boolean canRestrictMembers; /** * True, if the administrator can add new administrators with a subset of @@ -65,16 +71,19 @@ public class ChatAdministratorRights implements BotApiObject { * directly or indirectly (promoted by administrators that were appointed by the user) */ @JsonProperty(CANPROMOTEMEMBERS_FIELD) + @NonNull private Boolean canPromoteMembers; /** * True, if the user is allowed to change the chat title, photo and other settings */ @JsonProperty(CANCHANGEINFO_FIELD) + @NonNull private Boolean canChangeInfo; /** * True, if the user is allowed to invite new users to the chat */ @JsonProperty(CANINVITEUSERS_FIELD) + @NonNull private Boolean canInviteUsers; /** * Optional. 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 4d190885..3d4addc7 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 @@ -31,16 +31,23 @@ public class ChatMemberRestricted implements ChatMember { private static final String STATUS_FIELD = "status"; private static final String USER_FIELD = "user"; private static final String ISMEMBER_FIELD = "is_member"; - private static final String CANCHANGEINFO_FIELD = "can_change_info"; - private static final String CANINVITEUSERS_FIELD = "can_invite_users"; - private static final String CANPINMESSAGES_FIELD = "can_pin_messages"; private static final String CANSENDMESSAGES_FIELD = "can_send_messages"; - private static final String CANSENDMEDIAMESSAGES_FIELD = "can_send_media_messages"; + private static final String CANSENDAUDIOS_FIELD = "can_send_audios"; + private static final String CANSENDDOCUMENTS_FIELD = "can_send_documents"; + private static final String CANSENDPHOTOS_FIELD = "can_send_photos"; + private static final String CANSENDVIDEOS_FIELD = "can_send_videos"; + private static final String CANSENDVIDEONOTES_FIELD = "can_send_video_notes"; + private static final String CANSENDVOICENOTES_FIELD = "can_send_voice_notes"; private static final String CANSENDPOLLS_FIELD = "can_send_polls"; private static final String CANSENDOTHERMESSAGES_FIELD = "can_send_other_messages"; private static final String CANADDWEBPAGEPREVIEWS_FIELD = "can_add_web_page_previews"; - private static final String UNTILDATE_FIELD = "until_date"; + private static final String CANCHANGEINFO_FIELD = "can_change_info"; + private static final String CANINVITEUSERS_FIELD = "can_invite_users"; + private static final String CANPINMESSAGES_FIELD = "can_pin_messages"; private static final String CANMANAGETOPICS_FIELD = "can_manage_topics"; + private static final String UNTILDATE_FIELD = "until_date"; + + private static final String CANSENDMEDIAMESSAGES_FIELD = "can_send_media_messages"; /** * The member's status in the chat, always “restricted” @@ -57,31 +64,41 @@ public class ChatMemberRestricted implements ChatMember { */ @JsonProperty(ISMEMBER_FIELD) private Boolean isMember; - /** - * True, if the user is allowed to change the chat title, photo and other settings - */ - @JsonProperty(CANCHANGEINFO_FIELD) - private Boolean canChangeInfo; - /** - * True, if the user is allowed to invite new users to the chat - */ - @JsonProperty(CANINVITEUSERS_FIELD) - private Boolean canInviteUsers; - /** - * True, if the user is allowed to pin messages; groups and supergroups only - */ - @JsonProperty(CANPINMESSAGES_FIELD) - private Boolean canPinMessages; /** * True, if the user is allowed to send text messages, contacts, locations and venues */ @JsonProperty(CANSENDMESSAGES_FIELD) private Boolean canSendMessages; /** - * True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes + * True, if the user is allowed to send audios */ - @JsonProperty(CANSENDMEDIAMESSAGES_FIELD) - private Boolean canSendMediaMessages; + @JsonProperty(CANSENDAUDIOS_FIELD) + private Boolean canSendAudios; + /** + * True, if the user is allowed to send documents + */ + @JsonProperty(CANSENDDOCUMENTS_FIELD) + private Boolean canSendDocuments; + /** + * True, if the user is allowed to send photos + */ + @JsonProperty(CANSENDPHOTOS_FIELD) + private Boolean canSendPhotos; + /** + * True, if the user is allowed to send videos + */ + @JsonProperty(CANSENDVIDEOS_FIELD) + private Boolean canSendVideos; + /** + * True, if the user is allowed to send video notes + */ + @JsonProperty(CANSENDVIDEONOTES_FIELD) + private Boolean canSendVideoNotes; + /** + * Optional. True, if the user is allowed to send voice notes + */ + @JsonProperty(CANSENDVOICENOTES_FIELD) + private Boolean canSendVoiceNotes; /** * True, if the user is allowed to send polls */ @@ -98,13 +115,36 @@ public class ChatMemberRestricted implements ChatMember { @JsonProperty(CANADDWEBPAGEPREVIEWS_FIELD) private Boolean canAddWebpagePreviews; /** - * Date when restrictions will be lifted for this user; unix time + * True, if the user is allowed to change the chat title, photo and other settings */ - @JsonProperty(UNTILDATE_FIELD) - private Integer untilDate; + @JsonProperty(CANCHANGEINFO_FIELD) + private Boolean canChangeInfo; + /** + * True, if the user is allowed to invite new users to the chat + */ + @JsonProperty(CANINVITEUSERS_FIELD) + private Boolean canInviteUsers; + /** + * True, if the user is allowed to pin messages; groups and supergroups only + */ + @JsonProperty(CANPINMESSAGES_FIELD) + private Boolean canPinMessages; /** * True, if the user is allowed to create forum topics */ @JsonProperty(CANMANAGETOPICS_FIELD) private Boolean canManageTopics; + /** + * Date when restrictions will be lifted for this user; unix time + */ + @JsonProperty(UNTILDATE_FIELD) + private Integer untilDate; + + /** + * True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes + * @deprecated Use individual permissions instead + */ + @JsonProperty(CANSENDMEDIAMESSAGES_FIELD) + @Deprecated + private Boolean canSendMediaMessages; } 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 index fd118497..e381c948 100644 --- 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 @@ -2,7 +2,6 @@ package org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessageconte 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; @@ -13,6 +12,7 @@ import lombok.RequiredArgsConstructor; import lombok.Setter; import lombok.Singular; import lombok.ToString; +import org.apache.commons.lang3.StringUtils; import org.telegram.telegrambots.meta.api.objects.payments.LabeledPrice; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; @@ -189,19 +189,19 @@ public class InputInvoiceMessageContent implements InputMessageContent { @Override public void validate() throws TelegramApiValidationException { - if (Strings.isNullOrEmpty(title) || title.length() > 32) { + if (StringUtils.isEmpty(title) || title.length() > 32) { throw new TelegramApiValidationException("Title parameter must be between 1 and 32 characters", this); } - if (Strings.isNullOrEmpty(description) || description.length() > 32) { + if (StringUtils.isEmpty(description) || description.length() > 32) { throw new TelegramApiValidationException("Description parameter must be between 1 and 255 characters", this); } - if (Strings.isNullOrEmpty(payload) || payload.length() > 32) { + if (StringUtils.isEmpty(payload) || payload.length() > 32) { throw new TelegramApiValidationException("Payload parameter must be between 1 and 128 characters", this); } - if (Strings.isNullOrEmpty(providerToken)) { + if (StringUtils.isEmpty(providerToken)) { throw new TelegramApiValidationException("ProviderToken parameter must not be empty", this); } - if (Strings.isNullOrEmpty(currency)) { + if (StringUtils.isEmpty(currency)) { throw new TelegramApiValidationException("Currency parameter must not be empty", this); } if (prices == null || prices.isEmpty()) { diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardButton.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardButton.java index 63c26b82..2e2e949c 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardButton.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardButton.java @@ -26,6 +26,8 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; * after 9 April, 2016. Older clients will ignore them. * @apiNote request_poll option will only work in Telegram versions released after 1X January, 2020. * Older clients will receive unsupported message. + * @apiNote The optional fields web_app, request_user, request_chat, request_contact, request_location, + * and request_poll are mutually exclusive */ @EqualsAndHashCode(callSuper = false) @Getter @@ -42,6 +44,8 @@ public class KeyboardButton implements Validable, BotApiObject { private static final String REQUEST_LOCATION_FIELD = "request_location"; private static final String REQUEST_POLL_FIELD = "request_poll"; private static final String WEBAPP_FIELD = "web_app"; + private static final String REQUESTUSER_FIELD = "request_user"; + private static final String REQUESTCHAT_FIELD = "request_chat"; /** * Text of the button. * If none of the optional fields are used, it will be sent to the bot as a message when the button is pressed @@ -79,22 +83,51 @@ public class KeyboardButton implements Validable, BotApiObject { @JsonProperty(WEBAPP_FIELD) private WebAppInfo webApp; + /** + * Optional. + * If specified, pressing the button will open a list of suitable users. + * Tapping on any user will send their identifier to the bot in a “user_shared” service message. + * Available in private chats only. + */ + @JsonProperty(REQUESTUSER_FIELD) + private KeyboardButtonRequestUser requestUser; + + /** + * Optional. + * If specified, pressing the button will open a list of suitable chats. + * Tapping on a chat will send its identifier to the bot in a “chat_shared” service message. + * Available in private chats only. + */ + @JsonProperty(REQUESTCHAT_FIELD) + private KeyboardButtonRequestChat requestChat; + @Override public void validate() throws TelegramApiValidationException { if (text.isEmpty()) { throw new TelegramApiValidationException("Text parameter can't be empty", this); } - if (requestContact != null && requestLocation != null && requestContact && requestLocation) { - throw new TelegramApiValidationException("Cant request contact and location at the same time", this); - } - if (requestContact != null && requestPoll != null && requestContact) { - throw new TelegramApiValidationException("Cant request contact and poll at the same time", this); - } - if (requestLocation != null && requestPoll != null && requestLocation) { - throw new TelegramApiValidationException("Cant request location and poll at the same time", this); + + int requestsProvided = 0; + requestsProvided += (requestContact == null ? 0 : 1); + requestsProvided += (requestLocation == null ? 0 : 1); + requestsProvided += (requestPoll == null ? 0 : 1); + requestsProvided += (webApp == null ? 0 : 1); + requestsProvided += (requestUser == null ? 0 : 1); + requestsProvided += (requestChat == null ? 0 : 1); + if (requestsProvided > 1) { + throw new TelegramApiValidationException("The optional fields web_app, request_user, request_chat, request_contact, request_location, and request_poll are mutually exclusive", this); } if (webApp != null) { webApp.validate(); } + if (requestPoll != null) { + requestPoll.validate(); + } + if (requestUser != null) { + requestUser.validate(); + } + if (requestChat != null) { + requestChat.validate(); + } } } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardButtonRequestChat.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardButtonRequestChat.java new file mode 100644 index 00000000..ba6833d7 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardButtonRequestChat.java @@ -0,0 +1,113 @@ +package org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons; + +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.api.objects.adminrights.ChatAdministratorRights; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * @author Ruben Bermudez + * @version 6.5 + * + * This object defines the criteria used to request a suitable chat. + * The identifier of the selected chat will be shared with the bot when the corresponding button is pressed. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@RequiredArgsConstructor +@AllArgsConstructor +@Builder +public class KeyboardButtonRequestChat implements Validable, BotApiObject { + + private static final String REQUESTID_FIELD = "request_id"; + private static final String CHATISCHANNEL_FIELD = "chat_is_channel"; + private static final String CHATISFORUM_FIELD = "chat_is_forum"; + private static final String CHATHASUSERNAME_FIELD = "chat_has_username"; + private static final String CHATISCREATED_FIELD = "chat_is_created"; + private static final String USERADMINISTRATORRIGHTS_FIELD = "user_administrator_rights"; + private static final String BOTADMINISTRATORRIGHTS_FIELD = "bot_administrator_rights"; + private static final String BOTISMEMBER_FIELD = "bot_is_member"; + + /** + * Signed 32-bit identifier of the request + */ + @JsonProperty(REQUESTID_FIELD) + @NonNull + private String requestId; + /** + * Pass True to request a channel chat, pass False to request a group or a supergroup chat. + */ + @JsonProperty(CHATISCHANNEL_FIELD) + @NonNull + private Boolean chatIsChannel; + /** + * Optional. + * Pass True to request a forum supergroup, pass False to request a non-forum chat. + * If not specified, no additional restrictions are applied. + */ + @JsonProperty(CHATISFORUM_FIELD) + private Boolean chatIsForum; + /** + * Optional. + * Pass True to request a supergroup or a channel with a username, pass False to request a chat without a username. + * If not specified, no additional restrictions are applied. + */ + @JsonProperty(CHATHASUSERNAME_FIELD) + private Boolean chatHasUsername; + /** + * Optional. + * Pass True to request a chat owned by the user. + * Otherwise, no additional restrictions are applied. + */ + @JsonProperty(CHATISCREATED_FIELD) + private Boolean chatIsCreated; + /** + * Optional. + * A JSON-serialized object listing the required administrator rights of the user in the chat. + * If not specified, no additional restrictions are applied. + */ + @JsonProperty(USERADMINISTRATORRIGHTS_FIELD) + private ChatAdministratorRights userAdministratorRights; + /** + * Optional. + * A JSON-serialized object listing the required administrator rights of the bot in the chat. + * The rights must be a subset of user_administrator_rights. + * If not specified, no additional restrictions are applied. + */ + @JsonProperty(BOTADMINISTRATORRIGHTS_FIELD) + private ChatAdministratorRights botAdministratorRights; + /** + * Optional. + * Pass True to request a chat with the bot as a member. + * Otherwise, no additional restrictions are applied. + */ + @JsonProperty(BOTISMEMBER_FIELD) + private Boolean botIsMember; + + + @Override + public void validate() throws TelegramApiValidationException { + if (requestId.isEmpty()) { + throw new TelegramApiValidationException("Text parameter can't be empty", this); + } + if (userAdministratorRights != null) { + userAdministratorRights.validate(); + } + if (botAdministratorRights != null) { + botAdministratorRights.validate(); + } + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardButtonRequestUser.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardButtonRequestUser.java new file mode 100644 index 00000000..e238f864 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardButtonRequestUser.java @@ -0,0 +1,66 @@ +package org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons; + +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 6.5 + * + * This object defines the criteria used to request a suitable user. + * The identifier of the selected user will be shared with the bot when the corresponding button is pressed. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@RequiredArgsConstructor +@AllArgsConstructor +@Builder +public class KeyboardButtonRequestUser implements Validable, BotApiObject { + + private static final String REQUESTID_FIELD = "request_id"; + private static final String USERISBOT_FIELD = "user_is_bot"; + private static final String USERISPREMIUM_FIELD = "user_is_premium"; + + /** + * Signed 32-bit identifier of the request + */ + @JsonProperty(REQUESTID_FIELD) + @NonNull + private String requestId; + /** + * Optional. + * Pass True to request a bot, pass False to request a regular user. + * If not specified, no additional restrictions are applied. + */ + @JsonProperty(USERISBOT_FIELD) + private Boolean userIsBot; + /** + * Optional. + * Pass True to request a premium user, pass False to request a non-premium user. + * If not specified, no additional restrictions are applied. + */ + @JsonProperty(USERISPREMIUM_FIELD) + private Boolean userIsPremium; + + + @Override + public void validate() throws TelegramApiValidationException { + if (requestId.isEmpty()) { + throw new TelegramApiValidationException("Text parameter can't be empty", this); + } + } +} diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/adminrights/SetMyDefaultAdministratorRightsTest.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/adminrights/SetMyDefaultAdministratorRightsTest.java index 8a060543..a0fd39b6 100644 --- a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/adminrights/SetMyDefaultAdministratorRightsTest.java +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/adminrights/SetMyDefaultAdministratorRightsTest.java @@ -39,6 +39,13 @@ public class SetMyDefaultAdministratorRightsTest { .rights(ChatAdministratorRights .builder() .isAnonymous(true) + .canManageChat(false) + .canDeleteMessages(false) + .canManageVideoChats(false) + .canRestrictMembers(false) + .canPromoteMembers(true) + .canChangeInfo(true) + .canInviteUsers(false) .build()) .build(); assertEquals("setMyDefaultAdministratorRights", setMyDefaultAdministratorRights.getMethod()); diff --git a/telegrambots-spring-boot-starter/README.md b/telegrambots-spring-boot-starter/README.md index a6e25263..b23762b3 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 - 6.4.0 + 6.5.0 ``` **Gradle** ```gradle - implementation 'org.telegram:telegrambots-spring-boot-starter:6.4.0' + implementation 'org.telegram:telegrambots-spring-boot-starter:6.5.0' ``` Motivation diff --git a/telegrambots-spring-boot-starter/pom.xml b/telegrambots-spring-boot-starter/pom.xml index 28d95491..7103c81e 100644 --- a/telegrambots-spring-boot-starter/pom.xml +++ b/telegrambots-spring-boot-starter/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 6.4.0 + 6.5.0 telegrambots-spring-boot-starter @@ -70,7 +70,7 @@ UTF-8 UTF-8 - 6.4.0 + 6.5.0 2.7.5 1.6 diff --git a/telegrambots-spring-boot-starter/src/main/java/org/telegram/telegrambots/starter/SpringWebhookBot.java b/telegrambots-spring-boot-starter/src/main/java/org/telegram/telegrambots/starter/SpringWebhookBot.java index c271956a..20d2a163 100644 --- a/telegrambots-spring-boot-starter/src/main/java/org/telegram/telegrambots/starter/SpringWebhookBot.java +++ b/telegrambots-spring-boot-starter/src/main/java/org/telegram/telegrambots/starter/SpringWebhookBot.java @@ -11,18 +11,38 @@ import org.telegram.telegrambots.meta.api.objects.Update; * @version 1.0 */ public abstract class SpringWebhookBot extends TelegramWebhookBot { - private SetWebhook setWebhook; + private final SetWebhook setWebhook; + /** + * If this is used getBotToken has to be overridden in order to return the bot token! + * @deprecated Overwriting the getBotToken() method is deprecated. Use the constructor instead + */ + @Deprecated public SpringWebhookBot(SetWebhook setWebhook) { super(); this.setWebhook = setWebhook; } + /** + * If this is used getBotToken has to be overridden in order to return the bot token! + * @deprecated Overwriting the getBotToken() method is deprecated. Use the constructor instead + */ + @Deprecated public SpringWebhookBot(DefaultBotOptions options, SetWebhook setWebhook) { super(options); this.setWebhook = setWebhook; } + public SpringWebhookBot(SetWebhook setWebhook, String botToken) { + super(botToken); + this.setWebhook = setWebhook; + } + + public SpringWebhookBot(DefaultBotOptions options, SetWebhook setWebhook, String botToken) { + super(options, botToken); + this.setWebhook = setWebhook; + } + public SetWebhook getSetWebhook() { return setWebhook; } @@ -30,11 +50,11 @@ public abstract class SpringWebhookBot extends TelegramWebhookBot { public class TestSpringWebhookBot extends SpringWebhookBot { public TestSpringWebhookBot(SetWebhook setWebhook) { - super(setWebhook); + super(setWebhook, null); } public TestSpringWebhookBot(DefaultBotOptions options, SetWebhook setWebhook) { - super(options, setWebhook); + super(options, setWebhook, null); } @Override @@ -42,11 +62,6 @@ public abstract class SpringWebhookBot extends TelegramWebhookBot { return null; } - @Override - public String getBotToken() { - return null; - } - @Override public BotApiMethod onWebhookUpdateReceived(Update update) { return null; diff --git a/telegrambots-spring-boot-starter/src/test/java/org/telegram/telegrambots/starter/TestTelegramBotStarterRegistrationHooks.java b/telegrambots-spring-boot-starter/src/test/java/org/telegram/telegrambots/starter/TestTelegramBotStarterRegistrationHooks.java index fa2e395c..0ce7680d 100644 --- a/telegrambots-spring-boot-starter/src/test/java/org/telegram/telegrambots/starter/TestTelegramBotStarterRegistrationHooks.java +++ b/telegrambots-spring-boot-starter/src/test/java/org/telegram/telegrambots/starter/TestTelegramBotStarterRegistrationHooks.java @@ -14,12 +14,7 @@ import org.telegram.telegrambots.meta.generics.LongPollingBot; import org.telegram.telegrambots.updatesreceivers.DefaultBotSession; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; class TestTelegramBotStarterRegistrationHooks { @@ -72,6 +67,9 @@ class TestTelegramBotStarterRegistrationHooks { } static class AnnotatedLongPollingBot extends TelegramLongPollingBot { + public AnnotatedLongPollingBot() { + super((String) null); + } @Override public void onUpdateReceived(final Update update) { @@ -82,11 +80,6 @@ class TestTelegramBotStarterRegistrationHooks { return null; } - @Override - public String getBotToken() { - return null; - } - @AfterBotRegistration public void afterBotHook() { hookCalled = true; diff --git a/telegrambots/pom.xml b/telegrambots/pom.xml index 48a199ae..b343201b 100644 --- a/telegrambots/pom.xml +++ b/telegrambots/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 6.4.0 + 6.5.0 telegrambots @@ -91,7 +91,7 @@ org.telegram telegrambots-meta - 6.4.0 + 6.5.0 org.projectlombok diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java b/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java index 0a7c24bf..5023a9f3 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java @@ -73,9 +73,20 @@ public abstract class DefaultAbsSender extends AbsSender { private final CloseableHttpClient httpClient; private final RequestConfig requestConfig; private final TelegramFileDownloader telegramFileDownloader; + private final String botToken; + /** + * If this is used getBotToken has to be overridden in order to return the bot token! + * @deprecated Overwriting the getBotToken() method is deprecated. Use the constructor instead + */ + @Deprecated protected DefaultAbsSender(DefaultBotOptions options) { + this(options, null); + } + + protected DefaultAbsSender(DefaultBotOptions options, String botToken) { super(); + this.botToken = botToken; this.exe = Executors.newFixedThreadPool(options.getMaxThreads()); this.options = options; @@ -98,8 +109,12 @@ public abstract class DefaultAbsSender extends AbsSender { /** * Returns the token of the bot to be able to perform Telegram Api Requests * @return Token of the bot + * @deprecated Overriding this method is deprecated. Pass to constructor instead */ - public abstract String getBotToken(); + @Deprecated + public String getBotToken() { + return botToken; + } public final DefaultBotOptions getOptions() { return options; diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingBot.java b/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingBot.java index 4468e52b..ecc9d755 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingBot.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingBot.java @@ -11,14 +11,31 @@ import org.telegram.telegrambots.util.WebhookUtils; * long-polling method */ public abstract class TelegramLongPollingBot extends DefaultAbsSender implements LongPollingBot { + /** + * If this is used getBotToken has to be overridden in order to return the bot token! + * @deprecated Overwriting the getBotToken() method is deprecated. Use the constructor instead + */ + @Deprecated() public TelegramLongPollingBot() { this(new DefaultBotOptions()); } + /** + * If this is used getBotToken has to be overridden in order to return the bot token! + * @deprecated Overwriting the getBotToken() method is deprecated. Use the constructor instead + */ + @Deprecated() public TelegramLongPollingBot(DefaultBotOptions options) { super(options); } + public TelegramLongPollingBot(String botToken) { + this(new DefaultBotOptions(), botToken); + } + public TelegramLongPollingBot(DefaultBotOptions options, String botToken) { + super(options, botToken); + } + @Override public void clearWebhook() throws TelegramApiRequestException { WebhookUtils.clearWebhook(this); diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramWebhookBot.java b/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramWebhookBot.java index 5ddee09b..db05b577 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramWebhookBot.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramWebhookBot.java @@ -13,14 +13,32 @@ import org.telegram.telegrambots.util.WebhookUtils; */ @SuppressWarnings("WeakerAccess") public abstract class TelegramWebhookBot extends DefaultAbsSender implements WebhookBot { + /** + * If this is used getBotToken has to be overridden in order to return the bot token! + * @deprecated Overwriting the getBotToken() method is deprecated. Use the constructor instead + */ + @Deprecated public TelegramWebhookBot() { this(new DefaultBotOptions()); } + /** + * If this is used getBotToken has to be overridden in order to return the bot token! + * @deprecated Overwriting the getBotToken() method is deprecated. Use the constructor instead + */ + @Deprecated public TelegramWebhookBot(DefaultBotOptions options) { super(options); } + public TelegramWebhookBot(String botToken) { + this(new DefaultBotOptions(), botToken); + } + + public TelegramWebhookBot(DefaultBotOptions options, String botToken) { + super(options, botToken); + } + @Override public void setWebhook(SetWebhook setWebhook) throws TelegramApiException { WebhookUtils.setWebhook(this, this, setWebhook); diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/facilities/filedownloader/TelegramFileDownloader.java b/telegrambots/src/main/java/org/telegram/telegrambots/facilities/filedownloader/TelegramFileDownloader.java index 10ba1bfa..b750d17f 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/facilities/filedownloader/TelegramFileDownloader.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/facilities/filedownloader/TelegramFileDownloader.java @@ -25,6 +25,7 @@ import static org.apache.http.HttpStatus.SC_OK; */ public class TelegramFileDownloader { private final HttpClient httpClient; + //TODO Replace with concrete token once deprecations are removed private final Supplier botTokenSupplier; public TelegramFileDownloader(final Supplier botTokenSupplier) { diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/ExponentialBackOff.java b/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/ExponentialBackOff.java index eeed99ae..1786dde7 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/ExponentialBackOff.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/ExponentialBackOff.java @@ -13,7 +13,6 @@ */ package org.telegram.telegrambots.updatesreceivers; -import com.google.common.base.Preconditions; import org.telegram.telegrambots.meta.generics.BackOff; /** @@ -153,11 +152,21 @@ public class ExponentialBackOff implements BackOff { multiplier = builder.multiplier; maxIntervalMillis = builder.maxIntervalMillis; maxElapsedTimeMillis = builder.maxElapsedTimeMillis; - Preconditions.checkArgument(initialIntervalMillis > 0); - Preconditions.checkArgument(0 <= randomizationFactor && randomizationFactor < 1); - Preconditions.checkArgument(multiplier >= 1); - Preconditions.checkArgument(maxIntervalMillis >= initialIntervalMillis); - Preconditions.checkArgument(maxElapsedTimeMillis > 0); + if (initialIntervalMillis <= 0) { + throw new IllegalArgumentException("InitialIntervalMillis must not be negative"); + } + if (maxElapsedTimeMillis <= 0) { + throw new IllegalArgumentException("MaxElapsedTimeMillis must not be negative"); + } + if (multiplier < 1) { + throw new IllegalArgumentException("Multiplier must be bigger than 0"); + } + if (maxIntervalMillis < initialIntervalMillis) { + throw new IllegalArgumentException("InitialIntervalMillis must be smaller or equal maxIntervalMillis"); + } + if (randomizationFactor < 0 || randomizationFactor >= 1) { + throw new IllegalArgumentException("RandomizationFactor must be between 0 and 1"); + } reset(); } @@ -310,4 +319,4 @@ public class ExponentialBackOff implements BackOff { return new ExponentialBackOff(this); } } -} \ No newline at end of file +} diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/util/WebhookUtils.java b/telegrambots/src/main/java/org/telegram/telegrambots/util/WebhookUtils.java index 2a95601d..ade12942 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/util/WebhookUtils.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/util/WebhookUtils.java @@ -2,7 +2,7 @@ package org.telegram.telegrambots.util; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.Strings; +import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpEntity; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.CloseableHttpResponse; @@ -124,7 +124,7 @@ public final class WebhookUtils { externalUrl += "/"; } externalUrl += Constants.WEBHOOK_URL_PATH; - if (!Strings.isNullOrEmpty(botPath)) { + if (StringUtils.isNotEmpty(botPath)) { if (!botPath.startsWith("/")) { externalUrl += "/"; } 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 1a617772..c3070473 100644 --- a/telegrambots/src/test/java/org/telegram/telegrambots/test/TelegramLongPollingBotTest.java +++ b/telegrambots/src/test/java/org/telegram/telegrambots/test/TelegramLongPollingBotTest.java @@ -47,6 +47,10 @@ public class TelegramLongPollingBotTest { private static class TestBot extends TelegramLongPollingBot { + public TestBot() { + super(""); + } + @Override public void onUpdateReceived(Update update) { } @@ -60,10 +64,6 @@ public class TelegramLongPollingBotTest { return ""; } - @Override - public String getBotToken() { - return ""; - } } }