Merge branch 'rubenlagus:master' into master
This commit is contained in:
commit
df26c228f8
@ -13,6 +13,10 @@ notifications:
|
||||
secure: "jC7dK/x67ONWQoeLZg4HfW0mHhcjDerJjsLLkrbcpltiqAbw2p7XfY8Pk4zHoD72a+5o6WKu5WvYvZ4OdldnjP8Y6ZUbliQ5RG3olg3gFDoe0+sc3geeb4HRYVcdI20O0z4Bup/qO0ZihxPBc0D5IpHmFxlaqlZG0WeST4CicU8PNnBh6aX9/VMrwXhkMb2vfzmjmIhMbx/uK5+93bnk/vR5Uwu00/Yd2cTAAWMaqK1MRdtR0WLbxlUNsprEfCjYiH3n9XZnlKXs6cLC8EOU436Wx7aepiAszW0wWFMe/7nVqOqztrQiKNvL0qXYwlQf0BLechJdt458EopL9QCu687TNDFYvg1yERAmCRiaayYZcX3PbUSMr6H5Q+Odntjs3XKyzfgSqqlkgf/SAND5jny1/1uteVoplZmFXuZFIiK4H8Rl2ezy1/8pnbp+JD3YEfiA2NuRjlou1BZXyMhiqqVXbrJqk/tXF6yZSkDlYJfNsWzRCGfra4B6JjEvUP927chIFm1ii3dgNstXDo1evV46+OQQO4HKvMPdtU2FPvWpPlkTxnmpZRZjB+bjmybluJdWT3E+e1C3wm7YbRe3vporhpfNPlnod6M0G10y9CKzl9Fbcku6X1FtM+IoPO/aqZ8S4/CBZoYEuR/Nk6bcvsYouxtyIl6PSuF9E8YjpJE="
|
||||
email: false
|
||||
matrix:
|
||||
fast_finish: true
|
||||
allow_failures:
|
||||
- jdk: openjdk-ea
|
||||
- jdk: oraclejdk-ea
|
||||
- jdk: oraclejdk-ea
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.m2
|
||||
|
@ -27,18 +27,18 @@ Just import add the library to your project with one of these options:
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.4.0.1</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
2. Using Gradle:
|
||||
|
||||
```gradle
|
||||
implementation 'org.telegram:telegrambots:5.2.0'
|
||||
implementation 'org.telegram:telegrambots:5.4.0.1'
|
||||
```
|
||||
|
||||
3. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/5.2.0)
|
||||
4. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/5.2.0)
|
||||
3. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/5.4.0.1)
|
||||
4. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/5.4.0.1)
|
||||
|
||||
In order to use Long Polling mode, just create your own bot extending `org.telegram.telegrambots.bots.TelegramLongPollingBot`.
|
||||
|
||||
|
@ -1,5 +1,19 @@
|
||||
### <a id="5.4.0.1"></a>5.4.0.1 ###
|
||||
1Bug fixing: #999
|
||||
|
||||
### <a id="5.4.0"></a>5.4.0 ###
|
||||
1. Update Api version [5.4](https://core.telegram.org/bots/api-changelog#november-5-2021)
|
||||
2. Bug fixing: #968, #958, #942
|
||||
|
||||
### <a id="5.3.0"></a>5.3.0 ###
|
||||
1. Update Api version [5.3](https://core.telegram.org/bots/api-changelog#june-25-2021)
|
||||
2. `KeyboardRow` now support creation from a collection of buttons.
|
||||
3. Bug fixing: #920, #931 and #937
|
||||
|
||||
**[[How to update to version 5.3.0|How-To-Update#5.3.0]]**
|
||||
|
||||
### <a id="5.2.0"></a>5.2.0 ###
|
||||
1. Update Api version [5.2](https://core.telegram.org/bots/api#april-26-2021)
|
||||
1. Update Api version [5.2](https://core.telegram.org/bots/api-changelog#april-26-2021)
|
||||
2. Allow custom BackOff implementations
|
||||
3. Spring version 2.4.5 in spring module
|
||||
4. Bug fixing: #869, #888 and #892
|
||||
|
@ -225,6 +225,46 @@ Custom keyboards can be appended to messages using the `setReplyMarkup`. In this
|
||||
}
|
||||
```
|
||||
|
||||
[InlineKeyboardMarkup](https://core.telegram.org/bots/api#inlinekeyboardmarkup) use list to capture the buttons instead of KeyboardRow.
|
||||
|
||||
```java
|
||||
public void sendInlineKeyboard(String chatId) {
|
||||
SendMessage message = new SendMessage();
|
||||
message.setChatId(chatId);
|
||||
message.setText("Inline model below.");
|
||||
|
||||
// Create InlineKeyboardMarkup object
|
||||
InlineKeyboardMarkup inlineKeyboardMarkup = new InlineKeyboardMarkup();
|
||||
// Create the keyboard (list of InlineKeyboardButton list)
|
||||
List<List<InlineKeyboardButton>> keyboard = new ArrayList<>();
|
||||
// Create a list for buttons
|
||||
List<InlineKeyboardButton> Buttons = new ArrayList<InlineKeyboardButton>();
|
||||
// Initialize each button, the text must be written
|
||||
InlineKeyboardButton youtube= new InlineKeyboardButton("youtube");
|
||||
// Also must use exactly one of the optional fields,it can edit by set method
|
||||
youtube.setUrl("https://www.youtube.com");
|
||||
// Add button to the list
|
||||
Buttons.add(youtube);
|
||||
// Initialize each button, the text must be written
|
||||
InlineKeyboardButton github= new InlineKeyboardButton("github");
|
||||
// Also must use exactly one of the optional fields,it can edit by set method
|
||||
github.setUrl("https://github.com");
|
||||
// Add button to the list
|
||||
Buttons.add(github);
|
||||
keyboard.add(Buttons);
|
||||
inlineKeyboardMarkup.setKeyboard(keyboard);
|
||||
// Add it to the message
|
||||
message.setReplyMarkup(inlineKeyboardMarkup);
|
||||
|
||||
try {
|
||||
// Send the message
|
||||
execute(message);
|
||||
} catch (TelegramApiException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## <a id="how_to_host"></a>How can I run my bot? ##
|
||||
|
||||
You don't need to spend a lot of money into hosting your own telegram bot. Basically, there are two options around how to host:
|
||||
|
@ -11,13 +11,13 @@ First you need ot get the library and add it to your project. There are few poss
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.4.0.1</version>
|
||||
</dependency>
|
||||
```
|
||||
* With **Gradle**:
|
||||
|
||||
```gradle
|
||||
implementation 'org.telegram:telegrambots:5.2.0'
|
||||
implementation 'org.telegram:telegrambots:5.4.0.1'
|
||||
```
|
||||
|
||||
2. Don't like **Maven Central Repository**? It can also be taken from [Jitpack](https://jitpack.io/#rubenlagus/TelegramBots).
|
||||
|
@ -1,3 +1,18 @@
|
||||
### <a id="5.3.0"></a>To version 5.3.0 ###
|
||||
1. As per API guidelines, ChatMember method has been divided in different classed.
|
||||
Where used in your code, replace old import with new one
|
||||
(GetChatAdministrators.java, GetChatMember.java, ChatMemberUpdated.java):
|
||||
|
||||
`import org.telegram.telegrambots.meta.api.objects.ChatMember;`
|
||||
|
||||
to
|
||||
|
||||
`import org.telegram.telegrambots.meta.api.objects.chatmember.ChatMember;`
|
||||
2. ChatMember is an interface now, you'll need to cast it to the corresponding implementation when using it.
|
||||
3. `GetChatMembersCount` renamed to `GetChatMemberCount`, old version will still work until next major version.
|
||||
4. `KickChatMember` renamed to `BanChatMember`, old version will still work until next major version.
|
||||
|
||||
|
||||
### <a id="5.1.0"></a>To version 5.1.0 ###
|
||||
1. All users IDs fields are now Long type as per API guidelines.
|
||||
|
||||
|
@ -48,7 +48,7 @@ public class Main {
|
||||
TelegramBotsApi botsApi = new TelegramBotsApi(DefaultBotSessioin.class);
|
||||
|
||||
// Set up Http proxy
|
||||
DefaultBotOptions botOptions = new DefaultBotOptions());
|
||||
DefaultBotOptions botOptions = new DefaultBotOptions();
|
||||
|
||||
botOptions.setProxyHost(PROXY_HOST);
|
||||
botOptions.setProxyPort(PROXY_PORT);
|
||||
|
@ -9,12 +9,12 @@ As with any Java project, you will need to set your dependencies.
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots-abilities</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.4.0.1</version>
|
||||
</dependency>
|
||||
```
|
||||
* **Gradle**
|
||||
```gradle
|
||||
implementation 'org.telegram:telegrambots-abilities:5.2.0'
|
||||
implementation 'org.telegram:telegrambots-abilities:5.4.0.1'
|
||||
```
|
||||
* [JitPack](https://jitpack.io/#rubenlagus/TelegramBots)
|
||||
|
||||
|
2
pom.xml
2
pom.xml
@ -7,7 +7,7 @@
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>Bots</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>5.2.0</version>
|
||||
<version>5.4.0.1</version>
|
||||
|
||||
<modules>
|
||||
<module>telegrambots</module>
|
||||
|
@ -18,14 +18,14 @@ Usage
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots-abilities</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.4.0.1</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
**Gradle**
|
||||
|
||||
```gradle
|
||||
implementation 'org.telegram:telegrambots-abilities:5.2.0'
|
||||
implementation 'org.telegram:telegrambots-abilities:5.4.0.1'
|
||||
```
|
||||
|
||||
**JitPack** - [JitPack](https://jitpack.io/#rubenlagus/TelegramBots/v5.0.1)
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>Bots</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.4.0.1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>telegrambots-abilities</artifactId>
|
||||
@ -84,7 +84,7 @@
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.4.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
|
@ -21,6 +21,8 @@ import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatAdm
|
||||
import org.telegram.telegrambots.meta.api.objects.Message;
|
||||
import org.telegram.telegrambots.meta.api.objects.Update;
|
||||
import org.telegram.telegrambots.meta.api.objects.User;
|
||||
import org.telegram.telegrambots.meta.api.objects.chatmember.ChatMemberAdministrator;
|
||||
import org.telegram.telegrambots.meta.api.objects.chatmember.ChatMemberOwner;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
@ -260,8 +262,17 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability
|
||||
public boolean isGroupAdmin(long chatId, long id) {
|
||||
GetChatAdministrators admins = GetChatAdministrators.builder().chatId(Long.toString(chatId)).build();
|
||||
return silent.execute(admins)
|
||||
.orElse(new ArrayList<>()).stream()
|
||||
.anyMatch(member -> member.getUser().getId() == id);
|
||||
.orElse(new ArrayList<>())
|
||||
.stream()
|
||||
.map(member -> {
|
||||
final String status = member.getStatus();
|
||||
if (status.equals(ChatMemberOwner.STATUS)
|
||||
|| status.equals(ChatMemberAdministrator.STATUS)) {
|
||||
return member.getUser().getId();
|
||||
}
|
||||
return 0L;
|
||||
})
|
||||
.anyMatch(member -> member == id);
|
||||
}
|
||||
|
||||
public boolean isCreator(long id) {
|
||||
|
@ -31,6 +31,7 @@ public enum Flag implements Predicate<Update> {
|
||||
POLL_ANSWER(Update::hasPollAnswer),
|
||||
MY_CHAT_MEMBER(Update::hasMyChatMember),
|
||||
CHAT_MEMBER(Update::hasChatMember),
|
||||
CHAT_JOIN_REQUEST(Update::hasChatJoinRequest),
|
||||
|
||||
|
||||
// Message Flags
|
||||
|
@ -39,7 +39,10 @@ public class SilentSender {
|
||||
SendMessage msg = new SendMessage();
|
||||
msg.setText(message);
|
||||
msg.setChatId(Long.toString(id));
|
||||
msg.setReplyMarkup(new ForceReplyKeyboard());
|
||||
ForceReplyKeyboard kb = new ForceReplyKeyboard();
|
||||
kb.setForceReply(true);
|
||||
kb.setSelective(true);
|
||||
msg.setReplyMarkup(kb);
|
||||
|
||||
return execute(msg);
|
||||
}
|
||||
|
@ -86,6 +86,8 @@ public final class AbilityUtils {
|
||||
return update.getMyChatMember().getFrom();
|
||||
} else if (CHAT_MEMBER.test(update)) {
|
||||
return update.getChatMember().getFrom();
|
||||
} else if (CHAT_JOIN_REQUEST.test(update)) {
|
||||
return update.getChatJoinRequest().getUser();
|
||||
} else if (POLL.test(update)) {
|
||||
return EMPTY_USER;
|
||||
} else {
|
||||
@ -171,6 +173,8 @@ public final class AbilityUtils {
|
||||
return update.getMyChatMember().getChat().getId();
|
||||
} else if (CHAT_MEMBER.test(update)) {
|
||||
return update.getChatMember().getChat().getId();
|
||||
} else if (CHAT_JOIN_REQUEST.test(update)) {
|
||||
return update.getChatJoinRequest().getChat().getId();
|
||||
} else {
|
||||
throw new IllegalStateException("Could not retrieve originating chat ID from update");
|
||||
}
|
||||
|
@ -10,14 +10,24 @@ import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentMatchers;
|
||||
import org.mockito.Mockito;
|
||||
import org.telegram.abilitybots.api.db.DBContext;
|
||||
import org.telegram.abilitybots.api.objects.*;
|
||||
import org.telegram.abilitybots.api.objects.Ability;
|
||||
import org.telegram.abilitybots.api.objects.Flag;
|
||||
import org.telegram.abilitybots.api.objects.Locality;
|
||||
import org.telegram.abilitybots.api.objects.MessageContext;
|
||||
import org.telegram.abilitybots.api.objects.Privacy;
|
||||
import org.telegram.abilitybots.api.sender.MessageSender;
|
||||
import org.telegram.abilitybots.api.sender.SilentSender;
|
||||
import org.telegram.abilitybots.api.util.AbilityUtils;
|
||||
import org.telegram.abilitybots.api.util.Pair;
|
||||
import org.telegram.abilitybots.api.util.Trio;
|
||||
import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatAdministrators;
|
||||
import org.telegram.telegrambots.meta.api.objects.*;
|
||||
import org.telegram.telegrambots.meta.api.objects.Document;
|
||||
import org.telegram.telegrambots.meta.api.objects.File;
|
||||
import org.telegram.telegrambots.meta.api.objects.Message;
|
||||
import org.telegram.telegrambots.meta.api.objects.Update;
|
||||
import org.telegram.telegrambots.meta.api.objects.User;
|
||||
import org.telegram.telegrambots.meta.api.objects.chatmember.ChatMember;
|
||||
import org.telegram.telegrambots.meta.api.objects.chatmember.ChatMemberAdministrator;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
@ -37,19 +47,32 @@ import static java.util.Optional.empty;
|
||||
import static org.apache.commons.io.FileUtils.deleteQuietly;
|
||||
import static org.apache.commons.lang3.ArrayUtils.addAll;
|
||||
import static org.apache.commons.lang3.StringUtils.EMPTY;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.anyLong;
|
||||
import static org.mockito.Mockito.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.internal.verification.VerificationModeFactory.times;
|
||||
import static org.telegram.abilitybots.api.bot.DefaultBot.*;
|
||||
import static org.telegram.abilitybots.api.bot.DefaultBot.FIRST_REPLY_KEY_MESSAGE;
|
||||
import static org.telegram.abilitybots.api.bot.DefaultBot.SECOND_REPLY_KEY_MESSAGE;
|
||||
import static org.telegram.abilitybots.api.bot.DefaultBot.getDefaultBuilder;
|
||||
import static org.telegram.abilitybots.api.bot.TestUtils.CREATOR;
|
||||
import static org.telegram.abilitybots.api.bot.TestUtils.*;
|
||||
import static org.telegram.abilitybots.api.bot.TestUtils.USER;
|
||||
import static org.telegram.abilitybots.api.bot.TestUtils.mockContext;
|
||||
import static org.telegram.abilitybots.api.bot.TestUtils.mockFullUpdate;
|
||||
import static org.telegram.abilitybots.api.db.MapDBContext.offlineInstance;
|
||||
import static org.telegram.abilitybots.api.objects.Flag.DOCUMENT;
|
||||
import static org.telegram.abilitybots.api.objects.Flag.MESSAGE;
|
||||
import static org.telegram.abilitybots.api.objects.Locality.ALL;
|
||||
import static org.telegram.abilitybots.api.objects.Locality.GROUP;
|
||||
import static org.telegram.abilitybots.api.objects.MessageContext.newContext;
|
||||
import static org.telegram.abilitybots.api.objects.Privacy.*;
|
||||
import static org.telegram.abilitybots.api.objects.Privacy.ADMIN;
|
||||
import static org.telegram.abilitybots.api.objects.Privacy.GROUP_ADMIN;
|
||||
import static org.telegram.abilitybots.api.objects.Privacy.PUBLIC;
|
||||
|
||||
public class AbilityBotTest {
|
||||
// Messages
|
||||
@ -432,7 +455,7 @@ public class AbilityBotTest {
|
||||
when(message.isGroupMessage()).thenReturn(true);
|
||||
|
||||
ChatMember member = mock(ChatMember.class);
|
||||
when(member.getUser()).thenReturn(user);
|
||||
when(member.getStatus()).thenReturn(ChatMemberAdministrator.STATUS);
|
||||
when(member.getUser()).thenReturn(user);
|
||||
|
||||
when(silent.execute(any(GetChatAdministrators.class))).thenReturn(Optional.of(newArrayList(member)));
|
||||
|
@ -15,14 +15,14 @@ Usage
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots-chat-session-bot</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.4.0.1</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
**Gradle**
|
||||
|
||||
```gradle
|
||||
implementation 'org.telegram:telegrambots-chat-session-bot:5.2.0'
|
||||
implementation 'org.telegram:telegrambots-chat-session-bot:5.4.0.1'
|
||||
```
|
||||
|
||||
Motivation
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>Bots</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.4.0.1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>telegrambots-chat-session-bot</artifactId>
|
||||
@ -76,7 +76,7 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
|
||||
<shiro.version>1.7.0</shiro.version>
|
||||
<shiro.version>1.8.0</shiro.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@ -84,7 +84,7 @@
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.4.0.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.shiro/shiro-core -->
|
||||
|
@ -16,12 +16,12 @@ Just import add the library to your project with one of these options:
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambotsextensions</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.4.0.1</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
2. Using Gradle:
|
||||
|
||||
```gradle
|
||||
implementation 'org.telegram:telegrambotsextensions:5.2.0'
|
||||
implementation 'org.telegram:telegrambotsextensions:5.4.0.1'
|
||||
```
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>Bots</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.4.0.1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>telegrambotsextensions</artifactId>
|
||||
@ -75,7 +75,7 @@
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.4.0.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>Bots</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.4.0.1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>telegrambots-meta</artifactId>
|
||||
|
@ -0,0 +1,85 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.commands;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.api.objects.commands.scope.BotCommandScope;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.3
|
||||
*
|
||||
* Use this method to delete the list of the bot's commands for the given scope and user language.
|
||||
* After deletion, higher level commands will be shown to affected users.
|
||||
* Returns True on success.
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class DeleteMyCommands extends BotApiMethod<Boolean> {
|
||||
public static final String PATH = "deleteMyCommands";
|
||||
|
||||
private static final String SCOPE_FIELD = "scope";
|
||||
private static final String LANGUAGECODE_FIELD = "language_code";
|
||||
|
||||
/**
|
||||
* Optional
|
||||
* A JSON-serialized object, describing scope of users for which the commands are relevant.
|
||||
* Defaults to BotCommandScopeDefault.
|
||||
*/
|
||||
@JsonProperty(SCOPE_FIELD)
|
||||
private BotCommandScope scope;
|
||||
/**
|
||||
* Optional
|
||||
* A two-letter ISO 639-1 language code.
|
||||
* If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands
|
||||
*/
|
||||
@JsonProperty(LANGUAGECODE_FIELD)
|
||||
private String languageCode;
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<Boolean> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<Boolean>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error sending commands", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (scope != null) {
|
||||
scope.validate();
|
||||
}
|
||||
if (languageCode != null && languageCode.isEmpty()) {
|
||||
throw new TelegramApiValidationException("LanguageCode parameter can't be empty string", this);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,15 +1,18 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.commands;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.api.objects.commands.BotCommand;
|
||||
import org.telegram.telegrambots.meta.api.objects.commands.scope.BotCommandScope;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
@ -19,19 +22,38 @@ import java.util.ArrayList;
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 4.7
|
||||
* Use this method to get the current list of the bot's commands.
|
||||
* Requires no parameters.
|
||||
* Use this method to get the current list of the bot's commands for the given scope and user language.
|
||||
* Returns Array of BotCommand on success.
|
||||
* If commands aren't set, an empty list is returned.
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class GetMyCommands extends BotApiMethod<ArrayList<BotCommand>> {
|
||||
public static final String PATH = "getMyCommands";
|
||||
|
||||
private static final String SCOPE_FIELD = "scope";
|
||||
private static final String LANGUAGECODE_FIELD = "language_code";
|
||||
|
||||
/**
|
||||
* Optional
|
||||
* A JSON-serialized object, describing scope of users for which the commands are relevant.
|
||||
* Defaults to BotCommandScopeDefault.
|
||||
*/
|
||||
@JsonProperty(SCOPE_FIELD)
|
||||
private BotCommandScope scope;
|
||||
/**
|
||||
* Optional
|
||||
* A two-letter ISO 639-1 language code.
|
||||
* If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands
|
||||
*/
|
||||
@JsonProperty(LANGUAGECODE_FIELD)
|
||||
private String languageCode;
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
@ -54,5 +76,11 @@ public class GetMyCommands extends BotApiMethod<ArrayList<BotCommand>> {
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (scope != null) {
|
||||
scope.validate();
|
||||
}
|
||||
if (languageCode != null && languageCode.isEmpty()) {
|
||||
throw new TelegramApiValidationException("LanguageCode parameter can't be empty string", this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.api.objects.commands.BotCommand;
|
||||
import org.telegram.telegrambots.meta.api.objects.commands.scope.BotCommandScope;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
@ -23,7 +24,9 @@ import java.util.List;
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 4.7
|
||||
* Use this method to change the list of the bot's commands. Returns True on success.
|
||||
* Use this method to change the list of the bot's commands.
|
||||
* See https://core.telegram.org/bots#commands for more details about bot commands.
|
||||
* Returns True on success.
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Getter
|
||||
@ -36,6 +39,8 @@ public class SetMyCommands extends BotApiMethod<Boolean> {
|
||||
public static final String PATH = "setMyCommands";
|
||||
|
||||
private static final String COMMANDS_FIELD = "commands";
|
||||
private static final String SCOPE_FIELD = "scope";
|
||||
private static final String LANGUAGECODE_FIELD = "language_code";
|
||||
|
||||
/**
|
||||
* A JSON-serialized list of bot commands to be set as the list of the bot's commands.
|
||||
@ -45,6 +50,20 @@ public class SetMyCommands extends BotApiMethod<Boolean> {
|
||||
@Singular
|
||||
@NonNull
|
||||
private List<BotCommand> commands;
|
||||
/**
|
||||
* Optional
|
||||
* A JSON-serialized object, describing scope of users for which the commands are relevant.
|
||||
* Defaults to BotCommandScopeDefault.
|
||||
*/
|
||||
@JsonProperty(SCOPE_FIELD)
|
||||
private BotCommandScope scope;
|
||||
/**
|
||||
* Optional
|
||||
* A two-letter ISO 639-1 language code.
|
||||
* If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands
|
||||
*/
|
||||
@JsonProperty(LANGUAGECODE_FIELD)
|
||||
private String languageCode;
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
@ -68,7 +87,10 @@ public class SetMyCommands extends BotApiMethod<Boolean> {
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (commands == null) {
|
||||
if (languageCode != null && languageCode.isEmpty()) {
|
||||
throw new TelegramApiValidationException("LanguageCode parameter can't be empty string", this);
|
||||
}
|
||||
if (commands == null || commands.isEmpty()) {
|
||||
throw new TelegramApiValidationException("Commands parameter can't be empty", this);
|
||||
}
|
||||
if (commands.size() > 100) {
|
||||
@ -77,5 +99,8 @@ public class SetMyCommands extends BotApiMethod<Boolean> {
|
||||
for (BotCommand command : commands) {
|
||||
command.validate();
|
||||
}
|
||||
if (scope != null) {
|
||||
scope.validate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,69 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.groupadministration;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.*;
|
||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.4
|
||||
* Use this method to approve a chat join request.
|
||||
* The bot must be an administrator in the chat for this to work and must have the can_invite_users admin right.
|
||||
* Returns True on success.
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
@Builder
|
||||
public class ApproveChatJoinRequest extends BotApiMethod<Boolean> {
|
||||
public static final String PATH = "approveChatJoinRequest";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
private static final String USERID_FIELD = "user_id";
|
||||
|
||||
@JsonProperty(CHATID_FIELD)
|
||||
@NonNull
|
||||
private String chatId; ///< Required. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
@JsonProperty(USERID_FIELD)
|
||||
@NonNull
|
||||
private Long userId; ///< Required. Unique identifier of the target user
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<Boolean> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<Boolean>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error approving chat join request", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId can't be empty", this);
|
||||
}
|
||||
if (userId == 0) {
|
||||
throw new TelegramApiValidationException("UserId can't be null or 0", this);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,117 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.groupadministration;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.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.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.3
|
||||
* Use this method to kick a user from a group, a supergroup or a channel. In the case of supergroups,
|
||||
* the user will not be able to return to the group on their own using invite links, etc., unless
|
||||
* unbanned first. The bot must be an administrator in the group for this to work. Returns True on
|
||||
* success.
|
||||
* @apiNote This will method only work if the ‘All Members Are Admins’ setting is off in the target
|
||||
* group. Otherwise members may only be removed by the group's creator or by the member that added
|
||||
* them.
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class BanChatMember extends BotApiMethod<Boolean> {
|
||||
public static final String PATH = "banChatMember";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
private static final String USER_ID_FIELD = "user_id";
|
||||
private static final String UNTILDATE_FIELD = "until_date";
|
||||
private static final String REVOKEMESSAGES_FIELD = "revoke_messages";
|
||||
|
||||
@JsonProperty(CHATID_FIELD)
|
||||
@NonNull
|
||||
private String chatId; ///< Required. Unique identifier for the chat to send the message to (Or username for channels)
|
||||
@JsonProperty(USER_ID_FIELD)
|
||||
@NonNull
|
||||
private Long userId; ///< Required. Unique identifier of the target user
|
||||
@JsonProperty(UNTILDATE_FIELD)
|
||||
private Integer untilDate; ///< Optional. Date when the user will be unbanned, unix time. If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever
|
||||
/**
|
||||
* Optional
|
||||
*
|
||||
* Pass True to delete all messages from the chat for the user that is being removed.
|
||||
*
|
||||
* If False, the user will be able to see messages in the group that were sent before the user was removed.
|
||||
*
|
||||
* Always True for supergroups and channels.
|
||||
*/
|
||||
@JsonProperty(REVOKEMESSAGES_FIELD)
|
||||
private Boolean revokeMessages;
|
||||
|
||||
|
||||
@JsonIgnore
|
||||
public void setUntilDateInstant(Instant instant) {
|
||||
setUntilDate((int) instant.getEpochSecond());
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public void setUntilDateDateTime(ZonedDateTime date) {
|
||||
setUntilDateInstant(date.toInstant());
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public void forTimePeriodDuration(Duration duration) {
|
||||
setUntilDateInstant(Instant.now().plusMillis(duration.toMillis()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<Boolean> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<Boolean>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error kicking chat member", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId can't be empty", this);
|
||||
}
|
||||
if (userId == null || userId == 0) {
|
||||
throw new TelegramApiValidationException("UserId can't be null or 0", this);
|
||||
}
|
||||
}
|
||||
}
|
@ -43,6 +43,8 @@ public class CreateChatInviteLink extends BotApiMethod<ChatInviteLink> {
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
private static final String EXPIREDATE_FIELD = "expire_date";
|
||||
private static final String MEMBERLIMIT_FIELD = "member_limit";
|
||||
private static final String NAME_FIELD = "name";
|
||||
private static final String CREATESJOINREQUEST_FIELD = "creates_join_request";
|
||||
|
||||
@JsonProperty(CHATID_FIELD)
|
||||
@NonNull
|
||||
@ -55,7 +57,17 @@ public class CreateChatInviteLink extends BotApiMethod<ChatInviteLink> {
|
||||
* Maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999
|
||||
*/
|
||||
@JsonProperty(MEMBERLIMIT_FIELD)
|
||||
private Integer memberLimit;
|
||||
private Integer memberLimit; ///< Optional. Invite link name; 0-32 characters
|
||||
@JsonProperty(NAME_FIELD)
|
||||
private String name; ///< Optional. Invite link name; 0-32 characters
|
||||
/**
|
||||
* Optional.
|
||||
*
|
||||
* True, if users joining the chat via the link need to be approved by chat administrators.
|
||||
* If True, member_limit can't be specified
|
||||
*/
|
||||
@JsonProperty(CREATESJOINREQUEST_FIELD)
|
||||
private Boolean createsJoinRequest;
|
||||
|
||||
|
||||
@Override
|
||||
@ -80,9 +92,15 @@ public class CreateChatInviteLink extends BotApiMethod<ChatInviteLink> {
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId can't be empty", this);
|
||||
}
|
||||
if (name != null && name.length() > 32) {
|
||||
throw new TelegramApiValidationException("Name must be between 0 and 32 characters", this);
|
||||
}
|
||||
if (createsJoinRequest != null && memberLimit != null) {
|
||||
throw new TelegramApiValidationException("MemberLimit can not be used with CreatesJoinRequest field", this);
|
||||
}
|
||||
if (memberLimit != null && (memberLimit < 1 || memberLimit > 99999)) {
|
||||
throw new TelegramApiValidationException("MemberLimit must be between 1 and 99999", this);
|
||||
}
|
||||
|
@ -0,0 +1,69 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.groupadministration;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.*;
|
||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.4
|
||||
* Use this method to decline a chat join request.
|
||||
* The bot must be an administrator in the chat for this to work and must have the can_invite_users admin right.
|
||||
* Returns True on success.
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
@Builder
|
||||
public class DeclineChatJoinRequest extends BotApiMethod<Boolean> {
|
||||
public static final String PATH = "declineChatJoinRequest";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
private static final String USERID_FIELD = "user_id";
|
||||
|
||||
@JsonProperty(CHATID_FIELD)
|
||||
@NonNull
|
||||
private String chatId; ///< Required. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
@JsonProperty(USERID_FIELD)
|
||||
@NonNull
|
||||
private Long userId; ///< Required. Unique identifier of the target user
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<Boolean> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<Boolean>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error declining chat join request", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId can't be empty", this);
|
||||
}
|
||||
if (userId == 0) {
|
||||
throw new TelegramApiValidationException("UserId can't be null or 0", this);
|
||||
}
|
||||
}
|
||||
}
|
@ -45,6 +45,8 @@ public class EditChatInviteLink extends BotApiMethod<ChatInviteLink> {
|
||||
private static final String INVITELINK_FIELD = "invite_link";
|
||||
private static final String EXPIREDATE_FIELD = "expire_date";
|
||||
private static final String MEMBERLIMIT_FIELD = "member_limit";
|
||||
private static final String NAME_FIELD = "name";
|
||||
private static final String CREATESJOINREQUEST_FIELD = "creates_join_request";
|
||||
|
||||
@JsonProperty(CHATID_FIELD)
|
||||
@NonNull
|
||||
@ -61,6 +63,16 @@ public class EditChatInviteLink extends BotApiMethod<ChatInviteLink> {
|
||||
*/
|
||||
@JsonProperty(MEMBERLIMIT_FIELD)
|
||||
private Integer memberLimit;
|
||||
@JsonProperty(NAME_FIELD)
|
||||
private String name; ///< Optional. Invite link name; 0-32 characters
|
||||
/**
|
||||
* Optional.
|
||||
*
|
||||
* True, if users joining the chat via the link need to be approved by chat administrators.
|
||||
* If True, member_limit can't be specified
|
||||
*/
|
||||
@JsonProperty(CREATESJOINREQUEST_FIELD)
|
||||
private Boolean createsJoinRequest;
|
||||
|
||||
|
||||
@Override
|
||||
@ -91,6 +103,12 @@ public class EditChatInviteLink extends BotApiMethod<ChatInviteLink> {
|
||||
if (Strings.isNullOrEmpty(inviteLink)) {
|
||||
throw new TelegramApiValidationException("InviteLink can't be empty", this);
|
||||
}
|
||||
if (name != null && name.length() > 32) {
|
||||
throw new TelegramApiValidationException("Name must be between 0 and 32 characters", this);
|
||||
}
|
||||
if (createsJoinRequest != null && memberLimit != null) {
|
||||
throw new TelegramApiValidationException("MemberLimit can not be used with CreatesJoinRequest field", this);
|
||||
}
|
||||
if (memberLimit != null && (memberLimit < 1 || memberLimit > 99999)) {
|
||||
throw new TelegramApiValidationException("MemberLimit must be between 1 and 99999", this);
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.api.objects.ChatMember;
|
||||
import org.telegram.telegrambots.meta.api.objects.chatmember.ChatMember;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
|
@ -12,7 +12,7 @@ import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.api.objects.ChatMember;
|
||||
import org.telegram.telegrambots.meta.api.objects.chatmember.ChatMember;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
|
@ -0,0 +1,67 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.groupadministration;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.3
|
||||
* Use this method to get the number of members in a chat. Returns Int on success.
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class GetChatMemberCount extends BotApiMethod<Integer> {
|
||||
public static final String PATH = "getChatMemberCount";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
|
||||
@JsonProperty(CHATID_FIELD)
|
||||
@NonNull
|
||||
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<Integer> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<Integer>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error getting chat members count", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId can't be empty", this);
|
||||
}
|
||||
}
|
||||
}
|
@ -21,6 +21,8 @@ import java.io.IOException;
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
* Use this method to get the number of members in a chat. Returns Int on success.
|
||||
*
|
||||
* @deprecated Use {{@link GetChatMemberCount#GetChatMemberCount()}
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Getter
|
||||
@ -29,6 +31,7 @@ import java.io.IOException;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@Deprecated
|
||||
public class GetChatMembersCount extends BotApiMethod<Integer> {
|
||||
public static final String PATH = "getChatMembersCount";
|
||||
|
||||
|
@ -32,6 +32,8 @@ import java.time.ZonedDateTime;
|
||||
* @apiNote This will method only work if the ‘All Members Are Admins’ setting is off in the target
|
||||
* group. Otherwise members may only be removed by the group's creator or by the member that added
|
||||
* them.
|
||||
*
|
||||
* @deprecated Use {@link BanChatMember#BanChatMember()} instead
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Getter
|
||||
@ -41,6 +43,7 @@ import java.time.ZonedDateTime;
|
||||
@RequiredArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@Deprecated
|
||||
public class KickChatMember extends BotApiMethod<Boolean> {
|
||||
public static final String PATH = "kickchatmember";
|
||||
|
||||
|
@ -44,10 +44,16 @@ public class SendChatAction extends BotApiMethod<Boolean> {
|
||||
@NonNull
|
||||
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
|
||||
/**
|
||||
* Type of action to broadcast. Choose one, depending on what the user is about to receive: typing for text messages,
|
||||
* upload_photo for photos, record_video or upload_video for videos, record_audio or upload_audio for audio files,
|
||||
* upload_document for general files, find_location for location data,
|
||||
* record_video_note or upload_video_note for video notes.
|
||||
* Type of action to broadcast. Choose one, depending on what the user is about to receive:
|
||||
* typing for text messages
|
||||
* upload_photo for photos
|
||||
* record_video or upload_video for videos
|
||||
* record_voice or upload_voice for voice notes
|
||||
* upload_document for general files
|
||||
* choose_sticker for stickers
|
||||
* find_location for location data
|
||||
* record_video_note
|
||||
* upload_video_note for video notes
|
||||
*/
|
||||
@JsonProperty(ACTION_FIELD)
|
||||
@NonNull
|
||||
@ -85,10 +91,10 @@ public class SendChatAction extends BotApiMethod<Boolean> {
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
|
||||
}
|
||||
if (action == null) {
|
||||
if (action.isEmpty()) {
|
||||
throw new TelegramApiValidationException("Action parameter can't be empty", this);
|
||||
}
|
||||
}
|
||||
|
@ -199,9 +199,6 @@ public class SendInvoice extends BotApiMethod<Message> {
|
||||
if (Strings.isNullOrEmpty(providerToken)) {
|
||||
throw new TelegramApiValidationException("ProviderToken parameter can't be empty", this);
|
||||
}
|
||||
if (Strings.isNullOrEmpty(startParameter)) {
|
||||
throw new TelegramApiValidationException("StartParameter parameter can't be empty", this);
|
||||
}
|
||||
if (Strings.isNullOrEmpty(currency)) {
|
||||
throw new TelegramApiValidationException("Currency parameter can't be empty", this);
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ import java.io.IOException;
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class SetStickerSetThumb extends BotApiMethod<Boolean> {
|
||||
private static final String PATH = "setStickerSetThumb";
|
||||
public static final String PATH = "setStickerSetThumb";
|
||||
|
||||
public static final String NAME_FIELD = "name";
|
||||
public static final String USERID_FIELD = "user_id";
|
||||
|
@ -28,6 +28,9 @@ public class ChatInviteLink implements BotApiObject {
|
||||
private static final String ISREVOKED_FIELD = "is_revoked";
|
||||
private static final String EXPIREDATE_FIELD = "expire_date";
|
||||
private static final String MEMBERLIMIT_FIELD = "member_limit";
|
||||
private static final String NAME_FIELD = "name";
|
||||
private static final String PENDINGJOINREQUESTCOUNT_FIELD = "pending_join_request_count";
|
||||
private static final String CREATESJOINREQUEST_FIELD = "creates_join_request";
|
||||
|
||||
/**
|
||||
* The invite link.
|
||||
@ -50,4 +53,13 @@ public class ChatInviteLink implements BotApiObject {
|
||||
*/
|
||||
@JsonProperty(MEMBERLIMIT_FIELD)
|
||||
private Integer memberLimit;
|
||||
@JsonProperty(NAME_FIELD)
|
||||
private String name; ///< Optional. Invite link name
|
||||
@JsonProperty(PENDINGJOINREQUESTCOUNT_FIELD)
|
||||
private Integer pendingJoinRequestCount; ///< Optional. Number of pending join requests created using this link
|
||||
/**
|
||||
* True, if users joining the chat via the link need to be approved by chat administrators
|
||||
*/
|
||||
@JsonProperty(CREATESJOINREQUEST_FIELD)
|
||||
private Boolean createsJoinRequest;
|
||||
}
|
||||
|
@ -0,0 +1,37 @@
|
||||
package org.telegram.telegrambots.meta.api.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.*;
|
||||
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.4
|
||||
*
|
||||
* Represents a join request sent to a chat.
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ChatJoinRequest implements BotApiObject {
|
||||
private static final String CHAT_FIELD = "chat";
|
||||
private static final String FROM_FIELD = "from";
|
||||
private static final String DATE_FIELD = "date";
|
||||
private static final String BIO_FIELD = "bio";
|
||||
private static final String INVITELINK_FIELD = "invite_link";
|
||||
|
||||
|
||||
@JsonProperty(CHAT_FIELD)
|
||||
private Chat chat; ///< Chat to which the request was sent
|
||||
@JsonProperty(FROM_FIELD)
|
||||
private User user; ///< User that sent the join request
|
||||
@JsonProperty(DATE_FIELD)
|
||||
private Integer date; ///< Date the request was sent in Unix time
|
||||
@JsonProperty(BIO_FIELD)
|
||||
private String bio; ///< Optional. Bio of the user.
|
||||
@JsonProperty(INVITELINK_FIELD)
|
||||
private ChatInviteLink inviteLink; ///< Optional. Chat invite link that was used by the user to send the join request
|
||||
}
|
@ -1,117 +0,0 @@
|
||||
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;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
* This object contains information about one member of the chat.
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ChatMember implements BotApiObject {
|
||||
private static final String USER_FIELD = "user";
|
||||
private static final String STATUS_FIELD = "status";
|
||||
private static final String UNTILDATE_FIELD = "until_date";
|
||||
private static final String CANBEEDITED_FIELD = "can_be_edited";
|
||||
private static final String CANCHANGEINFO_FIELD = "can_change_info";
|
||||
private static final String CANPOSTMESSAGES_FIELD = "can_post_messages";
|
||||
private static final String CANEDITMESSAGES_FIELD = "can_edit_messages";
|
||||
private static final String CANDELETEMESSAGES_FIELD = "can_delete_messages";
|
||||
private static final String CANINVITEUSERS_FIELD = "can_invite_users";
|
||||
private static final String CANRESTRICTMEMBERS_FIELD = "can_restrict_members";
|
||||
private static final String CANPINMESSAGES_FIELD = "can_pin_messages";
|
||||
private static final String CANPROMOTEMEMBERS_FIELD = "can_promote_members";
|
||||
private static final String CANSENDMESSAGES_FIELD = "can_send_messages";
|
||||
private static final String CANSENDMEDIAMESSAGES_FIELD = "can_send_media_messages";
|
||||
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 CAN_SEND_POLLS_FIELD = "can_send_polls";
|
||||
private static final String ISMEMBER_FIELD = "is_member";
|
||||
private static final String CUSTOMTITLE_FIELD = "custom_title";
|
||||
private static final String ISANONYMOUS_FIELD = "is_anonymous";
|
||||
private static final String CANMANAGECHAT_FIELD = "can_manage_chat";
|
||||
private static final String CANMANAGEVOICECHATS_FIELD = "can_manage_voice_chats";
|
||||
|
||||
@JsonProperty(USER_FIELD)
|
||||
private User user; ///< Information about the user
|
||||
@JsonProperty(STATUS_FIELD)
|
||||
private String status; ///< The member's status in the chat. Can be “creator”, “administrator”, “member”, “restricted”, “left” or “kicked”
|
||||
@JsonProperty(UNTILDATE_FIELD)
|
||||
private Integer untilDate; ///< Optional. Restricted and kicked only. Date when restrictions will be lifted for this user, unix time
|
||||
@JsonProperty(CANBEEDITED_FIELD)
|
||||
private Boolean canBeEdited; ///< Optional. Administrators only. True, if the bot is allowed to edit administrator privileges of that user
|
||||
@JsonProperty(CANCHANGEINFO_FIELD)
|
||||
private Boolean canChangeInfo; ///< Optional. Administrators and restricted only. True, if the administrator can change the chat title, photo and other settings
|
||||
@JsonProperty(CANPOSTMESSAGES_FIELD)
|
||||
private Boolean canPostMessages; ///< Optional. Administrators only. True, if the administrator can post in the channel, channels only
|
||||
@JsonProperty(CANEDITMESSAGES_FIELD)
|
||||
private Boolean canEditMessages; ///< Optional. Administrators only. True, if the administrator can edit messages of other users and can pin messages, channels only
|
||||
@JsonProperty(CANDELETEMESSAGES_FIELD)
|
||||
private Boolean canDeleteMessages; ///< Optional. Administrators only. True, if the administrator can delete messages of other users
|
||||
@JsonProperty(CANINVITEUSERS_FIELD)
|
||||
private Boolean canInviteUsers; ///< Optional. Administrators and restricted only. True, if the administrator can invite new users to the chat
|
||||
@JsonProperty(CANRESTRICTMEMBERS_FIELD)
|
||||
private Boolean canRestrictMembers; ///< Optional. Administrators only. True, if the administrator can restrict, ban or unban chat members
|
||||
@JsonProperty(CANPINMESSAGES_FIELD)
|
||||
private Boolean canPinMessages; ///< Optional. Administrators and restricted only. True, if the administrator can pin messages, groups and supergroups only
|
||||
@JsonProperty(CANPROMOTEMEMBERS_FIELD)
|
||||
private Boolean canPromoteMembers; ///< Optional. Administrators only. True, if the administrator can add new administrators with a subset of his own privileges or demote administrators that it has promoted, directly or indirectly (promoted by administrators that were appointed by the bot)
|
||||
@JsonProperty(CANSENDMESSAGES_FIELD)
|
||||
private Boolean canSendMessages; ///< Optional. Restricted only. True, if the user is allowed to send text messages, contacts, locations and venues
|
||||
@JsonProperty(CANSENDMEDIAMESSAGES_FIELD)
|
||||
private Boolean canSendMediaMessages; ///< Optional. Restricted only. True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes, implies can_send_messages
|
||||
@JsonProperty(CANSENDOTHERMESSAGES_FIELD)
|
||||
private Boolean canSendOtherMessages; ///< Optional. Restricted only. True, if the user is allowed to send animations, games, stickers and use inline bots, implies can_send_media_messages
|
||||
@JsonProperty(CANADDWEBPAGEPREVIEWS_FIELD)
|
||||
private Boolean canAddWebPagePreviews; ///< Optional. Restricted only. True, if the user is allowed to add web page previews to his messages
|
||||
@JsonProperty(CAN_SEND_POLLS_FIELD)
|
||||
private Boolean canSendPolls; ///< Optional. Restricted only. True, if the user is allowed to send polls.
|
||||
@JsonProperty(ISMEMBER_FIELD)
|
||||
private Boolean isMember; ///< True, if the user is a member of the chat at the moment of the request. For example, it can be false for the chat creator or for a restricted user.
|
||||
@JsonProperty(CUSTOMTITLE_FIELD)
|
||||
private String customTitle; ///< Optional. Owner and administrators only. Custom title for this user
|
||||
@JsonProperty(ISANONYMOUS_FIELD)
|
||||
private Boolean isAnonymous; ///< Optional. Owner and administrators only. True, if the user's presence in the chat is hidden
|
||||
/**
|
||||
* Optional.
|
||||
*
|
||||
* Administrators only.
|
||||
*
|
||||
* True, if the administrator can access the chat event log, chat statistics, message statistics in channels,
|
||||
* see channel members, see anonymous administrators in supergoups and ignore slow mode.
|
||||
*
|
||||
* Implied by any other administrator privilege
|
||||
*/
|
||||
@JsonProperty(CANMANAGECHAT_FIELD)
|
||||
private Boolean canManageChat;
|
||||
/**
|
||||
* Optional.
|
||||
*
|
||||
* Administrators only.
|
||||
*
|
||||
* True, if the administrator can manage voice chats; groups and supergroups only
|
||||
*/
|
||||
@JsonProperty(CANMANAGEVOICECHATS_FIELD)
|
||||
private Boolean canManageVoiceChats;
|
||||
|
||||
public Instant getUntilDateAsInstant() {
|
||||
if (untilDate == null) {
|
||||
return null;
|
||||
}
|
||||
return Instant.ofEpochSecond(untilDate);
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
|
||||
import org.telegram.telegrambots.meta.api.objects.chatmember.ChatMember;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
|
@ -44,6 +44,7 @@ public class Update implements BotApiObject {
|
||||
private static final String POLLANSWER_FIELD = "poll_answer";
|
||||
private static final String MYCHATMEMBER_FIELD = "my_chat_member";
|
||||
private static final String CHATMEMBER_FIELD = "chat_member";
|
||||
private static final String CHATJOINREQUEST_FIELD = "chat_join_request";
|
||||
|
||||
@JsonProperty(UPDATEID_FIELD)
|
||||
private Integer updateId;
|
||||
@ -91,6 +92,8 @@ public class Update implements BotApiObject {
|
||||
*/
|
||||
@JsonProperty(CHATMEMBER_FIELD)
|
||||
private ChatMemberUpdated chatMember;
|
||||
@JsonProperty(CHATJOINREQUEST_FIELD)
|
||||
private ChatJoinRequest chatJoinRequest;
|
||||
|
||||
public boolean hasMessage() {
|
||||
return message != null;
|
||||
@ -143,4 +146,8 @@ public class Update implements BotApiObject {
|
||||
public boolean hasChatMember() {
|
||||
return chatMember != null;
|
||||
}
|
||||
|
||||
public boolean hasChatJoinRequest() {
|
||||
return chatJoinRequest != null;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
package org.telegram.telegrambots.meta.api.objects.chatmember;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
|
||||
import org.telegram.telegrambots.meta.api.objects.User;
|
||||
import org.telegram.telegrambots.meta.api.objects.chatmember.serialization.ChatMemberDeserializer;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.3
|
||||
*
|
||||
* This object contains information about one member of a chat. Currently, the following 6
|
||||
* types of chat members are supported:
|
||||
*/
|
||||
@JsonDeserialize(using = ChatMemberDeserializer.class)
|
||||
public interface ChatMember extends BotApiObject {
|
||||
String getStatus();
|
||||
User getUser();
|
||||
}
|
@ -0,0 +1,127 @@
|
||||
package org.telegram.telegrambots.meta.api.objects.chatmember;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.api.objects.User;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.3
|
||||
*
|
||||
* Represents a chat member that has some additional privileges.
|
||||
*/
|
||||
@JsonDeserialize
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class ChatMemberAdministrator implements ChatMember {
|
||||
public static final String STATUS = "administrator";
|
||||
|
||||
private static final String STATUS_FIELD = "status";
|
||||
private static final String USER_FIELD = "user";
|
||||
private static final String CANBEEDITED_FIELD = "can_be_edited";
|
||||
private static final String CUSTOMTITLE_FIELD = "custom_title";
|
||||
private static final String ISANONYMOUS_FIELD = "is_anonymous";
|
||||
private static final String CANMANAGECHAT_FIELD = "can_manage_chat";
|
||||
private static final String CANPOSTMESSAGES_FIELD = "can_post_messages";
|
||||
private static final String CANEDITMESSAGES_FIELD = "can_edit_messages";
|
||||
private static final String CANDELETEMESSAGES_FIELD = "can_delete_messages";
|
||||
private static final String CANMANAGEVOICECHATS_FIELD = "can_manage_voice_chats";
|
||||
private static final String CANRESTRICTMEMBERS_FIELD = "can_restrict_members";
|
||||
private static final String CANPROMOTEMEMBERS_FIELD = "can_promote_members";
|
||||
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";
|
||||
|
||||
/**
|
||||
* The member's status in the chat, always “administrator”
|
||||
*/
|
||||
@JsonProperty(STATUS_FIELD)
|
||||
private final String status = STATUS;
|
||||
/**
|
||||
* Information about the user
|
||||
*/
|
||||
@JsonProperty(USER_FIELD)
|
||||
private User user;
|
||||
/**
|
||||
* True, if the bot is allowed to edit administrator privileges of that user
|
||||
*/
|
||||
@JsonProperty(CANBEEDITED_FIELD)
|
||||
private Boolean canBeEdited;
|
||||
/**
|
||||
* Custom title for this user
|
||||
*/
|
||||
@JsonProperty(CUSTOMTITLE_FIELD)
|
||||
private String customTitle;
|
||||
/**
|
||||
* True, if the user's presence in the chat is hidden
|
||||
*/
|
||||
@JsonProperty(ISANONYMOUS_FIELD)
|
||||
private Boolean isAnonymous;
|
||||
/**
|
||||
* True, if the administrator can access the chat event log, chat statistics,
|
||||
* message statistics in channels, see channel members,
|
||||
* see anonymous administrators in supergroups and ignore slow mode.
|
||||
* Implied by any other administrator privilege
|
||||
*/
|
||||
@JsonProperty(CANMANAGECHAT_FIELD)
|
||||
private Boolean canManageChat;
|
||||
/**
|
||||
* True, if the administrator can post in the channel; channels only
|
||||
*/
|
||||
@JsonProperty(CANPOSTMESSAGES_FIELD)
|
||||
private Boolean canPostMessages;
|
||||
/**
|
||||
* True, if the administrator can edit messages of other users and can pin messages; channels only
|
||||
*/
|
||||
@JsonProperty(CANEDITMESSAGES_FIELD)
|
||||
private Boolean canEditMessages;
|
||||
/**
|
||||
* True, if the administrator can delete messages of other users
|
||||
*/
|
||||
@JsonProperty(CANDELETEMESSAGES_FIELD)
|
||||
private Boolean canDeleteMessages;
|
||||
/**
|
||||
* True, if the administrator can manage voice chats
|
||||
*/
|
||||
@JsonProperty(CANMANAGEVOICECHATS_FIELD)
|
||||
private Boolean canManageVoiceChats;
|
||||
/**
|
||||
* True, if the administrator can restrict, ban or unban chat members
|
||||
*/
|
||||
@JsonProperty(CANRESTRICTMEMBERS_FIELD)
|
||||
private Boolean canRestrictMembers;
|
||||
/**
|
||||
* True, if the administrator can add new administrators with a subset of their own privileges or
|
||||
* demote administrators that he has promoted, directly or indirectly
|
||||
* (promoted by administrators that were appointed by the user)
|
||||
*/
|
||||
@JsonProperty(CANPROMOTEMEMBERS_FIELD)
|
||||
private Boolean canPromoteMembers;
|
||||
/**
|
||||
* 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;
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package org.telegram.telegrambots.meta.api.objects.chatmember;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.api.objects.User;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.3
|
||||
*
|
||||
* Represents a chat member that was banned in the chat and can't return to the chat or view chat messages.
|
||||
*/
|
||||
@JsonDeserialize
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class ChatMemberBanned implements ChatMember {
|
||||
public static final String STATUS = "kicked";
|
||||
|
||||
private static final String STATUS_FIELD = "status";
|
||||
private static final String USER_FIELD = "user";
|
||||
private static final String UNTILDATE_FIELD = "until_date";
|
||||
|
||||
/**
|
||||
* The member's status in the chat, always “kicked”
|
||||
*/
|
||||
@JsonProperty(STATUS_FIELD)
|
||||
private final String status = STATUS;
|
||||
/**
|
||||
* Information about the user
|
||||
*/
|
||||
@JsonProperty(USER_FIELD)
|
||||
private User user;
|
||||
/**
|
||||
* Date when restrictions will be lifted for this user; unix time
|
||||
*/
|
||||
@JsonProperty(UNTILDATE_FIELD)
|
||||
private Integer untilDate;
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package org.telegram.telegrambots.meta.api.objects.chatmember;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.api.objects.User;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.3
|
||||
*
|
||||
* Represents a chat member that isn't currently a member of the chat, but may join it themselves.
|
||||
*/
|
||||
@JsonDeserialize
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class ChatMemberLeft implements ChatMember {
|
||||
public static final String STATUS = "left";
|
||||
|
||||
private static final String STATUS_FIELD = "status";
|
||||
private static final String USER_FIELD = "user";
|
||||
|
||||
/**
|
||||
* The member's status in the chat, always “left”
|
||||
*/
|
||||
@JsonProperty(STATUS_FIELD)
|
||||
private final String status = STATUS;
|
||||
/**
|
||||
* Information about the user
|
||||
*/
|
||||
@JsonProperty(USER_FIELD)
|
||||
private User user;
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package org.telegram.telegrambots.meta.api.objects.chatmember;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.api.objects.User;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.3
|
||||
*
|
||||
* Represents a chat member that has no additional privileges or restrictions.
|
||||
*/
|
||||
@JsonDeserialize
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class ChatMemberMember implements ChatMember {
|
||||
public static final String STATUS = "member";
|
||||
|
||||
private static final String STATUS_FIELD = "status";
|
||||
private static final String USER_FIELD = "user";
|
||||
|
||||
/**
|
||||
* The member's status in the chat, always “member”
|
||||
*/
|
||||
@JsonProperty(STATUS_FIELD)
|
||||
private final String status = STATUS;
|
||||
/**
|
||||
* Information about the user
|
||||
*/
|
||||
@JsonProperty(USER_FIELD)
|
||||
private User user;
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package org.telegram.telegrambots.meta.api.objects.chatmember;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.api.objects.User;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.3
|
||||
*
|
||||
* Represents a chat member that owns the chat and has all administrator privileges.
|
||||
*/
|
||||
@JsonDeserialize
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class ChatMemberOwner implements ChatMember {
|
||||
public static final String STATUS = "creator";
|
||||
|
||||
private static final String STATUS_FIELD = "status";
|
||||
private static final String USER_FIELD = "user";
|
||||
private static final String CUSTOMTITLE_FIELD = "custom_title";
|
||||
private static final String ISANONYMOUS_FIELD = "is_anonymous";
|
||||
|
||||
/**
|
||||
* The member's status in the chat, always “creator”
|
||||
*/
|
||||
@JsonProperty(STATUS_FIELD)
|
||||
private final String status = STATUS;
|
||||
/**
|
||||
* Information about the user
|
||||
*/
|
||||
@JsonProperty(USER_FIELD)
|
||||
private User user;
|
||||
/**
|
||||
* Custom title for this user
|
||||
*/
|
||||
@JsonProperty(CUSTOMTITLE_FIELD)
|
||||
private String customTitle;
|
||||
/**
|
||||
* True, if the user's presence in the chat is hidden
|
||||
*/
|
||||
@JsonProperty(ISANONYMOUS_FIELD)
|
||||
private Boolean isAnonymous;
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
package org.telegram.telegrambots.meta.api.objects.chatmember;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.api.objects.User;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.3
|
||||
*
|
||||
* Represents a chat member that is under certain restrictions in the chat. Supergroups only.
|
||||
*/
|
||||
@JsonDeserialize
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class ChatMemberRestricted implements ChatMember {
|
||||
public static final String STATUS = "restricted";
|
||||
|
||||
private static final String STATUS_FIELD = "status";
|
||||
private static final String USER_FIELD = "user";
|
||||
private static final String ISMEMBER_FIELD = "is_member";
|
||||
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 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";
|
||||
|
||||
/**
|
||||
* The member's status in the chat, always “restricted”
|
||||
*/
|
||||
@JsonProperty(STATUS_FIELD)
|
||||
private final String status = STATUS;
|
||||
/**
|
||||
* Information about the user
|
||||
*/
|
||||
@JsonProperty(USER_FIELD)
|
||||
private User user;
|
||||
/**
|
||||
* True, if the user is a member of the chat at the moment of the request
|
||||
*/
|
||||
@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
|
||||
*/
|
||||
@JsonProperty(CANSENDMEDIAMESSAGES_FIELD)
|
||||
private Boolean canSendMediaMessages;
|
||||
/**
|
||||
* True, if the user is allowed to send polls
|
||||
*/
|
||||
@JsonProperty(CANSENDPOLLS_FIELD)
|
||||
private Boolean canSendPolls;
|
||||
/**
|
||||
* True, if the user is allowed to send animations, games, stickers and use inline bots
|
||||
*/
|
||||
@JsonProperty(CANSENDOTHERMESSAGES_FIELD)
|
||||
private Boolean canSendOtherMessages;
|
||||
/**
|
||||
* True, if the user is allowed to add web page previews to their messages
|
||||
*/
|
||||
@JsonProperty(CANADDWEBPAGEPREVIEWS_FIELD)
|
||||
private Boolean canAddWebpagePreviews;
|
||||
/**
|
||||
* Date when restrictions will be lifted for this user; unix time
|
||||
*/
|
||||
@JsonProperty(UNTILDATE_FIELD)
|
||||
private Integer untilDate;
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package org.telegram.telegrambots.meta.api.objects.chatmember.serialization;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
|
||||
import org.telegram.telegrambots.meta.api.objects.chatmember.ChatMember;
|
||||
import org.telegram.telegrambots.meta.api.objects.chatmember.ChatMemberAdministrator;
|
||||
import org.telegram.telegrambots.meta.api.objects.chatmember.ChatMemberBanned;
|
||||
import org.telegram.telegrambots.meta.api.objects.chatmember.ChatMemberLeft;
|
||||
import org.telegram.telegrambots.meta.api.objects.chatmember.ChatMemberMember;
|
||||
import org.telegram.telegrambots.meta.api.objects.chatmember.ChatMemberOwner;
|
||||
import org.telegram.telegrambots.meta.api.objects.chatmember.ChatMemberRestricted;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.3
|
||||
*/
|
||||
public class ChatMemberDeserializer extends StdDeserializer<ChatMember> {
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public ChatMemberDeserializer() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
private ChatMemberDeserializer(Class<?> vc) {
|
||||
super(vc);
|
||||
this.objectMapper = new ObjectMapper();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatMember deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
|
||||
throws IOException {
|
||||
JsonNode node = jsonParser.getCodec().readTree(jsonParser);
|
||||
|
||||
String type = node.has("status") ? node.get("status").asText() : "";
|
||||
switch (type) {
|
||||
case "administrator":
|
||||
return objectMapper.readValue(node.toString(),
|
||||
new TypeReference<ChatMemberAdministrator>(){});
|
||||
case "kicked":
|
||||
return objectMapper.readValue(node.toString(),
|
||||
new TypeReference<ChatMemberBanned>(){});
|
||||
case "left":
|
||||
return objectMapper.readValue(node.toString(),
|
||||
new TypeReference<ChatMemberLeft>(){});
|
||||
case "member":
|
||||
return objectMapper.readValue(node.toString(),
|
||||
new TypeReference<ChatMemberMember>(){});
|
||||
case "creator":
|
||||
return objectMapper.readValue(node.toString(),
|
||||
new TypeReference<ChatMemberOwner>(){});
|
||||
case "restricted":
|
||||
return objectMapper.readValue(node.toString(),
|
||||
new TypeReference<ChatMemberRestricted>(){});
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package org.telegram.telegrambots.meta.api.objects.commands.scope;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
|
||||
import org.telegram.telegrambots.meta.api.interfaces.Validable;
|
||||
import org.telegram.telegrambots.meta.api.objects.commands.scope.serialization.BotCommandScopeDeserializer;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.3
|
||||
*
|
||||
* This object represents the scope to which bot commands are applied. Currently, the following 7 scopes are supported:
|
||||
*
|
||||
* BotCommandScopeDefault
|
||||
* BotCommandScopeAllPrivateChats
|
||||
* BotCommandScopeAllGroupChats
|
||||
* BotCommandScopeAllChatAdministrators
|
||||
* BotCommandScopeChat
|
||||
* BotCommandScopeChatAdministrators
|
||||
* BotCommandScopeChatMember
|
||||
*
|
||||
* The following algorithm is used to determine the list of commands for a particular user viewing the bot menu. The first list of commands which is set is returned:
|
||||
*
|
||||
* Commands in the chat with the bot
|
||||
*
|
||||
* botCommandScopeChat + language_code
|
||||
* botCommandScopeChat
|
||||
* botCommandScopeAllPrivateChats + language_code
|
||||
* botCommandScopeAllPrivateChats
|
||||
* botCommandScopeDefault + language_code
|
||||
* botCommandScopeDefault
|
||||
* Commands in group and supergroup chats
|
||||
*
|
||||
* botCommandScopeChatMember + language_code
|
||||
* botCommandScopeChatMember
|
||||
* botCommandScopeChatAdministrators + language_code (admins only)
|
||||
* botCommandScopeChatAdministrators (admins only)
|
||||
* botCommandScopeChat + language_code
|
||||
* botCommandScopeChat
|
||||
* botCommandScopeAllChatAdministrators + language_code (admins only)
|
||||
* botCommandScopeAllChatAdministrators (admins only)
|
||||
* botCommandScopeAllGroupChats + language_code
|
||||
* botCommandScopeAllGroupChats
|
||||
* botCommandScopeDefault + language_code
|
||||
* botCommandScopeDefault
|
||||
*/
|
||||
@JsonDeserialize(using = BotCommandScopeDeserializer.class)
|
||||
public interface BotCommandScope extends BotApiObject, Validable {
|
||||
String getType();
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package org.telegram.telegrambots.meta.api.objects.commands.scope;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.3
|
||||
*
|
||||
* Represents the scope of bot commands, covering all group and supergroup chat administrators.
|
||||
*/
|
||||
@JsonDeserialize
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class BotCommandScopeAllChatAdministrators implements BotCommandScope {
|
||||
private static final String TYPE_FIELD = "type";
|
||||
|
||||
/**
|
||||
* Scope type, must be chat
|
||||
*/
|
||||
@JsonProperty(TYPE_FIELD)
|
||||
private final String type = "all_chat_administrators";
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package org.telegram.telegrambots.meta.api.objects.commands.scope;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.3
|
||||
*
|
||||
* Represents the scope of bot commands, covering all group and supergroup chats.
|
||||
*/
|
||||
@JsonDeserialize
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class BotCommandScopeAllGroupChats implements BotCommandScope {
|
||||
private static final String TYPE_FIELD = "type";
|
||||
|
||||
/**
|
||||
* Scope type, must be chat
|
||||
*/
|
||||
@JsonProperty(TYPE_FIELD)
|
||||
private final String type = "all_group_chats";
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package org.telegram.telegrambots.meta.api.objects.commands.scope;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.3
|
||||
*
|
||||
* Represents the scope of bot commands, covering all private chats.
|
||||
*/
|
||||
@JsonDeserialize
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class BotCommandScopeAllPrivateChats implements BotCommandScope {
|
||||
private static final String TYPE_FIELD = "type";
|
||||
|
||||
/**
|
||||
* Scope type, must be chat
|
||||
*/
|
||||
@JsonProperty(TYPE_FIELD)
|
||||
private final String type = "all_private_chats";
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package org.telegram.telegrambots.meta.api.objects.commands.scope;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.3
|
||||
*
|
||||
* Represents the scope of bot commands, covering a specific chat.
|
||||
*/
|
||||
@JsonDeserialize
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class BotCommandScopeChat implements BotCommandScope {
|
||||
private static final String TYPE_FIELD = "type";
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
|
||||
/**
|
||||
* Scope type, must be chat
|
||||
*/
|
||||
@JsonProperty(TYPE_FIELD)
|
||||
private final String type = "chat";
|
||||
/**
|
||||
* Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
|
||||
*/
|
||||
@JsonProperty(CHATID_FIELD)
|
||||
@NonNull
|
||||
private String chatId;
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package org.telegram.telegrambots.meta.api.objects.commands.scope;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.3
|
||||
*
|
||||
* Represents the scope of bot commands, covering all administrators of a specific group or supergroup chat.
|
||||
*/
|
||||
@JsonDeserialize
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class BotCommandScopeChatAdministrators implements BotCommandScope {
|
||||
private static final String TYPE_FIELD = "type";
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
|
||||
/**
|
||||
* Scope type, must be chat
|
||||
*/
|
||||
@JsonProperty(TYPE_FIELD)
|
||||
private final String type = "chat_administrators";
|
||||
/**
|
||||
* Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
|
||||
*/
|
||||
@JsonProperty(CHATID_FIELD)
|
||||
@NonNull
|
||||
private String chatId;
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package org.telegram.telegrambots.meta.api.objects.commands.scope;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.3
|
||||
*
|
||||
* Represents the scope of bot commands, covering a specific member of a group or supergroup chat.
|
||||
*/
|
||||
@JsonDeserialize
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class BotCommandScopeChatMember implements BotCommandScope {
|
||||
private static final String TYPE_FIELD = "type";
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
private static final String USERID_FIELD = "user_id";
|
||||
|
||||
/**
|
||||
* Scope type, must be chat
|
||||
*/
|
||||
@JsonProperty(TYPE_FIELD)
|
||||
private final String type = "chat_member";
|
||||
/**
|
||||
* Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
|
||||
*/
|
||||
@JsonProperty(CHATID_FIELD)
|
||||
@NonNull
|
||||
private String chatId;
|
||||
/**
|
||||
* Unique identifier of the target user
|
||||
*/
|
||||
@JsonProperty(USERID_FIELD)
|
||||
@NonNull
|
||||
private Long userId;
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
|
||||
}
|
||||
if (userId == null || userId == 0L) {
|
||||
throw new TelegramApiValidationException("UserId parameter can't be empty", this);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package org.telegram.telegrambots.meta.api.objects.commands.scope;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.3
|
||||
*
|
||||
* Represents the default scope of bot commands.
|
||||
* Default commands are used if no commands with a narrower scope are specified for the user.
|
||||
*/
|
||||
@JsonDeserialize
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class BotCommandScopeDefault implements BotCommandScope {
|
||||
private static final String TYPE_FIELD = "type";
|
||||
|
||||
/**
|
||||
* Scope type, must be chat
|
||||
*/
|
||||
@JsonProperty(TYPE_FIELD)
|
||||
private final String type = "default";
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package org.telegram.telegrambots.meta.api.objects.commands.scope.serialization;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
|
||||
import org.telegram.telegrambots.meta.api.objects.commands.scope.BotCommandScope;
|
||||
import org.telegram.telegrambots.meta.api.objects.commands.scope.BotCommandScopeAllChatAdministrators;
|
||||
import org.telegram.telegrambots.meta.api.objects.commands.scope.BotCommandScopeAllGroupChats;
|
||||
import org.telegram.telegrambots.meta.api.objects.commands.scope.BotCommandScopeAllPrivateChats;
|
||||
import org.telegram.telegrambots.meta.api.objects.commands.scope.BotCommandScopeChat;
|
||||
import org.telegram.telegrambots.meta.api.objects.commands.scope.BotCommandScopeChatAdministrators;
|
||||
import org.telegram.telegrambots.meta.api.objects.commands.scope.BotCommandScopeChatMember;
|
||||
import org.telegram.telegrambots.meta.api.objects.commands.scope.BotCommandScopeDefault;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.3
|
||||
*/
|
||||
public class BotCommandScopeDeserializer extends StdDeserializer<BotCommandScope> {
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public BotCommandScopeDeserializer() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
private BotCommandScopeDeserializer(Class<?> vc) {
|
||||
super(vc);
|
||||
this.objectMapper = new ObjectMapper();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BotCommandScope deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
|
||||
throws IOException {
|
||||
JsonNode node = jsonParser.getCodec().readTree(jsonParser);
|
||||
|
||||
String type = node.has("Type") ? node.get("type").asText() : "";
|
||||
switch (type) {
|
||||
case "default":
|
||||
return objectMapper.readValue(node.toString(),
|
||||
new TypeReference<BotCommandScopeDefault>(){});
|
||||
case "all_private_chats":
|
||||
return objectMapper.readValue(node.toString(),
|
||||
new TypeReference<BotCommandScopeAllPrivateChats>(){});
|
||||
case "all_group_chats":
|
||||
return objectMapper.readValue(node.toString(),
|
||||
new TypeReference<BotCommandScopeAllGroupChats>(){});
|
||||
case "all_chat_administrators":
|
||||
return objectMapper.readValue(node.toString(),
|
||||
new TypeReference<BotCommandScopeAllChatAdministrators>(){});
|
||||
case "chat":
|
||||
return objectMapper.readValue(node.toString(),
|
||||
new TypeReference<BotCommandScopeChat>(){});
|
||||
case "chat_administrators":
|
||||
return objectMapper.readValue(node.toString(),
|
||||
new TypeReference<BotCommandScopeChatAdministrators>(){});
|
||||
case "chat_member":
|
||||
return objectMapper.readValue(node.toString(),
|
||||
new TypeReference<BotCommandScopeChatMember>(){});
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -33,6 +33,7 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
public class ForceReplyKeyboard implements ReplyKeyboard {
|
||||
private static final String FORCEREPLY_FIELD = "force_reply";
|
||||
private static final String SELECTIVE_FIELD = "selective";
|
||||
private static final String INPUTFIELDPLACEHOLDER_FIELD = "input_field_placeholder";
|
||||
|
||||
/**
|
||||
* Shows reply interface to the user, as if they manually selected the bot‘s message and tapped
|
||||
@ -40,7 +41,8 @@ public class ForceReplyKeyboard implements ReplyKeyboard {
|
||||
*/
|
||||
@JsonProperty(FORCEREPLY_FIELD)
|
||||
@NonNull
|
||||
private Boolean forceReply;
|
||||
@Builder.Default
|
||||
private Boolean forceReply = true;
|
||||
/**
|
||||
* Optional.
|
||||
*
|
||||
@ -50,11 +52,20 @@ public class ForceReplyKeyboard implements ReplyKeyboard {
|
||||
*/
|
||||
@JsonProperty(SELECTIVE_FIELD)
|
||||
private Boolean selective;
|
||||
/**
|
||||
* Optional.
|
||||
* The placeholder to be shown in the input field when the keyboard is active; 1-64 characters
|
||||
*/
|
||||
@JsonProperty(INPUTFIELDPLACEHOLDER_FIELD)
|
||||
private String inputFieldPlaceholder;
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (forceReply == null) {
|
||||
throw new TelegramApiValidationException("ForceReply parameter can't not be null", this);
|
||||
}
|
||||
if (inputFieldPlaceholder != null && (inputFieldPlaceholder.length() < 1 || inputFieldPlaceholder.length() > 64)) {
|
||||
throw new TelegramApiValidationException("InputFieldPlaceholder must be between 1 and 64 characters", this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ public class ReplyKeyboardMarkup implements ReplyKeyboard {
|
||||
private static final String RESIZEKEYBOARD_FIELD = "resize_keyboard";
|
||||
private static final String ONETIMEKEYBOARD_FIELD = "one_time_keyboard";
|
||||
private static final String SELECTIVE_FIELD = "selective";
|
||||
private static final String INPUTFIELDPLACEHOLDER_FIELD = "input_field_placeholder";
|
||||
|
||||
@JsonProperty(KEYBOARD_FIELD)
|
||||
@NonNull
|
||||
@ -55,12 +56,21 @@ public class ReplyKeyboardMarkup implements ReplyKeyboard {
|
||||
*/
|
||||
@JsonProperty(SELECTIVE_FIELD)
|
||||
private Boolean selective;
|
||||
/**
|
||||
* Optional.
|
||||
* The placeholder to be shown in the input field when the keyboard is active; 1-64 characters
|
||||
*/
|
||||
@JsonProperty(INPUTFIELDPLACEHOLDER_FIELD)
|
||||
private String inputFieldPlaceholder;
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (keyboard == null) {
|
||||
throw new TelegramApiValidationException("Keyboard parameter can't be null", this);
|
||||
}
|
||||
if (inputFieldPlaceholder != null && (inputFieldPlaceholder.length() < 1 || inputFieldPlaceholder.length() > 64)) {
|
||||
throw new TelegramApiValidationException("InputFieldPlaceholder must be between 1 and 64 characters", this);
|
||||
}
|
||||
for (KeyboardRow keyboardButtons : keyboard) {
|
||||
keyboardButtons.validate();
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import org.telegram.telegrambots.meta.api.interfaces.Validable;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -12,6 +13,17 @@ import java.util.List;
|
||||
* Row for ReplyKeyBoardMarkup
|
||||
*/
|
||||
public class KeyboardRow extends ArrayList<KeyboardButton> implements Validable {
|
||||
public KeyboardRow(int initialCapacity) {
|
||||
super(initialCapacity);
|
||||
}
|
||||
|
||||
public KeyboardRow() {
|
||||
}
|
||||
|
||||
public KeyboardRow(Collection<? extends KeyboardButton> c) {
|
||||
super(c);
|
||||
}
|
||||
|
||||
public boolean add(String text) {
|
||||
return super.add(new KeyboardButton(text));
|
||||
}
|
||||
|
@ -0,0 +1,41 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.commands;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.telegram.telegrambots.meta.api.objects.commands.scope.BotCommandScopeDefault;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.3
|
||||
*/
|
||||
public class DeleteMyCommandsTest {
|
||||
@Test
|
||||
public void testDeleteMyCommandsWithEmptyScope() {
|
||||
DeleteMyCommands deleteMyCommands = DeleteMyCommands.builder().build();
|
||||
assertEquals("deleteMyCommands", deleteMyCommands.getMethod());
|
||||
assertDoesNotThrow(deleteMyCommands::validate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteMyCommandsWithEmptyStringLanguageCode() {
|
||||
DeleteMyCommands deleteMyCommands = DeleteMyCommands.builder().languageCode("").build();
|
||||
assertEquals("deleteMyCommands", deleteMyCommands.getMethod());
|
||||
Throwable thrown = assertThrows(TelegramApiValidationException.class, deleteMyCommands::validate);
|
||||
assertEquals("LanguageCode parameter can't be empty string", thrown.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteMyCommandsWithScope() {
|
||||
DeleteMyCommands deleteMyCommands = DeleteMyCommands
|
||||
.builder()
|
||||
.scope(BotCommandScopeDefault.builder().build())
|
||||
.build();
|
||||
assertEquals("deleteMyCommands", deleteMyCommands.getMethod());
|
||||
assertEquals("default", deleteMyCommands.getScope().getType());
|
||||
assertDoesNotThrow(deleteMyCommands::validate);
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.commands;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.telegram.telegrambots.meta.api.objects.commands.scope.BotCommandScopeDefault;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.3
|
||||
*/
|
||||
public class GetMyCommandsTest {
|
||||
@Test
|
||||
public void testGetMyCommandsWithAllSet() {
|
||||
GetMyCommands getMyCommands = GetMyCommands
|
||||
.builder()
|
||||
.languageCode("en")
|
||||
.scope(BotCommandScopeDefault.builder().build())
|
||||
.build();
|
||||
assertEquals("getMyCommands", getMyCommands.getMethod());
|
||||
assertDoesNotThrow(getMyCommands::validate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMyCommandsWithEmptyScope() {
|
||||
GetMyCommands getMyCommands = GetMyCommands
|
||||
.builder()
|
||||
.languageCode("en")
|
||||
.build();
|
||||
assertEquals("getMyCommands", getMyCommands.getMethod());
|
||||
assertDoesNotThrow(getMyCommands::validate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetMyCommandsWithEmptyStringLanguageCode() {
|
||||
GetMyCommands getMyCommands = GetMyCommands
|
||||
.builder()
|
||||
.languageCode("")
|
||||
.scope(BotCommandScopeDefault.builder().build())
|
||||
.build();
|
||||
assertEquals("getMyCommands", getMyCommands.getMethod());
|
||||
Throwable thrown = assertThrows(TelegramApiValidationException.class, getMyCommands::validate);
|
||||
assertEquals("LanguageCode parameter can't be empty string", thrown.getMessage());
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.commands;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.telegram.telegrambots.meta.api.objects.commands.BotCommand;
|
||||
import org.telegram.telegrambots.meta.api.objects.commands.scope.BotCommandScopeDefault;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.3
|
||||
*/
|
||||
public class SetMyCommandsTest {
|
||||
@Test
|
||||
public void testSetMyCommandsWithAllSet() {
|
||||
SetMyCommands setMyCommands = SetMyCommands
|
||||
.builder()
|
||||
.command(BotCommand.builder().command("test").description("Test description").build())
|
||||
.languageCode("en")
|
||||
.scope(BotCommandScopeDefault.builder().build())
|
||||
.build();
|
||||
assertEquals("setMyCommands", setMyCommands.getMethod());
|
||||
assertDoesNotThrow(setMyCommands::validate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetMyCommandsWithEmptyScope() {
|
||||
SetMyCommands setMyCommands = SetMyCommands
|
||||
.builder()
|
||||
.command(BotCommand.builder().command("test").description("Test description").build())
|
||||
.languageCode("en")
|
||||
.build();
|
||||
assertEquals("setMyCommands", setMyCommands.getMethod());
|
||||
assertDoesNotThrow(setMyCommands::validate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetMyCommandsWithEmptyStringLanguageCode() {
|
||||
SetMyCommands setMyCommands = SetMyCommands
|
||||
.builder()
|
||||
.command(BotCommand.builder().command("test").description("Test description").build())
|
||||
.languageCode("")
|
||||
.scope(BotCommandScopeDefault.builder().build())
|
||||
.build();
|
||||
assertEquals("setMyCommands", setMyCommands.getMethod());
|
||||
Throwable thrown = assertThrows(TelegramApiValidationException.class, setMyCommands::validate);
|
||||
assertEquals("LanguageCode parameter can't be empty string", thrown.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetMyCommandsWithEmptyCommands() {
|
||||
SetMyCommands setMyCommands = SetMyCommands
|
||||
.builder()
|
||||
.languageCode("en")
|
||||
.scope(BotCommandScopeDefault.builder().build())
|
||||
.build();
|
||||
assertEquals("setMyCommands", setMyCommands.getMethod());
|
||||
Throwable thrown = assertThrows(TelegramApiValidationException.class, setMyCommands::validate);
|
||||
assertEquals("Commands parameter can't be empty", thrown.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetMyCommandsWithMoreThan100Commands() {
|
||||
SetMyCommands setMyCommands = SetMyCommands
|
||||
.builder()
|
||||
.languageCode("en")
|
||||
.scope(BotCommandScopeDefault.builder().build())
|
||||
.build();
|
||||
List<BotCommand> commands = new ArrayList<>();
|
||||
for(int i = 0; i < 102; i++) {
|
||||
commands.add(BotCommand.builder().command("test").description("Test Description").build());
|
||||
}
|
||||
setMyCommands.setCommands(commands);
|
||||
assertEquals("setMyCommands", setMyCommands.getMethod());
|
||||
Throwable thrown = assertThrows(TelegramApiValidationException.class, setMyCommands::validate);
|
||||
assertEquals("No more than 100 commands are allowed", thrown.getMessage());
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.groupadministration;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.3
|
||||
*/
|
||||
public class BanChatMemberTest {
|
||||
@Test
|
||||
public void testBanChatMemberWithAllSet() {
|
||||
BanChatMember banChatMember = BanChatMember
|
||||
.builder()
|
||||
.chatId("12345")
|
||||
.userId(12345L)
|
||||
.untilDate(1000)
|
||||
.revokeMessages(true)
|
||||
.build();
|
||||
assertEquals("banChatMember", banChatMember.getMethod());
|
||||
assertDoesNotThrow(banChatMember::validate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBanChatMemberWithEmptyChatId() {
|
||||
BanChatMember banChatMember = BanChatMember
|
||||
.builder()
|
||||
.chatId("")
|
||||
.userId(12345L)
|
||||
.untilDate(1000)
|
||||
.revokeMessages(true)
|
||||
.build();
|
||||
assertEquals("banChatMember", banChatMember.getMethod());
|
||||
Throwable thrown = assertThrows(TelegramApiValidationException.class, banChatMember::validate);
|
||||
assertEquals("ChatId can't be empty", thrown.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBanChatMemberWithEmptyUserId() {
|
||||
BanChatMember banChatMember = BanChatMember
|
||||
.builder()
|
||||
.chatId("12345")
|
||||
.userId(0L)
|
||||
.untilDate(1000)
|
||||
.revokeMessages(true)
|
||||
.build();
|
||||
assertEquals("banChatMember", banChatMember.getMethod());
|
||||
Throwable thrown = assertThrows(TelegramApiValidationException.class, banChatMember::validate);
|
||||
assertEquals("UserId can't be null or 0", thrown.getMessage());
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.groupadministration;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.3
|
||||
*/
|
||||
public class GetChatMemberCountTest {
|
||||
@Test
|
||||
public void testGetChatMemberCountWithAllSet() {
|
||||
GetChatMemberCount getChatMemberCount = GetChatMemberCount
|
||||
.builder()
|
||||
.chatId("12345")
|
||||
.build();
|
||||
assertEquals("getChatMemberCount", getChatMemberCount.getMethod());
|
||||
assertDoesNotThrow(getChatMemberCount::validate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetChatMemberCountWithEmptyChatId() {
|
||||
GetChatMemberCount getChatMemberCount = GetChatMemberCount
|
||||
.builder()
|
||||
.chatId("")
|
||||
.build();
|
||||
assertEquals("getChatMemberCount", getChatMemberCount.getMethod());
|
||||
Throwable thrown = assertThrows(TelegramApiValidationException.class, getChatMemberCount::validate);
|
||||
assertEquals("ChatId can't be empty", thrown.getMessage());
|
||||
}
|
||||
}
|
@ -67,14 +67,6 @@ public class SendInvoiceTest {
|
||||
assertEquals("ProviderToken parameter can't be empty", thrown.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startParameterCantBeEmpty() {
|
||||
SendInvoice sendInvoice = createSendInvoiceObject();
|
||||
sendInvoice.setStartParameter("");
|
||||
Throwable thrown = assertThrows(TelegramApiValidationException.class, sendInvoice::validate);
|
||||
assertEquals("StartParameter parameter can't be empty", thrown.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void currencyCantBeEmpty() {
|
||||
SendInvoice sendInvoice = createSendInvoiceObject();
|
||||
|
@ -0,0 +1,203 @@
|
||||
package org.telegram.telegrambots.meta.api.objects.chatmember;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatMember;
|
||||
import org.telegram.telegrambots.meta.api.objects.User;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.3
|
||||
*/
|
||||
public class ChatMemberTest {
|
||||
@Test
|
||||
public void testDeserializationChatMember() throws TelegramApiRequestException {
|
||||
String text = "{\n" +
|
||||
" \"ok\": true,\n" +
|
||||
" \"result\": {\n" +
|
||||
" \"status\": \"member\",\n" +
|
||||
" \"user\": {\n" +
|
||||
" \"id\": 123456,\n" +
|
||||
" \"first_name\": \"FirstName\",\n" +
|
||||
" \"last_name\": \"LastName\",\n" +
|
||||
" \"username\": \"UserName\",\n" +
|
||||
" \"language_code\": \"en\"\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
ChatMember chatMember = new GetChatMember().deserializeResponse(text);
|
||||
assertEquals("member", chatMember.getStatus());
|
||||
ChatMemberMember chatMemberMember = (ChatMemberMember) chatMember;
|
||||
assertEquals(getUser(), chatMemberMember.getUser());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserializationChatMemberLeft() throws TelegramApiRequestException {
|
||||
String text = "{\n" +
|
||||
" \"ok\": true,\n" +
|
||||
" \"result\": {\n" +
|
||||
" \"status\": \"left\",\n" +
|
||||
" \"user\": {\n" +
|
||||
" \"id\": 123456,\n" +
|
||||
" \"first_name\": \"FirstName\",\n" +
|
||||
" \"last_name\": \"LastName\",\n" +
|
||||
" \"username\": \"UserName\",\n" +
|
||||
" \"language_code\": \"en\"\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
ChatMember chatMember = new GetChatMember().deserializeResponse(text);
|
||||
assertEquals("left", chatMember.getStatus());
|
||||
ChatMemberLeft chatMemberLeft = (ChatMemberLeft) chatMember;
|
||||
assertEquals(getUser(), chatMemberLeft.getUser());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserializationChatMemberBanned() throws TelegramApiRequestException {
|
||||
String text = "{\n" +
|
||||
" \"ok\": true,\n" +
|
||||
" \"result\": {\n" +
|
||||
" \"status\": \"kicked\",\n" +
|
||||
" \"user\": {\n" +
|
||||
" \"id\": 123456,\n" +
|
||||
" \"first_name\": \"FirstName\",\n" +
|
||||
" \"last_name\": \"LastName\",\n" +
|
||||
" \"username\": \"UserName\",\n" +
|
||||
" \"language_code\": \"en\"\n" +
|
||||
" },\n" +
|
||||
" \"until_date\": 10\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
ChatMember chatMember = new GetChatMember().deserializeResponse(text);
|
||||
assertEquals("kicked", chatMember.getStatus());
|
||||
ChatMemberBanned chatMemberBanned = (ChatMemberBanned) chatMember;
|
||||
assertEquals(getUser(), chatMemberBanned.getUser());
|
||||
assertEquals(10, chatMemberBanned.getUntilDate());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserializationChatMemberOwner() throws TelegramApiRequestException {
|
||||
String text = "{\n" +
|
||||
" \"ok\": true,\n" +
|
||||
" \"result\": {\n" +
|
||||
" \"status\": \"creator\",\n" +
|
||||
" \"user\": {\n" +
|
||||
" \"id\": 123456,\n" +
|
||||
" \"first_name\": \"FirstName\",\n" +
|
||||
" \"last_name\": \"LastName\",\n" +
|
||||
" \"username\": \"UserName\",\n" +
|
||||
" \"language_code\": \"en\"\n" +
|
||||
" },\n" +
|
||||
" \"custom_title\": \"CustomTitle\",\n" +
|
||||
" \"is_anonymous\": true\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
ChatMember chatMember = new GetChatMember().deserializeResponse(text);
|
||||
assertEquals("creator", chatMember.getStatus());
|
||||
ChatMemberOwner chatMemberOwner = (ChatMemberOwner) chatMember;
|
||||
assertEquals(getUser(), chatMemberOwner.getUser());
|
||||
assertEquals("CustomTitle", chatMemberOwner.getCustomTitle());
|
||||
assertEquals(true, chatMemberOwner.getIsAnonymous());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserializationChatMemberAdministrator() throws TelegramApiRequestException {
|
||||
String text = "{\n" +
|
||||
" \"ok\": true,\n" +
|
||||
" \"result\": {\n" +
|
||||
" \"status\": \"administrator\",\n" +
|
||||
" \"user\": {\n" +
|
||||
" \"id\": 123456,\n" +
|
||||
" \"first_name\": \"FirstName\",\n" +
|
||||
" \"last_name\": \"LastName\",\n" +
|
||||
" \"username\": \"UserName\",\n" +
|
||||
" \"language_code\": \"en\"\n" +
|
||||
" },\n" +
|
||||
" \"can_be_edited\": true,\n" +
|
||||
" \"custom_title\": \"CustomTitle\",\n" +
|
||||
" \"is_anonymous\": true,\n" +
|
||||
" \"can_manage_chat\": true,\n" +
|
||||
" \"can_post_messages\": true,\n" +
|
||||
" \"can_edit_messages\": true,\n" +
|
||||
" \"can_delete_messages\": true,\n" +
|
||||
" \"can_manage_voice_chats\": true,\n" +
|
||||
" \"can_restrict_members\": true,\n" +
|
||||
" \"can_promote_members\": true,\n" +
|
||||
" \"can_change_info\": true,\n" +
|
||||
" \"can_invite_users\": true,\n" +
|
||||
" \"can_pin_messages\": true\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
ChatMember chatMember = new GetChatMember().deserializeResponse(text);
|
||||
assertEquals("administrator", chatMember.getStatus());
|
||||
ChatMemberAdministrator chatMemberAdministrator = (ChatMemberAdministrator) chatMember;
|
||||
assertEquals(getUser(), chatMemberAdministrator.getUser());
|
||||
assertEquals("CustomTitle", chatMemberAdministrator.getCustomTitle());
|
||||
assertEquals(true, chatMemberAdministrator.getIsAnonymous());
|
||||
assertEquals(true, chatMemberAdministrator.getCanBeEdited());
|
||||
assertEquals(true, chatMemberAdministrator.getCanManageChat());
|
||||
assertEquals(true, chatMemberAdministrator.getCanPostMessages());
|
||||
assertEquals(true, chatMemberAdministrator.getCanEditMessages());
|
||||
assertEquals(true, chatMemberAdministrator.getCanDeleteMessages());
|
||||
assertEquals(true, chatMemberAdministrator.getCanManageVoiceChats());
|
||||
assertEquals(true, chatMemberAdministrator.getCanRestrictMembers());
|
||||
assertEquals(true, chatMemberAdministrator.getCanPromoteMembers());
|
||||
assertEquals(true, chatMemberAdministrator.getCanChangeInfo());
|
||||
assertEquals(true, chatMemberAdministrator.getCanInviteUsers());
|
||||
assertEquals(true, chatMemberAdministrator.getCanPinMessages());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserializationChatMemberRestricted() throws TelegramApiRequestException {
|
||||
String text = "{\n" +
|
||||
" \"ok\": true,\n" +
|
||||
" \"result\": {\n" +
|
||||
" \"status\": \"restricted\",\n" +
|
||||
" \"user\": {\n" +
|
||||
" \"id\": 123456,\n" +
|
||||
" \"first_name\": \"FirstName\",\n" +
|
||||
" \"last_name\": \"LastName\",\n" +
|
||||
" \"username\": \"UserName\",\n" +
|
||||
" \"language_code\": \"en\"\n" +
|
||||
" },\n" +
|
||||
" \"is_anonymous\": true,\n" +
|
||||
" \"can_change_info\": true,\n" +
|
||||
" \"can_invite_users\": true,\n" +
|
||||
" \"can_pin_messages\": true,\n" +
|
||||
" \"is_member\": true,\n" +
|
||||
" \"can_send_messages\": true,\n" +
|
||||
" \"can_send_media_messages\": true,\n" +
|
||||
" \"can_send_polls\": true,\n" +
|
||||
" \"can_send_other_messages\": true,\n" +
|
||||
" \"can_add_web_page_previews\": true,\n" +
|
||||
" \"until_date\": 100\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
ChatMember chatMember = new GetChatMember().deserializeResponse(text);
|
||||
assertEquals("restricted", chatMember.getStatus());
|
||||
ChatMemberRestricted chatMemberRestricted = (ChatMemberRestricted) chatMember;
|
||||
assertEquals(getUser(), chatMemberRestricted.getUser());
|
||||
assertEquals(true, chatMemberRestricted.getCanChangeInfo());
|
||||
assertEquals(true, chatMemberRestricted.getCanInviteUsers());
|
||||
assertEquals(true, chatMemberRestricted.getCanPinMessages());
|
||||
assertEquals(true, chatMemberRestricted.getCanSendMessages());
|
||||
assertEquals(true, chatMemberRestricted.getCanSendMediaMessages());
|
||||
assertEquals(true, chatMemberRestricted.getCanSendPolls());
|
||||
assertEquals(true, chatMemberRestricted.getCanSendOtherMessages());
|
||||
assertEquals(true, chatMemberRestricted.getCanAddWebpagePreviews());
|
||||
assertEquals(100, chatMemberRestricted.getUntilDate());
|
||||
}
|
||||
|
||||
|
||||
private User getUser() {
|
||||
User user = new User();
|
||||
user.setId(123456L);
|
||||
user.setFirstName("FirstName");
|
||||
user.setLastName("LastName");
|
||||
user.setUserName("UserName");
|
||||
user.setLanguageCode("en");
|
||||
return user;
|
||||
}
|
||||
}
|
@ -0,0 +1,120 @@
|
||||
package org.telegram.telegrambots.meta.api.objects.commands.scope;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
*/
|
||||
public class BotCommandScopeTest {
|
||||
@Test
|
||||
public void testBotCommandScopeDefault() {
|
||||
BotCommandScopeDefault botCommandScope = BotCommandScopeDefault.builder().build();
|
||||
assertEquals("default", botCommandScope.getType());
|
||||
assertDoesNotThrow(botCommandScope::validate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBotCommandScopeAllChatAdministrators() {
|
||||
BotCommandScopeAllChatAdministrators botCommandScope = BotCommandScopeAllChatAdministrators.builder().build();
|
||||
assertEquals("all_chat_administrators", botCommandScope.getType());
|
||||
assertDoesNotThrow(botCommandScope::validate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBotCommandScopeAllGroupChats() {
|
||||
BotCommandScopeAllGroupChats botCommandScope = BotCommandScopeAllGroupChats.builder().build();
|
||||
assertEquals("all_group_chats", botCommandScope.getType());
|
||||
assertDoesNotThrow(botCommandScope::validate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBotCommandScopeAllPrivateChats() {
|
||||
BotCommandScopeAllPrivateChats botCommandScope = BotCommandScopeAllPrivateChats.builder().build();
|
||||
assertEquals("all_private_chats", botCommandScope.getType());
|
||||
assertDoesNotThrow(botCommandScope::validate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBotCommandScopeChatWithValidChatIId() {
|
||||
BotCommandScopeChat botCommandScope = BotCommandScopeChat
|
||||
.builder()
|
||||
.chatId("12345")
|
||||
.build();
|
||||
assertEquals("chat", botCommandScope.getType());
|
||||
assertDoesNotThrow(botCommandScope::validate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBotCommandScopeChatWithEmptyChatId() {
|
||||
BotCommandScopeChat botCommandScope = BotCommandScopeChat
|
||||
.builder()
|
||||
.chatId("")
|
||||
.build();
|
||||
assertEquals("chat", botCommandScope.getType());
|
||||
Throwable thrown = assertThrows(TelegramApiValidationException.class, botCommandScope::validate);
|
||||
assertEquals("ChatId parameter can't be empty", thrown.getMessage());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBotCommandScopeChatAdministratorsWithValidChatIId() {
|
||||
BotCommandScopeChatAdministrators botCommandScope = BotCommandScopeChatAdministrators
|
||||
.builder()
|
||||
.chatId("12345")
|
||||
.build();
|
||||
assertEquals("chat_administrators", botCommandScope.getType());
|
||||
assertDoesNotThrow(botCommandScope::validate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBotCommandScopeChatAdministratorsWithEmptyChatId() {
|
||||
BotCommandScopeChatAdministrators botCommandScope = BotCommandScopeChatAdministrators
|
||||
.builder()
|
||||
.chatId("")
|
||||
.build();
|
||||
assertEquals("chat_administrators", botCommandScope.getType());
|
||||
Throwable thrown = assertThrows(TelegramApiValidationException.class, botCommandScope::validate);
|
||||
assertEquals("ChatId parameter can't be empty", thrown.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBotCommandScopeChatMemberWithValidSetUp() {
|
||||
BotCommandScopeChatMember botCommandScope = BotCommandScopeChatMember
|
||||
.builder()
|
||||
.chatId("12345")
|
||||
.userId(12345L)
|
||||
.build();
|
||||
assertEquals("chat_member", botCommandScope.getType());
|
||||
assertDoesNotThrow(botCommandScope::validate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBotCommandScopeChatMemberWithEmptyChatId() {
|
||||
BotCommandScopeChatMember botCommandScope = BotCommandScopeChatMember
|
||||
.builder()
|
||||
.chatId("")
|
||||
.userId(12345L)
|
||||
.build();
|
||||
assertEquals("chat_member", botCommandScope.getType());
|
||||
Throwable thrown = assertThrows(TelegramApiValidationException.class, botCommandScope::validate);
|
||||
assertEquals("ChatId parameter can't be empty", thrown.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBotCommandScopeChatMemberWith0UserId() {
|
||||
BotCommandScopeChatMember botCommandScope = BotCommandScopeChatMember
|
||||
.builder()
|
||||
.chatId("12345")
|
||||
.userId(0L)
|
||||
.build();
|
||||
assertEquals("chat_member", botCommandScope.getType());
|
||||
Throwable thrown = assertThrows(TelegramApiValidationException.class, botCommandScope::validate);
|
||||
assertEquals("UserId parameter can't be empty", thrown.getMessage());
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package org.telegram.telegrambots.meta.api.objects.replykeyboard;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
*/
|
||||
public class ForceReplyKeyboardTest {
|
||||
@Test
|
||||
public void testForceReplyDefaultFields() {
|
||||
ForceReplyKeyboard forceReplyKeyboard = ForceReplyKeyboard
|
||||
.builder()
|
||||
.build();
|
||||
assertDoesNotThrow(forceReplyKeyboard::validate);
|
||||
forceReplyKeyboard = new ForceReplyKeyboard();
|
||||
assertDoesNotThrow(forceReplyKeyboard::validate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForceReplyAllFieldSet() {
|
||||
ForceReplyKeyboard forceReplyKeyboard = ForceReplyKeyboard
|
||||
.builder()
|
||||
.forceReply(true)
|
||||
.selective(true)
|
||||
.inputFieldPlaceholder("Placeholder")
|
||||
.build();
|
||||
assertDoesNotThrow(forceReplyKeyboard::validate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForceReplyEmptyInputPlaceholder() {
|
||||
ForceReplyKeyboard forceReplyKeyboard = ForceReplyKeyboard
|
||||
.builder()
|
||||
.forceReply(true)
|
||||
.selective(true)
|
||||
.inputFieldPlaceholder("")
|
||||
.build();
|
||||
Throwable thrown = assertThrows(TelegramApiValidationException.class, forceReplyKeyboard::validate);
|
||||
assertEquals("InputFieldPlaceholder must be between 1 and 64 characters", thrown.getMessage());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testForceReplyOver64InputPlaceholder() {
|
||||
ForceReplyKeyboard forceReplyKeyboard = ForceReplyKeyboard
|
||||
.builder()
|
||||
.forceReply(true)
|
||||
.selective(true)
|
||||
.inputFieldPlaceholder("D%YNdVJe/6xUGR_)W]rVLx_,g/9:ZX7+XiiM-*nPm{(g5gEtv![te6H[;tWAT&Z4K")
|
||||
.build();
|
||||
Throwable thrown = assertThrows(TelegramApiValidationException.class, forceReplyKeyboard::validate);
|
||||
assertEquals("InputFieldPlaceholder must be between 1 and 64 characters", thrown.getMessage());
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
package org.telegram.telegrambots.meta.api.objects.replykeyboard;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.KeyboardButton;
|
||||
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.KeyboardRow;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
*/
|
||||
public class ReplyKeyboardMarkupTest {
|
||||
@Test
|
||||
public void testReplyKeyboardMarkupAllDefaults() {
|
||||
ReplyKeyboardMarkup replyKeyboardMarkup = ReplyKeyboardMarkup
|
||||
.builder()
|
||||
.build();
|
||||
assertDoesNotThrow(replyKeyboardMarkup::validate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReplyKeyboardMarkupAllFieldSet() {
|
||||
ReplyKeyboardMarkup replyKeyboardMarkup = ReplyKeyboardMarkup
|
||||
.builder()
|
||||
.keyboard(Collections.singletonList(new KeyboardRow(Collections.singletonList(KeyboardButton
|
||||
.builder()
|
||||
.text("ButtonText")
|
||||
.build()))))
|
||||
.resizeKeyboard(true)
|
||||
.oneTimeKeyboard(true)
|
||||
.selective(true)
|
||||
.inputFieldPlaceholder("Placeholder")
|
||||
.build();
|
||||
assertDoesNotThrow(replyKeyboardMarkup::validate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReplyKeyboardMarkupEmptyInputPlaceholder() {
|
||||
ReplyKeyboardMarkup replyKeyboardMarkup = ReplyKeyboardMarkup
|
||||
.builder()
|
||||
.keyboard(Collections.singletonList(new KeyboardRow(Collections.singletonList(KeyboardButton
|
||||
.builder()
|
||||
.text("ButtonText")
|
||||
.build()))))
|
||||
.resizeKeyboard(true)
|
||||
.oneTimeKeyboard(true)
|
||||
.selective(true)
|
||||
.inputFieldPlaceholder("")
|
||||
.build();
|
||||
Throwable thrown = assertThrows(TelegramApiValidationException.class, replyKeyboardMarkup::validate);
|
||||
assertEquals("InputFieldPlaceholder must be between 1 and 64 characters", thrown.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReplyKeyboardMarkupOver64InputPlaceholder() {
|
||||
ReplyKeyboardMarkup replyKeyboardMarkup = ReplyKeyboardMarkup
|
||||
.builder()
|
||||
.keyboard(Collections.singletonList(new KeyboardRow(Collections.singletonList(KeyboardButton
|
||||
.builder()
|
||||
.text("ButtonText")
|
||||
.build()))))
|
||||
.resizeKeyboard(true)
|
||||
.oneTimeKeyboard(true)
|
||||
.selective(true)
|
||||
.inputFieldPlaceholder("D%YNdVJe/6xUGR_)W]rVLx_,g/9:ZX7+XiiM-*nPm{(g5gEtv![te6H[;tWAT&Z4K")
|
||||
.build();
|
||||
Throwable thrown = assertThrows(TelegramApiValidationException.class, replyKeyboardMarkup::validate);
|
||||
assertEquals("InputFieldPlaceholder must be between 1 and 64 characters", thrown.getMessage());
|
||||
}
|
||||
}
|
@ -15,7 +15,6 @@ import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.api.objects.Audio;
|
||||
import org.telegram.telegrambots.meta.api.objects.CallbackQuery;
|
||||
import org.telegram.telegrambots.meta.api.objects.Chat;
|
||||
import org.telegram.telegrambots.meta.api.objects.ChatMember;
|
||||
import org.telegram.telegrambots.meta.api.objects.Document;
|
||||
import org.telegram.telegrambots.meta.api.objects.EntityType;
|
||||
import org.telegram.telegrambots.meta.api.objects.Message;
|
||||
@ -23,6 +22,8 @@ import org.telegram.telegrambots.meta.api.objects.MessageEntity;
|
||||
import org.telegram.telegrambots.meta.api.objects.Update;
|
||||
import org.telegram.telegrambots.meta.api.objects.User;
|
||||
import org.telegram.telegrambots.meta.api.objects.Voice;
|
||||
import org.telegram.telegrambots.meta.api.objects.chatmember.ChatMember;
|
||||
import org.telegram.telegrambots.meta.api.objects.chatmember.ChatMemberRestricted;
|
||||
import org.telegram.telegrambots.meta.api.objects.commands.BotCommand;
|
||||
import org.telegram.telegrambots.meta.api.objects.inlinequery.ChosenInlineQuery;
|
||||
import org.telegram.telegrambots.meta.api.objects.inlinequery.InlineQuery;
|
||||
@ -322,25 +323,27 @@ class TestDeserialization {
|
||||
" }\n" +
|
||||
"}";
|
||||
|
||||
ChatMember response = new GetChatMember().deserializeResponse(updateText);
|
||||
ChatMember chatMember = new GetChatMember().deserializeResponse(updateText);
|
||||
|
||||
assertNotNull(response);
|
||||
assertNotNull(response.getUser());
|
||||
assertEquals(1111111, response.getUser().getId());
|
||||
assertTrue(response.getUser().getIsBot());
|
||||
assertEquals("MyTesting", response.getUser().getFirstName());
|
||||
assertEquals("MyTestingUsername", response.getUser().getUserName());
|
||||
assertEquals("restricted", response.getStatus());
|
||||
assertEquals(0, response.getUntilDate());
|
||||
assertFalse(response.getCanSendMessages());
|
||||
assertFalse(response.getCanSendMediaMessages());
|
||||
assertFalse(response.getCanSendPolls());
|
||||
assertFalse(response.getCanSendOtherMessages());
|
||||
assertFalse(response.getCanAddWebPagePreviews());
|
||||
assertFalse(response.getCanChangeInfo());
|
||||
assertFalse(response.getCanInviteUsers());
|
||||
assertFalse(response.getCanPinMessages());
|
||||
assertTrue(response.getIsMember());
|
||||
assertNotNull(chatMember);
|
||||
assertTrue(chatMember instanceof ChatMemberRestricted);
|
||||
ChatMemberRestricted chatMemberRestricted = (ChatMemberRestricted) chatMember;
|
||||
assertNotNull(chatMemberRestricted.getUser());
|
||||
assertEquals(1111111, chatMemberRestricted.getUser().getId());
|
||||
assertTrue(chatMemberRestricted.getUser().getIsBot());
|
||||
assertEquals("MyTesting", chatMemberRestricted.getUser().getFirstName());
|
||||
assertEquals("MyTestingUsername", chatMemberRestricted.getUser().getUserName());
|
||||
assertEquals("restricted", chatMemberRestricted.getStatus());
|
||||
assertEquals(0, chatMemberRestricted.getUntilDate());
|
||||
assertFalse(chatMemberRestricted.getCanSendMessages());
|
||||
assertFalse(chatMemberRestricted.getCanSendMediaMessages());
|
||||
assertFalse(chatMemberRestricted.getCanSendPolls());
|
||||
assertFalse(chatMemberRestricted.getCanSendOtherMessages());
|
||||
assertFalse(chatMemberRestricted.getCanAddWebpagePreviews());
|
||||
assertFalse(chatMemberRestricted.getCanChangeInfo());
|
||||
assertFalse(chatMemberRestricted.getCanInviteUsers());
|
||||
assertFalse(chatMemberRestricted.getCanPinMessages());
|
||||
assertTrue(chatMemberRestricted.getIsMember());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -18,14 +18,14 @@ Usage
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots-spring-boot-starter</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.4.0.1</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
**Gradle**
|
||||
|
||||
```gradle
|
||||
implementation 'org.telegram:telegrambots-spring-boot-starter:5.2.0'
|
||||
implementation 'org.telegram:telegrambots-spring-boot-starter:5.4.0.1'
|
||||
```
|
||||
|
||||
Motivation
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>Bots</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.4.0.1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>telegrambots-spring-boot-starter</artifactId>
|
||||
@ -70,7 +70,7 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
|
||||
<telegrambots.version>5.2.0</telegrambots.version>
|
||||
<telegrambots.version>5.4.0.1</telegrambots.version>
|
||||
<spring-boot.version>2.4.5</spring-boot.version>
|
||||
|
||||
<maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>Bots</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.4.0.1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>telegrambots</artifactId>
|
||||
@ -92,7 +92,7 @@
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots-meta</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.4.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
|
@ -610,7 +610,7 @@ public abstract class DefaultAbsSender extends AbsSender {
|
||||
assertParamNotNull(setStickerSetThumb, "setStickerSetThumb");
|
||||
setStickerSetThumb.validate();
|
||||
try {
|
||||
String url = getBaseUrl() + AddStickerToSet.PATH;
|
||||
String url = getBaseUrl() + SetStickerSetThumb.PATH;
|
||||
HttpPost httppost = configuredHttpPost(url);
|
||||
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
|
||||
builder.setLaxMode();
|
||||
@ -623,7 +623,7 @@ public abstract class DefaultAbsSender extends AbsSender {
|
||||
|
||||
return setStickerSetThumb.deserializeResponse(sendHttpPostRequest(httppost));
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiException("Unable to add sticker to set", e);
|
||||
throw new TelegramApiException("Unable to set sticker set thumb", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ public class TelegramFileDownloader {
|
||||
|
||||
public final java.io.File downloadFile(String filePath, java.io.File outputFile) throws TelegramApiException {
|
||||
if (filePath == null || filePath.isEmpty()) {
|
||||
throw new TelegramApiException("Parameter file can not be null");
|
||||
throw new TelegramApiException("Parameter file can not be null or empty");
|
||||
}
|
||||
String url = File.getFileUrl(botTokenSupplier.get(), filePath);
|
||||
return downloadToFile(url, outputFile);
|
||||
@ -84,7 +84,7 @@ public class TelegramFileDownloader {
|
||||
|
||||
public final void downloadFileAsync(String filePath, DownloadFileCallback<String> callback) throws TelegramApiException {
|
||||
if (filePath == null || filePath.isEmpty()) {
|
||||
throw new TelegramApiException("Parameter filePath can not be null");
|
||||
throw new TelegramApiException("Parameter filePath can not be null or empty");
|
||||
}
|
||||
if (callback == null) {
|
||||
throw new TelegramApiException("Parameter callback can not be null");
|
||||
|
@ -11,11 +11,11 @@ import org.telegram.telegrambots.meta.api.methods.GetUserProfilePhotos;
|
||||
import org.telegram.telegrambots.meta.api.methods.ParseMode;
|
||||
import org.telegram.telegrambots.meta.api.methods.games.GetGameHighScores;
|
||||
import org.telegram.telegrambots.meta.api.methods.games.SetGameScore;
|
||||
import org.telegram.telegrambots.meta.api.methods.groupadministration.BanChatMember;
|
||||
import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChat;
|
||||
import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatAdministrators;
|
||||
import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatMember;
|
||||
import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatMembersCount;
|
||||
import org.telegram.telegrambots.meta.api.methods.groupadministration.KickChatMember;
|
||||
import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatMemberCount;
|
||||
import org.telegram.telegrambots.meta.api.methods.groupadministration.LeaveChat;
|
||||
import org.telegram.telegrambots.meta.api.methods.groupadministration.UnbanChatMember;
|
||||
import org.telegram.telegrambots.meta.api.methods.send.SendChatAction;
|
||||
@ -30,12 +30,12 @@ import org.telegram.telegrambots.meta.api.methods.updatingmessages.EditMessageCa
|
||||
import org.telegram.telegrambots.meta.api.methods.updatingmessages.EditMessageReplyMarkup;
|
||||
import org.telegram.telegrambots.meta.api.methods.updatingmessages.EditMessageText;
|
||||
import org.telegram.telegrambots.meta.api.objects.Chat;
|
||||
import org.telegram.telegrambots.meta.api.objects.ChatMember;
|
||||
import org.telegram.telegrambots.meta.api.objects.File;
|
||||
import org.telegram.telegrambots.meta.api.objects.Message;
|
||||
import org.telegram.telegrambots.meta.api.objects.User;
|
||||
import org.telegram.telegrambots.meta.api.objects.UserProfilePhotos;
|
||||
import org.telegram.telegrambots.meta.api.objects.WebhookInfo;
|
||||
import org.telegram.telegrambots.meta.api.objects.chatmember.ChatMember;
|
||||
import org.telegram.telegrambots.meta.api.objects.games.GameHighScore;
|
||||
import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent;
|
||||
import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputTextMessageContent;
|
||||
@ -159,8 +159,8 @@ public final class BotApiMethodHelperFactory {
|
||||
.build();
|
||||
}
|
||||
|
||||
public static BotApiMethod<Integer> getChatMembersCount() {
|
||||
return GetChatMembersCount
|
||||
public static BotApiMethod<Integer> getChatMemberCount() {
|
||||
return GetChatMemberCount
|
||||
.builder()
|
||||
.chatId("12345")
|
||||
.build();
|
||||
@ -199,8 +199,8 @@ public final class BotApiMethodHelperFactory {
|
||||
return new GetWebhookInfo();
|
||||
}
|
||||
|
||||
public static BotApiMethod<Boolean> getKickChatMember() {
|
||||
return KickChatMember
|
||||
public static BotApiMethod<Boolean> getBanChatMember() {
|
||||
return BanChatMember
|
||||
.builder()
|
||||
.chatId("12345")
|
||||
.userId(98765L)
|
||||
|
@ -16,11 +16,11 @@ import org.telegram.telegrambots.meta.api.methods.GetMe;
|
||||
import org.telegram.telegrambots.meta.api.methods.GetUserProfilePhotos;
|
||||
import org.telegram.telegrambots.meta.api.methods.games.GetGameHighScores;
|
||||
import org.telegram.telegrambots.meta.api.methods.games.SetGameScore;
|
||||
import org.telegram.telegrambots.meta.api.methods.groupadministration.BanChatMember;
|
||||
import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChat;
|
||||
import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatAdministrators;
|
||||
import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatMember;
|
||||
import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatMembersCount;
|
||||
import org.telegram.telegrambots.meta.api.methods.groupadministration.KickChatMember;
|
||||
import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatMemberCount;
|
||||
import org.telegram.telegrambots.meta.api.methods.groupadministration.LeaveChat;
|
||||
import org.telegram.telegrambots.meta.api.methods.groupadministration.UnbanChatMember;
|
||||
import org.telegram.telegrambots.meta.api.methods.send.SendChatAction;
|
||||
@ -35,13 +35,13 @@ import org.telegram.telegrambots.meta.api.methods.updatingmessages.EditMessageCa
|
||||
import org.telegram.telegrambots.meta.api.methods.updatingmessages.EditMessageReplyMarkup;
|
||||
import org.telegram.telegrambots.meta.api.methods.updatingmessages.EditMessageText;
|
||||
import org.telegram.telegrambots.meta.api.objects.Chat;
|
||||
import org.telegram.telegrambots.meta.api.objects.ChatMember;
|
||||
import org.telegram.telegrambots.meta.api.objects.File;
|
||||
import org.telegram.telegrambots.meta.api.objects.Message;
|
||||
import org.telegram.telegrambots.meta.api.objects.Update;
|
||||
import org.telegram.telegrambots.meta.api.objects.User;
|
||||
import org.telegram.telegrambots.meta.api.objects.UserProfilePhotos;
|
||||
import org.telegram.telegrambots.meta.api.objects.WebhookInfo;
|
||||
import org.telegram.telegrambots.meta.api.objects.chatmember.ChatMember;
|
||||
import org.telegram.telegrambots.meta.api.objects.games.GameHighScore;
|
||||
import org.telegram.telegrambots.test.Fakes.FakeWebhook;
|
||||
import org.telegram.telegrambots.updatesreceivers.RestApi;
|
||||
@ -219,13 +219,13 @@ public class TestRestApi extends JerseyTest {
|
||||
|
||||
@Test
|
||||
public void TestGetChatMembersCount() {
|
||||
webhookBot.setReturnValue(BotApiMethodHelperFactory.getChatMembersCount());
|
||||
webhookBot.setReturnValue(BotApiMethodHelperFactory.getChatMemberCount());
|
||||
|
||||
Entity<Update> entity = Entity.json(getUpdate());
|
||||
BotApiMethod<Integer> result =
|
||||
target("callback/testbot")
|
||||
.request(MediaType.APPLICATION_JSON)
|
||||
.post(entity, GetChatMembersCount.class);
|
||||
.post(entity, GetChatMemberCount.class);
|
||||
|
||||
assertEquals("{\"chat_id\":\"12345\",\"method\":\"getChatMembersCount\"}", map(result));
|
||||
}
|
||||
@ -297,13 +297,13 @@ public class TestRestApi extends JerseyTest {
|
||||
|
||||
@Test
|
||||
public void TestKickChatMember() {
|
||||
webhookBot.setReturnValue(BotApiMethodHelperFactory.getKickChatMember());
|
||||
webhookBot.setReturnValue(BotApiMethodHelperFactory.getBanChatMember());
|
||||
|
||||
Entity<Update> entity = Entity.json(getUpdate());
|
||||
BotApiMethod<Boolean> result =
|
||||
target("callback/testbot")
|
||||
.request(MediaType.APPLICATION_JSON)
|
||||
.post(entity, KickChatMember.class);
|
||||
.post(entity, BanChatMember.class);
|
||||
|
||||
assertEquals("{\"chat_id\":\"12345\",\"user_id\":98765,\"method\":\"kickchatmember\"}", map(result));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user