Merge pull request #572 from rubenlagus/dev

Dev
This commit is contained in:
Ruben Bermudez 2019-01-27 23:33:43 +00:00 committed by GitHub
commit da5e7a776f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
75 changed files with 2159 additions and 1398 deletions

133
Bots.ipr
View File

@ -220,7 +220,6 @@
<content-type name="Java" enabled="true" />
<content-type name="SQL" enabled="true" />
<content-type name="PL/SQL" enabled="true" />
<content-type name="JPA QL" enabled="true" />
<content-type name="JavaScript" enabled="true" />
<content-type name="JSP" enabled="true" />
<content-type name="JSPx" enabled="true" />
@ -501,7 +500,7 @@
<component name="DBNavigator.Project.StatementExecutionManager">
<execution-variables />
</component>
<component name="Encoding" defaultCharsetForPropertiesFiles="UTF-8">
<component name="Encoding" defaultCharsetForPropertiesFiles="UTF-8" addBOMForNewFiles="with NO BOM">
<file url="file://$PROJECT_DIR$/telegrambots" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/telegrambots-abilities" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/telegrambots-chat-session-bot" charset="UTF-8" />
@ -896,70 +895,92 @@
<root url="jar://$MAVEN_REPOSITORY$/aopalliance/aopalliance/1.0/aopalliance-1.0-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0">
<library name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.0">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-annotations/2.8.0/jackson-annotations-2.8.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-annotations/2.9.0/jackson-annotations-2.9.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-annotations/2.8.0/jackson-annotations-2.8.0-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-annotations/2.9.0/jackson-annotations-2.9.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-annotations/2.8.0/jackson-annotations-2.8.0-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-annotations/2.9.0/jackson-annotations-2.9.0-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.7">
<library name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.7">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-core/2.8.7/jackson-core-2.8.7.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-core/2.9.7/jackson-core-2.9.7.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-core/2.8.7/jackson-core-2.8.7-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-core/2.9.7/jackson-core-2.9.7-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-core/2.8.7/jackson-core-2.8.7-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-core/2.9.7/jackson-core-2.9.7-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.7">
<library name="Maven: com.fasterxml.jackson.core:jackson-databind:2.9.7">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-databind/2.8.7/jackson-databind-2.8.7.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-databind/2.9.7/jackson-databind-2.9.7.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-databind/2.8.7/jackson-databind-2.8.7-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-databind/2.9.7/jackson-databind-2.9.7-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-databind/2.8.7/jackson-databind-2.8.7-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-databind/2.9.7/jackson-databind-2.9.7-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:2.8.7">
<library name="Maven: com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:2.9.7">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/jaxrs/jackson-jaxrs-base/2.8.7/jackson-jaxrs-base-2.8.7.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/jaxrs/jackson-jaxrs-base/2.9.7/jackson-jaxrs-base-2.9.7.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/jaxrs/jackson-jaxrs-base/2.8.7/jackson-jaxrs-base-2.8.7-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/jaxrs/jackson-jaxrs-base/2.9.7/jackson-jaxrs-base-2.9.7-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/jaxrs/jackson-jaxrs-base/2.8.7/jackson-jaxrs-base-2.8.7-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/jaxrs/jackson-jaxrs-base/2.9.7/jackson-jaxrs-base-2.9.7-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.8.7">
<library name="Maven: com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.9.7">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/jaxrs/jackson-jaxrs-json-provider/2.8.7/jackson-jaxrs-json-provider-2.8.7.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/jaxrs/jackson-jaxrs-json-provider/2.9.7/jackson-jaxrs-json-provider-2.9.7.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/jaxrs/jackson-jaxrs-json-provider/2.8.7/jackson-jaxrs-json-provider-2.8.7-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/jaxrs/jackson-jaxrs-json-provider/2.9.7/jackson-jaxrs-json-provider-2.9.7-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/jaxrs/jackson-jaxrs-json-provider/2.8.7/jackson-jaxrs-json-provider-2.8.7-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/jaxrs/jackson-jaxrs-json-provider/2.9.7/jackson-jaxrs-json-provider-2.9.7-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.8.7">
<library name="Maven: com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.9.7">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/module/jackson-module-jaxb-annotations/2.8.7/jackson-module-jaxb-annotations-2.8.7.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/module/jackson-module-jaxb-annotations/2.9.7/jackson-module-jaxb-annotations-2.9.7.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/module/jackson-module-jaxb-annotations/2.8.7/jackson-module-jaxb-annotations-2.8.7-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/module/jackson-module-jaxb-annotations/2.9.7/jackson-module-jaxb-annotations-2.9.7-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/module/jackson-module-jaxb-annotations/2.8.7/jackson-module-jaxb-annotations-2.8.7-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/module/jackson-module-jaxb-annotations/2.9.7/jackson-module-jaxb-annotations-2.9.7-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: com.google.code.findbugs:jsr305:3.0.2">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: com.google.errorprone:error_prone_annotations:2.1.3">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/google/errorprone/error_prone_annotations/2.1.3/error_prone_annotations-2.1.3.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/com/google/errorprone/error_prone_annotations/2.1.3/error_prone_annotations-2.1.3-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/com/google/errorprone/error_prone_annotations/2.1.3/error_prone_annotations-2.1.3-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: com.google.guava:guava:19.0">
@ -973,15 +994,37 @@
<root url="jar://$MAVEN_REPOSITORY$/com/google/guava/guava/19.0/guava-19.0-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: com.google.inject:guice:4.1.0">
<library name="Maven: com.google.guava:guava:25.1-android">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/google/inject/guice/4.1.0/guice-4.1.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/google/guava/guava/25.1-android/guava-25.1-android.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/com/google/inject/guice/4.1.0/guice-4.1.0-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/google/guava/guava/25.1-android/guava-25.1-android-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/com/google/inject/guice/4.1.0/guice-4.1.0-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/google/guava/guava/25.1-android/guava-25.1-android-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: com.google.inject:guice:4.2.2">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/google/inject/guice/4.2.2/guice-4.2.2.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/com/google/inject/guice/4.2.2/guice-4.2.2-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/com/google/inject/guice/4.2.2/guice-4.2.2-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: com.google.j2objc:j2objc-annotations:1.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/google/j2objc/j2objc-annotations/1.1/j2objc-annotations-1.1.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/com/google/j2objc/j2objc-annotations/1.1/j2objc-annotations-1.1-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/com/google/j2objc/j2objc-annotations/1.1/j2objc-annotations-1.1-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: commons-beanutils:commons-beanutils:1.9.3">
@ -1292,6 +1335,28 @@
<root url="jar://$MAVEN_REPOSITORY$/org/assertj/assertj-core/3.9.1/assertj-core-3.9.1-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: org.checkerframework:checker-compat-qual:2.0.0">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/checkerframework/checker-compat-qual/2.0.0/checker-compat-qual-2.0.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/checkerframework/checker-compat-qual/2.0.0/checker-compat-qual-2.0.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/checkerframework/checker-compat-qual/2.0.0/checker-compat-qual-2.0.0-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: org.codehaus.mojo:animal-sniffer-annotations:1.14">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/codehaus/mojo/animal-sniffer-annotations/1.14/animal-sniffer-annotations-1.14.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/codehaus/mojo/animal-sniffer-annotations/1.14/animal-sniffer-annotations-1.14-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/codehaus/mojo/animal-sniffer-annotations/1.14/animal-sniffer-annotations-1.14-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: org.eclipse.collections:eclipse-collections-api:7.1.2">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections-api/7.1.2/eclipse-collections-api-7.1.2.jar!/" />
@ -1622,15 +1687,15 @@
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/1.0.7/kotlin-stdlib-1.0.7-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: org.json:json:20160810">
<library name="Maven: org.json:json:20180813">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/json/json/20160810/json-20160810.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/json/json/20180813/json-20180813.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/json/json/20160810/json-20160810-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/json/json/20180813/json-20180813-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/json/json/20160810/json-20160810-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/json/json/20180813/json-20180813-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: org.mapdb:elsa:3.0.0-M5">

View File

@ -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.1</version>
<version>4.1.1</version>
</dependency>
```
```gradle
compile "org.telegram:telegrambots:4.1"
compile "org.telegram:telegrambots:4.1.1"
```
2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/4.1)
3. Download the jar(including all dependencies) from [here](https://github.com/rubenlagus/TelegramBots/releases/tag/v4.1)
2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/4.1.1)
3. Download the jar(including all dependencies) from [here](https://github.com/rubenlagus/TelegramBots/releases/tag/v4.1.1)
In order to use Long Polling mode, just create your own bot extending `org.telegram.telegrambots.bots.TelegramLongPollingBot`.

View File

@ -1,3 +1,7 @@
### <a id="4.1.1"></a>4.1.1 ###
1. Removed unsafe dependencies
2. Fix bugs: #535, #524, #563, #562 and #557
### <a id="4.1"></a>4.1 ###
1. Support for Api Version [4.1](https://core.telegram.org/bots/api-changelog#august-27-2018)
2. Fix #507 and #512

View File

@ -1,4 +1,5 @@
* [How to get picture?](#how_to_get_picture)
* [How to display ChatActions like "typing" or "recording a voice message"?](#how_to_sendchataction)
* [How to send photos?](#how_to_send_photos)
* [How do I send photos by file_id?](#how_to_send_photos_file_id)
* [How to use custom keyboards?](#how_to_use_custom_keyboards)
@ -74,6 +75,38 @@ public java.io.File downloadPhotoByFilePath(String filePath) {
The returned `java.io.File` object will be your photo
## <a id="how_to_sendchataction"></a>How to display ChatActions like "typing" or "recording a voice message"? ##
Quick example here that is showing ChactActions for commands like "/type" or "/record_audio"
```java
if (update.hasMessage() && update.getMessage().hasText()) {
String text = update.getMessage().getText();
SendChatAction sendChatAction = new SendChatAction();
sendChatAction.setChatId(update.getMessage().getChatId());
if (text.equals("/type")) {
// -> "typing"
sendChatAction.setAction(ActionType.TYPING);
// -> "recording a voice message"
} else if (text.equals("/record_audio")) {
sendChatAction.setAction(ActionType.RECORDAUDIO);
} else {
// -> more actions in the Enum ActionType
// For information: https://core.telegram.org/bots/api#sendchataction
sendChatAction.setAction(ActionType.UPLOADDOCUMENT);
}
try {
Boolean wasSuccessfull = execute(sendChatAction);
} catch (TelegramApiException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
```
## <a id="how_to_send_photos"></a>How to send photos? ##
There are several method to send a photo to an user using `sendPhoto` method: With a `file_id`, with an `url` or uploading the file. In this example, we assume that we already have the *chat_id* where we want to send the photo:
@ -231,8 +264,6 @@ 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) {
@ -246,7 +277,7 @@ public class YourApplicationMainClass {
After that your bot will look like:
```java
//Standart Spring component annotation
//Standard Spring component annotation
@Component
public class YourBotClassName extends TelegramLongPollingBot {
//Bot body.

View File

@ -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.1</version>
<version>4.1.1</version>
</dependency>
```
* With **Gradle**:
```groovy
compile group: 'org.telegram', name: 'telegrambots', version: '4.1'
compile group: 'org.telegram', name: 'telegrambots', version: '4.1.1'
```
2. Don't like **Maven Central Repository**? It can also be taken from [Jitpack](https://jitpack.io/#rubenlagus/TelegramBots).

View File

@ -0,0 +1,88 @@
* [Bot Token Dont's](#bot-token-donts)
* [Using Enviroment Variables](#using-environment-variables)
* [Setting Enviroment Variables](#setting-environment-variables)
* [Accessing Enviroment Variables](#accessing-enviroment-variables)
* [Using Command Line Arguments](#using-command-line-arguments)
# <a id="bot-token-donts"></a> Bot Token Dont's ##
* Tokens should not be hardcoded into the bot code
* Tokens should never be published
* Tokens should not be pushed into Repositorys
# <a id="using-environment-variables"></a> Using Environment Variables ###
One convenient way to inject your bot token into the application is by using Environment Variables. Environment Variables are Values that are set in the Environment the Bot is running.
Those Values are not defined in the Application and therefore are not visible in the code.
## <a id="setting-environment-variables"></a> Setting Environment Variables ###
### Windows
Enviroment Variables in Windows can be set using the Console (CMD) using
```batchfile
SETX [VARIABLE_NAME] [YOUR_BOT_TOKEN]
```
It can also be set using the Windows GUI
* From the desktop, right click the Computer icon.
* Choose Properties from the context menu.
* Click the Advanced system settings link.
* Click Environment Variables...
* In the 'User Variables for X' click New and enter a Name and your Token as the Value
### Linux & Mac
* Open the '~/.bash_profile' File
* Append the following to it:
```bash
export VARIABLE_NAME = {YOUR_BOT_TOKEN}
```
* Save the file
* Either reboot your system or run the command above in your terminal
### IntelliJ
* Go to Run->Edit Configuratuions...
* Navigate to your Java Run Configuration
* Under Enviroment->Enviroment Variables click the Folder Icon
* Click the Plus Icon to add a new Variable
* Enter a Name and your Token as the Value
###Heroku Cloud
* Naviage to your App
* In the Settings Tab under Config Vars, click "Reveal Config Vars"
* Enter a Name and your Token as the Value
* Click the "Add" button
## <a id="accessing-enviroment-variables"></a> Accessing Enviroment Variables ##
### Java
You can access the Enviroment Variables by using System.getEnv()
```java
String BOT_TOKEN = System.getenv("VARIABLE_NAME");
```
### Spring
In Spring the @Value annotation allows you to inject the Value into your class
```java
public class Bot extends TelegramLongPollingBot {
public Bot(@Value("${VARIABLE_NAME") String botToken) {
this.botToken = botToken;
}
}
```
# <a id="sing-command-line-arguments"></a> Using Command Line Arguments
An easier but not Recommended way of injecting the Bottoken is by utilizing Command Line Arguments when starting the Application
In this case your main Method is responsible for taking in the Token
```java
public static void main(String[] args) {
String botToken = args[0];
}
```
You now have to call your jar by using
```
java -jar myBot.jar [BOT_TOKEN]
```

View File

@ -1,3 +1,3 @@
Welcome to the TelegramBots wiki. Use the sidebar on the right. If you're not sure what to look at, why not take a look at the [[Getting Started|Getting-Started]] guide?
If you want more detailed explanations, you can also visit this [gitbook by MonsterDeveloper's](https://www.gitbook.com/book/monsterdeveloper/writing-telegram-bots-on-java/details)
If you want more detailed explanations, you can also visit this [gitbook by MonsterDeveloper's](https://monsterdeveloper.gitbooks.io/writing-telegram-bots-on-java/content/)

View File

@ -3,6 +3,7 @@
* [[Errors Handling]]
* [[Using HTTP Proxy]]
* [[FAQ]]
* [[Handling Bot Tokens]]
* AbilityBot
* [[Simple Example]]
* [[Hello Ability]]
@ -11,5 +12,6 @@
* [[Bot Testing]]
* [[Bot Recovery]]
* [[Advanced]]
* [[Additional Examples]]
* [[Changelog]]
* [[How To Update]]

View File

@ -0,0 +1,5 @@
# Additional Examples
The following are nifty links to projects and examples that leverage the AbilityBot module. If you do have a project that you would like to share, please reach out!
[FitnessBot](https://craftcodecrew.com/getting-started-with-the-telegram-abilitybot/) -
A fully fledged guide that walks you through building a fitness bot from A to Z

View File

@ -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.1</version>
<version>4.1.1</version>
</dependency>
```
* **Gradle**
```groovy
compile group: 'org.telegram', name: 'telegrambots-abilties', version: '4.1'
compile group: 'org.telegram', name: 'telegrambots-abilties', version: '4.1.1'
```
* [JitPack](https://jitpack.io/#rubenlagus/TelegramBots)

View File

@ -7,7 +7,7 @@
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<packaging>pom</packaging>
<version>4.1</version>
<version>4.1.1</version>
<modules>
<module>telegrambots</module>
@ -28,6 +28,5 @@
<properties>
<maven.deploy.skip>true</maven.deploy.skip>
<bots.version>4.1</bots.version>
</properties>
</project>

View File

@ -18,19 +18,19 @@ Usage
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-abilities</artifactId>
<version>4.1</version>
<version>4.1.1</version>
</dependency>
```
**Gradle**
```gradle
compile "org.telegram:telegrambots-abilities:4.1"
compile "org.telegram:telegrambots-abilities:4.1.1"
```
**JitPack** - [JitPack](https://jitpack.io/#rubenlagus/TelegramBots/v4.1)
**JitPack** - [JitPack](https://jitpack.io/#rubenlagus/TelegramBots/v4.1.1)
**Plain imports** - [Here](https://github.com/rubenlagus/TelegramBots/releases/tag/v4.1)
**Plain imports** - [Here](https://github.com/rubenlagus/TelegramBots/releases/tag/v4.1.1)
Motivation
----------

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-abilities</artifactId>
<version>4.1</version>
<version>4.1.1</version>
<packaging>jar</packaging>
<name>Telegram Ability Bot</name>
@ -65,17 +65,16 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<bots.version>4.1</bots.version>
<commonslang.version>3.5</commonslang.version>
<mapdb.version>3.0.4</mapdb.version>
<guava.version>19.0</guava.version>
<guava.version>27.0.1-jre</guava.version>
</properties>
<dependencies>
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>${bots.version}</version>
<version>4.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
@ -91,6 +90,28 @@
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
<exclusions>
<exclusion>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_annotations</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.j2objc</groupId>
<artifactId>j2objc-annotations</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-annotations</artifactId>
</exclusion>
<exclusion>
<groupId>org.checkerframework</groupId>
<artifactId>checker-compat-qual</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>

View File

@ -12,20 +12,21 @@ import org.telegram.abilitybots.api.objects.*;
import org.telegram.abilitybots.api.sender.DefaultSender;
import org.telegram.abilitybots.api.sender.MessageSender;
import org.telegram.abilitybots.api.sender.SilentSender;
import org.telegram.abilitybots.api.util.AbilityExtension;
import org.telegram.abilitybots.api.util.AbilityUtils;
import org.telegram.abilitybots.api.util.Pair;
import org.telegram.abilitybots.api.util.Trio;
import org.telegram.telegrambots.bots.DefaultAbsSender;
import org.telegram.telegrambots.bots.DefaultBotOptions;
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.meta.api.methods.GetFile;
import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatAdministrators;
import org.telegram.telegrambots.meta.api.methods.send.SendDocument;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.api.objects.User;
import org.telegram.telegrambots.bots.DefaultAbsSender;
import org.telegram.telegrambots.bots.DefaultBotOptions;
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.meta.logging.BotLogger;
import org.telegram.telegrambots.meta.api.objects.Update;
import java.io.File;
import java.io.FileNotFoundException;
@ -36,7 +37,9 @@ import java.lang.reflect.Method;
import java.util.*;
import java.util.Map.Entry;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static com.google.common.base.Strings.isNullOrEmpty;
@ -93,7 +96,7 @@ import static org.telegram.abilitybots.api.util.AbilityUtils.*;
* @author Abbas Abou Daya
*/
@SuppressWarnings({"ConfusingArgumentToVarargsMethod", "UnusedReturnValue", "WeakerAccess", "unused", "ConstantConditions"})
public abstract class BaseAbilityBot extends DefaultAbsSender {
public abstract class BaseAbilityBot extends DefaultAbsSender implements AbilityExtension {
private static final String TAG = BaseAbilityBot.class.getSimpleName();
// DB objects
@ -611,22 +614,38 @@ public abstract class BaseAbilityBot extends DefaultAbsSender {
*/
private void registerAbilities() {
try {
abilities = stream(this.getClass().getMethods())
.filter(method -> method.getReturnType().equals(Ability.class))
.map(this::returnAbility)
// Collect all classes that implement AbilityExtension declared in the bot
List<AbilityExtension> extensions = stream(getClass().getMethods())
.filter(checkReturnType(AbilityExtension.class))
.map(returnExtension(this))
.collect(Collectors.toList());
// Add the bot itself as it is an AbilityExtension
extensions.add(this);
// Extract all abilities from every single extension instance
abilities = extensions.stream()
.flatMap(ext -> stream(ext.getClass().getMethods())
.filter(checkReturnType(Ability.class))
.map(returnAbility(ext)))
// Abilities are immutable, build it respectively
.collect(ImmutableMap::<String, Ability>builder,
(b, a) -> b.put(a.name(), a),
(b1, b2) -> b1.putAll(b2.build()))
.build();
Stream<Reply> methodReplies = stream(this.getClass().getMethods())
.filter(method -> method.getReturnType().equals(Reply.class))
.map(this::returnReply);
// Extract all replies from every single extension instance
Stream<Reply> extensionReplies = extensions.stream()
.flatMap(ext -> stream(ext.getClass().getMethods())
.filter(checkReturnType(Reply.class))
.map(returnReply(ext)));
// Replies can be standalone or attached to abilities, fetch those too
Stream<Reply> abilityReplies = abilities.values().stream()
.flatMap(ability -> ability.replies().stream());
replies = Stream.concat(methodReplies, abilityReplies).collect(
// Now create the replies registry (list)
replies = Stream.concat(abilityReplies, extensionReplies).collect(
ImmutableList::<Reply>builder,
Builder::add,
(b1, b2) -> b1.addAll(b2.build()))
@ -635,37 +654,65 @@ public abstract class BaseAbilityBot extends DefaultAbsSender {
BotLogger.error(TAG, "Duplicate names found while registering abilities. Make sure that the abilities declared don't clash with the reserved ones.", e);
throw propagate(e);
}
}
/**
* @param clazz the type to be tested
* @return a predicate testing the return type of the method corresponding to the class parameter
*/
private Predicate<Method> checkReturnType(Class<?> clazz) {
return method -> clazz.isAssignableFrom(method.getReturnType());
}
/**
* Invokes the method and retrieves its return {@link Reply}.
*
* @param obj an bot or extension that this method is invoked with
* @return a {@link Function} which returns the {@link Reply} returned by the given method
*/
private Function<? super Method, AbilityExtension> returnExtension(Object obj) {
return method -> {
try {
return (AbilityExtension) method.invoke(obj);
} catch (IllegalAccessException | InvocationTargetException e) {
BotLogger.error("Could not add ability extension", TAG, e);
throw propagate(e);
}
};
}
/**
* Invokes the method and retrieves its return {@link Ability}.
*
* @param method a method that returns an ability
* @return the ability returned by the method
* @param obj an bot or extension that this method is invoked with
* @return a {@link Function} which returns the {@link Ability} returned by the given method
*/
private Ability returnAbility(Method method) {
private Function<? super Method, Ability> returnAbility(Object obj) {
return method -> {
try {
return (Ability) method.invoke(this);
return (Ability) method.invoke(obj);
} catch (IllegalAccessException | InvocationTargetException e) {
BotLogger.error("Could not add ability", TAG, e);
throw propagate(e);
}
};
}
/**
* Invokes the method and retrieves its returned Reply.
* Invokes the method and retrieves its return {@link Reply}.
*
* @param method a method that returns a reply
* @return the reply returned by the method
* @param obj an bot or extension that this method is invoked with
* @return a {@link Function} which returns the {@link Reply} returned by the given method
*/
private Reply returnReply(Method method) {
private Function<? super Method, Reply> returnReply(Object obj) {
return method -> {
try {
return (Reply) method.invoke(this);
return (Reply) method.invoke(obj);
} catch (IllegalAccessException | InvocationTargetException e) {
BotLogger.error("Could not add reply", TAG, e);
throw propagate(e);
}
};
}
private void postConsumption(Pair<MessageContext, Ability> pair) {

View File

@ -0,0 +1,7 @@
package org.telegram.abilitybots.api.util;
/**
* An interface to mark a class as an extension. Similar to when a method returns an Ability, it is added to the bot, a method which returns an AbilityExtension will add all Abilities or Replies from this Extension to the bot.
*/
public interface AbilityExtension {
}

View File

@ -0,0 +1,89 @@
package org.telegram.abilitybots.api.bot;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.telegram.abilitybots.api.objects.Ability;
import org.telegram.abilitybots.api.util.AbilityExtension;
import java.io.IOException;
import static junit.framework.TestCase.assertTrue;
import static org.telegram.abilitybots.api.db.MapDBContext.offlineInstance;
import static org.telegram.abilitybots.api.objects.Locality.ALL;
import static org.telegram.abilitybots.api.objects.Privacy.PUBLIC;
public class ExtensionTest {
private ExtensionUsingBot bot;
@Before
public void setUp() {
bot = new ExtensionUsingBot();
}
@Test
public void methodReturningAbilities() {
assertTrue("Failed to find Ability in directly declared in root extension/bot", hasAbilityNamed("direct"));
assertTrue("Failed to find Ability in directly declared in extension returned by method returning the AbilityExtension class", hasAbilityNamed("returningSuperClass0abc"));
assertTrue("Failed to find Ability in directly declared in extension returned by method returning the AbilityExtension subclass", hasAbilityNamed("returningSubClass0abc"));
}
@After
public void tearDown() throws IOException {
bot.db.clear();
bot.db.close();
}
private boolean hasAbilityNamed(String name) {
return bot.abilities().values().stream().map(Ability::name).anyMatch(name::equals);
}
public static class ExtensionUsingBot extends AbilityBot {
public ExtensionUsingBot() {
super("", "", offlineInstance("testing"));
}
@Override
public int creatorId() {
return 0;
}
public AbilityBotExtension methodReturningExtensionSubClass() {
return new AbilityBotExtension("returningSubClass");
}
public AbilityExtension methodReturningExtensionSuperClass() {
return new AbilityBotExtension("returningSuperClass");
}
public Ability methodReturningAbility() {
return Ability.builder()
.name("direct")
.info("Test ability")
.locality(ALL)
.privacy(PUBLIC)
.action(messageContext -> {
})
.build();
}
}
public static class AbilityBotExtension implements AbilityExtension {
private String name;
public AbilityBotExtension(String name) {
this.name = name;
}
public Ability abc() {
return Ability.builder()
.name(name + "0abc")
.info("Test ability")
.locality(ALL)
.privacy(PUBLIC)
.action(ctx -> {
})
.build();
}
}
}

View File

@ -15,7 +15,7 @@ Usage
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-chat-session-bot</artifactId>
<version>4.1</version>
<version>4.1.1</version>
</dependency>
```

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-chat-session-bot</artifactId>
<version>4.1</version>
<version>4.1.1</version>
<packaging>jar</packaging>
<name>Telegram Bots Chat Session Bot</name>
@ -65,7 +65,6 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<bots.version>4.1</bots.version>
<shiro.version>1.4.0</shiro.version>
</properties>
@ -74,7 +73,7 @@
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>${bots.version}</version>
<version>4.1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.shiro/shiro-core -->

View File

@ -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.1</version>
<version>4.1.1</version>
</dependency>
```
2. Using Gradle:
```gradle
compile "org.telegram:telegrambotsextensions:4.1"
compile "org.telegram:telegrambotsextensions:4.1.1"
```

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.telegram</groupId>
<artifactId>telegrambotsextensions</artifactId>
<version>4.1</version>
<version>4.1.1</version>
<packaging>jar</packaging>
<name>Telegram Bots Extensions</name>
@ -59,14 +59,13 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<bots.version>4.1</bots.version>
</properties>
<dependencies>
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>${bots.version}</version>
<version>4.1.1</version>
</dependency>
</dependencies>

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-meta</artifactId>
<version>4.1</version>
<version>4.1.1</version>
<packaging>jar</packaging>
<name>Telegram Bots Meta</name>
@ -59,10 +59,10 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<guice.version>4.1.0</guice.version>
<jackson.version>2.8.7</jackson.version>
<jacksonanotation.version>2.8.0</jacksonanotation.version>
<json.version>20160810</json.version>
<guice.version>4.2.2</guice.version>
<jackson.version>2.9.7</jackson.version>
<jacksonanotation.version>2.9.0</jacksonanotation.version>
<json.version>20180813</json.version>
<junit.version>4.12</junit.version>
</properties>

View File

@ -18,7 +18,7 @@ public class TelegramBotsApi {
private static final String webhookUrlFormat = "{0}callback/";
private boolean useWebhook; ///< True to enable webhook usage
private Webhook webhook; ///< Webhook instance
private String extrenalUrl; ///< External url of the bots
private String externalUrl; ///< External url of the bots
private String pathToCertificate; ///< Path to public key certificate
/**
@ -43,7 +43,7 @@ public class TelegramBotsApi {
}
this.useWebhook = true;
this.extrenalUrl = fixExternalUrl(externalUrl);
this.externalUrl = fixExternalUrl(externalUrl);
webhook = ApiContext.getInstance(Webhook.class);
webhook.setInternalUrl(internalUrl);
webhook.startServer();
@ -71,7 +71,7 @@ public class TelegramBotsApi {
}
this.useWebhook = true;
this.extrenalUrl = fixExternalUrl(externalUrl);
this.externalUrl = fixExternalUrl(externalUrl);
webhook = ApiContext.getInstance(Webhook.class);
webhook.setInternalUrl(internalUrl);
webhook.setKeyStore(keyStore, keyStorePassword);
@ -104,7 +104,7 @@ public class TelegramBotsApi {
}
this.useWebhook = true;
this.extrenalUrl = fixExternalUrl(externalUrl);
this.externalUrl = fixExternalUrl(externalUrl);
this.pathToCertificate = pathToCertificate;
webhook = ApiContext.getInstance(Webhook.class);
webhook.setInternalUrl(internalUrl);
@ -133,7 +133,7 @@ public class TelegramBotsApi {
public void registerBot(WebhookBot bot) throws TelegramApiRequestException {
if (useWebhook) {
webhook.registerWebhook(bot);
bot.setWebhook(extrenalUrl + bot.getBotPath(), pathToCertificate);
bot.setWebhook(externalUrl + bot.getBotPath(), pathToCertificate);
}
}

View File

@ -9,9 +9,11 @@ package org.telegram.telegrambots.meta.api.methods;
public enum ActionType {
TYPING("typing"),
RECORDVIDEO("record_video"),
RECORDVIDEONOTE("record_video_note"),
RECORDAUDIO("record_audio"),
UPLOADPHOTO("upload_photo"),
UPLOADVIDEO("upload_video"),
UPLOADVIDEONOTE("upload_video_note"),
UPLOADAUDIO("upload_audio"),
UPLOADDOCUMENT("upload_document"),
FINDLOCATION("find_location");
@ -36,12 +38,16 @@ public enum ActionType {
return TYPING;
case "record_video":
return RECORDVIDEO;
case "record_video_note":
return RECORDVIDEONOTE;
case "record_audio":
return RECORDAUDIO;
case "upload_photo":
return UPLOADPHOTO;
case "upload_video":
return UPLOADVIDEO;
case "upload_video_note":
return UPLOADVIDEONOTE;
case "upload_audio":
return UPLOADAUDIO;
case "upload_document":

View File

@ -35,13 +35,13 @@ public class AnswerCallbackQuery extends BotApiMethod<Boolean> {
@JsonProperty(TEXT_FIELD)
private String text; ///< Optional Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters
@JsonProperty(SHOWALERT_FIELD)
private Boolean showAlert; ///< Optional. If true, an alert will be shown by the client instead of a notificaiton at the top of the chat screen. Defaults to false.
private Boolean showAlert; ///< Optional. If true, an alert will be shown by the client instead of a notification at the top of the chat screen. Defaults to false.
@JsonProperty(URL_FIELD)
/**
* Optional. URL that will be opened by the user's client.
* If you have created a Game and accepted the conditions via @Botfather,
* specify the URL that opens your game. Otherwise you may use links
* InlineQueryResultGamelike telegram.me/your_bot?start=XXXX that open your bot with a parameter.
* like telegram.me/your_bot?start=XXXX that open your bot with a parameter.
*/
private String url;
@JsonProperty(CACHETIME_FIELD)

View File

@ -136,8 +136,8 @@ public class AnswerInlineQuery extends BotApiMethod<Boolean> {
if (switchPmParameter.length() > 64) {
throw new TelegramApiValidationException("SwitchPmParameter can't be longer than 64 chars", this);
}
if (!Pattern.matches("[A-Za-z0-9_]+", switchPmParameter.trim() )) {
throw new TelegramApiValidationException("SwitchPmParameter only allows A-Z, a-z, 0-9 and _ characters", this);
if (!Pattern.matches("[A-Za-z0-9_\\-]+", switchPmParameter.trim() )) {
throw new TelegramApiValidationException("SwitchPmParameter only allows A-Z, a-z, 0-9, _ and - characters", this);
}
}
for (InlineQueryResult result : results) {

View File

@ -63,7 +63,7 @@ public class SetGameScore extends BotApiMethod<Serializable> {
@JsonProperty(SCORE_FIELD)
private Integer score; ///< New score, must be positive
@JsonProperty(FORCE_FIELD)
private Boolean force; ///< Opfional. Pass True, if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters
private Boolean force; ///< Optional. Pass True, if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters
public SetGameScore() {
super();

View File

@ -0,0 +1,91 @@
package org.telegram.telegrambots.meta.api.methods.groupadministration;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import java.io.IOException;
import java.util.Objects;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ApiResponse;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 3.4
* Use this method to delete a group sticker set from a supergroup.
* The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
* Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method.
* Returns True on success.
*/
public class DeleteChatStickerSet extends BotApiMethod<Boolean> {
public static final String PATH = "deleteChatStickerSet";
private static final String CHATID_FIELD = "chat_id";
@JsonProperty(CHATID_FIELD)
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
public DeleteChatStickerSet() {
super();
}
public DeleteChatStickerSet(String chatId) {
super();
this.chatId = checkNotNull(chatId);
}
public DeleteChatStickerSet(Long chatId) {
super();
this.chatId = checkNotNull(chatId).toString();
}
public String getChatId() {
return chatId;
}
public DeleteChatStickerSet setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public DeleteChatStickerSet setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
@Override
public String getMethod() {
return PATH;
}
@Override
public Boolean deserializeResponse(String answer) throws TelegramApiRequestException {
try {
ApiResponse<Boolean> result = OBJECT_MAPPER.readValue(answer,
new TypeReference<ApiResponse<Boolean>>(){});
if (result.getOk()) {
return result.getResult();
} else {
throw new TelegramApiRequestException("Error deleting chat sticker set", result);
}
} catch (IOException e) {
throw new TelegramApiRequestException("Unable to deserialize response", e);
}
}
@Override
public void validate() throws TelegramApiValidationException {
if (chatId == null || chatId.isEmpty()) {
throw new TelegramApiValidationException("ChatId can't be empty", this);
}
}
@Override
public String toString() {
return "DeleteChatStickerSet{" +
"chatId='" + chatId + '\'' +
'}';
}
}

View File

@ -1,17 +1,5 @@
package org.telegram.telegrambots.meta.api.methods.groupadministration;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ApiResponse;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.IOException;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 3.4
@ -19,75 +7,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
* The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
* Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method.
* Returns True on success.
* @deprecated Replaced by {@link DeleteChatStickerSet}
*/
public class DeleteStickerSetName extends BotApiMethod<Boolean> {
public static final String PATH = "deleteChatStickerSet";
private static final String CHATID_FIELD = "chat_id";
@JsonProperty(CHATID_FIELD)
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
public DeleteStickerSetName() {
super();
}
public DeleteStickerSetName(String chatId) {
super();
this.chatId = checkNotNull(chatId);
}
public DeleteStickerSetName(Long chatId) {
super();
this.chatId = checkNotNull(chatId).toString();
}
public String getChatId() {
return chatId;
}
public DeleteStickerSetName setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public DeleteStickerSetName setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
@Override
public String getMethod() {
return PATH;
}
@Override
public Boolean deserializeResponse(String answer) throws TelegramApiRequestException {
try {
ApiResponse<Boolean> result = OBJECT_MAPPER.readValue(answer,
new TypeReference<ApiResponse<Boolean>>(){});
if (result.getOk()) {
return result.getResult();
} else {
throw new TelegramApiRequestException("Error deleting sticker set name", result);
}
} catch (IOException e) {
throw new TelegramApiRequestException("Unable to deserialize response", e);
}
}
@Override
public void validate() throws TelegramApiValidationException {
if (chatId == null || chatId.isEmpty()) {
throw new TelegramApiValidationException("ChatId can't be empty", this);
}
}
@Override
public String toString() {
return "GetChat{" +
"chatId='" + chatId + '\'' +
'}';
}
@Deprecated
public class DeleteStickerSetName extends DeleteChatStickerSet {
}

View File

@ -1,80 +1,11 @@
package org.telegram.telegrambots.meta.api.methods.groupadministration;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ApiResponse;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.IOException;
import java.util.Objects;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief Use this method to get the number of members in a chat. Returns Int on success.
* @date 20 of May of 2016
* Use this method to get the number of members in a chat. Returns Int on success.
* @deprecated Replaced by {@link GetChatMembersCount}
*/
public class GetChatMemberCount extends BotApiMethod<Integer> {
public static final String PATH = "getChatMembersCount";
private static final String CHATID_FIELD = "chat_id";
@JsonProperty(CHATID_FIELD)
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
public GetChatMemberCount() {
super();
}
public String getChatId() {
return chatId;
}
public GetChatMemberCount setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public GetChatMemberCount setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
@Override
public String getMethod() {
return PATH;
}
@Override
public Integer deserializeResponse(String answer) throws TelegramApiRequestException {
try {
ApiResponse<Integer> result = OBJECT_MAPPER.readValue(answer,
new TypeReference<ApiResponse<Integer>>(){});
if (result.getOk()) {
return result.getResult();
} else {
throw new TelegramApiRequestException("Error getting chat member count", result);
}
} catch (IOException e) {
throw new TelegramApiRequestException("Unable to deserialize response", e);
}
}
@Override
public void validate() throws TelegramApiValidationException {
if (chatId == null || chatId.isEmpty()) {
throw new TelegramApiValidationException("ChatId can't be empty", this);
}
}
@Override
public String toString() {
return "GetChatMemberCount{" +
"chatId='" + chatId + '\'' +
'}';
}
@Deprecated
public class GetChatMemberCount extends GetChatMembersCount {
}

View File

@ -0,0 +1,78 @@
package org.telegram.telegrambots.meta.api.methods.groupadministration;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ApiResponse;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.IOException;
import java.util.Objects;
/**
* @author Ruben Bermudez
* @version 1.0
* Use this method to get the number of members in a chat. Returns Int on success.
*/
public class GetChatMembersCount extends BotApiMethod<Integer> {
public static final String PATH = "getChatMembersCount";
private static final String CHATID_FIELD = "chat_id";
@JsonProperty(CHATID_FIELD)
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
public GetChatMembersCount() {
super();
}
public String getChatId() {
return chatId;
}
public GetChatMembersCount setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public GetChatMembersCount setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
@Override
public String getMethod() {
return PATH;
}
@Override
public Integer deserializeResponse(String answer) throws TelegramApiRequestException {
try {
ApiResponse<Integer> result = OBJECT_MAPPER.readValue(answer,
new TypeReference<ApiResponse<Integer>>(){});
if (result.getOk()) {
return result.getResult();
} else {
throw new TelegramApiRequestException("Error getting chat members count", result);
}
} catch (IOException e) {
throw new TelegramApiRequestException("Unable to deserialize response", e);
}
}
@Override
public void validate() throws TelegramApiValidationException {
if (chatId == null || chatId.isEmpty()) {
throw new TelegramApiValidationException("ChatId can't be empty", this);
}
}
@Override
public String toString() {
return "GetChatMembersCount{" +
"chatId='" + chatId + '\'' +
'}';
}
}

View File

@ -1,5 +1,6 @@
package org.telegram.telegrambots.meta.api.methods.groupadministration;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
@ -9,6 +10,9 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
import java.time.ZonedDateTime;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
@ -81,11 +85,25 @@ public class KickChatMember extends BotApiMethod<Boolean> {
return untilDate;
}
public KickChatMember setUntilDate(Integer untilDate) {
this.untilDate = untilDate;
public KickChatMember setUntilDate(Integer untilDateInSeconds) {
this.untilDate = untilDateInSeconds;
return this;
}
@JsonIgnore
public KickChatMember setUntilDate(Instant instant) {
return setUntilDate((int) instant.getEpochSecond());
}
@JsonIgnore
public KickChatMember setUntilDate(ZonedDateTime date) {
return setUntilDate(date.toInstant());
}
public KickChatMember forTimePeriod(Duration duration) {
return setUntilDate(Instant.now().plusMillis(duration.toMillis()));
}
@Override
public String getMethod() {
return PATH;

View File

@ -1,5 +1,6 @@
package org.telegram.telegrambots.meta.api.methods.groupadministration;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
@ -8,6 +9,9 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
import java.time.ZonedDateTime;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
@ -89,11 +93,25 @@ public class RestrictChatMember extends BotApiMethod<Boolean> {
return untilDate;
}
public RestrictChatMember setUntilDate(Integer untilDate) {
this.untilDate = untilDate;
public RestrictChatMember setUntilDate(Integer untilDateInSeconds) {
this.untilDate = untilDateInSeconds;
return this;
}
@JsonIgnore
public RestrictChatMember setUntilDate(Instant instant) {
return setUntilDate((int) instant.getEpochSecond());
}
@JsonIgnore
public RestrictChatMember setUntilDate(ZonedDateTime date) {
return setUntilDate(date.toInstant());
}
public RestrictChatMember forTimePeriod(Duration duration) {
return setUntilDate(Instant.now().plusMillis(duration.toMillis()));
}
public Boolean getCanSendMessages() {
return canSendMessages;
}

View File

@ -46,9 +46,9 @@ public class SendAnimation extends PartialBotApiMethod<Message> {
*/
private InputFile animation;
private Integer duration; ///< Optional. Duration of sent animation in seconds
private String caption; ///< OptionaL. Animation caption (may also be used when resending videos by file_id).
private String caption; ///< Optional. Animation caption (may also be used when resending videos by file_id).
private Integer width; ///< Optional. Animation width
private Integer height; ///< OptionaL. Animation height
private Integer height; ///< Optional. Animation height
private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message
private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard

View File

@ -2,7 +2,6 @@ package org.telegram.telegrambots.meta.api.methods.send;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.methods.ParseMode;
import org.telegram.telegrambots.meta.api.objects.Message;
@ -222,6 +221,7 @@ public class SendMessage extends BotApiMethod<Message> {
"chatId='" + chatId + '\'' +
", text='" + text + '\'' +
", parseMode='" + parseMode + '\'' +
", disableNotification='" + disableNotification + '\'' +
", disableWebPagePreview=" + disableWebPagePreview +
", replyToMessageId=" + replyToMessageId +
", replyMarkup=" + replyMarkup +

View File

@ -39,9 +39,9 @@ public class SendVideo extends PartialBotApiMethod<Message> {
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
private InputFile video; ///< Video to send. file_id as String to resend a video that is already on the Telegram servers or URL to upload it
private Integer duration; ///< Optional. Duration of sent video in seconds
private String caption; ///< OptionaL. Video caption (may also be used when resending videos by file_id).
private String caption; ///< Optional. Video caption (may also be used when resending videos by file_id).
private Integer width; ///< Optional. Video width
private Integer height; ///< OptionaL. Video height
private Integer height; ///< Optional. Video height
private Boolean supportsStreaming; ///< Optional. Pass True, if the uploaded video is suitable for streaming
private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message

View File

@ -164,7 +164,7 @@ public class CreateNewStickerSet extends PartialBotApiMethod<Boolean> {
throw new TelegramApiValidationException("name can't be empty", this);
}
if (title == null || title.isEmpty()) {
throw new TelegramApiValidationException("userId can't be empty", this);
throw new TelegramApiValidationException("title can't be empty", this);
}
if (emojis == null || emojis.isEmpty()) {
throw new TelegramApiValidationException("emojis can't be empty", this);

View File

@ -17,14 +17,14 @@ import static com.google.common.base.Preconditions.checkNotNull;
* Use this method to move a sticker in a set created by the bot to a specific position. Returns True on success.
*/
public class SetStickerPositionInSet extends BotApiMethod<Boolean> {
private static final String PATH = "getStickerSet";
private static final String PATH = "setStickerPositionInSet";
private static final String STICKER_FIELD = "sticker";
private static final String POSITION_FIELD = "position";
@JsonProperty(STICKER_FIELD)
private String sticker; ///< File identifier of the sticker
@JsonProperty(STICKER_FIELD)
@JsonProperty(POSITION_FIELD)
private Integer position; ///< New sticker position in the set, zero-based
public SetStickerPositionInSet(String sticker, Integer position) {
@ -61,7 +61,7 @@ public class SetStickerPositionInSet extends BotApiMethod<Boolean> {
if (sticker == null || sticker.isEmpty()) {
throw new TelegramApiValidationException("sticker can't be null", this);
}
if (position == null || position > 0) {
if (position == null || position < 0) {
throw new TelegramApiValidationException("position can't be null", this);
}
}
@ -71,7 +71,7 @@ public class SetStickerPositionInSet extends BotApiMethod<Boolean> {
}
public SetStickerPositionInSet setSticker(String sticker) {
this.sticker = sticker;
this.sticker = checkNotNull(sticker);
return this;
}
@ -80,7 +80,7 @@ public class SetStickerPositionInSet extends BotApiMethod<Boolean> {
}
public SetStickerPositionInSet setPosition(Integer position) {
this.position = position;
this.position = checkNotNull(position);
return this;
}

View File

@ -1,5 +1,6 @@
package org.telegram.telegrambots.meta.api.methods.updatingmessages;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
@ -50,7 +51,7 @@ public class EditMessageLiveLocation extends BotApiMethod<Serializable> {
@JsonProperty(LATITUDE_FIELD)
private Float latitude; ///< Latitude of new location
@JsonProperty(LONGITUDE_FIELD)
private Float longitud; ///< Longitude of new location
private Float longitude; ///< Longitude of new location
@JsonProperty(REPLYMARKUP_FIELD)
private InlineKeyboardMarkup replyMarkup; ///< Optional. A JSON-serialized object for an inline keyboard.
@ -109,13 +110,31 @@ public class EditMessageLiveLocation extends BotApiMethod<Serializable> {
return this;
}
/**
* @deprecated Replaced by {@link #getLongitude()}
*/
@Deprecated
@JsonIgnore
public Float getLongitud() {
return longitud;
return longitude;
}
public EditMessageLiveLocation setLongitud(Float longitud) {
Objects.requireNonNull(longitud);
this.longitud = longitud;
public Float getLongitude() {
return longitude;
}
/**
* @deprecated Replaced by {@link #setLongitude(Float)}
*/
@Deprecated
@JsonIgnore
public EditMessageLiveLocation setLongitud(Float longitude) {
return setLongitude(longitude);
}
public EditMessageLiveLocation setLongitude(Float longitude) {
Objects.requireNonNull(longitude);
this.longitude = longitude;
return this;
}
@ -170,8 +189,8 @@ public class EditMessageLiveLocation extends BotApiMethod<Serializable> {
if (latitude == null) {
throw new TelegramApiValidationException("Latitude parameter can't be empty", this);
}
if (longitud == null) {
throw new TelegramApiValidationException("Longitud parameter can't be empty", this);
if (longitude == null) {
throw new TelegramApiValidationException("Longitude parameter can't be empty", this);
}
if (replyMarkup != null) {
replyMarkup.validate();
@ -185,7 +204,7 @@ public class EditMessageLiveLocation extends BotApiMethod<Serializable> {
", messageId=" + messageId +
", inlineMessageId='" + inlineMessageId + '\'' +
", latitude=" + latitude +
", longitud=" + longitud +
", longitude=" + longitude +
", replyMarkup=" + replyMarkup +
'}';
}

View File

@ -153,7 +153,7 @@ public class EditMessageMedia extends PartialBotApiMethod<Serializable> {
}
}
if (media == null) {
throw new TelegramApiValidationException("Text parameter can't be empty", this);
throw new TelegramApiValidationException("Media parameter can't be empty", this);
}
media.validate();

View File

@ -38,7 +38,7 @@ public class Chat implements BotApiObject {
* so a signed 64 bit integer or double-precision float type are safe for storing this identifier.
*/
@JsonProperty(ID_FIELD)
private Long id; ///< Unique identifier for this chat, not exciding 1e13 by absolute value
private Long id; ///< Unique identifier for this chat, not exceeding 1e13 by absolute value
@JsonProperty(TYPE_FIELD)
private String type; ///< Type of the chat, one of private, group or channel
@JsonProperty(TITLE_FIELD)

View File

@ -4,6 +4,8 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
import java.time.Instant;
/**
* @author Ruben Bermudez
* @version 1.0
@ -33,7 +35,7 @@ public class ChatMember implements BotApiObject {
@JsonProperty(STATUS_FIELD)
private String status; ///< The member's status in the chat. Can be creator, administrator, member, restricted, left or kicked
@JsonProperty(UNTILDATE_FIELD)
private Integer untilDate; ///< Optional. Resticted and kicked only. Date when restrictions will be lifted for this user, unix time
private Integer untilDate; ///< Optional. Restricted and kicked only. Date when restrictions will be lifted for this user, unix time
@JsonProperty(CANBEEDITED_FIELD)
private Boolean canBeEdited; ///< Optional. Administrators only. True, if the bot is allowed to edit administrator privileges of that user
@JsonProperty(CANCHANGEINFORMATION_FIELD)
@ -51,7 +53,7 @@ public class ChatMember implements BotApiObject {
@JsonProperty(CANPINMESSAGES_FIELD)
private Boolean canPinMessages; ///< Optional. Administrators only. True, if the administrator can pin messages
@JsonProperty(CANPROMOTEMEMBERS_FIELD)
private Boolean canPromoteMembers; ///< Optional. Administrators only. True, if the administrator can add new administrators with a subset of his own privileges or demote administrators that it has promoted, directly or indirectly (promoted by administators that were appointed by the bot)
private Boolean canPromoteMembers; ///< Optional. Administrators only. True, if the administrator can add new administrators with a subset of his own privileges or demote administrators that it has promoted, directly or indirectly (promoted by administrators that were appointed by the bot)
@JsonProperty(CANSENDMESSAGES_FIELD)
private Boolean canSendMessages; ///< Optional. Restricted only. True, if the user can send text messages, contacts, locations and venues
@JsonProperty(CANSENDMEDIAMESSAGES_FIELD)
@ -77,6 +79,13 @@ public class ChatMember implements BotApiObject {
return untilDate;
}
public Instant getUntilDateAsInstant() {
if (untilDate == null) {
return null;
}
return Instant.ofEpochSecond(untilDate);
}
public Boolean getCanBeEdited() {
return canBeEdited;
}

View File

@ -27,7 +27,7 @@ public class PhotoSize implements BotApiObject {
@JsonProperty(FILESIZE_FIELD)
private Integer fileSize; ///< Optional. File size
@JsonProperty(FILEPATH_FIELD)
private String filePath; ///< Undocumented field. Optional. Can contain the path to download the file direclty without calling to getFile
private String filePath; ///< Undocumented field. Optional. Can contain the path to download the file directly without calling to getFile
public PhotoSize() {
super();

View File

@ -189,7 +189,7 @@ public class InlineQueryResultVenue implements InlineQueryResult {
throw new TelegramApiValidationException("Longitude parameter can't be empty", this);
}
if (address == null || address.isEmpty()) {
throw new TelegramApiValidationException("Longitude parameter can't be empty", this);
throw new TelegramApiValidationException("Address parameter can't be empty", this);
}
if (inputMessageContent != null) {
inputMessageContent.validate();

View File

@ -0,0 +1,135 @@
package org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent;
import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief Represents a link to an mp3 audio file stored on the Telegram servers. By default, this
* audio file will be sent by the user. Alternatively, you can use input_message_content to send a
* message with the specified content instead of the audio.
* @note This will only work in Telegram versions released after 9 April, 2016. Older clients will
* ignore them.
* @date 10 of April of 2016
*/
public class InlineQueryResultCachedAudio implements InlineQueryResult {
private static final String TYPE_FIELD = "type";
private static final String ID_FIELD = "id";
private static final String AUDIO_FILE_ID_FIELD = "audio_file_id";
private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content";
private static final String REPLY_MARKUP_FIELD = "reply_markup";
private static final String CAPTION_FIELD = "caption";
private static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(TYPE_FIELD)
private final String type = "audio"; ///< Type of the result, must be "audio"
@JsonProperty(ID_FIELD)
private String id; ///< Unique identifier of this result
@JsonProperty(AUDIO_FILE_ID_FIELD)
private String audioFileId; ///< A valid file identifier for the audio file
@JsonProperty(INPUTMESSAGECONTENT_FIELD)
private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the audio
@JsonProperty(REPLY_MARKUP_FIELD)
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
@JsonProperty(CAPTION_FIELD)
private String caption; ///< Optional. Audio caption (may also be used when resending documents by file_id), 0-200 characters
@JsonProperty(PARSEMODE_FIELD)
private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
public InlineQueryResultCachedAudio() {
super();
}
public String getType() {
return type;
}
public String getId() {
return id;
}
public InlineQueryResultCachedAudio setId(String id) {
this.id = id;
return this;
}
public String getAudioFileId() {
return audioFileId;
}
public InlineQueryResultCachedAudio setAudioFileId(String audioFileId) {
this.audioFileId = audioFileId;
return this;
}
public InputMessageContent getInputMessageContent() {
return inputMessageContent;
}
public InlineQueryResultCachedAudio setInputMessageContent(InputMessageContent inputMessageContent) {
this.inputMessageContent = inputMessageContent;
return this;
}
public InlineKeyboardMarkup getReplyMarkup() {
return replyMarkup;
}
public InlineQueryResultCachedAudio setReplyMarkup(InlineKeyboardMarkup replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
public String getCaption() {
return caption;
}
public InlineQueryResultCachedAudio setCaption(String caption) {
this.caption = caption;
return this;
}
public String getParseMode() {
return parseMode;
}
public InlineQueryResultCachedAudio setParseMode(String parseMode) {
this.parseMode = parseMode;
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (id == null || id.isEmpty()) {
throw new TelegramApiValidationException("ID parameter can't be empty", this);
}
if (audioFileId == null || audioFileId.isEmpty()) {
throw new TelegramApiValidationException("AudioFileId parameter can't be empty", this);
}
if (inputMessageContent != null) {
inputMessageContent.validate();
}
if (replyMarkup != null) {
replyMarkup.validate();
}
}
@Override
public String toString() {
return "InlineQueryResultCachedAudio{" +
"type='" + type + '\'' +
", id='" + id + '\'' +
", audioFileId='" + audioFileId + '\'' +
", inputMessageContent=" + inputMessageContent +
", replyMarkup=" + replyMarkup +
", caption='" + caption + '\'' +
", parseMode='" + parseMode + '\'' +
'}';
}
}

View File

@ -0,0 +1,164 @@
package org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent;
import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 1.0
* Represents a link to a file stored on the Telegram servers. By default, this file will be
* sent by the user with an optional caption. Alternatively, you can use input_message_content to
* send a message with the specified content instead of the file.
* @note Currently, only pdf-files and zip archives can be sent using this method.
* @note This will only work in Telegram versions released after 9 April, 2016. Older clients will
* ignore them.
*/
public class InlineQueryResultCachedDocument implements InlineQueryResult {
private static final String TYPE_FIELD = "type";
private static final String ID_FIELD = "id";
private static final String TITLE_FIELD = "title";
private static final String DOCUMENT_FILE_ID_FIELD = "document_file_id";
private static final String DESCRIPTION_FIELD = "description";
private static final String CAPTION_FIELD = "caption";
private static final String REPLY_MARKUP_FIELD = "reply_markup";
private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content";
private static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(TYPE_FIELD)
private final String type = "document"; ///< Type of the result, must be "document"
@JsonProperty(ID_FIELD)
private String id; ///< Unique identifier of this result, 1-64 bytes
@JsonProperty(TITLE_FIELD)
private String title; ///< Optional. Title for the result
@JsonProperty(DOCUMENT_FILE_ID_FIELD)
private String documentFileId; ///< A valid file identifier for the file
@JsonProperty(DESCRIPTION_FIELD)
private String description; ///< Optional. Short description of the result
@JsonProperty(CAPTION_FIELD)
private String caption; ///< Optional. Caption of the document to be sent, 0-200 characters
@JsonProperty(REPLY_MARKUP_FIELD)
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
@JsonProperty(INPUTMESSAGECONTENT_FIELD)
private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the file
@JsonProperty(PARSEMODE_FIELD)
private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
public InlineQueryResultCachedDocument() {
super();
}
public String getType() {
return type;
}
public String getId() {
return id;
}
public InlineQueryResultCachedDocument setId(String id) {
this.id = id;
return this;
}
public String getTitle() {
return title;
}
public InlineQueryResultCachedDocument setTitle(String title) {
this.title = title;
return this;
}
public String getDocumentFileId() {
return documentFileId;
}
public InlineQueryResultCachedDocument setDocumentFileId(String documentFileId) {
this.documentFileId = documentFileId;
return this;
}
public String getDescription() {
return description;
}
public InlineQueryResultCachedDocument setDescription(String description) {
this.description = description;
return this;
}
public String getCaption() {
return caption;
}
public InlineQueryResultCachedDocument setCaption(String caption) {
this.caption = caption;
return this;
}
public InlineKeyboardMarkup getReplyMarkup() {
return replyMarkup;
}
public InlineQueryResultCachedDocument setReplyMarkup(InlineKeyboardMarkup replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
public InputMessageContent getInputMessageContent() {
return inputMessageContent;
}
public InlineQueryResultCachedDocument setInputMessageContent(InputMessageContent inputMessageContent) {
this.inputMessageContent = inputMessageContent;
return this;
}
public String getParseMode() {
return parseMode;
}
public InlineQueryResultCachedDocument setParseMode(String parseMode) {
this.parseMode = parseMode;
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (id == null || id.isEmpty()) {
throw new TelegramApiValidationException("ID parameter can't be empty", this);
}
if (documentFileId == null || documentFileId.isEmpty()) {
throw new TelegramApiValidationException("DocumentFileId parameter can't be empty", this);
}
if (title == null || title.isEmpty()) {
throw new TelegramApiValidationException("Title parameter can't be empty", this);
}
if (inputMessageContent != null) {
inputMessageContent.validate();
}
if (replyMarkup != null) {
replyMarkup.validate();
}
}
@Override
public String toString() {
return "InlineQueryResultCachedDocument{" +
"type='" + type + '\'' +
", id='" + id + '\'' +
", title='" + title + '\'' +
", documentFileId='" + documentFileId + '\'' +
", description='" + description + '\'' +
", caption='" + caption + '\'' +
", replyMarkup=" + replyMarkup +
", inputMessageContent=" + inputMessageContent +
", parseMode='" + parseMode + '\'' +
'}';
}
}

View File

@ -0,0 +1,144 @@
package org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent;
import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 1.0
* Represents a link to an animated GIF file stored on the Telegram servers. By default, this
* animated GIF file will be sent by the user with an optional caption. Alternatively, you can use
* input_message_content to send a message with specified content instead of the animation.
*/
public class InlineQueryResultCachedGif implements InlineQueryResult {
private static final String TYPE_FIELD = "type";
private static final String ID_FIELD = "id";
private static final String GIF_FILE_ID_FIELD = "gif_file_id";
private static final String TITLE_FIELD = "title";
private static final String CAPTION_FIELD = "caption";
private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content";
private static final String REPLY_MARKUP_FIELD = "reply_markup";
private static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(TYPE_FIELD)
private final String type = "gif"; ///< Type of the result, must be "gif"
@JsonProperty(ID_FIELD)
private String id; ///< Unique identifier of this result, 1-64 bytes
@JsonProperty(GIF_FILE_ID_FIELD)
private String gifFileId; ///< A valid file identifier for the GIF file
@JsonProperty(TITLE_FIELD)
private String title; ///< Optional. Title for the result
@JsonProperty(CAPTION_FIELD)
private String caption; ///< Optional. Caption of the GIF file to be sent
@JsonProperty(INPUTMESSAGECONTENT_FIELD)
private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the GIF animation
@JsonProperty(REPLY_MARKUP_FIELD)
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
@JsonProperty(PARSEMODE_FIELD)
private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
public InlineQueryResultCachedGif() {
super();
}
public String getType() {
return type;
}
public String getId() {
return id;
}
public InlineQueryResultCachedGif setId(String id) {
this.id = id;
return this;
}
public String getGifFileId() {
return gifFileId;
}
public InlineQueryResultCachedGif setGifFileId(String gifFileId) {
this.gifFileId = gifFileId;
return this;
}
public String getTitle() {
return title;
}
public InlineQueryResultCachedGif setTitle(String title) {
this.title = title;
return this;
}
public String getCaption() {
return caption;
}
public InlineQueryResultCachedGif setCaption(String caption) {
this.caption = caption;
return this;
}
public InputMessageContent getInputMessageContent() {
return inputMessageContent;
}
public InlineQueryResultCachedGif setInputMessageContent(InputMessageContent inputMessageContent) {
this.inputMessageContent = inputMessageContent;
return this;
}
public InlineKeyboardMarkup getReplyMarkup() {
return replyMarkup;
}
public InlineQueryResultCachedGif setReplyMarkup(InlineKeyboardMarkup replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
public String getParseMode() {
return parseMode;
}
public InlineQueryResultCachedGif setParseMode(String parseMode) {
this.parseMode = parseMode;
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (id == null || id.isEmpty()) {
throw new TelegramApiValidationException("ID parameter can't be empty", this);
}
if (gifFileId == null || gifFileId.isEmpty()) {
throw new TelegramApiValidationException("GifFileId parameter can't be empty", this);
}
if (inputMessageContent != null) {
inputMessageContent.validate();
}
if (replyMarkup != null) {
replyMarkup.validate();
}
}
@Override
public String toString() {
return "InlineQueryResultCachedGif{" +
"type='" + type + '\'' +
", id='" + id + '\'' +
", gifFileId='" + gifFileId + '\'' +
", title='" + title + '\'' +
", caption='" + caption + '\'' +
", inputMessageContent=" + inputMessageContent +
", replyMarkup=" + replyMarkup +
", parseMode='" + parseMode + '\'' +
'}';
}
}

View File

@ -0,0 +1,146 @@
package org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent;
import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief Represents a link to a video animation (H.264/MPEG-4 AVC video without sound). By default,
* this animated MPEG-4 file will be sent by the user with optional caption. Alternatively, you can
* use input_message_content to send a message with the specified content instead of the animation.
* @date 01 of January of 2016
*/
public class InlineQueryResultCachedMpeg4Gif implements InlineQueryResult {
private static final String TYPE_FIELD = "type";
private static final String ID_FIELD = "id";
private static final String MPEG4_FILE_ID_FIELD = "mpeg4_file_id";
private static final String TITLE_FIELD = "title";
private static final String CAPTION_FIELD = "caption";
private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content";
private static final String REPLY_MARKUP_FIELD = "reply_markup";
private static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(TYPE_FIELD)
private final String type = "mpeg4_gif"; ///< Type of the result, must be "mpeg4_gif"
@JsonProperty(ID_FIELD)
private String id; ///< Unique identifier of this result, 1-64 bytes
@JsonProperty(MPEG4_FILE_ID_FIELD)
private String mpeg4FileId; ///< A valid file identifier for the MP4 file
@JsonProperty(TITLE_FIELD)
private String title; ///< Optional. Title for the result
@JsonProperty(CAPTION_FIELD)
private String caption; ///< Optional. Caption of the MPEG-4 file to be sent
@JsonProperty(INPUTMESSAGECONTENT_FIELD)
private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the photo
@JsonProperty(REPLY_MARKUP_FIELD)
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
@JsonProperty(PARSEMODE_FIELD)
private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
public InlineQueryResultCachedMpeg4Gif() {
super();
}
public String getType() {
return type;
}
public String getId() {
return id;
}
public InlineQueryResultCachedMpeg4Gif setId(String id) {
this.id = id;
return this;
}
public String getMpeg4FileId() {
return mpeg4FileId;
}
public InlineQueryResultCachedMpeg4Gif setMpeg4FileId(String mpeg4FileId) {
this.mpeg4FileId = mpeg4FileId;
return this;
}
public String getTitle() {
return title;
}
public InlineQueryResultCachedMpeg4Gif setTitle(String title) {
this.title = title;
return this;
}
public String getCaption() {
return caption;
}
public InlineQueryResultCachedMpeg4Gif setCaption(String caption) {
this.caption = caption;
return this;
}
public InputMessageContent getInputMessageContent() {
return inputMessageContent;
}
public InlineQueryResultCachedMpeg4Gif setInputMessageContent(InputMessageContent inputMessageContent) {
this.inputMessageContent = inputMessageContent;
return this;
}
public InlineKeyboardMarkup getReplyMarkup() {
return replyMarkup;
}
public InlineQueryResultCachedMpeg4Gif setReplyMarkup(InlineKeyboardMarkup replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
public String getParseMode() {
return parseMode;
}
public InlineQueryResultCachedMpeg4Gif setParseMode(String parseMode) {
this.parseMode = parseMode;
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (id == null || id.isEmpty()) {
throw new TelegramApiValidationException("ID parameter can't be empty", this);
}
if (mpeg4FileId == null || mpeg4FileId.isEmpty()) {
throw new TelegramApiValidationException("Mpeg4FileId parameter can't be empty", this);
}
if (inputMessageContent != null) {
inputMessageContent.validate();
}
if (replyMarkup != null) {
replyMarkup.validate();
}
}
@Override
public String toString() {
return "InlineQueryResultCachedMpeg4Gif{" +
"type='" + type + '\'' +
", id='" + id + '\'' +
", mpeg4FileId='" + mpeg4FileId + '\'' +
", title='" + title + '\'' +
", caption='" + caption + '\'' +
", inputMessageContent=" + inputMessageContent +
", replyMarkup=" + replyMarkup +
", parseMode='" + parseMode + '\'' +
'}';
}
}

View File

@ -0,0 +1,157 @@
package org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent;
import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 1.0
* Represents a link to a photo stored on the Telegram servers. By default, this photo will
* be sent by the user with an optional caption. Alternatively, you can use input_message_content to
* send a message with the specified content instead of the photo.
*/
public class InlineQueryResultCachedPhoto implements InlineQueryResult {
private static final String TYPE_FIELD = "type";
private static final String ID_FIELD = "id";
private static final String PHOTOFILEID_FIELD = "photo_file_id";
private static final String TITLE_FIELD = "title";
private static final String DESCRIPTION_FIELD = "description";
private static final String CAPTION_FIELD = "caption";
private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content";
private static final String REPLY_MARKUP_FIELD = "reply_markup";
private static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(TYPE_FIELD)
private final String type = "photo"; ///< Type of the result, must be photo
@JsonProperty(ID_FIELD)
private String id; ///< Unique identifier of this result, 1-64 bytes
@JsonProperty(PHOTOFILEID_FIELD)
private String photoFileId; ///< A valid file identifier of the photo
@JsonProperty(TITLE_FIELD)
private String title; ///< Optional. Title for the result
@JsonProperty(DESCRIPTION_FIELD)
private String description; ///< Optional. Short description of the result
@JsonProperty(CAPTION_FIELD)
private String caption; ///< Optional. Caption of the photo to be sent
@JsonProperty(INPUTMESSAGECONTENT_FIELD)
private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the photo
@JsonProperty(REPLY_MARKUP_FIELD)
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
@JsonProperty(PARSEMODE_FIELD)
private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
public InlineQueryResultCachedPhoto() {
super();
}
public String getType() {
return type;
}
public String getId() {
return id;
}
public InlineQueryResultCachedPhoto setId(String id) {
this.id = id;
return this;
}
public String getPhotoFileId() {
return photoFileId;
}
public InlineQueryResultCachedPhoto setPhotoFileId(String photoFileId) {
this.photoFileId = photoFileId;
return this;
}
public String getTitle() {
return title;
}
public InlineQueryResultCachedPhoto setTitle(String title) {
this.title = title;
return this;
}
public String getDescription() {
return description;
}
public InlineQueryResultCachedPhoto setDescription(String description) {
this.description = description;
return this;
}
public String getCaption() {
return caption;
}
public InlineQueryResultCachedPhoto setCaption(String caption) {
this.caption = caption;
return this;
}
public InputMessageContent getInputMessageContent() {
return inputMessageContent;
}
public InlineQueryResultCachedPhoto setInputMessageContent(InputMessageContent inputMessageContent) {
this.inputMessageContent = inputMessageContent;
return this;
}
public InlineKeyboardMarkup getReplyMarkup() {
return replyMarkup;
}
public InlineQueryResultCachedPhoto setReplyMarkup(InlineKeyboardMarkup replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
public String getParseMode() {
return parseMode;
}
public InlineQueryResultCachedPhoto setParseMode(String parseMode) {
this.parseMode = parseMode;
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (id == null || id.isEmpty()) {
throw new TelegramApiValidationException("ID parameter can't be empty", this);
}
if (photoFileId == null || photoFileId.isEmpty()) {
throw new TelegramApiValidationException("PhotoFileId parameter can't be empty", this);
}
if (inputMessageContent != null) {
inputMessageContent.validate();
}
if (replyMarkup != null) {
replyMarkup.validate();
}
}
@Override
public String toString() {
return "InlineQueryResultCachedPhoto{" +
"type='" + type + '\'' +
", id='" + id + '\'' +
", photoFileId='" + photoFileId + '\'' +
", title='" + title + '\'' +
", description='" + description + '\'' +
", caption='" + caption + '\'' +
", inputMessageContent=" + inputMessageContent +
", replyMarkup=" + replyMarkup +
", parseMode='" + parseMode + '\'' +
'}';
}
}

View File

@ -0,0 +1,109 @@
package org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent;
import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief Represents a link to a sticker stored on the Telegram servers. By default, this sticker
* will be sent by the user. Alternatively, you can use input_message_content to send a message with
* the specified content instead of the sticker.
* @note This will only work in Telegram versions released after 9 April, 2016. Older clients will
* ignore them.
* @date 10 of April of 2016
*/
public class InlineQueryResultCachedSticker implements InlineQueryResult {
private static final String TYPE_FIELD = "type";
private static final String ID_FIELD = "id";
private static final String STICKER_FILE_ID_FIELD = "sticker_file_id";
private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content";
private static final String REPLY_MARKUP_FIELD = "reply_markup";
@JsonProperty(TYPE_FIELD)
private final String type = "sticker"; ///< Type of the result, must be "sticker"
@JsonProperty(ID_FIELD)
private String id; ///< Unique identifier of this result, 1-64 bytes
@JsonProperty(STICKER_FILE_ID_FIELD)
private String stickerFileId; ///< A valid file identifier of the sticker
@JsonProperty(INPUTMESSAGECONTENT_FIELD)
private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the sticker
@JsonProperty(REPLY_MARKUP_FIELD)
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
public InlineQueryResultCachedSticker() {
super();
}
public String getType() {
return type;
}
public String getId() {
return id;
}
public InlineQueryResultCachedSticker setId(String id) {
this.id = id;
return this;
}
public String getStickerFileId() {
return stickerFileId;
}
public InlineQueryResultCachedSticker setStickerFileId(String stickerFileId) {
this.stickerFileId = stickerFileId;
return this;
}
public InputMessageContent getInputMessageContent() {
return inputMessageContent;
}
public InlineQueryResultCachedSticker setInputMessageContent(InputMessageContent inputMessageContent) {
this.inputMessageContent = inputMessageContent;
return this;
}
public InlineKeyboardMarkup getReplyMarkup() {
return replyMarkup;
}
public InlineQueryResultCachedSticker setReplyMarkup(InlineKeyboardMarkup replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (id == null || id.isEmpty()) {
throw new TelegramApiValidationException("ID parameter can't be empty", this);
}
if (stickerFileId == null || stickerFileId.isEmpty()) {
throw new TelegramApiValidationException("StickerFileId parameter can't be empty", this);
}
if (inputMessageContent != null) {
inputMessageContent.validate();
}
if (replyMarkup != null) {
replyMarkup.validate();
}
}
@Override
public String toString() {
return "InlineQueryResultCachedSticker{" +
"type='" + type + '\'' +
", id='" + id + '\'' +
", sticker_file_id='" + stickerFileId + '\'' +
", inputMessageContent='" + inputMessageContent + '\'' +
", replyMarkup='" + replyMarkup + '\'' +
'}';
}
}

View File

@ -0,0 +1,157 @@
package org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent;
import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 1.0
* Represents a link to a video file stored on the Telegram servers. By default, this video
* file will be sent by the user with an optional caption. Alternatively, you can use
* input_message_content to send a message with the specified content instead of the video.
*/
public class InlineQueryResultCachedVideo implements InlineQueryResult {
private static final String TYPE_FIELD = "type";
private static final String ID_FIELD = "id";
private static final String VIDEO_FILE_ID_FIELD = "video_file_id";
private static final String TITLE_FIELD = "title";
private static final String DESCRIPTION_FIELD = "description";
private static final String CAPTION_FIELD = "caption";
private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content";
private static final String REPLY_MARKUP_FIELD = "reply_markup";
private static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(TYPE_FIELD)
private final String type = "video"; ///< Type of the result, must be "video"
@JsonProperty(ID_FIELD)
private String id; ///< Unique identifier of this result
@JsonProperty(VIDEO_FILE_ID_FIELD)
private String videoFileId; ///< A valid file identifier for the video file
@JsonProperty(TITLE_FIELD)
private String title; ///< Optional. Title for the result
@JsonProperty(DESCRIPTION_FIELD)
private String description; ///< Optional. Short description of the result
@JsonProperty(CAPTION_FIELD)
private String caption; ///< Optional. Caption of the video to be sent, 0-200 characters
@JsonProperty(INPUTMESSAGECONTENT_FIELD)
private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the photo
@JsonProperty(REPLY_MARKUP_FIELD)
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
@JsonProperty(PARSEMODE_FIELD)
private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
public InlineQueryResultCachedVideo() {
super();
}
public String getType() {
return type;
}
public String getId() {
return id;
}
public InlineQueryResultCachedVideo setId(String id) {
this.id = id;
return this;
}
public String getVideoFileId() {
return videoFileId;
}
public InlineQueryResultCachedVideo setVideoFileId(String videoFileId) {
this.videoFileId = videoFileId;
return this;
}
public String getTitle() {
return title;
}
public InlineQueryResultCachedVideo setTitle(String title) {
this.title = title;
return this;
}
public String getDescription() {
return description;
}
public InlineQueryResultCachedVideo setDescription(String description) {
this.description = description;
return this;
}
public String getCaption() {
return caption;
}
public InlineQueryResultCachedVideo setCaption(String caption) {
this.caption = caption;
return this;
}
public InputMessageContent getInputMessageContent() {
return inputMessageContent;
}
public InlineQueryResultCachedVideo setInputMessageContent(InputMessageContent inputMessageContent) {
this.inputMessageContent = inputMessageContent;
return this;
}
public InlineKeyboardMarkup getReplyMarkup() {
return replyMarkup;
}
public InlineQueryResultCachedVideo setReplyMarkup(InlineKeyboardMarkup replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
public String getParseMode() {
return parseMode;
}
public InlineQueryResultCachedVideo setParseMode(String parseMode) {
this.parseMode = parseMode;
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (id == null || id.isEmpty()) {
throw new TelegramApiValidationException("ID parameter can't be empty", this);
}
if (videoFileId == null || videoFileId.isEmpty()) {
throw new TelegramApiValidationException("VideoFileId parameter can't be empty", this);
}
if (inputMessageContent != null) {
inputMessageContent.validate();
}
if (replyMarkup != null) {
replyMarkup.validate();
}
}
@Override
public String toString() {
return "InlineQueryResultCachedVideo{" +
"type='" + type + '\'' +
", id='" + id + '\'' +
", videoFileId='" + videoFileId + '\'' +
", title='" + title + '\'' +
", description='" + description + '\'' +
", caption='" + caption + '\'' +
", inputMessageContent=" + inputMessageContent +
", replyMarkup=" + replyMarkup +
", parseMode='" + parseMode + '\'' +
'}';
}
}

View File

@ -0,0 +1,146 @@
package org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent;
import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 1.0
* Represents a link to a voice message stored on the Telegram servers. By default, this
* voice message will be sent by the user. Alternatively, you can use input_message_content to send
* a message with the specified content instead of the voice message.
* @note This will only work in Telegram versions released after 9 April, 2016. Older clients will
* ignore them.
*/
public class InlineQueryResultCachedVoice implements InlineQueryResult {
private static final String TYPE_FIELD = "type";
private static final String ID_FIELD = "id";
private static final String VOICE_FILE_ID_FIELD = "voice_file_id";
private static final String TITLE_FIELD = "title";
private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content";
private static final String REPLY_MARKUP_FIELD = "reply_markup";
private static final String CAPTION_FIELD = "caption";
private static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(TYPE_FIELD)
private final String type = "voice"; ///< Type of the result, must be "voice"
@JsonProperty(ID_FIELD)
private String id; ///< Unique identifier of this result, 1-64 bytes
@JsonProperty(VOICE_FILE_ID_FIELD)
private String voiceFileId; ///< A valid file identifier for the voice message
@JsonProperty(TITLE_FIELD)
private String title; ///< Recording title
@JsonProperty(INPUTMESSAGECONTENT_FIELD)
private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the voice recording
@JsonProperty(REPLY_MARKUP_FIELD)
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
@JsonProperty(CAPTION_FIELD)
private String caption; ///< Optional. Voice caption (may also be used when resending documents by file_id), 0-200 characters
@JsonProperty(PARSEMODE_FIELD)
private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
public InlineQueryResultCachedVoice() {
super();
}
public String getType() {
return type;
}
public String getId() {
return id;
}
public InlineQueryResultCachedVoice setId(String id) {
this.id = id;
return this;
}
public String getVoiceFileId() {
return voiceFileId;
}
public InlineQueryResultCachedVoice setVoiceFileId(String voiceFileId) {
this.voiceFileId = voiceFileId;
return this;
}
public String getTitle() {
return title;
}
public InlineQueryResultCachedVoice setTitle(String title) {
this.title = title;
return this;
}
public InputMessageContent getInputMessageContent() {
return inputMessageContent;
}
public InlineQueryResultCachedVoice setInputMessageContent(InputMessageContent inputMessageContent) {
this.inputMessageContent = inputMessageContent;
return this;
}
public InlineKeyboardMarkup getReplyMarkup() {
return replyMarkup;
}
public InlineQueryResultCachedVoice setReplyMarkup(InlineKeyboardMarkup replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
public String getCaption() {
return caption;
}
public InlineQueryResultCachedVoice setCaption(String caption) {
this.caption = caption;
return this;
}
public String getParseMode() {
return parseMode;
}
public InlineQueryResultCachedVoice setParseMode(String parseMode) {
this.parseMode = parseMode;
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (id == null || id.isEmpty()) {
throw new TelegramApiValidationException("ID parameter can't be empty", this);
}
if (voiceFileId == null || voiceFileId.isEmpty()) {
throw new TelegramApiValidationException("VoiceFileId parameter can't be empty", this);
}
if (inputMessageContent != null) {
inputMessageContent.validate();
}
if (replyMarkup != null) {
replyMarkup.validate();
}
}
@Override
public String toString() {
return "InlineQueryResultCachedVoice{" +
"type='" + type + '\'' +
", id='" + id + '\'' +
", voiceFileId='" + voiceFileId + '\'' +
", title='" + title + '\'' +
", inputMessageContent=" + inputMessageContent +
", replyMarkup=" + replyMarkup +
", caption='" + caption + '\'' +
", parseMode='" + parseMode + '\'' +
'}';
}
}

View File

@ -1,135 +1,15 @@
package org.telegram.telegrambots.meta.api.objects.inlinequery.result.chached;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent;
import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief Represents a link to an mp3 audio file stored on the Telegram servers. By default, this
* Represents a link to an mp3 audio file stored on the Telegram servers. By default, this
* audio file will be sent by the user. Alternatively, you can use input_message_content to send a
* message with the specified content instead of the audio.
* @note This will only work in Telegram versions released after 9 April, 2016. Older clients will
* ignore them.
* @date 10 of April of 2016
* @deprecated Replaced by {@link org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedAudio}
*/
public class InlineQueryResultCachedAudio implements InlineQueryResult {
private static final String TYPE_FIELD = "type";
private static final String ID_FIELD = "id";
private static final String AUDIO_FILE_ID_FIELD = "audio_file_id";
private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content";
private static final String REPLY_MARKUP_FIELD = "reply_markup";
private static final String CAPTION_FIELD = "caption";
private static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(TYPE_FIELD)
private final String type = "audio"; ///< Type of the result, must be "audio"
@JsonProperty(ID_FIELD)
private String id; ///< Unique identifier of this result
@JsonProperty(AUDIO_FILE_ID_FIELD)
private String audioFileId; ///< A valid file identifier for the audio file
@JsonProperty(INPUTMESSAGECONTENT_FIELD)
private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the audio
@JsonProperty(REPLY_MARKUP_FIELD)
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
@JsonProperty(CAPTION_FIELD)
private String caption; ///< Optional. Audio caption (may also be used when resending documents by file_id), 0-200 characters
@JsonProperty(PARSEMODE_FIELD)
private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
public InlineQueryResultCachedAudio() {
super();
}
public String getType() {
return type;
}
public String getId() {
return id;
}
public InlineQueryResultCachedAudio setId(String id) {
this.id = id;
return this;
}
public String getAudioFileId() {
return audioFileId;
}
public InlineQueryResultCachedAudio setAudioFileId(String audioFileId) {
this.audioFileId = audioFileId;
return this;
}
public InputMessageContent getInputMessageContent() {
return inputMessageContent;
}
public InlineQueryResultCachedAudio setInputMessageContent(InputMessageContent inputMessageContent) {
this.inputMessageContent = inputMessageContent;
return this;
}
public InlineKeyboardMarkup getReplyMarkup() {
return replyMarkup;
}
public InlineQueryResultCachedAudio setReplyMarkup(InlineKeyboardMarkup replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
public String getCaption() {
return caption;
}
public InlineQueryResultCachedAudio setCaption(String caption) {
this.caption = caption;
return this;
}
public String getParseMode() {
return parseMode;
}
public InlineQueryResultCachedAudio setParseMode(String parseMode) {
this.parseMode = parseMode;
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (id == null || id.isEmpty()) {
throw new TelegramApiValidationException("ID parameter can't be empty", this);
}
if (audioFileId == null || audioFileId.isEmpty()) {
throw new TelegramApiValidationException("AudioFileId parameter can't be empty", this);
}
if (inputMessageContent != null) {
inputMessageContent.validate();
}
if (replyMarkup != null) {
replyMarkup.validate();
}
}
@Override
public String toString() {
return "InlineQueryResultCachedAudio{" +
"type='" + type + '\'' +
", id='" + id + '\'' +
", audioFileId='" + audioFileId + '\'' +
", inputMessageContent=" + inputMessageContent +
", replyMarkup=" + replyMarkup +
", caption='" + caption + '\'' +
", parseMode='" + parseMode + '\'' +
'}';
}
@Deprecated
public class InlineQueryResultCachedAudio extends org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedAudio {
}

View File

@ -1,12 +1,5 @@
package org.telegram.telegrambots.meta.api.objects.inlinequery.result.chached;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent;
import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 1.0
@ -16,149 +9,8 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
* @note Currently, only pdf-files and zip archives can be sent using this method.
* @note This will only work in Telegram versions released after 9 April, 2016. Older clients will
* ignore them.
* @deprecated Replaced by {@link org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedDocument}
*/
public class InlineQueryResultCachedDocument implements InlineQueryResult {
private static final String TYPE_FIELD = "type";
private static final String ID_FIELD = "id";
private static final String TITLE_FIELD = "title";
private static final String DOCUMENT_FILE_ID_FIELD = "document_file_id";
private static final String DESCRIPTION_FIELD = "description";
private static final String CAPTION_FIELD = "caption";
private static final String REPLY_MARKUP_FIELD = "reply_markup";
private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content";
private static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(TYPE_FIELD)
private final String type = "document"; ///< Type of the result, must be "document"
@JsonProperty(ID_FIELD)
private String id; ///< Unique identifier of this result, 1-64 bytes
@JsonProperty(TITLE_FIELD)
private String title; ///< Optional. Title for the result
@JsonProperty(DOCUMENT_FILE_ID_FIELD)
private String documentFileId; ///< A valid file identifier for the file
@JsonProperty(DESCRIPTION_FIELD)
private String description; ///< Optional. Short description of the result
@JsonProperty(CAPTION_FIELD)
private String caption; ///< Optional. Caption of the document to be sent, 0-200 characters
@JsonProperty(REPLY_MARKUP_FIELD)
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
@JsonProperty(INPUTMESSAGECONTENT_FIELD)
private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the file
@JsonProperty(PARSEMODE_FIELD)
private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
public InlineQueryResultCachedDocument() {
super();
}
public String getType() {
return type;
}
public String getId() {
return id;
}
public InlineQueryResultCachedDocument setId(String id) {
this.id = id;
return this;
}
public String getTitle() {
return title;
}
public InlineQueryResultCachedDocument setTitle(String title) {
this.title = title;
return this;
}
public String getDocumentFileId() {
return documentFileId;
}
public InlineQueryResultCachedDocument setDocumentFileId(String documentFileId) {
this.documentFileId = documentFileId;
return this;
}
public String getDescription() {
return description;
}
public InlineQueryResultCachedDocument setDescription(String description) {
this.description = description;
return this;
}
public String getCaption() {
return caption;
}
public InlineQueryResultCachedDocument setCaption(String caption) {
this.caption = caption;
return this;
}
public InlineKeyboardMarkup getReplyMarkup() {
return replyMarkup;
}
public InlineQueryResultCachedDocument setReplyMarkup(InlineKeyboardMarkup replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
public InputMessageContent getInputMessageContent() {
return inputMessageContent;
}
public InlineQueryResultCachedDocument setInputMessageContent(InputMessageContent inputMessageContent) {
this.inputMessageContent = inputMessageContent;
return this;
}
public String getParseMode() {
return parseMode;
}
public InlineQueryResultCachedDocument setParseMode(String parseMode) {
this.parseMode = parseMode;
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (id == null || id.isEmpty()) {
throw new TelegramApiValidationException("ID parameter can't be empty", this);
}
if (documentFileId == null || documentFileId.isEmpty()) {
throw new TelegramApiValidationException("DocumentFileId parameter can't be empty", this);
}
if (title == null || title.isEmpty()) {
throw new TelegramApiValidationException("Title parameter can't be empty", this);
}
if (inputMessageContent != null) {
inputMessageContent.validate();
}
if (replyMarkup != null) {
replyMarkup.validate();
}
}
@Override
public String toString() {
return "InlineQueryResultCachedDocument{" +
"type='" + type + '\'' +
", id='" + id + '\'' +
", title='" + title + '\'' +
", documentFileId='" + documentFileId + '\'' +
", description='" + description + '\'' +
", caption='" + caption + '\'' +
", replyMarkup=" + replyMarkup +
", inputMessageContent=" + inputMessageContent +
", parseMode='" + parseMode + '\'' +
'}';
}
@Deprecated
public class InlineQueryResultCachedDocument extends org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedDocument {
}

View File

@ -1,144 +1,13 @@
package org.telegram.telegrambots.meta.api.objects.inlinequery.result.chached;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent;
import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 1.0
* Represents a link to an animated GIF file stored on the Telegram servers. By default, this
* animated GIF file will be sent by the user with an optional caption. Alternatively, you can use
* input_message_content to send a message with specified content instead of the animation.
* @deprecated Replaced by {@link org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedGif}
*/
public class InlineQueryResultCachedGif implements InlineQueryResult {
private static final String TYPE_FIELD = "type";
private static final String ID_FIELD = "id";
private static final String GIF_FILE_ID_FIELD = "gif_file_id";
private static final String TITLE_FIELD = "title";
private static final String CAPTION_FIELD = "caption";
private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content";
private static final String REPLY_MARKUP_FIELD = "reply_markup";
private static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(TYPE_FIELD)
private final String type = "gif"; ///< Type of the result, must be "gif"
@JsonProperty(ID_FIELD)
private String id; ///< Unique identifier of this result, 1-64 bytes
@JsonProperty(GIF_FILE_ID_FIELD)
private String gifFileId; ///< A valid file identifier for the GIF file
@JsonProperty(TITLE_FIELD)
private String title; ///< Optional. Title for the result
@JsonProperty(CAPTION_FIELD)
private String caption; ///< Optional. Caption of the GIF file to be sent
@JsonProperty(INPUTMESSAGECONTENT_FIELD)
private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the GIF animation
@JsonProperty(REPLY_MARKUP_FIELD)
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
@JsonProperty(PARSEMODE_FIELD)
private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
public InlineQueryResultCachedGif() {
super();
}
public String getType() {
return type;
}
public String getId() {
return id;
}
public InlineQueryResultCachedGif setId(String id) {
this.id = id;
return this;
}
public String getGifFileId() {
return gifFileId;
}
public InlineQueryResultCachedGif setGifFileId(String gifFileId) {
this.gifFileId = gifFileId;
return this;
}
public String getTitle() {
return title;
}
public InlineQueryResultCachedGif setTitle(String title) {
this.title = title;
return this;
}
public String getCaption() {
return caption;
}
public InlineQueryResultCachedGif setCaption(String caption) {
this.caption = caption;
return this;
}
public InputMessageContent getInputMessageContent() {
return inputMessageContent;
}
public InlineQueryResultCachedGif setInputMessageContent(InputMessageContent inputMessageContent) {
this.inputMessageContent = inputMessageContent;
return this;
}
public InlineKeyboardMarkup getReplyMarkup() {
return replyMarkup;
}
public InlineQueryResultCachedGif setReplyMarkup(InlineKeyboardMarkup replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
public String getParseMode() {
return parseMode;
}
public InlineQueryResultCachedGif setParseMode(String parseMode) {
this.parseMode = parseMode;
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (id == null || id.isEmpty()) {
throw new TelegramApiValidationException("ID parameter can't be empty", this);
}
if (gifFileId == null || gifFileId.isEmpty()) {
throw new TelegramApiValidationException("GifFileId parameter can't be empty", this);
}
if (inputMessageContent != null) {
inputMessageContent.validate();
}
if (replyMarkup != null) {
replyMarkup.validate();
}
}
@Override
public String toString() {
return "InlineQueryResultCachedGif{" +
"type='" + type + '\'' +
", id='" + id + '\'' +
", gifFileId='" + gifFileId + '\'' +
", title='" + title + '\'' +
", caption='" + caption + '\'' +
", inputMessageContent=" + inputMessageContent +
", replyMarkup=" + replyMarkup +
", parseMode='" + parseMode + '\'' +
'}';
}
@Deprecated
public class InlineQueryResultCachedGif extends org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedGif {
}

View File

@ -1,146 +1,13 @@
package org.telegram.telegrambots.meta.api.objects.inlinequery.result.chached;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent;
import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief Represents a link to a video animation (H.264/MPEG-4 AVC video without sound). By default,
* Represents a link to a video animation (H.264/MPEG-4 AVC video without sound). By default,
* this animated MPEG-4 file will be sent by the user with optional caption. Alternatively, you can
* use input_message_content to send a message with the specified content instead of the animation.
* @date 01 of January of 2016
* @deprecated Replaced by {@link org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedMpeg4Gif}
*/
public class InlineQueryResultCachedMpeg4Gif implements InlineQueryResult {
private static final String TYPE_FIELD = "type";
private static final String ID_FIELD = "id";
private static final String MPEG4_FILE_ID_FIELD = "mpeg4_file_id";
private static final String TITLE_FIELD = "title";
private static final String CAPTION_FIELD = "caption";
private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content";
private static final String REPLY_MARKUP_FIELD = "reply_markup";
private static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(TYPE_FIELD)
private final String type = "mpeg4_gif"; ///< Type of the result, must be "mpeg4_gif"
@JsonProperty(ID_FIELD)
private String id; ///< Unique identifier of this result, 1-64 bytes
@JsonProperty(MPEG4_FILE_ID_FIELD)
private String mpeg4FileId; ///< A valid file identifier for the MP4 file
@JsonProperty(TITLE_FIELD)
private String title; ///< Optional. Title for the result
@JsonProperty(CAPTION_FIELD)
private String caption; ///< Optional. Caption of the MPEG-4 file to be sent
@JsonProperty(INPUTMESSAGECONTENT_FIELD)
private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the photo
@JsonProperty(REPLY_MARKUP_FIELD)
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
@JsonProperty(PARSEMODE_FIELD)
private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
public InlineQueryResultCachedMpeg4Gif() {
super();
}
public String getType() {
return type;
}
public String getId() {
return id;
}
public InlineQueryResultCachedMpeg4Gif setId(String id) {
this.id = id;
return this;
}
public String getMpeg4FileId() {
return mpeg4FileId;
}
public InlineQueryResultCachedMpeg4Gif setMpeg4FileId(String mpeg4FileId) {
this.mpeg4FileId = mpeg4FileId;
return this;
}
public String getTitle() {
return title;
}
public InlineQueryResultCachedMpeg4Gif setTitle(String title) {
this.title = title;
return this;
}
public String getCaption() {
return caption;
}
public InlineQueryResultCachedMpeg4Gif setCaption(String caption) {
this.caption = caption;
return this;
}
public InputMessageContent getInputMessageContent() {
return inputMessageContent;
}
public InlineQueryResultCachedMpeg4Gif setInputMessageContent(InputMessageContent inputMessageContent) {
this.inputMessageContent = inputMessageContent;
return this;
}
public InlineKeyboardMarkup getReplyMarkup() {
return replyMarkup;
}
public InlineQueryResultCachedMpeg4Gif setReplyMarkup(InlineKeyboardMarkup replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
public String getParseMode() {
return parseMode;
}
public InlineQueryResultCachedMpeg4Gif setParseMode(String parseMode) {
this.parseMode = parseMode;
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (id == null || id.isEmpty()) {
throw new TelegramApiValidationException("ID parameter can't be empty", this);
}
if (mpeg4FileId == null || mpeg4FileId.isEmpty()) {
throw new TelegramApiValidationException("Mpeg4FileId parameter can't be empty", this);
}
if (inputMessageContent != null) {
inputMessageContent.validate();
}
if (replyMarkup != null) {
replyMarkup.validate();
}
}
@Override
public String toString() {
return "InlineQueryResultCachedMpeg4Gif{" +
"type='" + type + '\'' +
", id='" + id + '\'' +
", mpeg4FileId='" + mpeg4FileId + '\'' +
", title='" + title + '\'' +
", caption='" + caption + '\'' +
", inputMessageContent=" + inputMessageContent +
", replyMarkup=" + replyMarkup +
", parseMode='" + parseMode + '\'' +
'}';
}
@Deprecated
public class InlineQueryResultCachedMpeg4Gif extends org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedMpeg4Gif {
}

View File

@ -1,157 +1,13 @@
package org.telegram.telegrambots.meta.api.objects.inlinequery.result.chached;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent;
import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 1.0
* Represents a link to a photo stored on the Telegram servers. By default, this photo will
* be sent by the user with an optional caption. Alternatively, you can use input_message_content to
* send a message with the specified content instead of the photo.
* @deprecated Replaced by {@link org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedPhoto}
*/
public class InlineQueryResultCachedPhoto implements InlineQueryResult {
private static final String TYPE_FIELD = "type";
private static final String ID_FIELD = "id";
private static final String PHOTOFILEID_FIELD = "photo_file_id";
private static final String TITLE_FIELD = "title";
private static final String DESCRIPTION_FIELD = "description";
private static final String CAPTION_FIELD = "caption";
private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content";
private static final String REPLY_MARKUP_FIELD = "reply_markup";
private static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(TYPE_FIELD)
private final String type = "photo"; ///< Type of the result, must be photo
@JsonProperty(ID_FIELD)
private String id; ///< Unique identifier of this result, 1-64 bytes
@JsonProperty(PHOTOFILEID_FIELD)
private String photoFileId; ///< A valid file identifier of the photo
@JsonProperty(TITLE_FIELD)
private String title; ///< Optional. Title for the result
@JsonProperty(DESCRIPTION_FIELD)
private String description; ///< Optional. Short description of the result
@JsonProperty(CAPTION_FIELD)
private String caption; ///< Optional. Caption of the photo to be sent
@JsonProperty(INPUTMESSAGECONTENT_FIELD)
private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the photo
@JsonProperty(REPLY_MARKUP_FIELD)
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
@JsonProperty(PARSEMODE_FIELD)
private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
public InlineQueryResultCachedPhoto() {
super();
}
public String getType() {
return type;
}
public String getId() {
return id;
}
public InlineQueryResultCachedPhoto setId(String id) {
this.id = id;
return this;
}
public String getPhotoFileId() {
return photoFileId;
}
public InlineQueryResultCachedPhoto setPhotoFileId(String photoFileId) {
this.photoFileId = photoFileId;
return this;
}
public String getTitle() {
return title;
}
public InlineQueryResultCachedPhoto setTitle(String title) {
this.title = title;
return this;
}
public String getDescription() {
return description;
}
public InlineQueryResultCachedPhoto setDescription(String description) {
this.description = description;
return this;
}
public String getCaption() {
return caption;
}
public InlineQueryResultCachedPhoto setCaption(String caption) {
this.caption = caption;
return this;
}
public InputMessageContent getInputMessageContent() {
return inputMessageContent;
}
public InlineQueryResultCachedPhoto setInputMessageContent(InputMessageContent inputMessageContent) {
this.inputMessageContent = inputMessageContent;
return this;
}
public InlineKeyboardMarkup getReplyMarkup() {
return replyMarkup;
}
public InlineQueryResultCachedPhoto setReplyMarkup(InlineKeyboardMarkup replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
public String getParseMode() {
return parseMode;
}
public InlineQueryResultCachedPhoto setParseMode(String parseMode) {
this.parseMode = parseMode;
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (id == null || id.isEmpty()) {
throw new TelegramApiValidationException("ID parameter can't be empty", this);
}
if (photoFileId == null || photoFileId.isEmpty()) {
throw new TelegramApiValidationException("PhotoFileId parameter can't be empty", this);
}
if (inputMessageContent != null) {
inputMessageContent.validate();
}
if (replyMarkup != null) {
replyMarkup.validate();
}
}
@Override
public String toString() {
return "InlineQueryResultCachedPhoto{" +
"type='" + type + '\'' +
", id='" + id + '\'' +
", photoFileId='" + photoFileId + '\'' +
", title='" + title + '\'' +
", description='" + description + '\'' +
", caption='" + caption + '\'' +
", inputMessageContent=" + inputMessageContent +
", replyMarkup=" + replyMarkup +
", parseMode='" + parseMode + '\'' +
'}';
}
@Deprecated
public class InlineQueryResultCachedPhoto extends org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedPhoto {
}

View File

@ -1,109 +1,16 @@
package org.telegram.telegrambots.meta.api.objects.inlinequery.result.chached;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent;
import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief Represents a link to a sticker stored on the Telegram servers. By default, this sticker
* Represents a link to a sticker stored on the Telegram servers. By default, this sticker
* will be sent by the user. Alternatively, you can use input_message_content to send a message with
* the specified content instead of the sticker.
* @note This will only work in Telegram versions released after 9 April, 2016. Older clients will
* ignore them.
* @date 10 of April of 2016
* @deprecated Replaced by {@link org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedSticker}
*/
public class InlineQueryResultCachedSticker implements InlineQueryResult {
@Deprecated
public class InlineQueryResultCachedSticker extends org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedSticker {
private static final String TYPE_FIELD = "type";
private static final String ID_FIELD = "id";
private static final String STICKER_FILE_ID_FIELD = "sticker_file_id";
private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content";
private static final String REPLY_MARKUP_FIELD = "reply_markup";
@JsonProperty(TYPE_FIELD)
private final String type = "sticker"; ///< Type of the result, must be "sticker"
@JsonProperty(ID_FIELD)
private String id; ///< Unique identifier of this result, 1-64 bytes
@JsonProperty(STICKER_FILE_ID_FIELD)
private String stickerFileId; ///< A valid file identifier of the sticker
@JsonProperty(INPUTMESSAGECONTENT_FIELD)
private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the sticker
@JsonProperty(REPLY_MARKUP_FIELD)
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
public InlineQueryResultCachedSticker() {
super();
}
public String getType() {
return type;
}
public String getId() {
return id;
}
public InlineQueryResultCachedSticker setId(String id) {
this.id = id;
return this;
}
public String getStickerFileId() {
return stickerFileId;
}
public InlineQueryResultCachedSticker setStickerFileId(String stickerFileId) {
this.stickerFileId = stickerFileId;
return this;
}
public InputMessageContent getInputMessageContent() {
return inputMessageContent;
}
public InlineQueryResultCachedSticker setInputMessageContent(InputMessageContent inputMessageContent) {
this.inputMessageContent = inputMessageContent;
return this;
}
public InlineKeyboardMarkup getReplyMarkup() {
return replyMarkup;
}
public InlineQueryResultCachedSticker setReplyMarkup(InlineKeyboardMarkup replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (id == null || id.isEmpty()) {
throw new TelegramApiValidationException("ID parameter can't be empty", this);
}
if (stickerFileId == null || stickerFileId.isEmpty()) {
throw new TelegramApiValidationException("StickerFileId parameter can't be empty", this);
}
if (inputMessageContent != null) {
inputMessageContent.validate();
}
if (replyMarkup != null) {
replyMarkup.validate();
}
}
@Override
public String toString() {
return "InlineQueryResultCachedSticker{" +
"type='" + type + '\'' +
", id='" + id + '\'' +
", sticker_file_id='" + stickerFileId + '\'' +
", inputMessageContent='" + inputMessageContent + '\'' +
", replyMarkup='" + replyMarkup + '\'' +
'}';
}
}

View File

@ -1,157 +1,13 @@
package org.telegram.telegrambots.meta.api.objects.inlinequery.result.chached;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent;
import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 1.0
* Represents a link to a video file stored on the Telegram servers. By default, this video
* file will be sent by the user with an optional caption. Alternatively, you can use
* input_message_content to send a message with the specified content instead of the video.
* @deprecated Replaced by {@link org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedVideo}
*/
public class InlineQueryResultCachedVideo implements InlineQueryResult {
private static final String TYPE_FIELD = "type";
private static final String ID_FIELD = "id";
private static final String VIDEO_FILE_ID_FIELD = "video_file_id";
private static final String TITLE_FIELD = "title";
private static final String DESCRIPTION_FIELD = "description";
private static final String CAPTION_FIELD = "caption";
private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content";
private static final String REPLY_MARKUP_FIELD = "reply_markup";
private static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(TYPE_FIELD)
private final String type = "video"; ///< Type of the result, must be "video"
@JsonProperty(ID_FIELD)
private String id; ///< Unique identifier of this result
@JsonProperty(VIDEO_FILE_ID_FIELD)
private String videoFileId; ///< A valid file identifier for the video file
@JsonProperty(TITLE_FIELD)
private String title; ///< Optional. Title for the result
@JsonProperty(DESCRIPTION_FIELD)
private String description; ///< Optional. Short description of the result
@JsonProperty(CAPTION_FIELD)
private String caption; ///< Optional. Caption of the video to be sent, 0-200 characters
@JsonProperty(INPUTMESSAGECONTENT_FIELD)
private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the photo
@JsonProperty(REPLY_MARKUP_FIELD)
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
@JsonProperty(PARSEMODE_FIELD)
private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
public InlineQueryResultCachedVideo() {
super();
}
public String getType() {
return type;
}
public String getId() {
return id;
}
public InlineQueryResultCachedVideo setId(String id) {
this.id = id;
return this;
}
public String getVideoFileId() {
return videoFileId;
}
public InlineQueryResultCachedVideo setVideoFileId(String videoFileId) {
this.videoFileId = videoFileId;
return this;
}
public String getTitle() {
return title;
}
public InlineQueryResultCachedVideo setTitle(String title) {
this.title = title;
return this;
}
public String getDescription() {
return description;
}
public InlineQueryResultCachedVideo setDescription(String description) {
this.description = description;
return this;
}
public String getCaption() {
return caption;
}
public InlineQueryResultCachedVideo setCaption(String caption) {
this.caption = caption;
return this;
}
public InputMessageContent getInputMessageContent() {
return inputMessageContent;
}
public InlineQueryResultCachedVideo setInputMessageContent(InputMessageContent inputMessageContent) {
this.inputMessageContent = inputMessageContent;
return this;
}
public InlineKeyboardMarkup getReplyMarkup() {
return replyMarkup;
}
public InlineQueryResultCachedVideo setReplyMarkup(InlineKeyboardMarkup replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
public String getParseMode() {
return parseMode;
}
public InlineQueryResultCachedVideo setParseMode(String parseMode) {
this.parseMode = parseMode;
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (id == null || id.isEmpty()) {
throw new TelegramApiValidationException("ID parameter can't be empty", this);
}
if (videoFileId == null || videoFileId.isEmpty()) {
throw new TelegramApiValidationException("VideoFileId parameter can't be empty", this);
}
if (inputMessageContent != null) {
inputMessageContent.validate();
}
if (replyMarkup != null) {
replyMarkup.validate();
}
}
@Override
public String toString() {
return "InlineQueryResultCachedVideo{" +
"type='" + type + '\'' +
", id='" + id + '\'' +
", videoFileId='" + videoFileId + '\'' +
", title='" + title + '\'' +
", description='" + description + '\'' +
", caption='" + caption + '\'' +
", inputMessageContent=" + inputMessageContent +
", replyMarkup=" + replyMarkup +
", parseMode='" + parseMode + '\'' +
'}';
}
@Deprecated
public class InlineQueryResultCachedVideo extends org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedVideo {
}

View File

@ -1,12 +1,5 @@
package org.telegram.telegrambots.meta.api.objects.inlinequery.result.chached;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputMessageContent;
import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 1.0
@ -15,132 +8,8 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
* a message with the specified content instead of the voice message.
* @note This will only work in Telegram versions released after 9 April, 2016. Older clients will
* ignore them.
* @deprecated Replaced by {@link org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedVoice}
*/
public class InlineQueryResultCachedVoice implements InlineQueryResult {
private static final String TYPE_FIELD = "type";
private static final String ID_FIELD = "id";
private static final String VOICE_FILE_ID_FIELD = "voice_file_id";
private static final String TITLE_FIELD = "title";
private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content";
private static final String REPLY_MARKUP_FIELD = "reply_markup";
private static final String CAPTION_FIELD = "caption";
private static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(TYPE_FIELD)
private final String type = "voice"; ///< Type of the result, must be "voice"
@JsonProperty(ID_FIELD)
private String id; ///< Unique identifier of this result, 1-64 bytes
@JsonProperty(VOICE_FILE_ID_FIELD)
private String voiceFileId; ///< A valid file identifier for the voice message
@JsonProperty(TITLE_FIELD)
private String title; ///< Recording title
@JsonProperty(INPUTMESSAGECONTENT_FIELD)
private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the voice recording
@JsonProperty(REPLY_MARKUP_FIELD)
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
@JsonProperty(CAPTION_FIELD)
private String caption; ///< Optional. Voice caption (may also be used when resending documents by file_id), 0-200 characters
@JsonProperty(PARSEMODE_FIELD)
private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
public InlineQueryResultCachedVoice() {
super();
}
public String getType() {
return type;
}
public String getId() {
return id;
}
public InlineQueryResultCachedVoice setId(String id) {
this.id = id;
return this;
}
public String getVoiceFileId() {
return voiceFileId;
}
public InlineQueryResultCachedVoice setVoiceFileId(String voiceFileId) {
this.voiceFileId = voiceFileId;
return this;
}
public String getTitle() {
return title;
}
public InlineQueryResultCachedVoice setTitle(String title) {
this.title = title;
return this;
}
public InputMessageContent getInputMessageContent() {
return inputMessageContent;
}
public InlineQueryResultCachedVoice setInputMessageContent(InputMessageContent inputMessageContent) {
this.inputMessageContent = inputMessageContent;
return this;
}
public InlineKeyboardMarkup getReplyMarkup() {
return replyMarkup;
}
public InlineQueryResultCachedVoice setReplyMarkup(InlineKeyboardMarkup replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
public String getCaption() {
return caption;
}
public InlineQueryResultCachedVoice setCaption(String caption) {
this.caption = caption;
return this;
}
public String getParseMode() {
return parseMode;
}
public InlineQueryResultCachedVoice setParseMode(String parseMode) {
this.parseMode = parseMode;
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (id == null || id.isEmpty()) {
throw new TelegramApiValidationException("ID parameter can't be empty", this);
}
if (voiceFileId == null || voiceFileId.isEmpty()) {
throw new TelegramApiValidationException("VoiceFileId parameter can't be empty", this);
}
if (inputMessageContent != null) {
inputMessageContent.validate();
}
if (replyMarkup != null) {
replyMarkup.validate();
}
}
@Override
public String toString() {
return "InlineQueryResultCachedVoice{" +
"type='" + type + '\'' +
", id='" + id + '\'' +
", voiceFileId='" + voiceFileId + '\'' +
", title='" + title + '\'' +
", inputMessageContent=" + inputMessageContent +
", replyMarkup=" + replyMarkup +
", caption='" + caption + '\'' +
", parseMode='" + parseMode + '\'' +
'}';
}
@Deprecated
public class InlineQueryResultCachedVoice extends org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached.InlineQueryResultCachedVoice {
}

View File

@ -0,0 +1,4 @@
/**
* @deprecated Replaced by {@link org.telegram.telegrambots.meta.api.objects.inlinequery.result.cached}
*/
package org.telegram.telegrambots.meta.api.objects.inlinequery.result.chached;

View File

@ -4,6 +4,7 @@ import org.telegram.telegrambots.meta.api.interfaces.Validable;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.util.ArrayList;
import java.util.List;
/**
* @author Ruben Bermudez
@ -20,6 +21,10 @@ public class KeyboardRow extends ArrayList<KeyboardButton> implements Validable
super.add(index, new KeyboardButton(text));
}
public void addAll(List<String> buttonNames) {
buttonNames.forEach(name -> super.add(new KeyboardButton(name)));
}
public boolean contains(String text) {
return super.contains(new KeyboardButton(text));
}

View File

@ -1,6 +1,7 @@
package org.telegram.telegrambots.meta.api.objects.stickers;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import org.telegram.telegrambots.meta.api.interfaces.InputBotApiObject;
import org.telegram.telegrambots.meta.api.interfaces.Validable;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
@ -10,6 +11,7 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
* @version 3.2
* This object describes the position on faces where a mask should be placed by default.
*/
@JsonTypeInfo(use=JsonTypeInfo.Id.NONE)
public class MaskPosition implements InputBotApiObject, Validable {
private static final String POINT_FIELD = "point";
private static final String XSHIFT_FIELD = "x_shift";

View File

@ -36,7 +36,7 @@ public class Sticker implements BotApiObject {
@JsonProperty(SETNAME_FIELD)
private String setName; ///< Optional. Name of the sticker set to which the sticker belongs
@JsonProperty(MASKPOSITON_FIELD)
private String maskPosition; ///< Optional. For mask stickers, the position where the mask should be placed
private MaskPosition maskPosition; ///< Optional. For mask stickers, the position where the mask should be placed
public Sticker() {
super();
@ -70,7 +70,7 @@ public class Sticker implements BotApiObject {
return setName;
}
public String getMaskPosition() {
public MaskPosition getMaskPosition() {
return maskPosition;
}
@ -84,7 +84,7 @@ public class Sticker implements BotApiObject {
", fileSize=" + fileSize +
", emoji='" + emoji + '\'' +
", setName='" + setName + '\'' +
", maskPosition='" + maskPosition + '\'' +
", maskPosition=" + maskPosition +
'}';
}
}

View File

@ -0,0 +1,34 @@
package org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static java.util.Arrays.asList;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
public class KeyboardRowTest {
private static final List<String> BUTTON_NAMES = asList("Carlotta Valdes", "Jimmy Stewart");
@Test
public void shouldAddAllButtons() {
final KeyboardRow keyboardRow = new KeyboardRow();
keyboardRow.addAll(BUTTON_NAMES);
assertThat(keyboardRow.size(), is(2));
assertThat(keyboardRow.get(0).getText(), is("Carlotta Valdes"));
assertThat(keyboardRow.get(1).getText(), is("Jimmy Stewart"));
}
@Test
public void shouldAddNoButtons() {
final KeyboardRow keyboardRow = new KeyboardRow();
keyboardRow.addAll(new ArrayList<String>());
assertTrue(keyboardRow.isEmpty());
}
}

View File

@ -113,7 +113,7 @@ public class TestAnswerInlineQuery {
try {
answerInlineQuery.validate();
} catch (TelegramApiValidationException e) {
Assert.assertEquals("SwitchPmParameter only allows A-Z, a-z, 0-9 and _ characters", e.getMessage());
Assert.assertEquals("SwitchPmParameter only allows A-Z, a-z, 0-9, _ and - characters", e.getMessage());
}
}
}

View File

@ -18,14 +18,14 @@ Usage
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-spring-boot-starter</artifactId>
<version>4.1</version>
<version>4.1.1</version>
</dependency>
```
**Gradle**
```gradle
compile "org.telegram:telegrambots-spring-boot-starter:4.1"
compile "org.telegram:telegrambots-spring-boot-starter:4.1.1"
```
Motivation
@ -52,7 +52,7 @@ public class YourApplicationMainClass {
After that your bot will look like:
```java
//Standart Spring component annotation
//Standard Spring component annotation
@Component
public class YourBotName extends TelegramLongPollingBot {
//Bot body.

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-spring-boot-starter</artifactId>
<version>4.1</version>
<version>4.1.1</version>
<packaging>jar</packaging>
<name>Telegram Bots Spring Boot Starter</name>
@ -59,7 +59,6 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<bots.version>4.1</bots.version>
<spring-boot.version>2.0.2.RELEASE</spring-boot.version>
</properties>
@ -68,7 +67,7 @@
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>${bots.version}</version>
<version>4.1.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@ -0,0 +1,20 @@
package org.telegram.telegrambots.starter;
import org.telegram.telegrambots.meta.TelegramBotsApi;
import org.telegram.telegrambots.meta.generics.BotSession;
import org.telegram.telegrambots.meta.generics.LongPollingBot;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Indicated that the Method of a Class extending {@link LongPollingBot} will be called after the bot was registered
* If the Method has a single Parameter of type {@link BotSession}, the method get passed the bot session the bot was registered with
* <br><br>
* <p>The bot session passed is the ones returned by {@link TelegramBotsApi#registerBot(LongPollingBot)}</p>
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface AfterBotRegistration {}

View File

@ -1,13 +1,20 @@
package org.telegram.telegrambots.starter;
import java.util.List;
import java.util.Objects;
import org.springframework.beans.factory.InitializingBean;
import org.telegram.telegrambots.meta.TelegramBotsApi;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.meta.generics.BotSession;
import org.telegram.telegrambots.meta.generics.LongPollingBot;
import org.telegram.telegrambots.meta.generics.WebhookBot;
import org.telegram.telegrambots.meta.logging.BotLogger;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;
import static java.lang.String.format;
/**
* Receives all beand which are #LongPollingBot and #WebhookBot and register them in #TelegramBotsApi.
@ -33,7 +40,8 @@ public class TelegramBotInitializer implements InitializingBean {
public void afterPropertiesSet() throws Exception {
try {
for (LongPollingBot bot : longPollingBots) {
telegramBotsApi.registerBot(bot);
BotSession session = telegramBotsApi.registerBot(bot);
handleAfterRegistrationHook(bot, session);
}
for (WebhookBot bot : webHookBots) {
telegramBotsApi.registerBot(bot);
@ -42,4 +50,45 @@ public class TelegramBotInitializer implements InitializingBean {
throw new RuntimeException(e);
}
}
private void handleAnnotatedMethod(Object bot, Method method, BotSession session) {
try {
if (method.getParameterCount() > 1) {
BotLogger.warn(this.getClass().getSimpleName(),
format("Method %s of Type %s has too many parameters",
method.getName(),
method.getDeclaringClass().getCanonicalName()
)
);
return;
}
if (method.getParameterCount() == 0) {
method.invoke(bot);
return;
}
if (method.getParameterTypes()[0].equals(BotSession.class)) {
method.invoke(bot, session);
return;
}
BotLogger.warn(this.getClass().getSimpleName(),
format("Method %s of Type %s has invalid parameter type",
method.getName(),
method.getDeclaringClass().getCanonicalName()
)
);
} catch (InvocationTargetException | IllegalAccessException e) {
BotLogger.error(this.getClass().getSimpleName(),
format("Couldn't invoke Method %s of Type %s",
method.getName(), method.getDeclaringClass().getCanonicalName()
)
);
}
}
private void handleAfterRegistrationHook(Object bot, BotSession botSession) {
Stream.of(bot.getClass().getMethods())
.filter(method -> method.getAnnotation(AfterBotRegistration.class) != null)
.forEach(method -> handleAnnotatedMethod(bot, method, botSession));
}
}

View File

@ -0,0 +1,88 @@
package org.telegram.telegrambots.starter;
import org.junit.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.meta.TelegramBotsApi;
import org.telegram.telegrambots.meta.api.objects.Update;
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.updatesreceivers.DefaultBotSession;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.*;
public class TestTelegramBotStarterRegistrationHooks {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(MockTelegramBotsApi.class, TelegramBotStarterConfiguration.class));
// Terrible workaround for mockito loosing annotations on methods
private static boolean hookCalled = false;
private static boolean hookCalledWithSession = false;
private static final DefaultBotSession someBotSession = new DefaultBotSession();
private static final TelegramBotsApi mockTelegramBotsApi = mock(TelegramBotsApi.class);
@Test
public void longPollingBotWithAnnotatedMethodshouldBeCalled() throws TelegramApiRequestException {
when(mockTelegramBotsApi.registerBot(any(LongPollingBot.class))).thenReturn(someBotSession);
this.contextRunner.withUserConfiguration(LongPollingBotConfig.class)
.run((context) -> {
assertThat(context).hasSingleBean(AnnotatedLongPollingBot.class);
final LongPollingBot bot = context.getBean(LongPollingBot.class);
final TelegramBotsApi telegramBotsApi = context.getBean(TelegramBotsApi.class);
assertThat(hookCalled).isTrue();
assertThat(hookCalledWithSession).isTrue();
verify(telegramBotsApi, times(1)).registerBot(bot);
verifyNoMoreInteractions(telegramBotsApi);
});
}
@Configuration
static class MockTelegramBotsApi{
@Bean
public TelegramBotsApi telegramBotsApi() {
return mockTelegramBotsApi;
}
}
@Configuration
static class LongPollingBotConfig{
@Bean
public LongPollingBot longPollingBot() { return new AnnotatedLongPollingBot(); }
}
static class AnnotatedLongPollingBot extends TelegramLongPollingBot {
@Override
public void onUpdateReceived(final Update update) {}
@Override
public String getBotUsername() { return null; }
@Override
public String getBotToken() { return null; }
@AfterBotRegistration
public void afterBotHook() {
hookCalled = true;
}
@AfterBotRegistration
public void afterBotHookWithSession(BotSession session) {
hookCalledWithSession = session.equals(someBotSession);
}
}
}

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>4.1</version>
<version>4.1.1</version>
<packaging>jar</packaging>
<name>Telegram Bots</name>
@ -62,11 +62,10 @@
<glassfish.version>2.25.1</glassfish.version>
<jerseybundle.version>1.19.3</jerseybundle.version>
<httpcompontents.version>4.5.3</httpcompontents.version>
<json.version>20160810</json.version>
<jackson.version>2.8.7</jackson.version>
<jacksonanotation.version>2.8.0</jacksonanotation.version>
<json.version>20180813</json.version>
<jackson.version>2.9.7</jackson.version>
<jacksonanotation.version>2.9.0</jacksonanotation.version>
<commonio.version>2.5</commonio.version>
<bots.version>4.1</bots.version>
</properties>
<dependencyManagement>
@ -85,7 +84,7 @@
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-meta</artifactId>
<version>${bots.version}</version>
<version>4.1.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>

View File

@ -641,7 +641,7 @@ public abstract class DefaultAbsSender extends AbsSender {
assertParamNotNull(sendAnimation, "sendAnimation");
sendAnimation.validate();
try {
String url = getBaseUrl() + SendVoice.PATH;
String url = getBaseUrl() + SendAnimation.PATH;
HttpPost httppost = configuredHttpPost(url);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setLaxMode();

View File

@ -53,7 +53,7 @@ public final class WebhookUtils {
}
HttpEntity multipart = builder.build();
httppost.setEntity(multipart);
try (CloseableHttpResponse response = httpclient.execute(httppost)) {
try (CloseableHttpResponse response = httpclient.execute(httppost, botOptions.getHttpContext())) {
HttpEntity ht = response.getEntity();
BufferedHttpEntity buf = new BufferedHttpEntity(ht);
String responseContent = EntityUtils.toString(buf, StandardCharsets.UTF_8);

View File

@ -14,7 +14,7 @@ import org.telegram.telegrambots.meta.api.methods.games.SetGameScore;
import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChat;
import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatAdministrators;
import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatMember;
import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatMemberCount;
import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatMembersCount;
import org.telegram.telegrambots.meta.api.methods.groupadministration.KickChatMember;
import org.telegram.telegrambots.meta.api.methods.groupadministration.LeaveChat;
import org.telegram.telegrambots.meta.api.methods.groupadministration.UnbanChatMember;
@ -123,8 +123,8 @@ public final class BotApiMethodHelperFactory {
.setUserId(98765);
}
public static BotApiMethod getChatMemberCount() {
return new GetChatMemberCount()
public static BotApiMethod getChatMembersCount() {
return new GetChatMembersCount()
.setChatId("12345");
}

View File

@ -196,14 +196,14 @@ public class TestRestApi extends JerseyTest {
}
@Test
public void TestGetChatMemberCount() {
webhookBot.setReturnValue(BotApiMethodHelperFactory.getChatMemberCount());
public void TestGetChatMembersCount() {
webhookBot.setReturnValue(BotApiMethodHelperFactory.getChatMembersCount());
Entity<Update> entity = Entity.json(getUpdate());
BotApiMethod result =
target("callback/testbot")
.request(MediaType.APPLICATION_JSON)
.post(entity, GetChatMemberCount.class);
.post(entity, GetChatMembersCount.class);
assertEquals("{\"chat_id\":\"12345\",\"method\":\"getChatMembersCount\"}", map(result));
}