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 876fb5f20..ef74a5003 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
@@ -127,8 +127,7 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability
// Ability toggle
private final AbilityToggle toggle;
- // Bot token and username
- private final String botToken;
+ // Bot username
private final String botUsername;
// Ability registry
@@ -142,9 +141,8 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability
public abstract long creatorId();
protected BaseAbilityBot(String botToken, String botUsername, DBContext db, AbilityToggle toggle, DefaultBotOptions botOptions) {
- super(botOptions);
+ super(botOptions, botToken);
- this.botToken = botToken;
this.botUsername = botUsername;
this.db = db;
this.toggle = toggle;
@@ -264,10 +262,6 @@ public void onUpdateReceived(Update update) {
log.info(format("[%s] Processing of update [%s] ended at %s%n---> Processing time: [%d ms] <---%n", botUsername, update.getUpdateId(), now(), processingTime));
}
- public String getBotToken() {
- return botToken;
- }
-
public String getBotUsername() {
return botUsername;
}
diff --git a/telegrambots-chat-session-bot/src/main/java/org/telegram/telegrambots/session/TelegramLongPollingSessionBot.java b/telegrambots-chat-session-bot/src/main/java/org/telegram/telegrambots/session/TelegramLongPollingSessionBot.java
index 3f33fba76..35317b906 100644
--- a/telegrambots-chat-session-bot/src/main/java/org/telegram/telegrambots/session/TelegramLongPollingSessionBot.java
+++ b/telegrambots-chat-session-bot/src/main/java/org/telegram/telegrambots/session/TelegramLongPollingSessionBot.java
@@ -6,9 +6,9 @@
import org.apache.shiro.session.mgt.SessionContext;
import org.apache.shiro.session.mgt.eis.AbstractSessionDAO;
import org.telegram.telegrambots.bots.DefaultBotOptions;
+import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.Update;
-import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import java.util.Optional;
@@ -17,23 +17,50 @@ public abstract class TelegramLongPollingSessionBot extends TelegramLongPollingB
DefaultSessionManager sessionManager;
ChatIdConverter chatIdConverter;
-
+ /**
+ * If this is used getBotToken has to be overridden in order to return the bot token!
+ * @deprecated Overwriting the getBotToken() method is deprecated. Use the constructor instead
+ */
+ @Deprecated
public TelegramLongPollingSessionBot(){
this(new DefaultChatIdConverter());
}
+ /**
+ * If this is used getBotToken has to be overridden in order to return the bot token!
+ * @deprecated Overwriting the getBotToken() method is deprecated. Use the constructor instead
+ */
+ @Deprecated
public TelegramLongPollingSessionBot(ChatIdConverter chatIdConverter){
this(chatIdConverter, new DefaultBotOptions());
}
+ /**
+ * If this is used getBotToken has to be overridden in order to return the bot token!
+ * @deprecated Overwriting the getBotToken() method is deprecated. Use the constructor instead
+ */
+ @Deprecated
public TelegramLongPollingSessionBot(ChatIdConverter chatIdConverter, DefaultBotOptions defaultBotOptions){
- super(defaultBotOptions);
+ this(chatIdConverter, defaultBotOptions, null);
+ }
+
+ public TelegramLongPollingSessionBot(String botToken){
+ this(new DefaultChatIdConverter(), botToken);
+ }
+
+ public TelegramLongPollingSessionBot(ChatIdConverter chatIdConverter, String botToken){
+ this(chatIdConverter, new DefaultBotOptions(), botToken);
+ }
+
+ public TelegramLongPollingSessionBot(ChatIdConverter chatIdConverter, DefaultBotOptions defaultBotOptions, String botToken){
+ super(defaultBotOptions, botToken);
this.setSessionManager(new DefaultSessionManager());
this.setChatIdConverter(chatIdConverter);
AbstractSessionDAO sessionDAO = (AbstractSessionDAO) sessionManager.getSessionDAO();
sessionDAO.setSessionIdGenerator(chatIdConverter);
}
+
public void setSessionManager(DefaultSessionManager sessionManager) {
this.sessionManager = sessionManager;
}
diff --git a/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/commandbot/TelegramWebhookCommandBot.java b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/commandbot/TelegramWebhookCommandBot.java
index dcc373809..9d466b3d0 100644
--- a/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/commandbot/TelegramWebhookCommandBot.java
+++ b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/commandbot/TelegramWebhookCommandBot.java
@@ -27,7 +27,9 @@ public abstract class TelegramWebhookCommandBot extends TelegramWebhookBot imple
* Creates a TelegramWebhookCommandBot using default options
* Use ICommandRegistry's methods on this bot to register commands
*
+ * @deprecated Overwriting the getBotToken() method is deprecated. Use the constructor instead
*/
+ @Deprecated
public TelegramWebhookCommandBot() {
this(new DefaultBotOptions());
}
@@ -37,8 +39,11 @@ public TelegramWebhookCommandBot() {
* usernames
* Use ICommandRegistry's methods on this bot to register commands
*
+ * @deprecated Overwriting the getBotToken() method is deprecated. Use the constructor instead
+ *
* @param options Bot options
*/
+ @Deprecated
public TelegramWebhookCommandBot(DefaultBotOptions options) {
this(options, true);
}
@@ -47,15 +52,54 @@ public TelegramWebhookCommandBot(DefaultBotOptions options) {
* Creates a TelegramWebhookCommandBot
* Use ICommandRegistry's methods on this bot to register commands
*
+ * @deprecated Overwriting the getBotToken() method is deprecated. Use the constructor instead
+ *
* @param options Bot options
* @param allowCommandsWithUsername true to allow commands with parameters (default),
* false otherwise
*/
+ @Deprecated
public TelegramWebhookCommandBot(DefaultBotOptions options, boolean allowCommandsWithUsername) {
super(options);
this.commandRegistry = new CommandRegistry(allowCommandsWithUsername, this::getBotUsername);
}
+ /**
+ * Creates a TelegramWebhookCommandBot using default options
+ * Use ICommandRegistry's methods on this bot to register commands
+ *
+ * @param botToken the telegram api token
+ */
+ public TelegramWebhookCommandBot(String botToken) {
+ this(new DefaultBotOptions(), botToken);
+ }
+
+ /**
+ * Creates a TelegramWebhookCommandBot with custom options and allowing commands with
+ * usernames
+ * Use ICommandRegistry's methods on this bot to register commands
+ *
+ * @param options Bot options
+ * @param botToken the telegram api token
+ */
+ public TelegramWebhookCommandBot(DefaultBotOptions options, String botToken) {
+ this(options, true, botToken);
+ }
+
+ /**
+ * Creates a TelegramWebhookCommandBot
+ * Use ICommandRegistry's methods on this bot to register commands
+ *
+ * @param options Bot options
+ * @param allowCommandsWithUsername true to allow commands with parameters (default),
+ * false otherwise
+ * @param botToken the telegram api token
+ */
+ public TelegramWebhookCommandBot(DefaultBotOptions options, boolean allowCommandsWithUsername, String botToken) {
+ super(options, botToken);
+ this.commandRegistry = new CommandRegistry(allowCommandsWithUsername, this::getBotUsername);
+ }
+
@Override
public BotApiMethod> onWebhookUpdateReceived(Update update) {
if (update.hasMessage()) {
diff --git a/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/timedbot/TimedSendLongPollingBot.java b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/timedbot/TimedSendLongPollingBot.java
index 97ee169ca..415a2ff54 100644
--- a/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/timedbot/TimedSendLongPollingBot.java
+++ b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/extensions/bots/timedbot/TimedSendLongPollingBot.java
@@ -132,8 +132,20 @@ public Long getChatId()
}
//Constructor
+
+ /**
+ * @deprecated Overwriting the getBotToken() method is deprecated. Use the constructor instead
+ */
+ @Deprecated
protected TimedSendLongPollingBot()
{
+ super();
+ mSendTimer.schedule(new MessageSenderTask(), MANY_CHATS_SEND_INTERVAL, MANY_CHATS_SEND_INTERVAL);
+ }
+
+ protected TimedSendLongPollingBot(String botToken)
+ {
+ super(botToken);
mSendTimer.schedule(new MessageSenderTask(), MANY_CHATS_SEND_INTERVAL, MANY_CHATS_SEND_INTERVAL);
}
diff --git a/telegrambots-spring-boot-starter/src/main/java/org/telegram/telegrambots/starter/SpringWebhookBot.java b/telegrambots-spring-boot-starter/src/main/java/org/telegram/telegrambots/starter/SpringWebhookBot.java
index c271956a9..20d2a1635 100644
--- a/telegrambots-spring-boot-starter/src/main/java/org/telegram/telegrambots/starter/SpringWebhookBot.java
+++ b/telegrambots-spring-boot-starter/src/main/java/org/telegram/telegrambots/starter/SpringWebhookBot.java
@@ -11,18 +11,38 @@
* @version 1.0
*/
public abstract class SpringWebhookBot extends TelegramWebhookBot {
- private SetWebhook setWebhook;
+ private final SetWebhook setWebhook;
+ /**
+ * If this is used getBotToken has to be overridden in order to return the bot token!
+ * @deprecated Overwriting the getBotToken() method is deprecated. Use the constructor instead
+ */
+ @Deprecated
public SpringWebhookBot(SetWebhook setWebhook) {
super();
this.setWebhook = setWebhook;
}
+ /**
+ * If this is used getBotToken has to be overridden in order to return the bot token!
+ * @deprecated Overwriting the getBotToken() method is deprecated. Use the constructor instead
+ */
+ @Deprecated
public SpringWebhookBot(DefaultBotOptions options, SetWebhook setWebhook) {
super(options);
this.setWebhook = setWebhook;
}
+ public SpringWebhookBot(SetWebhook setWebhook, String botToken) {
+ super(botToken);
+ this.setWebhook = setWebhook;
+ }
+
+ public SpringWebhookBot(DefaultBotOptions options, SetWebhook setWebhook, String botToken) {
+ super(options, botToken);
+ this.setWebhook = setWebhook;
+ }
+
public SetWebhook getSetWebhook() {
return setWebhook;
}
@@ -30,11 +50,11 @@ public SetWebhook getSetWebhook() {
public class TestSpringWebhookBot extends SpringWebhookBot {
public TestSpringWebhookBot(SetWebhook setWebhook) {
- super(setWebhook);
+ super(setWebhook, null);
}
public TestSpringWebhookBot(DefaultBotOptions options, SetWebhook setWebhook) {
- super(options, setWebhook);
+ super(options, setWebhook, null);
}
@Override
@@ -42,11 +62,6 @@ public String getBotUsername() {
return null;
}
- @Override
- public String getBotToken() {
- return null;
- }
-
@Override
public BotApiMethod onWebhookUpdateReceived(Update update) {
return null;
diff --git a/telegrambots-spring-boot-starter/src/test/java/org/telegram/telegrambots/starter/TestTelegramBotStarterRegistrationHooks.java b/telegrambots-spring-boot-starter/src/test/java/org/telegram/telegrambots/starter/TestTelegramBotStarterRegistrationHooks.java
index fa2e395cd..0ce7680da 100644
--- a/telegrambots-spring-boot-starter/src/test/java/org/telegram/telegrambots/starter/TestTelegramBotStarterRegistrationHooks.java
+++ b/telegrambots-spring-boot-starter/src/test/java/org/telegram/telegrambots/starter/TestTelegramBotStarterRegistrationHooks.java
@@ -14,12 +14,7 @@
import org.telegram.telegrambots.updatesreceivers.DefaultBotSession;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
class TestTelegramBotStarterRegistrationHooks {
@@ -72,6 +67,9 @@ public LongPollingBot longPollingBot() {
}
static class AnnotatedLongPollingBot extends TelegramLongPollingBot {
+ public AnnotatedLongPollingBot() {
+ super((String) null);
+ }
@Override
public void onUpdateReceived(final Update update) {
@@ -82,11 +80,6 @@ public String getBotUsername() {
return null;
}
- @Override
- public String getBotToken() {
- return null;
- }
-
@AfterBotRegistration
public void afterBotHook() {
hookCalled = true;
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 0a7c24bf8..5023a9f33 100644
--- a/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java
+++ b/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java
@@ -73,9 +73,20 @@ public abstract class DefaultAbsSender extends AbsSender {
private final CloseableHttpClient httpClient;
private final RequestConfig requestConfig;
private final TelegramFileDownloader telegramFileDownloader;
+ private final String botToken;
+ /**
+ * If this is used getBotToken has to be overridden in order to return the bot token!
+ * @deprecated Overwriting the getBotToken() method is deprecated. Use the constructor instead
+ */
+ @Deprecated
protected DefaultAbsSender(DefaultBotOptions options) {
+ this(options, null);
+ }
+
+ protected DefaultAbsSender(DefaultBotOptions options, String botToken) {
super();
+ this.botToken = botToken;
this.exe = Executors.newFixedThreadPool(options.getMaxThreads());
this.options = options;
@@ -98,8 +109,12 @@ protected DefaultAbsSender(DefaultBotOptions options) {
/**
* Returns the token of the bot to be able to perform Telegram Api Requests
* @return Token of the bot
+ * @deprecated Overriding this method is deprecated. Pass to constructor instead
*/
- public abstract String getBotToken();
+ @Deprecated
+ public String getBotToken() {
+ return botToken;
+ }
public final DefaultBotOptions getOptions() {
return options;
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 4468e52b0..ecc9d755f 100644
--- a/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingBot.java
+++ b/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingBot.java
@@ -11,14 +11,31 @@
* long-polling method
*/
public abstract class TelegramLongPollingBot extends DefaultAbsSender implements LongPollingBot {
+ /**
+ * If this is used getBotToken has to be overridden in order to return the bot token!
+ * @deprecated Overwriting the getBotToken() method is deprecated. Use the constructor instead
+ */
+ @Deprecated()
public TelegramLongPollingBot() {
this(new DefaultBotOptions());
}
+ /**
+ * If this is used getBotToken has to be overridden in order to return the bot token!
+ * @deprecated Overwriting the getBotToken() method is deprecated. Use the constructor instead
+ */
+ @Deprecated()
public TelegramLongPollingBot(DefaultBotOptions options) {
super(options);
}
+ public TelegramLongPollingBot(String botToken) {
+ this(new DefaultBotOptions(), botToken);
+ }
+ public TelegramLongPollingBot(DefaultBotOptions options, String botToken) {
+ super(options, botToken);
+ }
+
@Override
public void clearWebhook() throws TelegramApiRequestException {
WebhookUtils.clearWebhook(this);
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 5ddee09b8..db05b5778 100644
--- a/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramWebhookBot.java
+++ b/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramWebhookBot.java
@@ -13,14 +13,32 @@
*/
@SuppressWarnings("WeakerAccess")
public abstract class TelegramWebhookBot extends DefaultAbsSender implements WebhookBot {
+ /**
+ * If this is used getBotToken has to be overridden in order to return the bot token!
+ * @deprecated Overwriting the getBotToken() method is deprecated. Use the constructor instead
+ */
+ @Deprecated
public TelegramWebhookBot() {
this(new DefaultBotOptions());
}
+ /**
+ * If this is used getBotToken has to be overridden in order to return the bot token!
+ * @deprecated Overwriting the getBotToken() method is deprecated. Use the constructor instead
+ */
+ @Deprecated
public TelegramWebhookBot(DefaultBotOptions options) {
super(options);
}
+ public TelegramWebhookBot(String botToken) {
+ this(new DefaultBotOptions(), botToken);
+ }
+
+ public TelegramWebhookBot(DefaultBotOptions options, String botToken) {
+ super(options, botToken);
+ }
+
@Override
public void setWebhook(SetWebhook setWebhook) throws TelegramApiException {
WebhookUtils.setWebhook(this, this, setWebhook);
diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/facilities/filedownloader/TelegramFileDownloader.java b/telegrambots/src/main/java/org/telegram/telegrambots/facilities/filedownloader/TelegramFileDownloader.java
index 10ba1bfa8..b750d17ff 100644
--- a/telegrambots/src/main/java/org/telegram/telegrambots/facilities/filedownloader/TelegramFileDownloader.java
+++ b/telegrambots/src/main/java/org/telegram/telegrambots/facilities/filedownloader/TelegramFileDownloader.java
@@ -25,6 +25,7 @@
*/
public class TelegramFileDownloader {
private final HttpClient httpClient;
+ //TODO Replace with concrete token once deprecations are removed
private final Supplier botTokenSupplier;
public TelegramFileDownloader(final Supplier botTokenSupplier) {
diff --git a/telegrambots/src/test/java/org/telegram/telegrambots/test/TelegramLongPollingBotTest.java b/telegrambots/src/test/java/org/telegram/telegrambots/test/TelegramLongPollingBotTest.java
index 1a6177727..c3070473e 100644
--- a/telegrambots/src/test/java/org/telegram/telegrambots/test/TelegramLongPollingBotTest.java
+++ b/telegrambots/src/test/java/org/telegram/telegrambots/test/TelegramLongPollingBotTest.java
@@ -47,6 +47,10 @@ public void testExecutorShutdown() throws Exception {
private static class TestBot extends TelegramLongPollingBot {
+ public TestBot() {
+ super("");
+ }
+
@Override
public void onUpdateReceived(Update update) {
}
@@ -60,10 +64,6 @@ public String getBotUsername() {
return "";
}
- @Override
- public String getBotToken() {
- return "";
- }
}
}