From f0f616c63c940814f572754321af84b6f28fb597 Mon Sep 17 00:00:00 2001 From: Abbas Abou Daya Date: Tue, 13 Feb 2018 21:24:20 -0500 Subject: [PATCH 01/17] Fix abilities Maven dependency typo --- TelegramBots.wiki/abilities/Simple-Example.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TelegramBots.wiki/abilities/Simple-Example.md b/TelegramBots.wiki/abilities/Simple-Example.md index 8b718183..9d245b66 100644 --- a/TelegramBots.wiki/abilities/Simple-Example.md +++ b/TelegramBots.wiki/abilities/Simple-Example.md @@ -8,7 +8,7 @@ As with any Java project, you will need to set your dependencies. ```xml org.telegram - telegrambots-abilties + telegrambots-abilities 3.5 ``` From 2bc7ebc0559591f3a08e2592df77b601bd64d9ed Mon Sep 17 00:00:00 2001 From: gekoramy Date: Thu, 15 Feb 2018 15:19:34 +0100 Subject: [PATCH 02/17] Fixed Bot API methods ## AnswerCallbackQuery `setCacheTime(...)` now returns `AnswerCallbackQuery` ## EditMessageLiveLocation `setLongitud(...)` corrected requireNonNull check `setLatitude(...)` corrected requireNonNull check ## Suggestion Removed `Objects.requireNonNull(chatId)` check from methods which can have `inline_message_id` instead of `chat_id` --- .../telegrambots/api/methods/AnswerCallbackQuery.java | 3 ++- .../telegrambots/api/methods/StopMessageLiveLocation.java | 1 - .../telegrambots/api/methods/games/GetGameHighScores.java | 1 - .../telegram/telegrambots/api/methods/games/SetGameScore.java | 1 - .../api/methods/updatingmessages/EditMessageLiveLocation.java | 4 ++-- .../api/methods/updatingmessages/EditMessageReplyMarkup.java | 1 - .../api/methods/updatingmessages/EditMessageText.java | 1 - 7 files changed, 4 insertions(+), 8 deletions(-) diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/AnswerCallbackQuery.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/AnswerCallbackQuery.java index bff2cf55..e6759cc2 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/AnswerCallbackQuery.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/AnswerCallbackQuery.java @@ -97,8 +97,9 @@ public class AnswerCallbackQuery extends BotApiMethod { return cacheTime; } - public void setCacheTime(Integer cacheTime) { + public AnswerCallbackQuery setCacheTime(Integer cacheTime) { this.cacheTime = cacheTime; + return this; } @Override diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/StopMessageLiveLocation.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/StopMessageLiveLocation.java index 9b8ff3ef..9042f5f8 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/StopMessageLiveLocation.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/StopMessageLiveLocation.java @@ -60,7 +60,6 @@ public class StopMessageLiveLocation extends BotApiMethod { } public StopMessageLiveLocation setChatId(Long chatId) { - Objects.requireNonNull(chatId); this.chatId = chatId.toString(); return this; } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/games/GetGameHighScores.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/games/GetGameHighScores.java index 4c15322d..f3ad3953 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/games/GetGameHighScores.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/games/GetGameHighScores.java @@ -86,7 +86,6 @@ public class GetGameHighScores extends BotApiMethod> { } public GetGameHighScores setChatId(Long chatId) { - Objects.requireNonNull(chatId); this.chatId = chatId.toString(); return this; } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/games/SetGameScore.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/games/SetGameScore.java index daa06841..50e3c1cb 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/games/SetGameScore.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/games/SetGameScore.java @@ -104,7 +104,6 @@ public class SetGameScore extends BotApiMethod { } public SetGameScore setChatId(Long chatId) { - Objects.requireNonNull(chatId); this.chatId = chatId.toString(); return this; } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/updatingmessages/EditMessageLiveLocation.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/updatingmessages/EditMessageLiveLocation.java index 2260b035..ff0d79ec 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/updatingmessages/EditMessageLiveLocation.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/updatingmessages/EditMessageLiveLocation.java @@ -104,7 +104,7 @@ public class EditMessageLiveLocation extends BotApiMethod { } public EditMessageLiveLocation setLatitude(Float latitude) { - Objects.requireNonNull(chatId); + Objects.requireNonNull(latitude); this.latitude = latitude; return this; } @@ -114,7 +114,7 @@ public class EditMessageLiveLocation extends BotApiMethod { } public EditMessageLiveLocation setLongitud(Float longitud) { - Objects.requireNonNull(chatId); + Objects.requireNonNull(longitud); this.longitud = longitud; return this; } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/updatingmessages/EditMessageReplyMarkup.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/updatingmessages/EditMessageReplyMarkup.java index f34e6748..9952f3b4 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/updatingmessages/EditMessageReplyMarkup.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/updatingmessages/EditMessageReplyMarkup.java @@ -63,7 +63,6 @@ public class EditMessageReplyMarkup extends BotApiMethod { } public EditMessageReplyMarkup setChatId(Long chatId) { - Objects.requireNonNull(chatId); this.chatId = chatId.toString(); return this; } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/updatingmessages/EditMessageText.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/updatingmessages/EditMessageText.java index b87ae198..39376ec6 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/updatingmessages/EditMessageText.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/updatingmessages/EditMessageText.java @@ -79,7 +79,6 @@ public class EditMessageText extends BotApiMethod { } public EditMessageText setChatId(Long chatId) { - Objects.requireNonNull(chatId); this.chatId = chatId.toString(); return this; } From adced55fdc4ed4d443aab1a703318972c51ab5cd Mon Sep 17 00:00:00 2001 From: Baspla Date: Fri, 23 Feb 2018 20:23:04 +0100 Subject: [PATCH 03/17] Update Using-Replies.md The Consumer has the variable name of "action" not "upd". --- TelegramBots.wiki/abilities/Using-Replies.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TelegramBots.wiki/abilities/Using-Replies.md b/TelegramBots.wiki/abilities/Using-Replies.md index 314dbeb7..82307360 100644 --- a/TelegramBots.wiki/abilities/Using-Replies.md +++ b/TelegramBots.wiki/abilities/Using-Replies.md @@ -12,7 +12,7 @@ public Reply sayYuckOnImage() { // getChatId is a public utility function in rg.telegram.abilitybots.api.util.AbilityUtils Consumer action = upd -> silent.send("Yuck", getChatId(upd)); - return Reply.of(upd, Flag.PHOTO) + return Reply.of(action, Flag.PHOTO) } ``` @@ -74,4 +74,4 @@ public Ability playWithMe() { In this example, we showcase how we can supply our own predicates. The two new predicates are `isReplyToMessage` and `isReplyToBot`. The checks are made so that, once you execute your logic there is no need to check for the validity of the reply. -They were all made once the action logic is being executed. \ No newline at end of file +They were all made once the action logic is being executed. From 422b26d661b3d01c7d857960a5737879b9947d91 Mon Sep 17 00:00:00 2001 From: Marijn Koesen Date: Tue, 27 Feb 2018 06:37:26 +0100 Subject: [PATCH 04/17] Add IBotCommand to create Commands that get whole Message --- .../TelegramLongPollingCommandBot.java | 13 ++++--- .../bots/commandbot/commands/BotCommand.java | 4 +- .../commandbot/commands/CommandRegistry.java | 22 +++++------ .../commands/DefaultBotCommand.java | 2 +- .../bots/commandbot/commands/IBotCommand.java | 37 +++++++++++++++++++ .../commandbot/commands/ICommandRegistry.java | 12 +++--- .../commands/helpCommand/HelpCommand.java | 19 +++++----- 7 files changed, 73 insertions(+), 36 deletions(-) create mode 100644 telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/commands/IBotCommand.java diff --git a/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/TelegramLongPollingCommandBot.java b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/TelegramLongPollingCommandBot.java index c408580d..5e2e30f0 100644 --- a/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/TelegramLongPollingCommandBot.java +++ b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/TelegramLongPollingCommandBot.java @@ -9,6 +9,7 @@ import org.telegram.telegrambots.bots.DefaultBotOptions; import org.telegram.telegrambots.bots.TelegramLongPollingBot; import org.telegram.telegrambots.bots.commandbot.commands.BotCommand; import org.telegram.telegrambots.bots.commandbot.commands.CommandRegistry; +import org.telegram.telegrambots.bots.commandbot.commands.IBotCommand; import org.telegram.telegrambots.bots.commandbot.commands.ICommandRegistry; import java.util.Collection; @@ -105,27 +106,27 @@ public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingB } @Override - public final boolean register(BotCommand botCommand) { + public final boolean register(IBotCommand botCommand) { return commandRegistry.register(botCommand); } @Override - public final Map registerAll(BotCommand... botCommands) { + public final Map registerAll(IBotCommand... botCommands) { return commandRegistry.registerAll(botCommands); } @Override - public final boolean deregister(BotCommand botCommand) { + public final boolean deregister(IBotCommand botCommand) { return commandRegistry.deregister(botCommand); } @Override - public final Map deregisterAll(BotCommand... botCommands) { + public final Map deregisterAll(IBotCommand... botCommands) { return commandRegistry.deregisterAll(botCommands); } @Override - public final Collection getRegisteredCommands() { + public final Collection getRegisteredCommands() { return commandRegistry.getRegisteredCommands(); } @@ -135,7 +136,7 @@ public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingB } @Override - public final BotCommand getRegisteredCommand(String commandIdentifier) { + public final IBotCommand getRegisteredCommand(String commandIdentifier) { return commandRegistry.getRegisteredCommand(commandIdentifier); } diff --git a/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/commands/BotCommand.java b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/commands/BotCommand.java index 6d6c3b63..3ef941ec 100644 --- a/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/commands/BotCommand.java +++ b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/commands/BotCommand.java @@ -10,7 +10,7 @@ import org.telegram.telegrambots.bots.AbsSender; * * @author Timo Schulz (Mit0x2) */ -public abstract class BotCommand { +public abstract class BotCommand implements IBotCommand { public final static String COMMAND_INIT_CHARACTER = "/"; public static final String COMMAND_PARAMETER_SEPARATOR_REGEXP = "\\s+"; private final static int COMMAND_MAX_LENGTH = 32; @@ -74,7 +74,7 @@ public abstract class BotCommand { * @param message the message to process * @param arguments passed arguments */ - void processMessage(AbsSender absSender, Message message, String[] arguments) { + public void processMessage(AbsSender absSender, Message message, String[] arguments) { execute(absSender, message.getFrom(), message.getChat(), arguments); } diff --git a/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/commands/CommandRegistry.java b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/commands/CommandRegistry.java index 7ca5c0cc..2f44eada 100644 --- a/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/commands/CommandRegistry.java +++ b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/commands/CommandRegistry.java @@ -16,7 +16,7 @@ import java.util.function.BiConsumer; */ public final class CommandRegistry implements ICommandRegistry { - private final Map commandRegistryMap = new HashMap<>(); + private final Map commandRegistryMap = new HashMap<>(); private final boolean allowCommandsWithUsername; private final String botUsername; private BiConsumer defaultConsumer; @@ -37,7 +37,7 @@ public final class CommandRegistry implements ICommandRegistry { } @Override - public final boolean register(BotCommand botCommand) { + public final boolean register(IBotCommand botCommand) { if (commandRegistryMap.containsKey(botCommand.getCommandIdentifier())) { return false; } @@ -46,16 +46,16 @@ public final class CommandRegistry implements ICommandRegistry { } @Override - public final Map registerAll(BotCommand... botCommands) { - Map resultMap = new HashMap<>(botCommands.length); - for (BotCommand botCommand : botCommands) { + public final Map registerAll(IBotCommand... botCommands) { + Map resultMap = new HashMap<>(botCommands.length); + for (IBotCommand botCommand : botCommands) { resultMap.put(botCommand, register(botCommand)); } return resultMap; } @Override - public final boolean deregister(BotCommand botCommand) { + public final boolean deregister(IBotCommand botCommand) { if (commandRegistryMap.containsKey(botCommand.getCommandIdentifier())) { commandRegistryMap.remove(botCommand.getCommandIdentifier()); return true; @@ -64,21 +64,21 @@ public final class CommandRegistry implements ICommandRegistry { } @Override - public final Map deregisterAll(BotCommand... botCommands) { - Map resultMap = new HashMap<>(botCommands.length); - for (BotCommand botCommand : botCommands) { + public final Map deregisterAll(IBotCommand... botCommands) { + Map resultMap = new HashMap<>(botCommands.length); + for (IBotCommand botCommand : botCommands) { resultMap.put(botCommand, deregister(botCommand)); } return resultMap; } @Override - public final Collection getRegisteredCommands() { + public final Collection getRegisteredCommands() { return commandRegistryMap.values(); } @Override - public final BotCommand getRegisteredCommand(String commandIdentifier) { + public final IBotCommand getRegisteredCommand(String commandIdentifier) { return commandRegistryMap.get(commandIdentifier); } diff --git a/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/commands/DefaultBotCommand.java b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/commands/DefaultBotCommand.java index a4124150..e4cb2d2d 100644 --- a/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/commands/DefaultBotCommand.java +++ b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/commands/DefaultBotCommand.java @@ -31,7 +31,7 @@ public abstract class DefaultBotCommand extends BotCommand { * @param arguments passed arguments */ @Override - void processMessage(AbsSender absSender, Message message, String[] arguments) { + public void processMessage(AbsSender absSender, Message message, String[] arguments) { execute(absSender, message.getFrom(), message.getChat(), message.getMessageId(), arguments); } diff --git a/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/commands/IBotCommand.java b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/commands/IBotCommand.java new file mode 100644 index 00000000..618e9936 --- /dev/null +++ b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/commands/IBotCommand.java @@ -0,0 +1,37 @@ +package org.telegram.telegrambots.bots.commandbot.commands; + +import org.telegram.telegrambots.api.objects.Message; +import org.telegram.telegrambots.bots.AbsSender; + +import java.util.Collection; +import java.util.Map; +import java.util.function.BiConsumer; + +/** + * This Interface represents the a Command that can be executed + * + * @author Timo Schulz (Mit0x2) + */ +public interface IBotCommand { + /** + * Get the identifier of this command + * + * @return the identifier + */ + String getCommandIdentifier(); + + /** + * Get the description of this command + * + * @return the description as String + */ + String getDescription(); + + /** + * Process the message and execute the command + * + * @param absSender absSender to send messages over + * @param message the message to process + */ + void processMessage(AbsSender absSender, Message message, String[] arguments); +} \ No newline at end of file diff --git a/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/commands/ICommandRegistry.java b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/commands/ICommandRegistry.java index 1f2a4d5f..a6a4905c 100644 --- a/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/commands/ICommandRegistry.java +++ b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/commands/ICommandRegistry.java @@ -29,7 +29,7 @@ public interface ICommandRegistry { * @param botCommand the command to register * @return whether the command could be registered, was not already registered */ - boolean register(BotCommand botCommand); + boolean register(IBotCommand botCommand); /** * register multiple commands @@ -37,7 +37,7 @@ public interface ICommandRegistry { * @param botCommands commands to register * @return map with results of the command register per command */ - Map registerAll(BotCommand... botCommands); + Map registerAll(IBotCommand... botCommands); /** * deregister a command @@ -45,7 +45,7 @@ public interface ICommandRegistry { * @param botCommand the command to deregister * @return whether the command could be deregistered, was registered */ - boolean deregister(BotCommand botCommand); + boolean deregister(IBotCommand botCommand); /** * deregister multiple commands @@ -53,19 +53,19 @@ public interface ICommandRegistry { * @param botCommands commands to deregister * @return map with results of the command deregistered per command */ - Map deregisterAll(BotCommand... botCommands); + Map deregisterAll(IBotCommand... botCommands); /** * get a collection of all registered commands * * @return a collection of registered commands */ - Collection getRegisteredCommands(); + Collection getRegisteredCommands(); /** * get registered command * * @return registered command if exists or null if not */ - BotCommand getRegisteredCommand(String commandIdentifier); + IBotCommand getRegisteredCommand(String commandIdentifier); } \ No newline at end of file diff --git a/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/commands/helpCommand/HelpCommand.java b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/commands/helpCommand/HelpCommand.java index 2926b0e6..bd108a19 100644 --- a/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/commands/helpCommand/HelpCommand.java +++ b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/commands/helpCommand/HelpCommand.java @@ -1,16 +1,15 @@ package org.telegram.telegrambots.bots.commandbot.commands.helpCommand; -import java.util.Collection; - import org.telegram.telegrambots.api.methods.send.SendMessage; import org.telegram.telegrambots.api.objects.Chat; import org.telegram.telegrambots.api.objects.User; import org.telegram.telegrambots.bots.AbsSender; -import org.telegram.telegrambots.bots.commandbot.TelegramLongPollingCommandBot; -import org.telegram.telegrambots.bots.commandbot.commands.BotCommand; +import org.telegram.telegrambots.bots.commandbot.commands.IBotCommand; import org.telegram.telegrambots.bots.commandbot.commands.ICommandRegistry; import org.telegram.telegrambots.exceptions.TelegramApiException; +import java.util.Collection; + /** * A special bot command used for printing help messages similiar to the Linux man command. * The commands printed by this command should implement the {@link IManCommand} interface to provide an extended description. @@ -29,9 +28,9 @@ public class HelpCommand extends ManCommand { * @param botCommands the Commands that should be included in the String * @return a formatted String containing command and description for all supplied commands */ - public static String getHelpText(BotCommand...botCommands) { + public static String getHelpText(IBotCommand...botCommands) { StringBuilder reply = new StringBuilder(); - for (BotCommand com : botCommands) { + for (IBotCommand com : botCommands) { reply.append(com.toString()).append(System.lineSeparator()).append(System.lineSeparator()); } return reply.toString(); @@ -42,8 +41,8 @@ public class HelpCommand extends ManCommand { * @param botCommands a collection of commands that should be included in the String * @return a formatted String containing command and description for all supplied commands */ - public static String getHelpText(Collection botCommands) { - return getHelpText(botCommands.toArray(new BotCommand[botCommands.size()])); + public static String getHelpText(Collection botCommands) { + return getHelpText(botCommands.toArray(new IBotCommand[botCommands.size()])); } /** @@ -60,7 +59,7 @@ public class HelpCommand extends ManCommand { * @param command a command the extended Descriptions is read from * @return the extended Description or the toString() if IManCommand is not implemented */ - public static String getManText(BotCommand command) { + public static String getManText(IBotCommand command) { return IManCommand.class.isInstance(command) ? getManText((IManCommand) command) : command.toString(); } @@ -96,7 +95,7 @@ public class HelpCommand extends ManCommand { ICommandRegistry registry = (ICommandRegistry) absSender; if (arguments.length > 0) { - BotCommand command = registry.getRegisteredCommand(arguments[0]); + IBotCommand command = registry.getRegisteredCommand(arguments[0]); String reply = getManText(command); try { absSender.execute(new SendMessage(chat.getId(), reply).setParseMode("HTML")); From 7a83b45a91fe6597fd9490e72633c471e666747d Mon Sep 17 00:00:00 2001 From: Ruben Bermudez Date: Sun, 1 Apr 2018 12:20:55 +0200 Subject: [PATCH 05/17] Closes #319 --- TelegramBots.wiki/How-To-Update.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TelegramBots.wiki/How-To-Update.md b/TelegramBots.wiki/How-To-Update.md index d641fa88..370ce664 100644 --- a/TelegramBots.wiki/How-To-Update.md +++ b/TelegramBots.wiki/How-To-Update.md @@ -1,6 +1,6 @@ ### To version 2.4.3 ### 1. Replace `BotOptions` by `DefaultBotOptions`. -2. At the beginning of your program (before creating your `TelegramBotsApi` instance, add the following line: +2. At the beginning of your program (before creating your `TelegramBotsApi` or `Bot` instance, add the following line: ```java ApiContextInitializer.init(); ``` From b057a98ada1eaa7ddb43427705daf277b2686226 Mon Sep 17 00:00:00 2001 From: Ruben Bermudez Date: Sun, 1 Apr 2018 12:37:28 +0200 Subject: [PATCH 06/17] Closes #361 --- .../telegram/telegrambots/api/objects/ResponseParameters.java | 4 ++-- .../org/telegram/telegrambots/test/TestDeserialization.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/ResponseParameters.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/ResponseParameters.java index fb6915a5..68191090 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/ResponseParameters.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/ResponseParameters.java @@ -38,7 +38,7 @@ public class ResponseParameters implements BotApiObject { * so a signed 64 bit integer or double-precision float type are safe for storing this identifier. */ @JsonProperty(MIGRATETOCHATID_FIELD) - private Integer migrateToChatId; + private Long migrateToChatId; /** * Optional. In case of exceeding flood control a number of seconds to * wait before the request can be repeated @@ -50,7 +50,7 @@ public class ResponseParameters implements BotApiObject { super(); } - public Integer getMigrateToChatId() { + public Long getMigrateToChatId() { return migrateToChatId; } diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/test/TestDeserialization.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/test/TestDeserialization.java index 37c92ea9..9968df5b 100644 --- a/telegrambots-meta/src/test/java/org/telegram/telegrambots/test/TestDeserialization.java +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/test/TestDeserialization.java @@ -59,7 +59,7 @@ public class TestDeserialization { Assert.assertEquals(Integer.valueOf(400), result.getErrorCode()); Assert.assertEquals("Error descriptions", result.getErrorDescription()); Assert.assertNotNull(result.getParameters()); - Assert.assertEquals(Integer.valueOf(12345), result.getParameters().getMigrateToChatId()); + Assert.assertEquals(Long.valueOf(12345), result.getParameters().getMigrateToChatId()); Assert.assertEquals(Integer.valueOf(12), result.getParameters().getRetryAfter()); } From 025be6eefd6fb9970235d5b12dbc8b7225015741 Mon Sep 17 00:00:00 2001 From: Ruben Bermudez Date: Sun, 1 Apr 2018 12:40:58 +0200 Subject: [PATCH 07/17] Closes #364 --- .../java/org/telegram/telegrambots/api/objects/Message.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/Message.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/Message.java index 76d56c1e..c4210256 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/Message.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/Message.java @@ -397,6 +397,10 @@ public class Message implements BotApiObject { return successfulPayment != null; } + public boolean hasContact() { + return contact != null; + } + public Invoice getInvoice() { return invoice; } From e53f0bd9ef30549c242259614706d637c51a7f60 Mon Sep 17 00:00:00 2001 From: Ruben Bermudez Date: Sun, 1 Apr 2018 12:49:39 +0200 Subject: [PATCH 08/17] Closes #368 --- .../api/methods/updatingmessages/DeleteMessage.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/updatingmessages/DeleteMessage.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/updatingmessages/DeleteMessage.java index b34bf360..256d1b4a 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/updatingmessages/DeleteMessage.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/updatingmessages/DeleteMessage.java @@ -8,6 +8,7 @@ import org.telegram.telegrambots.exceptions.TelegramApiRequestException; import org.telegram.telegrambots.exceptions.TelegramApiValidationException; import java.io.IOException; +import java.util.Objects; import static com.google.common.base.Preconditions.checkNotNull; @@ -62,6 +63,12 @@ public class DeleteMessage extends BotApiMethod { return this; } + public DeleteMessage setChatId(Long chatId) { + Objects.requireNonNull(chatId); + this.chatId = chatId.toString(); + return this; + } + public Integer getMessageId() { return messageId; } From 7a13821e51a36a1c1fa950b1cf6e6525c6818485 Mon Sep 17 00:00:00 2001 From: Ruben Bermudez Date: Sun, 1 Apr 2018 19:28:40 +0200 Subject: [PATCH 09/17] Closes #413 --- .../telegrambots/api/methods/stickers/UploadStickerFile.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/stickers/UploadStickerFile.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/stickers/UploadStickerFile.java index a4196a46..b7363609 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/stickers/UploadStickerFile.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/stickers/UploadStickerFile.java @@ -21,7 +21,7 @@ import static com.google.common.base.Preconditions.checkNotNull; public class UploadStickerFile extends PartialBotApiMethod { public static final String PATH = "uploadStickerFile"; - public static final String USERID_FIELD = "name"; + public static final String USERID_FIELD = "user_id"; public static final String PNGSTICKER_FIELD = "png_sticker"; private Integer userId; ///< User identifier of sticker file owner From 3534fa789deab2b4fbf4ca14e336ff5ad2301c12 Mon Sep 17 00:00:00 2001 From: Relecto Date: Mon, 2 Apr 2018 22:38:29 +0600 Subject: [PATCH 10/17] Added hasVideo() method to Message --- .../java/org/telegram/telegrambots/api/objects/Message.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/Message.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/Message.java index c4210256..449e93f7 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/Message.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/Message.java @@ -357,6 +357,10 @@ public class Message implements BotApiObject { return this.document != null; } + public boolean hasVideo() { + return this.video != null; + } + public boolean isReply() { return this.replyToMessage != null; } From 378c8aaddc0b342684e6578b070a7ab2dd8b90c6 Mon Sep 17 00:00:00 2001 From: "Vyacheslav N. Boyko" Date: Mon, 16 Apr 2018 17:58:51 +0300 Subject: [PATCH 11/17] implemented authorization via http proxy --- .../telegrambots/bots/DefaultAbsSender.java | 46 +++++++++++++++++-- .../telegrambots/bots/DefaultBotOptions.java | 21 +++++++++ .../bots/TelegramLongPollingBot.java | 2 +- .../telegrambots/bots/TelegramWebhookBot.java | 2 +- .../updatesreceivers/DefaultBotSession.java | 30 ++++++++++-- 5 files changed, 89 insertions(+), 12 deletions(-) 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 52d88b08..eff31bb5 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java @@ -13,6 +13,7 @@ import org.apache.http.entity.StringEntity; import org.apache.http.entity.mime.MultipartEntityBuilder; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.client.ProxyAuthenticationStrategy; import org.apache.http.util.EntityUtils; import org.telegram.telegrambots.api.methods.BotApiMethod; import org.telegram.telegrambots.api.methods.groupadministration.SetChatPhoto; @@ -61,11 +62,23 @@ public abstract class DefaultAbsSender extends AbsSender { super(); this.exe = Executors.newFixedThreadPool(options.getMaxThreads()); this.options = options; - httpclient = HttpClientBuilder.create() - .setSSLHostnameVerifier(new NoopHostnameVerifier()) - .setConnectionTimeToLive(70, TimeUnit.SECONDS) - .setMaxConnTotal(100) - .build(); + + if (options.getCredentialsProvider() != null) { + httpclient = HttpClientBuilder.create() + .setProxy(options.getHttpProxy()) + .setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy()) + .setDefaultCredentialsProvider(options.getCredentialsProvider()) + .setSSLHostnameVerifier(new NoopHostnameVerifier()) + .setConnectionTimeToLive(70, TimeUnit.SECONDS) + .setMaxConnTotal(100) + .build(); + } else { + httpclient = HttpClientBuilder.create() + .setSSLHostnameVerifier(new NoopHostnameVerifier()) + .setConnectionTimeToLive(70, TimeUnit.SECONDS) + .setMaxConnTotal(100) + .build(); + } requestConfig = options.getRequestConfig(); @@ -87,6 +100,29 @@ public abstract class DefaultAbsSender extends AbsSender { return options; } + protected CloseableHttpClient createHttpClient() { + CloseableHttpClient localClient = null; + + if (options.getCredentialsProvider() != null) { + localClient = HttpClientBuilder.create() + .setProxy(options.getHttpProxy()) + .setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy()) + .setDefaultCredentialsProvider(options.getCredentialsProvider()) + .setSSLHostnameVerifier(new NoopHostnameVerifier()) + .setConnectionTimeToLive(70, TimeUnit.SECONDS) + .setMaxConnTotal(100) + .build(); + } else { + localClient = HttpClientBuilder.create() + .setSSLHostnameVerifier(new NoopHostnameVerifier()) + .setConnectionTimeToLive(70, TimeUnit.SECONDS) + .setMaxConnTotal(100) + .build(); + } + + return localClient; + } + // Send Requests public final java.io.File downloadFile(String filePath) throws TelegramApiException { diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultBotOptions.java b/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultBotOptions.java index b8e115cf..f965ab91 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultBotOptions.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultBotOptions.java @@ -1,5 +1,7 @@ package org.telegram.telegrambots.bots; +import org.apache.http.HttpHost; +import org.apache.http.client.CredentialsProvider; import org.apache.http.client.config.RequestConfig; import org.telegram.telegrambots.ApiConstants; import org.telegram.telegrambots.generics.BotOptions; @@ -21,6 +23,9 @@ public class DefaultBotOptions implements BotOptions { private String baseUrl; private List allowedUpdates; + private CredentialsProvider credentialsProvider; + private HttpHost httpProxy; + public DefaultBotOptions() { maxThreads = 1; baseUrl = ApiConstants.BASE_URL; @@ -82,4 +87,20 @@ public class DefaultBotOptions implements BotOptions { public void setExponentialBackOff(ExponentialBackOff exponentialBackOff) { this.exponentialBackOff = exponentialBackOff; } + + public CredentialsProvider getCredentialsProvider() { + return credentialsProvider; + } + + public void setCredentialsProvider(CredentialsProvider credentialsProvider) { + this.credentialsProvider = credentialsProvider; + } + + public HttpHost getHttpProxy() { + return httpProxy; + } + + public void setHttpProxy(HttpHost httpProxy) { + this.httpProxy = httpProxy; + } } diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingBot.java b/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingBot.java index 8a3508de..4550a903 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingBot.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingBot.java @@ -36,7 +36,7 @@ public abstract class TelegramLongPollingBot extends DefaultAbsSender implements @Override public void clearWebhook() throws TelegramApiRequestException { - try (CloseableHttpClient httpclient = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()).build()) { + try (CloseableHttpClient httpclient = this.createHttpClient()) { String url = getOptions().getBaseUrl() + getBotToken() + "/" + SetWebhook.PATH; HttpGet httpGet = new HttpGet(url); httpGet.setConfig(getOptions().getRequestConfig()); diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramWebhookBot.java b/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramWebhookBot.java index bc07b96f..9c345134 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramWebhookBot.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramWebhookBot.java @@ -44,7 +44,7 @@ public abstract class TelegramWebhookBot extends DefaultAbsSender implements Web @Override public void setWebhook(String url, String publicCertificatePath) throws TelegramApiRequestException { - try (CloseableHttpClient httpclient = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()).build()) { + try (CloseableHttpClient httpclient = this.createHttpClient()) { String requestUrl = getBaseUrl() + SetWebhook.PATH; HttpPost httppost = new HttpPost(requestUrl); diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/DefaultBotSession.java b/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/DefaultBotSession.java index 2e310b33..190cf136 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/DefaultBotSession.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/DefaultBotSession.java @@ -12,6 +12,7 @@ import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.client.ProxyAuthenticationStrategy; import org.apache.http.util.EntityUtils; import org.json.JSONException; import org.telegram.telegrambots.ApiConstants; @@ -145,13 +146,32 @@ public class DefaultBotSession implements BotSession { this.lock = lock; } + protected CloseableHttpClient createHttpClient() { + CloseableHttpClient localClient = null; + + if (options.getCredentialsProvider() != null) { + localClient = HttpClientBuilder.create() + .setProxy(options.getHttpProxy()) + .setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy()) + .setDefaultCredentialsProvider(options.getCredentialsProvider()) + .setSSLHostnameVerifier(new NoopHostnameVerifier()) + .setConnectionTimeToLive(70, TimeUnit.SECONDS) + .setMaxConnTotal(100) + .build(); + } else { + localClient = HttpClientBuilder.create() + .setSSLHostnameVerifier(new NoopHostnameVerifier()) + .setConnectionTimeToLive(70, TimeUnit.SECONDS) + .setMaxConnTotal(100) + .build(); + } + + return localClient; + } + @Override public synchronized void start() { - httpclient = HttpClientBuilder.create() - .setSSLHostnameVerifier(new NoopHostnameVerifier()) - .setConnectionTimeToLive(70, TimeUnit.SECONDS) - .setMaxConnTotal(100) - .build(); + httpclient = createHttpClient(); requestConfig = options.getRequestConfig(); exponentialBackOff = options.getExponentialBackOff(); From b9c32c55d84c7817657a1d028e61470ec21a39bc Mon Sep 17 00:00:00 2001 From: "Vyacheslav N. Boyko" Date: Mon, 16 Apr 2018 18:01:00 +0300 Subject: [PATCH 12/17] implemented authorization via http proxy --- .../telegrambots/bots/DefaultAbsSender.java | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) 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 eff31bb5..758c8346 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java @@ -63,22 +63,7 @@ public abstract class DefaultAbsSender extends AbsSender { this.exe = Executors.newFixedThreadPool(options.getMaxThreads()); this.options = options; - if (options.getCredentialsProvider() != null) { - httpclient = HttpClientBuilder.create() - .setProxy(options.getHttpProxy()) - .setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy()) - .setDefaultCredentialsProvider(options.getCredentialsProvider()) - .setSSLHostnameVerifier(new NoopHostnameVerifier()) - .setConnectionTimeToLive(70, TimeUnit.SECONDS) - .setMaxConnTotal(100) - .build(); - } else { - httpclient = HttpClientBuilder.create() - .setSSLHostnameVerifier(new NoopHostnameVerifier()) - .setConnectionTimeToLive(70, TimeUnit.SECONDS) - .setMaxConnTotal(100) - .build(); - } + httpclient = createHttpClient(); requestConfig = options.getRequestConfig(); From 28f80e1bcdf59e6cc2dbbe65eec873bd7a944d43 Mon Sep 17 00:00:00 2001 From: "Vyacheslav N. Boyko" Date: Tue, 17 Apr 2018 11:46:48 +0300 Subject: [PATCH 13/17] reworked proxy using --- .../telegrambots/bots/DefaultAbsSender.java | 26 +------------ .../bots/TelegramLongPollingBot.java | 3 +- .../telegrambots/bots/TelegramWebhookBot.java | 3 +- .../facilities/TelegramHttpClientBuilder.java | 37 +++++++++++++++++++ .../updatesreceivers/DefaultBotSession.java | 26 +------------ 5 files changed, 45 insertions(+), 50 deletions(-) create mode 100644 telegrambots/src/main/java/org/telegram/telegrambots/facilities/TelegramHttpClientBuilder.java 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 758c8346..400ab4b9 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java @@ -27,6 +27,7 @@ import org.telegram.telegrambots.api.objects.media.InputMedia; import org.telegram.telegrambots.exceptions.TelegramApiException; import org.telegram.telegrambots.exceptions.TelegramApiRequestException; import org.telegram.telegrambots.exceptions.TelegramApiValidationException; +import org.telegram.telegrambots.facilities.TelegramHttpClientBuilder; import org.telegram.telegrambots.updateshandlers.DownloadFileCallback; import org.telegram.telegrambots.updateshandlers.SentCallback; @@ -63,7 +64,7 @@ public abstract class DefaultAbsSender extends AbsSender { this.exe = Executors.newFixedThreadPool(options.getMaxThreads()); this.options = options; - httpclient = createHttpClient(); + httpclient = TelegramHttpClientBuilder.build(options); requestConfig = options.getRequestConfig(); @@ -85,29 +86,6 @@ public abstract class DefaultAbsSender extends AbsSender { return options; } - protected CloseableHttpClient createHttpClient() { - CloseableHttpClient localClient = null; - - if (options.getCredentialsProvider() != null) { - localClient = HttpClientBuilder.create() - .setProxy(options.getHttpProxy()) - .setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy()) - .setDefaultCredentialsProvider(options.getCredentialsProvider()) - .setSSLHostnameVerifier(new NoopHostnameVerifier()) - .setConnectionTimeToLive(70, TimeUnit.SECONDS) - .setMaxConnTotal(100) - .build(); - } else { - localClient = HttpClientBuilder.create() - .setSSLHostnameVerifier(new NoopHostnameVerifier()) - .setConnectionTimeToLive(70, TimeUnit.SECONDS) - .setMaxConnTotal(100) - .build(); - } - - return localClient; - } - // Send Requests public final java.io.File downloadFile(String filePath) throws TelegramApiException { diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingBot.java b/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingBot.java index 4550a903..25b99dfc 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingBot.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingBot.java @@ -14,6 +14,7 @@ import org.telegram.telegrambots.ApiConstants; import org.telegram.telegrambots.ApiContext; import org.telegram.telegrambots.api.methods.updates.SetWebhook; import org.telegram.telegrambots.exceptions.TelegramApiRequestException; +import org.telegram.telegrambots.facilities.TelegramHttpClientBuilder; import org.telegram.telegrambots.generics.LongPollingBot; import java.io.IOException; @@ -36,7 +37,7 @@ public abstract class TelegramLongPollingBot extends DefaultAbsSender implements @Override public void clearWebhook() throws TelegramApiRequestException { - try (CloseableHttpClient httpclient = this.createHttpClient()) { + try (CloseableHttpClient httpclient = TelegramHttpClientBuilder.build(getOptions())) { String url = getOptions().getBaseUrl() + getBotToken() + "/" + SetWebhook.PATH; HttpGet httpGet = new HttpGet(url); httpGet.setConfig(getOptions().getRequestConfig()); diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramWebhookBot.java b/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramWebhookBot.java index 9c345134..9b2ff0ec 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramWebhookBot.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramWebhookBot.java @@ -17,6 +17,7 @@ import org.telegram.telegrambots.ApiConstants; import org.telegram.telegrambots.ApiContext; import org.telegram.telegrambots.api.methods.updates.SetWebhook; import org.telegram.telegrambots.exceptions.TelegramApiRequestException; +import org.telegram.telegrambots.facilities.TelegramHttpClientBuilder; import org.telegram.telegrambots.generics.WebhookBot; import java.io.File; @@ -44,7 +45,7 @@ public abstract class TelegramWebhookBot extends DefaultAbsSender implements Web @Override public void setWebhook(String url, String publicCertificatePath) throws TelegramApiRequestException { - try (CloseableHttpClient httpclient = this.createHttpClient()) { + try (CloseableHttpClient httpclient = TelegramHttpClientBuilder.build(getOptions())) { String requestUrl = getBaseUrl() + SetWebhook.PATH; HttpPost httppost = new HttpPost(requestUrl); diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/facilities/TelegramHttpClientBuilder.java b/telegrambots/src/main/java/org/telegram/telegrambots/facilities/TelegramHttpClientBuilder.java new file mode 100644 index 00000000..fb911c04 --- /dev/null +++ b/telegrambots/src/main/java/org/telegram/telegrambots/facilities/TelegramHttpClientBuilder.java @@ -0,0 +1,37 @@ +package org.telegram.telegrambots.facilities; + +import org.apache.http.conn.ssl.NoopHostnameVerifier; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.client.ProxyAuthenticationStrategy; +import org.telegram.telegrambots.bots.DefaultBotOptions; + +import java.util.concurrent.TimeUnit; + +/** + * Created by bvn13 on 17.04.2018. + */ +public class TelegramHttpClientBuilder { + + public static CloseableHttpClient build(DefaultBotOptions options) { + HttpClientBuilder httpClientBuilder = HttpClientBuilder.create() + .setSSLHostnameVerifier(new NoopHostnameVerifier()) + .setConnectionTimeToLive(70, TimeUnit.SECONDS) + .setMaxConnTotal(100); + + if (options.getHttpProxy() != null) { + + httpClientBuilder.setProxy(options.getHttpProxy()); + + if (options.getCredentialsProvider() != null) { + httpClientBuilder + .setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy()) + .setDefaultCredentialsProvider(options.getCredentialsProvider()); + } + + } + + return httpClientBuilder.build(); + } + +} diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/DefaultBotSession.java b/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/DefaultBotSession.java index 190cf136..6e6b56b9 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/DefaultBotSession.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/DefaultBotSession.java @@ -20,6 +20,7 @@ import org.telegram.telegrambots.api.methods.updates.GetUpdates; import org.telegram.telegrambots.api.objects.Update; import org.telegram.telegrambots.bots.DefaultBotOptions; import org.telegram.telegrambots.exceptions.TelegramApiRequestException; +import org.telegram.telegrambots.facilities.TelegramHttpClientBuilder; import org.telegram.telegrambots.generics.*; import org.telegram.telegrambots.logging.BotLogger; @@ -146,32 +147,9 @@ public class DefaultBotSession implements BotSession { this.lock = lock; } - protected CloseableHttpClient createHttpClient() { - CloseableHttpClient localClient = null; - - if (options.getCredentialsProvider() != null) { - localClient = HttpClientBuilder.create() - .setProxy(options.getHttpProxy()) - .setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy()) - .setDefaultCredentialsProvider(options.getCredentialsProvider()) - .setSSLHostnameVerifier(new NoopHostnameVerifier()) - .setConnectionTimeToLive(70, TimeUnit.SECONDS) - .setMaxConnTotal(100) - .build(); - } else { - localClient = HttpClientBuilder.create() - .setSSLHostnameVerifier(new NoopHostnameVerifier()) - .setConnectionTimeToLive(70, TimeUnit.SECONDS) - .setMaxConnTotal(100) - .build(); - } - - return localClient; - } - @Override public synchronized void start() { - httpclient = createHttpClient(); + httpclient = TelegramHttpClientBuilder.build(options); requestConfig = options.getRequestConfig(); exponentialBackOff = options.getExponentialBackOff(); From 6b76e79f4dde3e41e0c2baebd87dc75860130648 Mon Sep 17 00:00:00 2001 From: Roman_Meerson Date: Tue, 17 Apr 2018 13:52:08 +0400 Subject: [PATCH 14/17] Added spring boot starter module --- pom.xml | 1 + telegrambots-spring-boot-starter/README.md | 63 +++++ telegrambots-spring-boot-starter/pom.xml | 238 ++++++++++++++++++ .../starter/EnableTelegramBots.java | 10 + .../TelegramBotStarterConfiguration.java | 55 ++++ 5 files changed, 367 insertions(+) create mode 100644 telegrambots-spring-boot-starter/README.md create mode 100644 telegrambots-spring-boot-starter/pom.xml create mode 100644 telegrambots-spring-boot-starter/src/main/java/org/telegram/telegrambots/starter/EnableTelegramBots.java create mode 100644 telegrambots-spring-boot-starter/src/main/java/org/telegram/telegrambots/starter/TelegramBotStarterConfiguration.java diff --git a/pom.xml b/pom.xml index dc751700..fe5346ee 100644 --- a/pom.xml +++ b/pom.xml @@ -14,6 +14,7 @@ telegrambots-meta telegrambots-extensions telegrambots-abilities + telegrambots-spring-boot-starter diff --git a/telegrambots-spring-boot-starter/README.md b/telegrambots-spring-boot-starter/README.md new file mode 100644 index 00000000..0d67db99 --- /dev/null +++ b/telegrambots-spring-boot-starter/README.md @@ -0,0 +1,63 @@ +
+ abilitybots + +[![Build Status](https://travis-ci.org/rubenlagus/TelegramBots.svg?branch=master)](https://travis-ci.org/rubenlagus/TelegramBots) +[![Jitpack](https://jitpack.io/v/rubenlagus/TelegramBots.svg)](https://jitpack.io/#rubenlagus/TelegramBots) +[![JavaDoc](http://svgur.com/i/1Ex.svg)](https://addo37.github.io/AbilityBots/) +[![Telegram](http://trellobot.doomdns.org/telegrambadge.svg)](https://telegram.me/JavaBotsApi) +[![ghit.me](https://ghit.me/badge.svg?repo=rubenlagus/TelegramBots)](https://ghit.me/repo/rubenlagus/TelegramBots) + +
+ +Usage +----- + +**Maven** + +```xml + + org.telegram + telegrambots-spring-boot-starter + 3.6 + +``` + +**Gradle** + +```gradle + compile "org.telegram:telegrambots-spring-boot-starter:3.6" +``` + +Motivation +---------- +If you are spring boot user it`s better to be in touch with spring starters. This module allows to register bots in spring context automatically and +also use them as standard spring beans. + +How to use +---------- +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) { + //Add this line to initialize bots context + ApiContextInitializer.init(); + + SpringApplication.run(MusicUploaderApplication.class, args); + } +} +``` + +After that your bot will look like: +```java + //Standart Spring component annotation + @Component + public class MusicBotImpl 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 diff --git a/telegrambots-spring-boot-starter/pom.xml b/telegrambots-spring-boot-starter/pom.xml new file mode 100644 index 00000000..301ee6b1 --- /dev/null +++ b/telegrambots-spring-boot-starter/pom.xml @@ -0,0 +1,238 @@ + + + 4.0.0 + org.telegram + telegrambots-spring-boot-starter + 3.6 + jar + + Telegram Bots Spring Boot Starter + https://github.com/rubenlagus/TelegramBots + Easy to use library to create Telegram Bots + + + https://github.com/rubenlagus/TelegramBots/issues + GitHub Issues + + + + https://github.com/rubenlagus/TelegramBots + scm:git:git://github.com/rubenlagus/TelegramBots.git + scm:git:git@github.com:rubenlagus/TelegramBots.git + + + + https://travis-ci.org/rubenlagus/TelegramBots + Travis + + + + + homich1991@gmail.com + Roman Meerson + https://github.com/homich1991 + homich1991 + + + + + + MIT License + http://www.opensource.org/licenses/mit-license.php + repo + + + + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + UTF-8 + UTF-8 + 3.6 + 1.5.10.RELEASE + + + + + + org.telegram + telegrambots + ${bots.version} + + + org.springframework.boot + spring-boot + ${spring-boot.version} + + + org.springframework.boot + spring-boot-autoconfigure + ${spring-boot.version} + + + + + ${project.basedir}/target + ${project.build.directory}/classes + ${project.artifactId}-${project.version} + ${project.build.directory}/test-classes + ${project.basedir}/src/main/java + + + org.apache.maven.plugins + maven-gpg-plugin + 1.5 + + + sign-artifacts + verify + + sign + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.3 + true + + ossrh + https://oss.sonatype.org/ + true + + + + maven-clean-plugin + 3.0.0 + + + clean-project + clean + + clean + + + + + + maven-assembly-plugin + 2.6 + + + jar-with-dependencies + + + + + make-assembly + package + + single + + + + + + org.apache.maven.plugins + maven-source-plugin + 3.0.0 + + + + jar + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.10.3 + + + + jar + + + -Xdoclint:none + + + + + + org.jacoco + jacoco-maven-plugin + 0.7.7.201606060606 + + + + prepare-agent + + + + report + test + + report + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + 1.4.1 + + + enforce-versions + + enforce + + + + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.4 + + + copy + package + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + UTF-8 + + + + + + \ No newline at end of file diff --git a/telegrambots-spring-boot-starter/src/main/java/org/telegram/telegrambots/starter/EnableTelegramBots.java b/telegrambots-spring-boot-starter/src/main/java/org/telegram/telegrambots/starter/EnableTelegramBots.java new file mode 100644 index 00000000..68c4acf9 --- /dev/null +++ b/telegrambots-spring-boot-starter/src/main/java/org/telegram/telegrambots/starter/EnableTelegramBots.java @@ -0,0 +1,10 @@ +package org.telegram.telegrambots.starter; + +import org.springframework.context.annotation.Import; + +/** + * Imports configuration #TelegramBotStarterConfiguration in spring context. + */ +@Import(TelegramBotStarterConfiguration.class) +public @interface EnableTelegramBots { +} diff --git a/telegrambots-spring-boot-starter/src/main/java/org/telegram/telegrambots/starter/TelegramBotStarterConfiguration.java b/telegrambots-spring-boot-starter/src/main/java/org/telegram/telegrambots/starter/TelegramBotStarterConfiguration.java new file mode 100644 index 00000000..ec851dc0 --- /dev/null +++ b/telegrambots-spring-boot-starter/src/main/java/org/telegram/telegrambots/starter/TelegramBotStarterConfiguration.java @@ -0,0 +1,55 @@ +package org.telegram.telegrambots.starter; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.telegram.telegrambots.TelegramBotsApi; +import org.telegram.telegrambots.exceptions.TelegramApiException; +import org.telegram.telegrambots.generics.LongPollingBot; +import org.telegram.telegrambots.generics.WebhookBot; + +import java.util.List; + +/** + * Receives all beand which are #LongPollingBot and #WebhookBot and register them in #TelegramBotsApi. + * #TelegramBotsApi added to spring context as well + */ +@Configuration +public class TelegramBotStarterConfiguration implements CommandLineRunner { + + + private final List longPollingBots; + private final List webHookBots; + + @Autowired + private TelegramBotsApi telegramBotsApi; + + public TelegramBotStarterConfiguration(List longPollingBots, + List webHookBots) { + this.longPollingBots = longPollingBots; + this.webHookBots = webHookBots; + } + + @Override + public void run(String... args) { + try { + for (LongPollingBot bot : longPollingBots) { + telegramBotsApi.registerBot(bot); + } + for (WebhookBot bot : webHookBots) { + telegramBotsApi.registerBot(bot); + } + } catch (TelegramApiException e) { + e.printStackTrace(); + } + } + + + @Bean + @ConditionalOnMissingBean(TelegramBotsApi.class) + public TelegramBotsApi telegramBotsApi() { + return new TelegramBotsApi(); + } +} From 01e046632c0f7230541106e2124a8c0df6d4b9e2 Mon Sep 17 00:00:00 2001 From: Roman_Meerson Date: Thu, 19 Apr 2018 15:51:30 +0400 Subject: [PATCH 15/17] Added FAQ --- TelegramBots.wiki/FAQ.md | 32 ++++++++++++++++++++++ telegrambots-spring-boot-starter/README.md | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/TelegramBots.wiki/FAQ.md b/TelegramBots.wiki/FAQ.md index 982a641a..a2094b30 100644 --- a/TelegramBots.wiki/FAQ.md +++ b/TelegramBots.wiki/FAQ.md @@ -6,6 +6,7 @@ * [How can I compile my project?](#how_to_compile) * [Method ```sendMessage()``` (or other) is deprecated, what should I do?](#sendmessage_deprecated) * [Is there any example for WebHook?](#example_webhook) +* [How to use spring boot starter?](#spring_boot_starter) ## How to download photo? ## @@ -221,3 +222,34 @@ If you extend ```TelegramLongPollingCommandBot```, then use ```AbsSender.execute ## Is there any example for WebHook? ## Please see the example Bot for https://telegram.me/SnowcrashBot in the [TelegramBotsExample]() repo and also an [example bot for Sping Boot](https://github.com/UnAfraid/SpringTelegramBot) from [UnAfraid](https://github.com/UnAfraid) [here](https://github.com/UnAfraid/SpringTelegramBot/blob/master/src/main/java/com/github/unafraid/spring/bot/TelegramWebhookBot.java) + + + +## How to use spring boot starter ## +---------- +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) { + //Add this line to initialize bots context + ApiContextInitializer.init(); + + SpringApplication.run(MusicUploaderApplication.class, args); + } +} +``` + +After that your bot will look like: +```java + //Standart Spring component annotation + @Component + public class YourBotClassName 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 diff --git a/telegrambots-spring-boot-starter/README.md b/telegrambots-spring-boot-starter/README.md index 0d67db99..9d1c7910 100644 --- a/telegrambots-spring-boot-starter/README.md +++ b/telegrambots-spring-boot-starter/README.md @@ -56,7 +56,7 @@ After that your bot will look like: ```java //Standart Spring component annotation @Component - public class MusicBotImpl extends TelegramLongPollingBot { + public class YourBotName extends TelegramLongPollingBot { //Bot body. } ``` From 2930f5091be89452a686b3001f9a405680a79faf Mon Sep 17 00:00:00 2001 From: "Vyacheslav N. Boyko" Date: Thu, 19 Apr 2018 15:13:40 +0300 Subject: [PATCH 16/17] updating wiki with page containing instance of http proxy using --- TelegramBots.wiki/Using-Http-Proxy.md | 122 ++++++++++++++++++++++++++ TelegramBots.wiki/_Sidebar.md | 1 + 2 files changed, 123 insertions(+) create mode 100644 TelegramBots.wiki/Using-Http-Proxy.md diff --git a/TelegramBots.wiki/Using-Http-Proxy.md b/TelegramBots.wiki/Using-Http-Proxy.md new file mode 100644 index 00000000..502f145e --- /dev/null +++ b/TelegramBots.wiki/Using-Http-Proxy.md @@ -0,0 +1,122 @@ +### Using HTTP proxy + +HTTP proxy support implemented since version 3.6.1 + +First of all you need to override constructor with `DefaultBotOptions` argument while inheriting from `AbilityBot` or `TelegramLongPollingBot` + +```java +public class MyBot extends AbilityBot { + + protected MyBot(String botToken, String botUsername, DefaultBotOptions botOptions) { + super(botToken, botUsername, botOptions); + } + + public int creatorId() { + return 0; + } + + public Ability pingPong() { + return Ability + .builder() + .name("ping") + .info("ping pong") + .locality(ALL) + .privacy(PUBLIC) + .action(ctx -> silent.send("pong", ctx.chatId())) + .build(); + } + +} +``` + +Now you are able to set up your proxy + +#### without authentication + +```java +public class Main { + + private static String BOT_NAME = "My test bot"; + private static String BOT_TOKEN = "..." /* your bot's token here */; + + private static String PROXY_HOST = "..." /* proxy host */; + private static Integer PROXY_PORT = 3128 /* proxy port */; + + public static void main(String[] args) { + try { + + ApiContextInitializer.init(); + + // Create the TelegramBotsApi object to register your bots + TelegramBotsApi botsApi = new TelegramBotsApi(); + + // Set up Http proxy + DefaultBotOptions botOptions = ApiContext.getInstance(DefaultBotOptions.class); + + HttpHost httpHost = new HttpHost(PROXY_HOST, PROXY_PORT); + + RequestConfig requestConfig = RequestConfig.custom().setProxy(httpHost).setAuthenticationEnabled(false).build(); + botOptions.setRequestConfig(requestConfig); + botOptions.setHttpProxy(httpHost); + + // Register your newly created AbilityBot + MyBot bot = new MyBot(BOT_TOKEN, BOT_NAME, botOptions); + + botsApi.registerBot(bot); + + } catch (TelegramApiException e) { + e.printStackTrace(); + } + } +} + +``` + + +#### With authentication + +```java +public class Main { + + private static String BOT_NAME = "My test bot"; + private static String BOT_TOKEN = "..." /* your bot's token here */; + + private static String PROXY_HOST = "..." /* proxy host */; + private static Integer PROXY_PORT = 3128 /* proxy port */; + private static String PROXY_USER = "..." /* proxy user */; + private static String PROXY_PASSWORD = "..." /* proxy password */; + + public static void main(String[] args) { + try { + + ApiContextInitializer.init(); + + // Create the TelegramBotsApi object to register your bots + TelegramBotsApi botsApi = new TelegramBotsApi(); + + // Set up Http proxy + DefaultBotOptions botOptions = ApiContext.getInstance(DefaultBotOptions.class); + + CredentialsProvider credsProvider = new BasicCredentialsProvider(); + credsProvider.setCredentials( + new AuthScope(PROXY_HOST, PROXY_PORT), + new UsernamePasswordCredentials(PROXY_USER, PROXY_PASSWORD)); + + HttpHost httpHost = new HttpHost(PROXY_HOST, PROXY_PORT); + + RequestConfig requestConfig = RequestConfig.custom().setProxy(httpHost).setAuthenticationEnabled(true).build(); + botOptions.setRequestConfig(requestConfig); + botOptions.setCredentialsProvider(credsProvider); + botOptions.setHttpProxy(httpHost); + + // Register your newly created AbilityBot + MyBot bot = new MyBot(BOT_TOKEN, BOT_NAME, botOptions); + + botsApi.registerBot(bot); + + } catch (TelegramApiException e) { + e.printStackTrace(); + } + } +} +``` \ No newline at end of file diff --git a/TelegramBots.wiki/_Sidebar.md b/TelegramBots.wiki/_Sidebar.md index fc7b47b2..0bc64b51 100644 --- a/TelegramBots.wiki/_Sidebar.md +++ b/TelegramBots.wiki/_Sidebar.md @@ -1,6 +1,7 @@ * Users guide * [[Getting Started]] * [[Errors Handling]] + * [[Using HTTP Proxy]] * [[FAQ]] * AbilityBot * [[Simple Example]] From 28a9cf1fdb8b0ea7cff7a36478f473b6e3a8916d Mon Sep 17 00:00:00 2001 From: Ruben Bermudez Date: Fri, 20 Apr 2018 01:44:04 +0200 Subject: [PATCH 17/17] Version 3.6.1 --- Bots.ipr | 137 +++++++++++++++++- README.md | 2 +- TelegramBots.wiki/Changelog.md | 5 + TelegramBots.wiki/Getting-Started.md | 2 +- TelegramBots.wiki/abilities/Simple-Example.md | 2 +- pom.xml | 4 +- telegrambots-abilities/README.md | 2 +- telegrambots-abilities/pom.xml | 4 +- telegrambots-extensions/README.md | 2 +- telegrambots-extensions/pom.xml | 4 +- telegrambots-meta/pom.xml | 2 +- telegrambots-spring-boot-starter/README.md | 2 +- telegrambots-spring-boot-starter/pom.xml | 4 +- telegrambots/pom.xml | 4 +- .../bots/TelegramLongPollingBot.java | 40 +---- 15 files changed, 165 insertions(+), 51 deletions(-) diff --git a/Bots.ipr b/Bots.ipr index fa84a71b..1a6f7b10 100644 --- a/Bots.ipr +++ b/Bots.ipr @@ -20,6 +20,7 @@ + @@ -34,11 +35,12 @@ + - + @@ -409,7 +411,6 @@ - @@ -501,6 +502,7 @@ + @@ -747,6 +749,59 @@ + + @@ -1472,6 +1528,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/README.md b/README.md index 0e7e1639..e9feeea2 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Just import add the library to your project with one of these options: org.telegram telegrambots - 3.6 + 3.6.1 ``` diff --git a/TelegramBots.wiki/Changelog.md b/TelegramBots.wiki/Changelog.md index 1509ad43..1e1bfa42 100644 --- a/TelegramBots.wiki/Changelog.md +++ b/TelegramBots.wiki/Changelog.md @@ -1,3 +1,8 @@ +### 3.6.1 ### +1. Support for proxy connections +2. New module for Spring +3. Bug fixing + ### 3.6 ### 1. Support for Api Version [3.6](https://core.telegram.org/bots/api-changelog#february-13-2018) 2. Bug fixing and other improvements diff --git a/TelegramBots.wiki/Getting-Started.md b/TelegramBots.wiki/Getting-Started.md index da550b3f..96b06556 100644 --- a/TelegramBots.wiki/Getting-Started.md +++ b/TelegramBots.wiki/Getting-Started.md @@ -11,7 +11,7 @@ First you need ot get the library and add it to your project. There are few poss org.telegram telegrambots - 3.6 + 3.6.1 ``` * With **Gradle**: diff --git a/TelegramBots.wiki/abilities/Simple-Example.md b/TelegramBots.wiki/abilities/Simple-Example.md index fbd08e7f..3e2419e3 100644 --- a/TelegramBots.wiki/abilities/Simple-Example.md +++ b/TelegramBots.wiki/abilities/Simple-Example.md @@ -9,7 +9,7 @@ As with any Java project, you will need to set your dependencies. org.telegram telegrambots-abilities - 3.6 + 3.6.1 ``` * **Gradle** diff --git a/pom.xml b/pom.xml index fe5346ee..4b5ea1dc 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots pom - 3.6 + 3.6.1 telegrambots @@ -27,6 +27,6 @@ true - 3.6 + 3.6.1 \ No newline at end of file diff --git a/telegrambots-abilities/README.md b/telegrambots-abilities/README.md index 8b01640f..23a3aab2 100644 --- a/telegrambots-abilities/README.md +++ b/telegrambots-abilities/README.md @@ -18,7 +18,7 @@ Usage org.telegram telegrambots-abilities - 3.6 + 3.6.1 ``` diff --git a/telegrambots-abilities/pom.xml b/telegrambots-abilities/pom.xml index c89607e7..716b8bd6 100644 --- a/telegrambots-abilities/pom.xml +++ b/telegrambots-abilities/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.telegram telegrambots-abilities - 3.6 + 3.6.1 jar Telegram Ability Bot @@ -65,7 +65,7 @@ UTF-8 UTF-8 - 3.6 + 3.6.1 3.5 3.0.4 19.0 diff --git a/telegrambots-extensions/README.md b/telegrambots-extensions/README.md index 97dd6f2c..4e5a3d10 100644 --- a/telegrambots-extensions/README.md +++ b/telegrambots-extensions/README.md @@ -16,7 +16,7 @@ Just import add the library to your project with one of these options: org.telegram telegrambotsextensions - 3.6 + 3.6.1 ``` diff --git a/telegrambots-extensions/pom.xml b/telegrambots-extensions/pom.xml index a6f41734..35d22cd6 100644 --- a/telegrambots-extensions/pom.xml +++ b/telegrambots-extensions/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.telegram telegrambotsextensions - 3.6 + 3.6.1 jar Telegram Bots Extensions @@ -59,7 +59,7 @@ UTF-8 UTF-8 - 3.6 + 3.6.1 diff --git a/telegrambots-meta/pom.xml b/telegrambots-meta/pom.xml index 3bb47ed2..a37020bc 100644 --- a/telegrambots-meta/pom.xml +++ b/telegrambots-meta/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.telegram telegrambots-meta - 3.6 + 3.6.1 jar Telegram Bots Meta diff --git a/telegrambots-spring-boot-starter/README.md b/telegrambots-spring-boot-starter/README.md index 9d1c7910..8bb3f2a8 100644 --- a/telegrambots-spring-boot-starter/README.md +++ b/telegrambots-spring-boot-starter/README.md @@ -18,7 +18,7 @@ Usage org.telegram telegrambots-spring-boot-starter - 3.6 + 3.6.1 ``` diff --git a/telegrambots-spring-boot-starter/pom.xml b/telegrambots-spring-boot-starter/pom.xml index 301ee6b1..b40ff9c9 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 - 3.6 + 3.6.1 jar Telegram Bots Spring Boot Starter @@ -59,7 +59,7 @@ UTF-8 UTF-8 - 3.6 + 3.6.1 1.5.10.RELEASE diff --git a/telegrambots/pom.xml b/telegrambots/pom.xml index cf56f9bb..95d1f3e3 100644 --- a/telegrambots/pom.xml +++ b/telegrambots/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.telegram telegrambots - 3.6 + 3.6.1 jar Telegram Bots @@ -66,7 +66,7 @@ 2.8.7 2.8.0 2.5 - 3.6 + 3.6.1 diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingBot.java b/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingBot.java index 25b99dfc..4ed163c7 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingBot.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingBot.java @@ -1,25 +1,11 @@ package org.telegram.telegrambots.bots; -import org.apache.http.HttpEntity; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.conn.ssl.NoopHostnameVerifier; -import org.apache.http.entity.BufferedHttpEntity; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.util.EntityUtils; -import org.json.JSONException; -import org.json.JSONObject; -import org.telegram.telegrambots.ApiConstants; import org.telegram.telegrambots.ApiContext; -import org.telegram.telegrambots.api.methods.updates.SetWebhook; +import org.telegram.telegrambots.api.methods.updates.DeleteWebhook; +import org.telegram.telegrambots.exceptions.TelegramApiException; import org.telegram.telegrambots.exceptions.TelegramApiRequestException; -import org.telegram.telegrambots.facilities.TelegramHttpClientBuilder; import org.telegram.telegrambots.generics.LongPollingBot; -import java.io.IOException; -import java.nio.charset.StandardCharsets; - /** * @author Ruben Bermudez * @version 1.0 @@ -37,23 +23,13 @@ public abstract class TelegramLongPollingBot extends DefaultAbsSender implements @Override public void clearWebhook() throws TelegramApiRequestException { - try (CloseableHttpClient httpclient = TelegramHttpClientBuilder.build(getOptions())) { - String url = getOptions().getBaseUrl() + getBotToken() + "/" + SetWebhook.PATH; - HttpGet httpGet = new HttpGet(url); - httpGet.setConfig(getOptions().getRequestConfig()); - try (CloseableHttpResponse response = httpclient.execute(httpGet)) { - HttpEntity ht = response.getEntity(); - BufferedHttpEntity buf = new BufferedHttpEntity(ht); - String responseContent = EntityUtils.toString(buf, StandardCharsets.UTF_8); - JSONObject jsonObject = new JSONObject(responseContent); - if (!jsonObject.getBoolean(ApiConstants.RESPONSE_FIELD_OK)) { - throw new TelegramApiRequestException("Error removing old webhook", jsonObject); - } + try { + boolean result = execute(new DeleteWebhook()); + if (!result) { + throw new TelegramApiRequestException("Error removing old webhook"); } - } catch (JSONException e) { - throw new TelegramApiRequestException("Error deserializing setWebhook method response", e); - } catch (IOException e) { - throw new TelegramApiRequestException("Error executing setWebook method", e); + } catch (TelegramApiException e) { + throw new TelegramApiRequestException("Error removing old webhook", e); } }