Api Version 5.4

This commit is contained in:
Ruben 2021-11-06 14:52:47 +00:00
parent eeff4d3ae6
commit eef0681ddf
24 changed files with 279 additions and 36 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.3.0</version>
<version>5.4.0</version>
</dependency>
```
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`.

View File

@ -1,3 +1,7 @@
### <a id="5.4.0"></a>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
### <a id="5.3.0"></a>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.

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.3.0</version>
<version>5.4.0</version>
</dependency>
```
* 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).

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.3.0</version>
<version>5.4.0</version>
</dependency>
```
* **Gradle**
```gradle
implementation 'org.telegram:telegrambots-abilities:5.3.0'
implementation 'org.telegram:telegrambots-abilities:5.4.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.3.0</version>
<version>5.4.0</version>
<modules>
<module>telegrambots</module>

View File

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

View File

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

View File

@ -31,6 +31,7 @@ public enum Flag implements Predicate<Update> {
POLL_ANSWER(Update::hasPollAnswer),
MY_CHAT_MEMBER(Update::hasMyChatMember),
CHAT_MEMBER(Update::hasChatMember),
HAS_CHAT_JOIN_REQUEST(Update::hasChatJoinRequest),
// Message Flags

View File

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

View File

@ -7,7 +7,7 @@
<parent>
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<version>5.3.0</version>
<version>5.4.0</version>
</parent>
<artifactId>telegrambots-chat-session-bot</artifactId>
@ -84,7 +84,7 @@
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>5.3.0</version>
<version>5.4.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.3.0</version>
<version>5.4.0</version>
</dependency>
```
2. Using Gradle:
```gradle
implementation 'org.telegram:telegrambotsextensions:5.3.0'
implementation 'org.telegram:telegrambotsextensions:5.4.0'
```

View File

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

View File

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

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.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
@AllArgsConstructor
@Builder
public class ApproveChatJoinRequest extends BotApiMethod<Boolean> {
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<Boolean> result = OBJECT_MAPPER.readValue(answer,
new TypeReference<ApiResponse<Boolean>>(){});
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);
}
}
}

View File

@ -43,6 +43,8 @@ public class CreateChatInviteLink extends BotApiMethod<ChatInviteLink> {
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<ChatInviteLink> {
* 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<ChatInviteLink> {
@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);
}

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.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
@AllArgsConstructor
@Builder
public class DeclineChatJoinRequest extends BotApiMethod<Boolean> {
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<Boolean> result = OBJECT_MAPPER.readValue(answer,
new TypeReference<ApiResponse<Boolean>>(){});
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);
}
}
}

View File

@ -45,6 +45,8 @@ public class EditChatInviteLink extends BotApiMethod<ChatInviteLink> {
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<ChatInviteLink> {
*/
@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<ChatInviteLink> {
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);
}

View File

@ -44,10 +44,16 @@ public class SendChatAction extends BotApiMethod<Boolean> {
@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<Boolean> {
@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);
}
}

View File

@ -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 = "member_limit";
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;
}

View File

@ -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
}

View File

@ -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;
}
}

View File

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

View File

@ -7,7 +7,7 @@
<parent>
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<version>5.3.0</version>
<version>5.4.0</version>
</parent>
<artifactId>telegrambots-spring-boot-starter</artifactId>
@ -70,7 +70,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<telegrambots.version>5.3.0</telegrambots.version>
<telegrambots.version>5.4.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.3.0</version>
<version>5.4.0</version>
</parent>
<artifactId>telegrambots</artifactId>
@ -92,7 +92,7 @@
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-meta</artifactId>
<version>5.3.0</version>
<version>5.4.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>