From 1728a23b0011e4e8fe2a0e6437969018beb21104 Mon Sep 17 00:00:00 2001 From: Davy Van Roy Date: Thu, 30 Aug 2018 14:31:26 +0200 Subject: [PATCH 01/37] typo --- telegrambots-spring-boot-starter/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/telegrambots-spring-boot-starter/README.md b/telegrambots-spring-boot-starter/README.md index a20ed49e..1d3ff441 100644 --- a/telegrambots-spring-boot-starter/README.md +++ b/telegrambots-spring-boot-starter/README.md @@ -52,10 +52,10 @@ public class YourApplicationMainClass { After that your bot will look like: ```java - //Standart Spring component annotation + //Standard Spring component annotation @Component public class YourBotName extends TelegramLongPollingBot { //Bot body. } ``` -Also you could just implement LongPollingBot or WebHookBot interfaces. All this bots will be registered in context and connected to Telegram api. \ No newline at end of file +Also you could just implement LongPollingBot or WebHookBot interfaces. All this bots will be registered in context and connected to Telegram api. From 584b9d5f9882902652309ae7dc0a82381a9fc80b Mon Sep 17 00:00:00 2001 From: ezachateyskiy Date: Sat, 15 Sep 2018 02:07:17 +0300 Subject: [PATCH 02/37] Fix wrong path for SendAnimation command --- .../java/org/telegram/telegrambots/bots/DefaultAbsSender.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java b/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java index 2a4e2d80..e7cbcec0 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java @@ -641,7 +641,7 @@ public abstract class DefaultAbsSender extends AbsSender { assertParamNotNull(sendAnimation, "sendAnimation"); sendAnimation.validate(); try { - String url = getBaseUrl() + SendVoice.PATH; + String url = getBaseUrl() + SendAnimation.PATH; HttpPost httppost = configuredHttpPost(url); MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.setLaxMode(); From ce82e627a6cbd01f1d5f4c8a668acab0098aa7fe Mon Sep 17 00:00:00 2001 From: chase Date: Fri, 28 Sep 2018 22:09:48 +0200 Subject: [PATCH 03/37] Created page on how to handle bot tokens --- TelegramBots.wiki/Handling-Bot-Tokens.md | 88 ++++++++++++++++++++++++ TelegramBots.wiki/_Sidebar.md | 1 + 2 files changed, 89 insertions(+) create mode 100644 TelegramBots.wiki/Handling-Bot-Tokens.md diff --git a/TelegramBots.wiki/Handling-Bot-Tokens.md b/TelegramBots.wiki/Handling-Bot-Tokens.md new file mode 100644 index 00000000..0904136d --- /dev/null +++ b/TelegramBots.wiki/Handling-Bot-Tokens.md @@ -0,0 +1,88 @@ +* [Bot Token Dont's](#bot-token-donts) +* [Using Enviroment Variables](#using-environment-variables) + * [Setting Enviroment Variables](#setting-environment-variables) + * [Accessing Enviroment Variables](#accessing-enviroment-variables) +* [Using Command Line Arguments](#using-command-line-arguments) + +## Bot Token Dont's ## +* Tokens should not be hardcoded into the bot code +* Tokens should never be published +* Tokens should not be pushed into Repositorys + +## Using Environment Variables ### +One convenient way to inject your bot token into the application is by using Environment Variables. Environment Variables are Values that are set in the Environment the Bot is running. + +Those Values are not defined in the Application and therefore are not visible in the code. + +### Setting Environment Variables ### + +####Windows +Enviroment Variables in Windows can be set using the Console (CMD) using +```batchfile +SETX [VARIABLE_NAME] [YOUR_BOT_TOKEN] +``` + +It can also be set using the Windows GUI +* From the desktop, right click the Computer icon. +* Choose Properties from the context menu. +* Click the Advanced system settings link. +* Click Environment Variables... +* In the 'User Variables for X' click New and enter a Name and your Token as the Value + +####Linux & Mac +* Open the '~/.bash_profile' File +* Append the following to it: +```bash +export VARIABLE_NAME = {YOUR_BOT_TOKEN} +``` +* Save the file +* Either reboot your system or run the command above in your terminal + +####IntelliJ +* Go to Run->Edit Configuratuions... +* Navigate to your Java Run Configuration +* Under Enviroment->Enviroment Variables click the Folder Icon +* Click the Plus Icon to add a new Variable +* Enter a Name and your Token as the Value + +####Heroku Cloud +* Naviage to your App +* In the Settings Tab under Config Vars, click "Reveal Config Vars" +* Enter a Name and your Token as the Value +* Click the "Add" button + +### Accessing Enviroment Variables ### + +####Java +You can access the Enviroment Variables by using System.getEnv() + +```java +String BOT_TOKEN = System.getenv("VARIABLE_NAME"); +``` + +####Spring + +In Spring the @Value annotation allows you to inject the Value into your class +```java +public class Bot extends TelegramLongPollingBot { + public Bot(@Value("${VARIABLE_NAME") String botToken) { + this.botToken = botToken; + } +} +``` + +## Using Command Line Arguments +An easier but not Recommended way of injecting the Bottoken is by utilizing Command Line Arguments when starting the Application + +In this case your main Method is responsible for taking in the Token + +```java +public static void main(String[] args) { + String botToken = args[0]; +} +``` + +You now have to call your jar by using +``` +java -jar myBot.jar [BOT_TOKEN] +``` \ No newline at end of file diff --git a/TelegramBots.wiki/_Sidebar.md b/TelegramBots.wiki/_Sidebar.md index 0bc64b51..c4a738ad 100644 --- a/TelegramBots.wiki/_Sidebar.md +++ b/TelegramBots.wiki/_Sidebar.md @@ -3,6 +3,7 @@ * [[Errors Handling]] * [[Using HTTP Proxy]] * [[FAQ]] + * [[Handling Bot Tokens]] * AbilityBot * [[Simple Example]] * [[Hello Ability]] From 8aa77f54eb4eb84d8fb5bf53df822cf454e6179e Mon Sep 17 00:00:00 2001 From: chase Date: Fri, 28 Sep 2018 22:11:33 +0200 Subject: [PATCH 04/37] Fix headers in Handling Bot Tokens page --- TelegramBots.wiki/Handling-Bot-Tokens.md | 22 +++++++++---------- .../api/bot/AbilityWebhookBot.java | 3 +++ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/TelegramBots.wiki/Handling-Bot-Tokens.md b/TelegramBots.wiki/Handling-Bot-Tokens.md index 0904136d..1366cf30 100644 --- a/TelegramBots.wiki/Handling-Bot-Tokens.md +++ b/TelegramBots.wiki/Handling-Bot-Tokens.md @@ -4,19 +4,19 @@ * [Accessing Enviroment Variables](#accessing-enviroment-variables) * [Using Command Line Arguments](#using-command-line-arguments) -## Bot Token Dont's ## +# Bot Token Dont's ## * Tokens should not be hardcoded into the bot code * Tokens should never be published * Tokens should not be pushed into Repositorys -## Using Environment Variables ### +# Using Environment Variables ### One convenient way to inject your bot token into the application is by using Environment Variables. Environment Variables are Values that are set in the Environment the Bot is running. Those Values are not defined in the Application and therefore are not visible in the code. -### Setting Environment Variables ### +## Setting Environment Variables ### -####Windows +###Windows Enviroment Variables in Windows can be set using the Console (CMD) using ```batchfile SETX [VARIABLE_NAME] [YOUR_BOT_TOKEN] @@ -29,7 +29,7 @@ It can also be set using the Windows GUI * Click Environment Variables... * In the 'User Variables for X' click New and enter a Name and your Token as the Value -####Linux & Mac +###Linux & Mac * Open the '~/.bash_profile' File * Append the following to it: ```bash @@ -38,29 +38,29 @@ export VARIABLE_NAME = {YOUR_BOT_TOKEN} * Save the file * Either reboot your system or run the command above in your terminal -####IntelliJ +###IntelliJ * Go to Run->Edit Configuratuions... * Navigate to your Java Run Configuration * Under Enviroment->Enviroment Variables click the Folder Icon * Click the Plus Icon to add a new Variable * Enter a Name and your Token as the Value -####Heroku Cloud +###Heroku Cloud * Naviage to your App * In the Settings Tab under Config Vars, click "Reveal Config Vars" * Enter a Name and your Token as the Value * Click the "Add" button -### Accessing Enviroment Variables ### +## Accessing Enviroment Variables ### -####Java +###Java You can access the Enviroment Variables by using System.getEnv() ```java String BOT_TOKEN = System.getenv("VARIABLE_NAME"); ``` -####Spring +###Spring In Spring the @Value annotation allows you to inject the Value into your class ```java @@ -71,7 +71,7 @@ public class Bot extends TelegramLongPollingBot { } ``` -## Using Command Line Arguments +# Using Command Line Arguments An easier but not Recommended way of injecting the Bottoken is by utilizing Command Line Arguments when starting the Application In this case your main Method is responsible for taking in the Token diff --git a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/AbilityWebhookBot.java b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/AbilityWebhookBot.java index 04887d7c..ffa62de5 100644 --- a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/AbilityWebhookBot.java +++ b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/AbilityWebhookBot.java @@ -1,5 +1,6 @@ package org.telegram.abilitybots.api.bot; +import org.apache.http.impl.client.SystemDefaultCredentialsProvider; import org.telegram.abilitybots.api.db.DBContext; import org.telegram.telegrambots.meta.api.methods.BotApiMethod; import org.telegram.telegrambots.meta.api.objects.Update; @@ -28,6 +29,8 @@ public abstract class AbilityWebhookBot extends BaseAbilityBot implements Webhoo protected AbilityWebhookBot(String botToken, String botUsername, String botPath, DBContext db) { this(botToken, botUsername, botPath, db, new DefaultBotOptions()); + + } protected AbilityWebhookBot(String botToken, String botUsername, String botPath, DefaultBotOptions botOptions) { From d7c5d28d4537bd40ffc3da0fe18f2a25c29bf514 Mon Sep 17 00:00:00 2001 From: chase Date: Fri, 28 Sep 2018 22:14:00 +0200 Subject: [PATCH 05/37] Fix headers in Handling Bot Tokens page again --- TelegramBots.wiki/Handling-Bot-Tokens.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/TelegramBots.wiki/Handling-Bot-Tokens.md b/TelegramBots.wiki/Handling-Bot-Tokens.md index 1366cf30..305f9d59 100644 --- a/TelegramBots.wiki/Handling-Bot-Tokens.md +++ b/TelegramBots.wiki/Handling-Bot-Tokens.md @@ -16,7 +16,7 @@ Those Values are not defined in the Application and therefore are not visible in ## Setting Environment Variables ### -###Windows +### Windows Enviroment Variables in Windows can be set using the Console (CMD) using ```batchfile SETX [VARIABLE_NAME] [YOUR_BOT_TOKEN] @@ -29,7 +29,7 @@ It can also be set using the Windows GUI * Click Environment Variables... * In the 'User Variables for X' click New and enter a Name and your Token as the Value -###Linux & Mac +### Linux & Mac * Open the '~/.bash_profile' File * Append the following to it: ```bash @@ -38,7 +38,7 @@ export VARIABLE_NAME = {YOUR_BOT_TOKEN} * Save the file * Either reboot your system or run the command above in your terminal -###IntelliJ +### IntelliJ * Go to Run->Edit Configuratuions... * Navigate to your Java Run Configuration * Under Enviroment->Enviroment Variables click the Folder Icon @@ -51,16 +51,16 @@ export VARIABLE_NAME = {YOUR_BOT_TOKEN} * Enter a Name and your Token as the Value * Click the "Add" button -## Accessing Enviroment Variables ### +## Accessing Enviroment Variables ## -###Java +### Java You can access the Enviroment Variables by using System.getEnv() ```java String BOT_TOKEN = System.getenv("VARIABLE_NAME"); ``` -###Spring +### Spring In Spring the @Value annotation allows you to inject the Value into your class ```java From 77a3c635b5ae21778181862daa12b0e45b50d966 Mon Sep 17 00:00:00 2001 From: chase Date: Fri, 28 Sep 2018 23:29:08 +0200 Subject: [PATCH 06/37] Revert: Fix headers in Handling Bot Tokens page --- .../org/telegram/abilitybots/api/bot/AbilityWebhookBot.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/AbilityWebhookBot.java b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/AbilityWebhookBot.java index ffa62de5..04887d7c 100644 --- a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/AbilityWebhookBot.java +++ b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/AbilityWebhookBot.java @@ -1,6 +1,5 @@ package org.telegram.abilitybots.api.bot; -import org.apache.http.impl.client.SystemDefaultCredentialsProvider; import org.telegram.abilitybots.api.db.DBContext; import org.telegram.telegrambots.meta.api.methods.BotApiMethod; import org.telegram.telegrambots.meta.api.objects.Update; @@ -29,8 +28,6 @@ public abstract class AbilityWebhookBot extends BaseAbilityBot implements Webhoo protected AbilityWebhookBot(String botToken, String botUsername, String botPath, DBContext db) { this(botToken, botUsername, botPath, db, new DefaultBotOptions()); - - } protected AbilityWebhookBot(String botToken, String botUsername, String botPath, DefaultBotOptions botOptions) { From 4efaa253b8048ef987c1462cdaeee0c5a5970120 Mon Sep 17 00:00:00 2001 From: d35h Date: Sun, 14 Oct 2018 21:45:49 +0200 Subject: [PATCH 07/37] Add addAll method for keyboardrow --- .../meta/api/objects/replykeyboard/buttons/KeyboardRow.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardRow.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardRow.java index 571e19d6..3381a09b 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardRow.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardRow.java @@ -4,6 +4,7 @@ import org.telegram.telegrambots.meta.api.interfaces.Validable; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; import java.util.ArrayList; +import java.util.List; /** * @author Ruben Bermudez @@ -20,6 +21,10 @@ public class KeyboardRow extends ArrayList implements Validable super.add(index, new KeyboardButton(text)); } + public void addAll(List buttonNames) { + buttonNames.forEach(KeyboardButton::new); + } + public boolean contains(String text) { return super.contains(new KeyboardButton(text)); } From dc62f9ce63b04ac9ad374d451a45ad6901eeae38 Mon Sep 17 00:00:00 2001 From: d35h Date: Sun, 14 Oct 2018 22:11:04 +0200 Subject: [PATCH 08/37] Add tests --- .../replykeyboard/buttons/KeyboardRow.java | 2 +- .../buttons/KeyboardRowTest.java | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardRowTest.java diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardRow.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardRow.java index 3381a09b..b1b76ecb 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardRow.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardRow.java @@ -22,7 +22,7 @@ public class KeyboardRow extends ArrayList implements Validable } public void addAll(List buttonNames) { - buttonNames.forEach(KeyboardButton::new); + buttonNames.forEach(name -> super.add(new KeyboardButton(name))); } public boolean contains(String text) { diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardRowTest.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardRowTest.java new file mode 100644 index 00000000..3e4f87f6 --- /dev/null +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardRowTest.java @@ -0,0 +1,34 @@ +package org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons; + +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import static java.util.Arrays.asList; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +public class KeyboardRowTest { + + private static final List BUTTON_NAMES = asList("Carlotta Valdes", "Jimmy Stewart"); + + @Test + public void shouldAddAllButtons() { + final KeyboardRow keyboardRow = new KeyboardRow(); + keyboardRow.addAll(BUTTON_NAMES); + assertThat(keyboardRow.size(), is(2)); + assertThat(keyboardRow.get(0).getText(), is("Carlotta Valdes")); + assertThat(keyboardRow.get(1).getText(), is("Jimmy Stewart")); + } + + @Test + public void shouldAddNoButtons() { + final KeyboardRow keyboardRow = new KeyboardRow(); + keyboardRow.addAll(new ArrayList()); + assertTrue(keyboardRow.isEmpty()); + } + +} From 4a244ce4daf64ce8aab59f81e8ff3c90d1f7382c Mon Sep 17 00:00:00 2001 From: Clevero Date: Wed, 17 Oct 2018 08:56:39 +0200 Subject: [PATCH 09/37] change deprecated URL to MonsterDeveloper's book The URL https://legacy.gitbook.com/book/monsterdeveloper/writing-telegram-bots-on-java/details seems to be deprecated https://monsterdeveloper.gitbooks.io/writing-telegram-bots-on-java/content/ --- TelegramBots.wiki/Home.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TelegramBots.wiki/Home.md b/TelegramBots.wiki/Home.md index b22449b3..882c90e8 100644 --- a/TelegramBots.wiki/Home.md +++ b/TelegramBots.wiki/Home.md @@ -1,3 +1,3 @@ Welcome to the TelegramBots wiki. Use the sidebar on the right. If you're not sure what to look at, why not take a look at the [[Getting Started|Getting-Started]] guide? -If you want more detailed explanations, you can also visit this [gitbook by MonsterDeveloper's](https://www.gitbook.com/book/monsterdeveloper/writing-telegram-bots-on-java/details) \ No newline at end of file +If you want more detailed explanations, you can also visit this [gitbook by MonsterDeveloper's](https://monsterdeveloper.gitbooks.io/writing-telegram-bots-on-java/content/) From 87fdde7fe15f73b7dccca4e81ae138659d5c943b Mon Sep 17 00:00:00 2001 From: Clevero Date: Wed, 17 Oct 2018 09:54:24 +0200 Subject: [PATCH 10/37] Update FAQ.md --- TelegramBots.wiki/FAQ.md | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/TelegramBots.wiki/FAQ.md b/TelegramBots.wiki/FAQ.md index eeac8dc7..c0e8727f 100644 --- a/TelegramBots.wiki/FAQ.md +++ b/TelegramBots.wiki/FAQ.md @@ -1,4 +1,5 @@ -* [How to get picture?](#how_to_get_picture) +* [How to get picture?](#how_to_get_picture) +* [How to display ChatActions like "typing" or "recording a voice message"?](#how_to_sendchataction) * [How to send photos?](#how_to_send_photos) * [How do I send photos by file_id?](#how_to_send_photos_file_id) * [How to use custom keyboards?](#how_to_use_custom_keyboards) @@ -74,6 +75,38 @@ public java.io.File downloadPhotoByFilePath(String filePath) { The returned `java.io.File` object will be your photo +## How to display ChatActions like "typing" or "recording a voice message"? ## +Quick example here that is showing ChactActions for commands like "/type" or "/record_audio" + +```java +if (update.hasMessage() && update.getMessage().hasText()) { + + String text = update.getMessage().getText(); + + SendChatAction sendChatAction = new SendChatAction(); + sendChatAction.setChatId(update.getMessage().getChatId()); + + if (text.equals("/type")) { + // -> "typing" + sendChatAction.setAction(ActionType.TYPING); + // -> "recording a voice message" + } else if (text.equals("/record_audio")) { + sendChatAction.setAction(ActionType.RECORDAUDIO); + } else { + // -> more actions in the Enum ActionType + // For information: https://core.telegram.org/bots/api#sendchataction + sendChatAction.setAction(ActionType.UPLOADDOCUMENT); + } + + try { + Boolean wasSuccessfull = execute(sendChatAction); + } catch (TelegramApiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } +} +``` + ## How to send photos? ## There are several method to send a photo to an user using `sendPhoto` method: With a `file_id`, with an `url` or uploading the file. In this example, we assume that we already have the *chat_id* where we want to send the photo: @@ -252,4 +285,4 @@ After that your bot will look like: //Bot body. } ``` -Also you could just implement LongPollingBot or WebHookBot interfaces. All this bots will be registered in context and connected to Telegram api. \ No newline at end of file +Also you could just implement LongPollingBot or WebHookBot interfaces. All this bots will be registered in context and connected to Telegram api. From 60d563493803f71f4d272dfcf0518a4a8e7c42e4 Mon Sep 17 00:00:00 2001 From: Stephan Groenewold Date: Wed, 24 Oct 2018 16:42:31 +0200 Subject: [PATCH 11/37] Update Wiki FAQ Spring Boot starter --- TelegramBots.wiki/FAQ.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/TelegramBots.wiki/FAQ.md b/TelegramBots.wiki/FAQ.md index eeac8dc7..a700c706 100644 --- a/TelegramBots.wiki/FAQ.md +++ b/TelegramBots.wiki/FAQ.md @@ -231,8 +231,6 @@ Your main spring boot class should look like this: ```java @SpringBootApplication -//Add this annotation to enable automatic bots initializing -@EnableTelegramBots public class YourApplicationMainClass { public static void main(String[] args) { @@ -246,7 +244,7 @@ public class YourApplicationMainClass { After that your bot will look like: ```java - //Standart Spring component annotation + //Standard Spring component annotation @Component public class YourBotClassName extends TelegramLongPollingBot { //Bot body. From cc5d365aed945faa78faf1ef5768c1e8cc733ce7 Mon Sep 17 00:00:00 2001 From: Victor Date: Tue, 6 Nov 2018 13:14:21 +0200 Subject: [PATCH 12/37] Fix setStickerPositionInSet method --- .../api/methods/stickers/SetStickerPositionInSet.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stickers/SetStickerPositionInSet.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stickers/SetStickerPositionInSet.java index f24fe53c..d25aea17 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stickers/SetStickerPositionInSet.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stickers/SetStickerPositionInSet.java @@ -17,14 +17,14 @@ import static com.google.common.base.Preconditions.checkNotNull; * Use this method to move a sticker in a set created by the bot to a specific position. Returns True on success. */ public class SetStickerPositionInSet extends BotApiMethod { - private static final String PATH = "getStickerSet"; + private static final String PATH = "setStickerPositionInSet"; private static final String STICKER_FIELD = "sticker"; private static final String POSITION_FIELD = "position"; @JsonProperty(STICKER_FIELD) private String sticker; ///< File identifier of the sticker - @JsonProperty(STICKER_FIELD) + @JsonProperty(POSITION_FIELD) private Integer position; ///< New sticker position in the set, zero-based public SetStickerPositionInSet(String sticker, Integer position) { @@ -61,7 +61,7 @@ public class SetStickerPositionInSet extends BotApiMethod { if (sticker == null || sticker.isEmpty()) { throw new TelegramApiValidationException("sticker can't be null", this); } - if (position == null || position > 0) { + if (position == null || position < 0) { throw new TelegramApiValidationException("position can't be null", this); } } @@ -71,7 +71,7 @@ public class SetStickerPositionInSet extends BotApiMethod { } public SetStickerPositionInSet setSticker(String sticker) { - this.sticker = sticker; + this.sticker = checkNotNull(sticker); return this; } @@ -80,7 +80,7 @@ public class SetStickerPositionInSet extends BotApiMethod { } public SetStickerPositionInSet setPosition(Integer position) { - this.position = position; + this.position = checkNotNull(position); return this; } From 1e764dfaf279af14540fe1916c1847c7ec3d099c Mon Sep 17 00:00:00 2001 From: Victor Date: Tue, 6 Nov 2018 14:12:13 +0200 Subject: [PATCH 13/37] Allow hyphen character in switchPmParameter --- .../telegrambots/meta/api/methods/AnswerInlineQuery.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/AnswerInlineQuery.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/AnswerInlineQuery.java index 80fb9434..5c341c80 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/AnswerInlineQuery.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/AnswerInlineQuery.java @@ -136,8 +136,8 @@ public class AnswerInlineQuery extends BotApiMethod { if (switchPmParameter.length() > 64) { throw new TelegramApiValidationException("SwitchPmParameter can't be longer than 64 chars", this); } - if (!Pattern.matches("[A-Za-z0-9_]+", switchPmParameter.trim() )) { - throw new TelegramApiValidationException("SwitchPmParameter only allows A-Z, a-z, 0-9 and _ characters", this); + if (!Pattern.matches("[A-Za-z0-9_\\-]+", switchPmParameter.trim() )) { + throw new TelegramApiValidationException("SwitchPmParameter only allows A-Z, a-z, 0-9, _ and - characters", this); } } for (InlineQueryResult result : results) { From 0f611bfd17ccd4ece59a04051309b99cc9e2ab32 Mon Sep 17 00:00:00 2001 From: Victor Date: Tue, 6 Nov 2018 14:33:50 +0200 Subject: [PATCH 14/37] Add record/upload video note to ActionType --- .../telegram/telegrambots/meta/api/methods/ActionType.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/ActionType.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/ActionType.java index 56c4f994..6b16949c 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/ActionType.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/ActionType.java @@ -9,9 +9,11 @@ package org.telegram.telegrambots.meta.api.methods; public enum ActionType { TYPING("typing"), RECORDVIDEO("record_video"), + RECORDVIDEONOTE("record_video_note"), RECORDAUDIO("record_audio"), UPLOADPHOTO("upload_photo"), UPLOADVIDEO("upload_video"), + UPLOADVIDEONOTE("upload_video_note"), UPLOADAUDIO("upload_audio"), UPLOADDOCUMENT("upload_document"), FINDLOCATION("find_location"); @@ -36,12 +38,16 @@ public enum ActionType { return TYPING; case "record_video": return RECORDVIDEO; + case "record_video_note": + return RECORDVIDEONOTE; case "record_audio": return RECORDAUDIO; case "upload_photo": return UPLOADPHOTO; case "upload_video": return UPLOADVIDEO; + case "upload_video_note": + return UPLOADVIDEONOTE; case "upload_audio": return UPLOADAUDIO; case "upload_document": From aa3e1fcf63d24686ec19ad44756e66c923df4818 Mon Sep 17 00:00:00 2001 From: Victor Date: Tue, 6 Nov 2018 16:35:55 +0200 Subject: [PATCH 15/37] Fix typos and error messages --- .../telegram/telegrambots/meta/TelegramBotsApi.java | 10 +++++----- .../meta/api/methods/AnswerCallbackQuery.java | 4 ++-- .../meta/api/methods/games/SetGameScore.java | 2 +- .../meta/api/methods/send/SendAnimation.java | 4 ++-- .../telegrambots/meta/api/methods/send/SendVideo.java | 4 ++-- .../meta/api/methods/stickers/CreateNewStickerSet.java | 2 +- .../api/methods/updatingmessages/EditMessageMedia.java | 2 +- .../telegram/telegrambots/meta/api/objects/Chat.java | 2 +- .../telegrambots/meta/api/objects/ChatMember.java | 4 ++-- .../telegrambots/meta/api/objects/PhotoSize.java | 2 +- .../inlinequery/result/InlineQueryResultVenue.java | 2 +- 11 files changed, 19 insertions(+), 19 deletions(-) diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/TelegramBotsApi.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/TelegramBotsApi.java index 94a2b1c3..ae8b5185 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/TelegramBotsApi.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/TelegramBotsApi.java @@ -18,7 +18,7 @@ public class TelegramBotsApi { private static final String webhookUrlFormat = "{0}callback/"; private boolean useWebhook; ///< True to enable webhook usage private Webhook webhook; ///< Webhook instance - private String extrenalUrl; ///< External url of the bots + private String externalUrl; ///< External url of the bots private String pathToCertificate; ///< Path to public key certificate /** @@ -43,7 +43,7 @@ public class TelegramBotsApi { } this.useWebhook = true; - this.extrenalUrl = fixExternalUrl(externalUrl); + this.externalUrl = fixExternalUrl(externalUrl); webhook = ApiContext.getInstance(Webhook.class); webhook.setInternalUrl(internalUrl); webhook.startServer(); @@ -71,7 +71,7 @@ public class TelegramBotsApi { } this.useWebhook = true; - this.extrenalUrl = fixExternalUrl(externalUrl); + this.externalUrl = fixExternalUrl(externalUrl); webhook = ApiContext.getInstance(Webhook.class); webhook.setInternalUrl(internalUrl); webhook.setKeyStore(keyStore, keyStorePassword); @@ -104,7 +104,7 @@ public class TelegramBotsApi { } this.useWebhook = true; - this.extrenalUrl = fixExternalUrl(externalUrl); + this.externalUrl = fixExternalUrl(externalUrl); this.pathToCertificate = pathToCertificate; webhook = ApiContext.getInstance(Webhook.class); webhook.setInternalUrl(internalUrl); @@ -133,7 +133,7 @@ public class TelegramBotsApi { public void registerBot(WebhookBot bot) throws TelegramApiRequestException { if (useWebhook) { webhook.registerWebhook(bot); - bot.setWebhook(extrenalUrl + bot.getBotPath(), pathToCertificate); + bot.setWebhook(externalUrl + bot.getBotPath(), pathToCertificate); } } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/AnswerCallbackQuery.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/AnswerCallbackQuery.java index fd1da785..a6783826 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/AnswerCallbackQuery.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/AnswerCallbackQuery.java @@ -35,13 +35,13 @@ public class AnswerCallbackQuery extends BotApiMethod { @JsonProperty(TEXT_FIELD) private String text; ///< Optional Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters @JsonProperty(SHOWALERT_FIELD) - private Boolean showAlert; ///< Optional. If true, an alert will be shown by the client instead of a notificaiton at the top of the chat screen. Defaults to false. + private Boolean showAlert; ///< Optional. If true, an alert will be shown by the client instead of a notification at the top of the chat screen. Defaults to false. @JsonProperty(URL_FIELD) /** * Optional. URL that will be opened by the user's client. * If you have created a Game and accepted the conditions via @Botfather, * specify the URL that opens your game. Otherwise you may use links - * InlineQueryResultGamelike telegram.me/your_bot?start=XXXX that open your bot with a parameter. + * like telegram.me/your_bot?start=XXXX that open your bot with a parameter. */ private String url; @JsonProperty(CACHETIME_FIELD) diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/games/SetGameScore.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/games/SetGameScore.java index 115da1ac..79f431d4 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/games/SetGameScore.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/games/SetGameScore.java @@ -63,7 +63,7 @@ public class SetGameScore extends BotApiMethod { @JsonProperty(SCORE_FIELD) private Integer score; ///< New score, must be positive @JsonProperty(FORCE_FIELD) - private Boolean force; ///< Opfional. Pass True, if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters + private Boolean force; ///< Optional. Pass True, if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters public SetGameScore() { super(); diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendAnimation.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendAnimation.java index d5a7fb37..f4d971aa 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendAnimation.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendAnimation.java @@ -46,9 +46,9 @@ public class SendAnimation extends PartialBotApiMethod { */ private InputFile animation; private Integer duration; ///< Optional. Duration of sent animation in seconds - private String caption; ///< OptionaL. Animation caption (may also be used when resending videos by file_id). + private String caption; ///< Optional. Animation caption (may also be used when resending videos by file_id). private Integer width; ///< Optional. Animation width - private Integer height; ///< OptionaL. Animation height + private Integer height; ///< Optional. Animation height private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound. private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendVideo.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendVideo.java index d37ce3f8..5c5bd310 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendVideo.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendVideo.java @@ -39,9 +39,9 @@ public class SendVideo extends PartialBotApiMethod { private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels) private InputFile video; ///< Video to send. file_id as String to resend a video that is already on the Telegram servers or URL to upload it private Integer duration; ///< Optional. Duration of sent video in seconds - private String caption; ///< OptionaL. Video caption (may also be used when resending videos by file_id). + private String caption; ///< Optional. Video caption (may also be used when resending videos by file_id). private Integer width; ///< Optional. Video width - private Integer height; ///< OptionaL. Video height + private Integer height; ///< Optional. Video height private Boolean supportsStreaming; ///< Optional. Pass True, if the uploaded video is suitable for streaming private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound. private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stickers/CreateNewStickerSet.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stickers/CreateNewStickerSet.java index ec6e2311..b3046a70 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stickers/CreateNewStickerSet.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/stickers/CreateNewStickerSet.java @@ -164,7 +164,7 @@ public class CreateNewStickerSet extends PartialBotApiMethod { throw new TelegramApiValidationException("name can't be empty", this); } if (title == null || title.isEmpty()) { - throw new TelegramApiValidationException("userId can't be empty", this); + throw new TelegramApiValidationException("title can't be empty", this); } if (emojis == null || emojis.isEmpty()) { throw new TelegramApiValidationException("emojis can't be empty", this); diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageMedia.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageMedia.java index 3cc7a200..20118738 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageMedia.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageMedia.java @@ -153,7 +153,7 @@ public class EditMessageMedia extends PartialBotApiMethod { } } if (media == null) { - throw new TelegramApiValidationException("Text parameter can't be empty", this); + throw new TelegramApiValidationException("Media parameter can't be empty", this); } media.validate(); diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Chat.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Chat.java index 14427628..24ac9d1e 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Chat.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Chat.java @@ -38,7 +38,7 @@ public class Chat implements BotApiObject { * so a signed 64 bit integer or double-precision float type are safe for storing this identifier. */ @JsonProperty(ID_FIELD) - private Long id; ///< Unique identifier for this chat, not exciding 1e13 by absolute value + private Long id; ///< Unique identifier for this chat, not exceeding 1e13 by absolute value @JsonProperty(TYPE_FIELD) private String type; ///< Type of the chat, one of “private”, “group” or “channel” @JsonProperty(TITLE_FIELD) diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatMember.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatMember.java index c22f29d0..59b42f03 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatMember.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatMember.java @@ -33,7 +33,7 @@ public class ChatMember implements BotApiObject { @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. Resticted and kicked only. Date when restrictions will be lifted for this user, unix time + 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(CANCHANGEINFORMATION_FIELD) @@ -51,7 +51,7 @@ public class ChatMember implements BotApiObject { @JsonProperty(CANPINMESSAGES_FIELD) private Boolean canPinMessages; ///< Optional. Administrators only. True, if the administrator can pin messages @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 administators that were appointed by the bot) + 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 can send text messages, contacts, locations and venues @JsonProperty(CANSENDMEDIAMESSAGES_FIELD) diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/PhotoSize.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/PhotoSize.java index 81b143a4..bdf8cbec 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/PhotoSize.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/PhotoSize.java @@ -27,7 +27,7 @@ public class PhotoSize implements BotApiObject { @JsonProperty(FILESIZE_FIELD) private Integer fileSize; ///< Optional. File size @JsonProperty(FILEPATH_FIELD) - private String filePath; ///< Undocumented field. Optional. Can contain the path to download the file direclty without calling to getFile + private String filePath; ///< Undocumented field. Optional. Can contain the path to download the file directly without calling to getFile public PhotoSize() { super(); diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/InlineQueryResultVenue.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/InlineQueryResultVenue.java index 0da6e048..c24da2aa 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/InlineQueryResultVenue.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/InlineQueryResultVenue.java @@ -189,7 +189,7 @@ public class InlineQueryResultVenue implements InlineQueryResult { throw new TelegramApiValidationException("Longitude parameter can't be empty", this); } if (address == null || address.isEmpty()) { - throw new TelegramApiValidationException("Longitude parameter can't be empty", this); + throw new TelegramApiValidationException("Address parameter can't be empty", this); } if (inputMessageContent != null) { inputMessageContent.validate(); From f133572a3ace763424887f8ef693465b3d6e0fcb Mon Sep 17 00:00:00 2001 From: Victor Date: Tue, 6 Nov 2018 16:40:50 +0200 Subject: [PATCH 16/37] Fix test case --- .../meta/test/apimethods/TestAnswerInlineQuery.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/test/apimethods/TestAnswerInlineQuery.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/test/apimethods/TestAnswerInlineQuery.java index 04f77a73..eea69669 100644 --- a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/test/apimethods/TestAnswerInlineQuery.java +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/test/apimethods/TestAnswerInlineQuery.java @@ -113,7 +113,7 @@ public class TestAnswerInlineQuery { try { answerInlineQuery.validate(); } catch (TelegramApiValidationException e) { - Assert.assertEquals("SwitchPmParameter only allows A-Z, a-z, 0-9 and _ characters", e.getMessage()); + Assert.assertEquals("SwitchPmParameter only allows A-Z, a-z, 0-9, _ and - characters", e.getMessage()); } } } From ce05d68e81e45f0ebc22af83a07d2db9aac3b772 Mon Sep 17 00:00:00 2001 From: Victor Date: Wed, 7 Nov 2018 12:34:50 +0200 Subject: [PATCH 17/37] Fix wrong class and method names --- .../DeleteChatStickerSet.java | 91 +++++++++++++++++++ .../DeleteStickerSetName.java | 2 + .../GetChatMemberCount.java | 2 + .../GetChatMembersCount.java | 78 ++++++++++++++++ .../EditMessageLiveLocation.java | 35 +++++-- .../test/BotApiMethodHelperFactory.java | 6 +- .../telegrambots/test/TestRestApi.java | 6 +- 7 files changed, 206 insertions(+), 14 deletions(-) create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/DeleteChatStickerSet.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/GetChatMembersCount.java diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/DeleteChatStickerSet.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/DeleteChatStickerSet.java new file mode 100644 index 00000000..609678d8 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/DeleteChatStickerSet.java @@ -0,0 +1,91 @@ +package org.telegram.telegrambots.meta.api.methods.groupadministration; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.type.TypeReference; +import java.io.IOException; +import java.util.Objects; +import org.telegram.telegrambots.meta.api.methods.BotApiMethod; +import org.telegram.telegrambots.meta.api.objects.replykeyboard.ApiResponse; +import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * @author Ruben Bermudez + * @version 3.4 + * Use this method to delete a group sticker set from a supergroup. + * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. + * Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method. + * Returns True on success. + */ +public class DeleteChatStickerSet extends BotApiMethod { + public static final String PATH = "deleteChatStickerSet"; + + private static final String CHATID_FIELD = "chat_id"; + + @JsonProperty(CHATID_FIELD) + private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels) + + public DeleteChatStickerSet() { + super(); + } + + public DeleteChatStickerSet(String chatId) { + super(); + this.chatId = checkNotNull(chatId); + } + + public DeleteChatStickerSet(Long chatId) { + super(); + this.chatId = checkNotNull(chatId).toString(); + } + + public String getChatId() { + return chatId; + } + + public DeleteChatStickerSet setChatId(String chatId) { + this.chatId = chatId; + return this; + } + + public DeleteChatStickerSet setChatId(Long chatId) { + Objects.requireNonNull(chatId); + this.chatId = chatId.toString(); + return this; + } + + @Override + public String getMethod() { + return PATH; + } + + @Override + public Boolean deserializeResponse(String answer) throws TelegramApiRequestException { + try { + ApiResponse result = OBJECT_MAPPER.readValue(answer, + new TypeReference>(){}); + if (result.getOk()) { + return result.getResult(); + } else { + throw new TelegramApiRequestException("Error deleting chat sticker set", 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); + } + } + + @Override + public String toString() { + return "DeleteChatStickerSet{" + + "chatId='" + chatId + '\'' + + '}'; + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/DeleteStickerSetName.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/DeleteStickerSetName.java index 4bda56ad..dcf72224 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/DeleteStickerSetName.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/DeleteStickerSetName.java @@ -19,7 +19,9 @@ import static com.google.common.base.Preconditions.checkNotNull; * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. * Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method. * Returns True on success. + * @deprecated Replaced by {@link DeleteChatStickerSet} */ +@Deprecated public class DeleteStickerSetName extends BotApiMethod { public static final String PATH = "deleteChatStickerSet"; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/GetChatMemberCount.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/GetChatMemberCount.java index d7691365..39fbb39f 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/GetChatMemberCount.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/GetChatMemberCount.java @@ -16,7 +16,9 @@ import java.util.Objects; * @version 1.0 * @brief Use this method to get the number of members in a chat. Returns Int on success. * @date 20 of May of 2016 + * @deprecated Replaced by {@link GetChatMembersCount} */ +@Deprecated public class GetChatMemberCount extends BotApiMethod { public static final String PATH = "getChatMembersCount"; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/GetChatMembersCount.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/GetChatMembersCount.java new file mode 100644 index 00000000..be757c73 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/GetChatMembersCount.java @@ -0,0 +1,78 @@ +package org.telegram.telegrambots.meta.api.methods.groupadministration; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.type.TypeReference; +import java.io.IOException; +import java.util.Objects; +import org.telegram.telegrambots.meta.api.methods.BotApiMethod; +import org.telegram.telegrambots.meta.api.objects.replykeyboard.ApiResponse; +import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief Use this method to get the number of members in a chat. Returns Int on success. + * @date 20 of May of 2016 + */ +public class GetChatMembersCount extends BotApiMethod { + public static final String PATH = "getChatMembersCount"; + + private static final String CHATID_FIELD = "chat_id"; + + @JsonProperty(CHATID_FIELD) + private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels) + + public GetChatMembersCount() { + super(); + } + + public String getChatId() { + return chatId; + } + + public GetChatMembersCount setChatId(String chatId) { + this.chatId = chatId; + return this; + } + + public GetChatMembersCount setChatId(Long chatId) { + Objects.requireNonNull(chatId); + this.chatId = chatId.toString(); + return this; + } + + @Override + public String getMethod() { + return PATH; + } + + @Override + public Integer deserializeResponse(String answer) throws TelegramApiRequestException { + try { + ApiResponse result = OBJECT_MAPPER.readValue(answer, + new TypeReference>(){}); + 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); + } + } + + @Override + public String toString() { + return "GetChatMembersCount{" + + "chatId='" + chatId + '\'' + + '}'; + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageLiveLocation.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageLiveLocation.java index df23324e..bb5c391c 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageLiveLocation.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageLiveLocation.java @@ -1,5 +1,6 @@ package org.telegram.telegrambots.meta.api.methods.updatingmessages; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.type.TypeReference; import org.telegram.telegrambots.meta.api.methods.BotApiMethod; @@ -50,7 +51,7 @@ public class EditMessageLiveLocation extends BotApiMethod { @JsonProperty(LATITUDE_FIELD) private Float latitude; ///< Latitude of new location @JsonProperty(LONGITUDE_FIELD) - private Float longitud; ///< Longitude of new location + private Float longitude; ///< Longitude of new location @JsonProperty(REPLYMARKUP_FIELD) private InlineKeyboardMarkup replyMarkup; ///< Optional. A JSON-serialized object for an inline keyboard. @@ -109,13 +110,31 @@ public class EditMessageLiveLocation extends BotApiMethod { return this; } + /** + * @deprecated Replaced by {@link #getLongitude()} + */ + @Deprecated + @JsonIgnore public Float getLongitud() { - return longitud; + return longitude; } - public EditMessageLiveLocation setLongitud(Float longitud) { - Objects.requireNonNull(longitud); - this.longitud = longitud; + public Float getLongitude() { + return longitude; + } + + /** + * @deprecated Replaced by {@link #setLongitude(Float)} + */ + @Deprecated + @JsonIgnore + public EditMessageLiveLocation setLongitud(Float longitude) { + return setLongitude(longitude); + } + + public EditMessageLiveLocation setLongitude(Float longitude) { + Objects.requireNonNull(longitude); + this.longitude = longitude; return this; } @@ -170,8 +189,8 @@ public class EditMessageLiveLocation extends BotApiMethod { if (latitude == null) { throw new TelegramApiValidationException("Latitude parameter can't be empty", this); } - if (longitud == null) { - throw new TelegramApiValidationException("Longitud parameter can't be empty", this); + if (longitude == null) { + throw new TelegramApiValidationException("Longitude parameter can't be empty", this); } if (replyMarkup != null) { replyMarkup.validate(); @@ -185,7 +204,7 @@ public class EditMessageLiveLocation extends BotApiMethod { ", messageId=" + messageId + ", inlineMessageId='" + inlineMessageId + '\'' + ", latitude=" + latitude + - ", longitud=" + longitud + + ", longitude=" + longitude + ", replyMarkup=" + replyMarkup + '}'; } diff --git a/telegrambots/src/test/java/org/telegram/telegrambots/test/BotApiMethodHelperFactory.java b/telegrambots/src/test/java/org/telegram/telegrambots/test/BotApiMethodHelperFactory.java index 7cd9c3f2..2b43acaa 100644 --- a/telegrambots/src/test/java/org/telegram/telegrambots/test/BotApiMethodHelperFactory.java +++ b/telegrambots/src/test/java/org/telegram/telegrambots/test/BotApiMethodHelperFactory.java @@ -14,7 +14,7 @@ import org.telegram.telegrambots.meta.api.methods.games.SetGameScore; import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChat; import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatAdministrators; import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatMember; -import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatMemberCount; +import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatMembersCount; import org.telegram.telegrambots.meta.api.methods.groupadministration.KickChatMember; import org.telegram.telegrambots.meta.api.methods.groupadministration.LeaveChat; import org.telegram.telegrambots.meta.api.methods.groupadministration.UnbanChatMember; @@ -123,8 +123,8 @@ public final class BotApiMethodHelperFactory { .setUserId(98765); } - public static BotApiMethod getChatMemberCount() { - return new GetChatMemberCount() + public static BotApiMethod getChatMembersCount() { + return new GetChatMembersCount() .setChatId("12345"); } diff --git a/telegrambots/src/test/java/org/telegram/telegrambots/test/TestRestApi.java b/telegrambots/src/test/java/org/telegram/telegrambots/test/TestRestApi.java index 15123914..09228816 100644 --- a/telegrambots/src/test/java/org/telegram/telegrambots/test/TestRestApi.java +++ b/telegrambots/src/test/java/org/telegram/telegrambots/test/TestRestApi.java @@ -196,14 +196,14 @@ public class TestRestApi extends JerseyTest { } @Test - public void TestGetChatMemberCount() { - webhookBot.setReturnValue(BotApiMethodHelperFactory.getChatMemberCount()); + public void TestGetChatMembersCount() { + webhookBot.setReturnValue(BotApiMethodHelperFactory.getChatMembersCount()); Entity entity = Entity.json(getUpdate()); BotApiMethod result = target("callback/testbot") .request(MediaType.APPLICATION_JSON) - .post(entity, GetChatMemberCount.class); + .post(entity, GetChatMembersCount.class); assertEquals("{\"chat_id\":\"12345\",\"method\":\"getChatMembersCount\"}", map(result)); } From 4916e9f8537821b6dc4aafc682eec5c83dd1e2b4 Mon Sep 17 00:00:00 2001 From: Victor Date: Thu, 8 Nov 2018 13:48:59 +0200 Subject: [PATCH 18/37] Fix wrong type in Sticker maskPosition field --- .../meta/api/objects/stickers/MaskPosition.java | 2 ++ .../telegrambots/meta/api/objects/stickers/Sticker.java | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stickers/MaskPosition.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stickers/MaskPosition.java index 8f1e1306..647cec40 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stickers/MaskPosition.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stickers/MaskPosition.java @@ -1,6 +1,7 @@ package org.telegram.telegrambots.meta.api.objects.stickers; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; import org.telegram.telegrambots.meta.api.interfaces.InputBotApiObject; import org.telegram.telegrambots.meta.api.interfaces.Validable; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; @@ -10,6 +11,7 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; * @version 3.2 * This object describes the position on faces where a mask should be placed by default. */ +@JsonTypeInfo(use=JsonTypeInfo.Id.NONE) public class MaskPosition implements InputBotApiObject, Validable { private static final String POINT_FIELD = "point"; private static final String XSHIFT_FIELD = "x_shift"; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stickers/Sticker.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stickers/Sticker.java index c44356d3..f33033b1 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stickers/Sticker.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/stickers/Sticker.java @@ -36,7 +36,7 @@ public class Sticker implements BotApiObject { @JsonProperty(SETNAME_FIELD) private String setName; ///< Optional. Name of the sticker set to which the sticker belongs @JsonProperty(MASKPOSITON_FIELD) - private String maskPosition; ///< Optional. For mask stickers, the position where the mask should be placed + private MaskPosition maskPosition; ///< Optional. For mask stickers, the position where the mask should be placed public Sticker() { super(); @@ -70,7 +70,7 @@ public class Sticker implements BotApiObject { return setName; } - public String getMaskPosition() { + public MaskPosition getMaskPosition() { return maskPosition; } @@ -84,7 +84,7 @@ public class Sticker implements BotApiObject { ", fileSize=" + fileSize + ", emoji='" + emoji + '\'' + ", setName='" + setName + '\'' + - ", maskPosition='" + maskPosition + '\'' + + ", maskPosition=" + maskPosition + '}'; } } From d515d8e44fe5ee457d6065eb03dbf46ea46a595e Mon Sep 17 00:00:00 2001 From: romangraef Date: Sat, 10 Nov 2018 00:51:00 +0100 Subject: [PATCH 19/37] Added the extensions to abilities --- Bots.ipr | 38 +- Bots.iws | 640 ++++++++++++++++++ TestMobileBot | Bin 0 -> 1048576 bytes .../abilitybots/api/bot/BaseAbilityBot.java | 93 ++- .../api/util/AbilityExtension.java | 7 + 5 files changed, 725 insertions(+), 53 deletions(-) create mode 100644 Bots.iws create mode 100644 TestMobileBot create mode 100644 telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/util/AbilityExtension.java diff --git a/Bots.ipr b/Bots.ipr index 992b5bc6..769d436c 100644 --- a/Bots.ipr +++ b/Bots.ipr @@ -632,6 +632,11 @@ + @@ -755,7 +760,7 @@ - diff --git a/Bots.iws b/Bots.iws new file mode 100644 index 00000000..a937786d --- /dev/null +++ b/Bots.iws @@ -0,0 +1,640 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + abilities + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1541802659942 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/TestMobileBot b/TestMobileBot new file mode 100644 index 0000000000000000000000000000000000000000..dd6b6263955049a1cc2c30094f22f18589087d2e GIT binary patch literal 1048576 zcmeIyy%9h#0Dw_H3s}L~#Hp-e37z>AHn0a0Kj&zail;~fr+AlqZJyk(bX%lNHB86D zunt!p$D%9a{2tEl%)1Q-4ne>^un+75=RgN^KnHX{2XsIObU+7mKnHX{2XsIObU+7m zKnHX{2XsIObU+7mKnHX{2XsIObU+7mKnHX{2XsIObU+7mKnHX{2XsIObU+7mKnHX{ z2XsIObU+7mKnHX{2XsIObU+7mKnHX{2XsIObU+7mKnHX{2XsIObU+7mKnHX{2XsIO zbU+7mKnHX{2XsIObU+7mKnHX{2XsIObU+7mKnHX{2XsIObU+7mKnHX{2XsIObl}l} zdEAf1HpVx7cFxNZ-(+9s>pyM?5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 h2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0Rle}SOLqZA+Z1e literal 0 HcmV?d00001 diff --git a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/BaseAbilityBot.java b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/BaseAbilityBot.java index aab22a2e..9f499a4e 100644 --- a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/BaseAbilityBot.java +++ b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/BaseAbilityBot.java @@ -12,6 +12,7 @@ import org.telegram.abilitybots.api.objects.*; import org.telegram.abilitybots.api.sender.DefaultSender; import org.telegram.abilitybots.api.sender.MessageSender; import org.telegram.abilitybots.api.sender.SilentSender; +import org.telegram.abilitybots.api.util.AbilityExtension; import org.telegram.abilitybots.api.util.AbilityUtils; import org.telegram.abilitybots.api.util.Pair; import org.telegram.abilitybots.api.util.Trio; @@ -36,7 +37,9 @@ import java.lang.reflect.Method; import java.util.*; import java.util.Map.Entry; import java.util.function.BiFunction; +import java.util.function.Function; import java.util.function.Predicate; +import java.util.stream.Collectors; import java.util.stream.Stream; import static com.google.common.base.Strings.isNullOrEmpty; @@ -93,7 +96,7 @@ import static org.telegram.abilitybots.api.util.AbilityUtils.*; * @author Abbas Abou Daya */ @SuppressWarnings({"ConfusingArgumentToVarargsMethod", "UnusedReturnValue", "WeakerAccess", "unused", "ConstantConditions"}) -public abstract class BaseAbilityBot extends DefaultAbsSender { +public abstract class BaseAbilityBot extends DefaultAbsSender implements AbilityExtension { private static final String TAG = BaseAbilityBot.class.getSimpleName(); // DB objects @@ -611,22 +614,31 @@ public abstract class BaseAbilityBot extends DefaultAbsSender { */ private void registerAbilities() { try { - abilities = stream(this.getClass().getMethods()) - .filter(method -> method.getReturnType().equals(Ability.class)) - .map(this::returnAbility) + Listextensions = stream(this.getClass().getMethods()) + .filter(checkReturnType(AbilityExtension.class)) + .map(this.returnExtension(this)) + .collect(Collectors.toList()); + + extensions.add(this); + + abilities = extensions.stream() + .flatMap(ext -> stream(ext.getClass().getMethods()) + .filter(checkReturnType(Ability.class)) + .map(this.returnAbility(ext))) .collect(ImmutableMap::builder, (b, a) -> b.put(a.name(), a), (b1, b2) -> b1.putAll(b2.build())) .build(); - Stream methodReplies = stream(this.getClass().getMethods()) - .filter(method -> method.getReturnType().equals(Reply.class)) - .map(this::returnReply); + Stream extensionReplies = extensions.stream() + .flatMap(ext -> stream(ext.getClass().getMethods()) + .filter(checkReturnType(Reply.class)) + .map(this.returnReply(ext))); Stream abilityReplies = abilities.values().stream() .flatMap(ability -> ability.replies().stream()); - replies = Stream.concat(methodReplies, abilityReplies).collect( + replies = Stream.concat(abilityReplies, extensionReplies).collect( ImmutableList::builder, Builder::add, (b1, b2) -> b1.addAll(b2.build())) @@ -638,34 +650,59 @@ public abstract class BaseAbilityBot extends DefaultAbsSender { } + private Predicate checkReturnType(Class clazz) { + return method -> clazz.isAssignableFrom(method.getReturnType()); + } + + /** - * Invokes the method and retrieves its return {@link Ability}. + * Invokes the method curried and retrieves its return {@link Reply}. * - * @param method a method that returns an ability - * @return the ability returned by the method + * @param obj an bot or extension that this method is invoked with + * @return a {@link Function} which returns the {@link Reply} returned by the given method */ - private Ability returnAbility(Method method) { - try { - return (Ability) method.invoke(this); - } catch (IllegalAccessException | InvocationTargetException e) { - BotLogger.error("Could not add ability", TAG, e); - throw propagate(e); - } + private Function returnExtension(Object obj) { + return method -> { + try { + return (AbilityExtension) method.invoke(obj); + } catch (IllegalAccessException | InvocationTargetException e) { + BotLogger.error("Could not add ability", TAG, e); + throw propagate(e); + } + }; + } + /** + * Invokes the method curried and retrieves its return {@link Ability}. + * + * @param obj an bot or extension that this method is invoked with + * @return a {@link Function} which returns the {@link Ability} returned by the given method + */ + private Function returnAbility(Object obj) { + return method -> { + try { + return (Ability) method.invoke(obj); + } catch (IllegalAccessException | InvocationTargetException e) { + BotLogger.error("Could not add ability", TAG, e); + throw propagate(e); + } + }; } /** - * Invokes the method and retrieves its returned Reply. + * Invokes the method curried and retrieves its return {@link Reply}. * - * @param method a method that returns a reply - * @return the reply returned by the method + * @param obj an bot or extension that this method is invoked with + * @return a {@link Function} which returns the {@link Reply} returned by the given method */ - private Reply returnReply(Method method) { - try { - return (Reply) method.invoke(this); - } catch (IllegalAccessException | InvocationTargetException e) { - BotLogger.error("Could not add reply", TAG, e); - throw propagate(e); - } + private Function returnReply(Object obj) { + return method -> { + try { + return (Reply) method.invoke(obj); + } catch (IllegalAccessException | InvocationTargetException e) { + BotLogger.error("Could not add ability", TAG, e); + throw propagate(e); + } + }; } private void postConsumption(Pair pair) { diff --git a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/util/AbilityExtension.java b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/util/AbilityExtension.java new file mode 100644 index 00000000..357ccebe --- /dev/null +++ b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/util/AbilityExtension.java @@ -0,0 +1,7 @@ +package org.telegram.abilitybots.api.util; + +/** + * An interface to mark a class as an extension. Similar to when a method returns an Ability, it is added to the bot, a method which returns an AbilityExtension will add all Abilities or Replies from this Extension to the bot. + */ +public interface AbilityExtension { +} From 159de38b297019462d8b9cba7cf67c4b16af6be8 Mon Sep 17 00:00:00 2001 From: romangraef Date: Sat, 10 Nov 2018 22:07:41 +0100 Subject: [PATCH 20/37] added tests for ability extension functionality --- .../api/bot/AbilityBotExtension.java | 26 ++++++++++++ .../abilitybots/api/bot/ExtensionTest.java | 36 ++++++++++++++++ .../api/bot/ExtensionUsingBot.java | 41 +++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotExtension.java create mode 100644 telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/ExtensionTest.java create mode 100644 telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/ExtensionUsingBot.java diff --git a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotExtension.java b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotExtension.java new file mode 100644 index 00000000..b0a1ccef --- /dev/null +++ b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotExtension.java @@ -0,0 +1,26 @@ +package org.telegram.abilitybots.api.bot; + +import org.telegram.abilitybots.api.objects.Ability; +import org.telegram.abilitybots.api.util.AbilityExtension; + +import static org.telegram.abilitybots.api.objects.Locality.ALL; +import static org.telegram.abilitybots.api.objects.Privacy.PUBLIC; + +public class AbilityBotExtension implements AbilityExtension { + private String name; + + public AbilityBotExtension(String name) { + this.name = name; + } + + public Ability abc() { + return Ability.builder() + .name(this.name + "0abc") + .info("Test ability") + .locality(ALL) + .privacy(PUBLIC) + .action(messageContext -> { + }) + .build(); + } +} diff --git a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/ExtensionTest.java b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/ExtensionTest.java new file mode 100644 index 00000000..bf6d3633 --- /dev/null +++ b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/ExtensionTest.java @@ -0,0 +1,36 @@ +package org.telegram.abilitybots.api.bot; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.telegram.abilitybots.api.objects.Ability; + +import static junit.framework.TestCase.assertTrue; + +public class ExtensionTest { + private ExtensionUsingBot bot; + + @Before + public void setUp() { + bot = new ExtensionUsingBot(); + } + + @After + public void teardown() { + bot = null; + } + + + @Test + public void methodReturningAbilities() { + assertTrue("Failed to find Ability in directly declared in root extension/bot", hasAbilityNamed("direct")); + assertTrue("Failed to find Ability in directly declared in extension returned by method returning the AbilityExtension class", hasAbilityNamed("returningSuperClass0abc")); + assertTrue("Failed to find Ability in directly declared in extension returned by method returning the AbilityExtension subclass", hasAbilityNamed("returningSubClass0abc")); + } + + private boolean hasAbilityNamed(String name) { + return bot.abilities().values().stream().map(Ability::name).anyMatch(name::equals); + } + + +} diff --git a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/ExtensionUsingBot.java b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/ExtensionUsingBot.java new file mode 100644 index 00000000..4cb593e7 --- /dev/null +++ b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/ExtensionUsingBot.java @@ -0,0 +1,41 @@ +package org.telegram.abilitybots.api.bot; + +import org.telegram.abilitybots.api.objects.Ability; +import org.telegram.abilitybots.api.util.AbilityExtension; + +import static org.telegram.abilitybots.api.db.MapDBContext.offlineInstance; +import static org.telegram.abilitybots.api.objects.Locality.ALL; +import static org.telegram.abilitybots.api.objects.Privacy.PUBLIC; + +public class ExtensionUsingBot extends AbilityBot { + public ExtensionUsingBot() { + super("", "", offlineInstance("testing")); + } + + + @Override + public int creatorId() { + return 0; + } + + public AbilityBotExtension methodReturningExtensionSubClass() { + return new AbilityBotExtension("returningSubClass"); + } + + public AbilityExtension methodReturningExtensionSuperClass() { + return new AbilityBotExtension("returningSuperClass"); + } + + public Ability methodReturningAbility() { + return Ability.builder() + .name("direct") + .info("Test ability") + .locality(ALL) + .privacy(PUBLIC) + .action(messageContext -> { + }) + .build(); + } + + +} From ff01673f8fe93e49a67e78276ad936c88e87742f Mon Sep 17 00:00:00 2001 From: romangraef Date: Sat, 10 Nov 2018 22:33:39 +0100 Subject: [PATCH 21/37] removed accidental tests --- Bots.iws | 640 -------------------------------------------------- TestMobileBot | Bin 1048576 -> 0 bytes 2 files changed, 640 deletions(-) delete mode 100644 Bots.iws delete mode 100644 TestMobileBot diff --git a/Bots.iws b/Bots.iws deleted file mode 100644 index a937786d..00000000 --- a/Bots.iws +++ /dev/null @@ -1,640 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - abilities - - - - - - - - - - - true - DEFINITION_ORDER - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1541802659942 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/TestMobileBot b/TestMobileBot deleted file mode 100644 index dd6b6263955049a1cc2c30094f22f18589087d2e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1048576 zcmeIyy%9h#0Dw_H3s}L~#Hp-e37z>AHn0a0Kj&zail;~fr+AlqZJyk(bX%lNHB86D zunt!p$D%9a{2tEl%)1Q-4ne>^un+75=RgN^KnHX{2XsIObU+7mKnHX{2XsIObU+7m zKnHX{2XsIObU+7mKnHX{2XsIObU+7mKnHX{2XsIObU+7mKnHX{2XsIObU+7mKnHX{ z2XsIObU+7mKnHX{2XsIObU+7mKnHX{2XsIObU+7mKnHX{2XsIObU+7mKnHX{2XsIO zbU+7mKnHX{2XsIObU+7mKnHX{2XsIObU+7mKnHX{2XsIObU+7mKnHX{2XsIObl}l} zdEAf1HpVx7cFxNZ-(+9s>pyM?5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 h2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0Rle}SOLqZA+Z1e From ee78c7016411e2fa3928b8acadde881fd0e5b215 Mon Sep 17 00:00:00 2001 From: romangraef Date: Sat, 10 Nov 2018 22:35:50 +0100 Subject: [PATCH 22/37] removed more accidental configs --- Bots.ipr | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/Bots.ipr b/Bots.ipr index 769d436c..992b5bc6 100644 --- a/Bots.ipr +++ b/Bots.ipr @@ -632,11 +632,6 @@ - @@ -760,7 +755,7 @@ - From 28740da0df54d0ede96eb6d4fe5ab048cdceba5b Mon Sep 17 00:00:00 2001 From: Erik-Berndt Scheper Date: Wed, 14 Nov 2018 07:09:41 +0100 Subject: [PATCH 23/37] Update dependencies to fix https://github.com/rubenlagus/TelegramBots/issues/547 --- telegrambots-abilities/pom.xml | 24 +++++++++++++++++++++++- telegrambots-meta/pom.xml | 10 +++++----- telegrambots/pom.xml | 6 +++--- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/telegrambots-abilities/pom.xml b/telegrambots-abilities/pom.xml index 16ebe0f3..eae5f436 100644 --- a/telegrambots-abilities/pom.xml +++ b/telegrambots-abilities/pom.xml @@ -68,7 +68,7 @@ 4.1 3.5 3.0.4 - 19.0 + 25.1-android @@ -91,6 +91,28 @@ com.google.guava guava ${guava.version} + + + com.google.code.findbugs + jsr305 + + + com.google.errorprone + error_prone_annotations + + + com.google.j2objc + j2objc-annotations + + + org.codehaus.mojo + animal-sniffer-annotations + + + org.checkerframework + checker-compat-qual + + diff --git a/telegrambots-meta/pom.xml b/telegrambots-meta/pom.xml index 88dd8d92..63fa43f5 100644 --- a/telegrambots-meta/pom.xml +++ b/telegrambots-meta/pom.xml @@ -59,10 +59,10 @@ UTF-8 UTF-8 - 4.1.0 - 2.8.7 - 2.8.0 - 20160810 + 4.2.2 + 2.9.7 + 2.9.0 + 20180813 4.12 @@ -254,4 +254,4 @@ - \ No newline at end of file + diff --git a/telegrambots/pom.xml b/telegrambots/pom.xml index baba488b..72eaa4e9 100644 --- a/telegrambots/pom.xml +++ b/telegrambots/pom.xml @@ -62,9 +62,9 @@ 2.25.1 1.19.3 4.5.3 - 20160810 - 2.8.7 - 2.8.0 + 20180813 + 2.9.7 + 2.9.0 2.5 4.1 From 1099ea07a334c994d996d5229890d19c2e17af89 Mon Sep 17 00:00:00 2001 From: Victor Date: Wed, 12 Dec 2018 17:28:25 +0200 Subject: [PATCH 24/37] Fix typo in package --- .../cached/InlineQueryResultCachedAudio.java | 135 ++++++++++++++ .../InlineQueryResultCachedDocument.java | 164 ++++++++++++++++++ .../cached/InlineQueryResultCachedGif.java | 144 +++++++++++++++ .../InlineQueryResultCachedMpeg4Gif.java | 146 ++++++++++++++++ .../cached/InlineQueryResultCachedPhoto.java | 157 +++++++++++++++++ .../InlineQueryResultCachedSticker.java | 109 ++++++++++++ .../cached/InlineQueryResultCachedVideo.java | 157 +++++++++++++++++ .../cached/InlineQueryResultCachedVoice.java | 146 ++++++++++++++++ .../chached/InlineQueryResultCachedAudio.java | 2 + .../InlineQueryResultCachedDocument.java | 2 + .../chached/InlineQueryResultCachedGif.java | 2 + .../InlineQueryResultCachedMpeg4Gif.java | 2 + .../chached/InlineQueryResultCachedPhoto.java | 2 + .../InlineQueryResultCachedSticker.java | 2 + .../chached/InlineQueryResultCachedVideo.java | 2 + .../chached/InlineQueryResultCachedVoice.java | 2 + .../result/chached/package-info.java | 4 + 17 files changed, 1178 insertions(+) create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/cached/InlineQueryResultCachedAudio.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/cached/InlineQueryResultCachedDocument.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/cached/InlineQueryResultCachedGif.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/cached/InlineQueryResultCachedMpeg4Gif.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/cached/InlineQueryResultCachedPhoto.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/cached/InlineQueryResultCachedSticker.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/cached/InlineQueryResultCachedVideo.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/cached/InlineQueryResultCachedVoice.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/package-info.java diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/cached/InlineQueryResultCachedAudio.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/cached/InlineQueryResultCachedAudio.java new file mode 100644 index 00000000..acd5966a --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/cached/InlineQueryResultCachedAudio.java @@ -0,0 +1,135 @@ +package org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent; +import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult; +import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief Represents a link to an mp3 audio file stored on the Telegram servers. By default, this + * audio file will be sent by the user. Alternatively, you can use input_message_content to send a + * message with the specified content instead of the audio. + * @note This will only work in Telegram versions released after 9 April, 2016. Older clients will + * ignore them. + * @date 10 of April of 2016 + */ +public class InlineQueryResultCachedAudio implements InlineQueryResult { + + private static final String TYPE_FIELD = "type"; + private static final String ID_FIELD = "id"; + private static final String AUDIO_FILE_ID_FIELD = "audio_file_id"; + private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content"; + private static final String REPLY_MARKUP_FIELD = "reply_markup"; + private static final String CAPTION_FIELD = "caption"; + private static final String PARSEMODE_FIELD = "parse_mode"; + + @JsonProperty(TYPE_FIELD) + private final String type = "audio"; ///< Type of the result, must be "audio" + @JsonProperty(ID_FIELD) + private String id; ///< Unique identifier of this result + @JsonProperty(AUDIO_FILE_ID_FIELD) + private String audioFileId; ///< A valid file identifier for the audio file + @JsonProperty(INPUTMESSAGECONTENT_FIELD) + private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the audio + @JsonProperty(REPLY_MARKUP_FIELD) + private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message + @JsonProperty(CAPTION_FIELD) + private String caption; ///< Optional. Audio caption (may also be used when resending documents by file_id), 0-200 characters + @JsonProperty(PARSEMODE_FIELD) + private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. + + public InlineQueryResultCachedAudio() { + super(); + } + + public String getType() { + return type; + } + + public String getId() { + return id; + } + + public InlineQueryResultCachedAudio setId(String id) { + this.id = id; + return this; + } + + public String getAudioFileId() { + return audioFileId; + } + + public InlineQueryResultCachedAudio setAudioFileId(String audioFileId) { + this.audioFileId = audioFileId; + return this; + } + + public InputMessageContent getInputMessageContent() { + return inputMessageContent; + } + + public InlineQueryResultCachedAudio setInputMessageContent(InputMessageContent inputMessageContent) { + this.inputMessageContent = inputMessageContent; + return this; + } + + public InlineKeyboardMarkup getReplyMarkup() { + return replyMarkup; + } + + public InlineQueryResultCachedAudio setReplyMarkup(InlineKeyboardMarkup replyMarkup) { + this.replyMarkup = replyMarkup; + return this; + } + + public String getCaption() { + return caption; + } + + public InlineQueryResultCachedAudio setCaption(String caption) { + this.caption = caption; + return this; + } + + public String getParseMode() { + return parseMode; + } + + public InlineQueryResultCachedAudio setParseMode(String parseMode) { + this.parseMode = parseMode; + return this; + } + + @Override + public void validate() throws TelegramApiValidationException { + if (id == null || id.isEmpty()) { + throw new TelegramApiValidationException("ID parameter can't be empty", this); + } + if (audioFileId == null || audioFileId.isEmpty()) { + throw new TelegramApiValidationException("AudioFileId parameter can't be empty", this); + } + if (inputMessageContent != null) { + inputMessageContent.validate(); + } + if (replyMarkup != null) { + replyMarkup.validate(); + } + } + + @Override + public String toString() { + return "InlineQueryResultCachedAudio{" + + "type='" + type + '\'' + + ", id='" + id + '\'' + + ", audioFileId='" + audioFileId + '\'' + + ", inputMessageContent=" + inputMessageContent + + ", replyMarkup=" + replyMarkup + + ", caption='" + caption + '\'' + + ", parseMode='" + parseMode + '\'' + + '}'; + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/cached/InlineQueryResultCachedDocument.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/cached/InlineQueryResultCachedDocument.java new file mode 100644 index 00000000..b11ea401 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/cached/InlineQueryResultCachedDocument.java @@ -0,0 +1,164 @@ +package org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent; +import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult; +import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * Represents a link to a file stored on the Telegram servers. By default, this file will be + * sent by the user with an optional caption. Alternatively, you can use input_message_content to + * send a message with the specified content instead of the file. + * @note Currently, only pdf-files and zip archives can be sent using this method. + * @note This will only work in Telegram versions released after 9 April, 2016. Older clients will + * ignore them. + */ +public class InlineQueryResultCachedDocument implements InlineQueryResult { + + private static final String TYPE_FIELD = "type"; + private static final String ID_FIELD = "id"; + private static final String TITLE_FIELD = "title"; + private static final String DOCUMENT_FILE_ID_FIELD = "document_file_id"; + private static final String DESCRIPTION_FIELD = "description"; + private static final String CAPTION_FIELD = "caption"; + private static final String REPLY_MARKUP_FIELD = "reply_markup"; + private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content"; + private static final String PARSEMODE_FIELD = "parse_mode"; + + @JsonProperty(TYPE_FIELD) + private final String type = "document"; ///< Type of the result, must be "document" + @JsonProperty(ID_FIELD) + private String id; ///< Unique identifier of this result, 1-64 bytes + @JsonProperty(TITLE_FIELD) + private String title; ///< Optional. Title for the result + @JsonProperty(DOCUMENT_FILE_ID_FIELD) + private String documentFileId; ///< A valid file identifier for the file + @JsonProperty(DESCRIPTION_FIELD) + private String description; ///< Optional. Short description of the result + @JsonProperty(CAPTION_FIELD) + private String caption; ///< Optional. Caption of the document to be sent, 0-200 characters + @JsonProperty(REPLY_MARKUP_FIELD) + private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message + @JsonProperty(INPUTMESSAGECONTENT_FIELD) + private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the file + @JsonProperty(PARSEMODE_FIELD) + private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. + + public InlineQueryResultCachedDocument() { + super(); + } + + public String getType() { + return type; + } + + public String getId() { + return id; + } + + public InlineQueryResultCachedDocument setId(String id) { + this.id = id; + return this; + } + + public String getTitle() { + return title; + } + + public InlineQueryResultCachedDocument setTitle(String title) { + this.title = title; + return this; + } + + public String getDocumentFileId() { + return documentFileId; + } + + public InlineQueryResultCachedDocument setDocumentFileId(String documentFileId) { + this.documentFileId = documentFileId; + return this; + } + + public String getDescription() { + return description; + } + + public InlineQueryResultCachedDocument setDescription(String description) { + this.description = description; + return this; + } + + public String getCaption() { + return caption; + } + + public InlineQueryResultCachedDocument setCaption(String caption) { + this.caption = caption; + return this; + } + + public InlineKeyboardMarkup getReplyMarkup() { + return replyMarkup; + } + + public InlineQueryResultCachedDocument setReplyMarkup(InlineKeyboardMarkup replyMarkup) { + this.replyMarkup = replyMarkup; + return this; + } + + public InputMessageContent getInputMessageContent() { + return inputMessageContent; + } + + public InlineQueryResultCachedDocument setInputMessageContent(InputMessageContent inputMessageContent) { + this.inputMessageContent = inputMessageContent; + return this; + } + + public String getParseMode() { + return parseMode; + } + + public InlineQueryResultCachedDocument setParseMode(String parseMode) { + this.parseMode = parseMode; + return this; + } + + @Override + public void validate() throws TelegramApiValidationException { + if (id == null || id.isEmpty()) { + throw new TelegramApiValidationException("ID parameter can't be empty", this); + } + if (documentFileId == null || documentFileId.isEmpty()) { + throw new TelegramApiValidationException("DocumentFileId parameter can't be empty", this); + } + if (title == null || title.isEmpty()) { + throw new TelegramApiValidationException("Title parameter can't be empty", this); + } + if (inputMessageContent != null) { + inputMessageContent.validate(); + } + if (replyMarkup != null) { + replyMarkup.validate(); + } + } + + @Override + public String toString() { + return "InlineQueryResultCachedDocument{" + + "type='" + type + '\'' + + ", id='" + id + '\'' + + ", title='" + title + '\'' + + ", documentFileId='" + documentFileId + '\'' + + ", description='" + description + '\'' + + ", caption='" + caption + '\'' + + ", replyMarkup=" + replyMarkup + + ", inputMessageContent=" + inputMessageContent + + ", parseMode='" + parseMode + '\'' + + '}'; + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/cached/InlineQueryResultCachedGif.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/cached/InlineQueryResultCachedGif.java new file mode 100644 index 00000000..ed24cded --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/cached/InlineQueryResultCachedGif.java @@ -0,0 +1,144 @@ +package org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent; +import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult; +import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * Represents a link to an animated GIF file stored on the Telegram servers. By default, this + * animated GIF file will be sent by the user with an optional caption. Alternatively, you can use + * input_message_content to send a message with specified content instead of the animation. + */ +public class InlineQueryResultCachedGif implements InlineQueryResult { + private static final String TYPE_FIELD = "type"; + private static final String ID_FIELD = "id"; + private static final String GIF_FILE_ID_FIELD = "gif_file_id"; + private static final String TITLE_FIELD = "title"; + private static final String CAPTION_FIELD = "caption"; + private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content"; + private static final String REPLY_MARKUP_FIELD = "reply_markup"; + private static final String PARSEMODE_FIELD = "parse_mode"; + + @JsonProperty(TYPE_FIELD) + private final String type = "gif"; ///< Type of the result, must be "gif" + @JsonProperty(ID_FIELD) + private String id; ///< Unique identifier of this result, 1-64 bytes + @JsonProperty(GIF_FILE_ID_FIELD) + private String gifFileId; ///< A valid file identifier for the GIF file + @JsonProperty(TITLE_FIELD) + private String title; ///< Optional. Title for the result + @JsonProperty(CAPTION_FIELD) + private String caption; ///< Optional. Caption of the GIF file to be sent + @JsonProperty(INPUTMESSAGECONTENT_FIELD) + private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the GIF animation + @JsonProperty(REPLY_MARKUP_FIELD) + private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message + @JsonProperty(PARSEMODE_FIELD) + private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. + + public InlineQueryResultCachedGif() { + super(); + } + + public String getType() { + return type; + } + + public String getId() { + return id; + } + + public InlineQueryResultCachedGif setId(String id) { + this.id = id; + return this; + } + + public String getGifFileId() { + return gifFileId; + } + + public InlineQueryResultCachedGif setGifFileId(String gifFileId) { + this.gifFileId = gifFileId; + return this; + } + + public String getTitle() { + return title; + } + + public InlineQueryResultCachedGif setTitle(String title) { + this.title = title; + return this; + } + + public String getCaption() { + return caption; + } + + public InlineQueryResultCachedGif setCaption(String caption) { + this.caption = caption; + return this; + } + + public InputMessageContent getInputMessageContent() { + return inputMessageContent; + } + + public InlineQueryResultCachedGif setInputMessageContent(InputMessageContent inputMessageContent) { + this.inputMessageContent = inputMessageContent; + return this; + } + + public InlineKeyboardMarkup getReplyMarkup() { + return replyMarkup; + } + + public InlineQueryResultCachedGif setReplyMarkup(InlineKeyboardMarkup replyMarkup) { + this.replyMarkup = replyMarkup; + return this; + } + + public String getParseMode() { + return parseMode; + } + + public InlineQueryResultCachedGif setParseMode(String parseMode) { + this.parseMode = parseMode; + return this; + } + + @Override + public void validate() throws TelegramApiValidationException { + if (id == null || id.isEmpty()) { + throw new TelegramApiValidationException("ID parameter can't be empty", this); + } + if (gifFileId == null || gifFileId.isEmpty()) { + throw new TelegramApiValidationException("GifFileId parameter can't be empty", this); + } + if (inputMessageContent != null) { + inputMessageContent.validate(); + } + if (replyMarkup != null) { + replyMarkup.validate(); + } + } + + @Override + public String toString() { + return "InlineQueryResultCachedGif{" + + "type='" + type + '\'' + + ", id='" + id + '\'' + + ", gifFileId='" + gifFileId + '\'' + + ", title='" + title + '\'' + + ", caption='" + caption + '\'' + + ", inputMessageContent=" + inputMessageContent + + ", replyMarkup=" + replyMarkup + + ", parseMode='" + parseMode + '\'' + + '}'; + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/cached/InlineQueryResultCachedMpeg4Gif.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/cached/InlineQueryResultCachedMpeg4Gif.java new file mode 100644 index 00000000..a64afef7 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/cached/InlineQueryResultCachedMpeg4Gif.java @@ -0,0 +1,146 @@ +package org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent; +import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult; +import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief Represents a link to a video animation (H.264/MPEG-4 AVC video without sound). By default, + * this animated MPEG-4 file will be sent by the user with optional caption. Alternatively, you can + * use input_message_content to send a message with the specified content instead of the animation. + * @date 01 of January of 2016 + */ +public class InlineQueryResultCachedMpeg4Gif implements InlineQueryResult { + + private static final String TYPE_FIELD = "type"; + private static final String ID_FIELD = "id"; + private static final String MPEG4_FILE_ID_FIELD = "mpeg4_file_id"; + private static final String TITLE_FIELD = "title"; + private static final String CAPTION_FIELD = "caption"; + private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content"; + private static final String REPLY_MARKUP_FIELD = "reply_markup"; + private static final String PARSEMODE_FIELD = "parse_mode"; + + @JsonProperty(TYPE_FIELD) + private final String type = "mpeg4_gif"; ///< Type of the result, must be "mpeg4_gif" + @JsonProperty(ID_FIELD) + private String id; ///< Unique identifier of this result, 1-64 bytes + @JsonProperty(MPEG4_FILE_ID_FIELD) + private String mpeg4FileId; ///< A valid file identifier for the MP4 file + @JsonProperty(TITLE_FIELD) + private String title; ///< Optional. Title for the result + @JsonProperty(CAPTION_FIELD) + private String caption; ///< Optional. Caption of the MPEG-4 file to be sent + @JsonProperty(INPUTMESSAGECONTENT_FIELD) + private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the photo + @JsonProperty(REPLY_MARKUP_FIELD) + private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message + @JsonProperty(PARSEMODE_FIELD) + private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. + + public InlineQueryResultCachedMpeg4Gif() { + super(); + } + + public String getType() { + return type; + } + + public String getId() { + return id; + } + + public InlineQueryResultCachedMpeg4Gif setId(String id) { + this.id = id; + return this; + } + + public String getMpeg4FileId() { + return mpeg4FileId; + } + + public InlineQueryResultCachedMpeg4Gif setMpeg4FileId(String mpeg4FileId) { + this.mpeg4FileId = mpeg4FileId; + return this; + } + + public String getTitle() { + return title; + } + + public InlineQueryResultCachedMpeg4Gif setTitle(String title) { + this.title = title; + return this; + } + + public String getCaption() { + return caption; + } + + public InlineQueryResultCachedMpeg4Gif setCaption(String caption) { + this.caption = caption; + return this; + } + + public InputMessageContent getInputMessageContent() { + return inputMessageContent; + } + + public InlineQueryResultCachedMpeg4Gif setInputMessageContent(InputMessageContent inputMessageContent) { + this.inputMessageContent = inputMessageContent; + return this; + } + + public InlineKeyboardMarkup getReplyMarkup() { + return replyMarkup; + } + + public InlineQueryResultCachedMpeg4Gif setReplyMarkup(InlineKeyboardMarkup replyMarkup) { + this.replyMarkup = replyMarkup; + return this; + } + + public String getParseMode() { + return parseMode; + } + + public InlineQueryResultCachedMpeg4Gif setParseMode(String parseMode) { + this.parseMode = parseMode; + return this; + } + + @Override + public void validate() throws TelegramApiValidationException { + if (id == null || id.isEmpty()) { + throw new TelegramApiValidationException("ID parameter can't be empty", this); + } + if (mpeg4FileId == null || mpeg4FileId.isEmpty()) { + throw new TelegramApiValidationException("Mpeg4FileId parameter can't be empty", this); + } + if (inputMessageContent != null) { + inputMessageContent.validate(); + } + if (replyMarkup != null) { + replyMarkup.validate(); + } + } + + @Override + public String toString() { + return "InlineQueryResultCachedMpeg4Gif{" + + "type='" + type + '\'' + + ", id='" + id + '\'' + + ", mpeg4FileId='" + mpeg4FileId + '\'' + + ", title='" + title + '\'' + + ", caption='" + caption + '\'' + + ", inputMessageContent=" + inputMessageContent + + ", replyMarkup=" + replyMarkup + + ", parseMode='" + parseMode + '\'' + + '}'; + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/cached/InlineQueryResultCachedPhoto.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/cached/InlineQueryResultCachedPhoto.java new file mode 100644 index 00000000..f0880a93 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/cached/InlineQueryResultCachedPhoto.java @@ -0,0 +1,157 @@ +package org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent; +import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult; +import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * Represents a link to a photo stored on the Telegram servers. By default, this photo will + * be sent by the user with an optional caption. Alternatively, you can use input_message_content to + * send a message with the specified content instead of the photo. + */ +public class InlineQueryResultCachedPhoto implements InlineQueryResult { + private static final String TYPE_FIELD = "type"; + private static final String ID_FIELD = "id"; + private static final String PHOTOFILEID_FIELD = "photo_file_id"; + private static final String TITLE_FIELD = "title"; + private static final String DESCRIPTION_FIELD = "description"; + private static final String CAPTION_FIELD = "caption"; + private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content"; + private static final String REPLY_MARKUP_FIELD = "reply_markup"; + private static final String PARSEMODE_FIELD = "parse_mode"; + + @JsonProperty(TYPE_FIELD) + private final String type = "photo"; ///< Type of the result, must be “photo” + @JsonProperty(ID_FIELD) + private String id; ///< Unique identifier of this result, 1-64 bytes + @JsonProperty(PHOTOFILEID_FIELD) + private String photoFileId; ///< A valid file identifier of the photo + @JsonProperty(TITLE_FIELD) + private String title; ///< Optional. Title for the result + @JsonProperty(DESCRIPTION_FIELD) + private String description; ///< Optional. Short description of the result + @JsonProperty(CAPTION_FIELD) + private String caption; ///< Optional. Caption of the photo to be sent + @JsonProperty(INPUTMESSAGECONTENT_FIELD) + private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the photo + @JsonProperty(REPLY_MARKUP_FIELD) + private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message + @JsonProperty(PARSEMODE_FIELD) + private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. + + public InlineQueryResultCachedPhoto() { + super(); + } + + public String getType() { + return type; + } + + public String getId() { + return id; + } + + public InlineQueryResultCachedPhoto setId(String id) { + this.id = id; + return this; + } + + public String getPhotoFileId() { + return photoFileId; + } + + public InlineQueryResultCachedPhoto setPhotoFileId(String photoFileId) { + this.photoFileId = photoFileId; + return this; + } + + public String getTitle() { + return title; + } + + public InlineQueryResultCachedPhoto setTitle(String title) { + this.title = title; + return this; + } + + public String getDescription() { + return description; + } + + public InlineQueryResultCachedPhoto setDescription(String description) { + this.description = description; + return this; + } + + public String getCaption() { + return caption; + } + + public InlineQueryResultCachedPhoto setCaption(String caption) { + this.caption = caption; + return this; + } + + public InputMessageContent getInputMessageContent() { + return inputMessageContent; + } + + public InlineQueryResultCachedPhoto setInputMessageContent(InputMessageContent inputMessageContent) { + this.inputMessageContent = inputMessageContent; + return this; + } + + public InlineKeyboardMarkup getReplyMarkup() { + return replyMarkup; + } + + public InlineQueryResultCachedPhoto setReplyMarkup(InlineKeyboardMarkup replyMarkup) { + this.replyMarkup = replyMarkup; + return this; + } + + public String getParseMode() { + return parseMode; + } + + public InlineQueryResultCachedPhoto setParseMode(String parseMode) { + this.parseMode = parseMode; + return this; + } + + @Override + public void validate() throws TelegramApiValidationException { + if (id == null || id.isEmpty()) { + throw new TelegramApiValidationException("ID parameter can't be empty", this); + } + if (photoFileId == null || photoFileId.isEmpty()) { + throw new TelegramApiValidationException("PhotoFileId parameter can't be empty", this); + } + if (inputMessageContent != null) { + inputMessageContent.validate(); + } + if (replyMarkup != null) { + replyMarkup.validate(); + } + } + + @Override + public String toString() { + return "InlineQueryResultCachedPhoto{" + + "type='" + type + '\'' + + ", id='" + id + '\'' + + ", photoFileId='" + photoFileId + '\'' + + ", title='" + title + '\'' + + ", description='" + description + '\'' + + ", caption='" + caption + '\'' + + ", inputMessageContent=" + inputMessageContent + + ", replyMarkup=" + replyMarkup + + ", parseMode='" + parseMode + '\'' + + '}'; + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/cached/InlineQueryResultCachedSticker.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/cached/InlineQueryResultCachedSticker.java new file mode 100644 index 00000000..2733e673 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/cached/InlineQueryResultCachedSticker.java @@ -0,0 +1,109 @@ +package org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent; +import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult; +import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief Represents a link to a sticker stored on the Telegram servers. By default, this sticker + * will be sent by the user. Alternatively, you can use input_message_content to send a message with + * the specified content instead of the sticker. + * @note This will only work in Telegram versions released after 9 April, 2016. Older clients will + * ignore them. + * @date 10 of April of 2016 + */ +public class InlineQueryResultCachedSticker implements InlineQueryResult { + + private static final String TYPE_FIELD = "type"; + private static final String ID_FIELD = "id"; + private static final String STICKER_FILE_ID_FIELD = "sticker_file_id"; + private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content"; + private static final String REPLY_MARKUP_FIELD = "reply_markup"; + + @JsonProperty(TYPE_FIELD) + private final String type = "sticker"; ///< Type of the result, must be "sticker" + @JsonProperty(ID_FIELD) + private String id; ///< Unique identifier of this result, 1-64 bytes + @JsonProperty(STICKER_FILE_ID_FIELD) + private String stickerFileId; ///< A valid file identifier of the sticker + @JsonProperty(INPUTMESSAGECONTENT_FIELD) + private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the sticker + @JsonProperty(REPLY_MARKUP_FIELD) + private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message + + public InlineQueryResultCachedSticker() { + super(); + } + + public String getType() { + return type; + } + + public String getId() { + return id; + } + + public InlineQueryResultCachedSticker setId(String id) { + this.id = id; + return this; + } + + public String getStickerFileId() { + return stickerFileId; + } + + public InlineQueryResultCachedSticker setStickerFileId(String stickerFileId) { + this.stickerFileId = stickerFileId; + return this; + } + + public InputMessageContent getInputMessageContent() { + return inputMessageContent; + } + + public InlineQueryResultCachedSticker setInputMessageContent(InputMessageContent inputMessageContent) { + this.inputMessageContent = inputMessageContent; + return this; + } + + public InlineKeyboardMarkup getReplyMarkup() { + return replyMarkup; + } + + public InlineQueryResultCachedSticker setReplyMarkup(InlineKeyboardMarkup replyMarkup) { + this.replyMarkup = replyMarkup; + return this; + } + + @Override + public void validate() throws TelegramApiValidationException { + if (id == null || id.isEmpty()) { + throw new TelegramApiValidationException("ID parameter can't be empty", this); + } + if (stickerFileId == null || stickerFileId.isEmpty()) { + throw new TelegramApiValidationException("StickerFileId parameter can't be empty", this); + } + if (inputMessageContent != null) { + inputMessageContent.validate(); + } + if (replyMarkup != null) { + replyMarkup.validate(); + } + } + + @Override + public String toString() { + return "InlineQueryResultCachedSticker{" + + "type='" + type + '\'' + + ", id='" + id + '\'' + + ", sticker_file_id='" + stickerFileId + '\'' + + ", inputMessageContent='" + inputMessageContent + '\'' + + ", replyMarkup='" + replyMarkup + '\'' + + '}'; + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/cached/InlineQueryResultCachedVideo.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/cached/InlineQueryResultCachedVideo.java new file mode 100644 index 00000000..6dccec17 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/cached/InlineQueryResultCachedVideo.java @@ -0,0 +1,157 @@ +package org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent; +import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult; +import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * Represents a link to a video file stored on the Telegram servers. By default, this video + * file will be sent by the user with an optional caption. Alternatively, you can use + * input_message_content to send a message with the specified content instead of the video. + */ +public class InlineQueryResultCachedVideo implements InlineQueryResult { + private static final String TYPE_FIELD = "type"; + private static final String ID_FIELD = "id"; + private static final String VIDEO_FILE_ID_FIELD = "video_file_id"; + private static final String TITLE_FIELD = "title"; + private static final String DESCRIPTION_FIELD = "description"; + private static final String CAPTION_FIELD = "caption"; + private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content"; + private static final String REPLY_MARKUP_FIELD = "reply_markup"; + private static final String PARSEMODE_FIELD = "parse_mode"; + + @JsonProperty(TYPE_FIELD) + private final String type = "video"; ///< Type of the result, must be "video" + @JsonProperty(ID_FIELD) + private String id; ///< Unique identifier of this result + @JsonProperty(VIDEO_FILE_ID_FIELD) + private String videoFileId; ///< A valid file identifier for the video file + @JsonProperty(TITLE_FIELD) + private String title; ///< Optional. Title for the result + @JsonProperty(DESCRIPTION_FIELD) + private String description; ///< Optional. Short description of the result + @JsonProperty(CAPTION_FIELD) + private String caption; ///< Optional. Caption of the video to be sent, 0-200 characters + @JsonProperty(INPUTMESSAGECONTENT_FIELD) + private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the photo + @JsonProperty(REPLY_MARKUP_FIELD) + private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message + @JsonProperty(PARSEMODE_FIELD) + private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. + + public InlineQueryResultCachedVideo() { + super(); + } + + public String getType() { + return type; + } + + public String getId() { + return id; + } + + public InlineQueryResultCachedVideo setId(String id) { + this.id = id; + return this; + } + + public String getVideoFileId() { + return videoFileId; + } + + public InlineQueryResultCachedVideo setVideoFileId(String videoFileId) { + this.videoFileId = videoFileId; + return this; + } + + public String getTitle() { + return title; + } + + public InlineQueryResultCachedVideo setTitle(String title) { + this.title = title; + return this; + } + + public String getDescription() { + return description; + } + + public InlineQueryResultCachedVideo setDescription(String description) { + this.description = description; + return this; + } + + public String getCaption() { + return caption; + } + + public InlineQueryResultCachedVideo setCaption(String caption) { + this.caption = caption; + return this; + } + + public InputMessageContent getInputMessageContent() { + return inputMessageContent; + } + + public InlineQueryResultCachedVideo setInputMessageContent(InputMessageContent inputMessageContent) { + this.inputMessageContent = inputMessageContent; + return this; + } + + public InlineKeyboardMarkup getReplyMarkup() { + return replyMarkup; + } + + public InlineQueryResultCachedVideo setReplyMarkup(InlineKeyboardMarkup replyMarkup) { + this.replyMarkup = replyMarkup; + return this; + } + + public String getParseMode() { + return parseMode; + } + + public InlineQueryResultCachedVideo setParseMode(String parseMode) { + this.parseMode = parseMode; + return this; + } + + @Override + public void validate() throws TelegramApiValidationException { + if (id == null || id.isEmpty()) { + throw new TelegramApiValidationException("ID parameter can't be empty", this); + } + if (videoFileId == null || videoFileId.isEmpty()) { + throw new TelegramApiValidationException("VideoFileId parameter can't be empty", this); + } + if (inputMessageContent != null) { + inputMessageContent.validate(); + } + if (replyMarkup != null) { + replyMarkup.validate(); + } + } + + @Override + public String toString() { + return "InlineQueryResultCachedVideo{" + + "type='" + type + '\'' + + ", id='" + id + '\'' + + ", videoFileId='" + videoFileId + '\'' + + ", title='" + title + '\'' + + ", description='" + description + '\'' + + ", caption='" + caption + '\'' + + ", inputMessageContent=" + inputMessageContent + + ", replyMarkup=" + replyMarkup + + ", parseMode='" + parseMode + '\'' + + '}'; + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/cached/InlineQueryResultCachedVoice.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/cached/InlineQueryResultCachedVoice.java new file mode 100644 index 00000000..94ec6256 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/cached/InlineQueryResultCachedVoice.java @@ -0,0 +1,146 @@ +package org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent; +import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult; +import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * Represents a link to a voice message stored on the Telegram servers. By default, this + * voice message will be sent by the user. Alternatively, you can use input_message_content to send + * a message with the specified content instead of the voice message. + * @note This will only work in Telegram versions released after 9 April, 2016. Older clients will + * ignore them. + */ +public class InlineQueryResultCachedVoice implements InlineQueryResult { + private static final String TYPE_FIELD = "type"; + private static final String ID_FIELD = "id"; + private static final String VOICE_FILE_ID_FIELD = "voice_file_id"; + private static final String TITLE_FIELD = "title"; + private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content"; + private static final String REPLY_MARKUP_FIELD = "reply_markup"; + private static final String CAPTION_FIELD = "caption"; + private static final String PARSEMODE_FIELD = "parse_mode"; + + @JsonProperty(TYPE_FIELD) + private final String type = "voice"; ///< Type of the result, must be "voice" + @JsonProperty(ID_FIELD) + private String id; ///< Unique identifier of this result, 1-64 bytes + @JsonProperty(VOICE_FILE_ID_FIELD) + private String voiceFileId; ///< A valid file identifier for the voice message + @JsonProperty(TITLE_FIELD) + private String title; ///< Recording title + @JsonProperty(INPUTMESSAGECONTENT_FIELD) + private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the voice recording + @JsonProperty(REPLY_MARKUP_FIELD) + private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message + @JsonProperty(CAPTION_FIELD) + private String caption; ///< Optional. Voice caption (may also be used when resending documents by file_id), 0-200 characters + @JsonProperty(PARSEMODE_FIELD) + private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. + + public InlineQueryResultCachedVoice() { + super(); + } + + public String getType() { + return type; + } + + public String getId() { + return id; + } + + public InlineQueryResultCachedVoice setId(String id) { + this.id = id; + return this; + } + + public String getVoiceFileId() { + return voiceFileId; + } + + public InlineQueryResultCachedVoice setVoiceFileId(String voiceFileId) { + this.voiceFileId = voiceFileId; + return this; + } + + public String getTitle() { + return title; + } + + public InlineQueryResultCachedVoice setTitle(String title) { + this.title = title; + return this; + } + + public InputMessageContent getInputMessageContent() { + return inputMessageContent; + } + + public InlineQueryResultCachedVoice setInputMessageContent(InputMessageContent inputMessageContent) { + this.inputMessageContent = inputMessageContent; + return this; + } + + public InlineKeyboardMarkup getReplyMarkup() { + return replyMarkup; + } + + public InlineQueryResultCachedVoice setReplyMarkup(InlineKeyboardMarkup replyMarkup) { + this.replyMarkup = replyMarkup; + return this; + } + + public String getCaption() { + return caption; + } + + public InlineQueryResultCachedVoice setCaption(String caption) { + this.caption = caption; + return this; + } + + public String getParseMode() { + return parseMode; + } + + public InlineQueryResultCachedVoice setParseMode(String parseMode) { + this.parseMode = parseMode; + return this; + } + + @Override + public void validate() throws TelegramApiValidationException { + if (id == null || id.isEmpty()) { + throw new TelegramApiValidationException("ID parameter can't be empty", this); + } + if (voiceFileId == null || voiceFileId.isEmpty()) { + throw new TelegramApiValidationException("VoiceFileId parameter can't be empty", this); + } + if (inputMessageContent != null) { + inputMessageContent.validate(); + } + if (replyMarkup != null) { + replyMarkup.validate(); + } + } + + @Override + public String toString() { + return "InlineQueryResultCachedVoice{" + + "type='" + type + '\'' + + ", id='" + id + '\'' + + ", voiceFileId='" + voiceFileId + '\'' + + ", title='" + title + '\'' + + ", inputMessageContent=" + inputMessageContent + + ", replyMarkup=" + replyMarkup + + ", caption='" + caption + '\'' + + ", parseMode='" + parseMode + '\'' + + '}'; + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedAudio.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedAudio.java index bb5d0298..f7b67ad4 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedAudio.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedAudio.java @@ -16,7 +16,9 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; * @note This will only work in Telegram versions released after 9 April, 2016. Older clients will * ignore them. * @date 10 of April of 2016 + * @deprecated Replaced by {@link org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedAudio} */ +@Deprecated public class InlineQueryResultCachedAudio implements InlineQueryResult { private static final String TYPE_FIELD = "type"; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedDocument.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedDocument.java index 5b13d647..fa3549cc 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedDocument.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedDocument.java @@ -16,7 +16,9 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; * @note Currently, only pdf-files and zip archives can be sent using this method. * @note This will only work in Telegram versions released after 9 April, 2016. Older clients will * ignore them. + * @deprecated Replaced by {@link org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedDocument} */ +@Deprecated public class InlineQueryResultCachedDocument implements InlineQueryResult { private static final String TYPE_FIELD = "type"; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedGif.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedGif.java index 4d60e6df..fb484cfd 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedGif.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedGif.java @@ -13,7 +13,9 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; * Represents a link to an animated GIF file stored on the Telegram servers. By default, this * animated GIF file will be sent by the user with an optional caption. Alternatively, you can use * input_message_content to send a message with specified content instead of the animation. + * @deprecated Replaced by {@link org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedGif} */ +@Deprecated public class InlineQueryResultCachedGif implements InlineQueryResult { private static final String TYPE_FIELD = "type"; private static final String ID_FIELD = "id"; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedMpeg4Gif.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedMpeg4Gif.java index 0a4a222d..75d9ad78 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedMpeg4Gif.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedMpeg4Gif.java @@ -14,7 +14,9 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; * this animated MPEG-4 file will be sent by the user with optional caption. Alternatively, you can * use input_message_content to send a message with the specified content instead of the animation. * @date 01 of January of 2016 + * @deprecated Replaced by {@link org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedMpeg4Gif} */ +@Deprecated public class InlineQueryResultCachedMpeg4Gif implements InlineQueryResult { private static final String TYPE_FIELD = "type"; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedPhoto.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedPhoto.java index 4ebd2d06..7aa781c3 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedPhoto.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedPhoto.java @@ -13,7 +13,9 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; * Represents a link to a photo stored on the Telegram servers. By default, this photo will * be sent by the user with an optional caption. Alternatively, you can use input_message_content to * send a message with the specified content instead of the photo. + * @deprecated Replaced by {@link org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedPhoto} */ +@Deprecated public class InlineQueryResultCachedPhoto implements InlineQueryResult { private static final String TYPE_FIELD = "type"; private static final String ID_FIELD = "id"; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedSticker.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedSticker.java index 9fb2558f..586651c8 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedSticker.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedSticker.java @@ -16,7 +16,9 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; * @note This will only work in Telegram versions released after 9 April, 2016. Older clients will * ignore them. * @date 10 of April of 2016 + * @deprecated Replaced by {@link org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedSticker} */ +@Deprecated public class InlineQueryResultCachedSticker implements InlineQueryResult { private static final String TYPE_FIELD = "type"; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedVideo.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedVideo.java index a46c5d43..890f4422 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedVideo.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedVideo.java @@ -13,7 +13,9 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; * Represents a link to a video file stored on the Telegram servers. By default, this video * file will be sent by the user with an optional caption. Alternatively, you can use * input_message_content to send a message with the specified content instead of the video. + * @deprecated Replaced by {@link org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedVideo} */ +@Deprecated public class InlineQueryResultCachedVideo implements InlineQueryResult { private static final String TYPE_FIELD = "type"; private static final String ID_FIELD = "id"; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedVoice.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedVoice.java index 3f110df3..c8f9a7c9 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedVoice.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedVoice.java @@ -15,7 +15,9 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; * a message with the specified content instead of the voice message. * @note This will only work in Telegram versions released after 9 April, 2016. Older clients will * ignore them. + * @deprecated Replaced by {@link org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedVoice} */ +@Deprecated public class InlineQueryResultCachedVoice implements InlineQueryResult { private static final String TYPE_FIELD = "type"; private static final String ID_FIELD = "id"; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/package-info.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/package-info.java new file mode 100644 index 00000000..96d11b44 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/package-info.java @@ -0,0 +1,4 @@ +/** + * @deprecated Replaced by {@link org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached} + */ +package org.telegram.telegrambots.meta.api.objects.inlinequery.result.chached; \ No newline at end of file From d091480f71d4514c1d96d701e0e87018279a0f31 Mon Sep 17 00:00:00 2001 From: Victor Date: Wed, 12 Dec 2018 18:10:00 +0200 Subject: [PATCH 25/37] Ability to set time periods with Instant, Duration and ZonedDateTime --- .../groupadministration/KickChatMember.java | 22 +++++++++++++++++-- .../RestrictChatMember.java | 22 +++++++++++++++++-- .../meta/api/objects/ChatMember.java | 9 ++++++++ 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/KickChatMember.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/KickChatMember.java index 99dcda52..252126b1 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/KickChatMember.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/KickChatMember.java @@ -1,5 +1,6 @@ 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; @@ -9,6 +10,9 @@ 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; import java.util.Objects; import static com.google.common.base.Preconditions.checkNotNull; @@ -81,11 +85,25 @@ public class KickChatMember extends BotApiMethod { return untilDate; } - public KickChatMember setUntilDate(Integer untilDate) { - this.untilDate = untilDate; + public KickChatMember setUntilDate(Integer untilDateInSeconds) { + this.untilDate = untilDateInSeconds; return this; } + @JsonIgnore + public KickChatMember setUntilDate(Instant instant) { + return setUntilDate((int) instant.getEpochSecond()); + } + + @JsonIgnore + public KickChatMember setUntilDate(ZonedDateTime date) { + return setUntilDate(date.toInstant()); + } + + public KickChatMember forTimePeriod(Duration duration) { + return setUntilDate(Instant.now().plusMillis(duration.toMillis())); + } + @Override public String getMethod() { return PATH; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/RestrictChatMember.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/RestrictChatMember.java index feeca4eb..49cdedb5 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/RestrictChatMember.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/RestrictChatMember.java @@ -1,5 +1,6 @@ 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 org.telegram.telegrambots.meta.api.methods.BotApiMethod; @@ -8,6 +9,9 @@ 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; import java.util.Objects; import static com.google.common.base.Preconditions.checkNotNull; @@ -89,11 +93,25 @@ public class RestrictChatMember extends BotApiMethod { return untilDate; } - public RestrictChatMember setUntilDate(Integer untilDate) { - this.untilDate = untilDate; + public RestrictChatMember setUntilDate(Integer untilDateInSeconds) { + this.untilDate = untilDateInSeconds; return this; } + @JsonIgnore + public RestrictChatMember setUntilDate(Instant instant) { + return setUntilDate((int) instant.getEpochSecond()); + } + + @JsonIgnore + public RestrictChatMember setUntilDate(ZonedDateTime date) { + return setUntilDate(date.toInstant()); + } + + public RestrictChatMember forTimePeriod(Duration duration) { + return setUntilDate(Instant.now().plusMillis(duration.toMillis())); + } + public Boolean getCanSendMessages() { return canSendMessages; } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatMember.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatMember.java index c22f29d0..c1996172 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatMember.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatMember.java @@ -4,6 +4,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import java.time.Instant; + /** * @author Ruben Bermudez * @version 1.0 @@ -77,6 +79,13 @@ public class ChatMember implements BotApiObject { return untilDate; } + public Instant getUntilDateAsInstant() { + if (untilDate == null) { + return null; + } + return Instant.ofEpochSecond(untilDate); + } + public Boolean getCanBeEdited() { return canBeEdited; } From ad195d8d599ec422b5d256d1a0ec01eb57ee9204 Mon Sep 17 00:00:00 2001 From: chase Date: Wed, 19 Dec 2018 22:09:04 +0100 Subject: [PATCH 26/37] Add annotation to allow bot to get botSession A method annotated with @AfterBotRegistration will be invoked after the bot is registered. Optionally the method can have a parameter of type BotSession to get passed the BotSession the bot was created with. --- .../starter/AfterBotRegistration.java | 20 +++++ .../starter/TelegramBotInitializer.java | 59 ++++++++++++- ...stTelegramBotStarterRegistrationHooks.java | 88 +++++++++++++++++++ 3 files changed, 163 insertions(+), 4 deletions(-) create mode 100644 telegrambots-spring-boot-starter/src/main/java/org/telegram/telegrambots/starter/AfterBotRegistration.java create mode 100644 telegrambots-spring-boot-starter/src/test/java/org/telegram/telegrambots/starter/TestTelegramBotStarterRegistrationHooks.java diff --git a/telegrambots-spring-boot-starter/src/main/java/org/telegram/telegrambots/starter/AfterBotRegistration.java b/telegrambots-spring-boot-starter/src/main/java/org/telegram/telegrambots/starter/AfterBotRegistration.java new file mode 100644 index 00000000..f613783b --- /dev/null +++ b/telegrambots-spring-boot-starter/src/main/java/org/telegram/telegrambots/starter/AfterBotRegistration.java @@ -0,0 +1,20 @@ +package org.telegram.telegrambots.starter; + +import org.telegram.telegrambots.meta.TelegramBotsApi; +import org.telegram.telegrambots.meta.generics.BotSession; +import org.telegram.telegrambots.meta.generics.LongPollingBot; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Indicated that the Method of a Class extending {@link LongPollingBot} will be called after the bot was registered + * If the Method has a single Parameter of type {@link BotSession}, the method get passed the bot session the bot was registered with + *

+ *

The bot session passed is the ones returned by {@link TelegramBotsApi#registerBot(LongPollingBot)}

+ */ +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +public @interface AfterBotRegistration {} diff --git a/telegrambots-spring-boot-starter/src/main/java/org/telegram/telegrambots/starter/TelegramBotInitializer.java b/telegrambots-spring-boot-starter/src/main/java/org/telegram/telegrambots/starter/TelegramBotInitializer.java index 4d9a1ec7..37b5ed46 100644 --- a/telegrambots-spring-boot-starter/src/main/java/org/telegram/telegrambots/starter/TelegramBotInitializer.java +++ b/telegrambots-spring-boot-starter/src/main/java/org/telegram/telegrambots/starter/TelegramBotInitializer.java @@ -1,13 +1,20 @@ package org.telegram.telegrambots.starter; -import java.util.List; -import java.util.Objects; - import org.springframework.beans.factory.InitializingBean; import org.telegram.telegrambots.meta.TelegramBotsApi; import org.telegram.telegrambots.meta.exceptions.TelegramApiException; +import org.telegram.telegrambots.meta.generics.BotSession; import org.telegram.telegrambots.meta.generics.LongPollingBot; import org.telegram.telegrambots.meta.generics.WebhookBot; +import org.telegram.telegrambots.meta.logging.BotLogger; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.List; +import java.util.Objects; +import java.util.stream.Stream; + +import static java.lang.String.format; /** * Receives all beand which are #LongPollingBot and #WebhookBot and register them in #TelegramBotsApi. @@ -33,7 +40,8 @@ public class TelegramBotInitializer implements InitializingBean { public void afterPropertiesSet() throws Exception { try { for (LongPollingBot bot : longPollingBots) { - telegramBotsApi.registerBot(bot); + BotSession session = telegramBotsApi.registerBot(bot); + handleAfterRegistrationHook(bot, session); } for (WebhookBot bot : webHookBots) { telegramBotsApi.registerBot(bot); @@ -42,4 +50,47 @@ public class TelegramBotInitializer implements InitializingBean { throw new RuntimeException(e); } } + + private void handleAnnotatedMethod(Object bot, Method method, BotSession session) throws InvocationTargetException, IllegalAccessException { + if (method.getParameterCount() > 1) { + BotLogger.warn(this.getClass().getSimpleName(), + format("Method %s of Type %s has too many parameters", + method.getName(), + method.getDeclaringClass().getCanonicalName() + ) + ); + return; + } + if (method.getParameterCount() == 0) { + method.invoke(bot); + return; + } + if (method.getParameterTypes()[0].equals(BotSession.class)) { + method.invoke(bot, session); + return; + } + BotLogger.warn(this.getClass().getSimpleName(), + format("Method %s of Type %s has invalid parameter type", + method.getName(), + method.getDeclaringClass().getCanonicalName() + ) + ); + } + + private void handleAfterRegistrationHook(Object bot, BotSession botSession) { + for (Method m : bot.getClass().getMethods()) { + Stream.of(m.getAnnotations()).forEach(annotation -> System.out.println(annotation.annotationType().getName())); + if (m.getAnnotation(AfterBotRegistration.class) != null) { + try { + handleAnnotatedMethod(bot, m, botSession); + } catch (InvocationTargetException | IllegalAccessException e) { + BotLogger.error(this.getClass().getSimpleName(), + format("Couldn't invoke Method %s of Type %s", + m.getName(), m.getDeclaringClass().getCanonicalName() + ) + ); + } + } + } + } } diff --git a/telegrambots-spring-boot-starter/src/test/java/org/telegram/telegrambots/starter/TestTelegramBotStarterRegistrationHooks.java b/telegrambots-spring-boot-starter/src/test/java/org/telegram/telegrambots/starter/TestTelegramBotStarterRegistrationHooks.java new file mode 100644 index 00000000..aba90dad --- /dev/null +++ b/telegrambots-spring-boot-starter/src/test/java/org/telegram/telegrambots/starter/TestTelegramBotStarterRegistrationHooks.java @@ -0,0 +1,88 @@ +package org.telegram.telegrambots.starter; + + +import org.junit.Test; +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.telegram.telegrambots.bots.TelegramLongPollingBot; +import org.telegram.telegrambots.meta.TelegramBotsApi; +import org.telegram.telegrambots.meta.api.objects.Update; +import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; +import org.telegram.telegrambots.meta.generics.BotSession; +import org.telegram.telegrambots.meta.generics.LongPollingBot; +import org.telegram.telegrambots.updatesreceivers.DefaultBotSession; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.*; + +public class TestTelegramBotStarterRegistrationHooks { + + private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(MockTelegramBotsApi.class, TelegramBotStarterConfiguration.class)); + + // Terrible workaround for mockito loosing annotations on methods + private static boolean hookCalled = false; + private static boolean hookCalledWithSession = false; + private static final DefaultBotSession someBotSession = new DefaultBotSession(); + + private static final TelegramBotsApi mockTelegramBotsApi = mock(TelegramBotsApi.class); + + @Test + public void longPollingBotWithAnnotatedMethodshouldBeCalled() throws TelegramApiRequestException { + + when(mockTelegramBotsApi.registerBot(any(LongPollingBot.class))).thenReturn(someBotSession); + + this.contextRunner.withUserConfiguration(LongPollingBotConfig.class) + .run((context) -> { + assertThat(context).hasSingleBean(AnnotatedLongPollingBot.class); + + final LongPollingBot bot = context.getBean(LongPollingBot.class); + final TelegramBotsApi telegramBotsApi = context.getBean(TelegramBotsApi.class); + + assertThat(hookCalled).isTrue(); + assertThat(hookCalledWithSession).isTrue(); + verify(telegramBotsApi, times(1)).registerBot(bot); + verifyNoMoreInteractions(telegramBotsApi); + }); + } + + + @Configuration + static class MockTelegramBotsApi{ + + @Bean + public TelegramBotsApi telegramBotsApi() { + return mockTelegramBotsApi; + } + } + + @Configuration + static class LongPollingBotConfig{ + @Bean + public LongPollingBot longPollingBot() { return new AnnotatedLongPollingBot(); } + } + + static class AnnotatedLongPollingBot extends TelegramLongPollingBot { + + @Override + public void onUpdateReceived(final Update update) {} + + @Override + public String getBotUsername() { return null; } + + @Override + public String getBotToken() { return null; } + + @AfterBotRegistration + public void afterBotHook() { + hookCalled = true; + } + + @AfterBotRegistration + public void afterBotHookWithSession(BotSession session) { + hookCalledWithSession = session.equals(someBotSession); + } + } +} From 4c86a3994d2a4d4d437159209e4f06007c8c17ea Mon Sep 17 00:00:00 2001 From: chase Date: Wed, 2 Jan 2019 14:04:01 +0100 Subject: [PATCH 27/37] Add missing "disableNotification" field to toString() of SendMessage class --- .../telegrambots/meta/api/methods/send/SendMessage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendMessage.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendMessage.java index 5c1bd562..58c5e806 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendMessage.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendMessage.java @@ -2,7 +2,6 @@ package org.telegram.telegrambots.meta.api.methods.send; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.type.TypeReference; - import org.telegram.telegrambots.meta.api.methods.BotApiMethod; import org.telegram.telegrambots.meta.api.methods.ParseMode; import org.telegram.telegrambots.meta.api.objects.Message; @@ -222,6 +221,7 @@ public class SendMessage extends BotApiMethod { "chatId='" + chatId + '\'' + ", text='" + text + '\'' + ", parseMode='" + parseMode + '\'' + + ", disableNotification='" + disableNotification + '\'' + ", disableWebPagePreview=" + disableWebPagePreview + ", replyToMessageId=" + replyToMessageId + ", replyMarkup=" + replyMarkup + From 880c8a20877539a33ef38ae127742fc74a78195d Mon Sep 17 00:00:00 2001 From: Rubenlagus Date: Wed, 2 Jan 2019 14:57:27 +0100 Subject: [PATCH 28/37] Fix guava dependency --- telegrambots-abilities/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telegrambots-abilities/pom.xml b/telegrambots-abilities/pom.xml index eae5f436..3f83756e 100644 --- a/telegrambots-abilities/pom.xml +++ b/telegrambots-abilities/pom.xml @@ -68,7 +68,7 @@ 4.1 3.5 3.0.4 - 25.1-android + 27.0.1-jre From 97e0aaa10fef219993932797289878566b78fe84 Mon Sep 17 00:00:00 2001 From: Rubenlagus Date: Wed, 2 Jan 2019 15:16:03 +0100 Subject: [PATCH 29/37] Fix inheritance of deprecated methods --- Bots.ipr | 133 +++++++++++---- .../DeleteStickerSetName.java | 83 +--------- .../GetChatMemberCount.java | 75 +-------- .../GetChatMembersCount.java | 8 +- .../chached/InlineQueryResultCachedAudio.java | 126 +-------------- .../InlineQueryResultCachedDocument.java | 152 +----------------- .../chached/InlineQueryResultCachedGif.java | 135 +--------------- .../InlineQueryResultCachedMpeg4Gif.java | 139 +--------------- .../chached/InlineQueryResultCachedPhoto.java | 148 +---------------- .../InlineQueryResultCachedSticker.java | 99 +----------- .../chached/InlineQueryResultCachedVideo.java | 148 +---------------- .../chached/InlineQueryResultCachedVoice.java | 135 +--------------- 12 files changed, 117 insertions(+), 1264 deletions(-) diff --git a/Bots.ipr b/Bots.ipr index 992b5bc6..4402de7d 100644 --- a/Bots.ipr +++ b/Bots.ipr @@ -220,7 +220,6 @@ - @@ -501,7 +500,7 @@ - + @@ -896,70 +895,92 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + @@ -973,15 +994,37 @@ - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + @@ -1292,6 +1335,28 @@ + + + + + + + + + + + + + + + + + + + + + + @@ -1622,15 +1687,15 @@ - + - + - + - + diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/DeleteStickerSetName.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/DeleteStickerSetName.java index dcf72224..23154628 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/DeleteStickerSetName.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/DeleteStickerSetName.java @@ -1,17 +1,5 @@ package org.telegram.telegrambots.meta.api.methods.groupadministration; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.type.TypeReference; -import org.telegram.telegrambots.meta.api.methods.BotApiMethod; -import org.telegram.telegrambots.meta.api.objects.replykeyboard.ApiResponse; -import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; -import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; - -import java.io.IOException; -import java.util.Objects; - -import static com.google.common.base.Preconditions.checkNotNull; - /** * @author Ruben Bermudez * @version 3.4 @@ -22,74 +10,5 @@ import static com.google.common.base.Preconditions.checkNotNull; * @deprecated Replaced by {@link DeleteChatStickerSet} */ @Deprecated -public class DeleteStickerSetName extends BotApiMethod { - public static final String PATH = "deleteChatStickerSet"; - - private static final String CHATID_FIELD = "chat_id"; - - @JsonProperty(CHATID_FIELD) - private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels) - - public DeleteStickerSetName() { - super(); - } - - public DeleteStickerSetName(String chatId) { - super(); - this.chatId = checkNotNull(chatId); - } - - public DeleteStickerSetName(Long chatId) { - super(); - this.chatId = checkNotNull(chatId).toString(); - } - - public String getChatId() { - return chatId; - } - - public DeleteStickerSetName setChatId(String chatId) { - this.chatId = chatId; - return this; - } - - public DeleteStickerSetName setChatId(Long chatId) { - Objects.requireNonNull(chatId); - this.chatId = chatId.toString(); - return this; - } - - @Override - public String getMethod() { - return PATH; - } - - @Override - public Boolean deserializeResponse(String answer) throws TelegramApiRequestException { - try { - ApiResponse result = OBJECT_MAPPER.readValue(answer, - new TypeReference>(){}); - if (result.getOk()) { - return result.getResult(); - } else { - throw new TelegramApiRequestException("Error deleting sticker set name", 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); - } - } - - @Override - public String toString() { - return "GetChat{" + - "chatId='" + chatId + '\'' + - '}'; - } +public class DeleteStickerSetName extends DeleteChatStickerSet { } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/GetChatMemberCount.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/GetChatMemberCount.java index 39fbb39f..6724a9ec 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/GetChatMemberCount.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/GetChatMemberCount.java @@ -1,82 +1,11 @@ package org.telegram.telegrambots.meta.api.methods.groupadministration; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.type.TypeReference; - -import org.telegram.telegrambots.meta.api.methods.BotApiMethod; -import org.telegram.telegrambots.meta.api.objects.replykeyboard.ApiResponse; -import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; -import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; - -import java.io.IOException; -import java.util.Objects; - /** * @author Ruben Bermudez * @version 1.0 - * @brief Use this method to get the number of members in a chat. Returns Int on success. - * @date 20 of May of 2016 + * Use this method to get the number of members in a chat. Returns Int on success. * @deprecated Replaced by {@link GetChatMembersCount} */ @Deprecated -public class GetChatMemberCount extends BotApiMethod { - public static final String PATH = "getChatMembersCount"; - - private static final String CHATID_FIELD = "chat_id"; - - @JsonProperty(CHATID_FIELD) - private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels) - - public GetChatMemberCount() { - super(); - } - - public String getChatId() { - return chatId; - } - - public GetChatMemberCount setChatId(String chatId) { - this.chatId = chatId; - return this; - } - - public GetChatMemberCount setChatId(Long chatId) { - Objects.requireNonNull(chatId); - this.chatId = chatId.toString(); - return this; - } - - @Override - public String getMethod() { - return PATH; - } - - @Override - public Integer deserializeResponse(String answer) throws TelegramApiRequestException { - try { - ApiResponse result = OBJECT_MAPPER.readValue(answer, - new TypeReference>(){}); - if (result.getOk()) { - return result.getResult(); - } else { - throw new TelegramApiRequestException("Error getting chat member 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); - } - } - - @Override - public String toString() { - return "GetChatMemberCount{" + - "chatId='" + chatId + '\'' + - '}'; - } +public class GetChatMemberCount extends GetChatMembersCount { } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/GetChatMembersCount.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/GetChatMembersCount.java index be757c73..16b91d3a 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/GetChatMembersCount.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/GetChatMembersCount.java @@ -2,18 +2,18 @@ package org.telegram.telegrambots.meta.api.methods.groupadministration; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.type.TypeReference; -import java.io.IOException; -import java.util.Objects; import org.telegram.telegrambots.meta.api.methods.BotApiMethod; import org.telegram.telegrambots.meta.api.objects.replykeyboard.ApiResponse; import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; +import java.io.IOException; +import java.util.Objects; + /** * @author Ruben Bermudez * @version 1.0 - * @brief Use this method to get the number of members in a chat. Returns Int on success. - * @date 20 of May of 2016 + * Use this method to get the number of members in a chat. Returns Int on success. */ public class GetChatMembersCount extends BotApiMethod { public static final String PATH = "getChatMembersCount"; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedAudio.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedAudio.java index f7b67ad4..68ac6663 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedAudio.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedAudio.java @@ -1,137 +1,15 @@ package org.telegram.telegrambots.meta.api.objects.inlinequery.result.chached; -import com.fasterxml.jackson.annotation.JsonProperty; - -import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent; -import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult; -import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup; -import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; - /** * @author Ruben Bermudez * @version 1.0 - * @brief Represents a link to an mp3 audio file stored on the Telegram servers. By default, this + * Represents a link to an mp3 audio file stored on the Telegram servers. By default, this * audio file will be sent by the user. Alternatively, you can use input_message_content to send a * message with the specified content instead of the audio. * @note This will only work in Telegram versions released after 9 April, 2016. Older clients will * ignore them. - * @date 10 of April of 2016 * @deprecated Replaced by {@link org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedAudio} */ @Deprecated -public class InlineQueryResultCachedAudio implements InlineQueryResult { - - private static final String TYPE_FIELD = "type"; - private static final String ID_FIELD = "id"; - private static final String AUDIO_FILE_ID_FIELD = "audio_file_id"; - private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content"; - private static final String REPLY_MARKUP_FIELD = "reply_markup"; - private static final String CAPTION_FIELD = "caption"; - private static final String PARSEMODE_FIELD = "parse_mode"; - - @JsonProperty(TYPE_FIELD) - private final String type = "audio"; ///< Type of the result, must be "audio" - @JsonProperty(ID_FIELD) - private String id; ///< Unique identifier of this result - @JsonProperty(AUDIO_FILE_ID_FIELD) - private String audioFileId; ///< A valid file identifier for the audio file - @JsonProperty(INPUTMESSAGECONTENT_FIELD) - private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the audio - @JsonProperty(REPLY_MARKUP_FIELD) - private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message - @JsonProperty(CAPTION_FIELD) - private String caption; ///< Optional. Audio caption (may also be used when resending documents by file_id), 0-200 characters - @JsonProperty(PARSEMODE_FIELD) - private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. - - public InlineQueryResultCachedAudio() { - super(); - } - - public String getType() { - return type; - } - - public String getId() { - return id; - } - - public InlineQueryResultCachedAudio setId(String id) { - this.id = id; - return this; - } - - public String getAudioFileId() { - return audioFileId; - } - - public InlineQueryResultCachedAudio setAudioFileId(String audioFileId) { - this.audioFileId = audioFileId; - return this; - } - - public InputMessageContent getInputMessageContent() { - return inputMessageContent; - } - - public InlineQueryResultCachedAudio setInputMessageContent(InputMessageContent inputMessageContent) { - this.inputMessageContent = inputMessageContent; - return this; - } - - public InlineKeyboardMarkup getReplyMarkup() { - return replyMarkup; - } - - public InlineQueryResultCachedAudio setReplyMarkup(InlineKeyboardMarkup replyMarkup) { - this.replyMarkup = replyMarkup; - return this; - } - - public String getCaption() { - return caption; - } - - public InlineQueryResultCachedAudio setCaption(String caption) { - this.caption = caption; - return this; - } - - public String getParseMode() { - return parseMode; - } - - public InlineQueryResultCachedAudio setParseMode(String parseMode) { - this.parseMode = parseMode; - return this; - } - - @Override - public void validate() throws TelegramApiValidationException { - if (id == null || id.isEmpty()) { - throw new TelegramApiValidationException("ID parameter can't be empty", this); - } - if (audioFileId == null || audioFileId.isEmpty()) { - throw new TelegramApiValidationException("AudioFileId parameter can't be empty", this); - } - if (inputMessageContent != null) { - inputMessageContent.validate(); - } - if (replyMarkup != null) { - replyMarkup.validate(); - } - } - - @Override - public String toString() { - return "InlineQueryResultCachedAudio{" + - "type='" + type + '\'' + - ", id='" + id + '\'' + - ", audioFileId='" + audioFileId + '\'' + - ", inputMessageContent=" + inputMessageContent + - ", replyMarkup=" + replyMarkup + - ", caption='" + caption + '\'' + - ", parseMode='" + parseMode + '\'' + - '}'; - } +public class InlineQueryResultCachedAudio extends org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedAudio { } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedDocument.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedDocument.java index fa3549cc..e20809af 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedDocument.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedDocument.java @@ -1,12 +1,5 @@ package org.telegram.telegrambots.meta.api.objects.inlinequery.result.chached; -import com.fasterxml.jackson.annotation.JsonProperty; - -import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent; -import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult; -import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup; -import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; - /** * @author Ruben Bermudez * @version 1.0 @@ -19,148 +12,5 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; * @deprecated Replaced by {@link org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedDocument} */ @Deprecated -public class InlineQueryResultCachedDocument implements InlineQueryResult { - - private static final String TYPE_FIELD = "type"; - private static final String ID_FIELD = "id"; - private static final String TITLE_FIELD = "title"; - private static final String DOCUMENT_FILE_ID_FIELD = "document_file_id"; - private static final String DESCRIPTION_FIELD = "description"; - private static final String CAPTION_FIELD = "caption"; - private static final String REPLY_MARKUP_FIELD = "reply_markup"; - private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content"; - private static final String PARSEMODE_FIELD = "parse_mode"; - - @JsonProperty(TYPE_FIELD) - private final String type = "document"; ///< Type of the result, must be "document" - @JsonProperty(ID_FIELD) - private String id; ///< Unique identifier of this result, 1-64 bytes - @JsonProperty(TITLE_FIELD) - private String title; ///< Optional. Title for the result - @JsonProperty(DOCUMENT_FILE_ID_FIELD) - private String documentFileId; ///< A valid file identifier for the file - @JsonProperty(DESCRIPTION_FIELD) - private String description; ///< Optional. Short description of the result - @JsonProperty(CAPTION_FIELD) - private String caption; ///< Optional. Caption of the document to be sent, 0-200 characters - @JsonProperty(REPLY_MARKUP_FIELD) - private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message - @JsonProperty(INPUTMESSAGECONTENT_FIELD) - private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the file - @JsonProperty(PARSEMODE_FIELD) - private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. - - public InlineQueryResultCachedDocument() { - super(); - } - - public String getType() { - return type; - } - - public String getId() { - return id; - } - - public InlineQueryResultCachedDocument setId(String id) { - this.id = id; - return this; - } - - public String getTitle() { - return title; - } - - public InlineQueryResultCachedDocument setTitle(String title) { - this.title = title; - return this; - } - - public String getDocumentFileId() { - return documentFileId; - } - - public InlineQueryResultCachedDocument setDocumentFileId(String documentFileId) { - this.documentFileId = documentFileId; - return this; - } - - public String getDescription() { - return description; - } - - public InlineQueryResultCachedDocument setDescription(String description) { - this.description = description; - return this; - } - - public String getCaption() { - return caption; - } - - public InlineQueryResultCachedDocument setCaption(String caption) { - this.caption = caption; - return this; - } - - public InlineKeyboardMarkup getReplyMarkup() { - return replyMarkup; - } - - public InlineQueryResultCachedDocument setReplyMarkup(InlineKeyboardMarkup replyMarkup) { - this.replyMarkup = replyMarkup; - return this; - } - - public InputMessageContent getInputMessageContent() { - return inputMessageContent; - } - - public InlineQueryResultCachedDocument setInputMessageContent(InputMessageContent inputMessageContent) { - this.inputMessageContent = inputMessageContent; - return this; - } - - public String getParseMode() { - return parseMode; - } - - public InlineQueryResultCachedDocument setParseMode(String parseMode) { - this.parseMode = parseMode; - return this; - } - - @Override - public void validate() throws TelegramApiValidationException { - if (id == null || id.isEmpty()) { - throw new TelegramApiValidationException("ID parameter can't be empty", this); - } - if (documentFileId == null || documentFileId.isEmpty()) { - throw new TelegramApiValidationException("DocumentFileId parameter can't be empty", this); - } - if (title == null || title.isEmpty()) { - throw new TelegramApiValidationException("Title parameter can't be empty", this); - } - if (inputMessageContent != null) { - inputMessageContent.validate(); - } - if (replyMarkup != null) { - replyMarkup.validate(); - } - } - - @Override - public String toString() { - return "InlineQueryResultCachedDocument{" + - "type='" + type + '\'' + - ", id='" + id + '\'' + - ", title='" + title + '\'' + - ", documentFileId='" + documentFileId + '\'' + - ", description='" + description + '\'' + - ", caption='" + caption + '\'' + - ", replyMarkup=" + replyMarkup + - ", inputMessageContent=" + inputMessageContent + - ", parseMode='" + parseMode + '\'' + - '}'; - } +public class InlineQueryResultCachedDocument extends org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedDocument { } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedGif.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedGif.java index fb484cfd..d5c89e03 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedGif.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedGif.java @@ -1,12 +1,5 @@ package org.telegram.telegrambots.meta.api.objects.inlinequery.result.chached; -import com.fasterxml.jackson.annotation.JsonProperty; - -import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent; -import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult; -import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup; -import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; - /** * @author Ruben Bermudez * @version 1.0 @@ -16,131 +9,5 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; * @deprecated Replaced by {@link org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedGif} */ @Deprecated -public class InlineQueryResultCachedGif implements InlineQueryResult { - private static final String TYPE_FIELD = "type"; - private static final String ID_FIELD = "id"; - private static final String GIF_FILE_ID_FIELD = "gif_file_id"; - private static final String TITLE_FIELD = "title"; - private static final String CAPTION_FIELD = "caption"; - private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content"; - private static final String REPLY_MARKUP_FIELD = "reply_markup"; - private static final String PARSEMODE_FIELD = "parse_mode"; - - @JsonProperty(TYPE_FIELD) - private final String type = "gif"; ///< Type of the result, must be "gif" - @JsonProperty(ID_FIELD) - private String id; ///< Unique identifier of this result, 1-64 bytes - @JsonProperty(GIF_FILE_ID_FIELD) - private String gifFileId; ///< A valid file identifier for the GIF file - @JsonProperty(TITLE_FIELD) - private String title; ///< Optional. Title for the result - @JsonProperty(CAPTION_FIELD) - private String caption; ///< Optional. Caption of the GIF file to be sent - @JsonProperty(INPUTMESSAGECONTENT_FIELD) - private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the GIF animation - @JsonProperty(REPLY_MARKUP_FIELD) - private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message - @JsonProperty(PARSEMODE_FIELD) - private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. - - public InlineQueryResultCachedGif() { - super(); - } - - public String getType() { - return type; - } - - public String getId() { - return id; - } - - public InlineQueryResultCachedGif setId(String id) { - this.id = id; - return this; - } - - public String getGifFileId() { - return gifFileId; - } - - public InlineQueryResultCachedGif setGifFileId(String gifFileId) { - this.gifFileId = gifFileId; - return this; - } - - public String getTitle() { - return title; - } - - public InlineQueryResultCachedGif setTitle(String title) { - this.title = title; - return this; - } - - public String getCaption() { - return caption; - } - - public InlineQueryResultCachedGif setCaption(String caption) { - this.caption = caption; - return this; - } - - public InputMessageContent getInputMessageContent() { - return inputMessageContent; - } - - public InlineQueryResultCachedGif setInputMessageContent(InputMessageContent inputMessageContent) { - this.inputMessageContent = inputMessageContent; - return this; - } - - public InlineKeyboardMarkup getReplyMarkup() { - return replyMarkup; - } - - public InlineQueryResultCachedGif setReplyMarkup(InlineKeyboardMarkup replyMarkup) { - this.replyMarkup = replyMarkup; - return this; - } - - public String getParseMode() { - return parseMode; - } - - public InlineQueryResultCachedGif setParseMode(String parseMode) { - this.parseMode = parseMode; - return this; - } - - @Override - public void validate() throws TelegramApiValidationException { - if (id == null || id.isEmpty()) { - throw new TelegramApiValidationException("ID parameter can't be empty", this); - } - if (gifFileId == null || gifFileId.isEmpty()) { - throw new TelegramApiValidationException("GifFileId parameter can't be empty", this); - } - if (inputMessageContent != null) { - inputMessageContent.validate(); - } - if (replyMarkup != null) { - replyMarkup.validate(); - } - } - - @Override - public String toString() { - return "InlineQueryResultCachedGif{" + - "type='" + type + '\'' + - ", id='" + id + '\'' + - ", gifFileId='" + gifFileId + '\'' + - ", title='" + title + '\'' + - ", caption='" + caption + '\'' + - ", inputMessageContent=" + inputMessageContent + - ", replyMarkup=" + replyMarkup + - ", parseMode='" + parseMode + '\'' + - '}'; - } +public class InlineQueryResultCachedGif extends org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedGif { } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedMpeg4Gif.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedMpeg4Gif.java index 75d9ad78..ff756d70 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedMpeg4Gif.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedMpeg4Gif.java @@ -1,148 +1,13 @@ package org.telegram.telegrambots.meta.api.objects.inlinequery.result.chached; -import com.fasterxml.jackson.annotation.JsonProperty; - -import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent; -import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult; -import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup; -import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; - /** * @author Ruben Bermudez * @version 1.0 - * @brief Represents a link to a video animation (H.264/MPEG-4 AVC video without sound). By default, + * Represents a link to a video animation (H.264/MPEG-4 AVC video without sound). By default, * this animated MPEG-4 file will be sent by the user with optional caption. Alternatively, you can * use input_message_content to send a message with the specified content instead of the animation. - * @date 01 of January of 2016 * @deprecated Replaced by {@link org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedMpeg4Gif} */ @Deprecated -public class InlineQueryResultCachedMpeg4Gif implements InlineQueryResult { - - private static final String TYPE_FIELD = "type"; - private static final String ID_FIELD = "id"; - private static final String MPEG4_FILE_ID_FIELD = "mpeg4_file_id"; - private static final String TITLE_FIELD = "title"; - private static final String CAPTION_FIELD = "caption"; - private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content"; - private static final String REPLY_MARKUP_FIELD = "reply_markup"; - private static final String PARSEMODE_FIELD = "parse_mode"; - - @JsonProperty(TYPE_FIELD) - private final String type = "mpeg4_gif"; ///< Type of the result, must be "mpeg4_gif" - @JsonProperty(ID_FIELD) - private String id; ///< Unique identifier of this result, 1-64 bytes - @JsonProperty(MPEG4_FILE_ID_FIELD) - private String mpeg4FileId; ///< A valid file identifier for the MP4 file - @JsonProperty(TITLE_FIELD) - private String title; ///< Optional. Title for the result - @JsonProperty(CAPTION_FIELD) - private String caption; ///< Optional. Caption of the MPEG-4 file to be sent - @JsonProperty(INPUTMESSAGECONTENT_FIELD) - private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the photo - @JsonProperty(REPLY_MARKUP_FIELD) - private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message - @JsonProperty(PARSEMODE_FIELD) - private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. - - public InlineQueryResultCachedMpeg4Gif() { - super(); - } - - public String getType() { - return type; - } - - public String getId() { - return id; - } - - public InlineQueryResultCachedMpeg4Gif setId(String id) { - this.id = id; - return this; - } - - public String getMpeg4FileId() { - return mpeg4FileId; - } - - public InlineQueryResultCachedMpeg4Gif setMpeg4FileId(String mpeg4FileId) { - this.mpeg4FileId = mpeg4FileId; - return this; - } - - public String getTitle() { - return title; - } - - public InlineQueryResultCachedMpeg4Gif setTitle(String title) { - this.title = title; - return this; - } - - public String getCaption() { - return caption; - } - - public InlineQueryResultCachedMpeg4Gif setCaption(String caption) { - this.caption = caption; - return this; - } - - public InputMessageContent getInputMessageContent() { - return inputMessageContent; - } - - public InlineQueryResultCachedMpeg4Gif setInputMessageContent(InputMessageContent inputMessageContent) { - this.inputMessageContent = inputMessageContent; - return this; - } - - public InlineKeyboardMarkup getReplyMarkup() { - return replyMarkup; - } - - public InlineQueryResultCachedMpeg4Gif setReplyMarkup(InlineKeyboardMarkup replyMarkup) { - this.replyMarkup = replyMarkup; - return this; - } - - public String getParseMode() { - return parseMode; - } - - public InlineQueryResultCachedMpeg4Gif setParseMode(String parseMode) { - this.parseMode = parseMode; - return this; - } - - @Override - public void validate() throws TelegramApiValidationException { - if (id == null || id.isEmpty()) { - throw new TelegramApiValidationException("ID parameter can't be empty", this); - } - if (mpeg4FileId == null || mpeg4FileId.isEmpty()) { - throw new TelegramApiValidationException("Mpeg4FileId parameter can't be empty", this); - } - if (inputMessageContent != null) { - inputMessageContent.validate(); - } - if (replyMarkup != null) { - replyMarkup.validate(); - } - } - - @Override - public String toString() { - return "InlineQueryResultCachedMpeg4Gif{" + - "type='" + type + '\'' + - ", id='" + id + '\'' + - ", mpeg4FileId='" + mpeg4FileId + '\'' + - ", title='" + title + '\'' + - ", caption='" + caption + '\'' + - ", inputMessageContent=" + inputMessageContent + - ", replyMarkup=" + replyMarkup + - ", parseMode='" + parseMode + '\'' + - '}'; - } +public class InlineQueryResultCachedMpeg4Gif extends org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedMpeg4Gif { } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedPhoto.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedPhoto.java index 7aa781c3..50224520 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedPhoto.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedPhoto.java @@ -1,12 +1,5 @@ package org.telegram.telegrambots.meta.api.objects.inlinequery.result.chached; -import com.fasterxml.jackson.annotation.JsonProperty; - -import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent; -import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult; -import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup; -import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; - /** * @author Ruben Bermudez * @version 1.0 @@ -16,144 +9,5 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; * @deprecated Replaced by {@link org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedPhoto} */ @Deprecated -public class InlineQueryResultCachedPhoto implements InlineQueryResult { - private static final String TYPE_FIELD = "type"; - private static final String ID_FIELD = "id"; - private static final String PHOTOFILEID_FIELD = "photo_file_id"; - private static final String TITLE_FIELD = "title"; - private static final String DESCRIPTION_FIELD = "description"; - private static final String CAPTION_FIELD = "caption"; - private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content"; - private static final String REPLY_MARKUP_FIELD = "reply_markup"; - private static final String PARSEMODE_FIELD = "parse_mode"; - - @JsonProperty(TYPE_FIELD) - private final String type = "photo"; ///< Type of the result, must be “photo” - @JsonProperty(ID_FIELD) - private String id; ///< Unique identifier of this result, 1-64 bytes - @JsonProperty(PHOTOFILEID_FIELD) - private String photoFileId; ///< A valid file identifier of the photo - @JsonProperty(TITLE_FIELD) - private String title; ///< Optional. Title for the result - @JsonProperty(DESCRIPTION_FIELD) - private String description; ///< Optional. Short description of the result - @JsonProperty(CAPTION_FIELD) - private String caption; ///< Optional. Caption of the photo to be sent - @JsonProperty(INPUTMESSAGECONTENT_FIELD) - private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the photo - @JsonProperty(REPLY_MARKUP_FIELD) - private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message - @JsonProperty(PARSEMODE_FIELD) - private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. - - public InlineQueryResultCachedPhoto() { - super(); - } - - public String getType() { - return type; - } - - public String getId() { - return id; - } - - public InlineQueryResultCachedPhoto setId(String id) { - this.id = id; - return this; - } - - public String getPhotoFileId() { - return photoFileId; - } - - public InlineQueryResultCachedPhoto setPhotoFileId(String photoFileId) { - this.photoFileId = photoFileId; - return this; - } - - public String getTitle() { - return title; - } - - public InlineQueryResultCachedPhoto setTitle(String title) { - this.title = title; - return this; - } - - public String getDescription() { - return description; - } - - public InlineQueryResultCachedPhoto setDescription(String description) { - this.description = description; - return this; - } - - public String getCaption() { - return caption; - } - - public InlineQueryResultCachedPhoto setCaption(String caption) { - this.caption = caption; - return this; - } - - public InputMessageContent getInputMessageContent() { - return inputMessageContent; - } - - public InlineQueryResultCachedPhoto setInputMessageContent(InputMessageContent inputMessageContent) { - this.inputMessageContent = inputMessageContent; - return this; - } - - public InlineKeyboardMarkup getReplyMarkup() { - return replyMarkup; - } - - public InlineQueryResultCachedPhoto setReplyMarkup(InlineKeyboardMarkup replyMarkup) { - this.replyMarkup = replyMarkup; - return this; - } - - public String getParseMode() { - return parseMode; - } - - public InlineQueryResultCachedPhoto setParseMode(String parseMode) { - this.parseMode = parseMode; - return this; - } - - @Override - public void validate() throws TelegramApiValidationException { - if (id == null || id.isEmpty()) { - throw new TelegramApiValidationException("ID parameter can't be empty", this); - } - if (photoFileId == null || photoFileId.isEmpty()) { - throw new TelegramApiValidationException("PhotoFileId parameter can't be empty", this); - } - if (inputMessageContent != null) { - inputMessageContent.validate(); - } - if (replyMarkup != null) { - replyMarkup.validate(); - } - } - - @Override - public String toString() { - return "InlineQueryResultCachedPhoto{" + - "type='" + type + '\'' + - ", id='" + id + '\'' + - ", photoFileId='" + photoFileId + '\'' + - ", title='" + title + '\'' + - ", description='" + description + '\'' + - ", caption='" + caption + '\'' + - ", inputMessageContent=" + inputMessageContent + - ", replyMarkup=" + replyMarkup + - ", parseMode='" + parseMode + '\'' + - '}'; - } +public class InlineQueryResultCachedPhoto extends org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedPhoto { } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedSticker.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedSticker.java index 586651c8..299b5280 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedSticker.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedSticker.java @@ -1,111 +1,16 @@ package org.telegram.telegrambots.meta.api.objects.inlinequery.result.chached; -import com.fasterxml.jackson.annotation.JsonProperty; - -import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent; -import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult; -import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup; -import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; - /** * @author Ruben Bermudez * @version 1.0 - * @brief Represents a link to a sticker stored on the Telegram servers. By default, this sticker + * Represents a link to a sticker stored on the Telegram servers. By default, this sticker * will be sent by the user. Alternatively, you can use input_message_content to send a message with * the specified content instead of the sticker. * @note This will only work in Telegram versions released after 9 April, 2016. Older clients will * ignore them. - * @date 10 of April of 2016 * @deprecated Replaced by {@link org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedSticker} */ @Deprecated -public class InlineQueryResultCachedSticker implements InlineQueryResult { +public class InlineQueryResultCachedSticker extends org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedSticker { - private static final String TYPE_FIELD = "type"; - private static final String ID_FIELD = "id"; - private static final String STICKER_FILE_ID_FIELD = "sticker_file_id"; - private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content"; - private static final String REPLY_MARKUP_FIELD = "reply_markup"; - - @JsonProperty(TYPE_FIELD) - private final String type = "sticker"; ///< Type of the result, must be "sticker" - @JsonProperty(ID_FIELD) - private String id; ///< Unique identifier of this result, 1-64 bytes - @JsonProperty(STICKER_FILE_ID_FIELD) - private String stickerFileId; ///< A valid file identifier of the sticker - @JsonProperty(INPUTMESSAGECONTENT_FIELD) - private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the sticker - @JsonProperty(REPLY_MARKUP_FIELD) - private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message - - public InlineQueryResultCachedSticker() { - super(); - } - - public String getType() { - return type; - } - - public String getId() { - return id; - } - - public InlineQueryResultCachedSticker setId(String id) { - this.id = id; - return this; - } - - public String getStickerFileId() { - return stickerFileId; - } - - public InlineQueryResultCachedSticker setStickerFileId(String stickerFileId) { - this.stickerFileId = stickerFileId; - return this; - } - - public InputMessageContent getInputMessageContent() { - return inputMessageContent; - } - - public InlineQueryResultCachedSticker setInputMessageContent(InputMessageContent inputMessageContent) { - this.inputMessageContent = inputMessageContent; - return this; - } - - public InlineKeyboardMarkup getReplyMarkup() { - return replyMarkup; - } - - public InlineQueryResultCachedSticker setReplyMarkup(InlineKeyboardMarkup replyMarkup) { - this.replyMarkup = replyMarkup; - return this; - } - - @Override - public void validate() throws TelegramApiValidationException { - if (id == null || id.isEmpty()) { - throw new TelegramApiValidationException("ID parameter can't be empty", this); - } - if (stickerFileId == null || stickerFileId.isEmpty()) { - throw new TelegramApiValidationException("StickerFileId parameter can't be empty", this); - } - if (inputMessageContent != null) { - inputMessageContent.validate(); - } - if (replyMarkup != null) { - replyMarkup.validate(); - } - } - - @Override - public String toString() { - return "InlineQueryResultCachedSticker{" + - "type='" + type + '\'' + - ", id='" + id + '\'' + - ", sticker_file_id='" + stickerFileId + '\'' + - ", inputMessageContent='" + inputMessageContent + '\'' + - ", replyMarkup='" + replyMarkup + '\'' + - '}'; - } } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedVideo.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedVideo.java index 890f4422..6bde7323 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedVideo.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedVideo.java @@ -1,12 +1,5 @@ package org.telegram.telegrambots.meta.api.objects.inlinequery.result.chached; -import com.fasterxml.jackson.annotation.JsonProperty; - -import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent; -import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult; -import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup; -import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; - /** * @author Ruben Bermudez * @version 1.0 @@ -16,144 +9,5 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; * @deprecated Replaced by {@link org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedVideo} */ @Deprecated -public class InlineQueryResultCachedVideo implements InlineQueryResult { - private static final String TYPE_FIELD = "type"; - private static final String ID_FIELD = "id"; - private static final String VIDEO_FILE_ID_FIELD = "video_file_id"; - private static final String TITLE_FIELD = "title"; - private static final String DESCRIPTION_FIELD = "description"; - private static final String CAPTION_FIELD = "caption"; - private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content"; - private static final String REPLY_MARKUP_FIELD = "reply_markup"; - private static final String PARSEMODE_FIELD = "parse_mode"; - - @JsonProperty(TYPE_FIELD) - private final String type = "video"; ///< Type of the result, must be "video" - @JsonProperty(ID_FIELD) - private String id; ///< Unique identifier of this result - @JsonProperty(VIDEO_FILE_ID_FIELD) - private String videoFileId; ///< A valid file identifier for the video file - @JsonProperty(TITLE_FIELD) - private String title; ///< Optional. Title for the result - @JsonProperty(DESCRIPTION_FIELD) - private String description; ///< Optional. Short description of the result - @JsonProperty(CAPTION_FIELD) - private String caption; ///< Optional. Caption of the video to be sent, 0-200 characters - @JsonProperty(INPUTMESSAGECONTENT_FIELD) - private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the photo - @JsonProperty(REPLY_MARKUP_FIELD) - private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message - @JsonProperty(PARSEMODE_FIELD) - private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. - - public InlineQueryResultCachedVideo() { - super(); - } - - public String getType() { - return type; - } - - public String getId() { - return id; - } - - public InlineQueryResultCachedVideo setId(String id) { - this.id = id; - return this; - } - - public String getVideoFileId() { - return videoFileId; - } - - public InlineQueryResultCachedVideo setVideoFileId(String videoFileId) { - this.videoFileId = videoFileId; - return this; - } - - public String getTitle() { - return title; - } - - public InlineQueryResultCachedVideo setTitle(String title) { - this.title = title; - return this; - } - - public String getDescription() { - return description; - } - - public InlineQueryResultCachedVideo setDescription(String description) { - this.description = description; - return this; - } - - public String getCaption() { - return caption; - } - - public InlineQueryResultCachedVideo setCaption(String caption) { - this.caption = caption; - return this; - } - - public InputMessageContent getInputMessageContent() { - return inputMessageContent; - } - - public InlineQueryResultCachedVideo setInputMessageContent(InputMessageContent inputMessageContent) { - this.inputMessageContent = inputMessageContent; - return this; - } - - public InlineKeyboardMarkup getReplyMarkup() { - return replyMarkup; - } - - public InlineQueryResultCachedVideo setReplyMarkup(InlineKeyboardMarkup replyMarkup) { - this.replyMarkup = replyMarkup; - return this; - } - - public String getParseMode() { - return parseMode; - } - - public InlineQueryResultCachedVideo setParseMode(String parseMode) { - this.parseMode = parseMode; - return this; - } - - @Override - public void validate() throws TelegramApiValidationException { - if (id == null || id.isEmpty()) { - throw new TelegramApiValidationException("ID parameter can't be empty", this); - } - if (videoFileId == null || videoFileId.isEmpty()) { - throw new TelegramApiValidationException("VideoFileId parameter can't be empty", this); - } - if (inputMessageContent != null) { - inputMessageContent.validate(); - } - if (replyMarkup != null) { - replyMarkup.validate(); - } - } - - @Override - public String toString() { - return "InlineQueryResultCachedVideo{" + - "type='" + type + '\'' + - ", id='" + id + '\'' + - ", videoFileId='" + videoFileId + '\'' + - ", title='" + title + '\'' + - ", description='" + description + '\'' + - ", caption='" + caption + '\'' + - ", inputMessageContent=" + inputMessageContent + - ", replyMarkup=" + replyMarkup + - ", parseMode='" + parseMode + '\'' + - '}'; - } +public class InlineQueryResultCachedVideo extends org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedVideo { } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedVoice.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedVoice.java index c8f9a7c9..b53ade0d 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedVoice.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/inlinequery/result/chached/InlineQueryResultCachedVoice.java @@ -1,12 +1,5 @@ package org.telegram.telegrambots.meta.api.objects.inlinequery.result.chached; -import com.fasterxml.jackson.annotation.JsonProperty; - -import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent; -import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult; -import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup; -import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; - /** * @author Ruben Bermudez * @version 1.0 @@ -18,131 +11,5 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; * @deprecated Replaced by {@link org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedVoice} */ @Deprecated -public class InlineQueryResultCachedVoice implements InlineQueryResult { - private static final String TYPE_FIELD = "type"; - private static final String ID_FIELD = "id"; - private static final String VOICE_FILE_ID_FIELD = "voice_file_id"; - private static final String TITLE_FIELD = "title"; - private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content"; - private static final String REPLY_MARKUP_FIELD = "reply_markup"; - private static final String CAPTION_FIELD = "caption"; - private static final String PARSEMODE_FIELD = "parse_mode"; - - @JsonProperty(TYPE_FIELD) - private final String type = "voice"; ///< Type of the result, must be "voice" - @JsonProperty(ID_FIELD) - private String id; ///< Unique identifier of this result, 1-64 bytes - @JsonProperty(VOICE_FILE_ID_FIELD) - private String voiceFileId; ///< A valid file identifier for the voice message - @JsonProperty(TITLE_FIELD) - private String title; ///< Recording title - @JsonProperty(INPUTMESSAGECONTENT_FIELD) - private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the voice recording - @JsonProperty(REPLY_MARKUP_FIELD) - private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message - @JsonProperty(CAPTION_FIELD) - private String caption; ///< Optional. Voice caption (may also be used when resending documents by file_id), 0-200 characters - @JsonProperty(PARSEMODE_FIELD) - private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. - - public InlineQueryResultCachedVoice() { - super(); - } - - public String getType() { - return type; - } - - public String getId() { - return id; - } - - public InlineQueryResultCachedVoice setId(String id) { - this.id = id; - return this; - } - - public String getVoiceFileId() { - return voiceFileId; - } - - public InlineQueryResultCachedVoice setVoiceFileId(String voiceFileId) { - this.voiceFileId = voiceFileId; - return this; - } - - public String getTitle() { - return title; - } - - public InlineQueryResultCachedVoice setTitle(String title) { - this.title = title; - return this; - } - - public InputMessageContent getInputMessageContent() { - return inputMessageContent; - } - - public InlineQueryResultCachedVoice setInputMessageContent(InputMessageContent inputMessageContent) { - this.inputMessageContent = inputMessageContent; - return this; - } - - public InlineKeyboardMarkup getReplyMarkup() { - return replyMarkup; - } - - public InlineQueryResultCachedVoice setReplyMarkup(InlineKeyboardMarkup replyMarkup) { - this.replyMarkup = replyMarkup; - return this; - } - - public String getCaption() { - return caption; - } - - public InlineQueryResultCachedVoice setCaption(String caption) { - this.caption = caption; - return this; - } - - public String getParseMode() { - return parseMode; - } - - public InlineQueryResultCachedVoice setParseMode(String parseMode) { - this.parseMode = parseMode; - return this; - } - - @Override - public void validate() throws TelegramApiValidationException { - if (id == null || id.isEmpty()) { - throw new TelegramApiValidationException("ID parameter can't be empty", this); - } - if (voiceFileId == null || voiceFileId.isEmpty()) { - throw new TelegramApiValidationException("VoiceFileId parameter can't be empty", this); - } - if (inputMessageContent != null) { - inputMessageContent.validate(); - } - if (replyMarkup != null) { - replyMarkup.validate(); - } - } - - @Override - public String toString() { - return "InlineQueryResultCachedVoice{" + - "type='" + type + '\'' + - ", id='" + id + '\'' + - ", voiceFileId='" + voiceFileId + '\'' + - ", title='" + title + '\'' + - ", inputMessageContent=" + inputMessageContent + - ", replyMarkup=" + replyMarkup + - ", caption='" + caption + '\'' + - ", parseMode='" + parseMode + '\'' + - '}'; - } +public class InlineQueryResultCachedVoice extends org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedVoice { } From 293d903083bd74894e2a255214e83159071a1dd0 Mon Sep 17 00:00:00 2001 From: Ruben Bermudez Date: Wed, 2 Jan 2019 15:56:45 +0100 Subject: [PATCH 30/37] Fix #563 --- .../main/java/org/telegram/telegrambots/util/WebhookUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/util/WebhookUtils.java b/telegrambots/src/main/java/org/telegram/telegrambots/util/WebhookUtils.java index 9d59fc7a..7db6f898 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/util/WebhookUtils.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/util/WebhookUtils.java @@ -53,7 +53,7 @@ public final class WebhookUtils { } HttpEntity multipart = builder.build(); httppost.setEntity(multipart); - try (CloseableHttpResponse response = httpclient.execute(httppost)) { + try (CloseableHttpResponse response = httpclient.execute(httppost, botOptions.getHttpContext())) { HttpEntity ht = response.getEntity(); BufferedHttpEntity buf = new BufferedHttpEntity(ht); String responseContent = EntityUtils.toString(buf, StandardCharsets.UTF_8); From e203abfab5301c59cb5b062a73c33fd8408e41c5 Mon Sep 17 00:00:00 2001 From: Rubenlagus Date: Wed, 2 Jan 2019 16:12:05 +0100 Subject: [PATCH 31/37] Update versions --- README.md | 8 ++++---- TelegramBots.wiki/Getting-Started.md | 4 ++-- TelegramBots.wiki/abilities/Simple-Example.md | 4 ++-- pom.xml | 3 +-- telegrambots-abilities/README.md | 8 ++++---- telegrambots-abilities/pom.xml | 5 ++--- telegrambots-chat-session-bot/README.md | 2 +- telegrambots-chat-session-bot/pom.xml | 5 ++--- telegrambots-extensions/README.md | 4 ++-- telegrambots-extensions/pom.xml | 5 ++--- telegrambots-meta/pom.xml | 2 +- telegrambots-spring-boot-starter/README.md | 4 ++-- telegrambots-spring-boot-starter/pom.xml | 5 ++--- telegrambots/pom.xml | 5 ++--- 14 files changed, 29 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index f7a862cd..df19c26d 100644 --- a/README.md +++ b/README.md @@ -27,16 +27,16 @@ Just import add the library to your project with one of these options: org.telegram telegrambots - 4.1 + 4.1.1 ``` ```gradle - compile "org.telegram:telegrambots:4.1" + compile "org.telegram:telegrambots:4.1.1" ``` - 2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/4.1) - 3. Download the jar(including all dependencies) from [here](https://github.com/rubenlagus/TelegramBots/releases/tag/v4.1) + 2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/4.1.1) + 3. Download the jar(including all dependencies) from [here](https://github.com/rubenlagus/TelegramBots/releases/tag/v4.1.1) In order to use Long Polling mode, just create your own bot extending `org.telegram.telegrambots.bots.TelegramLongPollingBot`. diff --git a/TelegramBots.wiki/Getting-Started.md b/TelegramBots.wiki/Getting-Started.md index 2bea5d5d..9b5e132a 100644 --- a/TelegramBots.wiki/Getting-Started.md +++ b/TelegramBots.wiki/Getting-Started.md @@ -11,13 +11,13 @@ First you need ot get the library and add it to your project. There are few poss org.telegram telegrambots - 4.1 + 4.1.1 ``` * With **Gradle**: ```groovy - compile group: 'org.telegram', name: 'telegrambots', version: '4.1' + compile group: 'org.telegram', name: 'telegrambots', version: '4.1.1' ``` 2. Don't like **Maven Central Repository**? It can also be taken from [Jitpack](https://jitpack.io/#rubenlagus/TelegramBots). diff --git a/TelegramBots.wiki/abilities/Simple-Example.md b/TelegramBots.wiki/abilities/Simple-Example.md index a05dddc6..800d1b7c 100644 --- a/TelegramBots.wiki/abilities/Simple-Example.md +++ b/TelegramBots.wiki/abilities/Simple-Example.md @@ -9,12 +9,12 @@ As with any Java project, you will need to set your dependencies. org.telegram telegrambots-abilities - 4.1 + 4.1.1 ``` * **Gradle** ```groovy - compile group: 'org.telegram', name: 'telegrambots-abilties', version: '4.1' + compile group: 'org.telegram', name: 'telegrambots-abilties', version: '4.1.1' ``` * [JitPack](https://jitpack.io/#rubenlagus/TelegramBots) diff --git a/pom.xml b/pom.xml index b6176008..f1c491ae 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots pom - 4.1 + 4.1.1 telegrambots @@ -28,6 +28,5 @@ true - 4.1 \ No newline at end of file diff --git a/telegrambots-abilities/README.md b/telegrambots-abilities/README.md index 22f0dbd7..0e3bb90f 100644 --- a/telegrambots-abilities/README.md +++ b/telegrambots-abilities/README.md @@ -18,19 +18,19 @@ Usage org.telegram telegrambots-abilities - 4.1 + 4.1.1 ``` **Gradle** ```gradle - compile "org.telegram:telegrambots-abilities:4.1" + compile "org.telegram:telegrambots-abilities:4.1.1" ``` -**JitPack** - [JitPack](https://jitpack.io/#rubenlagus/TelegramBots/v4.1) +**JitPack** - [JitPack](https://jitpack.io/#rubenlagus/TelegramBots/v4.1.1) -**Plain imports** - [Here](https://github.com/rubenlagus/TelegramBots/releases/tag/v4.1) +**Plain imports** - [Here](https://github.com/rubenlagus/TelegramBots/releases/tag/v4.1.1) Motivation ---------- diff --git a/telegrambots-abilities/pom.xml b/telegrambots-abilities/pom.xml index 3f83756e..b9c00fcc 100644 --- a/telegrambots-abilities/pom.xml +++ b/telegrambots-abilities/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.telegram telegrambots-abilities - 4.1 + ${parent.version} jar Telegram Ability Bot @@ -65,7 +65,6 @@ UTF-8 UTF-8 - 4.1 3.5 3.0.4 27.0.1-jre @@ -75,7 +74,7 @@ org.telegram telegrambots - ${bots.version} + ${parent.version} org.apache.commons diff --git a/telegrambots-chat-session-bot/README.md b/telegrambots-chat-session-bot/README.md index bbb7ec45..71b3e80a 100644 --- a/telegrambots-chat-session-bot/README.md +++ b/telegrambots-chat-session-bot/README.md @@ -15,7 +15,7 @@ Usage org.telegram telegrambots-chat-session-bot - 4.1 + 4.1.1 ``` diff --git a/telegrambots-chat-session-bot/pom.xml b/telegrambots-chat-session-bot/pom.xml index 3ce170a9..508588b2 100644 --- a/telegrambots-chat-session-bot/pom.xml +++ b/telegrambots-chat-session-bot/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.telegram telegrambots-chat-session-bot - 4.1 + ${parent.version} jar Telegram Bots Chat Session Bot @@ -65,7 +65,6 @@ UTF-8 UTF-8 - 4.1 1.4.0 @@ -74,7 +73,7 @@ org.telegram telegrambots - ${bots.version} + ${parent.version} diff --git a/telegrambots-extensions/README.md b/telegrambots-extensions/README.md index 02984f67..2eb943d9 100644 --- a/telegrambots-extensions/README.md +++ b/telegrambots-extensions/README.md @@ -16,12 +16,12 @@ Just import add the library to your project with one of these options: org.telegram telegrambotsextensions - 4.1 + 4.1.1 ``` 2. Using Gradle: ```gradle - compile "org.telegram:telegrambotsextensions:4.1" + compile "org.telegram:telegrambotsextensions:4.1.1" ``` \ No newline at end of file diff --git a/telegrambots-extensions/pom.xml b/telegrambots-extensions/pom.xml index ed11f08b..f6bb1b1c 100644 --- a/telegrambots-extensions/pom.xml +++ b/telegrambots-extensions/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.telegram telegrambotsextensions - 4.1 + ${parent.version} jar Telegram Bots Extensions @@ -59,14 +59,13 @@ UTF-8 UTF-8 - 4.1 org.telegram telegrambots - ${bots.version} + ${parent.version} diff --git a/telegrambots-meta/pom.xml b/telegrambots-meta/pom.xml index 63fa43f5..7e492e88 100644 --- a/telegrambots-meta/pom.xml +++ b/telegrambots-meta/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.telegram telegrambots-meta - 4.1 + ${parent.version} jar Telegram Bots Meta diff --git a/telegrambots-spring-boot-starter/README.md b/telegrambots-spring-boot-starter/README.md index 58e05081..0d11e128 100644 --- a/telegrambots-spring-boot-starter/README.md +++ b/telegrambots-spring-boot-starter/README.md @@ -18,14 +18,14 @@ Usage org.telegram telegrambots-spring-boot-starter - 4.1 + 4.1.1 ``` **Gradle** ```gradle - compile "org.telegram:telegrambots-spring-boot-starter:4.1" + compile "org.telegram:telegrambots-spring-boot-starter:4.1.1" ``` Motivation diff --git a/telegrambots-spring-boot-starter/pom.xml b/telegrambots-spring-boot-starter/pom.xml index d4060688..a8e7023e 100644 --- a/telegrambots-spring-boot-starter/pom.xml +++ b/telegrambots-spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.telegram telegrambots-spring-boot-starter - 4.1 + ${parent.version} jar Telegram Bots Spring Boot Starter @@ -59,7 +59,6 @@ UTF-8 UTF-8 - 4.1 2.0.2.RELEASE @@ -68,7 +67,7 @@ org.telegram telegrambots - ${bots.version} + ${parent.version} org.springframework.boot diff --git a/telegrambots/pom.xml b/telegrambots/pom.xml index 72eaa4e9..956a2131 100644 --- a/telegrambots/pom.xml +++ b/telegrambots/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.telegram telegrambots - 4.1 + ${parent.version} jar Telegram Bots @@ -66,7 +66,6 @@ 2.9.7 2.9.0 2.5 - 4.1 @@ -85,7 +84,7 @@ org.telegram telegrambots-meta - ${bots.version} + ${parent.version} com.fasterxml.jackson.core From f998cc2509af6ded54f3e44e58e3ceb0103fa5fa Mon Sep 17 00:00:00 2001 From: Rubenlagus Date: Wed, 2 Jan 2019 16:19:43 +0100 Subject: [PATCH 32/37] Update versions --- telegrambots-abilities/pom.xml | 4 ++-- telegrambots-chat-session-bot/pom.xml | 4 ++-- telegrambots-extensions/pom.xml | 4 ++-- telegrambots-meta/pom.xml | 2 +- telegrambots-spring-boot-starter/pom.xml | 4 ++-- telegrambots/pom.xml | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/telegrambots-abilities/pom.xml b/telegrambots-abilities/pom.xml index b9c00fcc..9ed5f523 100644 --- a/telegrambots-abilities/pom.xml +++ b/telegrambots-abilities/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.telegram telegrambots-abilities - ${parent.version} + 4.1.1 jar Telegram Ability Bot @@ -74,7 +74,7 @@ org.telegram telegrambots - ${parent.version} + 4.1.1 org.apache.commons diff --git a/telegrambots-chat-session-bot/pom.xml b/telegrambots-chat-session-bot/pom.xml index 508588b2..fafdc4f0 100644 --- a/telegrambots-chat-session-bot/pom.xml +++ b/telegrambots-chat-session-bot/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.telegram telegrambots-chat-session-bot - ${parent.version} + 4.1.1 jar Telegram Bots Chat Session Bot @@ -73,7 +73,7 @@ org.telegram telegrambots - ${parent.version} + 4.1.1 diff --git a/telegrambots-extensions/pom.xml b/telegrambots-extensions/pom.xml index f6bb1b1c..979c0b48 100644 --- a/telegrambots-extensions/pom.xml +++ b/telegrambots-extensions/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.telegram telegrambotsextensions - ${parent.version} + 4.1.1 jar Telegram Bots Extensions @@ -65,7 +65,7 @@ org.telegram telegrambots - ${parent.version} + 4.1.1 diff --git a/telegrambots-meta/pom.xml b/telegrambots-meta/pom.xml index 7e492e88..28f2baa6 100644 --- a/telegrambots-meta/pom.xml +++ b/telegrambots-meta/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.telegram telegrambots-meta - ${parent.version} + 4.1.1 jar Telegram Bots Meta diff --git a/telegrambots-spring-boot-starter/pom.xml b/telegrambots-spring-boot-starter/pom.xml index a8e7023e..48bd5a26 100644 --- a/telegrambots-spring-boot-starter/pom.xml +++ b/telegrambots-spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.telegram telegrambots-spring-boot-starter - ${parent.version} + 4.1.1 jar Telegram Bots Spring Boot Starter @@ -67,7 +67,7 @@ org.telegram telegrambots - ${parent.version} + 4.1.1 org.springframework.boot diff --git a/telegrambots/pom.xml b/telegrambots/pom.xml index 956a2131..32b05ecc 100644 --- a/telegrambots/pom.xml +++ b/telegrambots/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.telegram telegrambots - ${parent.version} + 4.1.1 jar Telegram Bots @@ -84,7 +84,7 @@ org.telegram telegrambots-meta - ${parent.version} + 4.1.1 com.fasterxml.jackson.core From 2f05976d0a3ec78c3ab56227dd4c0f76df91a78b Mon Sep 17 00:00:00 2001 From: Abbas Abou Daya Date: Thu, 3 Jan 2019 05:46:09 +0200 Subject: [PATCH 33/37] Consolidated ExtensionTest objects and minor refactoring --- .../abilitybots/api/bot/BaseAbilityBot.java | 48 +++++++------ .../api/bot/AbilityBotExtension.java | 26 ------- .../abilitybots/api/bot/ExtensionTest.java | 67 +++++++++++++++++-- .../api/bot/ExtensionUsingBot.java | 41 ------------ 4 files changed, 89 insertions(+), 93 deletions(-) delete mode 100644 telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotExtension.java delete mode 100644 telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/ExtensionUsingBot.java diff --git a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/BaseAbilityBot.java b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/BaseAbilityBot.java index 9f499a4e..301f2eab 100644 --- a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/BaseAbilityBot.java +++ b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/BaseAbilityBot.java @@ -16,17 +16,17 @@ import org.telegram.abilitybots.api.util.AbilityExtension; import org.telegram.abilitybots.api.util.AbilityUtils; import org.telegram.abilitybots.api.util.Pair; import org.telegram.abilitybots.api.util.Trio; +import org.telegram.telegrambots.bots.DefaultAbsSender; +import org.telegram.telegrambots.bots.DefaultBotOptions; +import org.telegram.telegrambots.bots.TelegramLongPollingBot; import org.telegram.telegrambots.meta.api.methods.GetFile; import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatAdministrators; import org.telegram.telegrambots.meta.api.methods.send.SendDocument; 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.bots.DefaultAbsSender; -import org.telegram.telegrambots.bots.DefaultBotOptions; -import org.telegram.telegrambots.bots.TelegramLongPollingBot; import org.telegram.telegrambots.meta.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.logging.BotLogger; -import org.telegram.telegrambots.meta.api.objects.Update; import java.io.File; import java.io.FileNotFoundException; @@ -614,30 +614,37 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability */ private void registerAbilities() { try { - Listextensions = stream(this.getClass().getMethods()) - .filter(checkReturnType(AbilityExtension.class)) - .map(this.returnExtension(this)) - .collect(Collectors.toList()); + // Collect all classes that implement AbilityExtension declared in the bot + List extensions = stream(getClass().getMethods()) + .filter(checkReturnType(AbilityExtension.class)) + .map(returnExtension(this)) + .collect(Collectors.toList()); + // Add the bot itself as it is an AbilityExtension extensions.add(this); + // Extract all abilities from every single extension instance abilities = extensions.stream() .flatMap(ext -> stream(ext.getClass().getMethods()) .filter(checkReturnType(Ability.class)) - .map(this.returnAbility(ext))) + .map(returnAbility(ext))) + // Abilities are immutable, build it respectively .collect(ImmutableMap::builder, (b, a) -> b.put(a.name(), a), (b1, b2) -> b1.putAll(b2.build())) .build(); + // Extract all replies from every single extension instance Stream extensionReplies = extensions.stream() - .flatMap(ext -> stream(ext.getClass().getMethods()) - .filter(checkReturnType(Reply.class)) - .map(this.returnReply(ext))); + .flatMap(ext -> stream(ext.getClass().getMethods()) + .filter(checkReturnType(Reply.class)) + .map(returnReply(ext))); + // Replies can be standalone or attached to abilities, fetch those too Stream abilityReplies = abilities.values().stream() .flatMap(ability -> ability.replies().stream()); + // Now create the replies registry (list) replies = Stream.concat(abilityReplies, extensionReplies).collect( ImmutableList::builder, Builder::add, @@ -647,16 +654,18 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability BotLogger.error(TAG, "Duplicate names found while registering abilities. Make sure that the abilities declared don't clash with the reserved ones.", e); throw propagate(e); } - } + /** + * @param clazz the type to be tested + * @return a predicate testing the return type of the method corresponding to the class parameter + */ private Predicate checkReturnType(Class clazz) { return method -> clazz.isAssignableFrom(method.getReturnType()); } - /** - * Invokes the method curried and retrieves its return {@link Reply}. + * Invokes the method and retrieves its return {@link Reply}. * * @param obj an bot or extension that this method is invoked with * @return a {@link Function} which returns the {@link Reply} returned by the given method @@ -666,13 +675,14 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability try { return (AbilityExtension) method.invoke(obj); } catch (IllegalAccessException | InvocationTargetException e) { - BotLogger.error("Could not add ability", TAG, e); + BotLogger.error("Could not add ability extension", TAG, e); throw propagate(e); } }; } + /** - * Invokes the method curried and retrieves its return {@link Ability}. + * Invokes the method and retrieves its return {@link Ability}. * * @param obj an bot or extension that this method is invoked with * @return a {@link Function} which returns the {@link Ability} returned by the given method @@ -689,7 +699,7 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability } /** - * Invokes the method curried and retrieves its return {@link Reply}. + * Invokes the method and retrieves its return {@link Reply}. * * @param obj an bot or extension that this method is invoked with * @return a {@link Function} which returns the {@link Reply} returned by the given method @@ -699,7 +709,7 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability try { return (Reply) method.invoke(obj); } catch (IllegalAccessException | InvocationTargetException e) { - BotLogger.error("Could not add ability", TAG, e); + BotLogger.error("Could not add reply", TAG, e); throw propagate(e); } }; diff --git a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotExtension.java b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotExtension.java deleted file mode 100644 index b0a1ccef..00000000 --- a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotExtension.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.telegram.abilitybots.api.bot; - -import org.telegram.abilitybots.api.objects.Ability; -import org.telegram.abilitybots.api.util.AbilityExtension; - -import static org.telegram.abilitybots.api.objects.Locality.ALL; -import static org.telegram.abilitybots.api.objects.Privacy.PUBLIC; - -public class AbilityBotExtension implements AbilityExtension { - private String name; - - public AbilityBotExtension(String name) { - this.name = name; - } - - public Ability abc() { - return Ability.builder() - .name(this.name + "0abc") - .info("Test ability") - .locality(ALL) - .privacy(PUBLIC) - .action(messageContext -> { - }) - .build(); - } -} diff --git a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/ExtensionTest.java b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/ExtensionTest.java index bf6d3633..43bb8da5 100644 --- a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/ExtensionTest.java +++ b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/ExtensionTest.java @@ -4,8 +4,14 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.telegram.abilitybots.api.objects.Ability; +import org.telegram.abilitybots.api.util.AbilityExtension; + +import java.io.IOException; import static junit.framework.TestCase.assertTrue; +import static org.telegram.abilitybots.api.db.MapDBContext.offlineInstance; +import static org.telegram.abilitybots.api.objects.Locality.ALL; +import static org.telegram.abilitybots.api.objects.Privacy.PUBLIC; public class ExtensionTest { private ExtensionUsingBot bot; @@ -15,12 +21,6 @@ public class ExtensionTest { bot = new ExtensionUsingBot(); } - @After - public void teardown() { - bot = null; - } - - @Test public void methodReturningAbilities() { assertTrue("Failed to find Ability in directly declared in root extension/bot", hasAbilityNamed("direct")); @@ -28,9 +28,62 @@ public class ExtensionTest { assertTrue("Failed to find Ability in directly declared in extension returned by method returning the AbilityExtension subclass", hasAbilityNamed("returningSubClass0abc")); } + @After + public void tearDown() throws IOException { + bot.db.clear(); + bot.db.close(); + } + private boolean hasAbilityNamed(String name) { return bot.abilities().values().stream().map(Ability::name).anyMatch(name::equals); } + public static class ExtensionUsingBot extends AbilityBot { + public ExtensionUsingBot() { + super("", "", offlineInstance("testing")); + } -} + @Override + public int creatorId() { + return 0; + } + + public AbilityBotExtension methodReturningExtensionSubClass() { + return new AbilityBotExtension("returningSubClass"); + } + + public AbilityExtension methodReturningExtensionSuperClass() { + return new AbilityBotExtension("returningSuperClass"); + } + + public Ability methodReturningAbility() { + return Ability.builder() + .name("direct") + .info("Test ability") + .locality(ALL) + .privacy(PUBLIC) + .action(messageContext -> { + }) + .build(); + } + } + + public static class AbilityBotExtension implements AbilityExtension { + private String name; + + public AbilityBotExtension(String name) { + this.name = name; + } + + public Ability abc() { + return Ability.builder() + .name(name + "0abc") + .info("Test ability") + .locality(ALL) + .privacy(PUBLIC) + .action(ctx -> { + }) + .build(); + } + } +} \ No newline at end of file diff --git a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/ExtensionUsingBot.java b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/ExtensionUsingBot.java deleted file mode 100644 index 4cb593e7..00000000 --- a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/ExtensionUsingBot.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.telegram.abilitybots.api.bot; - -import org.telegram.abilitybots.api.objects.Ability; -import org.telegram.abilitybots.api.util.AbilityExtension; - -import static org.telegram.abilitybots.api.db.MapDBContext.offlineInstance; -import static org.telegram.abilitybots.api.objects.Locality.ALL; -import static org.telegram.abilitybots.api.objects.Privacy.PUBLIC; - -public class ExtensionUsingBot extends AbilityBot { - public ExtensionUsingBot() { - super("", "", offlineInstance("testing")); - } - - - @Override - public int creatorId() { - return 0; - } - - public AbilityBotExtension methodReturningExtensionSubClass() { - return new AbilityBotExtension("returningSubClass"); - } - - public AbilityExtension methodReturningExtensionSuperClass() { - return new AbilityBotExtension("returningSuperClass"); - } - - public Ability methodReturningAbility() { - return Ability.builder() - .name("direct") - .info("Test ability") - .locality(ALL) - .privacy(PUBLIC) - .action(messageContext -> { - }) - .build(); - } - - -} From fed36f60f80a6e7d3a04d4e7d2ac1a8353956910 Mon Sep 17 00:00:00 2001 From: Abbas Abou Daya Date: Thu, 3 Jan 2019 06:09:55 +0200 Subject: [PATCH 34/37] Added additional examples section for AbillityBot wiki, addresses #482 --- TelegramBots.wiki/abilities/Additional-Examples.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 TelegramBots.wiki/abilities/Additional-Examples.md diff --git a/TelegramBots.wiki/abilities/Additional-Examples.md b/TelegramBots.wiki/abilities/Additional-Examples.md new file mode 100644 index 00000000..786bfbff --- /dev/null +++ b/TelegramBots.wiki/abilities/Additional-Examples.md @@ -0,0 +1,5 @@ +# Additional Examples +The following are nifty links to projects and examples that leverage the AbilityBot module. If you do have a project that you would like to share, please reach out! + +[FitnessBot](https://craftcodecrew.com/getting-started-with-the-telegram-abilitybot/) - +A fully fledged guide that walks you through building a fitness bot from A to Z \ No newline at end of file From c1597058f4ae41a84e83e28a24279bbcd6df7009 Mon Sep 17 00:00:00 2001 From: Abbas Abou Daya Date: Thu, 3 Jan 2019 06:12:06 +0200 Subject: [PATCH 35/37] Add additional examples to sidebar --- TelegramBots.wiki/_Sidebar.md | 1 + 1 file changed, 1 insertion(+) diff --git a/TelegramBots.wiki/_Sidebar.md b/TelegramBots.wiki/_Sidebar.md index 0bc64b51..897f9d95 100644 --- a/TelegramBots.wiki/_Sidebar.md +++ b/TelegramBots.wiki/_Sidebar.md @@ -11,5 +11,6 @@ * [[Bot Testing]] * [[Bot Recovery]] * [[Advanced]] + * [[Additional Examples]] * [[Changelog]] * [[How To Update]] \ No newline at end of file From 05c92d40377ea62fc83475d5b9888a289c3288c6 Mon Sep 17 00:00:00 2001 From: chase Date: Sat, 19 Jan 2019 09:49:44 +0100 Subject: [PATCH 36/37] Use stream to scan for annotations and to execute the methods --- .../starter/TelegramBotInitializer.java | 62 +++++++++---------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/telegrambots-spring-boot-starter/src/main/java/org/telegram/telegrambots/starter/TelegramBotInitializer.java b/telegrambots-spring-boot-starter/src/main/java/org/telegram/telegrambots/starter/TelegramBotInitializer.java index 37b5ed46..241d962d 100644 --- a/telegrambots-spring-boot-starter/src/main/java/org/telegram/telegrambots/starter/TelegramBotInitializer.java +++ b/telegrambots-spring-boot-starter/src/main/java/org/telegram/telegrambots/starter/TelegramBotInitializer.java @@ -51,46 +51,44 @@ public class TelegramBotInitializer implements InitializingBean { } } - private void handleAnnotatedMethod(Object bot, Method method, BotSession session) throws InvocationTargetException, IllegalAccessException { - if (method.getParameterCount() > 1) { + private void handleAnnotatedMethod(Object bot, Method method, BotSession session) { + try { + if (method.getParameterCount() > 1) { + BotLogger.warn(this.getClass().getSimpleName(), + format("Method %s of Type %s has too many parameters", + method.getName(), + method.getDeclaringClass().getCanonicalName() + ) + ); + return; + } + if (method.getParameterCount() == 0) { + method.invoke(bot); + return; + } + if (method.getParameterTypes()[0].equals(BotSession.class)) { + method.invoke(bot, session); + return; + } BotLogger.warn(this.getClass().getSimpleName(), - format("Method %s of Type %s has too many parameters", + format("Method %s of Type %s has invalid parameter type", method.getName(), method.getDeclaringClass().getCanonicalName() ) ); - return; + } catch (InvocationTargetException | IllegalAccessException e) { + BotLogger.error(this.getClass().getSimpleName(), + format("Couldn't invoke Method %s of Type %s", + method.getName(), method.getDeclaringClass().getCanonicalName() + ) + ); } - if (method.getParameterCount() == 0) { - method.invoke(bot); - return; - } - if (method.getParameterTypes()[0].equals(BotSession.class)) { - method.invoke(bot, session); - return; - } - BotLogger.warn(this.getClass().getSimpleName(), - format("Method %s of Type %s has invalid parameter type", - method.getName(), - method.getDeclaringClass().getCanonicalName() - ) - ); } private void handleAfterRegistrationHook(Object bot, BotSession botSession) { - for (Method m : bot.getClass().getMethods()) { - Stream.of(m.getAnnotations()).forEach(annotation -> System.out.println(annotation.annotationType().getName())); - if (m.getAnnotation(AfterBotRegistration.class) != null) { - try { - handleAnnotatedMethod(bot, m, botSession); - } catch (InvocationTargetException | IllegalAccessException e) { - BotLogger.error(this.getClass().getSimpleName(), - format("Couldn't invoke Method %s of Type %s", - m.getName(), m.getDeclaringClass().getCanonicalName() - ) - ); - } - } - } + Stream.of(bot.getClass().getMethods()) + .filter(method -> method.getAnnotation(AfterBotRegistration.class) != null) + .forEach(method -> handleAnnotatedMethod(bot, method, botSession)); + } } From f96c91cd48b8be33faf8584ea17341acdde2cd1e Mon Sep 17 00:00:00 2001 From: Rubenlagus Date: Sun, 27 Jan 2019 23:26:38 +0000 Subject: [PATCH 37/37] Update wiki --- TelegramBots.wiki/Changelog.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/TelegramBots.wiki/Changelog.md b/TelegramBots.wiki/Changelog.md index 07da17cb..82e9f2de 100644 --- a/TelegramBots.wiki/Changelog.md +++ b/TelegramBots.wiki/Changelog.md @@ -1,3 +1,7 @@ +### 4.1.1 ### +1. Removed unsafe dependencies +2. Fix bugs: #535, #524, #563, #562 and #557 + ### 4.1 ### 1. Support for Api Version [4.1](https://core.telegram.org/bots/api-changelog#august-27-2018) 2. Fix #507 and #512