Merge pull request #831 from rubenlagus/dev

Dev
This commit is contained in:
Ruben Bermudez 2020-11-08 18:00:40 +00:00 committed by GitHub
commit b03fe98798
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 149 additions and 103 deletions

View File

@ -27,16 +27,16 @@ 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.0.0</version> <version>5.0.1</version>
</dependency> </dependency>
``` ```
```gradle ```gradle
compile "org.telegram:telegrambots:5.0.0" compile "org.telegram:telegrambots:5.0.1"
``` ```
2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/5.0.0) 2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/5.0.1)
3. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/5.0.0) 3. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/5.0.1)
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`.
@ -50,8 +50,8 @@ Once done, you just need to create a `org.telegram.telegrambots.meta.TelegramBot
// Example taken from https://github.com/rubenlagus/TelegramBotsExample // Example taken from https://github.com/rubenlagus/TelegramBotsExample
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
TelegramBotsApi telegramBotsApi = new TelegramBotsApi(DefaultBotSession.class);
try { try {
TelegramBotsApi telegramBotsApi = new TelegramBotsApi(DefaultBotSession.class);
telegramBotsApi.registerBot(new ChannelHandlers()); telegramBotsApi.registerBot(new ChannelHandlers());
telegramBotsApi.registerBot(new DirectionsHandlers()); telegramBotsApi.registerBot(new DirectionsHandlers());
telegramBotsApi.registerBot(new RaeHandlers()); telegramBotsApi.registerBot(new RaeHandlers());

View File

@ -1,5 +1,11 @@
### <a id="5.0.1"></a>5.0.1 ###
1. Fixing couple of bugs from 5.0.0
2. Buf fixing: #794
3. Docs updated to reflect usage for version 5.0.0
4. EditMessageText setChatIId(Long) is removed to keep consistency
### <a id="5.0.0"></a>5.0.0 ### ### <a id="5.0.0"></a>5.0.0 ###
1. Update Api version [5.0](https://core.telegram.org/bots/api-changelog#june-4-2020) 1. Update Api version [5.0](https://core.telegram.org/bots/api-changelog#november-4-2020)
2. Added Builders for many of the API methods and objects (hopefully all of them unless I missed something) 2. Added Builders for many of the API methods and objects (hopefully all of them unless I missed something)
3. Some setters/getters may have change name. They no longer return a reference to itself, use Builder for that. 3. Some setters/getters may have change name. They no longer return a reference to itself, use Builder for that.
4. Simplified methods to set files in methods. Only InputFile is available now (this class contains constructors for all the cases) 4. Simplified methods to set files in methods. Only InputFile is available now (this class contains constructors for all the cases)

View File

@ -79,29 +79,29 @@ Quick example here that is showing ChactActions for commands like "/type" or "/r
```java ```java
if (update.hasMessage() && update.getMessage().hasText()) { if (update.hasMessage() && update.getMessage().hasText()) {
String text = update.getMessage().getText(); String text = update.getMessage().getText();
SendChatAction sendChatAction = new SendChatAction(); SendChatAction sendChatAction = new SendChatAction();
sendChatAction.setChatId(update.getMessage().getChatId()); sendChatAction.setChatId(update.getMessage().getChatId());
if (text.equals("/type")) { if (text.equals("/type")) {
// -> "typing" // -> "typing"
sendChatAction.setAction(ActionType.TYPING); sendChatAction.setAction(ActionType.TYPING);
// -> "recording a voice message" // -> "recording a voice message"
} else if (text.equals("/record_audio")) { } else if (text.equals("/record_audio")) {
sendChatAction.setAction(ActionType.RECORDAUDIO); sendChatAction.setAction(ActionType.RECORDAUDIO);
} else { } else {
// -> more actions in the Enum ActionType // -> more actions in the Enum ActionType
// For information: https://core.telegram.org/bots/api#sendchataction // For information: https://core.telegram.org/bots/api#sendchataction
sendChatAction.setAction(ActionType.UPLOADDOCUMENT); sendChatAction.setAction(ActionType.UPLOADDOCUMENT);
} }
try { try {
Boolean wasSuccessfull = execute(sendChatAction); Boolean wasSuccessfull = execute(sendChatAction);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
} }
``` ```
@ -116,7 +116,7 @@ There are several method to send a photo to an user using `sendPhoto` method: Wi
// Set destination chat id // Set destination chat id
sendPhotoRequest.setChatId(chatId); sendPhotoRequest.setChatId(chatId);
// Set the photo url as a simple photo // Set the photo url as a simple photo
sendPhotoRequest.setPhoto(url); sendPhotoRequest.setPhoto(new InputFile(url));
try { try {
// Execute the method // Execute the method
execute(sendPhotoRequest); execute(sendPhotoRequest);
@ -131,7 +131,7 @@ There are several method to send a photo to an user using `sendPhoto` method: Wi
// Set destination chat id // Set destination chat id
sendPhotoRequest.setChatId(chatId); sendPhotoRequest.setChatId(chatId);
// Set the photo url as a simple photo // Set the photo url as a simple photo
sendPhotoRequest.setPhoto(fileId); sendPhotoRequest.setPhoto(new InputFile(fileId));
try { try {
// Execute the method // Execute the method
execute(sendPhotoRequest); execute(sendPhotoRequest);
@ -145,8 +145,8 @@ There are several method to send a photo to an user using `sendPhoto` method: Wi
SendPhoto sendPhotoRequest = new SendPhoto(); SendPhoto sendPhotoRequest = new SendPhoto();
// Set destination chat id // Set destination chat id
sendPhotoRequest.setChatId(chatId); sendPhotoRequest.setChatId(chatId);
// Set the photo file as a new photo (You can also use InputStream with a method overload) // Set the photo file as a new photo (You can also use InputStream with a constructor overload)
sendPhotoRequest.setNewPhoto(new File(filePath)); sendPhotoRequest.setPhoto(new InputFile(new File(filePath)));
try { try {
// Execute the method // Execute the method
execute(sendPhotoRequest); execute(sendPhotoRequest);
@ -162,24 +162,23 @@ In this example we will check if user sends to bot a photo, if it is, get Photo'
```java ```java
// If it is a photo // If it is a photo
if (update.hasMessage() && update.getMessage().hasPhoto()) { if (update.hasMessage() && update.getMessage().hasPhoto()) {
// Array with photos // Array with photos
List<PhotoSize> photos = update.getMessage().getPhoto(); List<PhotoSize> photos = update.getMessage().getPhoto();
// Get largest photo's file_id // Get largest photo's file_id
String f_id = photos.stream() String f_id = photos.stream()
.sorted(Comparator.comparing(PhotoSize::getFileSize).reversed()) .max(Comparator.comparing(PhotoSize::getFileSize))
.findFirst() .orElseThrow().getFileId();
.orElse(null).getFileId(); // Send photo by file_id we got before
// Send photo by file_id we got before SendPhoto msg = new SendPhoto()
SendPhoto msg = new SendPhoto() .setChatId(update.getMessage().getChatId())
.setChatId(update.getMessage().getChatId()) .setPhoto(new InputFile(f_id))
.setPhoto(f_id) .setCaption("Photo");
.setCaption("Photo"); try {
try { execute(msg); // Call method to send the photo
execute(msg); // Call method to send the photo } catch (TelegramApiException e) {
} catch (TelegramApiException e) { e.printStackTrace();
e.printStackTrace(); }
} }
}
``` ```
## <a id="how_to_use_custom_keyboards"></a>How to use custom keyboards? ## ## <a id="how_to_use_custom_keyboards"></a>How to use custom keyboards? ##
@ -264,9 +263,9 @@ Your main spring boot class should look like this:
@SpringBootApplication @SpringBootApplication
public class YourApplicationMainClass { public class YourApplicationMainClass {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(YourApplicationMainClass.class, args); SpringApplication.run(YourApplicationMainClass.class, args);
} }
} }
``` ```

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.0.0</version> <version>5.0.1</version>
</dependency> </dependency>
``` ```
* With **Gradle**: * With **Gradle**:
```groovy ```groovy
compile group: 'org.telegram', name: 'telegrambots', version: '5.0.0' compile group: 'org.telegram', name: 'telegrambots', version: '5.0.1'
``` ```
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).
@ -135,9 +135,8 @@ Now that we have the library, we can start coding. There are few steps to follow
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
TelegramBotsApi botsApi = new TelegramBotsApi();
try { try {
TelegramBotsApi botsApi = new TelegramBotsApi(DefaultBotSession.class);
botsApi.registerBot(new MyAmazingBot()); botsApi.registerBot(new MyAmazingBot());
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -94,7 +94,7 @@ public class Main {
}); });
// Create the TelegramBotsApi object to register your bots // Create the TelegramBotsApi object to register your bots
TelegramBotsApi botsApi = new TelegramBotsApi(); TelegramBotsApi botsApi = new TelegramBotsApi(DefaultBotSession.class);
// Set up Http proxy // Set up Http proxy
DefaultBotOptions botOptions = new DefaultBotOptions(); DefaultBotOptions botOptions = new DefaultBotOptions();

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.0.0</version> <version>5.0.1</version>
</dependency> </dependency>
``` ```
* **Gradle** * **Gradle**
```groovy ```groovy
implementation group: 'org.telegram', name: 'telegrambots-abilities', version: '5.0.0' implementation group: 'org.telegram', name: 'telegrambots-abilities', version: '5.0.1'
``` ```
* [JitPack](https://jitpack.io/#rubenlagus/TelegramBots) * [JitPack](https://jitpack.io/#rubenlagus/TelegramBots)
@ -81,10 +81,10 @@ Running the bot is just like running the regular Telegram bots. Create a Java cl
```java ```java
public class Application { public class Application {
public static void main(String[] args) { public static void main(String[] args) {
// Create the TelegramBotsApi object to register your bots
TelegramBotsApi botsApi = new TelegramBotsApi(DefaultBotSession.class);
try { try {
// Create the TelegramBotsApi object to register your bots
TelegramBotsApi botsApi = new TelegramBotsApi(DefaultBotSession.class);
// Register your newly created AbilityBot // Register your newly created AbilityBot
botsApi.registerBot(new HelloBot()); botsApi.registerBot(new HelloBot());
} catch (TelegramApiException e) { } catch (TelegramApiException e) {

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.0.0</version> <version>5.0.1</version>
<modules> <modules>
<module>telegrambots</module> <module>telegrambots</module>

View File

@ -18,19 +18,19 @@ Usage
<dependency> <dependency>
<groupId>org.telegram</groupId> <groupId>org.telegram</groupId>
<artifactId>telegrambots-abilities</artifactId> <artifactId>telegrambots-abilities</artifactId>
<version>5.0.0</version> <version>5.0.1</version>
</dependency> </dependency>
``` ```
**Gradle** **Gradle**
```gradle ```gradle
compile "org.telegram:telegrambots-abilities:5.0.0" compile "org.telegram:telegrambots-abilities:5.0.1"
``` ```
**JitPack** - [JitPack](https://jitpack.io/#rubenlagus/TelegramBots/v5.0.0) **JitPack** - [JitPack](https://jitpack.io/#rubenlagus/TelegramBots/v5.0.1)
**Plain imports** - [Here](https://github.com/rubenlagus/TelegramBots/releases/tag/v5.0.0) **Plain imports** - [Here](https://github.com/rubenlagus/TelegramBots/releases/tag/v5.0.1)
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.0.0</version> <version>5.0.1</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.0.0</version> <version>5.0.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>

View File

@ -15,7 +15,7 @@ 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.0.0</version> <version>5.0.1</version>
</dependency> </dependency>
``` ```

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.telegram</groupId> <groupId>org.telegram</groupId>
<artifactId>Bots</artifactId> <artifactId>Bots</artifactId>
<version>5.0.0</version> <version>5.0.1</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.0.0</version> <version>5.0.1</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.0.0</version> <version>5.0.1</version>
</dependency> </dependency>
``` ```
2. Using Gradle: 2. Using Gradle:
```gradle ```gradle
compile "org.telegram:telegrambotsextensions:5.0.0" compile "org.telegram:telegrambotsextensions:5.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.0.0</version> <version>5.0.1</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.0.0</version> <version>5.0.1</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.0.0</version> <version>5.0.1</version>
</parent> </parent>
<artifactId>telegrambots-meta</artifactId> <artifactId>telegrambots-meta</artifactId>

View File

@ -1,10 +1,10 @@
package org.telegram.telegrambots.meta.api.methods.commands; package org.telegram.telegrambots.meta.api.methods.commands;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
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;
@ -27,7 +27,7 @@ import java.util.ArrayList;
@Getter @Getter
@Setter @Setter
@ToString @ToString
@NoArgsConstructor @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";

View File

@ -1,15 +1,14 @@
package org.telegram.telegrambots.meta.api.methods.updates; package org.telegram.telegrambots.meta.api.methods.updates;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
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.WebhookInfo;
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;
@ -28,9 +27,9 @@ import java.io.IOException;
@Getter @Getter
@Setter @Setter
@ToString @ToString
@NoArgsConstructor @AllArgsConstructor
@Builder @Builder
public class Close extends BotApiMethod<WebhookInfo> { public class Close extends BotApiMethod<Boolean> {
public static final String PATH = "close"; public static final String PATH = "close";
@Override @Override
@ -39,15 +38,15 @@ public class Close extends BotApiMethod<WebhookInfo> {
} }
@Override @Override
public WebhookInfo deserializeResponse(String answer) throws TelegramApiRequestException { public Boolean deserializeResponse(String answer) throws TelegramApiRequestException {
try { try {
ApiResponse<WebhookInfo> result = OBJECT_MAPPER.readValue(answer, ApiResponse<Boolean> result = OBJECT_MAPPER.readValue(answer,
new TypeReference<ApiResponse<WebhookInfo>>() { new TypeReference<ApiResponse<Boolean>>() {
}); });
if (result.getOk()) { if (result.getOk()) {
return result.getResult(); return result.getResult();
} else { } else {
throw new TelegramApiRequestException("Error logging out info", result); throw new TelegramApiRequestException("Error closing", result);
} }
} catch (IOException e2) { } catch (IOException e2) {
throw new TelegramApiRequestException("Unable to deserialize response", e2); throw new TelegramApiRequestException("Unable to deserialize response", e2);

View File

@ -9,7 +9,6 @@ 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.WebhookInfo;
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;
@ -30,7 +29,7 @@ import java.io.IOException;
@ToString @ToString
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
public class LogOut extends BotApiMethod<WebhookInfo> { public class LogOut extends BotApiMethod<Boolean> {
public static final String PATH = "logOut"; public static final String PATH = "logOut";
@Override @Override
@ -39,15 +38,15 @@ public class LogOut extends BotApiMethod<WebhookInfo> {
} }
@Override @Override
public WebhookInfo deserializeResponse(String answer) throws TelegramApiRequestException { public Boolean deserializeResponse(String answer) throws TelegramApiRequestException {
try { try {
ApiResponse<WebhookInfo> result = OBJECT_MAPPER.readValue(answer, ApiResponse<Boolean> result = OBJECT_MAPPER.readValue(answer,
new TypeReference<ApiResponse<WebhookInfo>>() { new TypeReference<ApiResponse<Boolean>>() {
}); });
if (result.getOk()) { if (result.getOk()) {
return result.getResult(); return result.getResult();
} else { } else {
throw new TelegramApiRequestException("Error logging out info", result); throw new TelegramApiRequestException("Error logging out", result);
} }
} catch (IOException e2) { } catch (IOException e2) {
throw new TelegramApiRequestException("Unable to deserialize response", e2); throw new TelegramApiRequestException("Unable to deserialize response", e2);

View File

@ -86,10 +86,6 @@ public class EditMessageText extends BotApiMethod<Serializable> {
@JsonProperty(ENTITIES_FIELD) @JsonProperty(ENTITIES_FIELD)
private List<MessageEntity> entities; ///< Optional. List of special entities that appear in message text, which can be specified instead of parse_mode private List<MessageEntity> entities; ///< Optional. List of special entities that appear in message text, which can be specified instead of parse_mode
public void setChatId(Long chatId) {
this.chatId = chatId.toString();
}
public void disableWebPagePreview() { public void disableWebPagePreview() {
disableWebPagePreview = true; disableWebPagePreview = true;
} }

View File

@ -37,7 +37,7 @@ public class ChatPermissions implements BotApiObject {
@JsonProperty(CAN_SEND_MESSAGES_FIELD) @JsonProperty(CAN_SEND_MESSAGES_FIELD)
private Boolean canSendMessages; ///< Optional. True, if the user is allowed to send text messages, contacts, locations and venues private Boolean canSendMessages; ///< Optional. True, if the user is allowed to send text messages, contacts, locations and venues
@JsonProperty(CAN_SEND_MEDIA_MESSAGES_FIELD) @JsonProperty(CAN_SEND_MEDIA_MESSAGES_FIELD)
private Boolean getCanSendMediaMessages; ///< Optional. True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes, implies can_send_messages private Boolean canSendMediaMessages; ///< Optional. True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes, implies can_send_messages
@JsonProperty(CAN_SEND_POLLS_FIELD) @JsonProperty(CAN_SEND_POLLS_FIELD)
private Boolean canSendPolls; ///< Optional. True, if the user is allowed to send polls, implies can_send_messages private Boolean canSendPolls; ///< Optional. True, if the user is allowed to send polls, implies can_send_messages
@JsonProperty(CAN_SEND_OTHER_MESSAGES_FIELD) @JsonProperty(CAN_SEND_OTHER_MESSAGES_FIELD)

View File

@ -5,7 +5,10 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.telegram.telegrambots.meta.api.methods.commands.GetMyCommands;
import org.telegram.telegrambots.meta.api.methods.updates.Close;
import org.telegram.telegrambots.meta.api.methods.updates.GetUpdates; import org.telegram.telegrambots.meta.api.methods.updates.GetUpdates;
import org.telegram.telegrambots.meta.api.methods.updates.LogOut;
import org.telegram.telegrambots.meta.api.objects.ApiResponse; 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;
@ -17,6 +20,7 @@ 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.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;
@ -151,6 +155,50 @@ class TestDeserialization {
} }
} }
@Test
void TestDeserializationCloseMethod() throws Exception {
String updateText = "{\"ok\":true,\"result\": true}";
Boolean response = new Close().deserializeResponse(updateText);
assertTrue(response);
}
@Test
void TestDeserializationLogoutMethod() throws Exception {
String updateText = "{\"ok\":true,\"result\": true}";
Boolean response = new LogOut().deserializeResponse(updateText);
assertTrue(response);
}
@Test
void TestDeserializationGetMyCommandsMethod() throws Exception {
String updateText = "{\n" +
" \"ok\": true,\n" +
" \"result\": [\n" +
" {\n" +
" \"command\": \"enabled\",\n" +
" \"description\": \"Enabled Command\"\n" +
" },\n" +
" {\n" +
" \"command\": \"disabled\",\n" +
" \"description\": \"Disabled Command\"\n" +
" }\n" +
" ]\n" +
"}";
ArrayList<BotCommand> response = new GetMyCommands().deserializeResponse(updateText);
assertNotNull(response);
assertEquals(2, response.size());
assertEquals("enabled", response.get(0).getCommand());
assertEquals("Enabled Command", response.get(0).getDescription());
assertEquals("disabled", response.get(1).getCommand());
assertEquals("Disabled Command", response.get(1).getDescription());
}
@Test @Test
void TestUpdateDeserialization() throws Exception { void TestUpdateDeserialization() throws Exception {
Update update = mapper.readValue(TelegramBotsHelper.GetUpdate(), Update.class); Update update = mapper.readValue(TelegramBotsHelper.GetUpdate(), Update.class);

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.0.0</version> <version>5.0.1</version>
</dependency> </dependency>
``` ```
**Gradle** **Gradle**
```gradle ```gradle
compile "org.telegram:telegrambots-spring-boot-starter:5.0.0" compile "org.telegram:telegrambots-spring-boot-starter:5.0.1"
``` ```
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.0.0</version> <version>5.0.1</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.0.0</telegrambots.version> <telegrambots.version>5.0.1</telegrambots.version>
<spring-boot.version>2.3.5.RELEASE</spring-boot.version> <spring-boot.version>2.3.5.RELEASE</spring-boot.version>
<assertj-core.version>3.18.0</assertj-core.version> <assertj-core.version>3.18.0</assertj-core.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.0.0</version> <version>5.0.1</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.0.0</version> <version>5.0.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>