From 1a77291d5bb2269cddc63dc32561d64874232f36 Mon Sep 17 00:00:00 2001 From: d2a-raudenaerde Date: Wed, 29 Jun 2016 17:59:35 +0200 Subject: [PATCH 1/8] Shading http components --- pom.xml | 336 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 182 insertions(+), 154 deletions(-) diff --git a/pom.xml b/pom.xml index f932c507..1e52c814 100644 --- a/pom.xml +++ b/pom.xml @@ -1,163 +1,191 @@ - 4.0.0 - jar - org.telegram - telegrambots - 2.3.3.4 + xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + jar + org.telegram + telegrambots + 2.3.3.4 - Telegram Bots - https://telegram.me/JavaBotsApi - Easy to use library to create Telegram Bots + Telegram Bots + https://telegram.me/JavaBotsApi + Easy to use library to create Telegram Bots - - - GNU General Public License (GPL) - http://www.gnu.org/licenses/gpl.html - - + + + GNU General Public License (GPL) + http://www.gnu.org/licenses/gpl.html + + - - UTF-8 - UTF-8 - 2.23 - 1.19.1 - 4.5.2 - 20160212 - 2.7.4 - + + UTF-8 + UTF-8 + 2.23 + 1.19.1 + 4.5.2 + 20160212 + 2.7.4 + - - - - org.glassfish.jersey - jersey-bom - ${jersey.version} - pom - import - - - + + + + org.glassfish.jersey + jersey-bom + ${jersey.version} + pom + import + + + - - - org.glassfish.jersey.containers - jersey-container-grizzly2-http - ${jersey.version} - - - org.glassfish.jersey.media - jersey-media-json-jackson - ${jersey.version} - - - com.sun.jersey - jersey-bundle - ${jerseybundle.version} - - - com.sun.jersey - jersey-grizzly2-servlet - ${jerseybundle.version} - - - org.json - json - ${json.version} - - - org.apache.httpcomponents - httpclient - ${httpcompontents.version} - - - org.apache.httpcomponents - httpmime - ${httpcompontents.version} - - + + + org.glassfish.jersey.containers + jersey-container-grizzly2-http + ${jersey.version} + + + org.glassfish.jersey.media + jersey-media-json-jackson + ${jersey.version} + + + com.sun.jersey + jersey-bundle + ${jerseybundle.version} + + + com.sun.jersey + jersey-grizzly2-servlet + ${jerseybundle.version} + + + org.json + json + ${json.version} + + + org.apache.httpcomponents + httpclient + ${httpcompontents.version} + + + org.apache.httpcomponents + httpmime + ${httpcompontents.version} + + - - ${project.basedir}/target - ${project.build.directory}/classes - ${project.artifactId}-${project.version} - ${project.build.directory}/test-classes - ${project.basedir}/src/main/java - - - 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 - - - attach-sources - verify - - jar-no-fork - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.10.3 - - - attach-javadocs - site - - javadoc-no-fork - - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.8 - 1.8 - UTF-8 - - - - - + + ${project.basedir}/target + ${project.build.directory}/classes + ${project.artifactId}-${project.version} + ${project.build.directory}/test-classes + ${project.basedir}/src/main/java + + + 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 + + + attach-sources + verify + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.10.3 + + + attach-javadocs + site + + javadoc-no-fork + + + + + + org.apache.maven.plugins + maven-shade-plugin + 2.4.3 + + + package + + shade + + + false + true + + + org.apache.httpcomponents:* + + + + + org.apache.http + embedded.org.apache.http + + + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + UTF-8 + + + + + \ No newline at end of file From ee13d9204418d31e8fe736dccd3e5adfe0c87931 Mon Sep 17 00:00:00 2001 From: valery1707 Date: Sun, 10 Jul 2016 23:44:21 +0600 Subject: [PATCH 2/8] Fix typo in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index de45d0c7..9d5eda66 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Both ways are supported, but I recommend long polling method. ## Usage -Just import add the library to your project using [Maven, Gradly, ...](https://jitpack.io/#rubenlagus/TelegramBots/v2.3.3.4) or download the jar(including all dependencies) from [here](https://github.com/rubenlagus/TelegramBots/releases/tag/v2.3.3.4) +Just import add the library to your project using [Maven, Gradle, ...](https://jitpack.io/#rubenlagus/TelegramBots/v2.3.3.4) or download the jar(including all dependencies) from [here](https://github.com/rubenlagus/TelegramBots/releases/tag/v2.3.3.4) In order to use Long Polling mode, just create your own bot extending `org.telegram.telegrambots.bots.TelegramLongPollingBot`. From e75a28f518750ac8dc3f0f57b262ab4e39c86930 Mon Sep 17 00:00:00 2001 From: Sheigutn Date: Wed, 13 Jul 2016 10:04:44 +0200 Subject: [PATCH 3/8] Fixed a few copy-paste mistakes in toString() methods & fixed functionality of GetChatMember and GetChatMemberCount --- src/main/java/org/telegram/telegrambots/TelegramBotsApi.java | 1 - .../telegram/telegrambots/api/methods/AnswerCallbackQuery.java | 2 +- .../api/methods/groupadministration/GetChatMember.java | 2 +- .../api/methods/groupadministration/GetChatMemberCount.java | 2 +- .../api/methods/groupadministration/KickChatMember.java | 2 +- .../api/methods/groupadministration/UnbanChatMember.java | 2 +- .../org/telegram/telegrambots/api/methods/send/SendContact.java | 2 +- .../org/telegram/telegrambots/api/methods/send/SendVenue.java | 2 +- .../org/telegram/telegrambots/api/objects/CallbackQuery.java | 2 +- .../org/telegram/telegrambots/api/objects/MessageEntity.java | 2 +- 10 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/telegram/telegrambots/TelegramBotsApi.java b/src/main/java/org/telegram/telegrambots/TelegramBotsApi.java index 10618642..c5b9e370 100644 --- a/src/main/java/org/telegram/telegrambots/TelegramBotsApi.java +++ b/src/main/java/org/telegram/telegrambots/TelegramBotsApi.java @@ -105,7 +105,6 @@ public class TelegramBotsApi { * @param webHookURL * @param botToken * @param publicCertificatePath - * @param publicCertificateName * @throws TelegramApiException */ private static void setWebhook(String webHookURL, String botToken, String publicCertificatePath) throws TelegramApiException { diff --git a/src/main/java/org/telegram/telegrambots/api/methods/AnswerCallbackQuery.java b/src/main/java/org/telegram/telegrambots/api/methods/AnswerCallbackQuery.java index 9f7d61b6..ed930884 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/AnswerCallbackQuery.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/AnswerCallbackQuery.java @@ -109,7 +109,7 @@ public class AnswerCallbackQuery extends BotApiMethod { @Override public String toString() { - return "AnswerInlineQuery{" + + return "AnswerCallbackQuery{" + "callbackQueryId='" + callbackQueryId + '\'' + ", text=" + text + ", showAlert=" + showAlert + '\'' + diff --git a/src/main/java/org/telegram/telegrambots/api/methods/groupadministration/GetChatMember.java b/src/main/java/org/telegram/telegrambots/api/methods/groupadministration/GetChatMember.java index 73648daf..a14a270f 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/groupadministration/GetChatMember.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/groupadministration/GetChatMember.java @@ -19,7 +19,7 @@ import java.io.IOException; * @date 20 of May of 2016 */ public class GetChatMember extends BotApiMethod { - public static final String PATH = "getChatAdministrators"; + public static final String PATH = "getChatMember"; private static final String CHATID_FIELD = "chat_id"; private static final String USERID_FIELD = "user_id"; diff --git a/src/main/java/org/telegram/telegrambots/api/methods/groupadministration/GetChatMemberCount.java b/src/main/java/org/telegram/telegrambots/api/methods/groupadministration/GetChatMemberCount.java index 3b350902..d75eb49f 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/groupadministration/GetChatMemberCount.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/groupadministration/GetChatMemberCount.java @@ -17,7 +17,7 @@ import java.io.IOException; * @date 20 of May of 2016 */ public class GetChatMemberCount extends BotApiMethod { - public static final String PATH = "getChatAdministrators"; + public static final String PATH = "getChatMembersCount"; private static final String CHATID_FIELD = "chat_id"; private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels) diff --git a/src/main/java/org/telegram/telegrambots/api/methods/groupadministration/KickChatMember.java b/src/main/java/org/telegram/telegrambots/api/methods/groupadministration/KickChatMember.java index 2ce1f911..c1d53356 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/groupadministration/KickChatMember.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/groupadministration/KickChatMember.java @@ -90,7 +90,7 @@ public class KickChatMember extends BotApiMethod { @Override public String toString() { - return "SendMessage{" + + return "KickChatMember{" + "chatId='" + chatId + '\'' + ", userId='" + userId + '}'; diff --git a/src/main/java/org/telegram/telegrambots/api/methods/groupadministration/UnbanChatMember.java b/src/main/java/org/telegram/telegrambots/api/methods/groupadministration/UnbanChatMember.java index 6c75940c..16381b69 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/groupadministration/UnbanChatMember.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/groupadministration/UnbanChatMember.java @@ -86,7 +86,7 @@ public class UnbanChatMember extends BotApiMethod { @Override public String toString() { - return "SendMessage{" + + return "UnbanChatMember{" + "chatId='" + chatId + '\'' + ", userId='" + userId + '}'; diff --git a/src/main/java/org/telegram/telegrambots/api/methods/send/SendContact.java b/src/main/java/org/telegram/telegrambots/api/methods/send/SendContact.java index a8c94889..cef6aa93 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/send/SendContact.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/send/SendContact.java @@ -207,7 +207,7 @@ public class SendContact extends BotApiMethod { @Override public String toString() { - return "SendLocation{" + + return "SendContact{" + "chatId='" + chatId + '\'' + ", phoneNumber=" + phoneNumber + ", firstName=" + firstName + diff --git a/src/main/java/org/telegram/telegrambots/api/methods/send/SendVenue.java b/src/main/java/org/telegram/telegrambots/api/methods/send/SendVenue.java index 46ead134..5e57207c 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/send/SendVenue.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/send/SendVenue.java @@ -233,7 +233,7 @@ public class SendVenue extends BotApiMethod { @Override public String toString() { - return "SendLocation{" + + return "SendVenue{" + "chatId='" + chatId + '\'' + ", latitude=" + latitude + ", longitude=" + longitude + diff --git a/src/main/java/org/telegram/telegrambots/api/objects/CallbackQuery.java b/src/main/java/org/telegram/telegrambots/api/objects/CallbackQuery.java index af25cc10..6487d28d 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/CallbackQuery.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/CallbackQuery.java @@ -107,7 +107,7 @@ public class CallbackQuery implements IBotApiObject { @Override public String toString() { - return "Contact{" + + return "CallbackQuery{" + "id='" + id + '\'' + ", from='" + from + '\'' + ", message='" + message + '\'' + diff --git a/src/main/java/org/telegram/telegrambots/api/objects/MessageEntity.java b/src/main/java/org/telegram/telegrambots/api/objects/MessageEntity.java index fc8fefa9..52ae50f5 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/MessageEntity.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/MessageEntity.java @@ -119,7 +119,7 @@ public class MessageEntity implements IBotApiObject { @Override public String toString() { - return "PhotoSize{" + + return "MessageEntity{" + "type='" + type + '\'' + ", offset=" + offset + ", length=" + length + From d4dc470706d064f67cad89f2e305bf31a02f802a Mon Sep 17 00:00:00 2001 From: Rubenlagus Date: Wed, 13 Jul 2016 20:23:38 +0200 Subject: [PATCH 4/8] reformat --- pom.xml | 364 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 182 insertions(+), 182 deletions(-) diff --git a/pom.xml b/pom.xml index 1e52c814..e05ed769 100644 --- a/pom.xml +++ b/pom.xml @@ -1,191 +1,191 @@ - 4.0.0 - jar - org.telegram - telegrambots - 2.3.3.4 + xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + jar + org.telegram + telegrambots + 2.3.3.4 - Telegram Bots - https://telegram.me/JavaBotsApi - Easy to use library to create Telegram Bots + Telegram Bots + https://telegram.me/JavaBotsApi + Easy to use library to create Telegram Bots - - - GNU General Public License (GPL) - http://www.gnu.org/licenses/gpl.html - - + + + GNU General Public License (GPL) + http://www.gnu.org/licenses/gpl.html + + - - UTF-8 - UTF-8 - 2.23 - 1.19.1 - 4.5.2 - 20160212 - 2.7.4 - + + UTF-8 + UTF-8 + 2.23 + 1.19.1 + 4.5.2 + 20160212 + 2.7.4 + - - - - org.glassfish.jersey - jersey-bom - ${jersey.version} - pom - import - - - + + + + org.glassfish.jersey + jersey-bom + ${jersey.version} + pom + import + + + - - - org.glassfish.jersey.containers - jersey-container-grizzly2-http - ${jersey.version} - - - org.glassfish.jersey.media - jersey-media-json-jackson - ${jersey.version} - - - com.sun.jersey - jersey-bundle - ${jerseybundle.version} - - - com.sun.jersey - jersey-grizzly2-servlet - ${jerseybundle.version} - - - org.json - json - ${json.version} - - - org.apache.httpcomponents - httpclient - ${httpcompontents.version} - - - org.apache.httpcomponents - httpmime - ${httpcompontents.version} - - + + + org.glassfish.jersey.containers + jersey-container-grizzly2-http + ${jersey.version} + + + org.glassfish.jersey.media + jersey-media-json-jackson + ${jersey.version} + + + com.sun.jersey + jersey-bundle + ${jerseybundle.version} + + + com.sun.jersey + jersey-grizzly2-servlet + ${jerseybundle.version} + + + org.json + json + ${json.version} + + + org.apache.httpcomponents + httpclient + ${httpcompontents.version} + + + org.apache.httpcomponents + httpmime + ${httpcompontents.version} + + - - ${project.basedir}/target - ${project.build.directory}/classes - ${project.artifactId}-${project.version} - ${project.build.directory}/test-classes - ${project.basedir}/src/main/java - - - 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 - - - attach-sources - verify - - jar-no-fork - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.10.3 - - - attach-javadocs - site - - javadoc-no-fork - - - - - - org.apache.maven.plugins - maven-shade-plugin - 2.4.3 - - - package - - shade - - - false - true - - - org.apache.httpcomponents:* - - - - - org.apache.http - embedded.org.apache.http - - - - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.8 - 1.8 - UTF-8 - - - - - + + ${project.basedir}/target + ${project.build.directory}/classes + ${project.artifactId}-${project.version} + ${project.build.directory}/test-classes + ${project.basedir}/src/main/java + + + 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 + + + attach-sources + verify + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.10.3 + + + attach-javadocs + site + + javadoc-no-fork + + + + + + org.apache.maven.plugins + maven-shade-plugin + 2.4.3 + + + package + + shade + + + false + true + + + org.apache.httpcomponents:* + + + + + org.apache.http + embedded.org.apache.http + + + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + UTF-8 + + + + + \ No newline at end of file From 759d829252a2027fbc0647139dbe40aea0c8f001 Mon Sep 17 00:00:00 2001 From: Rubenlagus Date: Wed, 13 Jul 2016 20:28:36 +0200 Subject: [PATCH 5/8] Merge filter in commandbot --- .../bots/TelegramLongPollingCommandBot.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingCommandBot.java b/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingCommandBot.java index f9f8091f..4cb0c0a6 100644 --- a/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingCommandBot.java +++ b/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingCommandBot.java @@ -32,7 +32,7 @@ public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingB public final void onUpdateReceived(Update update) { if (update.hasMessage()) { Message message = update.getMessage(); - if (message.isCommand()) { + if (message.isCommand() && !filter(message)) { if (commandRegistry.executeCommand(this, message)) { return; } @@ -41,6 +41,23 @@ public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingB processNonCommandUpdate(update); } + /** + * function message filter. + * Override this function in your bot implementation to filter messages with commands + * + * For example, if you want to prevent commands execution incoming from group chat: + * # + * # return !message.getChat().isGroupChat(); + * # + * + * @param message Received message + * @return true if the message must be ignored by the command bot and treated as a non command message, + * false otherwise + */ + protected boolean filter(Message message) { + return true; + } + @Override public final boolean register(BotCommand botCommand) { return commandRegistry.register(botCommand); From a24c147a17409df101212487e523c208687939d8 Mon Sep 17 00:00:00 2001 From: dartwata Date: Thu, 14 Jul 2016 12:49:06 +0800 Subject: [PATCH 6/8] get registered command by commandIdentifier --- .../telegrambots/bots/TelegramLongPollingCommandBot.java | 5 +++++ .../telegrambots/bots/commands/CommandRegistry.java | 5 +++++ .../telegrambots/bots/commands/ICommandRegistry.java | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingCommandBot.java b/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingCommandBot.java index f9f8091f..db39d8c4 100644 --- a/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingCommandBot.java +++ b/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingCommandBot.java @@ -71,6 +71,11 @@ public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingB commandRegistry.registerDefaultAction(defaultConsumer); } + @Override + public final BotCommand getRegisteredCommand(String commandIdentifier) { + return commandRegistry.getRegisteredCommand(commandIdentifier); + } + /** * Process all updates, that are not commands. * @warning Commands that have valid syntax but are not registered on this bot, diff --git a/src/main/java/org/telegram/telegrambots/bots/commands/CommandRegistry.java b/src/main/java/org/telegram/telegrambots/bots/commands/CommandRegistry.java index 1cbafd7f..bdc75e6d 100644 --- a/src/main/java/org/telegram/telegrambots/bots/commands/CommandRegistry.java +++ b/src/main/java/org/telegram/telegrambots/bots/commands/CommandRegistry.java @@ -65,6 +65,11 @@ public final class CommandRegistry implements ICommandRegistry { return commandRegistryMap.values(); } + @Override + public final BotCommand getRegisteredCommand(String commandIdentifier) { + return commandRegistryMap.get(commandIdentifier); + } + /** * Executes a command action if the command is registered. * diff --git a/src/main/java/org/telegram/telegrambots/bots/commands/ICommandRegistry.java b/src/main/java/org/telegram/telegrambots/bots/commands/ICommandRegistry.java index d6cd992c..56ae4c6c 100644 --- a/src/main/java/org/telegram/telegrambots/bots/commands/ICommandRegistry.java +++ b/src/main/java/org/telegram/telegrambots/bots/commands/ICommandRegistry.java @@ -62,4 +62,10 @@ public interface ICommandRegistry { */ Collection getRegisteredCommands(); + /** + * get registered command + * + * @return registered command if exists or null if not + */ + BotCommand getRegisteredCommand(String commandIdentifier); } \ No newline at end of file From 18b31aad376c2f05f13947b8dfde950fc132e98e Mon Sep 17 00:00:00 2001 From: Rubenlagus Date: Thu, 21 Jul 2016 21:28:13 +0200 Subject: [PATCH 7/8] Add support for proxys Marked as final methods not intended to be override Close #102 --- .../telegrambots/TelegramBotsApi.java | 2 +- .../telegram/telegrambots/bots/AbsSender.java | 114 ++++++++++-------- .../telegrambots/bots/BotOptions.java | 35 ++++++ .../bots/TelegramLongPollingBot.java | 6 + .../bots/TelegramLongPollingCommandBot.java | 10 +- .../telegrambots/bots/TelegramWebhookBot.java | 7 ++ .../updatesreceivers/BotSession.java | 23 +++- 7 files changed, 141 insertions(+), 56 deletions(-) create mode 100644 src/main/java/org/telegram/telegrambots/bots/BotOptions.java diff --git a/src/main/java/org/telegram/telegrambots/TelegramBotsApi.java b/src/main/java/org/telegram/telegrambots/TelegramBotsApi.java index c5b9e370..4b280b69 100644 --- a/src/main/java/org/telegram/telegrambots/TelegramBotsApi.java +++ b/src/main/java/org/telegram/telegrambots/TelegramBotsApi.java @@ -144,7 +144,7 @@ public class TelegramBotsApi { */ public BotSession registerBot(TelegramLongPollingBot bot) throws TelegramApiException { setWebhook(bot.getBotToken(), null); - return new BotSession(bot.getBotToken(), bot); + return new BotSession(bot.getBotToken(), bot, bot.getOptions()); } /** diff --git a/src/main/java/org/telegram/telegrambots/bots/AbsSender.java b/src/main/java/org/telegram/telegrambots/bots/AbsSender.java index 035ef98c..2c1cd61b 100644 --- a/src/main/java/org/telegram/telegrambots/bots/AbsSender.java +++ b/src/main/java/org/telegram/telegrambots/bots/AbsSender.java @@ -1,6 +1,7 @@ package org.telegram.telegrambots.bots; import org.apache.http.HttpEntity; +import org.apache.http.HttpHost; import org.apache.http.NameValuePair; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.entity.UrlEncodedFormEntity; @@ -77,18 +78,25 @@ public abstract class AbsSender { private static final ContentType TEXT_PLAIN_CONTENT_TYPE = ContentType.create("text/plain", StandardCharsets.UTF_8); private final ExecutorService exe = Executors.newSingleThreadExecutor(); + private final BotOptions options; private volatile CloseableHttpClient httpclient; private volatile RequestConfig requestConfig; private static final int SOCKET_TIMEOUT = 75 * 1000; - AbsSender() { + AbsSender(BotOptions options) { + this.options = options; httpclient = HttpClientBuilder.create() .setSSLHostnameVerifier(new NoopHostnameVerifier()) .setConnectionTimeToLive(70, TimeUnit.SECONDS) .setMaxConnTotal(100) .build(); - requestConfig = RequestConfig.copy(RequestConfig.custom().build()) - .setSocketTimeout(SOCKET_TIMEOUT) + + RequestConfig.Builder configBuilder = RequestConfig.copy(RequestConfig.custom().build()); + if (options.hasProxy()) { + configBuilder.setProxy(new HttpHost(options.getProxyHost(), options.getProxyPort())); + } + + requestConfig = configBuilder.setSocketTimeout(SOCKET_TIMEOUT) .setConnectTimeout(SOCKET_TIMEOUT) .setConnectionRequestTimeout(SOCKET_TIMEOUT).build(); } @@ -99,9 +107,13 @@ public abstract class AbsSender { */ public abstract String getBotToken(); + public final BotOptions getOptions() { + return options; + } + // Send Requests - public Message sendMessage(SendMessage sendMessage) throws TelegramApiException { + public final Message sendMessage(SendMessage sendMessage) throws TelegramApiException { if (sendMessage == null) { throw new TelegramApiException("Parameter sendMessage can not be null"); } @@ -109,7 +121,7 @@ public abstract class AbsSender { return sendApiMethod(sendMessage); } - public Boolean answerInlineQuery(AnswerInlineQuery answerInlineQuery) throws TelegramApiException { + public final Boolean answerInlineQuery(AnswerInlineQuery answerInlineQuery) throws TelegramApiException { if (answerInlineQuery == null) { throw new TelegramApiException("Parameter answerInlineQuery can not be null"); } @@ -117,7 +129,7 @@ public abstract class AbsSender { return sendApiMethod(answerInlineQuery); } - public Boolean sendChatAction(SendChatAction sendChatAction) throws TelegramApiException { + public final Boolean sendChatAction(SendChatAction sendChatAction) throws TelegramApiException { if (sendChatAction == null) { throw new TelegramApiException("Parameter sendChatAction can not be null"); } @@ -125,7 +137,7 @@ public abstract class AbsSender { return sendApiMethod(sendChatAction); } - public Message forwardMessage(ForwardMessage forwardMessage) throws TelegramApiException { + public final Message forwardMessage(ForwardMessage forwardMessage) throws TelegramApiException { if (forwardMessage == null) { throw new TelegramApiException("Parameter forwardMessage can not be null"); } @@ -133,7 +145,7 @@ public abstract class AbsSender { return sendApiMethod(forwardMessage); } - public Message sendLocation(SendLocation sendLocation) throws TelegramApiException { + public final Message sendLocation(SendLocation sendLocation) throws TelegramApiException { if (sendLocation == null) { throw new TelegramApiException("Parameter sendLocation can not be null"); } @@ -141,7 +153,7 @@ public abstract class AbsSender { return sendApiMethod(sendLocation); } - public Message sendVenue(SendVenue sendVenue) throws TelegramApiException { + public final Message sendVenue(SendVenue sendVenue) throws TelegramApiException { if (sendVenue == null) { throw new TelegramApiException("Parameter sendVenue can not be null"); } @@ -149,7 +161,7 @@ public abstract class AbsSender { return sendApiMethod(sendVenue); } - public Message sendContact(SendContact sendContact) throws TelegramApiException { + public final Message sendContact(SendContact sendContact) throws TelegramApiException { if (sendContact == null) { throw new TelegramApiException("Parameter sendContact can not be null"); } @@ -157,84 +169,84 @@ public abstract class AbsSender { return sendApiMethod(sendContact); } - public Boolean kickMember(KickChatMember kickChatMember) throws TelegramApiException { + public final Boolean kickMember(KickChatMember kickChatMember) throws TelegramApiException { if (kickChatMember == null) { throw new TelegramApiException("Parameter kickChatMember can not be null"); } return sendApiMethod(kickChatMember); } - public Boolean unbanMember(UnbanChatMember unbanChatMember) throws TelegramApiException { + public final Boolean unbanMember(UnbanChatMember unbanChatMember) throws TelegramApiException { if (unbanChatMember == null) { throw new TelegramApiException("Parameter unbanChatMember can not be null"); } return sendApiMethod(unbanChatMember); } - public Boolean leaveChat(LeaveChat leaveChat) throws TelegramApiException { + public final Boolean leaveChat(LeaveChat leaveChat) throws TelegramApiException { if (leaveChat == null) { throw new TelegramApiException("Parameter leaveChat can not be null"); } return sendApiMethod(leaveChat); } - public Chat getChat(GetChat getChat) throws TelegramApiException { + public final Chat getChat(GetChat getChat) throws TelegramApiException { if (getChat == null) { throw new TelegramApiException("Parameter getChat can not be null"); } return sendApiMethod(getChat); } - public List getChatAdministrators(GetChatAdministrators getChatAdministrators) throws TelegramApiException { + public final List getChatAdministrators(GetChatAdministrators getChatAdministrators) throws TelegramApiException { if (getChatAdministrators == null) { throw new TelegramApiException("Parameter getChatAdministrators can not be null"); } return sendApiMethod(getChatAdministrators); } - public ChatMember getChatMember(GetChatMember getChatMember) throws TelegramApiException { + public final ChatMember getChatMember(GetChatMember getChatMember) throws TelegramApiException { if (getChatMember == null) { throw new TelegramApiException("Parameter getChatMember can not be null"); } return sendApiMethod(getChatMember); } - public Integer getChatMemberCount(GetChatMemberCount getChatMemberCount) throws TelegramApiException { + public final Integer getChatMemberCount(GetChatMemberCount getChatMemberCount) throws TelegramApiException { if (getChatMemberCount == null) { throw new TelegramApiException("Parameter getChatMemberCount can not be null"); } return sendApiMethod(getChatMemberCount); } - public Message editMessageText(EditMessageText editMessageText) throws TelegramApiException { + public final Message editMessageText(EditMessageText editMessageText) throws TelegramApiException { if (editMessageText == null) { throw new TelegramApiException("Parameter editMessageText can not be null"); } return sendApiMethod(editMessageText); } - public Message editMessageCaption(EditMessageCaption editMessageCaption) throws TelegramApiException { + public final Message editMessageCaption(EditMessageCaption editMessageCaption) throws TelegramApiException { if (editMessageCaption == null) { throw new TelegramApiException("Parameter editMessageCaption can not be null"); } return sendApiMethod(editMessageCaption); } - public Message editMessageReplyMarkup(EditMessageReplyMarkup editMessageReplyMarkup) throws TelegramApiException { + public final Message editMessageReplyMarkup(EditMessageReplyMarkup editMessageReplyMarkup) throws TelegramApiException { if (editMessageReplyMarkup == null) { throw new TelegramApiException("Parameter editMessageReplyMarkup can not be null"); } return sendApiMethod(editMessageReplyMarkup); } - public Boolean answerCallbackQuery(AnswerCallbackQuery answerCallbackQuery) throws TelegramApiException { + public final Boolean answerCallbackQuery(AnswerCallbackQuery answerCallbackQuery) throws TelegramApiException { if (answerCallbackQuery == null) { throw new TelegramApiException("Parameter answerCallbackQuery can not be null"); } return sendApiMethod(answerCallbackQuery); } - public UserProfilePhotos getUserProfilePhotos(GetUserProfilePhotos getUserProfilePhotos) throws TelegramApiException { + public final UserProfilePhotos getUserProfilePhotos(GetUserProfilePhotos getUserProfilePhotos) throws TelegramApiException { if (getUserProfilePhotos == null) { throw new TelegramApiException("Parameter getUserProfilePhotos can not be null"); } @@ -242,7 +254,7 @@ public abstract class AbsSender { return sendApiMethod(getUserProfilePhotos); } - public File getFile(GetFile getFile) throws TelegramApiException{ + public final File getFile(GetFile getFile) throws TelegramApiException{ if(getFile == null){ throw new TelegramApiException("Parameter getFile can not be null"); } @@ -252,7 +264,7 @@ public abstract class AbsSender { return sendApiMethod(getFile); } - public User getMe() throws TelegramApiException { + public final User getMe() throws TelegramApiException { GetMe getMe = new GetMe(); return sendApiMethod(getMe); @@ -260,7 +272,7 @@ public abstract class AbsSender { // Send Requests Async - public void sendMessageAsync(SendMessage sendMessage, SentCallback sentCallback) throws TelegramApiException { + public final void sendMessageAsync(SendMessage sendMessage, SentCallback sentCallback) throws TelegramApiException { if (sendMessage == null) { throw new TelegramApiException("Parameter sendMessage can not be null"); } @@ -272,7 +284,7 @@ public abstract class AbsSender { sendApiMethodAsync(sendMessage, sentCallback); } - public void answerInlineQueryAsync(AnswerInlineQuery answerInlineQuery, SentCallback sentCallback) throws TelegramApiException { + public final void answerInlineQueryAsync(AnswerInlineQuery answerInlineQuery, SentCallback sentCallback) throws TelegramApiException { if (answerInlineQuery == null) { throw new TelegramApiException("Parameter answerInlineQuery can not be null"); } @@ -284,7 +296,7 @@ public abstract class AbsSender { sendApiMethodAsync(answerInlineQuery, sentCallback); } - public void sendChatActionAsync(SendChatAction sendChatAction, SentCallback sentCallback) throws TelegramApiException { + public final void sendChatActionAsync(SendChatAction sendChatAction, SentCallback sentCallback) throws TelegramApiException { if (sendChatAction == null) { throw new TelegramApiException("Parameter sendChatAction can not be null"); } @@ -296,7 +308,7 @@ public abstract class AbsSender { sendApiMethodAsync(sendChatAction, sentCallback); } - public void forwardMessageAsync(ForwardMessage forwardMessage, SentCallback sentCallback) throws TelegramApiException { + public final void forwardMessageAsync(ForwardMessage forwardMessage, SentCallback sentCallback) throws TelegramApiException { if (forwardMessage == null) { throw new TelegramApiException("Parameter forwardMessage can not be null"); } @@ -308,7 +320,7 @@ public abstract class AbsSender { sendApiMethodAsync(forwardMessage, sentCallback); } - public void sendLocationAsync(SendLocation sendLocation, SentCallback sentCallback) throws TelegramApiException { + public final void sendLocationAsync(SendLocation sendLocation, SentCallback sentCallback) throws TelegramApiException { if (sendLocation == null) { throw new TelegramApiException("Parameter sendLocation can not be null"); } @@ -320,7 +332,7 @@ public abstract class AbsSender { sendApiMethodAsync(sendLocation, sentCallback); } - public void sendVenueAsync(SendVenue sendVenue, SentCallback sentCallback) throws TelegramApiException { + public final void sendVenueAsync(SendVenue sendVenue, SentCallback sentCallback) throws TelegramApiException { if (sendVenue == null) { throw new TelegramApiException("Parameter sendVenue can not be null"); } @@ -332,7 +344,7 @@ public abstract class AbsSender { sendApiMethodAsync(sendVenue, sentCallback); } - public void sendContactAsync(SendContact sendContact, SentCallback sentCallback) throws TelegramApiException { + public final void sendContactAsync(SendContact sendContact, SentCallback sentCallback) throws TelegramApiException { if (sendContact == null) { throw new TelegramApiException("Parameter sendContact can not be null"); } @@ -343,7 +355,7 @@ public abstract class AbsSender { sendApiMethodAsync(sendContact, sentCallback); } - public void kickMemberAsync(KickChatMember kickChatMember, SentCallback sentCallback) throws TelegramApiException { + public final void kickMemberAsync(KickChatMember kickChatMember, SentCallback sentCallback) throws TelegramApiException { if (kickChatMember == null) { throw new TelegramApiException("Parameter kickChatMember can not be null"); } @@ -354,7 +366,7 @@ public abstract class AbsSender { sendApiMethodAsync(kickChatMember, sentCallback); } - public void unbanMemberAsync(UnbanChatMember unbanChatMember, SentCallback sentCallback) throws TelegramApiException { + public final void unbanMemberAsync(UnbanChatMember unbanChatMember, SentCallback sentCallback) throws TelegramApiException { if (unbanChatMember == null) { throw new TelegramApiException("Parameter unbanChatMember can not be null"); } @@ -365,7 +377,7 @@ public abstract class AbsSender { sendApiMethodAsync(unbanChatMember, sentCallback); } - public void leaveChatAsync(LeaveChat leaveChat, SentCallback sentCallback) throws TelegramApiException { + public final void leaveChatAsync(LeaveChat leaveChat, SentCallback sentCallback) throws TelegramApiException { if (leaveChat == null) { throw new TelegramApiException("Parameter leaveChat can not be null"); } @@ -375,7 +387,7 @@ public abstract class AbsSender { sendApiMethodAsync(leaveChat, sentCallback); } - public void getChatAsync(GetChat getChat, SentCallback sentCallback) throws TelegramApiException { + public final void getChatAsync(GetChat getChat, SentCallback sentCallback) throws TelegramApiException { if (getChat == null) { throw new TelegramApiException("Parameter getChat can not be null"); } @@ -385,7 +397,7 @@ public abstract class AbsSender { sendApiMethodAsync(getChat, sentCallback); } - public void getChatAdministratorsAsync(GetChatAdministrators getChatAdministrators, SentCallback> sentCallback) throws TelegramApiException { + public final void getChatAdministratorsAsync(GetChatAdministrators getChatAdministrators, SentCallback> sentCallback) throws TelegramApiException { if (getChatAdministrators == null) { throw new TelegramApiException("Parameter getChatAdministrators can not be null"); } @@ -395,7 +407,7 @@ public abstract class AbsSender { sendApiMethodAsync(getChatAdministrators, sentCallback); } - public void getChatMemberAsync(GetChatMember getChatMember, SentCallback sentCallback) throws TelegramApiException { + public final void getChatMemberAsync(GetChatMember getChatMember, SentCallback sentCallback) throws TelegramApiException { if (getChatMember == null) { throw new TelegramApiException("Parameter getChatMember can not be null"); } @@ -405,7 +417,7 @@ public abstract class AbsSender { sendApiMethodAsync(getChatMember, sentCallback); } - public void getChatMemberCountAsync(GetChatMemberCount getChatMemberCount, SentCallback sentCallback) throws TelegramApiException { + public final void getChatMemberCountAsync(GetChatMemberCount getChatMemberCount, SentCallback sentCallback) throws TelegramApiException { if (getChatMemberCount == null) { throw new TelegramApiException("Parameter getChatMemberCount can not be null"); } @@ -417,7 +429,7 @@ public abstract class AbsSender { } - public void editMessageTextAsync(EditMessageText editMessageText, SentCallback sentCallback) throws TelegramApiException { + public final void editMessageTextAsync(EditMessageText editMessageText, SentCallback sentCallback) throws TelegramApiException { if (editMessageText == null) { throw new TelegramApiException("Parameter editMessageText can not be null"); } @@ -428,7 +440,7 @@ public abstract class AbsSender { sendApiMethodAsync(editMessageText, sentCallback); } - public void editMessageCaptionAsync(EditMessageCaption editMessageCaption, SentCallback sentCallback) throws TelegramApiException { + public final void editMessageCaptionAsync(EditMessageCaption editMessageCaption, SentCallback sentCallback) throws TelegramApiException { if (editMessageCaption == null) { throw new TelegramApiException("Parameter editMessageCaption can not be null"); } @@ -439,7 +451,7 @@ public abstract class AbsSender { sendApiMethodAsync(editMessageCaption, sentCallback); } - public void editMessageReplyMarkup(EditMessageReplyMarkup editMessageReplyMarkup, SentCallback sentCallback) throws TelegramApiException { + public final void editMessageReplyMarkup(EditMessageReplyMarkup editMessageReplyMarkup, SentCallback sentCallback) throws TelegramApiException { if (editMessageReplyMarkup == null) { throw new TelegramApiException("Parameter editMessageReplyMarkup can not be null"); } @@ -450,7 +462,7 @@ public abstract class AbsSender { sendApiMethodAsync(editMessageReplyMarkup, sentCallback); } - public void answerCallbackQueryAsync(AnswerCallbackQuery answerCallbackQuery, SentCallback sentCallback) throws TelegramApiException { + public final void answerCallbackQueryAsync(AnswerCallbackQuery answerCallbackQuery, SentCallback sentCallback) throws TelegramApiException { if (answerCallbackQuery == null) { throw new TelegramApiException("Parameter answerCallbackQuery can not be null"); } @@ -461,7 +473,7 @@ public abstract class AbsSender { sendApiMethodAsync(answerCallbackQuery, sentCallback); } - public void getUserProfilePhotosAsync(GetUserProfilePhotos getUserProfilePhotos, SentCallback sentCallback) throws TelegramApiException { + public final void getUserProfilePhotosAsync(GetUserProfilePhotos getUserProfilePhotos, SentCallback sentCallback) throws TelegramApiException { if (getUserProfilePhotos == null) { throw new TelegramApiException("Parameter getUserProfilePhotos can not be null"); } @@ -473,7 +485,7 @@ public abstract class AbsSender { sendApiMethodAsync(getUserProfilePhotos, sentCallback); } - public void getFileAsync(GetFile getFile, SentCallback sentCallback) throws TelegramApiException { + public final void getFileAsync(GetFile getFile, SentCallback sentCallback) throws TelegramApiException { if (getFile == null) { throw new TelegramApiException("Parameter getFile can not be null"); } else if (getFile.getFileId() == null) { @@ -483,7 +495,7 @@ public abstract class AbsSender { sendApiMethodAsync(getFile, sentCallback); } - public void getMeAsync(SentCallback sentCallback) throws TelegramApiException { + public final void getMeAsync(SentCallback sentCallback) throws TelegramApiException { if (sentCallback == null) { throw new TelegramApiException("Parameter sentCallback can not be null"); } @@ -494,7 +506,7 @@ public abstract class AbsSender { // Specific Send Requests - public Message sendDocument(SendDocument sendDocument) throws TelegramApiException { + public final Message sendDocument(SendDocument sendDocument) throws TelegramApiException { String responseContent; try { @@ -561,7 +573,7 @@ public abstract class AbsSender { return new Message(jsonObject.getJSONObject(Constants.RESPONSEFIELDRESULT)); } - public Message sendPhoto(SendPhoto sendPhoto) throws TelegramApiException { + public final Message sendPhoto(SendPhoto sendPhoto) throws TelegramApiException { String responseContent; try { String url = getBaseUrl() + SendPhoto.PATH; @@ -627,7 +639,7 @@ public abstract class AbsSender { return new Message(jsonObject.getJSONObject(Constants.RESPONSEFIELDRESULT)); } - public Message sendVideo(SendVideo sendVideo) throws TelegramApiException { + public final Message sendVideo(SendVideo sendVideo) throws TelegramApiException { String responseContent; try { String url = getBaseUrl() + SendVideo.PATH; @@ -711,7 +723,7 @@ public abstract class AbsSender { return new Message(jsonObject.getJSONObject(Constants.RESPONSEFIELDRESULT)); } - public Message sendSticker(SendSticker sendSticker) throws TelegramApiException { + public final Message sendSticker(SendSticker sendSticker) throws TelegramApiException { String responseContent; try { @@ -778,7 +790,7 @@ public abstract class AbsSender { * @return If success, the sent Message is returned * @throws TelegramApiException If there is any error sending the audio */ - public Message sendAudio(SendAudio sendAudio) throws TelegramApiException { + public final Message sendAudio(SendAudio sendAudio) throws TelegramApiException { String responseContent; @@ -868,7 +880,7 @@ public abstract class AbsSender { * @return If success, the sent Message is returned * @throws TelegramApiException If there is any error sending the audio */ - public Message sendVoice(SendVoice sendVoice) throws TelegramApiException { + public final Message sendVoice(SendVoice sendVoice) throws TelegramApiException { String responseContent; try { diff --git a/src/main/java/org/telegram/telegrambots/bots/BotOptions.java b/src/main/java/org/telegram/telegrambots/bots/BotOptions.java new file mode 100644 index 00000000..081481a9 --- /dev/null +++ b/src/main/java/org/telegram/telegrambots/bots/BotOptions.java @@ -0,0 +1,35 @@ +package org.telegram.telegrambots.bots; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief Configurations for the Bot + * @date 21 of July of 2016 + */ +public class BotOptions { + private String proxyHost; + private int proxyPort; + + public BotOptions() { + } + + public String getProxyHost() { + return proxyHost; + } + + public int getProxyPort() { + return proxyPort; + } + + public void setProxyHost(String proxyHost) { + this.proxyHost = proxyHost; + } + + public void setProxyPort(int proxyPort) { + this.proxyPort = proxyPort; + } + + public boolean hasProxy() { + return proxyHost != null && !proxyHost.isEmpty() && proxyPort > 0; + } +} diff --git a/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingBot.java b/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingBot.java index 7afdf9c8..40915803 100644 --- a/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingBot.java +++ b/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingBot.java @@ -7,5 +7,11 @@ package org.telegram.telegrambots.bots; * @date 14 of January of 2016 */ public abstract class TelegramLongPollingBot extends AbsSender implements ITelegramLongPollingBot { + public TelegramLongPollingBot() { + this(new BotOptions()); + } + public TelegramLongPollingBot(BotOptions options) { + super(options); + } } diff --git a/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingCommandBot.java b/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingCommandBot.java index 8ff78678..e6d2b25f 100644 --- a/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingCommandBot.java +++ b/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingCommandBot.java @@ -24,7 +24,15 @@ public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingB * Use ICommandRegistry's methods on this bot to register commands */ public TelegramLongPollingCommandBot() { - super(); + this(new BotOptions()); + } + + /** + * construct creates CommandRegistry for this bot. + * Use ICommandRegistry's methods on this bot to register commands + */ + public TelegramLongPollingCommandBot(BotOptions options) { + super(options); this.commandRegistry = new CommandRegistry(); } diff --git a/src/main/java/org/telegram/telegrambots/bots/TelegramWebhookBot.java b/src/main/java/org/telegram/telegrambots/bots/TelegramWebhookBot.java index ddf56bca..b3f41afb 100644 --- a/src/main/java/org/telegram/telegrambots/bots/TelegramWebhookBot.java +++ b/src/main/java/org/telegram/telegrambots/bots/TelegramWebhookBot.java @@ -7,4 +7,11 @@ package org.telegram.telegrambots.bots; * @date 14 of January of 2016 */ public abstract class TelegramWebhookBot extends AbsSender implements ITelegramWebhookBot { + public TelegramWebhookBot() { + this(new BotOptions()); + } + + public TelegramWebhookBot(BotOptions options) { + super(options); + } } diff --git a/src/main/java/org/telegram/telegrambots/updatesreceivers/BotSession.java b/src/main/java/org/telegram/telegrambots/updatesreceivers/BotSession.java index 554c69e6..b13c5b2f 100644 --- a/src/main/java/org/telegram/telegrambots/updatesreceivers/BotSession.java +++ b/src/main/java/org/telegram/telegrambots/updatesreceivers/BotSession.java @@ -1,6 +1,7 @@ package org.telegram.telegrambots.updatesreceivers; import org.apache.http.HttpEntity; +import org.apache.http.HttpHost; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; @@ -18,6 +19,7 @@ import org.telegram.telegrambots.Constants; import org.telegram.telegrambots.TelegramApiException; import org.telegram.telegrambots.api.methods.updates.GetUpdates; import org.telegram.telegrambots.api.objects.Update; +import org.telegram.telegrambots.bots.BotOptions; import org.telegram.telegrambots.bots.ITelegramLongPollingBot; import org.telegram.telegrambots.logging.BotLogger; @@ -47,8 +49,19 @@ public class BotSession { private volatile CloseableHttpClient httpclient; private volatile RequestConfig requestConfig; - + /** + * Constructor present just to keep backward compatibility will be removed in next mayor release. + * + * @deprecated @deprecated use {@link #BotSession(String, ITelegramLongPollingBot, BotOptions)} + * @param token Token of the bot + * @param callback Callback for incomming updates + */ + @Deprecated public BotSession(String token, ITelegramLongPollingBot callback) { + this(token, callback, new BotOptions()); + } + + public BotSession(String token, ITelegramLongPollingBot callback, BotOptions options) { this.token = token; this.callback = callback; @@ -58,8 +71,12 @@ public class BotSession { .setMaxConnTotal(100) .build(); - requestConfig = RequestConfig.copy(RequestConfig.custom().build()) - .setSocketTimeout(SOCKET_TIMEOUT) + RequestConfig.Builder configBuilder = RequestConfig.copy(RequestConfig.custom().build()); + if (options.hasProxy()) { + configBuilder.setProxy(new HttpHost(options.getProxyHost(), options.getProxyPort())); + } + + requestConfig = configBuilder.setSocketTimeout(SOCKET_TIMEOUT) .setConnectTimeout(SOCKET_TIMEOUT) .setConnectionRequestTimeout(SOCKET_TIMEOUT).build(); From 45b63d9ea21c32521a2a9867ec7cf06b2914ae00 Mon Sep 17 00:00:00 2001 From: Rubenlagus Date: Thu, 21 Jul 2016 22:21:22 +0200 Subject: [PATCH 8/8] Update to version 2.3.3.5 --- README.md | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 09533615..ffb57048 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Both ways are supported, but I recommend long polling method. ## Usage -Just import add the library to your project using [Maven, Gradle, ...](https://jitpack.io/#rubenlagus/TelegramBots/v2.3.3.4) or download the jar(including all dependencies) from [here](https://github.com/rubenlagus/TelegramBots/releases/tag/v2.3.3.4) +Just import add the library to your project using [Maven, Gradle, ...](https://jitpack.io/#rubenlagus/TelegramBots/v2.3.3.5) or download the jar(including all dependencies) from [here](https://github.com/rubenlagus/TelegramBots/releases/tag/v2.3.3.5) In order to use Long Polling mode, just create your own bot extending `org.telegram.telegrambots.bots.TelegramLongPollingBot`. diff --git a/pom.xml b/pom.xml index e05ed769..ee620853 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ jar org.telegram telegrambots - 2.3.3.4 + 2.3.3.5 Telegram Bots https://telegram.me/JavaBotsApi