From 94d528192952899c7067ec113a7bdb440dd794a9 Mon Sep 17 00:00:00 2001 From: Ruben Date: Sun, 14 Nov 2021 23:00:52 +0000 Subject: [PATCH 1/3] Fix changelog --- TelegramBots.wiki/Changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TelegramBots.wiki/Changelog.md b/TelegramBots.wiki/Changelog.md index 71f840e1..9ae10a55 100644 --- a/TelegramBots.wiki/Changelog.md +++ b/TelegramBots.wiki/Changelog.md @@ -1,5 +1,5 @@ ### 5.4.0.1 ### -1Bug fixing: #999 +1Bug fixing: #999, #1000 ### 5.4.0 ### 1. Update Api version [5.4](https://core.telegram.org/bots/api-changelog#november-5-2021) From 2212afc8647441f0a7dfc47c53faf9a5ae28bc6a Mon Sep 17 00:00:00 2001 From: Ruben Date: Sun, 14 Nov 2021 23:01:27 +0000 Subject: [PATCH 2/3] Fix changelog --- TelegramBots.wiki/Changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TelegramBots.wiki/Changelog.md b/TelegramBots.wiki/Changelog.md index 9ae10a55..c1c6207d 100644 --- a/TelegramBots.wiki/Changelog.md +++ b/TelegramBots.wiki/Changelog.md @@ -1,5 +1,5 @@ ### 5.4.0.1 ### -1Bug fixing: #999, #1000 +1. Bug fixing: #999, #1000 ### 5.4.0 ### 1. Update Api version [5.4](https://core.telegram.org/bots/api-changelog#november-5-2021) From 3eea18aef6eb74792a246109013f3369a0dda294 Mon Sep 17 00:00:00 2001 From: Ruben Date: Tue, 7 Dec 2021 21:03:25 +0000 Subject: [PATCH 3/3] Api Version 5.5 --- README.md | 8 +- TelegramBots.wiki/Changelog.md | 3 + TelegramBots.wiki/Getting-Started.md | 4 +- TelegramBots.wiki/abilities/Simple-Example.md | 4 +- pom.xml | 2 +- telegrambots-abilities/README.md | 4 +- telegrambots-abilities/pom.xml | 4 +- telegrambots-chat-session-bot/README.md | 4 +- telegrambots-chat-session-bot/pom.xml | 4 +- telegrambots-extensions/README.md | 4 +- telegrambots-extensions/pom.xml | 4 +- telegrambots-meta/pom.xml | 2 +- .../BanChatSenderChat.java | 98 +++++++++++++++++++ .../unbanChatSenderChat.java | 70 +++++++++++++ .../telegrambots/meta/api/objects/Chat.java | 18 +++- .../meta/api/objects/Message.java | 11 +++ .../buttons/InlineKeyboardButton.java | 8 +- telegrambots-spring-boot-starter/README.md | 4 +- telegrambots-spring-boot-starter/pom.xml | 2 +- telegrambots/pom.xml | 4 +- 20 files changed, 233 insertions(+), 29 deletions(-) create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/BanChatSenderChat.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/unbanChatSenderChat.java diff --git a/README.md b/README.md index 955ab837..d2e03cd0 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.4.0.1 + 5.5.0 ``` 2. Using Gradle: ```gradle - implementation 'org.telegram:telegrambots:5.4.0.1' + implementation 'org.telegram:telegrambots:5.5.0' ``` - 3. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/5.4.0.1) - 4. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/5.4.0.1) + 3. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/5.5.0) + 4. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/5.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 c1c6207d..0546aa32 100644 --- a/TelegramBots.wiki/Changelog.md +++ b/TelegramBots.wiki/Changelog.md @@ -1,3 +1,6 @@ +### 5.5.0 ### +1. Update Api version [5.5](https://core.telegram.org/bots/api#december-7-2021) + ### 5.4.0.1 ### 1. Bug fixing: #999, #1000 diff --git a/TelegramBots.wiki/Getting-Started.md b/TelegramBots.wiki/Getting-Started.md index 62e7c643..f49f51b9 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.4.0.1 + 5.5.0 ``` * With **Gradle**: ```gradle - implementation 'org.telegram:telegrambots:5.4.0.1' + implementation 'org.telegram:telegrambots:5.5.0' ``` 2. Don't like **Maven Central Repository**? It can also be taken from [Jitpack](https://jitpack.io/#rubenlagus/TelegramBots). diff --git a/TelegramBots.wiki/abilities/Simple-Example.md b/TelegramBots.wiki/abilities/Simple-Example.md index 49e00389..31f8f126 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.4.0.1 + 5.5.0 ``` * **Gradle** ```gradle - implementation 'org.telegram:telegrambots-abilities:5.4.0.1' + implementation 'org.telegram:telegrambots-abilities:5.5.0' ``` * [JitPack](https://jitpack.io/#rubenlagus/TelegramBots) diff --git a/pom.xml b/pom.xml index aa39b391..0e4a4a11 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots pom - 5.4.0.1 + 5.5.0 telegrambots diff --git a/telegrambots-abilities/README.md b/telegrambots-abilities/README.md index 4ffad518..24f7af49 100644 --- a/telegrambots-abilities/README.md +++ b/telegrambots-abilities/README.md @@ -18,14 +18,14 @@ Usage org.telegram telegrambots-abilities - 5.4.0.1 + 5.5.0 ``` **Gradle** ```gradle - implementation 'org.telegram:telegrambots-abilities:5.4.0.1' + implementation 'org.telegram:telegrambots-abilities:5.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 c8340363..9a4a3255 100644 --- a/telegrambots-abilities/pom.xml +++ b/telegrambots-abilities/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 5.4.0.1 + 5.5.0 telegrambots-abilities @@ -84,7 +84,7 @@ org.telegram telegrambots - 5.4.0.1 + 5.5.0 org.apache.commons diff --git a/telegrambots-chat-session-bot/README.md b/telegrambots-chat-session-bot/README.md index b164199e..cf7cbc6c 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.4.0.1 + 5.5.0 ``` **Gradle** ```gradle - implementation 'org.telegram:telegrambots-chat-session-bot:5.4.0.1' + implementation 'org.telegram:telegrambots-chat-session-bot:5.5.0' ``` Motivation diff --git a/telegrambots-chat-session-bot/pom.xml b/telegrambots-chat-session-bot/pom.xml index 18e776c1..696e1437 100644 --- a/telegrambots-chat-session-bot/pom.xml +++ b/telegrambots-chat-session-bot/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 5.4.0.1 + 5.5.0 telegrambots-chat-session-bot @@ -84,7 +84,7 @@ org.telegram telegrambots - 5.4.0.1 + 5.5.0 diff --git a/telegrambots-extensions/README.md b/telegrambots-extensions/README.md index 289fd3ab..9dc231be 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.4.0.1 + 5.5.0 ``` 2. Using Gradle: ```gradle - implementation 'org.telegram:telegrambotsextensions:5.4.0.1' + implementation 'org.telegram:telegrambotsextensions:5.5.0' ``` \ No newline at end of file diff --git a/telegrambots-extensions/pom.xml b/telegrambots-extensions/pom.xml index 173fb1e2..52c88453 100644 --- a/telegrambots-extensions/pom.xml +++ b/telegrambots-extensions/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 5.4.0.1 + 5.5.0 telegrambotsextensions @@ -75,7 +75,7 @@ org.telegram telegrambots - 5.4.0.1 + 5.5.0 diff --git a/telegrambots-meta/pom.xml b/telegrambots-meta/pom.xml index b5aefd13..40f67730 100644 --- a/telegrambots-meta/pom.xml +++ b/telegrambots-meta/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 5.4.0.1 + 5.5.0 telegrambots-meta diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/BanChatSenderChat.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/BanChatSenderChat.java new file mode 100644 index 00000000..14086714 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/BanChatSenderChat.java @@ -0,0 +1,98 @@ +package org.telegram.telegrambots.meta.api.methods.groupadministration; + +import com.fasterxml.jackson.annotation.JsonIgnore; +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; +import java.time.Duration; +import java.time.Instant; +import java.time.ZonedDateTime; + +/** + * @author Ruben Bermudez + * @version 5.5 + * Use this method to ban a channel chat in a supergroup or a channel. + * The owner of the chat will not be able to send messages and join live streams on behalf of the chat, unless it is unbanned first. + * The bot must be an administrator in the supergroup or channel for this to work and must have the appropriate administrator rights. + * Returns True on success. + * + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@RequiredArgsConstructor +@AllArgsConstructor +@Builder +public class BanChatSenderChat extends BotApiMethod { + public static final String PATH = "banChatSenderChat"; + + private static final String CHATID_FIELD = "chat_id"; + private static final String SENDER_CHAT_ID_FIELD = "sender_chat_id"; + private static final String UNTILDATE_FIELD = "until_date"; + + @JsonProperty(CHATID_FIELD) + @NonNull + private String chatId; ///< Required. Unique identifier for the chat to send the message to (Or username for channels) + @JsonProperty(SENDER_CHAT_ID_FIELD) + @NonNull + private Long senderChatId; ///< Required. Unique identifier of the target sender chat + /** + * Date when the sender chat will be unbanned, unix time. + * If the chat is banned 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; + + @JsonIgnore + public void setUntilDateInstant(Instant instant) { + setUntilDate((int) instant.getEpochSecond()); + } + + @JsonIgnore + public void setUntilDateDateTime(ZonedDateTime date) { + setUntilDateInstant(date.toInstant()); + } + + @JsonIgnore + public void forTimePeriodDuration(Duration duration) { + setUntilDateInstant(Instant.now().plusMillis(duration.toMillis())); + } + + @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 banning chat sender", 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 (senderChatId == 0) { + throw new TelegramApiValidationException("SenderChatId can't be null or 0", this); + } + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/unbanChatSenderChat.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/unbanChatSenderChat.java new file mode 100644 index 00000000..b33e86bf --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/unbanChatSenderChat.java @@ -0,0 +1,70 @@ +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.5 + * Use this method to unban a previously banned channel chat in a supergroup or channel. + * The bot must be an administrator for this to work and must have the appropriate administrator rights. + * Returns True on success. + * + */ +@EqualsAndHashCode(callSuper = false) +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class unbanChatSenderChat extends BotApiMethod { + public static final String PATH = "unbanChatSenderChat"; + + private static final String CHATID_FIELD = "chat_id"; + private static final String SENDER_CHAT_ID_FIELD = "sender_chat_id"; + + @JsonProperty(CHATID_FIELD) + @NonNull + private String chatId; ///< Required. Unique identifier for the chat to send the message to (Or username for channels) + @JsonProperty(SENDER_CHAT_ID_FIELD) + @NonNull + private Long senderChatId; ///< Required. Unique identifier of the target sender chat + + @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 unbanning chat sender", 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 (senderChatId == 0) { + throw new TelegramApiValidationException("SenderChatId can't be null or 0", this); + } + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Chat.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Chat.java index 80c9926f..73ca0ad3 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Chat.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Chat.java @@ -46,6 +46,8 @@ public class Chat implements BotApiObject { private static final String LINKEDCHATID_FIELD = "linked_chat_id"; private static final String LOCATION_FIELD = "location"; private static final String MESSAGEAUTODELETETIME_FIELD = "message_auto_delete_time"; + private static final String ALLOWSAVINGCONTENT_FIELD = "allow_saving_content"; + private static final String HASPRIVATEFORWARDS_FIELD = "has_private_forwards"; private static final String USERCHATTYPE = "private"; private static final String GROUPCHATTYPE = "group"; @@ -116,7 +118,21 @@ public class Chat implements BotApiObject { private ChatLocation location; ///< Optional. For supergroups, the location to which the supergroup is connected. Returned only in getChat. @JsonProperty(MESSAGEAUTODELETETIME_FIELD) private Integer messageAutoDeleteTime; ///< Optional. The time after which all messages sent to the chat will be automatically deleted; in seconds. Returned only in getChat. - + /** + * Optional. + * True, if messages from the chat can be forwarded to other chats. + * Returned only in getChat. + */ + @JsonProperty(ALLOWSAVINGCONTENT_FIELD) + private Boolean allowSavingContent; + /** + * Optional. + * True, if privacy settings of the other party in the private chat allows to use tg://user?id= + * links only in chats with the user. + * Returned only in getChat. + */ + @JsonProperty(HASPRIVATEFORWARDS_FIELD) + private Boolean hasPrivateForwards; @JsonIgnore public Boolean isGroupChat() { 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 df518fdf..bbedba05 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 @@ -93,6 +93,8 @@ public class Message implements BotApiObject { private static final String VOICECHATENDED_FIELD = "voice_chat_ended"; private static final String VOICECHATPARTICIPANTSINVITED_FIELD = "voice_chat_participants_invited"; private static final String VOICECHATSCHEDULED_FIELD = "voice_chat_scheduled"; + private static final String ISAUTOMATICFORWARD_FIELD = "is_automatic_forward"; + private static final String CANBEFORWARDED_FIELD = "can_be_forwarded"; @JsonProperty(MESSAGEID_FIELD) private Integer messageId; ///< Integer Unique message identifier @@ -270,6 +272,15 @@ public class Message implements BotApiObject { private VoiceChatParticipantsInvited voiceChatParticipantsInvited; ///< Optional. Service message: new members invited to a voice chat @JsonProperty(VOICECHATSCHEDULED_FIELD) private VoiceChatScheduled voiceChatScheduled; ///< Optional. Service message: voice chat scheduled + @JsonProperty(ISAUTOMATICFORWARD_FIELD) + /** + * Optional. + * True, if the message is a channel post that was automatically forwarded to the connected discussion group + */ + private Boolean isAutomaticForward; + @JsonProperty(CANBEFORWARDED_FIELD) + private Boolean canBeForwarded; ///< Optional. True, if the message can be forwarded + public List getEntities() { if (entities != null) { diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/InlineKeyboardButton.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/InlineKeyboardButton.java index 5bee7fb6..4c28478a 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/InlineKeyboardButton.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/InlineKeyboardButton.java @@ -46,8 +46,14 @@ public class InlineKeyboardButton implements Validable, BotApiObject { @JsonProperty(TEXT_FIELD) @NonNull private String text; ///< Label text on the button + /** + * Optional. + * HTTP or tg:// url to be opened when the button is pressed. + * Links tg://user?id= can be used to mention a user by their ID without using a username, + * if this is allowed by their privacy settings. + */ @JsonProperty(URL_FIELD) - private String url; ///< Optional. HTTP or tg:// url to be opened when button is pressed + private String url; @JsonProperty(CALLBACK_DATA_FIELD) private String callbackData; ///< Optional. Data to be sent in a callback query to the bot when button is pressed /** diff --git a/telegrambots-spring-boot-starter/README.md b/telegrambots-spring-boot-starter/README.md index 59868916..5922a78a 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.4.0.1 + 5.5.0 ``` **Gradle** ```gradle - implementation 'org.telegram:telegrambots-spring-boot-starter:5.4.0.1' + implementation 'org.telegram:telegrambots-spring-boot-starter:5.5.0' ``` Motivation diff --git a/telegrambots-spring-boot-starter/pom.xml b/telegrambots-spring-boot-starter/pom.xml index 32aca79a..cec62f25 100644 --- a/telegrambots-spring-boot-starter/pom.xml +++ b/telegrambots-spring-boot-starter/pom.xml @@ -70,7 +70,7 @@ UTF-8 UTF-8 - 5.4.0.1 + 5.5.0 2.4.5 1.6 diff --git a/telegrambots/pom.xml b/telegrambots/pom.xml index dd894247..3e498d15 100644 --- a/telegrambots/pom.xml +++ b/telegrambots/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 5.4.0.1 + 5.5.0 telegrambots @@ -92,7 +92,7 @@ org.telegram telegrambots-meta - 5.4.0.1 + 5.5.0 org.projectlombok