From e616ebbddb754c5b86a462cae8d40e1998e13244 Mon Sep 17 00:00:00 2001 From: "j.r@wiuwiu.de" Date: Thu, 27 Jun 2019 20:51:03 +0200 Subject: [PATCH 01/13] Made usernames case insensitive Fixed because username in Telegram are not case sensitive, eg @fooBar is the same user as @Foobar --- .../extensions/bots/commandbot/commands/CommandRegistry.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/commandbot/commands/CommandRegistry.java b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/commandbot/commands/CommandRegistry.java index fdd3771b..f06e15fb 100644 --- a/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/commandbot/commands/CommandRegistry.java +++ b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/commandbot/commands/CommandRegistry.java @@ -8,6 +8,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.function.BiConsumer; +import java.util.regex.Pattern; /** * This class manages all the commands for a bot. You can register and deregister commands on demand @@ -122,7 +123,7 @@ public final class CommandRegistry implements ICommandRegistry { */ private String removeUsernameFromCommandIfNeeded(String command) { if (allowCommandsWithUsername) { - return command.replace("@" + botUsername, "").trim(); + return command.replaceAll("(?i)@" + Pattern.quote(botUsername), "").trim(); } return command; } From 01a7e7dc2120fbe010b1626661003fe692b3b53e Mon Sep 17 00:00:00 2001 From: "j.r@wiuwiu.de" Date: Thu, 27 Jun 2019 20:58:16 +0200 Subject: [PATCH 02/13] Fixed bot username Let the programmer of the bot decide where the username should come from --- .../bots/commandbot/TelegramLongPollingCommandBot.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/commandbot/TelegramLongPollingCommandBot.java b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/commandbot/TelegramLongPollingCommandBot.java index 8bb39742..88f8b5c5 100644 --- a/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/commandbot/TelegramLongPollingCommandBot.java +++ b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/commandbot/TelegramLongPollingCommandBot.java @@ -58,7 +58,7 @@ public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingB public TelegramLongPollingCommandBot(DefaultBotOptions options, boolean allowCommandsWithUsername, String botUsername) { super(options); this.botUsername = botUsername; - this.commandRegistry = new CommandRegistry(allowCommandsWithUsername, botUsername); + this.commandRegistry = new CommandRegistry(allowCommandsWithUsername, this.getBotUsername()); } @Override @@ -143,9 +143,7 @@ public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingB * @return Bot username */ @Override - public final String getBotUsername() { - return botUsername; - } + public abstract String getBotUsername(); /** * Process all updates, that are not commands. From 91508aeebbdead012bf698b725d180d3c674f7f1 Mon Sep 17 00:00:00 2001 From: "j.r@wiuwiu.de" Date: Thu, 27 Jun 2019 21:06:08 +0200 Subject: [PATCH 03/13] Removed unnecesarry botUsername argument --- .../commandbot/TelegramLongPollingCommandBot.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/commandbot/TelegramLongPollingCommandBot.java b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/commandbot/TelegramLongPollingCommandBot.java index 88f8b5c5..05de2c72 100644 --- a/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/commandbot/TelegramLongPollingCommandBot.java +++ b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/commandbot/TelegramLongPollingCommandBot.java @@ -22,16 +22,14 @@ import java.util.function.BiConsumer; */ public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingBot implements ICommandRegistry { private final CommandRegistry commandRegistry; - private String botUsername; /** * Creates a TelegramLongPollingCommandBot using default options * Use ICommandRegistry's methods on this bot to register commands * - * @param botUsername Username of the bot */ - public TelegramLongPollingCommandBot(String botUsername) { - this(ApiContext.getInstance(DefaultBotOptions.class), botUsername); + public TelegramLongPollingCommandBot() { + this(ApiContext.getInstance(DefaultBotOptions.class)); } /** @@ -40,10 +38,9 @@ public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingB * Use ICommandRegistry's methods on this bot to register commands * * @param options Bot options - * @param botUsername Username of the bot */ - public TelegramLongPollingCommandBot(DefaultBotOptions options, String botUsername) { - this(options, true, botUsername); + public TelegramLongPollingCommandBot(DefaultBotOptions options) { + this(options, true); } /** @@ -53,11 +50,9 @@ public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingB * @param options Bot options * @param allowCommandsWithUsername true to allow commands with parameters (default), * false otherwise - * @param botUsername bot username of this bot */ - public TelegramLongPollingCommandBot(DefaultBotOptions options, boolean allowCommandsWithUsername, String botUsername) { + public TelegramLongPollingCommandBot(DefaultBotOptions options, boolean allowCommandsWithUsername) { super(options); - this.botUsername = botUsername; this.commandRegistry = new CommandRegistry(allowCommandsWithUsername, this.getBotUsername()); } From ef1bd09a6ae312da059076e82de2ffafd98f45e8 Mon Sep 17 00:00:00 2001 From: UnAfraid Date: Mon, 9 Sep 2019 20:10:26 +0300 Subject: [PATCH 04/13] Replacing log4j with slf4j --- pom.xml | 14 +++++++------- telegrambots-abilities/pom.xml | 11 +++++++++++ .../abilitybots/api/bot/BaseAbilityBot.java | 6 +++--- .../telegram/abilitybots/api/db/MapDBContext.java | 6 +++--- .../telegram/abilitybots/api/objects/Ability.java | 6 +++--- .../abilitybots/api/sender/SilentSender.java | 6 +++--- .../org/telegram/telegrambots/meta/ApiContext.java | 6 +++--- .../exceptions/TelegramApiRequestException.java | 8 ++++---- .../starter/TelegramBotInitializer.java | 6 +++--- .../updatesreceivers/DefaultBotSession.java | 12 ++++++------ .../telegrambots/updatesreceivers/RestApi.java | 6 +++--- 11 files changed, 49 insertions(+), 38 deletions(-) diff --git a/pom.xml b/pom.xml index 37193d47..c6869154 100644 --- a/pom.xml +++ b/pom.xml @@ -39,7 +39,7 @@ 3.0.0 2.9.9 2.9.9.1 - 2.12.0 + 1.7.28 @@ -78,9 +78,9 @@ ${jackson.version} - org.apache.logging.log4j - log4j-core - ${log4j.version} + org.slf4j + slf4j-api + ${slf4j.version} @@ -108,9 +108,9 @@ - org.apache.logging.log4j - log4j-core - ${log4j.version} + org.slf4j + slf4j-api + ${slf4j.version} \ No newline at end of file diff --git a/telegrambots-abilities/pom.xml b/telegrambots-abilities/pom.xml index 9f8dc9b5..7f420e0a 100644 --- a/telegrambots-abilities/pom.xml +++ b/telegrambots-abilities/pom.xml @@ -78,6 +78,7 @@ 3.9 3.0.7 + 2.12.1 @@ -102,6 +103,16 @@ + + org.apache.logging.log4j + log4j-slf4j-impl + ${log4j.version} + + + org.apache.logging.log4j + log4j-core + ${log4j.version} + 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 d5f9c0ef..ca94dc0c 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 @@ -6,9 +6,9 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ListMultimap; import com.google.common.collect.Multimap; import org.apache.commons.io.IOUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.telegram.abilitybots.api.db.DBContext; import org.telegram.abilitybots.api.objects.Ability; import org.telegram.abilitybots.api.objects.Locality; @@ -139,7 +139,7 @@ import static org.telegram.abilitybots.api.util.AbilityUtils.stripTag; */ @SuppressWarnings({"ConfusingArgumentToVarargsMethod", "UnusedReturnValue", "WeakerAccess", "unused", "ConstantConditions"}) public abstract class BaseAbilityBot extends DefaultAbsSender implements AbilityExtension { - private static final Logger log = LogManager.getLogger(BaseAbilityBot.class); + private static final Logger log = LoggerFactory.getLogger(BaseAbilityBot.class); // DB objects public static final String ADMINS = "ADMINS"; diff --git a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/db/MapDBContext.java b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/db/MapDBContext.java index a6977917..c39a7b3f 100644 --- a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/db/MapDBContext.java +++ b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/db/MapDBContext.java @@ -3,12 +3,12 @@ package org.telegram.abilitybots.api.db; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.mapdb.Atomic; import org.mapdb.DB; import org.mapdb.DBMaker; import org.mapdb.Serializer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.telegram.abilitybots.api.util.Pair; import java.io.IOException; @@ -35,7 +35,7 @@ import static org.mapdb.Serializer.JAVA; */ @SuppressWarnings({"unchecked", "WeakerAccess"}) public class MapDBContext implements DBContext { - private static final Logger log = LogManager.getLogger(MapDBContext.class); + private static final Logger log = LoggerFactory.getLogger(MapDBContext.class); private final DB db; private final ObjectMapper objectMapper; diff --git a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/objects/Ability.java b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/objects/Ability.java index c3004c8b..fb6b27a3 100644 --- a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/objects/Ability.java +++ b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/objects/Ability.java @@ -2,8 +2,8 @@ package org.telegram.abilitybots.api.objects; import com.google.common.base.MoreObjects; import com.google.common.base.Objects; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.telegram.telegrambots.meta.api.objects.Update; import java.util.Arrays; @@ -35,7 +35,7 @@ import static org.apache.commons.lang3.StringUtils.*; * @author Abbas Abou Daya */ public final class Ability { - private static final Logger log = LogManager.getLogger(Ability.class); + private static final Logger log = LoggerFactory.getLogger(Ability.class); private final String name; private final String info; diff --git a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/sender/SilentSender.java b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/sender/SilentSender.java index b5d48bfb..2745f757 100644 --- a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/sender/SilentSender.java +++ b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/sender/SilentSender.java @@ -1,7 +1,7 @@ package org.telegram.abilitybots.api.sender; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.telegram.telegrambots.meta.api.methods.BotApiMethod; import org.telegram.telegrambots.meta.api.methods.send.SendMessage; import org.telegram.telegrambots.meta.api.objects.Message; @@ -18,7 +18,7 @@ import java.util.Optional; * @author Abbas Abou Daya */ public class SilentSender { - private static final Logger log = LogManager.getLogger(SilentSender.class); + private static final Logger log = LoggerFactory.getLogger(SilentSender.class); private final MessageSender sender; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/ApiContext.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/ApiContext.java index a5a2e0ce..3859fa91 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/ApiContext.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/ApiContext.java @@ -4,8 +4,8 @@ import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.Singleton; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.text.MessageFormat; import java.util.HashMap; @@ -16,7 +16,7 @@ import java.util.Map; * @version 1.0 */ public class ApiContext { - private static final Logger log = LogManager.getLogger(ApiContext.class); + private static final Logger log = LoggerFactory.getLogger(ApiContext.class); private static final Object lock = new Object(); private static Injector INJECTOR; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/exceptions/TelegramApiRequestException.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/exceptions/TelegramApiRequestException.java index 01d52b38..1dd7bcf7 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/exceptions/TelegramApiRequestException.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/exceptions/TelegramApiRequestException.java @@ -18,9 +18,9 @@ package org.telegram.telegrambots.meta.exceptions; import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.telegram.telegrambots.meta.api.objects.ApiResponse; import org.telegram.telegrambots.meta.api.objects.ResponseParameters; @@ -33,7 +33,7 @@ import java.io.IOException; * Exception thrown when something goes wrong in the api */ public class TelegramApiRequestException extends TelegramApiException { - private static final Logger log = LogManager.getLogger(TelegramApiRequestException.class); + private static final Logger log = LoggerFactory.getLogger(TelegramApiRequestException.class); private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); private static final String ERRORDESCRIPTIONFIELD = "description"; @@ -56,7 +56,7 @@ public class TelegramApiRequestException extends TelegramApiException { try { parameters = OBJECT_MAPPER.readValue(object.getJSONObject(PARAMETERSFIELD).toString(), ResponseParameters.class); } catch (IOException e) { - log.fatal(e.getLocalizedMessage(), e); + log.error(e.getLocalizedMessage(), e); } } } 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 951dc3b8..c0911641 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,7 +1,7 @@ package org.telegram.telegrambots.starter; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.InitializingBean; import org.telegram.telegrambots.meta.TelegramBotsApi; import org.telegram.telegrambots.meta.exceptions.TelegramApiException; @@ -21,7 +21,7 @@ import static java.lang.String.format; * Receives all beand which are #LongPollingBot and #WebhookBot and register them in #TelegramBotsApi. */ public class TelegramBotInitializer implements InitializingBean { - private static final Logger log = LogManager.getLogger(TelegramBotInitializer.class); + private static final Logger log = LoggerFactory.getLogger(TelegramBotInitializer.class); private final TelegramBotsApi telegramBotsApi; private final List longPollingBots; 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 319e39ac..78a84d8d 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/DefaultBotSession.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/DefaultBotSession.java @@ -11,9 +11,9 @@ import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.util.EntityUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.json.JSONException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.telegram.telegrambots.meta.ApiConstants; import org.telegram.telegrambots.meta.api.methods.updates.GetUpdates; import org.telegram.telegrambots.meta.api.objects.Update; @@ -40,7 +40,7 @@ import static org.telegram.telegrambots.Constants.SOCKET_TIMEOUT; * Thread to request updates with active wait */ public class DefaultBotSession implements BotSession { - private static final Logger log = LogManager.getLogger(DefaultBotSession.class); + private static final Logger log = LoggerFactory.getLogger(DefaultBotSession.class); private AtomicBoolean running = new AtomicBoolean(false); @@ -207,7 +207,7 @@ public class DefaultBotSession implements BotSession { log.debug(e.getLocalizedMessage(), e); interrupt(); } catch (Exception global) { - log.fatal(global.getLocalizedMessage(), global); + log.error(global.getLocalizedMessage(), global); try { synchronized (lock) { lock.wait(exponentialBackOff.nextBackOffMillis()); @@ -263,7 +263,7 @@ public class DefaultBotSession implements BotSession { } } } catch (SocketException | InvalidObjectException | TelegramApiRequestException e) { - log.fatal(e.getLocalizedMessage(), e); + log.error(e.getLocalizedMessage(), e); } catch (SocketTimeoutException e) { log.info(e.getLocalizedMessage(), e); } catch (InterruptedException e) { @@ -309,7 +309,7 @@ public class DefaultBotSession implements BotSession { log.debug(e.getLocalizedMessage(), e); interrupt(); } catch (Exception e) { - log.fatal(e.getLocalizedMessage(), e); + log.error(e.getLocalizedMessage(), e); } } log.debug("Handler thread has being closed"); diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/RestApi.java b/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/RestApi.java index 35fbc7f1..a6b4725f 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/RestApi.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/RestApi.java @@ -1,7 +1,7 @@ package org.telegram.telegrambots.updatesreceivers; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.telegram.telegrambots.meta.api.methods.BotApiMethod; import org.telegram.telegrambots.meta.api.objects.Update; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; @@ -24,7 +24,7 @@ import java.util.concurrent.ConcurrentHashMap; */ @Path("callback") public class RestApi { - private static final Logger log = LogManager.getLogger(RestApi.class); + private static final Logger log = LoggerFactory.getLogger(RestApi.class); private final ConcurrentHashMap callbacks = new ConcurrentHashMap<>(); From e526b9db142624c47e168c766b36b0357160ab68 Mon Sep 17 00:00:00 2001 From: "j.r@wiuwiu.de" Date: Sun, 13 Oct 2019 15:12:22 +0200 Subject: [PATCH 05/13] Added deprecated constructor with the old style --- .../TelegramLongPollingCommandBot.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/commandbot/TelegramLongPollingCommandBot.java b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/commandbot/TelegramLongPollingCommandBot.java index 05de2c72..1796b364 100644 --- a/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/commandbot/TelegramLongPollingCommandBot.java +++ b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/commandbot/TelegramLongPollingCommandBot.java @@ -22,6 +22,7 @@ import java.util.function.BiConsumer; */ public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingBot implements ICommandRegistry { private final CommandRegistry commandRegistry; + private String botUsername; /** * Creates a TelegramLongPollingCommandBot using default options @@ -32,6 +33,19 @@ public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingB this(ApiContext.getInstance(DefaultBotOptions.class)); } + /** + * Creates a TelegramLongPollingCommandBot using default options + * Use ICommandRegistry's methods on this bot to register commands + * + * @param botUsername Username of the bot + * @deprecated Overwrite {@link #getBotUsername() getBotUsername} instead + */ + @Deprecated + public TelegramLongPollingCommandBot(String botUsername){ + this(); + this.botUsername = botUsername; + } + /** * Creates a TelegramLongPollingCommandBot with custom options and allowing commands with * usernames @@ -138,7 +152,9 @@ public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingB * @return Bot username */ @Override - public abstract String getBotUsername(); + public String getBotUsername(){ + return this.botUsername; + }; /** * Process all updates, that are not commands. From 2d27f9e60f68820c58c30fc846a6ba453f86e017 Mon Sep 17 00:00:00 2001 From: UnAfraid Date: Mon, 14 Oct 2019 20:08:16 +0300 Subject: [PATCH 06/13] Post merge fixes --- .../java/org/telegram/abilitybots/api/bot/BaseAbilityBot.java | 2 -- 1 file changed, 2 deletions(-) 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 616a5067..a237616d 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 @@ -6,8 +6,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ListMultimap; import com.google.common.collect.Multimap; import org.apache.commons.io.IOUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; From 7cfcca3ae37b250c1ad8124d64108baf7ad77afe Mon Sep 17 00:00:00 2001 From: rubenlagus Date: Tue, 10 Sep 2019 22:29:10 +0100 Subject: [PATCH 07/13] Fix error importing project --- .gitignore | 3 + README.md | 8 +- TelegramBots.wiki/Changelog.md | 3 + TelegramBots.wiki/Getting-Started.md | 4 +- TelegramBots.wiki/abilities/Simple-Example.md | 2 +- pom.xml | 87 ++++++++++++++++++- telegrambots-abilities/README.md | 8 +- telegrambots-abilities/pom.xml | 4 +- .../src/test/resources/log4j2-test.xml | 19 ++++ telegrambots-chat-session-bot/README.md | 2 +- telegrambots-chat-session-bot/pom.xml | 4 +- telegrambots-extensions/README.md | 4 +- telegrambots-extensions/pom.xml | 4 +- telegrambots-meta/pom.xml | 2 +- .../src/test/resources/log4j2-test.xml | 19 ++++ telegrambots-spring-boot-starter/pom.xml | 4 +- .../src/test/resources/log4j2-test.xml | 19 ++++ telegrambots/pom.xml | 4 +- .../src/test/resources/log4j2-test.xml | 19 ++++ 19 files changed, 191 insertions(+), 28 deletions(-) create mode 100644 telegrambots-abilities/src/test/resources/log4j2-test.xml create mode 100644 telegrambots-meta/src/test/resources/log4j2-test.xml create mode 100644 telegrambots-spring-boot-starter/src/test/resources/log4j2-test.xml create mode 100644 telegrambots/src/test/resources/log4j2-test.xml diff --git a/.gitignore b/.gitignore index 737c7ac7..c0b06615 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,6 @@ copyright/ #File System specific files .DS_STORE + +# Default ignored files +/Bots.iws \ No newline at end of file diff --git a/README.md b/README.md index 5d45b712..15de0465 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.4.0 + 4.4.0.1 ``` ```gradle - compile "org.telegram:telegrambots:4.4.0" + compile "org.telegram:telegrambots:4.4.0.1" ``` - 2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/4.4.0) - 3. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/4.4.0) + 2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/4.4.0.1) + 3. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/4.4.0.1) In order to use Long Polling mode, just create your own bot extending `org.telegram.telegrambots.bots.TelegramLongPollingBot`. diff --git a/TelegramBots.wiki/Changelog.md b/TelegramBots.wiki/Changelog.md index d234ab7c..4f686e71 100644 --- a/TelegramBots.wiki/Changelog.md +++ b/TelegramBots.wiki/Changelog.md @@ -1,3 +1,6 @@ +### 4.4.0.1 ### +1. Bug fix when importing the project + ### 4.4.0 ### 1. Update Api version [4.4](https://core.telegram.org/bots/api-changelog#july-29-2019) 2. Removed BotLogger, replaced with [log4j2](https://logging.apache.org/log4j/2.x/) diff --git a/TelegramBots.wiki/Getting-Started.md b/TelegramBots.wiki/Getting-Started.md index e0878bbe..0f9d2a6c 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.4.0 + 4.4.0.1 ``` * With **Gradle**: ```groovy - compile group: 'org.telegram', name: 'telegrambots', version: '4.4.0' + compile group: 'org.telegram', name: 'telegrambots', version: '4.4.0.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 3aa89b8a..04bf57f5 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 - 4.4.0 + 4.4.0.1 ``` * **Gradle** diff --git a/pom.xml b/pom.xml index c6869154..5498fb4d 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots pom - 4.4.0 + 4.4.0.1 telegrambots @@ -26,14 +26,47 @@ + Bots + 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 + + + + + rberlopez@gmail.com + Ruben Bermudez + https://github.com/rubenlagus + rubenlagus + + + + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + 11 8 ${java.version} ${java.version} - true - 5.5.1 3.0.0 3.0.0 @@ -113,4 +146,52 @@ ${slf4j.version} + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.6 + + + sign-artifacts + verify + + sign + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.8 + true + + ossrh + https://oss.sonatype.org/ + true + + + + org.apache.maven.plugins + maven-enforcer-plugin + 3.0.0-M2 + + + enforce-versions + + enforce + + + + + + + + + + + \ No newline at end of file diff --git a/telegrambots-abilities/README.md b/telegrambots-abilities/README.md index d43fa96c..483334c0 100644 --- a/telegrambots-abilities/README.md +++ b/telegrambots-abilities/README.md @@ -18,19 +18,19 @@ Usage org.telegram telegrambots-abilities - 4.4.0 + 4.4.0.1 ``` **Gradle** ```gradle - compile "org.telegram:telegrambots-abilities:4.4.0" + compile "org.telegram:telegrambots-abilities:4.4.0.1" ``` -**JitPack** - [JitPack](https://jitpack.io/#rubenlagus/TelegramBots/v4.4.0) +**JitPack** - [JitPack](https://jitpack.io/#rubenlagus/TelegramBots/v4.4.0.1) -**Plain imports** - [Here](https://github.com/rubenlagus/TelegramBots/releases/tag/v4.4.0) +**Plain imports** - [Here](https://github.com/rubenlagus/TelegramBots/releases/tag/v4.4.0.1) Motivation ---------- diff --git a/telegrambots-abilities/pom.xml b/telegrambots-abilities/pom.xml index 7f420e0a..7325fd3a 100644 --- a/telegrambots-abilities/pom.xml +++ b/telegrambots-abilities/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 4.4.0 + 4.4.0.1 telegrambots-abilities @@ -85,7 +85,7 @@ org.telegram telegrambots - 4.4.0 + 4.4.0.1 org.apache.commons diff --git a/telegrambots-abilities/src/test/resources/log4j2-test.xml b/telegrambots-abilities/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000..8054f7f7 --- /dev/null +++ b/telegrambots-abilities/src/test/resources/log4j2-test.xml @@ -0,0 +1,19 @@ + + + + %d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} [%t] %-5level %logger{36} - %msg%n + App + + + + + + + + + + + + + + \ No newline at end of file diff --git a/telegrambots-chat-session-bot/README.md b/telegrambots-chat-session-bot/README.md index 212ceb0a..f0616b41 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.4.0 + 4.4.0.1 ``` diff --git a/telegrambots-chat-session-bot/pom.xml b/telegrambots-chat-session-bot/pom.xml index 3765c8f4..606db6ac 100644 --- a/telegrambots-chat-session-bot/pom.xml +++ b/telegrambots-chat-session-bot/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 4.4.0 + 4.4.0.1 telegrambots-chat-session-bot @@ -84,7 +84,7 @@ org.telegram telegrambots - 4.4.0 + 4.4.0.1 diff --git a/telegrambots-extensions/README.md b/telegrambots-extensions/README.md index 6e1d2173..448d404c 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.4.0 + 4.4.0.1 ``` 2. Using Gradle: ```gradle - compile "org.telegram:telegrambotsextensions:4.4.0" + compile "org.telegram:telegrambotsextensions:4.4.0.1" ``` \ No newline at end of file diff --git a/telegrambots-extensions/pom.xml b/telegrambots-extensions/pom.xml index b5990489..ea44f782 100644 --- a/telegrambots-extensions/pom.xml +++ b/telegrambots-extensions/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 4.4.0 + 4.4.0.1 telegrambotsextensions @@ -75,7 +75,7 @@ org.telegram telegrambots - 4.4.0 + 4.4.0.1 diff --git a/telegrambots-meta/pom.xml b/telegrambots-meta/pom.xml index c2eb4616..78b37e06 100644 --- a/telegrambots-meta/pom.xml +++ b/telegrambots-meta/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 4.4.0 + 4.4.0.1 telegrambots-meta diff --git a/telegrambots-meta/src/test/resources/log4j2-test.xml b/telegrambots-meta/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000..8054f7f7 --- /dev/null +++ b/telegrambots-meta/src/test/resources/log4j2-test.xml @@ -0,0 +1,19 @@ + + + + %d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} [%t] %-5level %logger{36} - %msg%n + App + + + + + + + + + + + + + + \ No newline at end of file diff --git a/telegrambots-spring-boot-starter/pom.xml b/telegrambots-spring-boot-starter/pom.xml index c28a9bdf..f2a6a2b9 100644 --- a/telegrambots-spring-boot-starter/pom.xml +++ b/telegrambots-spring-boot-starter/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 4.4.0 + 4.4.0.1 telegrambots-spring-boot-starter @@ -78,7 +78,7 @@ org.telegram telegrambots - 4.4.0 + 4.4.0.1 org.springframework.boot diff --git a/telegrambots-spring-boot-starter/src/test/resources/log4j2-test.xml b/telegrambots-spring-boot-starter/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000..8054f7f7 --- /dev/null +++ b/telegrambots-spring-boot-starter/src/test/resources/log4j2-test.xml @@ -0,0 +1,19 @@ + + + + %d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} [%t] %-5level %logger{36} - %msg%n + App + + + + + + + + + + + + + + \ No newline at end of file diff --git a/telegrambots/pom.xml b/telegrambots/pom.xml index 1143fd5e..cb8e45ef 100644 --- a/telegrambots/pom.xml +++ b/telegrambots/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 4.4.0 + 4.4.0.1 telegrambots @@ -95,7 +95,7 @@ org.telegram telegrambots-meta - 4.4.0 + 4.4.0.1 com.fasterxml.jackson.core diff --git a/telegrambots/src/test/resources/log4j2-test.xml b/telegrambots/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000..8054f7f7 --- /dev/null +++ b/telegrambots/src/test/resources/log4j2-test.xml @@ -0,0 +1,19 @@ + + + + %d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} [%t] %-5level %logger{36} - %msg%n + App + + + + + + + + + + + + + + \ No newline at end of file From 44c814256d61615dca5626ac186d1eb6166ef2ae Mon Sep 17 00:00:00 2001 From: rubenlagus Date: Tue, 10 Sep 2019 23:44:28 +0100 Subject: [PATCH 08/13] Bug fixes and pom dependencies upgrades --- Bots.ipr | 367 +++++++++--------- pom.xml | 10 +- telegrambots-meta/pom.xml | 4 +- .../meta/api/objects/ChatPermissions.java | 32 ++ telegrambots-spring-boot-starter/pom.xml | 4 +- telegrambots/pom.xml | 8 +- .../telegrambots/bots/DefaultAbsSender.java | 15 +- .../facilities/TelegramHttpClientBuilder.java | 3 +- .../updatesreceivers/DefaultBotSession.java | 23 +- .../telegrambots/util/WebhookUtils.java | 24 +- 10 files changed, 268 insertions(+), 222 deletions(-) diff --git a/Bots.ipr b/Bots.ipr index 48a1815b..3cba11c9 100644 --- a/Bots.ipr +++ b/Bots.ipr @@ -22,10 +22,10 @@ - - - + + + @@ -920,26 +920,15 @@ - + - + - + - - - - - - - - - - - - + @@ -1008,15 +997,15 @@ - + - + - + - + @@ -1129,37 +1118,48 @@ - + - + - + - + - + - + - + - + - + - + - + - + + + + + + + + + + + + @@ -1184,17 +1184,6 @@ - - - - - - - - - - - @@ -1250,37 +1239,37 @@ - + - + - + - + - + - + - + - + - + - + - + - + @@ -1415,15 +1404,15 @@ - + - + - + - + @@ -1437,15 +1426,15 @@ - + - + - + - + @@ -1525,59 +1514,59 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -1591,147 +1580,147 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -1800,48 +1789,48 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -1921,103 +1910,103 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/pom.xml b/pom.xml index 5498fb4d..df092cfe 100644 --- a/pom.xml +++ b/pom.xml @@ -67,12 +67,13 @@ ${java.version} ${java.version} - 5.5.1 + 5.5.2 3.0.0 3.0.0 2.9.9 - 2.9.9.1 + 2.9.9.2 1.7.28 + 1.3.5 @@ -115,6 +116,11 @@ slf4j-api ${slf4j.version} + + jakarta.annotation + jakarta.annotation-api + ${jakarta.annotation.version} + diff --git a/telegrambots-meta/pom.xml b/telegrambots-meta/pom.xml index 78b37e06..e60b3e72 100644 --- a/telegrambots-meta/pom.xml +++ b/telegrambots-meta/pom.xml @@ -70,10 +70,10 @@ UTF-8 UTF-8 4.2.2 - 2.9.9 + 2.9.9.2 2.9.9 20180813 - 28.0-jre + 28.1-jre diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatPermissions.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatPermissions.java index 7a42bd41..97c48de7 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatPermissions.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatPermissions.java @@ -73,6 +73,38 @@ public class ChatPermissions implements BotApiObject { return canPinMessages; } + public void setCanSendMessages(Boolean canSendMessages) { + this.canSendMessages = canSendMessages; + } + + public void setGetCanSendMediaMessages(Boolean getCanSendMediaMessages) { + this.getCanSendMediaMessages = getCanSendMediaMessages; + } + + public void setCanSendPolls(Boolean canSendPolls) { + this.canSendPolls = canSendPolls; + } + + public void setCanSendOtherMessages(Boolean canSendOtherMessages) { + this.canSendOtherMessages = canSendOtherMessages; + } + + public void setCanAddWebPagePreviews(Boolean canAddWebPagePreviews) { + this.canAddWebPagePreviews = canAddWebPagePreviews; + } + + public void setCanChangeInfo(Boolean canChangeInfo) { + this.canChangeInfo = canChangeInfo; + } + + public void setCanInviteUsers(Boolean canInviteUsers) { + this.canInviteUsers = canInviteUsers; + } + + public void setCanPinMessages(Boolean canPinMessages) { + this.canPinMessages = canPinMessages; + } + @Override public String toString() { return "ChatPermissions{" + diff --git a/telegrambots-spring-boot-starter/pom.xml b/telegrambots-spring-boot-starter/pom.xml index f2a6a2b9..0ba8111f 100644 --- a/telegrambots-spring-boot-starter/pom.xml +++ b/telegrambots-spring-boot-starter/pom.xml @@ -70,7 +70,7 @@ UTF-8 UTF-8 - 2.1.6.RELEASE + 2.1.8.RELEASE @@ -103,7 +103,7 @@ org.assertj assertj-core test - 3.13.1 + 3.13.2 diff --git a/telegrambots/pom.xml b/telegrambots/pom.xml index cb8e45ef..113bc407 100644 --- a/telegrambots/pom.xml +++ b/telegrambots/pom.xml @@ -70,11 +70,11 @@ UTF-8 UTF-8 - 2.29 + 2.29.1 1.19.3 - 4.5.9 + 4.5.10 20180813 - 2.9.9 + 2.9.9.2 2.9.9 2.6 @@ -105,7 +105,7 @@ com.fasterxml.jackson.jaxrs jackson-jaxrs-json-provider - ${jackson.version} + ${jacksonbase.version} com.fasterxml.jackson.module 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 b94d3a09..71c6d4ed 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java @@ -6,7 +6,6 @@ import org.apache.http.HttpEntity; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.BufferedHttpEntity; import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; import org.apache.http.entity.mime.MultipartEntityBuilder; @@ -16,7 +15,15 @@ import org.telegram.telegrambots.facilities.TelegramHttpClientBuilder; import org.telegram.telegrambots.facilities.filedownloader.TelegramFileDownloader; import org.telegram.telegrambots.meta.api.methods.BotApiMethod; import org.telegram.telegrambots.meta.api.methods.groupadministration.SetChatPhoto; -import org.telegram.telegrambots.meta.api.methods.send.*; +import org.telegram.telegrambots.meta.api.methods.send.SendAnimation; +import org.telegram.telegrambots.meta.api.methods.send.SendAudio; +import org.telegram.telegrambots.meta.api.methods.send.SendDocument; +import org.telegram.telegrambots.meta.api.methods.send.SendMediaGroup; +import org.telegram.telegrambots.meta.api.methods.send.SendPhoto; +import org.telegram.telegrambots.meta.api.methods.send.SendSticker; +import org.telegram.telegrambots.meta.api.methods.send.SendVideo; +import org.telegram.telegrambots.meta.api.methods.send.SendVideoNote; +import org.telegram.telegrambots.meta.api.methods.send.SendVoice; import org.telegram.telegrambots.meta.api.methods.stickers.AddStickerToSet; import org.telegram.telegrambots.meta.api.methods.stickers.CreateNewStickerSet; import org.telegram.telegrambots.meta.api.methods.stickers.UploadStickerFile; @@ -729,9 +736,7 @@ public abstract class DefaultAbsSender extends AbsSender { private String sendHttpPostRequest(HttpPost httppost) throws IOException { try (CloseableHttpResponse response = httpClient.execute(httppost, options.getHttpContext())) { - HttpEntity ht = response.getEntity(); - BufferedHttpEntity buf = new BufferedHttpEntity(ht); - return EntityUtils.toString(buf, StandardCharsets.UTF_8); + return EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8); } } diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/facilities/TelegramHttpClientBuilder.java b/telegrambots/src/main/java/org/telegram/telegrambots/facilities/TelegramHttpClientBuilder.java index 38a3a17a..3993fc79 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/facilities/TelegramHttpClientBuilder.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/facilities/TelegramHttpClientBuilder.java @@ -45,7 +45,8 @@ public class TelegramHttpClientBuilder { case SOCKS5: registry = RegistryBuilder. create() .register("http", new SocksConnectionSocketFactory()) - .register("https", new SocksSSLConnectionSocketFactory(SSLContexts.createSystemDefault())).build(); + .register("https", new SocksSSLConnectionSocketFactory(SSLContexts.createSystemDefault())) + .build(); return new PoolingHttpClientConnectionManager(registry); } return null; 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 78a84d8d..0f9f6334 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/DefaultBotSession.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/DefaultBotSession.java @@ -2,25 +2,27 @@ package org.telegram.telegrambots.updatesreceivers; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.inject.Inject; -import org.apache.http.HttpEntity; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.BufferedHttpEntity; import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.util.EntityUtils; import org.json.JSONException; +import org.telegram.telegrambots.bots.DefaultBotOptions; +import org.telegram.telegrambots.facilities.TelegramHttpClientBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.telegram.telegrambots.meta.ApiConstants; import org.telegram.telegrambots.meta.api.methods.updates.GetUpdates; import org.telegram.telegrambots.meta.api.objects.Update; -import org.telegram.telegrambots.bots.DefaultBotOptions; import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; -import org.telegram.telegrambots.facilities.TelegramHttpClientBuilder; -import org.telegram.telegrambots.meta.generics.*; +import org.telegram.telegrambots.meta.generics.BotOptions; +import org.telegram.telegrambots.meta.generics.BotSession; +import org.telegram.telegrambots.meta.generics.LongPollingBot; +import org.telegram.telegrambots.meta.generics.UpdatesHandler; +import org.telegram.telegrambots.meta.generics.UpdatesReader; import java.io.IOException; import java.io.InvalidObjectException; @@ -28,7 +30,11 @@ import java.net.SocketException; import java.net.SocketTimeoutException; import java.nio.charset.StandardCharsets; import java.security.InvalidParameterException; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Optional; import java.util.concurrent.ConcurrentLinkedDeque; import java.util.concurrent.atomic.AtomicBoolean; @@ -132,6 +138,7 @@ public class DefaultBotSession implements BotSession { return running.get(); } + @SuppressWarnings("WeakerAccess") private class ReaderThread extends Thread implements UpdatesReader { private final UpdatesSupplier updatesSupplier; @@ -244,9 +251,7 @@ public class DefaultBotSession implements BotSession { httpPost.setEntity(new StringEntity(objectMapper.writeValueAsString(request), ContentType.APPLICATION_JSON)); try (CloseableHttpResponse response = httpclient.execute(httpPost, options.getHttpContext())) { - HttpEntity ht = response.getEntity(); - BufferedHttpEntity buf = new BufferedHttpEntity(ht); - String responseContent = EntityUtils.toString(buf, StandardCharsets.UTF_8); + String responseContent = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8); if (response.getStatusLine().getStatusCode() >= 500) { log.warn(responseContent); 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 a294738d..5210cd6c 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/util/WebhookUtils.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/util/WebhookUtils.java @@ -1,9 +1,9 @@ package org.telegram.telegrambots.util; import org.apache.http.HttpEntity; +import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.BufferedHttpEntity; import org.apache.http.entity.ContentType; import org.apache.http.entity.mime.MultipartEntityBuilder; import org.apache.http.impl.client.CloseableHttpClient; @@ -11,19 +11,21 @@ import org.apache.http.util.EntityUtils; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import org.telegram.telegrambots.meta.ApiConstants; -import org.telegram.telegrambots.meta.api.methods.updates.DeleteWebhook; import org.telegram.telegrambots.bots.DefaultAbsSender; import org.telegram.telegrambots.bots.DefaultBotOptions; -import org.telegram.telegrambots.meta.exceptions.TelegramApiException; import org.telegram.telegrambots.facilities.TelegramHttpClientBuilder; +import org.telegram.telegrambots.meta.ApiConstants; +import org.telegram.telegrambots.meta.api.methods.updates.DeleteWebhook; import org.telegram.telegrambots.meta.api.methods.updates.SetWebhook; +import org.telegram.telegrambots.meta.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; +import static org.telegram.telegrambots.Constants.SOCKET_TIMEOUT; + public final class WebhookUtils { private WebhookUtils() { @@ -35,8 +37,16 @@ public final class WebhookUtils { try (CloseableHttpClient httpclient = TelegramHttpClientBuilder.build(botOptions)) { String requestUrl = bot.getBaseUrl() + SetWebhook.PATH; + RequestConfig requestConfig = botOptions.getRequestConfig(); + if (requestConfig == null) { + requestConfig = RequestConfig.copy(RequestConfig.custom().build()) + .setSocketTimeout(SOCKET_TIMEOUT) + .setConnectTimeout(SOCKET_TIMEOUT) + .setConnectionRequestTimeout(SOCKET_TIMEOUT).build(); + } + HttpPost httppost = new HttpPost(requestUrl); - httppost.setConfig(botOptions.getRequestConfig()); + httppost.setConfig(requestConfig); MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.addTextBody(SetWebhook.URL_FIELD, url); if (botOptions.getMaxWebhookConnections() != null) { @@ -54,9 +64,7 @@ public final class WebhookUtils { HttpEntity multipart = builder.build(); httppost.setEntity(multipart); 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); + String responseContent = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8); JSONObject jsonObject = new JSONObject(responseContent); if (!jsonObject.getBoolean(ApiConstants.RESPONSE_FIELD_OK)) { throw new TelegramApiRequestException("Error setting webhook", jsonObject); From 0cbc21b1425e6a8cd008651693f91cf074f4d59b Mon Sep 17 00:00:00 2001 From: Ruben Bermudez Date: Tue, 19 Nov 2019 00:22:04 +0000 Subject: [PATCH 09/13] Update version 4.4.0.2 --- Bots.ipr | 16 ++++++++++++---- README.md | 8 ++++---- TelegramBots.wiki/Changelog.md | 8 ++++++++ TelegramBots.wiki/Getting-Started.md | 4 ++-- TelegramBots.wiki/How-To-Update.md | 3 +++ TelegramBots.wiki/abilities/Simple-Example.md | 2 +- pom.xml | 2 +- telegrambots-abilities/README.md | 8 ++++---- telegrambots-abilities/pom.xml | 4 ++-- telegrambots-chat-session-bot/README.md | 2 +- telegrambots-chat-session-bot/pom.xml | 4 ++-- telegrambots-extensions/README.md | 4 ++-- telegrambots-extensions/pom.xml | 4 ++-- telegrambots-meta/pom.xml | 2 +- telegrambots-spring-boot-starter/pom.xml | 4 ++-- telegrambots/pom.xml | 4 ++-- 16 files changed, 49 insertions(+), 30 deletions(-) diff --git a/Bots.ipr b/Bots.ipr index 3cba11c9..164a7410 100644 --- a/Bots.ipr +++ b/Bots.ipr @@ -506,10 +506,18 @@ + + + + + + + + @@ -1118,15 +1126,15 @@ - + - + - + - + diff --git a/README.md b/README.md index 15de0465..d66ba1f3 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.4.0.1 + 4.4.0.2 ``` ```gradle - compile "org.telegram:telegrambots:4.4.0.1" + compile "org.telegram:telegrambots:4.4.0.2" ``` - 2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/4.4.0.1) - 3. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/4.4.0.1) + 2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/4.4.0.2) + 3. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/4.4.0.2) In order to use Long Polling mode, just create your own bot extending `org.telegram.telegrambots.bots.TelegramLongPollingBot`. diff --git a/TelegramBots.wiki/Changelog.md b/TelegramBots.wiki/Changelog.md index 4f686e71..aa6bbe75 100644 --- a/TelegramBots.wiki/Changelog.md +++ b/TelegramBots.wiki/Changelog.md @@ -1,3 +1,11 @@ +### 4.4.0.2 ### +1. Use SLF4J +2. Support case-insensitive usernames +3. Add Ability toggles and export default abilities to their own class +4. Add state machine capability to AbilityBot via ReplyFlow +5. Support backup and recovery of db vars +6. Fixes: #602, #641, #652 + ### 4.4.0.1 ### 1. Bug fix when importing the project diff --git a/TelegramBots.wiki/Getting-Started.md b/TelegramBots.wiki/Getting-Started.md index 0f9d2a6c..64a63865 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.4.0.1 + 4.4.0.2 ``` * With **Gradle**: ```groovy - compile group: 'org.telegram', name: 'telegrambots', version: '4.4.0.1' + compile group: 'org.telegram', name: 'telegrambots', version: '4.4.0.2' ``` 2. Don't like **Maven Central Repository**? It can also be taken from [Jitpack](https://jitpack.io/#rubenlagus/TelegramBots). diff --git a/TelegramBots.wiki/How-To-Update.md b/TelegramBots.wiki/How-To-Update.md index 0bc9c26b..11fe80e8 100644 --- a/TelegramBots.wiki/How-To-Update.md +++ b/TelegramBots.wiki/How-To-Update.md @@ -1,3 +1,6 @@ +### To version 4.4.0.2 ### +1. Logging framework has been replaced by slf4j, so now you'll need to manage your own implementation. + ### To version 4.0.0 ### 1. Replace removed method from AbsSender with `execute` requests. 2. Everything under "Telegrambots-meta" has been moved to package `org.telegram.telegrambots.meta`. diff --git a/TelegramBots.wiki/abilities/Simple-Example.md b/TelegramBots.wiki/abilities/Simple-Example.md index 04bf57f5..f541cd66 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 - 4.4.0.1 + 4.4.0.2 ``` * **Gradle** diff --git a/pom.xml b/pom.xml index df092cfe..c1deab65 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots pom - 4.4.0.1 + 4.4.0.2 telegrambots diff --git a/telegrambots-abilities/README.md b/telegrambots-abilities/README.md index 483334c0..d4d1401a 100644 --- a/telegrambots-abilities/README.md +++ b/telegrambots-abilities/README.md @@ -18,19 +18,19 @@ Usage org.telegram telegrambots-abilities - 4.4.0.1 + 4.4.0.2 ``` **Gradle** ```gradle - compile "org.telegram:telegrambots-abilities:4.4.0.1" + compile "org.telegram:telegrambots-abilities:4.4.0.2" ``` -**JitPack** - [JitPack](https://jitpack.io/#rubenlagus/TelegramBots/v4.4.0.1) +**JitPack** - [JitPack](https://jitpack.io/#rubenlagus/TelegramBots/v4.4.0.2) -**Plain imports** - [Here](https://github.com/rubenlagus/TelegramBots/releases/tag/v4.4.0.1) +**Plain imports** - [Here](https://github.com/rubenlagus/TelegramBots/releases/tag/v4.4.0.2) Motivation ---------- diff --git a/telegrambots-abilities/pom.xml b/telegrambots-abilities/pom.xml index 7325fd3a..20599cad 100644 --- a/telegrambots-abilities/pom.xml +++ b/telegrambots-abilities/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 4.4.0.1 + 4.4.0.2 telegrambots-abilities @@ -85,7 +85,7 @@ org.telegram telegrambots - 4.4.0.1 + 4.4.0.2 org.apache.commons diff --git a/telegrambots-chat-session-bot/README.md b/telegrambots-chat-session-bot/README.md index f0616b41..095f2bc9 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.4.0.1 + 4.4.0.2 ``` diff --git a/telegrambots-chat-session-bot/pom.xml b/telegrambots-chat-session-bot/pom.xml index 606db6ac..856fdaa3 100644 --- a/telegrambots-chat-session-bot/pom.xml +++ b/telegrambots-chat-session-bot/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 4.4.0.1 + 4.4.0.2 telegrambots-chat-session-bot @@ -84,7 +84,7 @@ org.telegram telegrambots - 4.4.0.1 + 4.4.0.2 diff --git a/telegrambots-extensions/README.md b/telegrambots-extensions/README.md index 448d404c..72abbcf3 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.4.0.1 + 4.4.0.2 ``` 2. Using Gradle: ```gradle - compile "org.telegram:telegrambotsextensions:4.4.0.1" + compile "org.telegram:telegrambotsextensions:4.4.0.2" ``` \ No newline at end of file diff --git a/telegrambots-extensions/pom.xml b/telegrambots-extensions/pom.xml index ea44f782..8c346d7e 100644 --- a/telegrambots-extensions/pom.xml +++ b/telegrambots-extensions/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 4.4.0.1 + 4.4.0.2 telegrambotsextensions @@ -75,7 +75,7 @@ org.telegram telegrambots - 4.4.0.1 + 4.4.0.2 diff --git a/telegrambots-meta/pom.xml b/telegrambots-meta/pom.xml index e60b3e72..aed7c4ed 100644 --- a/telegrambots-meta/pom.xml +++ b/telegrambots-meta/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 4.4.0.1 + 4.4.0.2 telegrambots-meta diff --git a/telegrambots-spring-boot-starter/pom.xml b/telegrambots-spring-boot-starter/pom.xml index 0ba8111f..1eeee6f8 100644 --- a/telegrambots-spring-boot-starter/pom.xml +++ b/telegrambots-spring-boot-starter/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 4.4.0.1 + 4.4.0.2 telegrambots-spring-boot-starter @@ -78,7 +78,7 @@ org.telegram telegrambots - 4.4.0.1 + 4.4.0.2 org.springframework.boot diff --git a/telegrambots/pom.xml b/telegrambots/pom.xml index 113bc407..c25a7b4b 100644 --- a/telegrambots/pom.xml +++ b/telegrambots/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots - 4.4.0.1 + 4.4.0.2 telegrambots @@ -95,7 +95,7 @@ org.telegram telegrambots-meta - 4.4.0.1 + 4.4.0.2 com.fasterxml.jackson.core From 030aed2756b08122444b7444772d4d1d90d059eb Mon Sep 17 00:00:00 2001 From: Ruben Bermudez Date: Tue, 19 Nov 2019 00:30:27 +0000 Subject: [PATCH 10/13] Add comment --- Bots.ipr | 4 ++-- pom.xml | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Bots.ipr b/Bots.ipr index 164a7410..a1fedc3a 100644 --- a/Bots.ipr +++ b/Bots.ipr @@ -22,10 +22,10 @@ - - + + diff --git a/pom.xml b/pom.xml index c1deab65..2f7a5268 100644 --- a/pom.xml +++ b/pom.xml @@ -116,6 +116,7 @@ slf4j-api ${slf4j.version} + jakarta.annotation jakarta.annotation-api From 27649a99cf51bb7f8452ce5adad04ec683870568 Mon Sep 17 00:00:00 2001 From: Ruben Bermudez Date: Tue, 19 Nov 2019 01:01:49 +0000 Subject: [PATCH 11/13] Update dependencies --- Bots.ipr | 179 ++++++++++++----------- pom.xml | 10 +- telegrambots-chat-session-bot/pom.xml | 2 +- telegrambots-meta/pom.xml | 4 +- telegrambots-spring-boot-starter/pom.xml | 2 +- telegrambots/pom.xml | 6 +- 6 files changed, 107 insertions(+), 96 deletions(-) diff --git a/Bots.ipr b/Bots.ipr index a1fedc3a..33b4badd 100644 --- a/Bots.ipr +++ b/Bots.ipr @@ -906,70 +906,70 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -1280,125 +1280,136 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + + + + + + + + + + + @@ -1412,15 +1423,15 @@ - + - + - + - + @@ -1863,26 +1874,26 @@ - + - + - + - + - + - + - + - + @@ -1907,15 +1918,15 @@ - + - + - + - + diff --git a/pom.xml b/pom.xml index 2f7a5268..fb6636f4 100644 --- a/pom.xml +++ b/pom.xml @@ -68,11 +68,11 @@ ${java.version} 5.5.2 - 3.0.0 - 3.0.0 - 2.9.9 - 2.9.9.2 - 1.7.28 + 3.1.0 + 3.1.0 + 2.10.1 + 2.10.1 + 1.7.29 1.3.5 diff --git a/telegrambots-chat-session-bot/pom.xml b/telegrambots-chat-session-bot/pom.xml index 856fdaa3..fef0e5d2 100644 --- a/telegrambots-chat-session-bot/pom.xml +++ b/telegrambots-chat-session-bot/pom.xml @@ -76,7 +76,7 @@ UTF-8 UTF-8 - 1.4.1 + 1.4.2 diff --git a/telegrambots-meta/pom.xml b/telegrambots-meta/pom.xml index aed7c4ed..a6167035 100644 --- a/telegrambots-meta/pom.xml +++ b/telegrambots-meta/pom.xml @@ -70,8 +70,8 @@ UTF-8 UTF-8 4.2.2 - 2.9.9.2 - 2.9.9 + 2.10.1 + 2.10.1 20180813 28.1-jre diff --git a/telegrambots-spring-boot-starter/pom.xml b/telegrambots-spring-boot-starter/pom.xml index 1eeee6f8..dbd57c85 100644 --- a/telegrambots-spring-boot-starter/pom.xml +++ b/telegrambots-spring-boot-starter/pom.xml @@ -103,7 +103,7 @@ org.assertj assertj-core test - 3.13.2 + 3.14.0 diff --git a/telegrambots/pom.xml b/telegrambots/pom.xml index c25a7b4b..9ea6cb51 100644 --- a/telegrambots/pom.xml +++ b/telegrambots/pom.xml @@ -74,8 +74,8 @@ 1.19.3 4.5.10 20180813 - 2.9.9.2 - 2.9.9 + 2.10.1 + 2.10.1 2.6 @@ -110,7 +110,7 @@ com.fasterxml.jackson.module jackson-module-jaxb-annotations - 2.9.9 + 2.10.1 com.fasterxml.jackson.core From ff96318fefc3937bac0a5e9e64f81c18e9e60d07 Mon Sep 17 00:00:00 2001 From: Eugene Kortov Date: Wed, 20 Nov 2019 16:45:38 +0400 Subject: [PATCH 12/13] Add DI for TelegramFileDownloader, fix it for proxy usage - add DI for TelegramFileDownloader - replace volatile variables with final --- .../telegrambots/bots/DefaultAbsSender.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 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 71c6d4ed..f6c522d3 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java @@ -65,9 +65,9 @@ public abstract class DefaultAbsSender extends AbsSender { protected final ExecutorService exe; private final ObjectMapper objectMapper = new ObjectMapper(); private final DefaultBotOptions options; - private volatile CloseableHttpClient httpClient; - private volatile RequestConfig requestConfig; - private final TelegramFileDownloader telegramFileDownloader = new TelegramFileDownloader(this::getBotToken); + private final CloseableHttpClient httpClient; + private final RequestConfig requestConfig; + private final TelegramFileDownloader telegramFileDownloader; protected DefaultAbsSender(DefaultBotOptions options) { super(); @@ -76,11 +76,14 @@ public abstract class DefaultAbsSender extends AbsSender { this.options = options; httpClient = TelegramHttpClientBuilder.build(options); + this.telegramFileDownloader = new TelegramFileDownloader(httpClient, this::getBotToken); configureHttpContext(); - requestConfig = options.getRequestConfig(); - if (requestConfig == null) { - requestConfig = RequestConfig.copy(RequestConfig.custom().build()) + final RequestConfig configFromOptions = options.getRequestConfig(); + if (configFromOptions != null) { + this.requestConfig = configFromOptions; + } else { + this.requestConfig = RequestConfig.copy(RequestConfig.custom().build()) .setSocketTimeout(SOCKET_TIMEOUT) .setConnectTimeout(SOCKET_TIMEOUT) .setConnectionRequestTimeout(SOCKET_TIMEOUT).build(); From f58def63265d286d5881d00be30eacbfb5eaeb2c Mon Sep 17 00:00:00 2001 From: Ruben Bermudez Date: Sat, 23 Nov 2019 16:45:03 +0000 Subject: [PATCH 13/13] Update changelog --- TelegramBots.wiki/Changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TelegramBots.wiki/Changelog.md b/TelegramBots.wiki/Changelog.md index aa6bbe75..e568d16a 100644 --- a/TelegramBots.wiki/Changelog.md +++ b/TelegramBots.wiki/Changelog.md @@ -4,7 +4,7 @@ 3. Add Ability toggles and export default abilities to their own class 4. Add state machine capability to AbilityBot via ReplyFlow 5. Support backup and recovery of db vars -6. Fixes: #602, #641, #652 +6. Fixes: #602, #641, #652, #691 ### 4.4.0.1 ### 1. Bug fix when importing the project