diff --git a/.travis.yml b/.travis.yml index 168ea153..aed4b309 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,10 @@ notifications: secure: "jC7dK/x67ONWQoeLZg4HfW0mHhcjDerJjsLLkrbcpltiqAbw2p7XfY8Pk4zHoD72a+5o6WKu5WvYvZ4OdldnjP8Y6ZUbliQ5RG3olg3gFDoe0+sc3geeb4HRYVcdI20O0z4Bup/qO0ZihxPBc0D5IpHmFxlaqlZG0WeST4CicU8PNnBh6aX9/VMrwXhkMb2vfzmjmIhMbx/uK5+93bnk/vR5Uwu00/Yd2cTAAWMaqK1MRdtR0WLbxlUNsprEfCjYiH3n9XZnlKXs6cLC8EOU436Wx7aepiAszW0wWFMe/7nVqOqztrQiKNvL0qXYwlQf0BLechJdt458EopL9QCu687TNDFYvg1yERAmCRiaayYZcX3PbUSMr6H5Q+Odntjs3XKyzfgSqqlkgf/SAND5jny1/1uteVoplZmFXuZFIiK4H8Rl2ezy1/8pnbp+JD3YEfiA2NuRjlou1BZXyMhiqqVXbrJqk/tXF6yZSkDlYJfNsWzRCGfra4B6JjEvUP927chIFm1ii3dgNstXDo1evV46+OQQO4HKvMPdtU2FPvWpPlkTxnmpZRZjB+bjmybluJdWT3E+e1C3wm7YbRe3vporhpfNPlnod6M0G10y9CKzl9Fbcku6X1FtM+IoPO/aqZ8S4/CBZoYEuR/Nk6bcvsYouxtyIl6PSuF9E8YjpJE=" email: false matrix: + fast_finish: true allow_failures: - jdk: openjdk-ea - - jdk: oraclejdk-ea \ No newline at end of file + - jdk: oraclejdk-ea +cache: + directories: + - $HOME/.m2 diff --git a/README.md b/README.md index a4dfc65a..bd7ce472 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 - 5.3.0 + 5.4.0 ``` 2. Using Gradle: ```gradle - implementation 'org.telegram:telegrambots:5.3.0' + implementation 'org.telegram:telegrambots:5.4.0' ``` - 3. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/5.3.0) - 4. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/5.3.0) + 3. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/5.4.0) + 4. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/5.4.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 84e30ef5..388a2aae 100644 --- a/TelegramBots.wiki/Changelog.md +++ b/TelegramBots.wiki/Changelog.md @@ -1,3 +1,7 @@ +### 5.3.0 ### +1. Update Api version [5.4](https://core.telegram.org/bots/api-changelog#november-4-2021) +2. Bug fixing: #968, #958, #942 + ### 5.3.0 ### 1. Update Api version [5.3](https://core.telegram.org/bots/api-changelog#june-25-2021) 2. `KeyboardRow` now support creation from a collection of buttons. diff --git a/TelegramBots.wiki/Getting-Started.md b/TelegramBots.wiki/Getting-Started.md index 7ebb0299..97b8333f 100644 --- a/TelegramBots.wiki/Getting-Started.md +++ b/TelegramBots.wiki/Getting-Started.md @@ -11,13 +11,13 @@ First you need ot get the library and add it to your project. There are few poss org.telegram telegrambots - 5.3.0 + 5.4.0 ``` * With **Gradle**: ```gradle - implementation 'org.telegram:telegrambots:5.3.0' + implementation 'org.telegram:telegrambots:5.4.0' ``` 2. Don't like **Maven Central Repository**? It can also be taken from [Jitpack](https://jitpack.io/#rubenlagus/TelegramBots). diff --git a/TelegramBots.wiki/Using-Http-Proxy.md b/TelegramBots.wiki/Using-Http-Proxy.md index ea0833d5..69af1886 100644 --- a/TelegramBots.wiki/Using-Http-Proxy.md +++ b/TelegramBots.wiki/Using-Http-Proxy.md @@ -48,7 +48,7 @@ public class Main { TelegramBotsApi botsApi = new TelegramBotsApi(DefaultBotSessioin.class); // Set up Http proxy - DefaultBotOptions botOptions = new DefaultBotOptions()); + DefaultBotOptions botOptions = new DefaultBotOptions(); botOptions.setProxyHost(PROXY_HOST); botOptions.setProxyPort(PROXY_PORT); diff --git a/TelegramBots.wiki/abilities/Simple-Example.md b/TelegramBots.wiki/abilities/Simple-Example.md index da3736ca..7e1aa2f4 100644 --- a/TelegramBots.wiki/abilities/Simple-Example.md +++ b/TelegramBots.wiki/abilities/Simple-Example.md @@ -9,12 +9,12 @@ As with any Java project, you will need to set your dependencies. org.telegram telegrambots-abilities - 5.3.0 + 5.4.0 ``` * **Gradle** ```gradle - implementation 'org.telegram:telegrambots-abilities:5.3.0' + implementation 'org.telegram:telegrambots-abilities:5.4.0' ``` * [JitPack](https://jitpack.io/#rubenlagus/TelegramBots) diff --git a/pom.xml b/pom.xml index 1157e0cf..8e3715c3 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots pom - 5.3.0 + 5.4.0 telegrambots diff --git a/telegrambots-abilities/README.md b/telegrambots-abilities/README.md index 72c359e6..b869afae 100644 --- a/telegrambots-abilities/README.md +++ b/telegrambots-abilities/README.md @@ -18,14 +18,14 @@ Usage org.telegram telegrambots-abilities - 5.3.0 + 5.4.0 ``` **Gradle** ```gradle - implementation 'org.telegram:telegrambots-abilities:5.3.0' + implementation 'org.telegram:telegrambots-abilities:5.4.0' ``` **JitPack** - [JitPack](https://jitpack.io/#rubenlagus/TelegramBots/v5.0.1) diff --git a/telegrambots-abilities/pom.xml b/telegrambots-abilities/pom.xml index 68afd8cb..bf1ae158 100644 --- a/telegrambots-abilities/pom.xml +++ b/telegrambots-abilities/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 5.3.0 + 5.4.0 telegrambots-abilities @@ -84,7 +84,7 @@ org.telegram telegrambots - 5.3.0 + 5.4.0 org.apache.commons 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 4bf4a804..e8297590 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 @@ -265,10 +265,10 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability .orElse(new ArrayList<>()) .stream() .map(member -> { - if (member instanceof ChatMemberAdministrator) { - return ((ChatMemberAdministrator) member).getUser().getId(); - } else if (member instanceof ChatMemberOwner) { - return ((ChatMemberOwner) member).getUser().getId(); + final String status = member.getStatus(); + if (status.equals(ChatMemberOwner.STATUS) + || status.equals(ChatMemberAdministrator.STATUS)) { + return member.getUser().getId(); } return 0L; }) diff --git a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/objects/Flag.java b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/objects/Flag.java index 414d08da..8b2303b5 100644 --- a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/objects/Flag.java +++ b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/objects/Flag.java @@ -31,6 +31,7 @@ public enum Flag implements Predicate { POLL_ANSWER(Update::hasPollAnswer), MY_CHAT_MEMBER(Update::hasMyChatMember), CHAT_MEMBER(Update::hasChatMember), + CHAT_JOIN_REQUEST(Update::hasChatJoinRequest), // Message Flags diff --git a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/util/AbilityUtils.java b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/util/AbilityUtils.java index 013ba41d..39f0f210 100644 --- a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/util/AbilityUtils.java +++ b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/util/AbilityUtils.java @@ -86,6 +86,8 @@ public final class AbilityUtils { return update.getMyChatMember().getFrom(); } else if (CHAT_MEMBER.test(update)) { return update.getChatMember().getFrom(); + } else if (CHAT_JOIN_REQUEST.test(update)) { + return update.getChatJoinRequest().getUser(); } else if (POLL.test(update)) { return EMPTY_USER; } else { @@ -171,6 +173,8 @@ public final class AbilityUtils { return update.getMyChatMember().getChat().getId(); } else if (CHAT_MEMBER.test(update)) { return update.getChatMember().getChat().getId(); + } else if (CHAT_JOIN_REQUEST.test(update)) { + return update.getChatJoinRequest().getChat().getId(); } else { throw new IllegalStateException("Could not retrieve originating chat ID from update"); } diff --git a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotTest.java b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotTest.java index ba2f24ed..17edd4de 100644 --- a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotTest.java +++ b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotTest.java @@ -26,6 +26,7 @@ import org.telegram.telegrambots.meta.api.objects.File; import org.telegram.telegrambots.meta.api.objects.Message; import org.telegram.telegrambots.meta.api.objects.Update; import org.telegram.telegrambots.meta.api.objects.User; +import org.telegram.telegrambots.meta.api.objects.chatmember.ChatMember; import org.telegram.telegrambots.meta.api.objects.chatmember.ChatMemberAdministrator; import org.telegram.telegrambots.meta.exceptions.TelegramApiException; @@ -453,8 +454,8 @@ public class AbilityBotTest { mockUser(update, message, user); when(message.isGroupMessage()).thenReturn(true); - ChatMemberAdministrator member = mock(ChatMemberAdministrator.class); - when(member.getUser()).thenReturn(user); + ChatMember member = mock(ChatMember.class); + when(member.getStatus()).thenReturn(ChatMemberAdministrator.STATUS); when(member.getUser()).thenReturn(user); when(silent.execute(any(GetChatAdministrators.class))).thenReturn(Optional.of(newArrayList(member))); diff --git a/telegrambots-chat-session-bot/README.md b/telegrambots-chat-session-bot/README.md index 5b44068c..07c4ad09 100644 --- a/telegrambots-chat-session-bot/README.md +++ b/telegrambots-chat-session-bot/README.md @@ -15,14 +15,14 @@ Usage org.telegram telegrambots-chat-session-bot - 5.3.0 + 5.4.0 ``` **Gradle** ```gradle - implementation 'org.telegram:telegrambots-chat-session-bot:5.3.0' + implementation 'org.telegram:telegrambots-chat-session-bot:5.4.0' ``` Motivation diff --git a/telegrambots-chat-session-bot/pom.xml b/telegrambots-chat-session-bot/pom.xml index 3df975e7..36f5df43 100644 --- a/telegrambots-chat-session-bot/pom.xml +++ b/telegrambots-chat-session-bot/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 5.3.0 + 5.4.0 telegrambots-chat-session-bot @@ -76,7 +76,7 @@ UTF-8 UTF-8 - 1.7.0 + 1.8.0 @@ -84,7 +84,7 @@ org.telegram telegrambots - 5.3.0 + 5.4.0 diff --git a/telegrambots-extensions/README.md b/telegrambots-extensions/README.md index eb620d4d..8c55e16d 100644 --- a/telegrambots-extensions/README.md +++ b/telegrambots-extensions/README.md @@ -16,12 +16,12 @@ Just import add the library to your project with one of these options: org.telegram telegrambotsextensions - 5.3.0 + 5.4.0 ``` 2. Using Gradle: ```gradle - implementation 'org.telegram:telegrambotsextensions:5.3.0' + implementation 'org.telegram:telegrambotsextensions:5.4.0' ``` \ No newline at end of file diff --git a/telegrambots-extensions/pom.xml b/telegrambots-extensions/pom.xml index a8968c88..f95690e1 100644 --- a/telegrambots-extensions/pom.xml +++ b/telegrambots-extensions/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 5.3.0 + 5.4.0 telegrambotsextensions @@ -75,7 +75,7 @@ org.telegram telegrambots - 5.3.0 + 5.4.0 diff --git a/telegrambots-meta/pom.xml b/telegrambots-meta/pom.xml index 156a8c33..d753c26b 100644 --- a/telegrambots-meta/pom.xml +++ b/telegrambots-meta/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 5.3.0 + 5.4.0 telegrambots-meta diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/ApproveChatJoinRequest.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/ApproveChatJoinRequest.java new file mode 100644 index 00000000..9972477c --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/ApproveChatJoinRequest.java @@ -0,0 +1,69 @@ +package org.telegram.telegrambots.meta.api.methods.groupadministration; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.type.TypeReference; +import lombok.*; +import org.telegram.telegrambots.meta.api.methods.BotApiMethod; +import org.telegram.telegrambots.meta.api.objects.ApiResponse; +import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +import java.io.IOException; + +/** + * @author Ruben Bermudez + * @version 5.4 + * Use this method to approve a chat join request. + * The bot must be an administrator in the chat for this to work and must have the can_invite_users admin right. + * Returns True on success. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@RequiredArgsConstructor +@Builder +public class ApproveChatJoinRequest extends BotApiMethod { + public static final String PATH = "approveChatJoinRequest"; + + private static final String CHATID_FIELD = "chat_id"; + private static final String USERID_FIELD = "user_id"; + + @JsonProperty(CHATID_FIELD) + @NonNull + private String chatId; ///< Required. Unique identifier for the target chat or username of the target channel (in the format @channelusername) + @JsonProperty(USERID_FIELD) + @NonNull + private Long userId; ///< Required. Unique identifier of the target user + + @Override + public String getMethod() { + return PATH; + } + + @Override + public Boolean deserializeResponse(String answer) throws TelegramApiRequestException { + try { + ApiResponse result = OBJECT_MAPPER.readValue(answer, + new TypeReference>(){}); + if (result.getOk()) { + return result.getResult(); + } else { + throw new TelegramApiRequestException("Error approving chat join request", result); + } + } catch (IOException e) { + throw new TelegramApiRequestException("Unable to deserialize response", e); + } + } + + @Override + public void validate() throws TelegramApiValidationException { + if (chatId.isEmpty()) { + throw new TelegramApiValidationException("ChatId can't be empty", this); + } + if (userId == 0) { + throw new TelegramApiValidationException("UserId can't be null or 0", this); + } + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/CreateChatInviteLink.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/CreateChatInviteLink.java index 1daad76f..124e600a 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/CreateChatInviteLink.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/CreateChatInviteLink.java @@ -43,6 +43,8 @@ public class CreateChatInviteLink extends BotApiMethod { private static final String CHATID_FIELD = "chat_id"; private static final String EXPIREDATE_FIELD = "expire_date"; private static final String MEMBERLIMIT_FIELD = "member_limit"; + private static final String NAME_FIELD = "name"; + private static final String CREATESJOINREQUEST_FIELD = "creates_join_request"; @JsonProperty(CHATID_FIELD) @NonNull @@ -55,7 +57,17 @@ public class CreateChatInviteLink extends BotApiMethod { * Maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999 */ @JsonProperty(MEMBERLIMIT_FIELD) - private Integer memberLimit; + private Integer memberLimit; ///< Optional. Invite link name; 0-32 characters + @JsonProperty(NAME_FIELD) + private String name; ///< Optional. Invite link name; 0-32 characters + /** + * Optional. + * + * True, if users joining the chat via the link need to be approved by chat administrators. + * If True, member_limit can't be specified + */ + @JsonProperty(CREATESJOINREQUEST_FIELD) + private Boolean createsJoinRequest; @Override @@ -80,9 +92,15 @@ public class CreateChatInviteLink extends BotApiMethod { @Override public void validate() throws TelegramApiValidationException { - if (chatId == null || chatId.isEmpty()) { + if (chatId.isEmpty()) { throw new TelegramApiValidationException("ChatId can't be empty", this); } + if (name != null && name.length() > 32) { + throw new TelegramApiValidationException("Name must be between 0 and 32 characters", this); + } + if (createsJoinRequest != null && memberLimit != null) { + throw new TelegramApiValidationException("MemberLimit can not be used with CreatesJoinRequest field", this); + } if (memberLimit != null && (memberLimit < 1 || memberLimit > 99999)) { throw new TelegramApiValidationException("MemberLimit must be between 1 and 99999", this); } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/DeclineChatJoinRequest.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/DeclineChatJoinRequest.java new file mode 100644 index 00000000..97c47cbb --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/DeclineChatJoinRequest.java @@ -0,0 +1,69 @@ +package org.telegram.telegrambots.meta.api.methods.groupadministration; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.type.TypeReference; +import lombok.*; +import org.telegram.telegrambots.meta.api.methods.BotApiMethod; +import org.telegram.telegrambots.meta.api.objects.ApiResponse; +import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +import java.io.IOException; + +/** + * @author Ruben Bermudez + * @version 5.4 + * Use this method to decline a chat join request. + * The bot must be an administrator in the chat for this to work and must have the can_invite_users admin right. + * Returns True on success. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@RequiredArgsConstructor +@Builder +public class DeclineChatJoinRequest extends BotApiMethod { + public static final String PATH = "declineChatJoinRequest"; + + private static final String CHATID_FIELD = "chat_id"; + private static final String USERID_FIELD = "user_id"; + + @JsonProperty(CHATID_FIELD) + @NonNull + private String chatId; ///< Required. Unique identifier for the target chat or username of the target channel (in the format @channelusername) + @JsonProperty(USERID_FIELD) + @NonNull + private Long userId; ///< Required. Unique identifier of the target user + + @Override + public String getMethod() { + return PATH; + } + + @Override + public Boolean deserializeResponse(String answer) throws TelegramApiRequestException { + try { + ApiResponse result = OBJECT_MAPPER.readValue(answer, + new TypeReference>(){}); + if (result.getOk()) { + return result.getResult(); + } else { + throw new TelegramApiRequestException("Error declining chat join request", result); + } + } catch (IOException e) { + throw new TelegramApiRequestException("Unable to deserialize response", e); + } + } + + @Override + public void validate() throws TelegramApiValidationException { + if (chatId.isEmpty()) { + throw new TelegramApiValidationException("ChatId can't be empty", this); + } + if (userId == 0) { + throw new TelegramApiValidationException("UserId can't be null or 0", this); + } + } +} 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 18b617d6..014101df 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 @@ -45,6 +45,8 @@ public class EditChatInviteLink extends BotApiMethod { private static final String INVITELINK_FIELD = "invite_link"; private static final String EXPIREDATE_FIELD = "expire_date"; private static final String MEMBERLIMIT_FIELD = "member_limit"; + private static final String NAME_FIELD = "name"; + private static final String CREATESJOINREQUEST_FIELD = "creates_join_request"; @JsonProperty(CHATID_FIELD) @NonNull @@ -61,6 +63,16 @@ public class EditChatInviteLink extends BotApiMethod { */ @JsonProperty(MEMBERLIMIT_FIELD) private Integer memberLimit; + @JsonProperty(NAME_FIELD) + private String name; ///< Optional. Invite link name; 0-32 characters + /** + * Optional. + * + * True, if users joining the chat via the link need to be approved by chat administrators. + * If True, member_limit can't be specified + */ + @JsonProperty(CREATESJOINREQUEST_FIELD) + private Boolean createsJoinRequest; @Override @@ -91,6 +103,12 @@ public class EditChatInviteLink extends BotApiMethod { if (Strings.isNullOrEmpty(inviteLink)) { throw new TelegramApiValidationException("InviteLink can't be empty", this); } + if (name != null && name.length() > 32) { + throw new TelegramApiValidationException("Name must be between 0 and 32 characters", this); + } + if (createsJoinRequest != null && memberLimit != null) { + throw new TelegramApiValidationException("MemberLimit can not be used with CreatesJoinRequest field", this); + } if (memberLimit != null && (memberLimit < 1 || memberLimit > 99999)) { throw new TelegramApiValidationException("MemberLimit must be between 1 and 99999", this); } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendChatAction.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendChatAction.java index a821cd65..1e688945 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendChatAction.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendChatAction.java @@ -44,10 +44,16 @@ public class SendChatAction extends BotApiMethod { @NonNull private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels) /** - * Type of action to broadcast. Choose one, depending on what the user is about to receive: typing for text messages, - * upload_photo for photos, record_video or upload_video for videos, record_audio or upload_audio for audio files, - * upload_document for general files, find_location for location data, - * record_video_note or upload_video_note for video notes. + * Type of action to broadcast. Choose one, depending on what the user is about to receive: + * typing for text messages + * upload_photo for photos + * record_video or upload_video for videos + * record_voice or upload_voice for voice notes + * upload_document for general files + * choose_sticker for stickers + * find_location for location data + * record_video_note + * upload_video_note for video notes */ @JsonProperty(ACTION_FIELD) @NonNull @@ -85,10 +91,10 @@ public class SendChatAction extends BotApiMethod { @Override public void validate() throws TelegramApiValidationException { - if (chatId == null || chatId.isEmpty()) { + if (chatId.isEmpty()) { throw new TelegramApiValidationException("ChatId parameter can't be empty", this); } - if (action == null) { + if (action.isEmpty()) { throw new TelegramApiValidationException("Action parameter can't be empty", this); } } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatInviteLink.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatInviteLink.java index 9ebc4210..5c7f49f2 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatInviteLink.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatInviteLink.java @@ -28,6 +28,9 @@ public class ChatInviteLink implements BotApiObject { private static final String ISREVOKED_FIELD = "is_revoked"; private static final String EXPIREDATE_FIELD = "expire_date"; private static final String MEMBERLIMIT_FIELD = "member_limit"; + private static final String NAME_FIELD = "name"; + private static final String PENDINGJOINREQUESTCOUNT_FIELD = "pending_join_request_count"; + private static final String CREATESJOINREQUEST_FIELD = "creates_join_request"; /** * The invite link. @@ -50,4 +53,13 @@ public class ChatInviteLink implements BotApiObject { */ @JsonProperty(MEMBERLIMIT_FIELD) private Integer memberLimit; + @JsonProperty(NAME_FIELD) + private String name; ///< Optional. Invite link name + @JsonProperty(PENDINGJOINREQUESTCOUNT_FIELD) + private Integer pendingJoinRequestCount; ///< Optional. Number of pending join requests created using this link + /** + * True, if users joining the chat via the link need to be approved by chat administrators + */ + @JsonProperty(CREATESJOINREQUEST_FIELD) + private Boolean createsJoinRequest; } 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 new file mode 100644 index 00000000..7eba4c79 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatJoinRequest.java @@ -0,0 +1,37 @@ +package org.telegram.telegrambots.meta.api.objects; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; + +/** + * @author Ruben Bermudez + * @version 5.4 + * + * Represents a join request sent to a chat. + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +public class ChatJoinRequest implements BotApiObject { + private static final String CHAT_FIELD = "chat"; + private static final String FROM_FIELD = "from"; + private static final String DATE_FIELD = "date"; + private static final String BIO_FIELD = "bio"; + private static final String INVITELINK_FIELD = "invite_link"; + + + @JsonProperty(CHAT_FIELD) + private Chat chat; ///< Chat to which the request was sent + @JsonProperty(FROM_FIELD) + private User user; ///< User that sent the join request + @JsonProperty(DATE_FIELD) + private Integer date; ///< Date the request was sent in Unix time + @JsonProperty(BIO_FIELD) + private String bio; ///< Optional. Bio of the user. + @JsonProperty(INVITELINK_FIELD) + private String inviteLink; ///< Optional. Chat invite link that was used by the user to send the join request +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Update.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Update.java index d56697f9..fd0e63e1 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Update.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Update.java @@ -44,6 +44,7 @@ public class Update implements BotApiObject { private static final String POLLANSWER_FIELD = "poll_answer"; private static final String MYCHATMEMBER_FIELD = "my_chat_member"; private static final String CHATMEMBER_FIELD = "chat_member"; + private static final String CHATJOINREQUEST_FIELD = "chat_join_request"; @JsonProperty(UPDATEID_FIELD) private Integer updateId; @@ -91,6 +92,8 @@ public class Update implements BotApiObject { */ @JsonProperty(CHATMEMBER_FIELD) private ChatMemberUpdated chatMember; + @JsonProperty(CHATJOINREQUEST_FIELD) + private ChatJoinRequest chatJoinRequest; public boolean hasMessage() { return message != null; @@ -143,4 +146,8 @@ public class Update implements BotApiObject { public boolean hasChatMember() { return chatMember != null; } + + public boolean hasChatJoinRequest() { + return chatJoinRequest != null; + } } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMember.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMember.java index 30b86947..e9d38cab 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMember.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMember.java @@ -2,6 +2,7 @@ package org.telegram.telegrambots.meta.api.objects.chatmember; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import org.telegram.telegrambots.meta.api.objects.User; import org.telegram.telegrambots.meta.api.objects.chatmember.serialization.ChatMemberDeserializer; /** @@ -14,4 +15,5 @@ import org.telegram.telegrambots.meta.api.objects.chatmember.serialization.ChatM @JsonDeserialize(using = ChatMemberDeserializer.class) public interface ChatMember extends BotApiObject { String getStatus(); + User getUser(); } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMemberAdministrator.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMemberAdministrator.java index dc3a7c8c..c8ca7056 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMemberAdministrator.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMemberAdministrator.java @@ -26,6 +26,8 @@ import org.telegram.telegrambots.meta.api.objects.User; @AllArgsConstructor @Builder public class ChatMemberAdministrator implements ChatMember { + public static final String STATUS = "administrator"; + private static final String STATUS_FIELD = "status"; private static final String USER_FIELD = "user"; private static final String CANBEEDITED_FIELD = "can_be_edited"; @@ -46,7 +48,7 @@ public class ChatMemberAdministrator implements ChatMember { * The member's status in the chat, always “administrator” */ @JsonProperty(STATUS_FIELD) - private final String status = "administrator"; + private final String status = STATUS; /** * Information about the user */ diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMemberBanned.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMemberBanned.java index becee325..205181a1 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMemberBanned.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMemberBanned.java @@ -26,6 +26,8 @@ import org.telegram.telegrambots.meta.api.objects.User; @AllArgsConstructor @Builder public class ChatMemberBanned implements ChatMember { + public static final String STATUS = "kicked"; + private static final String STATUS_FIELD = "status"; private static final String USER_FIELD = "user"; private static final String UNTILDATE_FIELD = "until_date"; @@ -34,7 +36,7 @@ public class ChatMemberBanned implements ChatMember { * The member's status in the chat, always “kicked” */ @JsonProperty(STATUS_FIELD) - private final String status = "kicked"; + private final String status = STATUS; /** * Information about the user */ diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMemberLeft.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMemberLeft.java index c93da1e2..c05303a8 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMemberLeft.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMemberLeft.java @@ -26,6 +26,8 @@ import org.telegram.telegrambots.meta.api.objects.User; @AllArgsConstructor @Builder public class ChatMemberLeft implements ChatMember { + public static final String STATUS = "left"; + private static final String STATUS_FIELD = "status"; private static final String USER_FIELD = "user"; @@ -33,7 +35,7 @@ public class ChatMemberLeft implements ChatMember { * The member's status in the chat, always “left” */ @JsonProperty(STATUS_FIELD) - private final String status = "left"; + private final String status = STATUS; /** * Information about the user */ diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMemberMember.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMemberMember.java index 8227179b..12cbafb1 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMemberMember.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMemberMember.java @@ -26,6 +26,8 @@ import org.telegram.telegrambots.meta.api.objects.User; @AllArgsConstructor @Builder public class ChatMemberMember implements ChatMember { + public static final String STATUS = "member"; + private static final String STATUS_FIELD = "status"; private static final String USER_FIELD = "user"; @@ -33,7 +35,7 @@ public class ChatMemberMember implements ChatMember { * The member's status in the chat, always “member” */ @JsonProperty(STATUS_FIELD) - private final String status = "member"; + private final String status = STATUS; /** * Information about the user */ diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMemberOwner.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMemberOwner.java index ae1c97c5..f77a733e 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMemberOwner.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/chatmember/ChatMemberOwner.java @@ -26,6 +26,8 @@ import org.telegram.telegrambots.meta.api.objects.User; @AllArgsConstructor @Builder public class ChatMemberOwner implements ChatMember { + public static final String STATUS = "creator"; + private static final String STATUS_FIELD = "status"; private static final String USER_FIELD = "user"; private static final String CUSTOMTITLE_FIELD = "custom_title"; @@ -35,7 +37,7 @@ public class ChatMemberOwner implements ChatMember { * The member's status in the chat, always “creator” */ @JsonProperty(STATUS_FIELD) - private final String status = "creator"; + private final String status = STATUS; /** * Information about the user */ 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 02b3dcf1..b98ae180 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 @@ -26,6 +26,8 @@ import org.telegram.telegrambots.meta.api.objects.User; @AllArgsConstructor @Builder public class ChatMemberRestricted implements ChatMember { + public static final String STATUS = "restricted"; + private static final String STATUS_FIELD = "status"; private static final String USER_FIELD = "user"; private static final String ISMEMBER_FIELD = "is_member"; @@ -43,7 +45,7 @@ public class ChatMemberRestricted implements ChatMember { * The member's status in the chat, always “restricted” */ @JsonProperty(STATUS_FIELD) - private final String status = "restricted"; + private final String status = STATUS; /** * Information about the user */ diff --git a/telegrambots-spring-boot-starter/README.md b/telegrambots-spring-boot-starter/README.md index ede37898..f4ab20e7 100644 --- a/telegrambots-spring-boot-starter/README.md +++ b/telegrambots-spring-boot-starter/README.md @@ -18,14 +18,14 @@ Usage org.telegram telegrambots-spring-boot-starter - 5.3.0 + 5.4.0 ``` **Gradle** ```gradle - implementation 'org.telegram:telegrambots-spring-boot-starter:5.3.0' + implementation 'org.telegram:telegrambots-spring-boot-starter:5.4.0' ``` Motivation diff --git a/telegrambots-spring-boot-starter/pom.xml b/telegrambots-spring-boot-starter/pom.xml index 0f3d09b9..81cde1c6 100644 --- a/telegrambots-spring-boot-starter/pom.xml +++ b/telegrambots-spring-boot-starter/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 5.3.0 + 5.4.0 telegrambots-spring-boot-starter @@ -70,7 +70,7 @@ UTF-8 UTF-8 - 5.3.0 + 5.4.0 2.4.5 1.6 diff --git a/telegrambots/pom.xml b/telegrambots/pom.xml index 301e6bc5..89fe45f4 100644 --- a/telegrambots/pom.xml +++ b/telegrambots/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 5.3.0 + 5.4.0 telegrambots @@ -92,7 +92,7 @@ org.telegram telegrambots-meta - 5.3.0 + 5.4.0 org.projectlombok