commit
6ecc2af3b3
102
Bots.ipr
102
Bots.ipr
@ -22,10 +22,10 @@
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="telegrambots-abilities" />
|
||||
<module name="telegrambots-extensions" />
|
||||
<module name="telegrambots-meta" />
|
||||
<module name="telegrambots-extensions" />
|
||||
<module name="telegrambots" />
|
||||
<module name="telegrambots-abilities" />
|
||||
<module name="telegrambots-chat-session-bot" />
|
||||
<module name="telegrambots-spring-boot-starter" />
|
||||
</profile>
|
||||
@ -224,6 +224,8 @@
|
||||
<content-type name="SQL" enabled="true" />
|
||||
<content-type name="PL/SQL" enabled="true" />
|
||||
<content-type name="JavaScript" enabled="true" />
|
||||
<content-type name="JSON" enabled="true" />
|
||||
<content-type name="JSON5" enabled="true" />
|
||||
<content-type name="JSP" enabled="true" />
|
||||
<content-type name="JSPx" enabled="true" />
|
||||
<content-type name="Groovy" enabled="true" />
|
||||
@ -791,6 +793,30 @@
|
||||
<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">
|
||||
@ -1894,103 +1920,103 @@
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/1.7.29/slf4j-api-1.7.29-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
<library name="Maven: org.springframework.boot:spring-boot-autoconfigure:2.1.8.RELEASE">
|
||||
<library name="Maven: org.springframework.boot:spring-boot-autoconfigure:2.2.1.RELEASE">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-autoconfigure/2.1.8.RELEASE/spring-boot-autoconfigure-2.1.8.RELEASE.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-autoconfigure/2.2.1.RELEASE/spring-boot-autoconfigure-2.2.1.RELEASE.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-autoconfigure/2.1.8.RELEASE/spring-boot-autoconfigure-2.1.8.RELEASE-javadoc.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-autoconfigure/2.2.1.RELEASE/spring-boot-autoconfigure-2.2.1.RELEASE-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-autoconfigure/2.1.8.RELEASE/spring-boot-autoconfigure-2.1.8.RELEASE-sources.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-autoconfigure/2.2.1.RELEASE/spring-boot-autoconfigure-2.2.1.RELEASE-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
<library name="Maven: org.springframework.boot:spring-boot-test:2.1.8.RELEASE">
|
||||
<library name="Maven: org.springframework.boot:spring-boot-test:2.2.1.RELEASE">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-test/2.1.8.RELEASE/spring-boot-test-2.1.8.RELEASE.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-test/2.2.1.RELEASE/spring-boot-test-2.2.1.RELEASE.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-test/2.1.8.RELEASE/spring-boot-test-2.1.8.RELEASE-javadoc.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-test/2.2.1.RELEASE/spring-boot-test-2.2.1.RELEASE-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-test/2.1.8.RELEASE/spring-boot-test-2.1.8.RELEASE-sources.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-test/2.2.1.RELEASE/spring-boot-test-2.2.1.RELEASE-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
<library name="Maven: org.springframework.boot:spring-boot:2.1.8.RELEASE">
|
||||
<library name="Maven: org.springframework.boot:spring-boot:2.2.1.RELEASE">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot/2.1.8.RELEASE/spring-boot-2.1.8.RELEASE.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot/2.2.1.RELEASE/spring-boot-2.2.1.RELEASE.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot/2.1.8.RELEASE/spring-boot-2.1.8.RELEASE-javadoc.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot/2.2.1.RELEASE/spring-boot-2.2.1.RELEASE-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot/2.1.8.RELEASE/spring-boot-2.1.8.RELEASE-sources.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot/2.2.1.RELEASE/spring-boot-2.2.1.RELEASE-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
<library name="Maven: org.springframework:spring-aop:5.1.9.RELEASE">
|
||||
<library name="Maven: org.springframework:spring-aop:5.2.1.RELEASE">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-aop/5.1.9.RELEASE/spring-aop-5.1.9.RELEASE.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-aop/5.2.1.RELEASE/spring-aop-5.2.1.RELEASE.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-aop/5.1.9.RELEASE/spring-aop-5.1.9.RELEASE-javadoc.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-aop/5.2.1.RELEASE/spring-aop-5.2.1.RELEASE-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-aop/5.1.9.RELEASE/spring-aop-5.1.9.RELEASE-sources.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-aop/5.2.1.RELEASE/spring-aop-5.2.1.RELEASE-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
<library name="Maven: org.springframework:spring-beans:5.1.9.RELEASE">
|
||||
<library name="Maven: org.springframework:spring-beans:5.2.1.RELEASE">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-beans/5.1.9.RELEASE/spring-beans-5.1.9.RELEASE.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-beans/5.2.1.RELEASE/spring-beans-5.2.1.RELEASE.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-beans/5.1.9.RELEASE/spring-beans-5.1.9.RELEASE-javadoc.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-beans/5.2.1.RELEASE/spring-beans-5.2.1.RELEASE-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-beans/5.1.9.RELEASE/spring-beans-5.1.9.RELEASE-sources.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-beans/5.2.1.RELEASE/spring-beans-5.2.1.RELEASE-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
<library name="Maven: org.springframework:spring-context:5.1.9.RELEASE">
|
||||
<library name="Maven: org.springframework:spring-context:5.2.1.RELEASE">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-context/5.1.9.RELEASE/spring-context-5.1.9.RELEASE.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-context/5.2.1.RELEASE/spring-context-5.2.1.RELEASE.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-context/5.1.9.RELEASE/spring-context-5.1.9.RELEASE-javadoc.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-context/5.2.1.RELEASE/spring-context-5.2.1.RELEASE-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-context/5.1.9.RELEASE/spring-context-5.1.9.RELEASE-sources.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-context/5.2.1.RELEASE/spring-context-5.2.1.RELEASE-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
<library name="Maven: org.springframework:spring-core:5.1.9.RELEASE">
|
||||
<library name="Maven: org.springframework:spring-core:5.2.1.RELEASE">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-core/5.1.9.RELEASE/spring-core-5.1.9.RELEASE.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-core/5.2.1.RELEASE/spring-core-5.2.1.RELEASE.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-core/5.1.9.RELEASE/spring-core-5.1.9.RELEASE-javadoc.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-core/5.2.1.RELEASE/spring-core-5.2.1.RELEASE-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-core/5.1.9.RELEASE/spring-core-5.1.9.RELEASE-sources.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-core/5.2.1.RELEASE/spring-core-5.2.1.RELEASE-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
<library name="Maven: org.springframework:spring-expression:5.1.9.RELEASE">
|
||||
<library name="Maven: org.springframework:spring-expression:5.2.1.RELEASE">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-expression/5.1.9.RELEASE/spring-expression-5.1.9.RELEASE.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-expression/5.2.1.RELEASE/spring-expression-5.2.1.RELEASE.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-expression/5.1.9.RELEASE/spring-expression-5.1.9.RELEASE-javadoc.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-expression/5.2.1.RELEASE/spring-expression-5.2.1.RELEASE-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-expression/5.1.9.RELEASE/spring-expression-5.1.9.RELEASE-sources.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-expression/5.2.1.RELEASE/spring-expression-5.2.1.RELEASE-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
<library name="Maven: org.springframework:spring-jcl:5.1.9.RELEASE">
|
||||
<library name="Maven: org.springframework:spring-jcl:5.2.1.RELEASE">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-jcl/5.1.9.RELEASE/spring-jcl-5.1.9.RELEASE.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-jcl/5.2.1.RELEASE/spring-jcl-5.2.1.RELEASE.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-jcl/5.1.9.RELEASE/spring-jcl-5.1.9.RELEASE-javadoc.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-jcl/5.2.1.RELEASE/spring-jcl-5.2.1.RELEASE-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-jcl/5.1.9.RELEASE/spring-jcl-5.1.9.RELEASE-sources.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-jcl/5.2.1.RELEASE/spring-jcl-5.2.1.RELEASE-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
<library name="Maven: org.telegram:telegrambots-meta:3.5">
|
||||
|
@ -27,16 +27,16 @@ Just import add the library to your project with one of these options:
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots</artifactId>
|
||||
<version>4.7</version>
|
||||
<version>4.8.1</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
```gradle
|
||||
compile "org.telegram:telegrambots:4.7"
|
||||
compile "org.telegram:telegrambots:4.8.1"
|
||||
```
|
||||
|
||||
2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/4.7)
|
||||
3. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/4.7)
|
||||
2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/4.8.1)
|
||||
3. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/4.8.1)
|
||||
|
||||
In order to use Long Polling mode, just create your own bot extending `org.telegram.telegrambots.bots.TelegramLongPollingBot`.
|
||||
|
||||
|
@ -1,3 +1,10 @@
|
||||
### <a id="4.8.1"></a>4.8.1 ###
|
||||
1. Update Api version [4.8](https://core.telegram.org/bots/api-changelog#april-24-2020)
|
||||
2. Add stats for Abilities
|
||||
3. New and updated wiki page
|
||||
4. Spring-boot support for version 2.2.2
|
||||
5. Bug fixing: #745, #716, #629, #749, #730
|
||||
|
||||
### <a id="4.7"></a>4.7 ###
|
||||
1. Update Api version [4.7](https://core.telegram.org/bots/api-changelog#march-30-2020)
|
||||
|
||||
|
@ -11,13 +11,13 @@ 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>4.7</version>
|
||||
<version>4.8.1</version>
|
||||
</dependency>
|
||||
```
|
||||
* With **Gradle**:
|
||||
|
||||
```groovy
|
||||
compile group: 'org.telegram', name: 'telegrambots', version: '4.7'
|
||||
compile group: 'org.telegram', name: 'telegrambots', version: '4.8.1'
|
||||
```
|
||||
|
||||
2. Don't like **Maven Central Repository**? It can also be taken from [Jitpack](https://jitpack.io/#rubenlagus/TelegramBots).
|
||||
|
@ -4,6 +4,7 @@
|
||||
* [[Using HTTP Proxy]]
|
||||
* [[FAQ]]
|
||||
* [[Handling Bot Tokens]]
|
||||
* [[Understanding the Library]]
|
||||
* AbilityBot
|
||||
* [[Simple Example]]
|
||||
* [[Hello Ability]]
|
||||
|
@ -9,8 +9,10 @@ The barebone toggle is used to **turn off** all the default abilities that come
|
||||
import org.telegram.abilitybots.api.toggle.BareboneToggle;
|
||||
|
||||
public class YourAwesomeBot extends AbilityBot {
|
||||
|
||||
private static final BareboneToggle toggle = new BareboneToggle();
|
||||
|
||||
public YourAwesomeBot(String token, String username) {
|
||||
BareboneToggle toggle = new BareboneToggle();
|
||||
super(token, username, toggle);
|
||||
}
|
||||
|
||||
@ -25,11 +27,12 @@ The custom toggle allows you to customize or turn off the names of the abilities
|
||||
import org.telegram.abilitybots.api.toggle.CustomToggle;
|
||||
|
||||
public class YourAwesomeBot extends AbilityBot {
|
||||
public YourAwesomeBot(String token, String username) {
|
||||
CustomToggle toggle = new CustomToggle()
|
||||
|
||||
private static final CustomToggle toggle = new CustomToggle()
|
||||
.turnOff("ban")
|
||||
.toggle("promote", "upgrade");
|
||||
|
||||
public YourAwesomeBot(String token, String username) {
|
||||
super(token, username, toggle);
|
||||
}
|
||||
|
||||
|
@ -54,21 +54,20 @@ public Ability saysHelloWorld() {
|
||||
The test for this ability would be:
|
||||
|
||||
```java
|
||||
@Test
|
||||
@Test
|
||||
public void canSayHelloWorld() {
|
||||
Update upd = new Update();
|
||||
// Create a new EndUser - EndUser is a class similar to Telegram User, but contains
|
||||
// some utility methods like fullName() and shortName() for ease of use
|
||||
EndUser endUser = EndUser.endUser(USER_ID, "Abbas", "Abou Daya", "addo37");
|
||||
// Create a new User - User is a class similar to Telegram User
|
||||
User user = new User(USER_ID, "Abbas", false, "Abou Daya", "addo37", null);
|
||||
// This is the context that you're used to, it is the necessary conumer item for the ability
|
||||
MessageContext context = MessageContext.newContext(upd, endUser, CHAT_ID);
|
||||
MessageContext context = MessageContext.newContext(upd, user, CHAT_ID);
|
||||
|
||||
// We consume a context in the lamda declaration, so we pass the context to the action logic
|
||||
bot.saysHelloWorld().action().accept(context);
|
||||
|
||||
// We verify that the sender was called only ONCE and sent Hello World to CHAT_ID
|
||||
// The sender here is a mock!
|
||||
Mockito.verify(sender, times(1)).send("Hello World!", CHAT_ID);
|
||||
// We verify that the silent sender was called only ONCE and sent Hello World to CHAT_ID
|
||||
// The silent sender here is a mock!
|
||||
Mockito.verify(silent, times(1)).send("Hello World!", CHAT_ID);
|
||||
}
|
||||
```
|
||||
|
||||
@ -85,10 +84,10 @@ import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.telegram.abilitybots.api.db.DBContext;
|
||||
import org.telegram.abilitybots.api.db.MapDBContext;
|
||||
import org.telegram.abilitybots.api.objects.EndUser;
|
||||
import org.telegram.abilitybots.api.objects.MessageContext;
|
||||
import org.telegram.abilitybots.api.sender.MessageSender;
|
||||
import org.telegram.abilitybots.api.sender.SilentSender;
|
||||
import org.telegram.telegrambots.meta.api.objects.Update;
|
||||
import org.telegram.telegrambots.meta.api.objects.User;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@ -98,36 +97,36 @@ public class ExampleBotTest {
|
||||
|
||||
// Your bot handle here
|
||||
private ExampleBot bot;
|
||||
// Your sender here
|
||||
private MessageSender sender;
|
||||
// Your sender here. Also you can create MessageSender
|
||||
private SilentSender silent;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
// Create your bot
|
||||
bot = new ExampleBot();
|
||||
// Create a new sender as a mock
|
||||
sender = mock(MessageSender.class);
|
||||
// Set your bot sender to the mocked sender
|
||||
silent = mock(SilentSender.class);
|
||||
// Set your bot silent sender to the mocked sender
|
||||
// THIS is the line that prevents your bot from communicating with Telegram servers when it's running its own abilities
|
||||
// All method calls will go through the mocked interface -> which would do nothing except logging the fact that you've called this function with the specific arguments
|
||||
bot.sender = sender;
|
||||
// Create setter in your bot
|
||||
bot.setSilentSender(silent);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canSayHelloWorld() {
|
||||
Update upd = new Update();
|
||||
// Create a new EndUser - EndUser is a class similar to Telegram User, but contains
|
||||
// some utility methods like fullName() and shortName() for ease of use
|
||||
EndUser endUser = EndUser.endUser(USER_ID, "Abbas", "Abou Daya", "addo37");
|
||||
// Create a new User - User is a class similar to Telegram User
|
||||
User user = new User(USER_ID, "Abbas", false, "Abou Daya", "addo37", null);
|
||||
// This is the context that you're used to, it is the necessary conumer item for the ability
|
||||
MessageContext context = MessageContext.newContext(upd, endUser, CHAT_ID);
|
||||
MessageContext context = MessageContext.newContext(upd, user, CHAT_ID);
|
||||
|
||||
// We consume a context in the lamda declaration, so we pass the context to the action logic
|
||||
bot.saysHelloWorld().action().accept(context);
|
||||
|
||||
// We verify that the sender was called only ONCE and sent Hello World to CHAT_ID
|
||||
// The sender here is a mock!
|
||||
Mockito.verify(sender, times(1)).send("Hello World!", CHAT_ID);
|
||||
// We verify that the silent sender was called only ONCE and sent Hello World to CHAT_ID
|
||||
// The silent sender here is a mock!
|
||||
Mockito.verify(silent, times(1)).send("Hello World!", CHAT_ID);
|
||||
}
|
||||
}
|
||||
```
|
||||
@ -178,11 +177,13 @@ public class ExampleBotTest {
|
||||
private DBContext db;
|
||||
private MessageSender sender;
|
||||
|
||||
@Before
|
||||
@Before
|
||||
public void setUp() {
|
||||
bot = new ExampleBot(db);
|
||||
sender = mock(MessageSender.class);
|
||||
bot.silent = new SilentSender(sender);
|
||||
SilentSender silent = new SilentSender(sender);
|
||||
// Create setter in your bot
|
||||
bot.setSilentSender(silent);
|
||||
...
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ We'll be introducing an ability that maintains a special counter for every user.
|
||||
// db.getMap takes in a string, this must be unique and the same everytime you want to call the exact same map
|
||||
// TODO: Using integer as a key in this db map is not recommended, it won't be serialized/deserialized properly if you ever decide to recover/backup db
|
||||
Map<String, Integer> countMap = db.getMap("COUNTERS");
|
||||
int userId = ctx.user().id();
|
||||
int userId = ctx.user().getId();
|
||||
|
||||
// Get and increment counter, put it back in the map
|
||||
Integer counter = countMap.compute(String.valueOf(userId), (id, count) -> count == null ? 1 : ++count);
|
||||
@ -41,7 +41,7 @@ We'll be introducing an ability that maintains a special counter for every user.
|
||||
*/
|
||||
|
||||
// Send formatted will enable markdown
|
||||
String message = String.format("%s, your count is now *%d*!", ctx.user().shortName(), counter);
|
||||
String message = String.format("%s, your count is now *%d*!", ctx.user().getUserName(), counter);
|
||||
silent.send(message, ctx.chatId());
|
||||
})
|
||||
.build();
|
||||
|
@ -9,12 +9,12 @@ As with any Java project, you will need to set your dependencies.
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots-abilities</artifactId>
|
||||
<version>4.7</version>
|
||||
<version>4.8.1</version>
|
||||
</dependency>
|
||||
```
|
||||
* **Gradle**
|
||||
```groovy
|
||||
compile group: 'org.telegram', name: 'telegrambots-abilities', version: 'permissions'
|
||||
implementation group: 'org.telegram', name: 'telegrambots-abilities', version: '4.8.1'
|
||||
```
|
||||
* [JitPack](https://jitpack.io/#rubenlagus/TelegramBots)
|
||||
|
||||
|
BIN
TelegramBots.wiki/understanding-the-library/Bot_curl.png
Normal file
BIN
TelegramBots.wiki/understanding-the-library/Bot_curl.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.4 KiB |
BIN
TelegramBots.wiki/understanding-the-library/Bot_intellij.png
Normal file
BIN
TelegramBots.wiki/understanding-the-library/Bot_intellij.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
BIN
TelegramBots.wiki/understanding-the-library/Telegram-Diagram.png
Normal file
BIN
TelegramBots.wiki/understanding-the-library/Telegram-Diagram.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
@ -0,0 +1,167 @@
|
||||
# Understanding the Library
|
||||
Last updated: 2020-03-04
|
||||
|
||||
|
||||
This little handy guide will not teach you how to do a particular thing in the library.
|
||||
It will also not teach you how to create bots or anything in the liking of that.
|
||||
For that take a look at the [Getting Started] guide
|
||||
|
||||
This guide will give you a general understanding on how the library function and will answer a lot of frequently
|
||||
asked questions. I recommend everyone who wants to work with this library more to read this guide.
|
||||
|
||||
## Topics
|
||||
* The library and the bot API
|
||||
* Understanding how the API is mapped in the library
|
||||
* The general infrastructure of the library
|
||||
|
||||
## The Library and the Bot API
|
||||
Often in Conversations about the library they talk about the API or Application Programming Interface. Sometimes these
|
||||
terms are used interchangeably, which is not correct.
|
||||
|
||||
To understand the differences between those two things lets take a look at this diagram
|
||||
|
||||
![](Telegram-Diagram.png)
|
||||
|
||||
As you might have noticed. Our bot never actually talks to the user directly. Actually, Every communication between user
|
||||
and bot happens on the Telegram Servers (A little disclaimer. I actually don't know the entire infrastructure of telegram.
|
||||
So take everything between Bot API and Telegram Client with a grain of salt)
|
||||
|
||||
Important is that the Library communicates with the Telegram Bot API for everything. Sending Messages, Sending Pictures,
|
||||
and receiving Updates from Telegram
|
||||
|
||||
So we can conclude that the Library is the part of your code that handles all the communication between your bot and the
|
||||
Bot API. The Bot API is the actual interface telegram offers to implement bots. Everything we can do in the library,
|
||||
we can also do directly calling the library.
|
||||
|
||||
Take this piece of code:
|
||||
```java
|
||||
// We initialize our bot in a separate method. See this as the initialization code from the getting started guide
|
||||
AbsSender ourBot = getOurBot();
|
||||
|
||||
// We create the Method class. This one doesn't need any parameters to be able to be send
|
||||
GetMe getMe = new GetMe();
|
||||
|
||||
// At last, we just need to execute the method and get the result
|
||||
User bot = ourBot.execute(getMe);
|
||||
```
|
||||
|
||||
If we do this for one of our bots this is what theBot will look like:<br>
|
||||
![](Bot_intellij.png)
|
||||
|
||||
(you better be grateful for that picture. Spend an eternity trying to find a username)
|
||||
|
||||
We can also go ahead and just call the bot api directly:<br>
|
||||
![](Bot_curl.png)
|
||||
|
||||
We get the same result. The library just handily maps it to an object for us to work with.
|
||||
|
||||
So how do we find out how to do things with the library?
|
||||
|
||||
## Understanding how the API is mapped in the library
|
||||
The base for all our operations is the [telegram bot api documentations](https://core.telegram.org/bots/api) . This 220 kB monster of a website will tell us almost everything we need to know about how to use the api.
|
||||
|
||||
It is split into multiple sections. We can ignore the sections *Authorizing your bot", "Making Requests" and "Getting Updates". These things are done for us by the library.
|
||||
|
||||
So, let's see how we can send a poll for example. First, lets take a look at the *Available Methods*. It already gives us a bunch of send methods
|
||||
|
||||
* sendMessage
|
||||
* sendPhoto
|
||||
* sendAudio
|
||||
* sendDocument
|
||||
* sendVideo
|
||||
* sendAnimation
|
||||
* sendVoice
|
||||
* sendVideoNote
|
||||
* sendMediaGroup
|
||||
* sendLocation
|
||||
* sendVenue
|
||||
* sendContact
|
||||
* sendPoll
|
||||
* sendChatAction
|
||||
|
||||
One of them sticks out to us. *sendPoll* looks promising, and when we take a look at the description
|
||||
|
||||
`Use this method to send a native poll. On success, the sent Message is returned`
|
||||
|
||||
That looks like the thing we need. So let's see what we need to send it
|
||||
![](poll_params.png)
|
||||
|
||||
So as we can see, we need to set 3 things. The id of the chat we want to send it to, a question as a string and an Array of Strings.
|
||||
This will result in an anonymous regular type poll without mutliselection looking like this when sent:
|
||||
|
||||
![](poll_example.png)
|
||||
|
||||
We can customize a bunch of other things like create quizzes, send closed polls or reply to a certain message. Now, how is this api object mapped in the library? How *do* we create a poll?
|
||||
|
||||
Pretty straight forward. We take our libary, look for the "Go To Class" or "SearchClass" option and type in the name of the Method we are looking for. This will quickly yield a "SendPoll" method.
|
||||
|
||||
**Every** Method, listed under *Available Methods* has such a Class. And if we go ahead and scroll down a bit we find a set of fields for the class
|
||||
|
||||
```java
|
||||
@JsonProperty(CHATID_FIELD)
|
||||
private String chatId; ///< Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
@JsonProperty(QUESTION_FIELD)
|
||||
private String question; ///< Poll question, 1-255 characters
|
||||
@JsonProperty(OPTIONS_FIELD)
|
||||
private List<String> options = new ArrayList<>(); ///< List of answer options, 2-10 strings 1-100 characters each
|
||||
@JsonProperty(ISANONYMOUS_FIELD)
|
||||
private Boolean isAnonymous; ///< Optional True, if the poll needs to be anonymous, defaults to True
|
||||
@JsonProperty(TYPE_FIELD)
|
||||
private String type; ///< Optional Poll type, “quiz” or “regular”, defaults to “regular”
|
||||
@JsonProperty(ALLOWMULTIPLEANSWERS_FIELD)
|
||||
private Boolean allowMultipleAnswers; ///< Optional True, if the poll allows multiple answers, ignored for polls in quiz mode, defaults to False
|
||||
@JsonProperty(CORRECTOPTIONID_FIELD)
|
||||
private Integer correctOptionId; ///< Optional 0-based identifier of the correct answer option, required for polls in quiz mode
|
||||
@JsonProperty(ISCLOSED_FIELD)
|
||||
private Boolean isClosed; ///< Optional Pass True, if the poll needs to be immediately closed
|
||||
@JsonProperty(DISABLENOTIFICATION_FIELD)
|
||||
private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
|
||||
@JsonProperty(REPLYTOMESSAGEID_FIELD)
|
||||
private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message
|
||||
@JsonProperty(REPLYMARKUP_FIELD)
|
||||
@JsonDeserialize()
|
||||
private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
|
||||
```
|
||||
|
||||
This is a lot at first glance, but if we remember back at the table from the documentation, everything is there. We have the 3 required fields on top (chatId, question and the list of options and everything) else below
|
||||
|
||||
Let's reproduce our poll from earlier. We create the Method object and set all required fields. This particular class already allows us to set everything in a constructor, this is normally the case for required fields. All other fields can be set by using the setter method (**Attention** Calling a setter overrides the last value in a field. You can call setter multiple times on a method object, but it's normally not correct to do so)
|
||||
|
||||
```java
|
||||
AbsSender ourBot = getOurBot();
|
||||
|
||||
List<String> options = new List<>();
|
||||
options.add("Yes");
|
||||
options.add("No");
|
||||
|
||||
// Let's just assume we get the chatMessage as a parameter. For example from the message received, or from a database
|
||||
SendPoll ourPoll = new SendPoll(someChatId, "Some Question", options);
|
||||
|
||||
ourBot.execute(ourPoll);
|
||||
```
|
||||
This will send the message as expected to telegram and finally to the given chat. But what about return values?
|
||||
|
||||
If we go back to the documentation and look at the description it says:
|
||||
`Use this method to send a native poll. On success, the sent Message is returned`
|
||||
Message links us to the Message object. An object so big that i wont be showing it's documentation in this guide. It can be found here: [Telegram Bot Api: Message Object](https://core.telegram.org/bots/api#message)
|
||||
|
||||
Just the documentation tells us that it returns a Message object. How do we get that object? Easy. Execute() returns it.
|
||||
|
||||
```java
|
||||
Message thePollMessage = ourBot.execute(ourPoll);
|
||||
```
|
||||
This again works for any method that returns a value. SendMessage, SendPhoto, SendPoll, GetMe, GetChatMember etc.
|
||||
|
||||
## But what about Photos?
|
||||
Some methods aren't quite as straight forward to use. Let's take a bit of time to look at methods that upload files to telegram. Namely: SendPhoto, SendAnimation, SendSticker, SendDocument, SendVideo, SendVideoNote, SendAudio and SendVoice. All of these require what telegram calls an "InputFile". This can either be a FileId of a previous send file, a url to the file on a public sever or the actual file. In the Library this is mapped using different set methods in the above classes. Currently sending by FileId, sending by java.io.File and sending by InputStream is supported. Sending by URL is not supported as of writing this guide
|
||||
|
||||
### FileId
|
||||
Using a fileId is pretty straight forward. The FileId is returned from telegram upon sending a File. Just set the given FileId and execute the method. Make sure that the FileId actually point to a file of the correct type
|
||||
|
||||
### File
|
||||
The classic approach of creating a java.io.File by Path on your hard drive or by loading a classpath resource.
|
||||
|
||||
### InputStream
|
||||
Sending a file by InputStream will cause the library to read the stream and then converting it into the Request. It's the same as sending a java.io.File, but more convenient some times.
|
||||
|
||||
For more information on how to send Files, take a look at the [FAQ: How to send Photos](../FAQ.md). The basic concept will be the same across all Methods.
|
BIN
TelegramBots.wiki/understanding-the-library/poll_example.png
Normal file
BIN
TelegramBots.wiki/understanding-the-library/poll_example.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.2 KiB |
BIN
TelegramBots.wiki/understanding-the-library/poll_params.png
Normal file
BIN
TelegramBots.wiki/understanding-the-library/poll_params.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 41 KiB |
2
pom.xml
2
pom.xml
@ -7,7 +7,7 @@
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>Bots</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>4.7</version>
|
||||
<version>4.8.1</version>
|
||||
|
||||
<modules>
|
||||
<module>telegrambots</module>
|
||||
|
@ -18,19 +18,19 @@ Usage
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots-abilities</artifactId>
|
||||
<version>4.7</version>
|
||||
<version>4.8.1</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
**Gradle**
|
||||
|
||||
```gradle
|
||||
compile "org.telegram:telegrambots-abilities:4.7"
|
||||
compile "org.telegram:telegrambots-abilities:4.8.1"
|
||||
```
|
||||
|
||||
**JitPack** - [JitPack](https://jitpack.io/#rubenlagus/TelegramBots/v4.7)
|
||||
**JitPack** - [JitPack](https://jitpack.io/#rubenlagus/TelegramBots/v4.8.1)
|
||||
|
||||
**Plain imports** - [Here](https://github.com/rubenlagus/TelegramBots/releases/tag/v4.7)
|
||||
**Plain imports** - [Here](https://github.com/rubenlagus/TelegramBots/releases/tag/v4.8.1)
|
||||
|
||||
Motivation
|
||||
----------
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>Bots</artifactId>
|
||||
<version>4.7</version>
|
||||
<version>4.8.1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>telegrambots-abilities</artifactId>
|
||||
@ -84,7 +84,7 @@
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots</artifactId>
|
||||
<version>4.7</version>
|
||||
<version>4.8.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
|
@ -3,9 +3,6 @@ package org.telegram.abilitybots.api.bot;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableList.Builder;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ListMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -193,6 +190,9 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability
|
||||
.map(this::consumeUpdate)
|
||||
.forEach(this::postConsumption);
|
||||
|
||||
// Commit to DB now after all the actions have been dealt
|
||||
db.commit();
|
||||
|
||||
long processingTime = System.currentTimeMillis() - millisStarted;
|
||||
log.info(format("[%s] Processing of update [%s] ended at %s%n---> Processing time: [%d ms] <---%n", botUsername, update.getUpdateId(), now(), processingTime));
|
||||
}
|
||||
@ -465,6 +465,10 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability
|
||||
|
||||
Update addUser(Update update) {
|
||||
User endUser = AbilityUtils.getUser(update);
|
||||
if (endUser.equals(EMPTY_USER)) {
|
||||
// Can't add an empty user, return the update as is
|
||||
return update;
|
||||
}
|
||||
|
||||
users().compute(endUser.getId(), (id, user) -> {
|
||||
if (user == null) {
|
||||
@ -480,7 +484,6 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability
|
||||
return user;
|
||||
});
|
||||
|
||||
db.commit();
|
||||
return update;
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,6 @@ import static org.telegram.abilitybots.api.util.AbilityMessageCodes.ABILITY_UNBA
|
||||
import static org.telegram.abilitybots.api.util.AbilityMessageCodes.ABILITY_UNBAN_SUCCESS;
|
||||
import static org.telegram.abilitybots.api.util.AbilityMessageCodes.USER_NOT_FOUND;
|
||||
import static org.telegram.abilitybots.api.util.AbilityUtils.addTag;
|
||||
import static org.telegram.abilitybots.api.util.AbilityUtils.commitTo;
|
||||
import static org.telegram.abilitybots.api.util.AbilityUtils.escape;
|
||||
import static org.telegram.abilitybots.api.util.AbilityUtils.getLocalizedMessage;
|
||||
import static org.telegram.abilitybots.api.util.AbilityUtils.shortName;
|
||||
@ -288,7 +287,6 @@ public final class DefaultAbilities implements AbilityExtension {
|
||||
sendMd(ABILITY_BAN_SUCCESS, ctx, escape(bannedUser));
|
||||
}
|
||||
})
|
||||
.post(commitTo(bot.db))
|
||||
.build();
|
||||
}
|
||||
|
||||
@ -315,7 +313,6 @@ public final class DefaultAbilities implements AbilityExtension {
|
||||
bot.silent.sendMd(getLocalizedMessage(ABILITY_UNBAN_SUCCESS, ctx.user().getLanguageCode(), escape(username)), ctx.chatId());
|
||||
}
|
||||
})
|
||||
.post(commitTo(bot.db))
|
||||
.build();
|
||||
}
|
||||
|
||||
@ -339,7 +336,7 @@ public final class DefaultAbilities implements AbilityExtension {
|
||||
admins.add(userId);
|
||||
sendMd(ABILITY_PROMOTE_SUCCESS, ctx, escape(username));
|
||||
}
|
||||
}).post(commitTo(bot.db))
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
||||
@ -363,7 +360,6 @@ public final class DefaultAbilities implements AbilityExtension {
|
||||
sendMd(ABILITY_DEMOTE_FAIL, ctx, escape(username));
|
||||
}
|
||||
})
|
||||
.post(commitTo(bot.db))
|
||||
.build();
|
||||
}
|
||||
|
||||
@ -389,7 +385,6 @@ public final class DefaultAbilities implements AbilityExtension {
|
||||
send(ABILITY_CLAIM_SUCCESS, ctx);
|
||||
}
|
||||
})
|
||||
.post(commitTo(bot.db))
|
||||
.build();
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,10 @@ public enum Flag implements Predicate<Update> {
|
||||
EDITED_MESSAGE(Update::hasEditedMessage),
|
||||
INLINE_QUERY(Update::hasInlineQuery),
|
||||
CHOSEN_INLINE_QUERY(Update::hasChosenInlineQuery),
|
||||
SHIPPING_QUERY(Update::hasShippingQuery),
|
||||
PRECHECKOUT_QUERY(Update::hasPreCheckoutQuery),
|
||||
POLL(Update::hasPoll),
|
||||
POLL_ANSWER(Update::hasPollAnswer),
|
||||
|
||||
// Message Flags
|
||||
REPLY(upd -> MESSAGE.test(upd) && upd.getMessage().isReply()),
|
||||
|
@ -24,6 +24,8 @@ import static org.telegram.abilitybots.api.objects.Flag.*;
|
||||
* Helper and utility methods
|
||||
*/
|
||||
public final class AbilityUtils {
|
||||
public static User EMPTY_USER = new User();
|
||||
|
||||
private AbilityUtils() {
|
||||
|
||||
}
|
||||
@ -69,6 +71,14 @@ public final class AbilityUtils {
|
||||
return update.getEditedMessage().getFrom();
|
||||
} else if (CHOSEN_INLINE_QUERY.test(update)) {
|
||||
return update.getChosenInlineQuery().getFrom();
|
||||
} else if (SHIPPING_QUERY.test(update)) {
|
||||
return update.getShippingQuery().getFrom();
|
||||
} else if (PRECHECKOUT_QUERY.test(update)) {
|
||||
return update.getPreCheckoutQuery().getFrom();
|
||||
} else if (POLL_ANSWER.test(update)) {
|
||||
return update.getPollAnswer().getUser();
|
||||
} else if (POLL.test(update)) {
|
||||
return EMPTY_USER;
|
||||
} else {
|
||||
throw new IllegalStateException("Could not retrieve originating user from update");
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ Usage
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots-chat-session-bot</artifactId>
|
||||
<version>4.7</version>
|
||||
<version>4.8.1</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>Bots</artifactId>
|
||||
<version>4.7</version>
|
||||
<version>4.8.1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>telegrambots-chat-session-bot</artifactId>
|
||||
@ -84,7 +84,7 @@
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots</artifactId>
|
||||
<version>4.7</version>
|
||||
<version>4.8.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.shiro/shiro-core -->
|
||||
|
@ -16,12 +16,12 @@ Just import add the library to your project with one of these options:
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambotsextensions</artifactId>
|
||||
<version>4.7</version>
|
||||
<version>4.8.1</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
2. Using Gradle:
|
||||
|
||||
```gradle
|
||||
compile "org.telegram:telegrambotsextensions:4.7"
|
||||
compile "org.telegram:telegrambotsextensions:4.8.1"
|
||||
```
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>Bots</artifactId>
|
||||
<version>4.7</version>
|
||||
<version>4.8.1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>telegrambotsextensions</artifactId>
|
||||
@ -75,7 +75,7 @@
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots</artifactId>
|
||||
<version>4.7</version>
|
||||
<version>4.8.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@ -22,7 +22,6 @@ import java.util.function.BiConsumer;
|
||||
*/
|
||||
public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingBot implements ICommandRegistry {
|
||||
private final CommandRegistry commandRegistry;
|
||||
private String botUsername;
|
||||
|
||||
/**
|
||||
* Creates a TelegramLongPollingCommandBot using default options
|
||||
@ -33,19 +32,6 @@ public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingB
|
||||
this(ApiContext.getInstance(DefaultBotOptions.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a TelegramLongPollingCommandBot using default options
|
||||
* Use ICommandRegistry's methods on this bot to register commands
|
||||
*
|
||||
* @param botUsername Username of the bot
|
||||
* @deprecated Overwrite {@link #getBotUsername() getBotUsername} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public TelegramLongPollingCommandBot(String botUsername){
|
||||
this();
|
||||
this.botUsername = botUsername;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a TelegramLongPollingCommandBot with custom options and allowing commands with
|
||||
* usernames
|
||||
@ -152,9 +138,7 @@ public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingB
|
||||
* @return Bot username
|
||||
*/
|
||||
@Override
|
||||
public String getBotUsername(){
|
||||
return this.botUsername;
|
||||
};
|
||||
public abstract String getBotUsername();
|
||||
|
||||
/**
|
||||
* Process all updates, that are not commands.
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>Bots</artifactId>
|
||||
<version>4.7</version>
|
||||
<version>4.8.1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>telegrambots-meta</artifactId>
|
||||
|
@ -39,6 +39,10 @@ public class SendPoll extends BotApiMethod<Message> {
|
||||
private static final String DISABLENOTIFICATION_FIELD = "disable_notification";
|
||||
private static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
|
||||
private static final String REPLYMARKUP_FIELD = "reply_markup";
|
||||
private static final String OPENPERIOD_FIELD = "open_period";
|
||||
private static final String CLOSEDATE_FIELD = "close_date";
|
||||
private static final String EXPLANATION_FIELD = "explanation";
|
||||
private static final String EXPLANATIONPARSEMODE_FIELD = "explanation_parse_mode";
|
||||
|
||||
/**
|
||||
* Unique identifier for the target chat or username of the target channel (in the format @channelusername).
|
||||
@ -67,7 +71,14 @@ public class SendPoll extends BotApiMethod<Message> {
|
||||
@JsonProperty(REPLYMARKUP_FIELD)
|
||||
@JsonDeserialize()
|
||||
private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
|
||||
|
||||
@JsonProperty(OPENPERIOD_FIELD)
|
||||
private Integer openPeriod; ///< Optional. Amount of time in seconds the poll will be active after creation, 5-600. Can't be used together with close_date.
|
||||
@JsonProperty(CLOSEDATE_FIELD)
|
||||
private Integer closeDate; ///< Optional. Point in time (Unix timestamp) when the poll will be automatically closed. Must be at least 5 and no more than 600 seconds in the future. Can't be used together with open_period.
|
||||
@JsonProperty(EXPLANATION_FIELD)
|
||||
private String explanation; ///< Optional. Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters with at most 2 line feeds after entities parsing
|
||||
@JsonProperty(EXPLANATIONPARSEMODE_FIELD)
|
||||
private String explanationParseMode; ///< Optional. Mode for parsing entities in the explanation. See formatting options for more details.
|
||||
|
||||
public SendPoll() {
|
||||
super();
|
||||
@ -196,6 +207,42 @@ public class SendPoll extends BotApiMethod<Message> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getOpenPeriod() {
|
||||
return openPeriod;
|
||||
}
|
||||
|
||||
public SendPoll setOpenPeriod(Integer openPeriod) {
|
||||
this.openPeriod = openPeriod;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getCloseDate() {
|
||||
return closeDate;
|
||||
}
|
||||
|
||||
public SendPoll setCloseDate(Integer closeDate) {
|
||||
this.closeDate = closeDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getExplanation() {
|
||||
return explanation;
|
||||
}
|
||||
|
||||
public SendPoll setExplanation(String explanation) {
|
||||
this.explanation = explanation;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getExplanationParseMode() {
|
||||
return explanationParseMode;
|
||||
}
|
||||
|
||||
public SendPoll setExplanationParseMode(String explanationParseMode) {
|
||||
this.explanationParseMode = explanationParseMode;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
@ -228,6 +275,15 @@ public class SendPoll extends BotApiMethod<Message> {
|
||||
if (options == null || options.size() < 2 || options.size() > 10) {
|
||||
throw new TelegramApiValidationException("Options parameter must be between 2 and 10 item", this);
|
||||
}
|
||||
if (openPeriod != null && closeDate != null) {
|
||||
throw new TelegramApiValidationException("Only one of Open Period and Close Date are allowed", this);
|
||||
}
|
||||
if (openPeriod != null && (openPeriod < 5 || openPeriod > 600)) {
|
||||
throw new TelegramApiValidationException("Open period can only be between 5 and 600", this);
|
||||
}
|
||||
if (explanation != null && explanation.length() > 200) {
|
||||
throw new TelegramApiValidationException("Explanation can only have up to 200 characters", this);
|
||||
}
|
||||
if (options.parallelStream().anyMatch(x -> x.isEmpty() || x.length() > 100)) {
|
||||
throw new TelegramApiValidationException("Options parameter values must be between 1 and 100 chars length", this);
|
||||
}
|
||||
@ -236,7 +292,6 @@ public class SendPoll extends BotApiMethod<Message> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
@ -252,13 +307,17 @@ public class SendPoll extends BotApiMethod<Message> {
|
||||
Objects.equals(isClosed, sendPoll.isClosed) &&
|
||||
Objects.equals(disableNotification, sendPoll.disableNotification) &&
|
||||
Objects.equals(replyToMessageId, sendPoll.replyToMessageId) &&
|
||||
Objects.equals(replyMarkup, sendPoll.replyMarkup);
|
||||
Objects.equals(replyMarkup, sendPoll.replyMarkup) &&
|
||||
Objects.equals(openPeriod, sendPoll.openPeriod) &&
|
||||
Objects.equals(closeDate, sendPoll.closeDate) &&
|
||||
Objects.equals(explanation, sendPoll.explanation) &&
|
||||
Objects.equals(explanationParseMode, sendPoll.explanationParseMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(chatId, question, options, isAnonymous, type, allowMultipleAnswers, correctOptionId,
|
||||
isClosed, disableNotification, replyToMessageId, replyMarkup);
|
||||
return Objects.hash(chatId, question, options, isAnonymous, type, allowMultipleAnswers, correctOptionId, isClosed,
|
||||
disableNotification, replyToMessageId, replyMarkup, openPeriod, closeDate, explanation, explanationParseMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -275,6 +334,10 @@ public class SendPoll extends BotApiMethod<Message> {
|
||||
", disableNotification=" + disableNotification +
|
||||
", replyToMessageId=" + replyToMessageId +
|
||||
", replyMarkup=" + replyMarkup +
|
||||
", openPeriod=" + openPeriod +
|
||||
", closeDate=" + closeDate +
|
||||
", explanation='" + explanation + '\'' +
|
||||
", explanationParseMode='" + explanationParseMode + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -21,12 +21,15 @@ public class SendDice extends BotApiMethod<Message> {
|
||||
public static final String PATH = "sendDice";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
private static final String EMOJI_FIELD = "emoji";
|
||||
private static final String DISABLENOTIFICATION_FIELD = "disable_notification";
|
||||
private static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
|
||||
private static final String REPLYMARKUP_FIELD = "reply_markup";
|
||||
|
||||
@JsonProperty(CHATID_FIELD)
|
||||
private String chatId; ///< Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
@JsonProperty(EMOJI_FIELD)
|
||||
private String emoji; ///< Optional. Emoji on which the dice throw animation is based. Currently, must be one of “🎲” or “🎯”. Defauts to “🎲”
|
||||
@JsonProperty(DISABLENOTIFICATION_FIELD)
|
||||
private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
|
||||
@JsonProperty(REPLYTOMESSAGEID_FIELD)
|
||||
@ -84,6 +87,15 @@ public class SendDice extends BotApiMethod<Message> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getEmoji() {
|
||||
return emoji;
|
||||
}
|
||||
|
||||
public SendDice setEmoji(String emoji) {
|
||||
this.emoji = emoji;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
@ -109,6 +121,9 @@ public class SendDice extends BotApiMethod<Message> {
|
||||
if (chatId == null) {
|
||||
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
|
||||
}
|
||||
if (emoji != null && !emoji.equals("\uD83C\uDFB2") && !emoji.equals("\uD83C\uDFAF")) {
|
||||
throw new TelegramApiValidationException("Only \uD83C\uDFB2 and \uD83C\uDFAF are allowed in Emoji field ", this);
|
||||
}
|
||||
if (replyMarkup != null) {
|
||||
replyMarkup.validate();
|
||||
}
|
||||
@ -118,6 +133,7 @@ public class SendDice extends BotApiMethod<Message> {
|
||||
public String toString() {
|
||||
return "SendDice{" +
|
||||
"chatId='" + chatId + '\'' +
|
||||
", emoji='" + emoji + '\'' +
|
||||
", disableNotification=" + disableNotification +
|
||||
", replyToMessageId=" + replyToMessageId +
|
||||
", replyMarkup=" + replyMarkup +
|
||||
|
@ -11,9 +11,12 @@ import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
|
||||
*/
|
||||
public class Dice implements BotApiObject {
|
||||
private static final String VALUE_FIELD = "value";
|
||||
private static final String EMOJI_FIELD = "emoji";
|
||||
|
||||
@JsonProperty(VALUE_FIELD)
|
||||
private Integer value; ///< Value of the dice, 1-6
|
||||
@JsonProperty(EMOJI_FIELD)
|
||||
private String emoji; ///< Emoji on which the dice throw animation is based
|
||||
|
||||
public Dice() {
|
||||
super();
|
||||
@ -23,10 +26,15 @@ public class Dice implements BotApiObject {
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getEmoji() {
|
||||
return emoji;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Dice{" +
|
||||
"value=" + value +
|
||||
", emoji='" + emoji + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package org.telegram.telegrambots.meta.api.objects.polls;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
|
||||
import org.telegram.telegrambots.meta.api.objects.MessageEntity;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@ -22,6 +23,10 @@ public class Poll implements BotApiObject {
|
||||
private static final String TYPE_FIELD = "type";
|
||||
private static final String ALLOWSMULTIPLEANSWERS_FIELD = "allows_multiple_answers";
|
||||
private static final String CORRECTOPTIONID_FIELD = "correct_option_id";
|
||||
private static final String OPENPERIOD_FIELD = "open_period";
|
||||
private static final String CLOSEDATE_FIELD = "close_date";
|
||||
private static final String EXPLANATION_FIELD = "explanation";
|
||||
private static final String EXPLANATIONENTITIES_FIELD = "explanation_entities";
|
||||
|
||||
@JsonProperty(ID_FIELD)
|
||||
private String id; ///< Unique poll identifier
|
||||
@ -47,6 +52,14 @@ public class Poll implements BotApiObject {
|
||||
*/
|
||||
@JsonProperty(CORRECTOPTIONID_FIELD)
|
||||
private Integer correctOptionId; ///< True, if the poll allows multiple answers
|
||||
@JsonProperty(OPENPERIOD_FIELD)
|
||||
private Integer openPeriod; ///< Optional. Amount of time in seconds the poll will be active after creation
|
||||
@JsonProperty(CLOSEDATE_FIELD)
|
||||
private Integer closeDate; ///< Optional. Point in time (Unix timestamp) when the poll will be automatically closed
|
||||
@JsonProperty(EXPLANATION_FIELD)
|
||||
private String explanation; ///< Optional. Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters
|
||||
@JsonProperty(EXPLANATIONENTITIES_FIELD)
|
||||
private List<MessageEntity> explanationEntities; ///< Optional. Special entities like usernames, URLs, bot commands, etc. that appear in the explanation
|
||||
|
||||
public Poll() {
|
||||
}
|
||||
@ -123,6 +136,22 @@ public class Poll implements BotApiObject {
|
||||
this.correctOptionId = correctOptionId;
|
||||
}
|
||||
|
||||
public Integer getOpenPeriod() {
|
||||
return openPeriod;
|
||||
}
|
||||
|
||||
public Integer getCloseDate() {
|
||||
return closeDate;
|
||||
}
|
||||
|
||||
public String getExplanation() {
|
||||
return explanation;
|
||||
}
|
||||
|
||||
public List<MessageEntity> getExplanationEntities() {
|
||||
return explanationEntities;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
@ -136,12 +165,16 @@ public class Poll implements BotApiObject {
|
||||
Objects.equals(isAnonymous, poll.isAnonymous) &&
|
||||
Objects.equals(type, poll.type) &&
|
||||
Objects.equals(allowMultipleAnswers, poll.allowMultipleAnswers) &&
|
||||
Objects.equals(correctOptionId, poll.correctOptionId);
|
||||
Objects.equals(correctOptionId, poll.correctOptionId) &&
|
||||
Objects.equals(openPeriod, poll.openPeriod) &&
|
||||
Objects.equals(closeDate, poll.closeDate) &&
|
||||
Objects.equals(explanation, poll.explanation) &&
|
||||
Objects.equals(explanationEntities, poll.explanationEntities);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, question, options, totalVoterCount, isClosed, isAnonymous, type, allowMultipleAnswers, correctOptionId);
|
||||
return Objects.hash(id, question, options, totalVoterCount, isClosed, isAnonymous, type, allowMultipleAnswers, correctOptionId, openPeriod, closeDate, explanation, explanationEntities);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -156,6 +189,10 @@ public class Poll implements BotApiObject {
|
||||
", type='" + type + '\'' +
|
||||
", allowMultipleAnswers=" + allowMultipleAnswers +
|
||||
", correctOptionId=" + correctOptionId +
|
||||
", openPeriod=" + openPeriod +
|
||||
", closeDate=" + closeDate +
|
||||
", explanation='" + explanation + '\'' +
|
||||
", explanationEntities=" + explanationEntities +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>Bots</artifactId>
|
||||
<version>4.7</version>
|
||||
<version>4.8.1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>telegrambots-spring-boot-starter</artifactId>
|
||||
@ -70,7 +70,8 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
|
||||
<spring-boot.version>2.1.8.RELEASE</spring-boot.version>
|
||||
|
||||
<spring-boot.version>2.2.2.RELEASE</spring-boot.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@ -78,7 +79,7 @@
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots</artifactId>
|
||||
<version>4.7</version>
|
||||
<version>4.8.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
@ -4,7 +4,9 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.telegram.telegrambots.meta.TelegramBotsApi;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.generics.BotSession;
|
||||
import org.telegram.telegrambots.meta.generics.LongPollingBot;
|
||||
import org.telegram.telegrambots.meta.generics.WebhookBot;
|
||||
@ -55,6 +57,9 @@ public class TelegramBotInitializer implements InitializingBean {
|
||||
|
||||
private void handleAnnotatedMethod(Object bot, Method method, BotSession session) {
|
||||
try {
|
||||
TelegramApiRequestException test = new TelegramApiRequestException("Error getting updates", new ApiResponse());
|
||||
log.error(test.getMessage(), test);
|
||||
|
||||
if (method.getParameterCount() > 1) {
|
||||
log.warn(format("Method %s of Type %s has too many parameters",
|
||||
method.getName(), method.getDeclaringClass().getCanonicalName()));
|
||||
|
@ -2,8 +2,9 @@ package org.telegram.telegrambots.starter;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@ -11,12 +12,11 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.telegram.telegrambots.meta.TelegramBotsApi;
|
||||
import org.telegram.telegrambots.meta.generics.LongPollingBot;
|
||||
import org.telegram.telegrambots.meta.generics.WebhookBot;
|
||||
|
||||
/**
|
||||
* #TelegramBotsApi added to spring context as well
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnProperty(prefix="telegrambots",name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = "telegrambots", name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
public class TelegramBotStarterConfiguration {
|
||||
|
||||
@Bean
|
||||
@ -26,12 +26,12 @@ public class TelegramBotStarterConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public TelegramBotInitializer telegramBotInitializer(TelegramBotsApi telegramBotsApi,
|
||||
Optional<List<LongPollingBot>> longPollingBots,
|
||||
Optional<List<WebhookBot>> webHookBots) {
|
||||
return new TelegramBotInitializer(telegramBotsApi,
|
||||
longPollingBots.orElseGet(Collections::emptyList),
|
||||
webHookBots.orElseGet(Collections::emptyList));
|
||||
@ConditionalOnMissingBean
|
||||
public TelegramBotInitializer telegramBotInitializer(TelegramBotsApi telegramBotsApi,
|
||||
ObjectProvider<List<LongPollingBot>> longPollingBots,
|
||||
ObjectProvider<List<WebhookBot>> webHookBots) {
|
||||
return new TelegramBotInitializer(telegramBotsApi,
|
||||
longPollingBots.getIfAvailable(Collections::emptyList),
|
||||
webHookBots.getIfAvailable(Collections::emptyList));
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>Bots</artifactId>
|
||||
<version>4.7</version>
|
||||
<version>4.8.1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>telegrambots</artifactId>
|
||||
@ -95,7 +95,7 @@
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots-meta</artifactId>
|
||||
<version>4.7</version>
|
||||
<version>4.8.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
|
@ -26,6 +26,7 @@ import org.telegram.telegrambots.meta.generics.UpdatesReader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InvalidObjectException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.SocketException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@ -274,7 +275,15 @@ public class DefaultBotSession implements BotSession {
|
||||
} catch (InterruptedException e) {
|
||||
log.info(e.getLocalizedMessage(), e);
|
||||
interrupt();
|
||||
} catch (InternalError e) {
|
||||
// handle InternalError to workaround OpenJDK bug (resolved since 13.0)
|
||||
// https://bugs.openjdk.java.net/browse/JDK-8173620
|
||||
if (e.getCause() instanceof InvocationTargetException) {
|
||||
Throwable cause = e.getCause().getCause();
|
||||
log.error(cause.getLocalizedMessage(), cause);
|
||||
} else throw e;
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user