commit
431d945486
137
Bots.ipr
137
Bots.ipr
@ -20,6 +20,7 @@
|
||||
<module name="telegrambots-abilities" />
|
||||
<module name="telegrambots-extensions" />
|
||||
<module name="telegrambots-meta" />
|
||||
<module name="telegrambots-spring-boot-starter" />
|
||||
</profile>
|
||||
<profile name="Annotation profile for Bots" enabled="true">
|
||||
<sourceOutputDir name="../telegrambots/target/generated-sources/annotations" />
|
||||
@ -34,11 +35,12 @@
|
||||
<module name="telegrambots-abilities" target="1.8" />
|
||||
<module name="telegrambots-extensions" target="1.8" />
|
||||
<module name="telegrambots-meta" target="1.8" />
|
||||
<module name="telegrambots-spring-boot-starter" target="1.8" />
|
||||
</bytecodeTargetLevel>
|
||||
</component>
|
||||
<component name="DBNavigator.Project.DataEditorManager">
|
||||
<record-view-column-sorting-type value="BY_INDEX" />
|
||||
<value-preview-text-wrapping value="true" />
|
||||
<value-preview-text-wrapping value="false" />
|
||||
<value-preview-pinned value="false" />
|
||||
</component>
|
||||
<component name="DBNavigator.Project.DataExportManager">
|
||||
@ -409,7 +411,6 @@
|
||||
<debug-execution-timeout value="600" />
|
||||
<focus-result value="false" />
|
||||
<prompt-execution value="false" />
|
||||
<target-connection value="ASK" />
|
||||
</statement-execution>
|
||||
<script-execution>
|
||||
<command-line-interfaces />
|
||||
@ -501,6 +502,7 @@
|
||||
<file url="file://$PROJECT_DIR$/telegrambots-abilities" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/telegrambots-extensions" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/telegrambots-meta" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/telegrambots-spring-boot-starter" charset="UTF-8" />
|
||||
<file url="PROJECT" charset="UTF-8" />
|
||||
</component>
|
||||
<component name="InspectionProjectProfileManager">
|
||||
@ -747,6 +749,59 @@
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="GoogleStyle" />
|
||||
<code_scheme name="Project" version="173">
|
||||
<DBN-PSQL>
|
||||
<case-options enabled="false">
|
||||
<option name="KEYWORD_CASE" value="lower" />
|
||||
<option name="FUNCTION_CASE" value="lower" />
|
||||
<option name="PARAMETER_CASE" value="lower" />
|
||||
<option name="DATATYPE_CASE" value="lower" />
|
||||
<option name="OBJECT_CASE" value="preserve" />
|
||||
</case-options>
|
||||
<formatting-settings enabled="false" />
|
||||
</DBN-PSQL>
|
||||
<DBN-SQL>
|
||||
<case-options enabled="false">
|
||||
<option name="KEYWORD_CASE" value="lower" />
|
||||
<option name="FUNCTION_CASE" value="lower" />
|
||||
<option name="PARAMETER_CASE" value="lower" />
|
||||
<option name="DATATYPE_CASE" value="lower" />
|
||||
<option name="OBJECT_CASE" value="preserve" />
|
||||
</case-options>
|
||||
<formatting-settings enabled="false">
|
||||
<option name="STATEMENT_SPACING" value="one_line" />
|
||||
<option name="CLAUSE_CHOP_DOWN" value="chop_down_if_statement_long" />
|
||||
<option name="ITERATION_ELEMENTS_WRAPPING" value="chop_down_if_not_single" />
|
||||
</formatting-settings>
|
||||
</DBN-SQL>
|
||||
<DBN-PSQL>
|
||||
<case-options enabled="false">
|
||||
<option name="KEYWORD_CASE" value="lower" />
|
||||
<option name="FUNCTION_CASE" value="lower" />
|
||||
<option name="PARAMETER_CASE" value="lower" />
|
||||
<option name="DATATYPE_CASE" value="lower" />
|
||||
<option name="OBJECT_CASE" value="preserve" />
|
||||
</case-options>
|
||||
<formatting-settings enabled="false" />
|
||||
</DBN-PSQL>
|
||||
<DBN-SQL>
|
||||
<case-options enabled="false">
|
||||
<option name="KEYWORD_CASE" value="lower" />
|
||||
<option name="FUNCTION_CASE" value="lower" />
|
||||
<option name="PARAMETER_CASE" value="lower" />
|
||||
<option name="DATATYPE_CASE" value="lower" />
|
||||
<option name="OBJECT_CASE" value="preserve" />
|
||||
</case-options>
|
||||
<formatting-settings enabled="false">
|
||||
<option name="STATEMENT_SPACING" value="one_line" />
|
||||
<option name="CLAUSE_CHOP_DOWN" value="chop_down_if_statement_long" />
|
||||
<option name="ITERATION_ELEMENTS_WRAPPING" value="chop_down_if_not_single" />
|
||||
</formatting-settings>
|
||||
</DBN-SQL>
|
||||
</code_scheme>
|
||||
</component>
|
||||
<component name="ProjectCodeStyleSettingsManager">
|
||||
<option name="PER_PROJECT_SETTINGS">
|
||||
<value>
|
||||
@ -785,6 +840,7 @@
|
||||
<module fileurl="file://$PROJECT_DIR$/telegrambots-abilities/telegrambots-abilities.iml" filepath="$PROJECT_DIR$/telegrambots-abilities/telegrambots-abilities.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/telegrambots-extensions/telegrambots-extensions.iml" filepath="$PROJECT_DIR$/telegrambots-extensions/telegrambots-extensions.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/telegrambots-meta/telegrambots-meta.iml" filepath="$PROJECT_DIR$/telegrambots-meta/telegrambots-meta.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/telegrambots-spring-boot-starter/telegrambots-spring-boot-starter.iml" filepath="$PROJECT_DIR$/telegrambots-spring-boot-starter/telegrambots-spring-boot-starter.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
@ -1472,6 +1528,83 @@
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/mockito/mockito-all/2.0.2-beta/mockito-all-2.0.2-beta-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
<library name="Maven: org.springframework.boot:spring-boot-autoconfigure:1.5.10.RELEASE">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-autoconfigure/1.5.10.RELEASE/spring-boot-autoconfigure-1.5.10.RELEASE.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-autoconfigure/1.5.10.RELEASE/spring-boot-autoconfigure-1.5.10.RELEASE-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-autoconfigure/1.5.10.RELEASE/spring-boot-autoconfigure-1.5.10.RELEASE-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
<library name="Maven: org.springframework.boot:spring-boot:1.5.10.RELEASE">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot/1.5.10.RELEASE/spring-boot-1.5.10.RELEASE.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot/1.5.10.RELEASE/spring-boot-1.5.10.RELEASE-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot/1.5.10.RELEASE/spring-boot-1.5.10.RELEASE-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
<library name="Maven: org.springframework:spring-aop:4.3.14.RELEASE">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-aop/4.3.14.RELEASE/spring-aop-4.3.14.RELEASE.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-aop/4.3.14.RELEASE/spring-aop-4.3.14.RELEASE-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-aop/4.3.14.RELEASE/spring-aop-4.3.14.RELEASE-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
<library name="Maven: org.springframework:spring-beans:4.3.14.RELEASE">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-beans/4.3.14.RELEASE/spring-beans-4.3.14.RELEASE.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-beans/4.3.14.RELEASE/spring-beans-4.3.14.RELEASE-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-beans/4.3.14.RELEASE/spring-beans-4.3.14.RELEASE-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
<library name="Maven: org.springframework:spring-context:4.3.14.RELEASE">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-context/4.3.14.RELEASE/spring-context-4.3.14.RELEASE.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-context/4.3.14.RELEASE/spring-context-4.3.14.RELEASE-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-context/4.3.14.RELEASE/spring-context-4.3.14.RELEASE-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
<library name="Maven: org.springframework:spring-core:4.3.14.RELEASE">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-core/4.3.14.RELEASE/spring-core-4.3.14.RELEASE.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-core/4.3.14.RELEASE/spring-core-4.3.14.RELEASE-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-core/4.3.14.RELEASE/spring-core-4.3.14.RELEASE-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
<library name="Maven: org.springframework:spring-expression:4.3.14.RELEASE">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-expression/4.3.14.RELEASE/spring-expression-4.3.14.RELEASE.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-expression/4.3.14.RELEASE/spring-expression-4.3.14.RELEASE-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-expression/4.3.14.RELEASE/spring-expression-4.3.14.RELEASE-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
<library name="Maven: org.telegram:telegrambots-meta:3.5">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/telegram/telegrambots-meta/3.5/telegrambots-meta-3.5.jar!/" />
|
||||
|
@ -27,7 +27,7 @@ Just import add the library to your project with one of these options:
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots</artifactId>
|
||||
<version>3.6</version>
|
||||
<version>3.6.1</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
|
@ -1,3 +1,8 @@
|
||||
### <a id="3.6.1"></a>3.6.1 ###
|
||||
1. Support for proxy connections
|
||||
2. New module for Spring
|
||||
3. Bug fixing
|
||||
|
||||
### <a id="3.6"></a>3.6 ###
|
||||
1. Support for Api Version [3.6](https://core.telegram.org/bots/api-changelog#february-13-2018)
|
||||
2. Bug fixing and other improvements
|
||||
|
@ -6,6 +6,7 @@
|
||||
* [How can I compile my project?](#how_to_compile)
|
||||
* [Method ```sendMessage()``` (or other) is deprecated, what should I do?](#sendmessage_deprecated)
|
||||
* [Is there any example for WebHook?](#example_webhook)
|
||||
* [How to use spring boot starter?](#spring_boot_starter)
|
||||
|
||||
## <a id="how_to_get_picture"></a>How to download photo? ##
|
||||
|
||||
@ -221,3 +222,34 @@ If you extend ```TelegramLongPollingCommandBot```, then use ```AbsSender.execute
|
||||
|
||||
## <a id="example_webhook"></a>Is there any example for WebHook? ##
|
||||
Please see the example Bot for https://telegram.me/SnowcrashBot in the [TelegramBotsExample]() repo and also an [example bot for Sping Boot](https://github.com/UnAfraid/SpringTelegramBot) from [UnAfraid](https://github.com/UnAfraid) [here](https://github.com/UnAfraid/SpringTelegramBot/blob/master/src/main/java/com/github/unafraid/spring/bot/TelegramWebhookBot.java)
|
||||
|
||||
|
||||
|
||||
## <a id="spring_boot_starter"></a>How to use spring boot starter ##
|
||||
----------
|
||||
Your main spring boot class should look like this:
|
||||
|
||||
```java
|
||||
@SpringBootApplication
|
||||
//Add this annotation to enable automatic bots initializing
|
||||
@EnableTelegramBots
|
||||
public class YourApplicationMainClass {
|
||||
|
||||
public static void main(String[] args) {
|
||||
//Add this line to initialize bots context
|
||||
ApiContextInitializer.init();
|
||||
|
||||
SpringApplication.run(MusicUploaderApplication.class, args);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
After that your bot will look like:
|
||||
```java
|
||||
//Standart Spring component annotation
|
||||
@Component
|
||||
public class YourBotClassName extends TelegramLongPollingBot {
|
||||
//Bot body.
|
||||
}
|
||||
```
|
||||
Also you could just implement LongPollingBot or WebHookBot interfaces. All this bots will be registered in context and connected to Telegram api.
|
@ -11,7 +11,7 @@ First you need ot get the library and add it to your project. There are few poss
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots</artifactId>
|
||||
<version>3.6</version>
|
||||
<version>3.6.1</version>
|
||||
</dependency>
|
||||
```
|
||||
* With **Gradle**:
|
||||
|
@ -1,6 +1,6 @@
|
||||
### <a id="2.4.3"></a>To version 2.4.3 ###
|
||||
1. Replace `BotOptions` by `DefaultBotOptions`.
|
||||
2. At the beginning of your program (before creating your `TelegramBotsApi` instance, add the following line:
|
||||
2. At the beginning of your program (before creating your `TelegramBotsApi` or `Bot` instance, add the following line:
|
||||
```java
|
||||
ApiContextInitializer.init();
|
||||
```
|
||||
|
122
TelegramBots.wiki/Using-Http-Proxy.md
Normal file
122
TelegramBots.wiki/Using-Http-Proxy.md
Normal file
@ -0,0 +1,122 @@
|
||||
### Using HTTP proxy
|
||||
|
||||
HTTP proxy support implemented since version 3.6.1
|
||||
|
||||
First of all you need to override constructor with `DefaultBotOptions` argument while inheriting from `AbilityBot` or `TelegramLongPollingBot`
|
||||
|
||||
```java
|
||||
public class MyBot extends AbilityBot {
|
||||
|
||||
protected MyBot(String botToken, String botUsername, DefaultBotOptions botOptions) {
|
||||
super(botToken, botUsername, botOptions);
|
||||
}
|
||||
|
||||
public int creatorId() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Ability pingPong() {
|
||||
return Ability
|
||||
.builder()
|
||||
.name("ping")
|
||||
.info("ping pong")
|
||||
.locality(ALL)
|
||||
.privacy(PUBLIC)
|
||||
.action(ctx -> silent.send("pong", ctx.chatId()))
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
Now you are able to set up your proxy
|
||||
|
||||
#### without authentication
|
||||
|
||||
```java
|
||||
public class Main {
|
||||
|
||||
private static String BOT_NAME = "My test bot";
|
||||
private static String BOT_TOKEN = "..." /* your bot's token here */;
|
||||
|
||||
private static String PROXY_HOST = "..." /* proxy host */;
|
||||
private static Integer PROXY_PORT = 3128 /* proxy port */;
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
|
||||
ApiContextInitializer.init();
|
||||
|
||||
// Create the TelegramBotsApi object to register your bots
|
||||
TelegramBotsApi botsApi = new TelegramBotsApi();
|
||||
|
||||
// Set up Http proxy
|
||||
DefaultBotOptions botOptions = ApiContext.getInstance(DefaultBotOptions.class);
|
||||
|
||||
HttpHost httpHost = new HttpHost(PROXY_HOST, PROXY_PORT);
|
||||
|
||||
RequestConfig requestConfig = RequestConfig.custom().setProxy(httpHost).setAuthenticationEnabled(false).build();
|
||||
botOptions.setRequestConfig(requestConfig);
|
||||
botOptions.setHttpProxy(httpHost);
|
||||
|
||||
// Register your newly created AbilityBot
|
||||
MyBot bot = new MyBot(BOT_TOKEN, BOT_NAME, botOptions);
|
||||
|
||||
botsApi.registerBot(bot);
|
||||
|
||||
} catch (TelegramApiException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
#### With authentication
|
||||
|
||||
```java
|
||||
public class Main {
|
||||
|
||||
private static String BOT_NAME = "My test bot";
|
||||
private static String BOT_TOKEN = "..." /* your bot's token here */;
|
||||
|
||||
private static String PROXY_HOST = "..." /* proxy host */;
|
||||
private static Integer PROXY_PORT = 3128 /* proxy port */;
|
||||
private static String PROXY_USER = "..." /* proxy user */;
|
||||
private static String PROXY_PASSWORD = "..." /* proxy password */;
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
|
||||
ApiContextInitializer.init();
|
||||
|
||||
// Create the TelegramBotsApi object to register your bots
|
||||
TelegramBotsApi botsApi = new TelegramBotsApi();
|
||||
|
||||
// Set up Http proxy
|
||||
DefaultBotOptions botOptions = ApiContext.getInstance(DefaultBotOptions.class);
|
||||
|
||||
CredentialsProvider credsProvider = new BasicCredentialsProvider();
|
||||
credsProvider.setCredentials(
|
||||
new AuthScope(PROXY_HOST, PROXY_PORT),
|
||||
new UsernamePasswordCredentials(PROXY_USER, PROXY_PASSWORD));
|
||||
|
||||
HttpHost httpHost = new HttpHost(PROXY_HOST, PROXY_PORT);
|
||||
|
||||
RequestConfig requestConfig = RequestConfig.custom().setProxy(httpHost).setAuthenticationEnabled(true).build();
|
||||
botOptions.setRequestConfig(requestConfig);
|
||||
botOptions.setCredentialsProvider(credsProvider);
|
||||
botOptions.setHttpProxy(httpHost);
|
||||
|
||||
// Register your newly created AbilityBot
|
||||
MyBot bot = new MyBot(BOT_TOKEN, BOT_NAME, botOptions);
|
||||
|
||||
botsApi.registerBot(bot);
|
||||
|
||||
} catch (TelegramApiException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
@ -1,6 +1,7 @@
|
||||
* Users guide
|
||||
* [[Getting Started]]
|
||||
* [[Errors Handling]]
|
||||
* [[Using HTTP Proxy]]
|
||||
* [[FAQ]]
|
||||
* AbilityBot
|
||||
* [[Simple Example]]
|
||||
|
@ -8,8 +8,8 @@ As with any Java project, you will need to set your dependencies.
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots-abilties</artifactId>
|
||||
<version>3.6</version>
|
||||
<artifactId>telegrambots-abilities</artifactId>
|
||||
<version>3.6.1</version>
|
||||
</dependency>
|
||||
```
|
||||
* **Gradle**
|
||||
|
@ -12,7 +12,7 @@ public Reply sayYuckOnImage() {
|
||||
// getChatId is a public utility function in rg.telegram.abilitybots.api.util.AbilityUtils
|
||||
Consumer<Update> action = upd -> silent.send("Yuck", getChatId(upd));
|
||||
|
||||
return Reply.of(upd, Flag.PHOTO)
|
||||
return Reply.of(action, Flag.PHOTO)
|
||||
}
|
||||
```
|
||||
|
||||
@ -74,4 +74,4 @@ public Ability playWithMe() {
|
||||
|
||||
In this example, we showcase how we can supply our own predicates. The two new predicates are `isReplyToMessage` and `isReplyToBot`.
|
||||
The checks are made so that, once you execute your logic there is no need to check for the validity of the reply.
|
||||
They were all made once the action logic is being executed.
|
||||
They were all made once the action logic is being executed.
|
||||
|
5
pom.xml
5
pom.xml
@ -7,13 +7,14 @@
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>Bots</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>3.6</version>
|
||||
<version>3.6.1</version>
|
||||
|
||||
<modules>
|
||||
<module>telegrambots</module>
|
||||
<module>telegrambots-meta</module>
|
||||
<module>telegrambots-extensions</module>
|
||||
<module>telegrambots-abilities</module>
|
||||
<module>telegrambots-spring-boot-starter</module>
|
||||
</modules>
|
||||
|
||||
<licenses>
|
||||
@ -26,6 +27,6 @@
|
||||
|
||||
<properties>
|
||||
<maven.deploy.skip>true</maven.deploy.skip>
|
||||
<bots.version>3.6</bots.version>
|
||||
<bots.version>3.6.1</bots.version>
|
||||
</properties>
|
||||
</project>
|
@ -18,7 +18,7 @@ Usage
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots-abilities</artifactId>
|
||||
<version>3.6</version>
|
||||
<version>3.6.1</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots-abilities</artifactId>
|
||||
<version>3.6</version>
|
||||
<version>3.6.1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Telegram Ability Bot</name>
|
||||
@ -65,7 +65,7 @@
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<bots.version>3.6</bots.version>
|
||||
<bots.version>3.6.1</bots.version>
|
||||
<commonslang.version>3.5</commonslang.version>
|
||||
<mapdb.version>3.0.4</mapdb.version>
|
||||
<guava.version>19.0</guava.version>
|
||||
|
@ -16,7 +16,7 @@ Just import add the library to your project with one of these options:
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambotsextensions</artifactId>
|
||||
<version>3.6</version>
|
||||
<version>3.6.1</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambotsextensions</artifactId>
|
||||
<version>3.6</version>
|
||||
<version>3.6.1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Telegram Bots Extensions</name>
|
||||
@ -59,7 +59,7 @@
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<bots.version>3.6</bots.version>
|
||||
<bots.version>3.6.1</bots.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
@ -9,6 +9,7 @@ import org.telegram.telegrambots.bots.DefaultBotOptions;
|
||||
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
|
||||
import org.telegram.telegrambots.bots.commandbot.commands.BotCommand;
|
||||
import org.telegram.telegrambots.bots.commandbot.commands.CommandRegistry;
|
||||
import org.telegram.telegrambots.bots.commandbot.commands.IBotCommand;
|
||||
import org.telegram.telegrambots.bots.commandbot.commands.ICommandRegistry;
|
||||
|
||||
import java.util.Collection;
|
||||
@ -105,27 +106,27 @@ public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingB
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean register(BotCommand botCommand) {
|
||||
public final boolean register(IBotCommand botCommand) {
|
||||
return commandRegistry.register(botCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Map<BotCommand, Boolean> registerAll(BotCommand... botCommands) {
|
||||
public final Map<IBotCommand, Boolean> registerAll(IBotCommand... botCommands) {
|
||||
return commandRegistry.registerAll(botCommands);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean deregister(BotCommand botCommand) {
|
||||
public final boolean deregister(IBotCommand botCommand) {
|
||||
return commandRegistry.deregister(botCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Map<BotCommand, Boolean> deregisterAll(BotCommand... botCommands) {
|
||||
public final Map<IBotCommand, Boolean> deregisterAll(IBotCommand... botCommands) {
|
||||
return commandRegistry.deregisterAll(botCommands);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Collection<BotCommand> getRegisteredCommands() {
|
||||
public final Collection<IBotCommand> getRegisteredCommands() {
|
||||
return commandRegistry.getRegisteredCommands();
|
||||
}
|
||||
|
||||
@ -135,7 +136,7 @@ public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingB
|
||||
}
|
||||
|
||||
@Override
|
||||
public final BotCommand getRegisteredCommand(String commandIdentifier) {
|
||||
public final IBotCommand getRegisteredCommand(String commandIdentifier) {
|
||||
return commandRegistry.getRegisteredCommand(commandIdentifier);
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ import org.telegram.telegrambots.bots.AbsSender;
|
||||
*
|
||||
* @author Timo Schulz (Mit0x2)
|
||||
*/
|
||||
public abstract class BotCommand {
|
||||
public abstract class BotCommand implements IBotCommand {
|
||||
public final static String COMMAND_INIT_CHARACTER = "/";
|
||||
public static final String COMMAND_PARAMETER_SEPARATOR_REGEXP = "\\s+";
|
||||
private final static int COMMAND_MAX_LENGTH = 32;
|
||||
@ -74,7 +74,7 @@ public abstract class BotCommand {
|
||||
* @param message the message to process
|
||||
* @param arguments passed arguments
|
||||
*/
|
||||
void processMessage(AbsSender absSender, Message message, String[] arguments) {
|
||||
public void processMessage(AbsSender absSender, Message message, String[] arguments) {
|
||||
execute(absSender, message.getFrom(), message.getChat(), arguments);
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ import java.util.function.BiConsumer;
|
||||
*/
|
||||
public final class CommandRegistry implements ICommandRegistry {
|
||||
|
||||
private final Map<String, BotCommand> commandRegistryMap = new HashMap<>();
|
||||
private final Map<String, IBotCommand> commandRegistryMap = new HashMap<>();
|
||||
private final boolean allowCommandsWithUsername;
|
||||
private final String botUsername;
|
||||
private BiConsumer<AbsSender, Message> defaultConsumer;
|
||||
@ -37,7 +37,7 @@ public final class CommandRegistry implements ICommandRegistry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean register(BotCommand botCommand) {
|
||||
public final boolean register(IBotCommand botCommand) {
|
||||
if (commandRegistryMap.containsKey(botCommand.getCommandIdentifier())) {
|
||||
return false;
|
||||
}
|
||||
@ -46,16 +46,16 @@ public final class CommandRegistry implements ICommandRegistry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Map<BotCommand, Boolean> registerAll(BotCommand... botCommands) {
|
||||
Map<BotCommand, Boolean> resultMap = new HashMap<>(botCommands.length);
|
||||
for (BotCommand botCommand : botCommands) {
|
||||
public final Map<IBotCommand, Boolean> registerAll(IBotCommand... botCommands) {
|
||||
Map<IBotCommand, Boolean> resultMap = new HashMap<>(botCommands.length);
|
||||
for (IBotCommand botCommand : botCommands) {
|
||||
resultMap.put(botCommand, register(botCommand));
|
||||
}
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean deregister(BotCommand botCommand) {
|
||||
public final boolean deregister(IBotCommand botCommand) {
|
||||
if (commandRegistryMap.containsKey(botCommand.getCommandIdentifier())) {
|
||||
commandRegistryMap.remove(botCommand.getCommandIdentifier());
|
||||
return true;
|
||||
@ -64,21 +64,21 @@ public final class CommandRegistry implements ICommandRegistry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Map<BotCommand, Boolean> deregisterAll(BotCommand... botCommands) {
|
||||
Map<BotCommand, Boolean> resultMap = new HashMap<>(botCommands.length);
|
||||
for (BotCommand botCommand : botCommands) {
|
||||
public final Map<IBotCommand, Boolean> deregisterAll(IBotCommand... botCommands) {
|
||||
Map<IBotCommand, Boolean> resultMap = new HashMap<>(botCommands.length);
|
||||
for (IBotCommand botCommand : botCommands) {
|
||||
resultMap.put(botCommand, deregister(botCommand));
|
||||
}
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Collection<BotCommand> getRegisteredCommands() {
|
||||
public final Collection<IBotCommand> getRegisteredCommands() {
|
||||
return commandRegistryMap.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final BotCommand getRegisteredCommand(String commandIdentifier) {
|
||||
public final IBotCommand getRegisteredCommand(String commandIdentifier) {
|
||||
return commandRegistryMap.get(commandIdentifier);
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ public abstract class DefaultBotCommand extends BotCommand {
|
||||
* @param arguments passed arguments
|
||||
*/
|
||||
@Override
|
||||
void processMessage(AbsSender absSender, Message message, String[] arguments) {
|
||||
public void processMessage(AbsSender absSender, Message message, String[] arguments) {
|
||||
execute(absSender, message.getFrom(), message.getChat(), message.getMessageId(), arguments);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,37 @@
|
||||
package org.telegram.telegrambots.bots.commandbot.commands;
|
||||
|
||||
import org.telegram.telegrambots.api.objects.Message;
|
||||
import org.telegram.telegrambots.bots.AbsSender;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
/**
|
||||
* This Interface represents the a Command that can be executed
|
||||
*
|
||||
* @author Timo Schulz (Mit0x2)
|
||||
*/
|
||||
public interface IBotCommand {
|
||||
/**
|
||||
* Get the identifier of this command
|
||||
*
|
||||
* @return the identifier
|
||||
*/
|
||||
String getCommandIdentifier();
|
||||
|
||||
/**
|
||||
* Get the description of this command
|
||||
*
|
||||
* @return the description as String
|
||||
*/
|
||||
String getDescription();
|
||||
|
||||
/**
|
||||
* Process the message and execute the command
|
||||
*
|
||||
* @param absSender absSender to send messages over
|
||||
* @param message the message to process
|
||||
*/
|
||||
void processMessage(AbsSender absSender, Message message, String[] arguments);
|
||||
}
|
@ -29,7 +29,7 @@ public interface ICommandRegistry {
|
||||
* @param botCommand the command to register
|
||||
* @return whether the command could be registered, was not already registered
|
||||
*/
|
||||
boolean register(BotCommand botCommand);
|
||||
boolean register(IBotCommand botCommand);
|
||||
|
||||
/**
|
||||
* register multiple commands
|
||||
@ -37,7 +37,7 @@ public interface ICommandRegistry {
|
||||
* @param botCommands commands to register
|
||||
* @return map with results of the command register per command
|
||||
*/
|
||||
Map<BotCommand, Boolean> registerAll(BotCommand... botCommands);
|
||||
Map<IBotCommand, Boolean> registerAll(IBotCommand... botCommands);
|
||||
|
||||
/**
|
||||
* deregister a command
|
||||
@ -45,7 +45,7 @@ public interface ICommandRegistry {
|
||||
* @param botCommand the command to deregister
|
||||
* @return whether the command could be deregistered, was registered
|
||||
*/
|
||||
boolean deregister(BotCommand botCommand);
|
||||
boolean deregister(IBotCommand botCommand);
|
||||
|
||||
/**
|
||||
* deregister multiple commands
|
||||
@ -53,19 +53,19 @@ public interface ICommandRegistry {
|
||||
* @param botCommands commands to deregister
|
||||
* @return map with results of the command deregistered per command
|
||||
*/
|
||||
Map<BotCommand, Boolean> deregisterAll(BotCommand... botCommands);
|
||||
Map<IBotCommand, Boolean> deregisterAll(IBotCommand... botCommands);
|
||||
|
||||
/**
|
||||
* get a collection of all registered commands
|
||||
*
|
||||
* @return a collection of registered commands
|
||||
*/
|
||||
Collection<BotCommand> getRegisteredCommands();
|
||||
Collection<IBotCommand> getRegisteredCommands();
|
||||
|
||||
/**
|
||||
* get registered command
|
||||
*
|
||||
* @return registered command if exists or null if not
|
||||
*/
|
||||
BotCommand getRegisteredCommand(String commandIdentifier);
|
||||
IBotCommand getRegisteredCommand(String commandIdentifier);
|
||||
}
|
@ -1,16 +1,15 @@
|
||||
package org.telegram.telegrambots.bots.commandbot.commands.helpCommand;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.telegram.telegrambots.api.methods.send.SendMessage;
|
||||
import org.telegram.telegrambots.api.objects.Chat;
|
||||
import org.telegram.telegrambots.api.objects.User;
|
||||
import org.telegram.telegrambots.bots.AbsSender;
|
||||
import org.telegram.telegrambots.bots.commandbot.TelegramLongPollingCommandBot;
|
||||
import org.telegram.telegrambots.bots.commandbot.commands.BotCommand;
|
||||
import org.telegram.telegrambots.bots.commandbot.commands.IBotCommand;
|
||||
import org.telegram.telegrambots.bots.commandbot.commands.ICommandRegistry;
|
||||
import org.telegram.telegrambots.exceptions.TelegramApiException;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* A special bot command used for printing help messages similiar to the Linux man command.
|
||||
* The commands printed by this command should implement the {@link IManCommand} interface to provide an extended description.
|
||||
@ -29,9 +28,9 @@ public class HelpCommand extends ManCommand {
|
||||
* @param botCommands the Commands that should be included in the String
|
||||
* @return a formatted String containing command and description for all supplied commands
|
||||
*/
|
||||
public static String getHelpText(BotCommand...botCommands) {
|
||||
public static String getHelpText(IBotCommand...botCommands) {
|
||||
StringBuilder reply = new StringBuilder();
|
||||
for (BotCommand com : botCommands) {
|
||||
for (IBotCommand com : botCommands) {
|
||||
reply.append(com.toString()).append(System.lineSeparator()).append(System.lineSeparator());
|
||||
}
|
||||
return reply.toString();
|
||||
@ -42,8 +41,8 @@ public class HelpCommand extends ManCommand {
|
||||
* @param botCommands a collection of commands that should be included in the String
|
||||
* @return a formatted String containing command and description for all supplied commands
|
||||
*/
|
||||
public static String getHelpText(Collection<BotCommand> botCommands) {
|
||||
return getHelpText(botCommands.toArray(new BotCommand[botCommands.size()]));
|
||||
public static String getHelpText(Collection<IBotCommand> botCommands) {
|
||||
return getHelpText(botCommands.toArray(new IBotCommand[botCommands.size()]));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -60,7 +59,7 @@ public class HelpCommand extends ManCommand {
|
||||
* @param command a command the extended Descriptions is read from
|
||||
* @return the extended Description or the toString() if IManCommand is not implemented
|
||||
*/
|
||||
public static String getManText(BotCommand command) {
|
||||
public static String getManText(IBotCommand command) {
|
||||
return IManCommand.class.isInstance(command) ? getManText((IManCommand) command) : command.toString();
|
||||
}
|
||||
|
||||
@ -96,7 +95,7 @@ public class HelpCommand extends ManCommand {
|
||||
ICommandRegistry registry = (ICommandRegistry) absSender;
|
||||
|
||||
if (arguments.length > 0) {
|
||||
BotCommand command = registry.getRegisteredCommand(arguments[0]);
|
||||
IBotCommand command = registry.getRegisteredCommand(arguments[0]);
|
||||
String reply = getManText(command);
|
||||
try {
|
||||
absSender.execute(new SendMessage(chat.getId(), reply).setParseMode("HTML"));
|
||||
|
@ -5,7 +5,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots-meta</artifactId>
|
||||
<version>3.6</version>
|
||||
<version>3.6.1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Telegram Bots Meta</name>
|
||||
|
@ -97,8 +97,9 @@ public class AnswerCallbackQuery extends BotApiMethod<Boolean> {
|
||||
return cacheTime;
|
||||
}
|
||||
|
||||
public void setCacheTime(Integer cacheTime) {
|
||||
public AnswerCallbackQuery setCacheTime(Integer cacheTime) {
|
||||
this.cacheTime = cacheTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -60,7 +60,6 @@ public class StopMessageLiveLocation extends BotApiMethod<Serializable> {
|
||||
}
|
||||
|
||||
public StopMessageLiveLocation setChatId(Long chatId) {
|
||||
Objects.requireNonNull(chatId);
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
|
@ -86,7 +86,6 @@ public class GetGameHighScores extends BotApiMethod<ArrayList<GameHighScore>> {
|
||||
}
|
||||
|
||||
public GetGameHighScores setChatId(Long chatId) {
|
||||
Objects.requireNonNull(chatId);
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
|
@ -104,7 +104,6 @@ public class SetGameScore extends BotApiMethod<Serializable> {
|
||||
}
|
||||
|
||||
public SetGameScore setChatId(Long chatId) {
|
||||
Objects.requireNonNull(chatId);
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
public class UploadStickerFile extends PartialBotApiMethod<File> {
|
||||
public static final String PATH = "uploadStickerFile";
|
||||
|
||||
public static final String USERID_FIELD = "name";
|
||||
public static final String USERID_FIELD = "user_id";
|
||||
public static final String PNGSTICKER_FIELD = "png_sticker";
|
||||
|
||||
private Integer userId; ///< User identifier of sticker file owner
|
||||
|
@ -8,6 +8,7 @@ import org.telegram.telegrambots.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
@ -62,6 +63,12 @@ public class DeleteMessage extends BotApiMethod<Boolean> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public DeleteMessage setChatId(Long chatId) {
|
||||
Objects.requireNonNull(chatId);
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getMessageId() {
|
||||
return messageId;
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ public class EditMessageLiveLocation extends BotApiMethod<Serializable> {
|
||||
}
|
||||
|
||||
public EditMessageLiveLocation setLatitude(Float latitude) {
|
||||
Objects.requireNonNull(chatId);
|
||||
Objects.requireNonNull(latitude);
|
||||
this.latitude = latitude;
|
||||
return this;
|
||||
}
|
||||
@ -114,7 +114,7 @@ public class EditMessageLiveLocation extends BotApiMethod<Serializable> {
|
||||
}
|
||||
|
||||
public EditMessageLiveLocation setLongitud(Float longitud) {
|
||||
Objects.requireNonNull(chatId);
|
||||
Objects.requireNonNull(longitud);
|
||||
this.longitud = longitud;
|
||||
return this;
|
||||
}
|
||||
|
@ -63,7 +63,6 @@ public class EditMessageReplyMarkup extends BotApiMethod<Serializable> {
|
||||
}
|
||||
|
||||
public EditMessageReplyMarkup setChatId(Long chatId) {
|
||||
Objects.requireNonNull(chatId);
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
|
@ -79,7 +79,6 @@ public class EditMessageText extends BotApiMethod<Serializable> {
|
||||
}
|
||||
|
||||
public EditMessageText setChatId(Long chatId) {
|
||||
Objects.requireNonNull(chatId);
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
|
@ -357,6 +357,10 @@ public class Message implements BotApiObject {
|
||||
return this.document != null;
|
||||
}
|
||||
|
||||
public boolean hasVideo() {
|
||||
return this.video != null;
|
||||
}
|
||||
|
||||
public boolean isReply() {
|
||||
return this.replyToMessage != null;
|
||||
}
|
||||
@ -397,6 +401,10 @@ public class Message implements BotApiObject {
|
||||
return successfulPayment != null;
|
||||
}
|
||||
|
||||
public boolean hasContact() {
|
||||
return contact != null;
|
||||
}
|
||||
|
||||
public Invoice getInvoice() {
|
||||
return invoice;
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class ResponseParameters implements BotApiObject {
|
||||
* so a signed 64 bit integer or double-precision float type are safe for storing this identifier.
|
||||
*/
|
||||
@JsonProperty(MIGRATETOCHATID_FIELD)
|
||||
private Integer migrateToChatId;
|
||||
private Long migrateToChatId;
|
||||
/**
|
||||
* Optional. In case of exceeding flood control a number of seconds to
|
||||
* wait before the request can be repeated
|
||||
@ -50,7 +50,7 @@ public class ResponseParameters implements BotApiObject {
|
||||
super();
|
||||
}
|
||||
|
||||
public Integer getMigrateToChatId() {
|
||||
public Long getMigrateToChatId() {
|
||||
return migrateToChatId;
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ public class TestDeserialization {
|
||||
Assert.assertEquals(Integer.valueOf(400), result.getErrorCode());
|
||||
Assert.assertEquals("Error descriptions", result.getErrorDescription());
|
||||
Assert.assertNotNull(result.getParameters());
|
||||
Assert.assertEquals(Integer.valueOf(12345), result.getParameters().getMigrateToChatId());
|
||||
Assert.assertEquals(Long.valueOf(12345), result.getParameters().getMigrateToChatId());
|
||||
Assert.assertEquals(Integer.valueOf(12), result.getParameters().getRetryAfter());
|
||||
}
|
||||
|
||||
|
63
telegrambots-spring-boot-starter/README.md
Normal file
63
telegrambots-spring-boot-starter/README.md
Normal file
@ -0,0 +1,63 @@
|
||||
<div align="center">
|
||||
<img src="https://github.com/addo37/AbilityBots/blob/gh-pages/images/API%20BOT-03.png?raw=true" alt="abilitybots" width="200" height="200"/>
|
||||
|
||||
[![Build Status](https://travis-ci.org/rubenlagus/TelegramBots.svg?branch=master)](https://travis-ci.org/rubenlagus/TelegramBots)
|
||||
[![Jitpack](https://jitpack.io/v/rubenlagus/TelegramBots.svg)](https://jitpack.io/#rubenlagus/TelegramBots)
|
||||
[![JavaDoc](http://svgur.com/i/1Ex.svg)](https://addo37.github.io/AbilityBots/)
|
||||
[![Telegram](http://trellobot.doomdns.org/telegrambadge.svg)](https://telegram.me/JavaBotsApi)
|
||||
[![ghit.me](https://ghit.me/badge.svg?repo=rubenlagus/TelegramBots)](https://ghit.me/repo/rubenlagus/TelegramBots)
|
||||
|
||||
</div>
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
**Maven**
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots-spring-boot-starter</artifactId>
|
||||
<version>3.6.1</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
**Gradle**
|
||||
|
||||
```gradle
|
||||
compile "org.telegram:telegrambots-spring-boot-starter:3.6"
|
||||
```
|
||||
|
||||
Motivation
|
||||
----------
|
||||
If you are spring boot user it`s better to be in touch with spring starters. This module allows to register bots in spring context automatically and
|
||||
also use them as standard spring beans.
|
||||
|
||||
How to use
|
||||
----------
|
||||
Your main spring boot class should look like this:
|
||||
|
||||
```java
|
||||
@SpringBootApplication
|
||||
//Add this annotation to enable automatic bots initializing
|
||||
@EnableTelegramBots
|
||||
public class YourApplicationMainClass {
|
||||
|
||||
public static void main(String[] args) {
|
||||
//Add this line to initialize bots context
|
||||
ApiContextInitializer.init();
|
||||
|
||||
SpringApplication.run(MusicUploaderApplication.class, args);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
After that your bot will look like:
|
||||
```java
|
||||
//Standart Spring component annotation
|
||||
@Component
|
||||
public class YourBotName extends TelegramLongPollingBot {
|
||||
//Bot body.
|
||||
}
|
||||
```
|
||||
Also you could just implement LongPollingBot or WebHookBot interfaces. All this bots will be registered in context and connected to Telegram api.
|
238
telegrambots-spring-boot-starter/pom.xml
Normal file
238
telegrambots-spring-boot-starter/pom.xml
Normal file
@ -0,0 +1,238 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots-spring-boot-starter</artifactId>
|
||||
<version>3.6.1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Telegram Bots Spring Boot Starter</name>
|
||||
<url>https://github.com/rubenlagus/TelegramBots</url>
|
||||
<description>Easy to use library to create Telegram Bots</description>
|
||||
|
||||
<issueManagement>
|
||||
<url>https://github.com/rubenlagus/TelegramBots/issues</url>
|
||||
<system>GitHub Issues</system>
|
||||
</issueManagement>
|
||||
|
||||
<scm>
|
||||
<url>https://github.com/rubenlagus/TelegramBots</url>
|
||||
<connection>scm:git:git://github.com/rubenlagus/TelegramBots.git</connection>
|
||||
<developerConnection>scm:git:git@github.com:rubenlagus/TelegramBots.git</developerConnection>
|
||||
</scm>
|
||||
|
||||
<ciManagement>
|
||||
<url>https://travis-ci.org/rubenlagus/TelegramBots</url>
|
||||
<system>Travis</system>
|
||||
</ciManagement>
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
<email>homich1991@gmail.com</email>
|
||||
<name>Roman Meerson</name>
|
||||
<url>https://github.com/homich1991</url>
|
||||
<id>homich1991</id>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>MIT License</name>
|
||||
<url>http://www.opensource.org/licenses/mit-license.php</url>
|
||||
<distribution>repo</distribution>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
<id>ossrh</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</snapshotRepository>
|
||||
<repository>
|
||||
<id>ossrh</id>
|
||||
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<bots.version>3.6.1</bots.version>
|
||||
<spring-boot.version>1.5.10.RELEASE</spring-boot.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots</artifactId>
|
||||
<version>${bots.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-autoconfigure</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<directory>${project.basedir}/target</directory>
|
||||
<outputDirectory>${project.build.directory}/classes</outputDirectory>
|
||||
<finalName>${project.artifactId}-${project.version}</finalName>
|
||||
<testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>
|
||||
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<version>1.5</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>sign-artifacts</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>sign</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.sonatype.plugins</groupId>
|
||||
<artifactId>nexus-staging-maven-plugin</artifactId>
|
||||
<version>1.6.3</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<serverId>ossrh</serverId>
|
||||
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
|
||||
<autoReleaseAfterClose>true</autoReleaseAfterClose>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>clean-project</id>
|
||||
<phase>clean</phase>
|
||||
<goals>
|
||||
<goal>clean</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>make-assembly</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.10.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<additionalparam>-Xdoclint:none</additionalparam>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<version>0.7.7.201606060606</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>prepare-agent</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>report</id>
|
||||
<phase>test</phase>
|
||||
<goals>
|
||||
<goal>report</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-enforcer-plugin</artifactId>
|
||||
<version>1.4.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>enforce-versions</id>
|
||||
<goals>
|
||||
<goal>enforce</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<rules>
|
||||
<DependencyConvergence />
|
||||
</rules>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy</id>
|
||||
<phase>package</phase>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<encoding>UTF-8</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
</project>
|
@ -0,0 +1,10 @@
|
||||
package org.telegram.telegrambots.starter;
|
||||
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
/**
|
||||
* Imports configuration #TelegramBotStarterConfiguration in spring context.
|
||||
*/
|
||||
@Import(TelegramBotStarterConfiguration.class)
|
||||
public @interface EnableTelegramBots {
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package org.telegram.telegrambots.starter;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.telegram.telegrambots.TelegramBotsApi;
|
||||
import org.telegram.telegrambots.exceptions.TelegramApiException;
|
||||
import org.telegram.telegrambots.generics.LongPollingBot;
|
||||
import org.telegram.telegrambots.generics.WebhookBot;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Receives all beand which are #LongPollingBot and #WebhookBot and register them in #TelegramBotsApi.
|
||||
* #TelegramBotsApi added to spring context as well
|
||||
*/
|
||||
@Configuration
|
||||
public class TelegramBotStarterConfiguration implements CommandLineRunner {
|
||||
|
||||
|
||||
private final List<LongPollingBot> longPollingBots;
|
||||
private final List<WebhookBot> webHookBots;
|
||||
|
||||
@Autowired
|
||||
private TelegramBotsApi telegramBotsApi;
|
||||
|
||||
public TelegramBotStarterConfiguration(List<LongPollingBot> longPollingBots,
|
||||
List<WebhookBot> webHookBots) {
|
||||
this.longPollingBots = longPollingBots;
|
||||
this.webHookBots = webHookBots;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(String... args) {
|
||||
try {
|
||||
for (LongPollingBot bot : longPollingBots) {
|
||||
telegramBotsApi.registerBot(bot);
|
||||
}
|
||||
for (WebhookBot bot : webHookBots) {
|
||||
telegramBotsApi.registerBot(bot);
|
||||
}
|
||||
} catch (TelegramApiException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(TelegramBotsApi.class)
|
||||
public TelegramBotsApi telegramBotsApi() {
|
||||
return new TelegramBotsApi();
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots</artifactId>
|
||||
<version>3.6</version>
|
||||
<version>3.6.1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Telegram Bots</name>
|
||||
@ -66,7 +66,7 @@
|
||||
<jackson.version>2.8.7</jackson.version>
|
||||
<jacksonanotation.version>2.8.0</jacksonanotation.version>
|
||||
<commonio.version>2.5</commonio.version>
|
||||
<bots.version>3.6</bots.version>
|
||||
<bots.version>3.6.1</bots.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
|
@ -13,6 +13,7 @@ import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.entity.mime.MultipartEntityBuilder;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.apache.http.impl.client.ProxyAuthenticationStrategy;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.telegram.telegrambots.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.api.methods.groupadministration.SetChatPhoto;
|
||||
@ -26,6 +27,7 @@ import org.telegram.telegrambots.api.objects.media.InputMedia;
|
||||
import org.telegram.telegrambots.exceptions.TelegramApiException;
|
||||
import org.telegram.telegrambots.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
|
||||
import org.telegram.telegrambots.facilities.TelegramHttpClientBuilder;
|
||||
import org.telegram.telegrambots.updateshandlers.DownloadFileCallback;
|
||||
import org.telegram.telegrambots.updateshandlers.SentCallback;
|
||||
|
||||
@ -61,11 +63,8 @@ public abstract class DefaultAbsSender extends AbsSender {
|
||||
super();
|
||||
this.exe = Executors.newFixedThreadPool(options.getMaxThreads());
|
||||
this.options = options;
|
||||
httpclient = HttpClientBuilder.create()
|
||||
.setSSLHostnameVerifier(new NoopHostnameVerifier())
|
||||
.setConnectionTimeToLive(70, TimeUnit.SECONDS)
|
||||
.setMaxConnTotal(100)
|
||||
.build();
|
||||
|
||||
httpclient = TelegramHttpClientBuilder.build(options);
|
||||
|
||||
requestConfig = options.getRequestConfig();
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package org.telegram.telegrambots.bots;
|
||||
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.client.CredentialsProvider;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.telegram.telegrambots.ApiConstants;
|
||||
import org.telegram.telegrambots.generics.BotOptions;
|
||||
@ -21,6 +23,9 @@ public class DefaultBotOptions implements BotOptions {
|
||||
private String baseUrl;
|
||||
private List<String> allowedUpdates;
|
||||
|
||||
private CredentialsProvider credentialsProvider;
|
||||
private HttpHost httpProxy;
|
||||
|
||||
public DefaultBotOptions() {
|
||||
maxThreads = 1;
|
||||
baseUrl = ApiConstants.BASE_URL;
|
||||
@ -82,4 +87,20 @@ public class DefaultBotOptions implements BotOptions {
|
||||
public void setExponentialBackOff(ExponentialBackOff exponentialBackOff) {
|
||||
this.exponentialBackOff = exponentialBackOff;
|
||||
}
|
||||
|
||||
public CredentialsProvider getCredentialsProvider() {
|
||||
return credentialsProvider;
|
||||
}
|
||||
|
||||
public void setCredentialsProvider(CredentialsProvider credentialsProvider) {
|
||||
this.credentialsProvider = credentialsProvider;
|
||||
}
|
||||
|
||||
public HttpHost getHttpProxy() {
|
||||
return httpProxy;
|
||||
}
|
||||
|
||||
public void setHttpProxy(HttpHost httpProxy) {
|
||||
this.httpProxy = httpProxy;
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,11 @@
|
||||
package org.telegram.telegrambots.bots;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.conn.ssl.NoopHostnameVerifier;
|
||||
import org.apache.http.entity.BufferedHttpEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.telegram.telegrambots.ApiConstants;
|
||||
import org.telegram.telegrambots.ApiContext;
|
||||
import org.telegram.telegrambots.api.methods.updates.SetWebhook;
|
||||
import org.telegram.telegrambots.api.methods.updates.DeleteWebhook;
|
||||
import org.telegram.telegrambots.exceptions.TelegramApiException;
|
||||
import org.telegram.telegrambots.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.generics.LongPollingBot;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
@ -36,23 +23,13 @@ public abstract class TelegramLongPollingBot extends DefaultAbsSender implements
|
||||
|
||||
@Override
|
||||
public void clearWebhook() throws TelegramApiRequestException {
|
||||
try (CloseableHttpClient httpclient = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()).build()) {
|
||||
String url = getOptions().getBaseUrl() + getBotToken() + "/" + SetWebhook.PATH;
|
||||
HttpGet httpGet = new HttpGet(url);
|
||||
httpGet.setConfig(getOptions().getRequestConfig());
|
||||
try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
|
||||
HttpEntity ht = response.getEntity();
|
||||
BufferedHttpEntity buf = new BufferedHttpEntity(ht);
|
||||
String responseContent = EntityUtils.toString(buf, StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(responseContent);
|
||||
if (!jsonObject.getBoolean(ApiConstants.RESPONSE_FIELD_OK)) {
|
||||
throw new TelegramApiRequestException("Error removing old webhook", jsonObject);
|
||||
}
|
||||
try {
|
||||
boolean result = execute(new DeleteWebhook());
|
||||
if (!result) {
|
||||
throw new TelegramApiRequestException("Error removing old webhook");
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
throw new TelegramApiRequestException("Error deserializing setWebhook method response", e);
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Error executing setWebook method", e);
|
||||
} catch (TelegramApiException e) {
|
||||
throw new TelegramApiRequestException("Error removing old webhook", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@ import org.telegram.telegrambots.ApiConstants;
|
||||
import org.telegram.telegrambots.ApiContext;
|
||||
import org.telegram.telegrambots.api.methods.updates.SetWebhook;
|
||||
import org.telegram.telegrambots.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.facilities.TelegramHttpClientBuilder;
|
||||
import org.telegram.telegrambots.generics.WebhookBot;
|
||||
|
||||
import java.io.File;
|
||||
@ -44,7 +45,7 @@ public abstract class TelegramWebhookBot extends DefaultAbsSender implements Web
|
||||
|
||||
@Override
|
||||
public void setWebhook(String url, String publicCertificatePath) throws TelegramApiRequestException {
|
||||
try (CloseableHttpClient httpclient = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()).build()) {
|
||||
try (CloseableHttpClient httpclient = TelegramHttpClientBuilder.build(getOptions())) {
|
||||
String requestUrl = getBaseUrl() + SetWebhook.PATH;
|
||||
|
||||
HttpPost httppost = new HttpPost(requestUrl);
|
||||
|
@ -0,0 +1,37 @@
|
||||
package org.telegram.telegrambots.facilities;
|
||||
|
||||
import org.apache.http.conn.ssl.NoopHostnameVerifier;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.apache.http.impl.client.ProxyAuthenticationStrategy;
|
||||
import org.telegram.telegrambots.bots.DefaultBotOptions;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Created by bvn13 on 17.04.2018.
|
||||
*/
|
||||
public class TelegramHttpClientBuilder {
|
||||
|
||||
public static CloseableHttpClient build(DefaultBotOptions options) {
|
||||
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create()
|
||||
.setSSLHostnameVerifier(new NoopHostnameVerifier())
|
||||
.setConnectionTimeToLive(70, TimeUnit.SECONDS)
|
||||
.setMaxConnTotal(100);
|
||||
|
||||
if (options.getHttpProxy() != null) {
|
||||
|
||||
httpClientBuilder.setProxy(options.getHttpProxy());
|
||||
|
||||
if (options.getCredentialsProvider() != null) {
|
||||
httpClientBuilder
|
||||
.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy())
|
||||
.setDefaultCredentialsProvider(options.getCredentialsProvider());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return httpClientBuilder.build();
|
||||
}
|
||||
|
||||
}
|
@ -12,6 +12,7 @@ import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.apache.http.impl.client.ProxyAuthenticationStrategy;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.json.JSONException;
|
||||
import org.telegram.telegrambots.ApiConstants;
|
||||
@ -19,6 +20,7 @@ import org.telegram.telegrambots.api.methods.updates.GetUpdates;
|
||||
import org.telegram.telegrambots.api.objects.Update;
|
||||
import org.telegram.telegrambots.bots.DefaultBotOptions;
|
||||
import org.telegram.telegrambots.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.facilities.TelegramHttpClientBuilder;
|
||||
import org.telegram.telegrambots.generics.*;
|
||||
import org.telegram.telegrambots.logging.BotLogger;
|
||||
|
||||
@ -147,11 +149,7 @@ public class DefaultBotSession implements BotSession {
|
||||
|
||||
@Override
|
||||
public synchronized void start() {
|
||||
httpclient = HttpClientBuilder.create()
|
||||
.setSSLHostnameVerifier(new NoopHostnameVerifier())
|
||||
.setConnectionTimeToLive(70, TimeUnit.SECONDS)
|
||||
.setMaxConnTotal(100)
|
||||
.build();
|
||||
httpclient = TelegramHttpClientBuilder.build(options);
|
||||
requestConfig = options.getRequestConfig();
|
||||
exponentialBackOff = options.getExponentialBackOff();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user