Merge tag 'v6.5.0'
This commit is contained in:
commit
0f60dec532
@ -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>6.4.0</version>
|
||||
<version>6.5.0</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
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`.
|
||||
|
||||
|
@ -1,3 +1,6 @@
|
||||
### <a id="6.4.0"></a>6.4.0 ###
|
||||
1. Update Api version [6.5](https://core.telegram.org/bots/api-changelog#february-3-2023)
|
||||
|
||||
### <a id="6.4.0"></a>6.4.0 ###
|
||||
1. Update Api version [6.4](https://core.telegram.org/bots/api-changelog#december-30-2022)
|
||||
2. Bug fixing: #1159
|
||||
|
@ -11,13 +11,13 @@ First you need to acquire the library and add it to your project. There are seve
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots</artifactId>
|
||||
<version>6.4.0</version>
|
||||
<version>6.5.0</version>
|
||||
</dependency>
|
||||
```
|
||||
* 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).
|
||||
|
@ -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>6.4.0</version>
|
||||
<version>6.5.0</version>
|
||||
</dependency>
|
||||
```
|
||||
* **Gradle**
|
||||
```gradle
|
||||
implementation 'org.telegram:telegrambots-abilities:6.4.0'
|
||||
implementation 'org.telegram:telegrambots-abilities:6.5.0'
|
||||
```
|
||||
* [JitPack](https://jitpack.io/#rubenlagus/TelegramBots)
|
||||
|
||||
|
9
pom.xml
9
pom.xml
@ -7,7 +7,7 @@
|
||||
<groupId>org.warp</groupId>
|
||||
<artifactId>Bots</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>6.4.0</version>
|
||||
<version>6.5.0</version>
|
||||
|
||||
<modules>
|
||||
<module>telegrambots</module>
|
||||
@ -78,6 +78,7 @@
|
||||
<jakarta.annotation.version>2.1.1</jakarta.annotation.version>
|
||||
<lombok.version>1.18.24</lombok.version>
|
||||
<guava.version>31.1-jre</guava.version>
|
||||
<commons.version>3.12.0</commons.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
@ -129,6 +130,12 @@
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Included to enforce common version-->
|
||||
<dependency>
|
||||
<groupId>jakarta.annotation</groupId>
|
||||
|
@ -18,14 +18,14 @@ Usage
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots-abilities</artifactId>
|
||||
<version>6.4.0</version>
|
||||
<version>6.5.0</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
**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)
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.warp</groupId>
|
||||
<artifactId>Bots</artifactId>
|
||||
<version>6.4.0</version>
|
||||
<version>6.5.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>telegrambots-abilities</artifactId>
|
||||
@ -86,12 +86,16 @@
|
||||
<dependency>
|
||||
<groupId>org.warp</groupId>
|
||||
<artifactId>telegrambots</artifactId>
|
||||
<version>6.4.0</version>
|
||||
<version>6.5.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commonslang.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mapdb</groupId>
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -15,14 +15,14 @@ Usage
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots-chat-session-bot</artifactId>
|
||||
<version>6.4.0</version>
|
||||
<version>6.5.0</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
**Gradle**
|
||||
|
||||
```gradle
|
||||
implementation 'org.telegram:telegrambots-chat-session-bot:6.4.0'
|
||||
implementation 'org.telegram:telegrambots-chat-session-bot:6.5.0'
|
||||
```
|
||||
|
||||
Motivation
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.warp</groupId>
|
||||
<artifactId>Bots</artifactId>
|
||||
<version>6.4.0</version>
|
||||
<version>6.5.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>telegrambots-chat-session-bot</artifactId>
|
||||
@ -86,7 +86,7 @@
|
||||
<dependency>
|
||||
<groupId>org.warp</groupId>
|
||||
<artifactId>telegrambots</artifactId>
|
||||
<version>6.4.0</version>
|
||||
<version>6.5.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.shiro/shiro-core -->
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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>6.4.0</version>
|
||||
<version>6.5.0</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
2. Using Gradle:
|
||||
|
||||
```gradle
|
||||
implementation 'org.telegram:telegrambotsextensions:6.4.0'
|
||||
implementation 'org.telegram:telegrambotsextensions:6.5.0'
|
||||
```
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.warp</groupId>
|
||||
<artifactId>Bots</artifactId>
|
||||
<version>6.4.0</version>
|
||||
<version>6.5.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>telegrambotsextensions</artifactId>
|
||||
@ -77,7 +77,7 @@
|
||||
<dependency>
|
||||
<groupId>org.warp</groupId>
|
||||
<artifactId>telegrambots</artifactId>
|
||||
<version>6.4.0</version>
|
||||
<version>6.5.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.warp</groupId>
|
||||
<artifactId>Bots</artifactId>
|
||||
<version>6.4.0</version>
|
||||
<version>6.5.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>telegrambots-meta</artifactId>
|
||||
@ -89,15 +89,14 @@
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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<T extends Serializable> extends PartialBotApiMethod<T> {
|
||||
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();
|
||||
}
|
||||
|
@ -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<T extends Serializable> 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();
|
||||
}
|
||||
|
@ -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<ChatInviteLink> {
|
||||
|
||||
@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) {
|
||||
|
@ -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) {
|
||||
|
@ -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<ChatInviteLink> {
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -46,6 +46,11 @@ public class SetChatPhoto extends PartialBotApiMethod<Boolean> {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
return deserializeResponse(answer, Boolean.class);
|
||||
|
@ -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<String> {
|
||||
|
||||
@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()) {
|
||||
|
@ -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()) {
|
||||
|
@ -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<Message> {
|
||||
public class SendAnimation extends SendMediaBotMethod<Message> {
|
||||
public static final String PATH = "sendAnimation";
|
||||
|
||||
public static final String CHATID_FIELD = "chat_id";
|
||||
@ -59,6 +58,8 @@ public class SendAnimation extends PartialBotApiMethod<Message> {
|
||||
|
||||
@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<Message> {
|
||||
* 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<Message> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputFile getFile() {
|
||||
return animation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFileField() {
|
||||
return ANIMATION_FIELD;
|
||||
}
|
||||
|
||||
public static class SendAnimationBuilder {
|
||||
|
||||
@Tolerate
|
||||
|
@ -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<Message> {
|
||||
public class SendAudio extends SendMediaBotMethod<Message> {
|
||||
public static final String PATH = "sendaudio";
|
||||
|
||||
public static final String DURATION_FIELD = "duration";
|
||||
@ -166,6 +165,21 @@ public class SendAudio extends PartialBotApiMethod<Message> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputFile getFile() {
|
||||
return audio;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFileField() {
|
||||
return AUDIO_FIELD;
|
||||
}
|
||||
|
||||
public static class SendAudioBuilder {
|
||||
|
||||
@Tolerate
|
||||
|
@ -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<Message> {
|
||||
public class SendDocument extends SendMediaBotMethod<Message> {
|
||||
public static final String PATH = "senddocument";
|
||||
|
||||
public static final String CHATID_FIELD = "chat_id";
|
||||
@ -130,6 +129,7 @@ public class SendDocument extends PartialBotApiMethod<Message> {
|
||||
public Message deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
return deserializeResponse(answer, Message.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId.isEmpty()) {
|
||||
@ -151,6 +151,21 @@ public class SendDocument extends PartialBotApiMethod<Message> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputFile getFile() {
|
||||
return document;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFileField() {
|
||||
return DOCUMENT_FIELD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
public static class SendDocumentBuilder {
|
||||
|
||||
@Tolerate
|
||||
|
@ -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()) {
|
||||
|
@ -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<T extends Serializable> extends PartialBotApiMethod<T> {
|
||||
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();
|
||||
}
|
@ -115,6 +115,11 @@ public class SendMediaGroup extends PartialBotApiMethod<ArrayList<Message>> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
public static class SendMediaGroupBuilder {
|
||||
|
||||
@Tolerate
|
||||
|
@ -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<Message> {
|
||||
public class SendPhoto extends SendMediaBotMethod<Message> {
|
||||
public static final String PATH = "sendphoto";
|
||||
|
||||
public static final String CHATID_FIELD = "chat_id";
|
||||
@ -144,8 +143,22 @@ public class SendPhoto extends PartialBotApiMethod<Message> {
|
||||
}
|
||||
}
|
||||
|
||||
@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();
|
||||
|
@ -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<Message> {
|
||||
public class SendSticker extends SendMediaBotMethod<Message> {
|
||||
public static final String PATH = "sendsticker";
|
||||
|
||||
public static final String CHATID_FIELD = "chat_id";
|
||||
@ -93,6 +92,22 @@ public class SendSticker extends PartialBotApiMethod<Message> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputFile getFile() {
|
||||
return sticker;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFileField() {
|
||||
return STICKER_FIELD;
|
||||
}
|
||||
|
||||
|
||||
public static class SendStickerBuilder {
|
||||
|
||||
@Tolerate
|
||||
|
@ -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<Message> {
|
||||
public class SendVideo extends SendMediaBotMethod<Message> {
|
||||
public static final String PATH = "sendvideo";
|
||||
|
||||
public static final String CHATID_FIELD = "chat_id";
|
||||
@ -131,6 +130,21 @@ public class SendVideo extends PartialBotApiMethod<Message> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputFile getFile() {
|
||||
return video;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFileField() {
|
||||
return VIDEO_FIELD;
|
||||
}
|
||||
|
||||
public static class SendVideoBuilder {
|
||||
|
||||
@Tolerate
|
||||
|
@ -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<Message> {
|
||||
public class SendVideoNote extends SendMediaBotMethod<Message> {
|
||||
public static final String PATH = "sendvideonote";
|
||||
|
||||
public static final String CHATID_FIELD = "chat_id";
|
||||
@ -106,6 +105,21 @@ public class SendVideoNote extends PartialBotApiMethod<Message> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputFile getFile() {
|
||||
return videoNote;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFileField() {
|
||||
return VIDEONOTE_FIELD;
|
||||
}
|
||||
|
||||
public static class SendVideoNoteBuilder {
|
||||
|
||||
@Tolerate
|
||||
|
@ -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<Message> {
|
||||
public class SendVoice extends SendMediaBotMethod<Message> {
|
||||
public static final String PATH = "sendvoice";
|
||||
|
||||
public static final String CHATID_FIELD = "chat_id";
|
||||
@ -139,6 +138,21 @@ public class SendVoice extends PartialBotApiMethod<Message> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputFile getFile() {
|
||||
return voice;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFileField() {
|
||||
return VOICE_FIELD;
|
||||
}
|
||||
|
||||
public static class SendVoiceBuilder {
|
||||
|
||||
@Tolerate
|
||||
|
@ -76,6 +76,11 @@ public class AddStickerToSet extends PartialBotApiMethod<Boolean> {
|
||||
return deserializeResponse(answer, Boolean.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (userId <= 0) {
|
||||
|
@ -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<Boolean> {
|
||||
return "mask".equals(stickerType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
return deserializeResponse(answer, Boolean.class);
|
||||
|
@ -42,6 +42,11 @@ public class UploadStickerFile extends PartialBotApiMethod<File> {
|
||||
@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);
|
||||
|
@ -81,6 +81,11 @@ public class EditMessageMedia extends PartialBotApiMethod<Serializable> {
|
||||
this.chatId = chatId == null ? null : chatId.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Serializable deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -26,7 +26,12 @@ 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";
|
||||
@ -35,6 +40,8 @@ public class ChatPermissions implements BotApiObject {
|
||||
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.
|
||||
* True, if the user is allowed to send text messages, contacts, locations and venues
|
||||
@ -42,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
|
||||
@ -84,9 +115,18 @@ public class ChatPermissions implements BotApiObject {
|
||||
@JsonProperty(CAN_PIN_MESSAGES_FIELD)
|
||||
private Boolean canPinMessages;
|
||||
/**
|
||||
* Optional.
|
||||
* True, if the user is allowed to create, rename, close, and reopen forum topics; supergroups only
|
||||
* 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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
@ -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";
|
||||
|
||||
private static final String VIEWS_FIELD = "views";
|
||||
private static final String OUTGOING_FIELD = "outgoing";
|
||||
@ -544,6 +546,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;
|
||||
|
||||
@JsonProperty(OUTGOING_FIELD)
|
||||
private Boolean outgoing; ///< Optional. Extra.
|
||||
@ -762,4 +776,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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
@ -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.
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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()) {
|
||||
|
@ -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
|
||||
@ -80,22 +84,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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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());
|
||||
|
@ -18,14 +18,14 @@ Usage
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots-spring-boot-starter</artifactId>
|
||||
<version>6.4.0</version>
|
||||
<version>6.5.0</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
**Gradle**
|
||||
|
||||
```gradle
|
||||
implementation 'org.telegram:telegrambots-spring-boot-starter:6.4.0'
|
||||
implementation 'org.telegram:telegrambots-spring-boot-starter:6.5.0'
|
||||
```
|
||||
|
||||
Motivation
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.warp</groupId>
|
||||
<artifactId>Bots</artifactId>
|
||||
<version>6.4.0</version>
|
||||
<version>6.5.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>telegrambots-spring-boot-starter</artifactId>
|
||||
@ -72,7 +72,7 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
|
||||
<telegrambots.version>6.4.0</telegrambots.version>
|
||||
<telegrambots.version>6.5.0</telegrambots.version>
|
||||
<spring-boot.version>2.7.5</spring-boot.version>
|
||||
|
||||
<maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.warp</groupId>
|
||||
<artifactId>Bots</artifactId>
|
||||
<version>6.4.0</version>
|
||||
<version>6.5.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>telegrambots</artifactId>
|
||||
@ -93,7 +93,7 @@
|
||||
<dependency>
|
||||
<groupId>org.warp</groupId>
|
||||
<artifactId>telegrambots-meta</artifactId>
|
||||
<version>6.4.0</version>
|
||||
<version>6.5.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
|
@ -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;
|
||||
|
@ -11,14 +11,31 @@ import org.telegram.telegrambots.util.WebhookUtils;
|
||||
* <a href="https://core.telegram.org/bots/api#getupdates">long-polling</a> 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);
|
||||
|
@ -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);
|
||||
|
@ -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<String> botTokenSupplier;
|
||||
|
||||
public TelegramFileDownloader(final Supplier<String> botTokenSupplier) {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 += "/";
|
||||
}
|
||||
|
@ -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 "";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user