Merge pull request #938 from rubenlagus/dev

Dev
This commit is contained in:
Ruben Bermudez 2021-07-04 22:03:27 +01:00 committed by GitHub
commit 247274a568
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
67 changed files with 2200 additions and 211 deletions

View File

@ -27,18 +27,18 @@ Just import add the library to your project with one of these options:
<dependency> <dependency>
<groupId>org.telegram</groupId> <groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId> <artifactId>telegrambots</artifactId>
<version>5.2.0</version> <version>5.3.0</version>
</dependency> </dependency>
``` ```
2. Using Gradle: 2. Using Gradle:
```gradle ```gradle
implementation 'org.telegram:telegrambots:5.2.0' implementation 'org.telegram:telegrambots:5.3.0'
``` ```
3. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/5.2.0) 3. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/5.3.0)
4. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/5.2.0) 4. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/5.3.0)
In order to use Long Polling mode, just create your own bot extending `org.telegram.telegrambots.bots.TelegramLongPollingBot`. In order to use Long Polling mode, just create your own bot extending `org.telegram.telegrambots.bots.TelegramLongPollingBot`.

View File

@ -1,5 +1,12 @@
### <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 ### ### <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 2. Allow custom BackOff implementations
3. Spring version 2.4.5 in spring module 3. Spring version 2.4.5 in spring module
4. Bug fixing: #869, #888 and #892 4. Bug fixing: #869, #888 and #892

View File

@ -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? ## ## <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: 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:

View File

@ -11,13 +11,13 @@ First you need ot get the library and add it to your project. There are few poss
<dependency> <dependency>
<groupId>org.telegram</groupId> <groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId> <artifactId>telegrambots</artifactId>
<version>5.2.0</version> <version>5.3.0</version>
</dependency> </dependency>
``` ```
* With **Gradle**: * With **Gradle**:
```gradle ```gradle
implementation 'org.telegram:telegrambots:5.2.0' implementation 'org.telegram:telegrambots:5.3.0'
``` ```
2. Don't like **Maven Central Repository**? It can also be taken from [Jitpack](https://jitpack.io/#rubenlagus/TelegramBots). 2. Don't like **Maven Central Repository**? It can also be taken from [Jitpack](https://jitpack.io/#rubenlagus/TelegramBots).

View File

@ -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 ### ### <a id="5.1.0"></a>To version 5.1.0 ###
1. All users IDs fields are now Long type as per API guidelines. 1. All users IDs fields are now Long type as per API guidelines.

View File

@ -9,12 +9,12 @@ As with any Java project, you will need to set your dependencies.
<dependency> <dependency>
<groupId>org.telegram</groupId> <groupId>org.telegram</groupId>
<artifactId>telegrambots-abilities</artifactId> <artifactId>telegrambots-abilities</artifactId>
<version>5.2.0</version> <version>5.3.0</version>
</dependency> </dependency>
``` ```
* **Gradle** * **Gradle**
```gradle ```gradle
implementation 'org.telegram:telegrambots-abilities:5.2.0' implementation 'org.telegram:telegrambots-abilities:5.3.0'
``` ```
* [JitPack](https://jitpack.io/#rubenlagus/TelegramBots) * [JitPack](https://jitpack.io/#rubenlagus/TelegramBots)

View File

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

View File

@ -18,14 +18,14 @@ Usage
<dependency> <dependency>
<groupId>org.telegram</groupId> <groupId>org.telegram</groupId>
<artifactId>telegrambots-abilities</artifactId> <artifactId>telegrambots-abilities</artifactId>
<version>5.2.0</version> <version>5.3.0</version>
</dependency> </dependency>
``` ```
**Gradle** **Gradle**
```gradle ```gradle
implementation 'org.telegram:telegrambots-abilities:5.2.0' implementation 'org.telegram:telegrambots-abilities:5.3.0'
``` ```
**JitPack** - [JitPack](https://jitpack.io/#rubenlagus/TelegramBots/v5.0.1) **JitPack** - [JitPack](https://jitpack.io/#rubenlagus/TelegramBots/v5.0.1)

View File

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

View File

@ -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.Message;
import org.telegram.telegrambots.meta.api.objects.Update; import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.api.objects.User; 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.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -260,8 +262,17 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability
public boolean isGroupAdmin(long chatId, long id) { public boolean isGroupAdmin(long chatId, long id) {
GetChatAdministrators admins = GetChatAdministrators.builder().chatId(Long.toString(chatId)).build(); GetChatAdministrators admins = GetChatAdministrators.builder().chatId(Long.toString(chatId)).build();
return silent.execute(admins) return silent.execute(admins)
.orElse(new ArrayList<>()).stream() .orElse(new ArrayList<>())
.anyMatch(member -> member.getUser().getId() == id); .stream()
.map(member -> {
if (member instanceof ChatMemberAdministrator) {
return ((ChatMemberAdministrator) member).getUser().getId();
} else if (member instanceof ChatMemberOwner) {
return ((ChatMemberOwner) member).getUser().getId();
}
return 0L;
})
.anyMatch(member -> member == id);
} }
public boolean isCreator(long id) { public boolean isCreator(long id) {

View File

@ -39,7 +39,10 @@ public class SilentSender {
SendMessage msg = new SendMessage(); SendMessage msg = new SendMessage();
msg.setText(message); msg.setText(message);
msg.setChatId(Long.toString(id)); 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); return execute(msg);
} }

View File

@ -10,14 +10,23 @@ import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers; import org.mockito.ArgumentMatchers;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.telegram.abilitybots.api.db.DBContext; 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.MessageSender;
import org.telegram.abilitybots.api.sender.SilentSender; import org.telegram.abilitybots.api.sender.SilentSender;
import org.telegram.abilitybots.api.util.AbilityUtils; import org.telegram.abilitybots.api.util.AbilityUtils;
import org.telegram.abilitybots.api.util.Pair; import org.telegram.abilitybots.api.util.Pair;
import org.telegram.abilitybots.api.util.Trio; import org.telegram.abilitybots.api.util.Trio;
import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatAdministrators; 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.ChatMemberAdministrator;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import java.io.BufferedWriter; import java.io.BufferedWriter;
@ -37,19 +46,32 @@ import static java.util.Optional.empty;
import static org.apache.commons.io.FileUtils.deleteQuietly; import static org.apache.commons.io.FileUtils.deleteQuietly;
import static org.apache.commons.lang3.ArrayUtils.addAll; import static org.apache.commons.lang3.ArrayUtils.addAll;
import static org.apache.commons.lang3.StringUtils.EMPTY; import static org.apache.commons.lang3.StringUtils.EMPTY;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.*; 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.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.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.db.MapDBContext.offlineInstance;
import static org.telegram.abilitybots.api.objects.Flag.DOCUMENT; 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.Flag.MESSAGE;
import static org.telegram.abilitybots.api.objects.Locality.ALL; 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.Locality.GROUP;
import static org.telegram.abilitybots.api.objects.MessageContext.newContext; 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 { public class AbilityBotTest {
// Messages // Messages
@ -431,7 +453,7 @@ public class AbilityBotTest {
mockUser(update, message, user); mockUser(update, message, user);
when(message.isGroupMessage()).thenReturn(true); when(message.isGroupMessage()).thenReturn(true);
ChatMember member = mock(ChatMember.class); ChatMemberAdministrator member = mock(ChatMemberAdministrator.class);
when(member.getUser()).thenReturn(user); when(member.getUser()).thenReturn(user);
when(member.getUser()).thenReturn(user); when(member.getUser()).thenReturn(user);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,15 +1,18 @@
package org.telegram.telegrambots.meta.api.methods.commands; package org.telegram.telegrambots.meta.api.methods.commands;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import lombok.ToString; import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod; import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ApiResponse; 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.BotCommand;
import org.telegram.telegrambots.meta.api.objects.commands.scope.BotCommandScope;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
@ -19,19 +22,38 @@ import java.util.ArrayList;
/** /**
* @author Ruben Bermudez * @author Ruben Bermudez
* @version 4.7 * @version 4.7
* Use this method to get the current list of the bot's commands. * Use this method to get the current list of the bot's commands for the given scope and user language.
* Requires no parameters.
* Returns Array of BotCommand on success. * Returns Array of BotCommand on success.
* If commands aren't set, an empty list is returned.
*/ */
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
@Getter @Getter
@Setter @Setter
@ToString @ToString
@NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
public class GetMyCommands extends BotApiMethod<ArrayList<BotCommand>> { public class GetMyCommands extends BotApiMethod<ArrayList<BotCommand>> {
public static final String PATH = "getMyCommands"; 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 @Override
public String getMethod() { public String getMethod() {
return PATH; return PATH;
@ -54,5 +76,11 @@ public class GetMyCommands extends BotApiMethod<ArrayList<BotCommand>> {
@Override @Override
public void validate() throws TelegramApiValidationException { 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);
}
} }
} }

View File

@ -14,6 +14,7 @@ import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod; import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ApiResponse; 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.BotCommand;
import org.telegram.telegrambots.meta.api.objects.commands.scope.BotCommandScope;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
@ -23,7 +24,9 @@ import java.util.List;
/** /**
* @author Ruben Bermudez * @author Ruben Bermudez
* @version 4.7 * @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) @EqualsAndHashCode(callSuper = false)
@Getter @Getter
@ -36,6 +39,8 @@ public class SetMyCommands extends BotApiMethod<Boolean> {
public static final String PATH = "setMyCommands"; public static final String PATH = "setMyCommands";
private static final String COMMANDS_FIELD = "commands"; 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. * 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 @Singular
@NonNull @NonNull
private List<BotCommand> commands; 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 @Override
public String getMethod() { public String getMethod() {
@ -68,7 +87,10 @@ public class SetMyCommands extends BotApiMethod<Boolean> {
@Override @Override
public void validate() throws TelegramApiValidationException { 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); throw new TelegramApiValidationException("Commands parameter can't be empty", this);
} }
if (commands.size() > 100) { if (commands.size() > 100) {
@ -77,5 +99,8 @@ public class SetMyCommands extends BotApiMethod<Boolean> {
for (BotCommand command : commands) { for (BotCommand command : commands) {
command.validate(); command.validate();
} }
if (scope != null) {
scope.validate();
}
} }
} }

View File

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

View File

@ -12,7 +12,7 @@ import lombok.Setter;
import lombok.ToString; import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod; import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ApiResponse; 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.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;

View File

@ -12,7 +12,7 @@ import lombok.Setter;
import lombok.ToString; import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod; import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ApiResponse; 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.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;

View File

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

View File

@ -21,6 +21,8 @@ import java.io.IOException;
* @author Ruben Bermudez * @author Ruben Bermudez
* @version 1.0 * @version 1.0
* Use this method to get the number of members in a chat. Returns Int on success. * Use this method to get the number of members in a chat. Returns Int on success.
*
* @deprecated Use {{@link GetChatMemberCount#GetChatMemberCount()}
*/ */
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
@Getter @Getter
@ -29,6 +31,7 @@ import java.io.IOException;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
@Deprecated
public class GetChatMembersCount extends BotApiMethod<Integer> { public class GetChatMembersCount extends BotApiMethod<Integer> {
public static final String PATH = "getChatMembersCount"; public static final String PATH = "getChatMembersCount";

View File

@ -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 * @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 * group. Otherwise members may only be removed by the group's creator or by the member that added
* them. * them.
*
* @deprecated Use {@link BanChatMember#BanChatMember()} instead
*/ */
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
@Getter @Getter
@ -41,6 +43,7 @@ import java.time.ZonedDateTime;
@RequiredArgsConstructor @RequiredArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
@Deprecated
public class KickChatMember extends BotApiMethod<Boolean> { public class KickChatMember extends BotApiMethod<Boolean> {
public static final String PATH = "kickchatmember"; public static final String PATH = "kickchatmember";

View File

@ -199,9 +199,6 @@ public class SendInvoice extends BotApiMethod<Message> {
if (Strings.isNullOrEmpty(providerToken)) { if (Strings.isNullOrEmpty(providerToken)) {
throw new TelegramApiValidationException("ProviderToken parameter can't be empty", this); 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)) { if (Strings.isNullOrEmpty(currency)) {
throw new TelegramApiValidationException("Currency parameter can't be empty", this); throw new TelegramApiValidationException("Currency parameter can't be empty", this);
} }

View File

@ -31,7 +31,7 @@ import java.io.IOException;
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
public class SetStickerSetThumb extends BotApiMethod<Boolean> { 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 NAME_FIELD = "name";
public static final String USERID_FIELD = "user_id"; public static final String USERID_FIELD = "user_id";

View File

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

View File

@ -8,6 +8,7 @@ import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import lombok.ToString; import lombok.ToString;
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
import org.telegram.telegrambots.meta.api.objects.chatmember.ChatMember;
/** /**
* @author Ruben Bermudez * @author Ruben Bermudez

View File

@ -0,0 +1,17 @@
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.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();
}

View File

@ -0,0 +1,125 @@
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 {
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 = "administrator";
/**
* 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;
}

View File

@ -0,0 +1,48 @@
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 {
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 = "kicked";
/**
* 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;
}

View File

@ -0,0 +1,42 @@
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 {
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 = "left";
/**
* Information about the user
*/
@JsonProperty(USER_FIELD)
private User user;
}

View File

@ -0,0 +1,42 @@
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 {
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 = "member";
/**
* Information about the user
*/
@JsonProperty(USER_FIELD)
private User user;
}

View File

@ -0,0 +1,54 @@
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 {
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 = "creator";
/**
* 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;
}

View File

@ -0,0 +1,102 @@
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 {
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 = "restricted";
/**
* 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;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -33,6 +33,7 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
public class ForceReplyKeyboard implements ReplyKeyboard { public class ForceReplyKeyboard implements ReplyKeyboard {
private static final String FORCEREPLY_FIELD = "force_reply"; private static final String FORCEREPLY_FIELD = "force_reply";
private static final String SELECTIVE_FIELD = "selective"; 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 bots message and tapped * Shows reply interface to the user, as if they manually selected the bots message and tapped
@ -40,7 +41,8 @@ public class ForceReplyKeyboard implements ReplyKeyboard {
*/ */
@JsonProperty(FORCEREPLY_FIELD) @JsonProperty(FORCEREPLY_FIELD)
@NonNull @NonNull
private Boolean forceReply; @Builder.Default
private Boolean forceReply = true;
/** /**
* Optional. * Optional.
* *
@ -50,11 +52,20 @@ public class ForceReplyKeyboard implements ReplyKeyboard {
*/ */
@JsonProperty(SELECTIVE_FIELD) @JsonProperty(SELECTIVE_FIELD)
private Boolean selective; 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 @Override
public void validate() throws TelegramApiValidationException { public void validate() throws TelegramApiValidationException {
if (forceReply == null) { if (forceReply == null) {
throw new TelegramApiValidationException("ForceReply parameter can't not be null", this); 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);
}
} }
} }

View File

@ -37,6 +37,7 @@ public class ReplyKeyboardMarkup implements ReplyKeyboard {
private static final String RESIZEKEYBOARD_FIELD = "resize_keyboard"; private static final String RESIZEKEYBOARD_FIELD = "resize_keyboard";
private static final String ONETIMEKEYBOARD_FIELD = "one_time_keyboard"; private static final String ONETIMEKEYBOARD_FIELD = "one_time_keyboard";
private static final String SELECTIVE_FIELD = "selective"; private static final String SELECTIVE_FIELD = "selective";
private static final String INPUTFIELDPLACEHOLDER_FIELD = "input_field_placeholder";
@JsonProperty(KEYBOARD_FIELD) @JsonProperty(KEYBOARD_FIELD)
@NonNull @NonNull
@ -55,12 +56,21 @@ public class ReplyKeyboardMarkup implements ReplyKeyboard {
*/ */
@JsonProperty(SELECTIVE_FIELD) @JsonProperty(SELECTIVE_FIELD)
private Boolean selective; 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 @Override
public void validate() throws TelegramApiValidationException { public void validate() throws TelegramApiValidationException {
if (keyboard == null) { if (keyboard == null) {
throw new TelegramApiValidationException("Keyboard parameter can't be null", this); 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) { for (KeyboardRow keyboardButtons : keyboard) {
keyboardButtons.validate(); keyboardButtons.validate();
} }

View File

@ -4,6 +4,7 @@ import org.telegram.telegrambots.meta.api.interfaces.Validable;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
/** /**
@ -12,6 +13,17 @@ import java.util.List;
* Row for ReplyKeyBoardMarkup * Row for ReplyKeyBoardMarkup
*/ */
public class KeyboardRow extends ArrayList<KeyboardButton> implements Validable { 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) { public boolean add(String text) {
return super.add(new KeyboardButton(text)); return super.add(new KeyboardButton(text));
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -67,14 +67,6 @@ public class SendInvoiceTest {
assertEquals("ProviderToken parameter can't be empty", thrown.getMessage()); 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 @Test
public void currencyCantBeEmpty() { public void currencyCantBeEmpty() {
SendInvoice sendInvoice = createSendInvoiceObject(); SendInvoice sendInvoice = createSendInvoiceObject();

View File

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

View File

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

View File

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

View File

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

View File

@ -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.Audio;
import org.telegram.telegrambots.meta.api.objects.CallbackQuery; import org.telegram.telegrambots.meta.api.objects.CallbackQuery;
import org.telegram.telegrambots.meta.api.objects.Chat; 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.Document;
import org.telegram.telegrambots.meta.api.objects.EntityType; import org.telegram.telegrambots.meta.api.objects.EntityType;
import org.telegram.telegrambots.meta.api.objects.Message; 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.Update;
import org.telegram.telegrambots.meta.api.objects.User; import org.telegram.telegrambots.meta.api.objects.User;
import org.telegram.telegrambots.meta.api.objects.Voice; 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.commands.BotCommand;
import org.telegram.telegrambots.meta.api.objects.inlinequery.ChosenInlineQuery; import org.telegram.telegrambots.meta.api.objects.inlinequery.ChosenInlineQuery;
import org.telegram.telegrambots.meta.api.objects.inlinequery.InlineQuery; import org.telegram.telegrambots.meta.api.objects.inlinequery.InlineQuery;
@ -322,25 +323,27 @@ class TestDeserialization {
" }\n" + " }\n" +
"}"; "}";
ChatMember response = new GetChatMember().deserializeResponse(updateText); ChatMember chatMember = new GetChatMember().deserializeResponse(updateText);
assertNotNull(response); assertNotNull(chatMember);
assertNotNull(response.getUser()); assertTrue(chatMember instanceof ChatMemberRestricted);
assertEquals(1111111, response.getUser().getId()); ChatMemberRestricted chatMemberRestricted = (ChatMemberRestricted) chatMember;
assertTrue(response.getUser().getIsBot()); assertNotNull(chatMemberRestricted.getUser());
assertEquals("MyTesting", response.getUser().getFirstName()); assertEquals(1111111, chatMemberRestricted.getUser().getId());
assertEquals("MyTestingUsername", response.getUser().getUserName()); assertTrue(chatMemberRestricted.getUser().getIsBot());
assertEquals("restricted", response.getStatus()); assertEquals("MyTesting", chatMemberRestricted.getUser().getFirstName());
assertEquals(0, response.getUntilDate()); assertEquals("MyTestingUsername", chatMemberRestricted.getUser().getUserName());
assertFalse(response.getCanSendMessages()); assertEquals("restricted", chatMemberRestricted.getStatus());
assertFalse(response.getCanSendMediaMessages()); assertEquals(0, chatMemberRestricted.getUntilDate());
assertFalse(response.getCanSendPolls()); assertFalse(chatMemberRestricted.getCanSendMessages());
assertFalse(response.getCanSendOtherMessages()); assertFalse(chatMemberRestricted.getCanSendMediaMessages());
assertFalse(response.getCanAddWebPagePreviews()); assertFalse(chatMemberRestricted.getCanSendPolls());
assertFalse(response.getCanChangeInfo()); assertFalse(chatMemberRestricted.getCanSendOtherMessages());
assertFalse(response.getCanInviteUsers()); assertFalse(chatMemberRestricted.getCanAddWebpagePreviews());
assertFalse(response.getCanPinMessages()); assertFalse(chatMemberRestricted.getCanChangeInfo());
assertTrue(response.getIsMember()); assertFalse(chatMemberRestricted.getCanInviteUsers());
assertFalse(chatMemberRestricted.getCanPinMessages());
assertTrue(chatMemberRestricted.getIsMember());
} }
@Test @Test

View File

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

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.telegram</groupId> <groupId>org.telegram</groupId>
<artifactId>Bots</artifactId> <artifactId>Bots</artifactId>
<version>5.2.0</version> <version>5.3.0</version>
</parent> </parent>
<artifactId>telegrambots-spring-boot-starter</artifactId> <artifactId>telegrambots-spring-boot-starter</artifactId>
@ -70,7 +70,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<telegrambots.version>5.2.0</telegrambots.version> <telegrambots.version>5.3.0</telegrambots.version>
<spring-boot.version>2.4.5</spring-boot.version> <spring-boot.version>2.4.5</spring-boot.version>
<maven-gpg-plugin.version>1.6</maven-gpg-plugin.version> <maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>

View File

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

View File

@ -610,7 +610,7 @@ public abstract class DefaultAbsSender extends AbsSender {
assertParamNotNull(setStickerSetThumb, "setStickerSetThumb"); assertParamNotNull(setStickerSetThumb, "setStickerSetThumb");
setStickerSetThumb.validate(); setStickerSetThumb.validate();
try { try {
String url = getBaseUrl() + AddStickerToSet.PATH; String url = getBaseUrl() + SetStickerSetThumb.PATH;
HttpPost httppost = configuredHttpPost(url); HttpPost httppost = configuredHttpPost(url);
MultipartEntityBuilder builder = MultipartEntityBuilder.create(); MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setLaxMode(); builder.setLaxMode();
@ -623,7 +623,7 @@ public abstract class DefaultAbsSender extends AbsSender {
return setStickerSetThumb.deserializeResponse(sendHttpPostRequest(httppost)); return setStickerSetThumb.deserializeResponse(sendHttpPostRequest(httppost));
} catch (IOException e) { } catch (IOException e) {
throw new TelegramApiException("Unable to add sticker to set", e); throw new TelegramApiException("Unable to set sticker set thumb", e);
} }
} }

View File

@ -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.ParseMode;
import org.telegram.telegrambots.meta.api.methods.games.GetGameHighScores; 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.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.GetChat;
import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatAdministrators; 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.GetChatMember;
import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatMembersCount; import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatMemberCount;
import org.telegram.telegrambots.meta.api.methods.groupadministration.KickChatMember;
import org.telegram.telegrambots.meta.api.methods.groupadministration.LeaveChat; 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.groupadministration.UnbanChatMember;
import org.telegram.telegrambots.meta.api.methods.send.SendChatAction; 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.EditMessageReplyMarkup;
import org.telegram.telegrambots.meta.api.methods.updatingmessages.EditMessageText; import org.telegram.telegrambots.meta.api.methods.updatingmessages.EditMessageText;
import org.telegram.telegrambots.meta.api.objects.Chat; 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.File;
import org.telegram.telegrambots.meta.api.objects.Message; import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.User; import org.telegram.telegrambots.meta.api.objects.User;
import org.telegram.telegrambots.meta.api.objects.UserProfilePhotos; import org.telegram.telegrambots.meta.api.objects.UserProfilePhotos;
import org.telegram.telegrambots.meta.api.objects.WebhookInfo; 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.games.GameHighScore;
import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent; import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent;
import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputTextMessageContent; import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputTextMessageContent;
@ -159,8 +159,8 @@ public final class BotApiMethodHelperFactory {
.build(); .build();
} }
public static BotApiMethod<Integer> getChatMembersCount() { public static BotApiMethod<Integer> getChatMemberCount() {
return GetChatMembersCount return GetChatMemberCount
.builder() .builder()
.chatId("12345") .chatId("12345")
.build(); .build();
@ -199,8 +199,8 @@ public final class BotApiMethodHelperFactory {
return new GetWebhookInfo(); return new GetWebhookInfo();
} }
public static BotApiMethod<Boolean> getKickChatMember() { public static BotApiMethod<Boolean> getBanChatMember() {
return KickChatMember return BanChatMember
.builder() .builder()
.chatId("12345") .chatId("12345")
.userId(98765L) .userId(98765L)

View File

@ -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.GetUserProfilePhotos;
import org.telegram.telegrambots.meta.api.methods.games.GetGameHighScores; 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.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.GetChat;
import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatAdministrators; 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.GetChatMember;
import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatMembersCount; import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatMemberCount;
import org.telegram.telegrambots.meta.api.methods.groupadministration.KickChatMember;
import org.telegram.telegrambots.meta.api.methods.groupadministration.LeaveChat; 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.groupadministration.UnbanChatMember;
import org.telegram.telegrambots.meta.api.methods.send.SendChatAction; 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.EditMessageReplyMarkup;
import org.telegram.telegrambots.meta.api.methods.updatingmessages.EditMessageText; import org.telegram.telegrambots.meta.api.methods.updatingmessages.EditMessageText;
import org.telegram.telegrambots.meta.api.objects.Chat; 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.File;
import org.telegram.telegrambots.meta.api.objects.Message; import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.Update; import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.api.objects.User; import org.telegram.telegrambots.meta.api.objects.User;
import org.telegram.telegrambots.meta.api.objects.UserProfilePhotos; import org.telegram.telegrambots.meta.api.objects.UserProfilePhotos;
import org.telegram.telegrambots.meta.api.objects.WebhookInfo; 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.games.GameHighScore;
import org.telegram.telegrambots.test.Fakes.FakeWebhook; import org.telegram.telegrambots.test.Fakes.FakeWebhook;
import org.telegram.telegrambots.updatesreceivers.RestApi; import org.telegram.telegrambots.updatesreceivers.RestApi;
@ -219,13 +219,13 @@ public class TestRestApi extends JerseyTest {
@Test @Test
public void TestGetChatMembersCount() { public void TestGetChatMembersCount() {
webhookBot.setReturnValue(BotApiMethodHelperFactory.getChatMembersCount()); webhookBot.setReturnValue(BotApiMethodHelperFactory.getChatMemberCount());
Entity<Update> entity = Entity.json(getUpdate()); Entity<Update> entity = Entity.json(getUpdate());
BotApiMethod<Integer> result = BotApiMethod<Integer> result =
target("callback/testbot") target("callback/testbot")
.request(MediaType.APPLICATION_JSON) .request(MediaType.APPLICATION_JSON)
.post(entity, GetChatMembersCount.class); .post(entity, GetChatMemberCount.class);
assertEquals("{\"chat_id\":\"12345\",\"method\":\"getChatMembersCount\"}", map(result)); assertEquals("{\"chat_id\":\"12345\",\"method\":\"getChatMembersCount\"}", map(result));
} }
@ -297,13 +297,13 @@ public class TestRestApi extends JerseyTest {
@Test @Test
public void TestKickChatMember() { public void TestKickChatMember() {
webhookBot.setReturnValue(BotApiMethodHelperFactory.getKickChatMember()); webhookBot.setReturnValue(BotApiMethodHelperFactory.getBanChatMember());
Entity<Update> entity = Entity.json(getUpdate()); Entity<Update> entity = Entity.json(getUpdate());
BotApiMethod<Boolean> result = BotApiMethod<Boolean> result =
target("callback/testbot") target("callback/testbot")
.request(MediaType.APPLICATION_JSON) .request(MediaType.APPLICATION_JSON)
.post(entity, KickChatMember.class); .post(entity, BanChatMember.class);
assertEquals("{\"chat_id\":\"12345\",\"user_id\":98765,\"method\":\"kickchatmember\"}", map(result)); assertEquals("{\"chat_id\":\"12345\",\"user_id\":98765,\"method\":\"kickchatmember\"}", map(result));
} }