Merge pull request #1007 from rubenlagus/dev

Dev
This commit is contained in:
Ruben Bermudez 2021-12-07 21:18:17 +00:00 committed by GitHub
commit 2663d01761
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 234 additions and 30 deletions

View File

@ -27,18 +27,18 @@ Just import add the library to your project with one of these options:
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>5.4.0.1</version>
<version>5.5.0</version>
</dependency>
```
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`.

View File

@ -1,5 +1,8 @@
### <a id="5.5.0"></a>5.5.0 ###
1. Update Api version [5.5](https://core.telegram.org/bots/api#december-7-2021)
### <a id="5.4.0.1"></a>5.4.0.1 ###
1Bug fixing: #999
1. Bug fixing: #999, #1000
### <a id="5.4.0"></a>5.4.0 ###
1. Update Api version [5.4](https://core.telegram.org/bots/api-changelog#november-5-2021)

View File

@ -11,13 +11,13 @@ First you need ot get the library and add it to your project. There are few poss
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>5.4.0.1</version>
<version>5.5.0</version>
</dependency>
```
* 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).

View File

@ -9,12 +9,12 @@ As with any Java project, you will need to set your dependencies.
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-abilities</artifactId>
<version>5.4.0.1</version>
<version>5.5.0</version>
</dependency>
```
* **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)

View File

@ -7,7 +7,7 @@
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<packaging>pom</packaging>
<version>5.4.0.1</version>
<version>5.5.0</version>
<modules>
<module>telegrambots</module>

View File

@ -18,14 +18,14 @@ Usage
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-abilities</artifactId>
<version>5.4.0.1</version>
<version>5.5.0</version>
</dependency>
```
**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)

View File

@ -7,7 +7,7 @@
<parent>
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<version>5.4.0.1</version>
<version>5.5.0</version>
</parent>
<artifactId>telegrambots-abilities</artifactId>
@ -84,7 +84,7 @@
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>5.4.0.1</version>
<version>5.5.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>

View File

@ -15,14 +15,14 @@ Usage
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-chat-session-bot</artifactId>
<version>5.4.0.1</version>
<version>5.5.0</version>
</dependency>
```
**Gradle**
```gradle
implementation 'org.telegram:telegrambots-chat-session-bot:5.4.0.1'
implementation 'org.telegram:telegrambots-chat-session-bot:5.5.0'
```
Motivation

View File

@ -7,7 +7,7 @@
<parent>
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<version>5.4.0.1</version>
<version>5.5.0</version>
</parent>
<artifactId>telegrambots-chat-session-bot</artifactId>
@ -84,7 +84,7 @@
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>5.4.0.1</version>
<version>5.5.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.shiro/shiro-core -->

View File

@ -16,12 +16,12 @@ Just import add the library to your project with one of these options:
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambotsextensions</artifactId>
<version>5.4.0.1</version>
<version>5.5.0</version>
</dependency>
```
2. Using Gradle:
```gradle
implementation 'org.telegram:telegrambotsextensions:5.4.0.1'
implementation 'org.telegram:telegrambotsextensions:5.5.0'
```

View File

@ -7,7 +7,7 @@
<parent>
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<version>5.4.0.1</version>
<version>5.5.0</version>
</parent>
<artifactId>telegrambotsextensions</artifactId>
@ -75,7 +75,7 @@
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>5.4.0.1</version>
<version>5.5.0</version>
</dependency>
</dependencies>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<version>5.4.0.1</version>
<version>5.5.0</version>
</parent>
<artifactId>telegrambots-meta</artifactId>

View File

@ -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<Boolean> {
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<Boolean> result = OBJECT_MAPPER.readValue(answer,
new TypeReference<ApiResponse<Boolean>>(){});
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);
}
}
}

View File

@ -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<Boolean> {
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<Boolean> result = OBJECT_MAPPER.readValue(answer,
new TypeReference<ApiResponse<Boolean>>(){});
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);
}
}
}

View File

@ -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=<user_id>
* links only in chats with the user.
* Returned only in getChat.
*/
@JsonProperty(HASPRIVATEFORWARDS_FIELD)
private Boolean hasPrivateForwards;
@JsonIgnore
public Boolean isGroupChat() {

View File

@ -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<MessageEntity> getEntities() {
if (entities != null) {

View File

@ -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=<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
/**

View File

@ -18,14 +18,14 @@ Usage
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-spring-boot-starter</artifactId>
<version>5.4.0.1</version>
<version>5.5.0</version>
</dependency>
```
**Gradle**
```gradle
implementation 'org.telegram:telegrambots-spring-boot-starter:5.4.0.1'
implementation 'org.telegram:telegrambots-spring-boot-starter:5.5.0'
```
Motivation

View File

@ -70,7 +70,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<telegrambots.version>5.4.0.1</telegrambots.version>
<telegrambots.version>5.5.0</telegrambots.version>
<spring-boot.version>2.4.5</spring-boot.version>
<maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<version>5.4.0.1</version>
<version>5.5.0</version>
</parent>
<artifactId>telegrambots</artifactId>
@ -92,7 +92,7 @@
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-meta</artifactId>
<version>5.4.0.1</version>
<version>5.5.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>