Version 4.0.0

This commit is contained in:
Ruben Bermudez 2018-07-27 00:27:26 +02:00
parent 6c24155bdf
commit a75ca5f08d
62 changed files with 2840 additions and 1775 deletions

115
Bots.ipr
View File

@ -242,6 +242,8 @@
<general>
<show-object-navigation-gutter value="false" />
<show-spec-declaration-navigation-gutter value="true" />
<enable-spellchecking value="true" />
<enable-reference-spellchecking value="false" />
</general>
<confirmations>
<save-changes value="false" />
@ -1154,37 +1156,48 @@
<root url="jar://$MAVEN_REPOSITORY$/org/apache/httpcomponents/httpmime/4.5.3/httpmime-4.5.3-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: org.eclipse.collections:eclipse-collections-api:7.1.1">
<library name="Maven: org.assertj:assertj-core:3.9.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections-api/7.1.1/eclipse-collections-api-7.1.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/assertj/assertj-core/3.9.1/assertj-core-3.9.1.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections-api/7.1.1/eclipse-collections-api-7.1.1-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/assertj/assertj-core/3.9.1/assertj-core-3.9.1-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections-api/7.1.1/eclipse-collections-api-7.1.1-sources.jar!/" />
<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.eclipse.collections:eclipse-collections-forkjoin:7.1.1">
<library name="Maven: org.eclipse.collections:eclipse-collections-api:7.1.2">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections-forkjoin/7.1.1/eclipse-collections-forkjoin-7.1.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections-api/7.1.2/eclipse-collections-api-7.1.2.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections-forkjoin/7.1.1/eclipse-collections-forkjoin-7.1.1-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections-api/7.1.2/eclipse-collections-api-7.1.2-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections-forkjoin/7.1.1/eclipse-collections-forkjoin-7.1.1-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections-api/7.1.2/eclipse-collections-api-7.1.2-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: org.eclipse.collections:eclipse-collections:7.1.1">
<library name="Maven: org.eclipse.collections:eclipse-collections-forkjoin:7.1.2">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections/7.1.1/eclipse-collections-7.1.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections-forkjoin/7.1.2/eclipse-collections-forkjoin-7.1.2.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections/7.1.1/eclipse-collections-7.1.1-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections-forkjoin/7.1.2/eclipse-collections-forkjoin-7.1.2-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections/7.1.1/eclipse-collections-7.1.1-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections-forkjoin/7.1.2/eclipse-collections-forkjoin-7.1.2-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: org.eclipse.collections:eclipse-collections:7.1.2">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections/7.1.2/eclipse-collections-7.1.2.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections/7.1.2/eclipse-collections-7.1.2-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections/7.1.2/eclipse-collections-7.1.2-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: org.glassfish.grizzly:grizzly-framework:2.3.28">
@ -1528,81 +1541,103 @@
<root url="jar://$MAVEN_REPOSITORY$/org/mockito/mockito-all/2.0.2-beta/mockito-all-2.0.2-beta-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: org.springframework.boot:spring-boot-autoconfigure:1.5.10.RELEASE">
<library name="Maven: org.springframework.boot:spring-boot-autoconfigure:2.0.2.RELEASE">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-autoconfigure/1.5.10.RELEASE/spring-boot-autoconfigure-1.5.10.RELEASE.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-autoconfigure/2.0.2.RELEASE/spring-boot-autoconfigure-2.0.2.RELEASE.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-autoconfigure/1.5.10.RELEASE/spring-boot-autoconfigure-1.5.10.RELEASE-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-autoconfigure/2.0.2.RELEASE/spring-boot-autoconfigure-2.0.2.RELEASE-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-autoconfigure/1.5.10.RELEASE/spring-boot-autoconfigure-1.5.10.RELEASE-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-autoconfigure/2.0.2.RELEASE/spring-boot-autoconfigure-2.0.2.RELEASE-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: org.springframework.boot:spring-boot:1.5.10.RELEASE">
<library name="Maven: org.springframework.boot:spring-boot-test:2.0.2.RELEASE">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot/1.5.10.RELEASE/spring-boot-1.5.10.RELEASE.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-test/2.0.2.RELEASE/spring-boot-test-2.0.2.RELEASE.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot/1.5.10.RELEASE/spring-boot-1.5.10.RELEASE-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-test/2.0.2.RELEASE/spring-boot-test-2.0.2.RELEASE-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot/1.5.10.RELEASE/spring-boot-1.5.10.RELEASE-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-test/2.0.2.RELEASE/spring-boot-test-2.0.2.RELEASE-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: org.springframework:spring-aop:4.3.14.RELEASE">
<library name="Maven: org.springframework.boot:spring-boot:2.0.2.RELEASE">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-aop/4.3.14.RELEASE/spring-aop-4.3.14.RELEASE.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot/2.0.2.RELEASE/spring-boot-2.0.2.RELEASE.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-aop/4.3.14.RELEASE/spring-aop-4.3.14.RELEASE-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot/2.0.2.RELEASE/spring-boot-2.0.2.RELEASE-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-aop/4.3.14.RELEASE/spring-aop-4.3.14.RELEASE-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot/2.0.2.RELEASE/spring-boot-2.0.2.RELEASE-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: org.springframework:spring-beans:4.3.14.RELEASE">
<library name="Maven: org.springframework:spring-aop:5.0.6.RELEASE">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-beans/4.3.14.RELEASE/spring-beans-4.3.14.RELEASE.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-aop/5.0.6.RELEASE/spring-aop-5.0.6.RELEASE.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-beans/4.3.14.RELEASE/spring-beans-4.3.14.RELEASE-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-aop/5.0.6.RELEASE/spring-aop-5.0.6.RELEASE-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-beans/4.3.14.RELEASE/spring-beans-4.3.14.RELEASE-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-aop/5.0.6.RELEASE/spring-aop-5.0.6.RELEASE-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: org.springframework:spring-context:4.3.14.RELEASE">
<library name="Maven: org.springframework:spring-beans:5.0.6.RELEASE">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-context/4.3.14.RELEASE/spring-context-4.3.14.RELEASE.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-beans/5.0.6.RELEASE/spring-beans-5.0.6.RELEASE.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-context/4.3.14.RELEASE/spring-context-4.3.14.RELEASE-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-beans/5.0.6.RELEASE/spring-beans-5.0.6.RELEASE-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-context/4.3.14.RELEASE/spring-context-4.3.14.RELEASE-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-beans/5.0.6.RELEASE/spring-beans-5.0.6.RELEASE-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: org.springframework:spring-core:4.3.14.RELEASE">
<library name="Maven: org.springframework:spring-context:5.0.6.RELEASE">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-core/4.3.14.RELEASE/spring-core-4.3.14.RELEASE.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-context/5.0.6.RELEASE/spring-context-5.0.6.RELEASE.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-core/4.3.14.RELEASE/spring-core-4.3.14.RELEASE-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-context/5.0.6.RELEASE/spring-context-5.0.6.RELEASE-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-core/4.3.14.RELEASE/spring-core-4.3.14.RELEASE-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-context/5.0.6.RELEASE/spring-context-5.0.6.RELEASE-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: org.springframework:spring-expression:4.3.14.RELEASE">
<library name="Maven: org.springframework:spring-core:5.0.6.RELEASE">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-expression/4.3.14.RELEASE/spring-expression-4.3.14.RELEASE.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-core/5.0.6.RELEASE/spring-core-5.0.6.RELEASE.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-expression/4.3.14.RELEASE/spring-expression-4.3.14.RELEASE-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-core/5.0.6.RELEASE/spring-core-5.0.6.RELEASE-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-expression/4.3.14.RELEASE/spring-expression-4.3.14.RELEASE-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-core/5.0.6.RELEASE/spring-core-5.0.6.RELEASE-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: org.springframework:spring-expression:5.0.6.RELEASE">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-expression/5.0.6.RELEASE/spring-expression-5.0.6.RELEASE.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-expression/5.0.6.RELEASE/spring-expression-5.0.6.RELEASE-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-expression/5.0.6.RELEASE/spring-expression-5.0.6.RELEASE-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: org.springframework:spring-jcl:5.0.6.RELEASE">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-jcl/5.0.6.RELEASE/spring-jcl-5.0.6.RELEASE.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-jcl/5.0.6.RELEASE/spring-jcl-5.0.6.RELEASE-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-jcl/5.0.6.RELEASE/spring-jcl-5.0.6.RELEASE-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: org.telegram:telegrambots-meta:3.5">

View File

@ -1,3 +1,13 @@
### <a id="4.0.0"></a>4.0.0 ###
1. Support for Api Version [4.0](https://core.telegram.org/bots/api-changelog#july-26-2018)
2. Abilities: Internationalization
3. Socks 5 support
4. Improved spring boot start configuration
5. Removed previously deprecated methods
6. Support usage in Java 9 (library is still using java 8)
**[[How to update to version 4.0.0|How-To-Update#4.0.0]]**
### <a id="3.6.1"></a>3.6.1 ###
1. Support for proxy connections
2. New module for Spring

View File

@ -1,3 +1,9 @@
### <a id="4.0.0"></a>To version 4.0.0 ###
1. Replace removed method from AbsSender with `execute` requests.
2. Everything under "Telegrambots-meta" has been moved to package `org.telegram.telegrambots.meta`.
3. `close` method has been removed from `BotSession`, use `stop` instead.
4. All methods that are intended to upload files are using now `InputMedia` and `InputFile`.
### <a id="2.4.3"></a>To version 2.4.3 ###
1. Replace `BotOptions` by `DefaultBotOptions`.
2. At the beginning of your program (before creating your `TelegramBotsApi` or `Bot` instance, add the following line:

View File

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

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-abilities</artifactId>
<version>3.6.2</version>
<version>4.0.0</version>
<packaging>jar</packaging>
<name>Telegram Ability Bot</name>
@ -65,7 +65,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<bots.version>3.6.2</bots.version>
<bots.version>4.0.0</bots.version>
<commonslang.version>3.5</commonslang.version>
<mapdb.version>3.0.4</mapdb.version>
<guava.version>19.0</guava.version>

View File

@ -92,6 +92,7 @@ import static org.telegram.abilitybots.api.util.AbilityUtils.*;
*
* @author Abbas Abou Daya
*/
@SuppressWarnings({"WeakerAccess", "UnusedReturnValue", "ConfusingArgumentToVarargsMethod", "ConstantConditions"})
public abstract class AbilityBot extends TelegramLongPollingBot {
private static final String TAG = AbilityBot.class.getSimpleName();
@ -413,7 +414,7 @@ public abstract class AbilityBot extends TelegramLongPollingBot {
try (PrintStream printStream = new PrintStream(backup)) {
printStream.print(db.backup());
sender.sendDocument(new SendDocument()
.setNewDocument(backup)
.setDocument(backup)
.setChatId(ctx.chatId())
);
} catch (FileNotFoundException e) {

View File

@ -43,22 +43,22 @@ public class DefaultSender implements MessageSender {
@Override
public Boolean addStickerToSet(AddStickerToSet addStickerToSet) throws TelegramApiException {
return bot.addStickerToSet(addStickerToSet);
return bot.execute(addStickerToSet);
}
@Override
public Boolean createNewStickerSet(CreateNewStickerSet createNewStickerSet) throws TelegramApiException {
return bot.createNewStickerSet(createNewStickerSet);
return bot.execute(createNewStickerSet);
}
@Override
public File uploadStickerFile(UploadStickerFile uploadStickerFile) throws TelegramApiException {
return bot.uploadStickerFile(uploadStickerFile);
return bot.execute(uploadStickerFile);
}
@Override
public Boolean setChatPhoto(SetChatPhoto setChatPhoto) throws TelegramApiException {
return bot.setChatPhoto(setChatPhoto);
return bot.execute(setChatPhoto);
}
@Override
@ -104,36 +104,36 @@ public class DefaultSender implements MessageSender {
@Override
public Message sendDocument(SendDocument sendDocument) throws TelegramApiException {
return bot.sendDocument(sendDocument);
return bot.execute(sendDocument);
}
@Override
public Message sendPhoto(SendPhoto sendPhoto) throws TelegramApiException {
return bot.sendPhoto(sendPhoto);
return bot.execute(sendPhoto);
}
@Override
public Message sendVideo(SendVideo sendVideo) throws TelegramApiException {
return bot.sendVideo(sendVideo);
return bot.execute(sendVideo);
}
@Override
public Message sendSticker(SendSticker sendSticker) throws TelegramApiException {
return bot.sendSticker(sendSticker);
return bot.execute(sendSticker);
}
@Override
public Message sendAudio(SendAudio sendAudio) throws TelegramApiException {
return bot.sendAudio(sendAudio);
return bot.execute(sendAudio);
}
@Override
public Message sendVoice(SendVoice sendVoice) throws TelegramApiException {
return bot.sendVoice(sendVoice);
return bot.execute(sendVoice);
}
@Override
public Message sendVideoNote(SendVideoNote sendVideoNote) throws TelegramApiException {
public Message sendVideoNote(SendVideoNote sendVideoNote) {
return null;
}
}

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.telegram</groupId>
<artifactId>telegrambotsextensions</artifactId>
<version>3.6.2</version>
<version>4.0.0</version>
<packaging>jar</packaging>
<name>Telegram Bots Extensions</name>
@ -59,7 +59,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<bots.version>3.6.2</bots.version>
<bots.version>4.0.0</bots.version>
</properties>
<dependencies>

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-meta</artifactId>
<version>3.6.2</version>
<version>4.0.0</version>
<packaging>jar</packaging>
<name>Telegram Bots Meta</name>

View File

@ -0,0 +1,100 @@
package org.telegram.telegrambots.meta.api.methods;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.meta.api.objects.passport.dataerror.PassportElementError;
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.ArrayList;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 4.0.0
*
* Informs a user that some Telegram Passport data contains errors.
* The user will not be able to resend data, until the errors are fixed
*/
public class SetPassportDataErrors extends BotApiMethod<Boolean> {
public static final String PATH = "setPassportDataErrors";
private static final String USERID_FIELD = "user_id";
private static final String ERRORS_FIELD = "errors";
@JsonProperty(USERID_FIELD)
private Integer userId; ///< User identifier
@JsonProperty(ERRORS_FIELD)
private List<PassportElementError> errors; ///< A JSON-serialized array describing the errors
public SetPassportDataErrors(Integer userId, List<PassportElementError> errors) {
super();
this.userId = checkNotNull(userId);
this.errors = checkNotNull(errors);
}
public SetPassportDataErrors() {
super();
}
public Integer getUserId() {
return userId;
}
public SetPassportDataErrors setUserId(Integer userId) {
this.userId = userId;
return this;
}
public List<PassportElementError> getErrors() {
return errors;
}
public SetPassportDataErrors setErrors(List<PassportElementError> errors) {
this.errors = errors;
return this;
}
public SetPassportDataErrors addError(PassportElementError error) {
error = checkNotNull(error);
if (this.errors == null) {
this.errors = new ArrayList<>();
}
this.errors.add(error);
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 setting passport data errors", result);
}
} catch (IOException e) {
throw new TelegramApiRequestException("Unable to deserialize response", e);
}
}
@Override
public void validate() throws TelegramApiValidationException {
if (userId == null) {
throw new TelegramApiValidationException("User ID can't be empty", this);
}
if (errors == null || errors.isEmpty()) {
throw new TelegramApiValidationException("Errors can't be empty", this);
}
}
}

View File

@ -0,0 +1,247 @@
package org.telegram.telegrambots.meta.api.methods.send;
import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod;
import org.telegram.telegrambots.meta.api.objects.InputFile;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;
/**
* @author Ruben Bermudez
* @version 4.0.0
* Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound).
* On success, the sent Message is returned.
*
* Bots can currently send animation files of up to 50 MB in size, this limit may be changed in the future.
*/
public class SendAnimation extends PartialBotApiMethod<Message> {
public static final String PATH = "sendAnimation";
public static final String CHATID_FIELD = "chat_id";
public static final String ANIMATION_FIELD = "animation";
public static final String DURATION_FIELD = "duration";
public static final String WIDTH_FIELD = "width";
public static final String HEIGHT_FIELD = "height";
public static final String CAPTION_FIELD = "caption";
public static final String PARSEMODE_FIELD = "parse_mode";
public static final String DISABLENOTIFICATION_FIELD = "disable_notification";
public static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
public static final String REPLYMARKUP_FIELD = "reply_markup";
public static final String THUMB_FIELD = "thumb";
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
/**
* Animation to send. Pass a file_id as String to send an animation that exists on the
* Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get an animation
* from the Internet, or upload a new animation using multipart/form-data.
*/
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 Integer width; ///< Optional. Animation width
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
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.
/**
* Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size.
* A thumbnails width and height should not exceed 90.
* Ignored if the file is not uploaded using multipart/form-data.
* Thumbnails cant be reused and can be only uploaded as a new file, so you can pass attach://<file_attach_name>
* if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
*/
private InputFile thumb;
public SendAnimation() {
super();
}
public String getChatId() {
return chatId;
}
public SendAnimation setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public InputFile getAnimation() {
return animation;
}
public SendAnimation setAnimation(String animation) {
this.animation = new InputFile(animation);
return this;
}
public SendAnimation setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
public Integer getDuration() {
return duration;
}
public SendAnimation setDuration(Integer duration) {
this.duration = duration;
return this;
}
public String getCaption() {
return caption;
}
public SendAnimation setCaption(String caption) {
this.caption = caption;
return this;
}
public Integer getReplyToMessageId() {
return replyToMessageId;
}
public SendAnimation setReplyToMessageId(Integer replyToMessageId) {
this.replyToMessageId = replyToMessageId;
return this;
}
public ReplyKeyboard getReplyMarkup() {
return replyMarkup;
}
public SendAnimation setReplyMarkup(ReplyKeyboard replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
public Boolean getDisableNotification() {
return disableNotification;
}
public SendAnimation enableNotification() {
this.disableNotification = false;
return this;
}
public SendAnimation disableNotification() {
this.disableNotification = true;
return this;
}
public Integer getWidth() {
return width;
}
public SendAnimation setWidth(Integer width) {
this.width = width;
return this;
}
public Integer getHeight() {
return height;
}
public SendAnimation setHeight(Integer height) {
this.height = height;
return this;
}
public SendAnimation setAnimation(File file) {
this.animation = new InputFile(file, file.getName());
return this;
}
public SendAnimation setAnimation(String animationName, InputStream inputStream) {
Objects.requireNonNull(animationName, "animationName cannot be null!");
Objects.requireNonNull(inputStream, "inputStream cannot be null!");
this.animation = new InputFile(inputStream, animationName);
return this;
}
public SendAnimation setAnimation(InputFile animation) {
Objects.requireNonNull(animation, "animation cannot be null!");
this.animation = animation;
return this;
}
public String getParseMode() {
return parseMode;
}
public SendAnimation setParseMode(String parseMode) {
this.parseMode = parseMode;
return this;
}
public InputFile getThumb() {
return thumb;
}
public SendAnimation setThumb(InputFile thumb) {
this.thumb = thumb;
return this;
}
@Override
public Message deserializeResponse(String answer) throws TelegramApiRequestException {
try {
ApiResponse<Message> result = OBJECT_MAPPER.readValue(answer,
new TypeReference<ApiResponse<Message>>(){});
if (result.getOk()) {
return result.getResult();
} else {
throw new TelegramApiRequestException("Error sending animation", result);
}
} catch (IOException e) {
throw new TelegramApiRequestException("Unable to deserialize response", e);
}
}
@Override
public void validate() throws TelegramApiValidationException {
if (chatId == null) {
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
}
if (animation == null) {
throw new TelegramApiValidationException("Animation parameter can't be empty", this);
}
animation.validate();
if (replyMarkup != null) {
replyMarkup.validate();
}
if (thumb != null) {
thumb.validate();
}
}
@Override
public String toString() {
return "SendAnimation{" + "chatId='" + chatId + '\'' +
", animation=" + animation +
", duration=" + duration +
", caption='" + caption + '\'' +
", width=" + width +
", height=" + height +
", disableNotification=" + disableNotification +
", replyToMessageId=" + replyToMessageId +
", replyMarkup=" + replyMarkup +
", parseMode='" + parseMode + '\'' +
", thumb=" + thumb +
'}';
}
}

View File

@ -1,8 +1,8 @@
package org.telegram.telegrambots.meta.api.methods.send;
import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod;
import org.telegram.telegrambots.meta.api.objects.InputFile;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard;
@ -36,11 +36,11 @@ public class SendAudio extends PartialBotApiMethod<Message> {
public static final String TITLE_FIELD = "title";
public static final String CAPTION_FIELD = "caption";
public static final String PARSEMODE_FIELD = "parse_mode";
public static final String THUMB_FIELD = "thumb";
private Integer duration; ///< Integer Duration of the audio in seconds as defined by sender
private String chatId; ///< Unique identifier for the chat to send the message to (or Username fro channels)
private String audio; ///< Audio file to send. file_id as String to resend an audio that is already on the Telegram servers or Url to upload it
private InputFile audio; ///< Audio file to send. file_id as String to resend an audio that is already on the Telegram servers or Url to upload it
private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message
private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
@ -48,11 +48,14 @@ public class SendAudio extends PartialBotApiMethod<Message> {
private String title; ///< Optional. Title of sent audio
private String caption; ///< Optional. Audio caption (may also be used when resending documents by file_id), 0-200 characters
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.
private boolean isNewAudio; ///< True to upload a new audio, false to use a fileId
private String audioName;
private File newAudioFile; ///< New audio file
private InputStream newAudioStream; ///< New audio stream
/**
* Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size.
* A thumbnails width and height should not exceed 90.
* Ignored if the file is not uploaded using multipart/form-data.
* Thumbnails cant be reused and can be only uploaded as a new file, so you can pass
* attach://<file_attach_name> if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
*/
private InputFile thumb;
public SendAudio() {
super();
@ -82,7 +85,7 @@ public class SendAudio extends PartialBotApiMethod<Message> {
return this;
}
public String getAudio() {
public InputFile getAudio() {
return audio;
}
@ -93,8 +96,7 @@ public class SendAudio extends PartialBotApiMethod<Message> {
* @note The file_id must have already been received or sent by your bot
*/
public SendAudio setAudio(String audio) {
this.audio = audio;
this.isNewAudio = false;
this.audio = new InputFile(audio);
return this;
}
@ -103,18 +105,22 @@ public class SendAudio extends PartialBotApiMethod<Message> {
*
* @param file New audio file
*/
public SendAudio setNewAudio(File file) {
this.isNewAudio = true;
this.newAudioFile = file;
public SendAudio setAudio(File file) {
Objects.requireNonNull(file, "file cannot be null!");
this.audio = new InputFile(file, file.getName());
return this;
}
public SendAudio setNewAudio(String audioName, InputStream inputStream) {
public SendAudio setAudio(String audioName, InputStream inputStream) {
Objects.requireNonNull(audioName, "audioName cannot be null!");
Objects.requireNonNull(inputStream, "inputStream cannot be null!");
this.audioName = audioName;
this.isNewAudio = true;
this.newAudioStream = inputStream;
this.audio = new InputFile(inputStream, audioName);
return this;
}
public SendAudio setAudio(InputFile audio) {
Objects.requireNonNull(audio, "audio cannot be null!");
this.audio = audio;
return this;
}
@ -168,22 +174,6 @@ public class SendAudio extends PartialBotApiMethod<Message> {
return this;
}
public boolean isNewAudio() {
return isNewAudio;
}
public String getAudioName() {
return audioName;
}
public File getNewAudioFile() {
return newAudioFile;
}
public InputStream getNewAudioStream() {
return newAudioStream;
}
public String getCaption() {
return caption;
}
@ -202,6 +192,15 @@ public class SendAudio extends PartialBotApiMethod<Message> {
return this;
}
public InputFile getThumb() {
return thumb;
}
public SendAudio setThumb(InputFile thumb) {
this.thumb = thumb;
return this;
}
@Override
public Message deserializeResponse(String answer) throws TelegramApiRequestException {
try {
@ -223,15 +222,14 @@ public class SendAudio extends PartialBotApiMethod<Message> {
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
}
if (isNewAudio) {
if (newAudioFile == null && newAudioStream == null) {
throw new TelegramApiValidationException("Audio can't be empty", this);
}
if (newAudioStream != null && (audioName == null || audioName.isEmpty())) {
throw new TelegramApiValidationException("Audio name can't be empty", this);
}
} else if (audio == null) {
throw new TelegramApiValidationException("Audio can't be empty", this);
if (audio == null) {
throw new TelegramApiValidationException("Audio parameter can't be empty", this);
}
audio.validate();
if (thumb != null) {
thumb.validate();
}
if (replyMarkup != null) {
@ -244,7 +242,7 @@ public class SendAudio extends PartialBotApiMethod<Message> {
return "SendAudio{" +
"duration=" + duration +
", chatId='" + chatId + '\'' +
", audio='" + audio + '\'' +
", audio=" + audio +
", replyToMessageId=" + replyToMessageId +
", disableNotification=" + disableNotification +
", replyMarkup=" + replyMarkup +
@ -252,10 +250,7 @@ public class SendAudio extends PartialBotApiMethod<Message> {
", title='" + title + '\'' +
", caption='" + caption + '\'' +
", parseMode='" + parseMode + '\'' +
", isNewAudio=" + isNewAudio +
", audioName='" + audioName + '\'' +
", newAudioFile=" + newAudioFile +
", newAudioStream=" + newAudioStream +
", thumb=" + thumb +
'}';
}
}

View File

@ -16,9 +16,8 @@ import java.util.Objects;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief Use this method to send information about user contact. On success, the sent Message is
* Use this method to send information about user contact. On success, the sent Message is
* returned.
* @date 10 of April of 2016
*/
public class SendContact extends BotApiMethod<Message> {
public static final String PATH = "sendContact";
@ -30,6 +29,7 @@ public class SendContact extends BotApiMethod<Message> {
private static final String DISABLENOTIFICATION_FIELD = "disable_notification";
private static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
private static final String REPLYMARKUP_FIELD = "reply_markup";
private static final String VCARD_FIELD = "vcard";
@JsonProperty(CHATID_FIELD)
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
@ -45,6 +45,8 @@ public class SendContact extends BotApiMethod<Message> {
private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message
@JsonProperty(REPLYMARKUP_FIELD)
private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
@JsonProperty(VCARD_FIELD)
private String vCard; ///< Optional. Additional data about the contact in the form of a vCard
public SendContact() {
super();
@ -124,6 +126,14 @@ public class SendContact extends BotApiMethod<Message> {
return this;
}
public String getvCard() {
return vCard;
}
public void setvCard(String vCard) {
this.vCard = vCard;
}
@Override
public String getMethod() {
return PATH;
@ -164,11 +174,13 @@ public class SendContact extends BotApiMethod<Message> {
public String toString() {
return "SendContact{" +
"chatId='" + chatId + '\'' +
", phoneNumber=" + phoneNumber +
", firstName=" + firstName +
", lastName=" + lastName +
", phoneNumber='" + phoneNumber + '\'' +
", firstName='" + firstName + '\'' +
", lastName='" + lastName + '\'' +
", disableNotification=" + disableNotification +
", replyToMessageId=" + replyToMessageId +
", replyMarkup=" + replyMarkup +
", vCard='" + vCard + '\'' +
'}';
}
}

View File

@ -1,8 +1,8 @@
package org.telegram.telegrambots.meta.api.methods.send;
import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod;
import org.telegram.telegrambots.meta.api.objects.InputFile;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard;
@ -29,19 +29,23 @@ public class SendDocument extends PartialBotApiMethod<Message> {
public static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
public static final String REPLYMARKUP_FIELD = "reply_markup";
public static final String PARSEMODE_FIELD = "parse_mode";
public static final String THUMB_FIELD = "thumb";
private String chatId; ///< Unique identifier for the chat to send the message to or Username for the channel to send the message to
private String document; ///< File file to send. file_id as String to resend a file that is already on the Telegram servers or Url to upload it
private InputFile document; ///< File file to send. file_id as String to resend a file that is already on the Telegram servers or Url to upload it
private String caption; ///< Optional. Document caption (may also be used when resending documents by file_id), 0-200 characters
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
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.
private boolean isNewDocument; ///< True to upload a new document, false to use a fileId
private String documentName;
private File newDocumentFile; ///< New document file
private InputStream newDocumentStream; ///< New document stream
/**
* Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size.
* A thumbnails width and height should not exceed 90.
* Ignored if the file is not uploaded using multipart/form-data.
* Thumbnails cant be reused and can be only uploaded as a new file, so you can pass attach://<file_attach_name>
* if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
*/
private InputFile thumb;
public SendDocument() {
super();
@ -62,7 +66,7 @@ public class SendDocument extends PartialBotApiMethod<Message> {
return this;
}
public String getDocument() {
public InputFile getDocument() {
return document;
}
@ -73,8 +77,7 @@ public class SendDocument extends PartialBotApiMethod<Message> {
* @note The file_id must have already been received or sent by your bot
*/
public SendDocument setDocument(String document) {
this.document = document;
this.isNewDocument = false;
this.document = new InputFile(document);
return this;
}
@ -83,38 +86,25 @@ public class SendDocument extends PartialBotApiMethod<Message> {
*
* @param file New document file
*/
public SendDocument setNewDocument(File file) {
public SendDocument setDocument(File file) {
Objects.requireNonNull(file, "documentName cannot be null!");
this.isNewDocument = true;
this.newDocumentFile = file;
this.document = new InputFile(file, file.getName());
return this;
}
public SendDocument setNewDocument(String documentName, InputStream inputStream) {
public SendDocument setDocument(InputFile document) {
Objects.requireNonNull(document, "document cannot be null!");
this.document = document;
return this;
}
public SendDocument setDocument(String documentName, InputStream inputStream) {
Objects.requireNonNull(documentName, "documentName cannot be null!");
Objects.requireNonNull(inputStream, "inputStream cannot be null!");
this.documentName = documentName;
this.isNewDocument = true;
this.newDocumentStream = inputStream;
this.document = new InputFile(inputStream, documentName);
return this;
}
public boolean isNewDocument() {
return isNewDocument;
}
public String getDocumentName() {
return documentName;
}
public File getNewDocumentFile() {
return newDocumentFile;
}
public InputStream getNewDocumentStream() {
return newDocumentStream;
}
public Integer getReplyToMessageId() {
return replyToMessageId;
}
@ -165,6 +155,15 @@ public class SendDocument extends PartialBotApiMethod<Message> {
return this;
}
public InputFile getThumb() {
return thumb;
}
public SendDocument setThumb(InputFile thumb) {
this.thumb = thumb;
return this;
}
@Override
public Message deserializeResponse(String answer) throws TelegramApiRequestException {
try {
@ -186,15 +185,14 @@ public class SendDocument extends PartialBotApiMethod<Message> {
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
}
if (isNewDocument) {
if (newDocumentFile == null && newDocumentStream == null) {
throw new TelegramApiValidationException("Document can't be empty", this);
}
if (newDocumentStream != null && (documentName == null || documentName.isEmpty())) {
throw new TelegramApiValidationException("Document name can't be empty", this);
}
} else if (document == null) {
throw new TelegramApiValidationException("Document can't be empty", this);
if (document == null) {
throw new TelegramApiValidationException("Document parameter can't be empty", this);
}
document.validate();
if (thumb != null) {
thumb.validate();
}
if (replyMarkup != null) {
@ -206,16 +204,13 @@ public class SendDocument extends PartialBotApiMethod<Message> {
public String toString() {
return "SendDocument{" +
"chatId='" + chatId + '\'' +
", document='" + document + '\'' +
", document=" + document +
", caption='" + caption + '\'' +
", disableNotification=" + disableNotification +
", replyToMessageId=" + replyToMessageId +
", replyMarkup=" + replyMarkup +
", parseMode='" + parseMode + '\'' +
", isNewDocument=" + isNewDocument +
", documentName='" + documentName + '\'' +
", newDocumentFile=" + newDocumentFile +
", newDocumentStream=" + newDocumentStream +
", thumb=" + thumb +
'}';
}
}

View File

@ -5,6 +5,8 @@ import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.media.InputMedia;
import org.telegram.telegrambots.meta.api.objects.media.InputMediaPhoto;
import org.telegram.telegrambots.meta.api.objects.media.InputMediaVideo;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ApiResponse;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
@ -34,7 +36,7 @@ public class SendMediaGroup extends PartialBotApiMethod<ArrayList<Message>> {
@JsonProperty(CHATID_FIELD)
private String chatId; ///< Unique identifier for the target chat or username of the target channel (in the format @channelusername)
@JsonProperty(MEDIA_FIELD)
private List<InputMedia> media; ///< A JSON-serialized array describing photos and videos to be sent
private List<InputMedia> media; ///< A JSON-serialized array describing photos and videos to be sent, must include 210 items
@JsonProperty(REPLYTOMESSAGEID_FIELD)
private Integer replyToMessageId; ///< Optional. If the messages are a reply, ID of the original message
@JsonProperty(DISABLENOTIFICATION_FIELD)
@ -128,7 +130,11 @@ public class SendMediaGroup extends PartialBotApiMethod<ArrayList<Message>> {
}
for (InputMedia inputMedia : media) {
inputMedia.validate();
if (inputMedia instanceof InputMediaPhoto || inputMedia instanceof InputMediaVideo) {
inputMedia.validate();
} else {
throw new TelegramApiValidationException("Media parameter can only be Photo or Video", this);
}
}
}

View File

@ -1,8 +1,8 @@
package org.telegram.telegrambots.meta.api.methods.send;
import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod;
import org.telegram.telegrambots.meta.api.objects.InputFile;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard;
@ -31,18 +31,13 @@ public class SendPhoto extends PartialBotApiMethod<Message> {
public static final String PARSEMODE_FIELD = "parse_mode";
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
private String photo; ///< Photo to send. file_id as String to resend a photo that is already on the Telegram servers or URL to upload it
private InputFile photo; ///< Photo to send. file_id as String to resend a photo that is already on the Telegram servers or URL to upload it
private String caption; ///< Optional Photo caption (may also be used when resending photos by file_id).
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
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.
private boolean isNewPhoto; ///< True if the photo must be uploaded from a file, file if it is a fileId
private String photoName; ///< Name of the photo
private File newPhotoFile; // New photo file
private InputStream newPhotoStream; // New photo stream
public SendPhoto() {
super();
}
@ -62,13 +57,12 @@ public class SendPhoto extends PartialBotApiMethod<Message> {
return this;
}
public String getPhoto() {
public InputFile getPhoto() {
return photo;
}
public SendPhoto setPhoto(String photo) {
this.photo = photo;
this.isNewPhoto = false;
this.photo = new InputFile(photo);
return this;
}
@ -99,22 +93,6 @@ public class SendPhoto extends PartialBotApiMethod<Message> {
return this;
}
public boolean isNewPhoto() {
return isNewPhoto;
}
public String getPhotoName() {
return photoName;
}
public File getNewPhotoFile() {
return newPhotoFile;
}
public InputStream getNewPhotoStream() {
return newPhotoStream;
}
public Boolean getDisableNotification() {
return disableNotification;
}
@ -129,18 +107,22 @@ public class SendPhoto extends PartialBotApiMethod<Message> {
return this;
}
public SendPhoto setNewPhoto(File file) {
this.newPhotoFile = file;
this.isNewPhoto = true;
public SendPhoto setPhoto(File file) {
Objects.requireNonNull(file, "file cannot be null!");
this.photo = new InputFile(file, file.getName());
return this;
}
public SendPhoto setNewPhoto(String photoName, InputStream inputStream) {
public SendPhoto setPhoto(InputFile photo) {
Objects.requireNonNull(photo, "photo cannot be null!");
this.photo = photo;
return this;
}
public SendPhoto setPhoto(String photoName, InputStream inputStream) {
Objects.requireNonNull(photoName, "photoName cannot be null!");
Objects.requireNonNull(inputStream, "inputStream cannot be null!");
this.photoName = photoName;
this.newPhotoStream = inputStream;
this.isNewPhoto = true;
this.photo = new InputFile(inputStream, photoName);
return this;
}
@ -174,16 +156,12 @@ public class SendPhoto extends PartialBotApiMethod<Message> {
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
}
if (isNewPhoto) {
if (newPhotoFile == null && newPhotoStream == null) {
throw new TelegramApiValidationException("Photo can't be empty", this);
}
if (newPhotoStream != null && (photoName == null || photoName.isEmpty())) {
throw new TelegramApiValidationException("Photo name can't be empty", this);
}
} else if (photo == null) {
throw new TelegramApiValidationException("Photo can't be empty", this);
if (photo == null) {
throw new TelegramApiValidationException("Photo parameter can't be empty", this);
}
photo.validate();
if (replyMarkup != null) {
replyMarkup.validate();
}
@ -193,16 +171,12 @@ public class SendPhoto extends PartialBotApiMethod<Message> {
public String toString() {
return "SendPhoto{" +
"chatId='" + chatId + '\'' +
", photo='" + photo + '\'' +
", photo=" + photo +
", caption='" + caption + '\'' +
", disableNotification=" + disableNotification +
", replyToMessageId=" + replyToMessageId +
", replyMarkup=" + replyMarkup +
", parseMode='" + parseMode + '\'' +
", isNewPhoto=" + isNewPhoto +
", photoName='" + photoName + '\'' +
", newPhotoFile=" + newPhotoFile +
", newPhotoStream=" + newPhotoStream +
'}';
}
}

View File

@ -1,8 +1,8 @@
package org.telegram.telegrambots.meta.api.methods.send;
import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod;
import org.telegram.telegrambots.meta.api.objects.InputFile;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard;
@ -17,8 +17,7 @@ import java.util.Objects;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief Use this method to send .webp stickers. On success, the sent Message is returned.
* @date 20 of June of 2015
* Use this method to send .webp stickers. On success, the sent Message is returned.
*/
public class SendSticker extends PartialBotApiMethod<Message> {
public static final String PATH = "sendsticker";
@ -29,16 +28,11 @@ public class SendSticker extends PartialBotApiMethod<Message> {
public static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
public static final String REPLYMARKUP_FIELD = "reply_markup";
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
private String sticker; ///< Sticker file to send. file_id as String to resend a sticker that is already on the Telegram servers or URL to upload it
private InputFile sticker; ///< Sticker file to send. file_id as String to resend a sticker that is already on the Telegram servers or URL to upload it
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
private boolean isNewSticker; ///< True to upload a new sticker, false to use a fileId
private String stickerName;
private File newStickerFile; ///< New sticker file
private InputStream newStickerStream; ///< New sticker stream
public SendSticker() {
super();
}
@ -58,13 +52,12 @@ public class SendSticker extends PartialBotApiMethod<Message> {
return this;
}
public String getSticker() {
public InputFile getSticker() {
return sticker;
}
public SendSticker setSticker(String sticker) {
this.sticker = sticker;
this.isNewSticker = false;
this.sticker = new InputFile(sticker);
return this;
}
@ -86,18 +79,22 @@ public class SendSticker extends PartialBotApiMethod<Message> {
return this;
}
public SendSticker setNewSticker(File file) {
this.isNewSticker = true;
this.newStickerFile = file;
public SendSticker setSticker(InputFile sticker) {
Objects.requireNonNull(sticker, "sticker cannot be null!");
this.sticker = sticker;
return this;
}
public SendSticker setNewSticker(String stickerName, InputStream inputStream) {
public SendSticker setSticker(File file) {
Objects.requireNonNull(file, "file cannot be null!");
this.sticker = new InputFile(file, file.getName());
return this;
}
public SendSticker setSticker(String stickerName, InputStream inputStream) {
Objects.requireNonNull(stickerName, "stickerName cannot be null!");
Objects.requireNonNull(inputStream, "inputStream cannot be null!");
this.stickerName = stickerName;
this.isNewSticker = true;
this.newStickerStream = inputStream;
this.sticker = new InputFile(inputStream, stickerName);
return this;
}
@ -115,22 +112,6 @@ public class SendSticker extends PartialBotApiMethod<Message> {
return this;
}
public boolean isNewSticker() {
return isNewSticker;
}
public String getStickerName() {
return stickerName;
}
public File getNewStickerFile() {
return newStickerFile;
}
public InputStream getNewStickerStream() {
return newStickerStream;
}
@Override
public Message deserializeResponse(String answer) throws TelegramApiRequestException {
try {
@ -152,16 +133,12 @@ public class SendSticker extends PartialBotApiMethod<Message> {
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
}
if (isNewSticker) {
if (newStickerFile == null && newStickerStream == null) {
throw new TelegramApiValidationException("Sticker can't be empty", this);
}
if (newStickerStream != null && (stickerName == null || stickerName.isEmpty())) {
throw new TelegramApiValidationException("Sticker name can't be empty", this);
}
} else if (sticker == null) {
throw new TelegramApiValidationException("Sticker can't be empty", this);
if (sticker == null) {
throw new TelegramApiValidationException("Sticker parameter can't be empty", this);
}
sticker.validate();
if (replyMarkup != null) {
replyMarkup.validate();
}
@ -171,10 +148,10 @@ public class SendSticker extends PartialBotApiMethod<Message> {
public String toString() {
return "SendSticker{" +
"chatId='" + chatId + '\'' +
", sticker='" + sticker + '\'' +
", sticker=" + sticker +
", disableNotification=" + disableNotification +
", replyToMessageId=" + replyToMessageId +
", replyMarkup=" + replyMarkup +
", isNewSticker=" + isNewSticker +
'}';
}
}

View File

@ -16,9 +16,8 @@ import java.util.Objects;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief Use this method to send information about a venue. On success, the sent Message is
* Use this method to send information about a venue. On success, the sent Message is
* returned.
* @date 10 of April of 2016
*/
public class SendVenue extends BotApiMethod<Message> {
public static final String PATH = "sendVenue";
@ -29,9 +28,10 @@ public class SendVenue extends BotApiMethod<Message> {
private static final String TITLE_FIELD = "title";
private static final String DISABLENOTIFICATION_FIELD = "disable_notification";
private static final String ADDRESS_FIELD = "address";
private static final String FOURSQUARE_ID_FIELD = "foursquare_id";
private static final String FOURSQUAREID_FIELD = "foursquare_id";
private static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
private static final String REPLYMARKUP_FIELD = "reply_markup";
private static final String FOURSQUARETYPE_FIELD = "foursquare_type";
@JsonProperty(CHATID_FIELD)
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
@ -45,12 +45,14 @@ public class SendVenue extends BotApiMethod<Message> {
private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
@JsonProperty(ADDRESS_FIELD)
private String address; ///< Address of the venue
@JsonProperty(FOURSQUARE_ID_FIELD)
@JsonProperty(FOURSQUAREID_FIELD)
private String foursquareId; ///< Optional. Foursquare identifier of the venue
@JsonProperty(REPLYTOMESSAGEID_FIELD)
private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message
@JsonProperty(REPLYMARKUP_FIELD)
private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
@JsonProperty(FOURSQUARETYPE_FIELD)
private String foursquareType; ///< Optional. Foursquare type of the venue, if known.
public SendVenue() {
super();
@ -148,6 +150,15 @@ public class SendVenue extends BotApiMethod<Message> {
return this;
}
public String getFoursquareType() {
return foursquareType;
}
public SendVenue setFoursquareType(String foursquareType) {
this.foursquareType = foursquareType;
return this;
}
@Override
public String getMethod() {
return PATH;
@ -196,11 +207,13 @@ public class SendVenue extends BotApiMethod<Message> {
"chatId='" + chatId + '\'' +
", latitude=" + latitude +
", longitude=" + longitude +
", title=" + title +
", address=" + address +
", foursquareId=" + foursquareId +
", title='" + title + '\'' +
", disableNotification=" + disableNotification +
", address='" + address + '\'' +
", foursquareId='" + foursquareId + '\'' +
", replyToMessageId=" + replyToMessageId +
", replyMarkup=" + replyMarkup +
", foursquareType='" + foursquareType + '\'' +
'}';
}
}

View File

@ -1,8 +1,8 @@
package org.telegram.telegrambots.meta.api.methods.send;
import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod;
import org.telegram.telegrambots.meta.api.objects.InputFile;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard;
@ -17,9 +17,8 @@ import java.util.Objects;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief Use this method to send video files, Telegram clients support mp4 videos (other formats
* Use this method to send video files, Telegram clients support mp4 videos (other formats
* may be sent as Document). On success, the sent Message is returned.
* @date 20 of June of 2015
*/
public class SendVideo extends PartialBotApiMethod<Message> {
public static final String PATH = "sendvideo";
@ -35,9 +34,10 @@ public class SendVideo extends PartialBotApiMethod<Message> {
public static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
public static final String REPLYMARKUP_FIELD = "reply_markup";
public static final String PARSEMODE_FIELD = "parse_mode";
public static final String THUMB_FIELD = "thumb";
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
private String 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 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 Integer width; ///< Optional. Video width
@ -47,11 +47,14 @@ public class SendVideo extends PartialBotApiMethod<Message> {
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
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.
private boolean isNewVideo; ///< True to upload a new video, false to use a fileId
private String videoName; ///< Name of the video
private File newVideoFile; ///< New video file
private InputStream newVideoStream; ///< New video stream
/**
* Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size.
* A thumbnails width and height should not exceed 90.
* Ignored if the file is not uploaded using multipart/form-data.
* Thumbnails cant be reused and can be only uploaded as a new file, so you can pass attach://<file_attach_name>
* if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
*/
private InputFile thumb;
public SendVideo() {
super();
@ -66,13 +69,12 @@ public class SendVideo extends PartialBotApiMethod<Message> {
return this;
}
public String getVideo() {
public InputFile getVideo() {
return video;
}
public SendVideo setVideo(String video) {
this.video = video;
this.isNewVideo = false;
this.video = new InputFile(video);
return this;
}
@ -118,22 +120,6 @@ public class SendVideo extends PartialBotApiMethod<Message> {
return this;
}
public boolean isNewVideo() {
return isNewVideo;
}
public String getVideoName() {
return videoName;
}
public File getNewVideoFile() {
return newVideoFile;
}
public InputStream getNewVideoStream() {
return newVideoStream;
}
public Boolean getDisableNotification() {
return disableNotification;
}
@ -166,18 +152,22 @@ public class SendVideo extends PartialBotApiMethod<Message> {
return this;
}
public SendVideo setNewVideo(File file) {
this.isNewVideo = true;
this.newVideoFile = file;
public SendVideo setVideo(InputFile video) {
Objects.requireNonNull(video, "video cannot be null!");
this.video = video;
return this;
}
public SendVideo setNewVideo(String videoName, InputStream inputStream) {
public SendVideo setVideo(File file) {
Objects.requireNonNull(file, "file cannot be null!");
this.video = new InputFile(file, file.getName());
return this;
}
public SendVideo setVideo(String videoName, InputStream inputStream) {
Objects.requireNonNull(videoName, "videoName cannot be null!");
Objects.requireNonNull(inputStream, "inputStream cannot be null!");
this.videoName = videoName;
this.isNewVideo = true;
this.newVideoStream = inputStream;
this.video = new InputFile(inputStream, videoName);
return this;
}
@ -199,6 +189,15 @@ public class SendVideo extends PartialBotApiMethod<Message> {
return this;
}
public InputFile getThumb() {
return thumb;
}
public SendVideo setThumb(InputFile thumb) {
this.thumb = thumb;
return this;
}
@Override
public Message deserializeResponse(String answer) throws TelegramApiRequestException {
try {
@ -220,15 +219,14 @@ public class SendVideo extends PartialBotApiMethod<Message> {
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
}
if (isNewVideo) {
if (newVideoFile == null && newVideoStream == null) {
throw new TelegramApiValidationException("Video can't be empty", this);
}
if (newVideoStream != null && (videoName == null || videoName.isEmpty())) {
throw new TelegramApiValidationException("Video name can't be empty", this);
}
} else if (video == null) {
throw new TelegramApiValidationException("Video can't be empty", this);
if (video == null) {
throw new TelegramApiValidationException("Video parameter can't be empty", this);
}
video.validate();
if (thumb != null) {
thumb.validate();
}
if (replyMarkup != null) {
replyMarkup.validate();
@ -239,12 +237,17 @@ public class SendVideo extends PartialBotApiMethod<Message> {
public String toString() {
return "SendVideo{" +
"chatId='" + chatId + '\'' +
", video='" + video + '\'' +
", video=" + video +
", duration=" + duration +
", caption='" + caption + '\'' +
", width=" + width +
", height=" + height +
", supportsStreaming=" + supportsStreaming +
", disableNotification=" + disableNotification +
", replyToMessageId=" + replyToMessageId +
", replyMarkup=" + replyMarkup +
", isNewVideo=" + isNewVideo +
", parseMode='" + parseMode + '\'' +
", thumb=" + thumb +
'}';
}
}

View File

@ -2,6 +2,7 @@ package org.telegram.telegrambots.meta.api.methods.send;
import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod;
import org.telegram.telegrambots.meta.api.objects.InputFile;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard;
@ -21,6 +22,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
* As of v.4.0, Telegram clients support rounded square mp4 videos of up to 1 minute long.
* Use this method to send video messages. On success, the sent Message is returned.
*/
@SuppressWarnings({"UnusedReturnValue", "WeakerAccess"})
public class SendVideoNote extends PartialBotApiMethod<Message> {
public static final String PATH = "sendvideonote";
@ -31,19 +33,23 @@ public class SendVideoNote extends PartialBotApiMethod<Message> {
public static final String DISABLENOTIFICATION_FIELD = "disable_notification";
public static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
public static final String REPLYMARKUP_FIELD = "reply_markup";
public static final String THUMB_FIELD = "thumb";
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
private String videoNote; ///< Videonote to send. file_id as String to resend a video that is already on the Telegram servers.
private InputFile videoNote; ///< Videonote to send. file_id as String to resend a video that is already on the Telegram servers.
private Integer duration; ///< Optional. Duration of sent video in seconds
private Integer length; ///< Optional. Video width and 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
private boolean isNewVideoNote; ///< True to upload a new video note, false to use a fileId
private String videoNoteName; ///< Name of the video
private File newVideoNoteFile; ///< New video note file
private InputStream newVideoNoteStream; ///< New video note stream
/**
* Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size.
* A thumbnails width and height should not exceed 90.
* Ignored if the file is not uploaded using multipart/form-data.
* Thumbnails cant be reused and can be only uploaded as a new file, so you can pass attach://<file_attach_name>
* if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
*/
private InputFile thumb;
public SendVideoNote() {
super();
@ -56,8 +62,7 @@ public class SendVideoNote extends PartialBotApiMethod<Message> {
*/
public SendVideoNote(String chatId, String videoNote) {
this.chatId = checkNotNull(chatId);
this.videoNote = checkNotNull(videoNote);
this.isNewVideoNote = false;
this.setVideoNote(checkNotNull(videoNote));
}
/**
@ -66,59 +71,51 @@ public class SendVideoNote extends PartialBotApiMethod<Message> {
* @param videoNote Video note file_id to send
*/
public SendVideoNote(Long chatId, String videoNote) {
this.chatId = checkNotNull(chatId).toString();
this.videoNote = checkNotNull(videoNote);
this.isNewVideoNote = false;
this.setVideoNote(checkNotNull(videoNote));
}
/**
* Creates a new video note with a new video note
* @param chatId Chat Id to send the video note
* @param newVideoNoteFile Video note file to upload
* @param videoNote Video note file to upload
*/
public SendVideoNote(String chatId, File newVideoNoteFile) {
public SendVideoNote(String chatId, File videoNote) {
this.chatId = checkNotNull(chatId);
this.newVideoNoteFile = checkNotNull(newVideoNoteFile);
this.isNewVideoNote = true;
this.setVideoNote(videoNote);
}
/**
* Creates a new video note with a video already present in telegram servers
* @param chatId Chat Id to send the video note
* @param newVideoNoteFile Video note file to upload
* @param videoNote Video note file to upload
*/
public SendVideoNote(Integer chatId, File newVideoNoteFile) {
public SendVideoNote(Integer chatId, File videoNote) {
this.chatId = checkNotNull(chatId).toString();
this.newVideoNoteFile = checkNotNull(newVideoNoteFile);
this.isNewVideoNote = true;
this.setVideoNote(videoNote);
}
/**
* Creates a new video note with a new video note
* @param chatId Chat Id to send the video note
* @param videoNoteName Name of the video note file
* @param newVideoNoteStream Video note file to upload
* @param videoNote Video note file to upload
*/
public SendVideoNote(String chatId, String videoNoteName, InputStream newVideoNoteStream) {
public SendVideoNote(String chatId, String videoNoteName, InputStream videoNote) {
this.chatId = checkNotNull(chatId);
this.videoNoteName = checkNotNull(videoNoteName);
this.newVideoNoteStream = checkNotNull(newVideoNoteStream);
this.isNewVideoNote = true;
this.setVideoNote(videoNoteName, videoNote);
}
/**
* Creates a new video note with a video already present in telegram servers
* @param chatId Chat Id to send the video note
* @param videoNoteName Name of the video note file
* @param newVideoNoteStream Video note file to upload
* @param videoNote Video note file to upload
*/
public SendVideoNote(Integer chatId, String videoNoteName, InputStream newVideoNoteStream) {
public SendVideoNote(Integer chatId, String videoNoteName, InputStream videoNote) {
this.chatId = checkNotNull(chatId).toString();
this.videoNoteName = checkNotNull(videoNoteName);
this.newVideoNoteStream = checkNotNull(newVideoNoteStream);
this.isNewVideoNote = true;
this.setVideoNote(videoNoteName, videoNote);
}
public String getChatId() {
@ -130,13 +127,12 @@ public class SendVideoNote extends PartialBotApiMethod<Message> {
return this;
}
public String getVideoNote() {
public InputFile getVideoNote() {
return videoNote;
}
public SendVideoNote setVideoNote(String videoNote) {
this.videoNote = videoNote;
this.isNewVideoNote = false;
this.videoNote = new InputFile(videoNote);
return this;
}
@ -196,35 +192,32 @@ public class SendVideoNote extends PartialBotApiMethod<Message> {
return this;
}
public boolean isNewVideoNote() {
return isNewVideoNote;
}
public SendVideoNote setNewVideoNote(File file) {
this.isNewVideoNote = true;
this.newVideoNoteFile = file;
public SendVideoNote setVideoNote(InputFile videoNote) {
Objects.requireNonNull(videoNote, "videoNote cannot be null!");
this.videoNote = videoNote;
return this;
}
public SendVideoNote setNewVideo(String videoName, InputStream inputStream) {
public SendVideoNote setVideoNote(File file) {
Objects.requireNonNull(file, "file cannot be null!");
this.videoNote = new InputFile(file, file.getName());
return this;
}
public SendVideoNote setVideoNote(String videoName, InputStream inputStream) {
Objects.requireNonNull(videoName, "videoName cannot be null!");
Objects.requireNonNull(inputStream, "inputStream cannot be null!");
this.videoNoteName = videoName;
this.isNewVideoNote = true;
this.newVideoNoteStream = inputStream;
this.videoNote = new InputFile(inputStream, videoName);
return this;
}
public String getVideoNoteName() {
return videoNoteName;
public InputFile getThumb() {
return thumb;
}
public File getNewVideoNoteFile() {
return newVideoNoteFile;
}
public InputStream getNewVideoNoteStream() {
return newVideoNoteStream;
public SendVideoNote setThumb(InputFile thumb) {
this.thumb = thumb;
return this;
}
@Override
@ -235,7 +228,7 @@ public class SendVideoNote extends PartialBotApiMethod<Message> {
if (result.getOk()) {
return result.getResult();
} else {
throw new TelegramApiRequestException("Error sending video", result);
throw new TelegramApiRequestException("Error sending video note", result);
}
} catch (IOException e) {
throw new TelegramApiRequestException("Unable to deserialize response", e);
@ -248,15 +241,14 @@ public class SendVideoNote extends PartialBotApiMethod<Message> {
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
}
if (isNewVideoNote) {
if (newVideoNoteFile == null && newVideoNoteStream == null) {
throw new TelegramApiValidationException("Videonote can't be empty", this);
}
if (newVideoNoteStream != null && (videoNoteName == null || videoNoteName.isEmpty())) {
throw new TelegramApiValidationException("Video note name can't be empty", this);
}
} else if (videoNote == null) {
throw new TelegramApiValidationException("Video note can't be empty", this);
if (videoNote == null) {
throw new TelegramApiValidationException("VideoNote parameter can't be empty", this);
}
videoNote.validate();
if (thumb != null) {
thumb.validate();
}
if (replyMarkup != null) {
replyMarkup.validate();
@ -267,16 +259,13 @@ public class SendVideoNote extends PartialBotApiMethod<Message> {
public String toString() {
return "SendVideoNote{" +
"chatId='" + chatId + '\'' +
", videoNote='" + videoNote + '\'' +
", videoNote=" + videoNote +
", duration=" + duration +
", length=" + length +
", disableNotification=" + disableNotification +
", replyToMessageId=" + replyToMessageId +
", replyMarkup=" + replyMarkup +
", isNewVideoNote=" + isNewVideoNote +
", videoNoteName='" + videoNoteName + '\'' +
", newVideoNoteFile=" + newVideoNoteFile +
", newVideoNoteStream=" + newVideoNoteStream +
", thumb=" + thumb +
'}';
}
}

View File

@ -1,8 +1,8 @@
package org.telegram.telegrambots.meta.api.methods.send;
import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod;
import org.telegram.telegrambots.meta.api.objects.InputFile;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard;
@ -34,7 +34,7 @@ public class SendVoice extends PartialBotApiMethod<Message> {
public static final String PARSEMODE_FIELD = "parse_mode";
private String chatId; ///< Unique identifier for the chat sent message to (Or username for channels)
private String voice; ///< Audio file to send. You can either pass a file_id as String to resend an audio that is already on the Telegram servers, or upload a new audio file using multipart/form-data.
private InputFile voice; ///< Audio file to send. You can either pass a file_id as String to resend an audio that is already on the Telegram servers, or upload a new audio file using multipart/form-data.
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
@ -42,11 +42,6 @@ public class SendVoice extends PartialBotApiMethod<Message> {
private String caption; ///< Optional. Voice caption (may also be used when resending videos by file_id).
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.
private boolean isNewVoice; ///< True to upload a new voice note, false to use a fileId
private String voiceName; ///< Name of the voice note
private File newVoiceFile; ///< New voice note file
private InputStream newVoiceStream; ///< New voice note stream
public SendVoice() {
super();
}
@ -80,28 +75,32 @@ public class SendVoice extends PartialBotApiMethod<Message> {
return this;
}
public String getVoice() {
public InputFile getVoice() {
return voice;
}
public SendVoice setVoice(String voice) {
Objects.requireNonNull(voice, "voice cannot be null!");
this.voice = new InputFile(voice);
return this;
}
public SendVoice setVoice(File voice) {
Objects.requireNonNull(voice, "voice cannot be null!");
this.voice = new InputFile(voice, voice.getName());
return this;
}
public SendVoice setVoice(InputFile voice) {
Objects.requireNonNull(voice, "voice cannot be null!");
this.voice = voice;
this.isNewVoice = false;
return this;
}
public SendVoice setNewVoice(File file) {
this.isNewVoice = true;
this.newVoiceFile = file;
return this;
}
public SendVoice setNewVoice(String voiceName, InputStream inputStream) {
public SendVoice setVoice(String voiceName, InputStream inputStream) {
Objects.requireNonNull(voiceName, "voiceName cannot be null!");
Objects.requireNonNull(inputStream, "inputStream cannot be null!");
this.voiceName = voiceName;
this.isNewVoice = true;
this.newVoiceStream = inputStream;
this.voice = new InputFile(inputStream, voiceName);
return this;
}
@ -132,22 +131,6 @@ public class SendVoice extends PartialBotApiMethod<Message> {
return this;
}
public boolean isNewVoice() {
return isNewVoice;
}
public String getVoiceName() {
return voiceName;
}
public File getNewVoiceFile() {
return newVoiceFile;
}
public InputStream getNewVoiceStream() {
return newVoiceStream;
}
public String getCaption() {
return caption;
}
@ -187,17 +170,12 @@ public class SendVoice extends PartialBotApiMethod<Message> {
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
}
if (isNewVoice) {
if (newVoiceFile == null && newVoiceStream == null) {
throw new TelegramApiValidationException("Voice can't be empty", this);
}
if (newVoiceStream != null && (voiceName == null || voiceName.isEmpty())) {
throw new TelegramApiValidationException("Voice name can't be empty", this);
}
} else if (voice == null) {
throw new TelegramApiValidationException("Voice can't be empty", this);
if (voice == null) {
throw new TelegramApiValidationException("Voice parameter can't be empty", this);
}
voice.validate();
if (replyMarkup != null) {
replyMarkup.validate();
}
@ -207,17 +185,13 @@ public class SendVoice extends PartialBotApiMethod<Message> {
public String toString() {
return "SendVoice{" +
"chatId='" + chatId + '\'' +
", voice='" + voice + '\'' +
", voice=" + voice +
", disableNotification=" + disableNotification +
", replyToMessageId=" + replyToMessageId +
", replyMarkup=" + replyMarkup +
", duration=" + duration +
", caption='" + caption + '\'' +
", parseMode='" + parseMode + '\'' +
", isNewVoice=" + isNewVoice +
", voiceName='" + voiceName + '\'' +
", newVoiceFile=" + newVoiceFile +
", newVoiceStream=" + newVoiceStream +
'}';
}
}

View File

@ -2,6 +2,7 @@ package org.telegram.telegrambots.meta.api.methods.stickers;
import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod;
import org.telegram.telegrambots.meta.api.objects.InputFile;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.stickers.MaskPosition;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
@ -38,11 +39,7 @@ public class AddStickerToSet extends PartialBotApiMethod<Boolean> {
* that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram
* to get a file from the Internet, or upload a new one using multipart/form-data.
*/
private Boolean isNewPngSticker;
private String pngSticker;
private File pngStickerFile; ///< New sticker file
private InputStream pngStickerStream; ///< New sticker stream
private String pngStickerName; ///< New sticker stream name
private InputFile pngSticker;
public AddStickerToSet() {
super();
@ -63,48 +60,28 @@ public class AddStickerToSet extends PartialBotApiMethod<Boolean> {
return this;
}
public String getPngSticker() {
public InputFile getPngSticker() {
return pngSticker;
}
public AddStickerToSet setPngSticker(String pngSticker) {
this.pngSticker = pngSticker;
this.isNewPngSticker = false;
this.pngSticker = new InputFile(pngSticker);
return this;
}
public File getPngStickerFile() {
return pngStickerFile;
}
public AddStickerToSet setPngStickerFile(File pngStickerFile) {
Objects.requireNonNull(pngStickerFile, "pngStickerFile cannot be null!");
this.pngStickerFile = pngStickerFile;
this.isNewPngSticker = true;
public AddStickerToSet setPngSticker(File pngSticker) {
Objects.requireNonNull(pngSticker, "pngSticker cannot be null!");
this.pngSticker = new InputFile(pngSticker, pngSticker.getName());
return this;
}
public InputStream getPngStickerStream() {
return pngStickerStream;
}
public AddStickerToSet setPngStickerStream(String pngStickerName, InputStream pngStickerStream) {
public AddStickerToSet setPngSticker(String pngStickerName, InputStream pngSticker) {
Objects.requireNonNull(pngStickerName, "pngStickerName cannot be null!");
Objects.requireNonNull(pngStickerStream, "pngStickerStream cannot be null!");
this.pngStickerStream = pngStickerStream;
this.pngStickerName = pngStickerName;
this.isNewPngSticker = true;
Objects.requireNonNull(pngSticker, "pngSticker cannot be null!");
this.pngSticker = new InputFile(pngSticker, pngStickerName);
return this;
}
public String getPngStickerName() {
return pngStickerName;
}
public Boolean isNewPngSticker() {
return isNewPngSticker;
}
public String getName() {
return name;
}
@ -158,16 +135,13 @@ public class AddStickerToSet extends PartialBotApiMethod<Boolean> {
if (emojis == null || emojis.isEmpty()) {
throw new TelegramApiValidationException("emojis can't be empty", this);
}
if (isNewPngSticker) {
if (pngStickerFile == null && pngStickerStream == null) {
throw new TelegramApiValidationException("PngSticker can't be empty", this);
}
if (pngStickerStream != null && (pngStickerName == null || pngStickerName.isEmpty())) {
throw new TelegramApiValidationException("PngSticker name can't be empty", this);
}
} else if (pngSticker == null) {
if (pngSticker == null) {
throw new TelegramApiValidationException("PngSticker can't be empty", this);
}
pngSticker.validate();
if (maskPosition != null) {
maskPosition.validate();
}
@ -180,11 +154,7 @@ public class AddStickerToSet extends PartialBotApiMethod<Boolean> {
", name='" + name + '\'' +
", emojis='" + emojis + '\'' +
", maskPosition=" + maskPosition +
", isNewPngSticker=" + isNewPngSticker +
", pngSticker='" + pngSticker + '\'' +
", pngStickerFile=" + pngStickerFile +
", pngStickerStream=" + pngStickerStream +
", pngStickerName='" + pngStickerName + '\'' +
", pngSticker=" + pngSticker +
'}';
}
}

View File

@ -2,6 +2,7 @@ package org.telegram.telegrambots.meta.api.methods.stickers;
import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod;
import org.telegram.telegrambots.meta.api.objects.InputFile;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.stickers.MaskPosition;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
@ -50,11 +51,7 @@ public class CreateNewStickerSet extends PartialBotApiMethod<Boolean> {
* pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one
* using multipart/form-data. More info on Sending Files »
*/
private Boolean isNewPngSticker;
private String pngSticker;
private java.io.File pngStickerFile; ///< New sticker file
private InputStream pngStickerStream; ///< New sticker stream
private String pngStickerName; ///< New sticker stream name
private InputFile pngSticker;
public CreateNewStickerSet() {
super();
@ -75,48 +72,34 @@ public class CreateNewStickerSet extends PartialBotApiMethod<Boolean> {
this.userId = userId;
}
public String getPngSticker() {
public InputFile getPngSticker() {
return pngSticker;
}
public CreateNewStickerSet setPngSticker(String pngSticker) {
this.pngSticker = pngSticker;
this.isNewPngSticker = false;
this.pngSticker = new InputFile(pngSticker);
return this;
}
public File getPngStickerFile() {
return pngStickerFile;
public CreateNewStickerSet setPngStickerFile(InputFile pngStickerFile) {
Objects.requireNonNull(pngStickerFile, "pngStickerFile cannot be null!");
this.pngSticker = pngStickerFile;
return this;
}
public CreateNewStickerSet setPngStickerFile(File pngStickerFile) {
Objects.requireNonNull(pngStickerFile, "pngStickerFile cannot be null!");
this.pngStickerFile = pngStickerFile;
this.isNewPngSticker = true;
this.pngSticker = new InputFile(pngStickerFile, pngStickerFile.getName());
return this;
}
public InputStream getPngStickerStream() {
return pngStickerStream;
}
public CreateNewStickerSet setPngStickerStream(String pngStickerName, InputStream pngStickerStream) {
Objects.requireNonNull(pngStickerName, "pngStickerName cannot be null!");
Objects.requireNonNull(pngStickerStream, "pngStickerStream cannot be null!");
this.pngStickerStream = pngStickerStream;
this.pngStickerName = pngStickerName;
this.isNewPngSticker = true;
this.pngSticker = new InputFile(pngStickerStream, pngStickerName);
return this;
}
public String getPngStickerName() {
return pngStickerName;
}
public Boolean isNewPngSticker() {
return isNewPngSticker;
}
public String getName() {
return name;
}
@ -186,16 +169,13 @@ public class CreateNewStickerSet extends PartialBotApiMethod<Boolean> {
if (emojis == null || emojis.isEmpty()) {
throw new TelegramApiValidationException("emojis can't be empty", this);
}
if (isNewPngSticker) {
if (pngStickerFile == null && pngStickerStream == null) {
throw new TelegramApiValidationException("PngSticker can't be empty", this);
}
if (pngStickerStream != null && (pngStickerName == null || pngStickerName.isEmpty())) {
throw new TelegramApiValidationException("PngSticker name can't be empty", this);
}
} else if (pngSticker == null) {
throw new TelegramApiValidationException("PngSticker can't be empty", this);
if (pngSticker == null) {
throw new TelegramApiValidationException("PngSticker parameter can't be empty", this);
}
pngSticker.validate();
if (maskPosition != null) {
maskPosition.validate();
}
@ -210,11 +190,7 @@ public class CreateNewStickerSet extends PartialBotApiMethod<Boolean> {
", emojis='" + emojis + '\'' +
", containsMasks=" + containsMasks +
", maskPosition=" + maskPosition +
", isNewPngSticker=" + isNewPngSticker +
", pngSticker='" + pngSticker + '\'' +
", pngStickerFile=" + pngStickerFile +
", pngStickerStream=" + pngStickerStream +
", pngStickerName='" + pngStickerName + '\'' +
", pngSticker=" + pngSticker +
'}';
}
}

View File

@ -3,6 +3,7 @@ package org.telegram.telegrambots.meta.api.methods.stickers;
import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod;
import org.telegram.telegrambots.meta.api.objects.File;
import org.telegram.telegrambots.meta.api.objects.InputFile;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ApiResponse;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
@ -29,9 +30,7 @@ public class UploadStickerFile extends PartialBotApiMethod<File> {
* Png image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px,
* and either width or height must be exactly 512px. More info on Sending Files »
*/
private java.io.File newPngStickerFile; ///< New sticker file
private InputStream newPngStickerStream; ///< New sticker stream
private String newPngStickerName; ///< New sticker stream name
private InputFile pngSticker; ///< New sticker file
public UploadStickerFile() {
super();
@ -62,12 +61,12 @@ public class UploadStickerFile extends PartialBotApiMethod<File> {
if (userId == null || userId <= 0) {
throw new TelegramApiValidationException("userId can't be empty", this);
}
if (newPngStickerFile == null && newPngStickerStream == null) {
throw new TelegramApiValidationException("file or stream must be present", this);
}
if (newPngStickerStream != null && (newPngStickerName == null || newPngStickerName.isEmpty())) {
throw new TelegramApiValidationException("Stream name must be present", this);
if (pngSticker == null) {
throw new TelegramApiValidationException("PngSticker parameter can't be empty", this);
}
pngSticker.validate();
}
public Integer getUserId() {
@ -79,36 +78,25 @@ public class UploadStickerFile extends PartialBotApiMethod<File> {
return this;
}
public java.io.File getNewPngStickerFile() {
return newPngStickerFile;
public InputFile getPngSticker() {
return pngSticker;
}
public UploadStickerFile setNewPngSticker(java.io.File newPngStickerFile) {
this.newPngStickerFile = newPngStickerFile;
public UploadStickerFile setPngSticker(java.io.File pngSticker) {
this.pngSticker = new InputFile(pngSticker, pngSticker.getName());
return this;
}
public InputStream getNewPngStickerStream() {
return newPngStickerStream;
}
public UploadStickerFile setNewPngSticker(String newPngStickerName, InputStream newPngStickerStream) {
this.newPngStickerName = newPngStickerName;
this.newPngStickerStream = newPngStickerStream;
public UploadStickerFile setPngSticker(String pngStickerName, InputStream pngStickerStream) {
this.pngSticker = new InputFile(pngStickerStream, pngStickerName);
return this;
}
public String getNewPngStickerName() {
return newPngStickerName;
}
@Override
public String toString() {
return "UploadStickerFile{" +
"userId=" + userId +
", newPngStickerFile=" + newPngStickerFile +
", newPngStickerStream=" + newPngStickerStream +
", newPngStickerName='" + newPngStickerName + '\'' +
", pngSticker=" + pngSticker +
'}';
}
}

View File

@ -0,0 +1,176 @@
package org.telegram.telegrambots.meta.api.methods.updatingmessages;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.media.InputMedia;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.IOException;
import java.io.Serializable;
/**
* @author Ruben Bermudez
* @version 4.0.0
* Use this method to edit audio, document, photo, or video messages.
* If a message is a part of a message album, then it can be edited only to a photo or a video.
* Otherwise, message type can be changed arbitrarily. When inline message is edited, new file can't be uploaded.
* Use previously uploaded file via its file_id or specify a URL.
* On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned.
*/
public class EditMessageMedia extends PartialBotApiMethod<Serializable> {
public static final String PATH = "editMessageMedia";
public static final String CHATID_FIELD = "chat_id";
public static final String MESSAGEID_FIELD = "message_id";
public static final String INLINE_MESSAGE_ID_FIELD = "inline_message_id";
public static final String MEDIA_FIELD = "media";
public static final String REPLYMARKUP_FIELD = "reply_markup";
/**
* Required if inline_message_id is not specified. Unique identifier for the chat to send the
* message to (Or username for channels)
*/
@JsonProperty(CHATID_FIELD)
private String chatId;
/**
* Required if inline_message_id is not specified. Unique identifier of the sent message
*/
@JsonProperty(MESSAGEID_FIELD)
private Integer messageId;
/**
* Required if chat_id and message_id are not specified. Identifier of the inline message
*/
@JsonProperty(INLINE_MESSAGE_ID_FIELD)
private String inlineMessageId;
/**
* A JSON-serialized object for a new media content of the message
*/
@JsonProperty(MEDIA_FIELD)
private InputMedia media;
@JsonProperty(REPLYMARKUP_FIELD)
private InlineKeyboardMarkup replyMarkup; ///< Optional. A JSON-serialized object for an inline keyboard.
public EditMessageMedia() {
super();
}
public String getChatId() {
return chatId;
}
public EditMessageMedia setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public EditMessageMedia setChatId(Long chatId) {
this.chatId = chatId.toString();
return this;
}
public Integer getMessageId() {
return messageId;
}
public EditMessageMedia setMessageId(Integer messageId) {
this.messageId = messageId;
return this;
}
public String getInlineMessageId() {
return inlineMessageId;
}
public EditMessageMedia setInlineMessageId(String inlineMessageId) {
this.inlineMessageId = inlineMessageId;
return this;
}
public InputMedia getMedia() {
return media;
}
public void setMedia(InputMedia media) {
this.media = media;
}
public InlineKeyboardMarkup getReplyMarkup() {
return replyMarkup;
}
public EditMessageMedia setReplyMarkup(InlineKeyboardMarkup replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
@Override
public Serializable deserializeResponse(String answer) throws TelegramApiRequestException {
try {
ApiResponse<Message> result = OBJECT_MAPPER.readValue(answer,
new TypeReference<ApiResponse<Message>>(){});
if (result.getOk()) {
return result.getResult();
} else {
throw new TelegramApiRequestException("Error editing message text", result);
}
} catch (IOException e) {
try {
ApiResponse<Boolean> result = OBJECT_MAPPER.readValue(answer,
new TypeReference<ApiResponse<Boolean>>() {
});
if (result.getOk()) {
return result.getResult();
} else {
throw new TelegramApiRequestException("Error editing message text", result);
}
} catch (IOException e2) {
throw new TelegramApiRequestException("Unable to deserialize response", e);
}
}
}
@Override
public void validate() throws TelegramApiValidationException {
if (inlineMessageId == null) {
if (chatId == null) {
throw new TelegramApiValidationException("ChatId parameter can't be empty if inlineMessageId is not present", this);
}
if (messageId == null) {
throw new TelegramApiValidationException("MessageId parameter can't be empty if inlineMessageId is not present", this);
}
} else {
if (chatId != null) {
throw new TelegramApiValidationException("ChatId parameter must be empty if inlineMessageId is provided", this);
}
if (messageId != null) {
throw new TelegramApiValidationException("MessageId parameter must be empty if inlineMessageId is provided", this);
}
}
if (media == null) {
throw new TelegramApiValidationException("Text parameter can't be empty", this);
}
media.validate();
if (replyMarkup != null) {
replyMarkup.validate();
}
}
@Override
public String toString() {
return "EditMessageMedia{" +
"chatId='" + chatId + '\'' +
", messageId=" + messageId +
", inlineMessageId='" + inlineMessageId + '\'' +
", media=" + media +
", replyMarkup=" + replyMarkup +
'}';
}
}

View File

@ -7,8 +7,7 @@ import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief This object represents an audio file
* @date 16 of July of 2015
* This object represents an audio file
*/
public class Audio implements BotApiObject {
@ -18,6 +17,7 @@ public class Audio implements BotApiObject {
private static final String FILESIZE_FIELD = "file_size";
private static final String TITLE_FIELD = "title";
private static final String PERFORMER_FIELD = "performer";
private static final String THUMB_FIELD = "thumb";
@JsonProperty(FILEID_FIELD)
private String fileId; ///< Unique identifier for this file
@ -31,6 +31,8 @@ public class Audio implements BotApiObject {
private String title; ///< Optional. Title of the audio as defined by sender or by audio tags
@JsonProperty(PERFORMER_FIELD)
private String performer; ///< Optional. Performer of the audio as defined by sender or by audio tags
@JsonProperty(THUMB_FIELD)
private PhotoSize thumb; ///< Optional. Thumbnail of the album cover to which the music file belongs
public Audio() {
super();
@ -60,6 +62,10 @@ public class Audio implements BotApiObject {
return performer;
}
public PhotoSize getThumb() {
return thumb;
}
@Override
public String toString() {
return "Audio{" +
@ -69,6 +75,7 @@ public class Audio implements BotApiObject {
", fileSize=" + fileSize +
", title='" + title + '\'' +
", performer='" + performer + '\'' +
", thumb=" + thumb +
'}';
}
}

View File

@ -7,8 +7,7 @@ import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief This object represents a phone contact.
* @date 20 of June of 2015
* This object represents a phone contact.
*/
public class Contact implements BotApiObject {
@ -16,6 +15,7 @@ public class Contact implements BotApiObject {
private static final String FIRSTNAME_FIELD = "first_name";
private static final String LASTNAME_FIELD = "last_name";
private static final String USERID_FIELD = "user_id";
private static final String VCARD_FIELD = "vcard";
@JsonProperty(PHONENUMBER_FIELD)
private String phoneNumber; ///< Contact's phone number
@ -25,6 +25,8 @@ public class Contact implements BotApiObject {
private String lastName; ///< Optional. Contact's last name
@JsonProperty(USERID_FIELD)
private Integer userID; ///< Optional. Contact's user identifier in Telegram
@JsonProperty(VCARD_FIELD)
private String vCard; ///< Optional. Additional data about the contact in the form of a vCard
public Contact() {
super();
@ -46,6 +48,10 @@ public class Contact implements BotApiObject {
return userID;
}
public String getVCard() {
return vCard;
}
@Override
public String toString() {
return "Contact{" +
@ -53,6 +59,7 @@ public class Contact implements BotApiObject {
", firstName='" + firstName + '\'' +
", lastName='" + lastName + '\'' +
", userID=" + userID +
", vCard=" + vCard +
'}';
}
}

View File

@ -3,15 +3,17 @@ package org.telegram.telegrambots.meta.api.objects;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief Types of messages entities
* @date 10 of April of 2016
* Types of messages entities
*/
@SuppressWarnings("WeakerAccess")
public class EntityType {
public static final String MENTION = "mention"; ///< @username
public static final String HASHTAG = "hashtag"; ///< #hashtag
public static final String CASHTAG = "cashtag"; ///< $USD
public static final String BOTCOMMAND = "bot_command"; ///< /botcommand
public static final String URL = "url"; ///< http://url.url
public static final String EMAIL = "email"; ///< email@email.com
public static final String PHONENUMBER = "phone_number"; ///< +4299999999
public static final String BOLD = "bold"; ///< Bold text
public static final String ITALIC = "italic"; ///< Italic text
public static final String CODE = "code"; ///< Monowidth string

View File

@ -0,0 +1,133 @@
package org.telegram.telegrambots.meta.api.objects;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.telegram.telegrambots.meta.api.interfaces.InputBotApiObject;
import org.telegram.telegrambots.meta.api.interfaces.Validable;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.File;
import java.io.InputStream;
/**
* @author Ruben Bermudez
* @version 4.0.0
*
* Input file used to upload a file to Telegram server and use it afterwards
*/
@SuppressWarnings({"WeakerAccess", "UnusedReturnValue"})
@JsonSerialize(using = InputFileSerializer.class, as = String.class)
public class InputFile implements InputBotApiObject, Validable {
private String attachName;
@JsonIgnore
private String mediaName; ///< Name of the media to upload
@JsonIgnore
private File newMediaFile; ///< New media file
@JsonIgnore
private InputStream newMediaStream; ///< New media stream
@JsonIgnore
private boolean isNew; ///< True if the file is new, false if it is a file_id
public InputFile() {
super();
}
public InputFile(String attachName) {
this();
setMedia(attachName);
}
/**
* Constructor to set a new file
*
* @param mediaFile File to send
* @param fileName Name of the file
*/
public InputFile(File mediaFile, String fileName) {
this();
setMedia(mediaFile, fileName);
}
/**
* Constructor to set a new file as stream
*
* @param mediaStream File to send
* @param fileName Name of the file
*/
public InputFile(InputStream mediaStream, String fileName) {
this();
setMedia(mediaStream, fileName);
}
/**
* Use this setter to send new file.
* @param mediaFile File to send
* @param fileName Name of the file
* @return This object
*/
public InputFile setMedia(File mediaFile, String fileName) {
this.newMediaFile = mediaFile;
this.mediaName = fileName;
this.attachName = "attach://" + fileName;
this.isNew = true;
return this;
}
/**
* Use this setter to send new file as stream.
* @param mediaStream File to send
* @param fileName Name of the file
* @return This object
*/
public InputFile setMedia(InputStream mediaStream, String fileName) {
this.newMediaStream = mediaStream;
this.mediaName = fileName;
this.attachName = "attach://" + fileName;
this.isNew = true;
return this;
}
public InputFile setMedia(String attachName) {
this.attachName = attachName;
this.isNew = false;
return this;
}
public String getAttachName() {
return attachName;
}
public String getMediaName() {
return mediaName;
}
public File getNewMediaFile() {
return newMediaFile;
}
public InputStream getNewMediaStream() {
return newMediaStream;
}
public boolean isNew() {
return isNew;
}
@Override
public void validate() throws TelegramApiValidationException {
if (isNew) {
if (mediaName == null || mediaName.isEmpty()) {
throw new TelegramApiValidationException("Media name can't be empty", this);
}
if (newMediaFile == null && newMediaStream == null) {
throw new TelegramApiValidationException("Media can't be empty", this);
}
} else {
if (attachName == null || attachName.isEmpty()) {
throw new TelegramApiValidationException("File_id can't be empty", this);
}
}
}
}

View File

@ -0,0 +1,18 @@
package org.telegram.telegrambots.meta.api.objects;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
/**
* @author Ruben Bermudez
* @version 4.0.0
*/
public class InputFileSerializer extends JsonSerializer<InputFile> {
@Override
public void serialize(InputFile value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
gen.writeObject(value.getAttachName());
}
}

View File

@ -2,7 +2,9 @@ package org.telegram.telegrambots.meta.api.objects;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
import org.telegram.telegrambots.meta.api.objects.games.Animation;
import org.telegram.telegrambots.meta.api.objects.games.Game;
import org.telegram.telegrambots.meta.api.objects.passport.PassportData;
import org.telegram.telegrambots.meta.api.objects.payments.Invoice;
import org.telegram.telegrambots.meta.api.objects.payments.SuccessfulPayment;
import org.telegram.telegrambots.meta.api.objects.stickers.Sticker;
@ -33,6 +35,7 @@ public class Message implements BotApiObject {
private static final String CONTACT_FIELD = "contact";
private static final String LOCATION_FIELD = "location";
private static final String VENUE_FIELD = "venue";
private static final String ANIMATION_FIELD = "animation";
private static final String PINNED_MESSAGE_FIELD = "pinned_message";
private static final String NEWCHATMEMBERS_FIELD = "new_chat_members";
private static final String LEFTCHATMEMBER_FIELD = "left_chat_member";
@ -57,6 +60,7 @@ public class Message implements BotApiObject {
private static final String FORWARDSIGNATURE_FIELD = "forward_signature";
private static final String MEDIAGROUPID_FIELD = "media_group_id";
private static final String CONNECTEDWEBSITE_FIELD = "connected_website";
private static final String PASSPORTDATA_FIELD = "passport_data";
@JsonProperty(MESSAGEID_FIELD)
private Integer messageId; ///< Integer Unique message identifier
@ -102,6 +106,12 @@ public class Message implements BotApiObject {
private Location location; ///< Optional. Message is a shared location, information about the location
@JsonProperty(VENUE_FIELD)
private Venue venue; ///< Optional. Message is a venue, information about the venue
/**
* Optional. Message is an animation, information about the animation.
* For backward compatibility, when this field is set, the document field will be also set
*/
@JsonProperty(ANIMATION_FIELD)
private Animation animation;
@JsonProperty(PINNED_MESSAGE_FIELD)
private Message pinnedMessage; ///< Optional. Specified message was pinned. Note that the Message object in this field will not contain further reply_to_message fields even if it is itself a reply.
@JsonProperty(NEWCHATMEMBERS_FIELD)
@ -178,6 +188,8 @@ public class Message implements BotApiObject {
private String mediaGroupId; ///< Optional. The unique identifier of a media message group this message belongs to
@JsonProperty(CONNECTEDWEBSITE_FIELD)
private String connectedWebsite; ///< Optional. The domain name of the website on which the user has logged in
@JsonProperty(PASSPORTDATA_FIELD)
private PassportData passportData; ///< Optional. Telegram Passport data
public Message() {
super();
@ -241,10 +253,18 @@ public class Message implements BotApiObject {
return sticker;
}
public boolean hasSticker() {
return sticker != null;
}
public Video getVideo() {
return video;
}
public Animation getAnimation() {
return animation;
}
public Contact getContact() {
return contact;
}
@ -417,6 +437,10 @@ public class Message implements BotApiObject {
return videoNote;
}
public boolean hasVideoNote() {
return videoNote != null;
}
public String getAuthorSignature() {
return authorSignature;
}
@ -433,6 +457,18 @@ public class Message implements BotApiObject {
return connectedWebsite;
}
public PassportData getPassportData() {
return passportData;
}
public boolean hasPassportData() {
return passportData != null;
}
public boolean hasAnimation() {
return animation != null;
}
@Override
public String toString() {
return "Message{" +
@ -478,6 +514,7 @@ public class Message implements BotApiObject {
", forwardSignature='" + forwardSignature + '\'' +
", mediaGroupId='" + mediaGroupId + '\'' +
", connectedWebsite='" + connectedWebsite + '\'' +
", passportData=" + passportData +
'}';
}
}

View File

@ -8,12 +8,11 @@ import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief This object represents one special entity in a text message. For example, hashtags,
* This object represents one special entity in a text message. For example, hashtags,
* usernames, URL.
* @date 20 of June of 2015
*/
@SuppressWarnings("WeakerAccess")
public class MessageEntity implements BotApiObject {
private static final String TYPE_FIELD = "type";
private static final String OFFSET_FIELD = "offset";
private static final String LENGTH_FIELD = "length";
@ -23,9 +22,11 @@ public class MessageEntity implements BotApiObject {
* Type of the entity. One of
* mention (@username),
* hashtag,
* cashtag
* bot_command,
* url,
* email,
* phone_number,
* bold (bold text),
* italic (italic text),
* code (monowidth string),

View File

@ -7,14 +7,14 @@ import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief This object represents a venue.
* @date 10 of April of 2016
* This object represents a venue.
*/
public class Venue implements BotApiObject {
private static final String LOCATION_FIELD = "location";
private static final String TITLE_FIELD = "title";
private static final String ADDRESS_FIELD = "address";
private static final String FOURSQUARE_ID_FIELD = "foursquare_id";
private static final String FOURSQUAREID_FIELD = "foursquare_id";
private static final String FOURSQUARETYPE_FIELD = "foursquare_type";
@JsonProperty(LOCATION_FIELD)
private Location location; ///< Venue location
@ -22,8 +22,10 @@ public class Venue implements BotApiObject {
private String title; ///< Name of the venue
@JsonProperty(ADDRESS_FIELD)
private String address; ///< Address of the venue
@JsonProperty(FOURSQUARE_ID_FIELD)
@JsonProperty(FOURSQUAREID_FIELD)
private String foursquareId; ///< Optional. Foursquare identifier of the venue
@JsonProperty(FOURSQUARETYPE_FIELD)
private String foursquareType; ///< Optional. Foursquare type of the venue.
public Venue() {
super();
@ -45,13 +47,18 @@ public class Venue implements BotApiObject {
return foursquareId;
}
public String getFoursquareType() {
return foursquareType;
}
@Override
public String toString() {
return "Venue{" +
"location=" + location +
", title=" + title +
", address=" + address +
", foursquareId=" + foursquareId +
", title='" + title + '\'' +
", address='" + address + '\'' +
", foursquareId='" + foursquareId + '\'' +
", foursquareType='" + foursquareType + '\'' +
'}';
}
}

View File

@ -24,11 +24,13 @@ import org.telegram.telegrambots.meta.api.objects.PhotoSize;
/**
* @author Ruben Bermudez
* @version 2.4
* @brief This object represents an animation file.
* @date 27 of September of 2016
* This object represents an animation file (GIF or H.264/MPEG-4 AVC video without sound).
*/
public class Animation implements BotApiObject {
private static final String FILEID_FIELD = "file_id";
private static final String WIDTH_FIELD = "width";
private static final String HEIGHT_FIELD = "height";
private static final String DURATION_FIELD = "duration";
private static final String THUMB_FIELD = "thumb";
private static final String FILENAME_FIELD = "file_name";
private static final String MIMETYPE_FIELD = "mime_type";
@ -36,6 +38,12 @@ public class Animation implements BotApiObject {
@JsonProperty(FILEID_FIELD)
private String fileId; ///< Unique file identifier
@JsonProperty(WIDTH_FIELD)
private Integer width; ///< Video width as defined by sender
@JsonProperty(HEIGHT_FIELD)
private Integer height; ///< Video height as defined by sender
@JsonProperty(DURATION_FIELD)
private Integer duration; ///< Duration of the video in seconds as defined by sender
@JsonProperty(THUMB_FIELD)
private PhotoSize thumb; ///< Optional. Animation thumbnail as defined by sender
@JsonProperty(FILENAME_FIELD)
@ -69,10 +77,25 @@ public class Animation implements BotApiObject {
return fileSize;
}
public Integer getWidth() {
return width;
}
public Integer getHeight() {
return height;
}
public Integer getDuration() {
return duration;
}
@Override
public String toString() {
return "Animation{" +
"fileId='" + fileId + '\'' +
", width=" + width +
", height=" + height +
", duration=" + duration +
", thumb=" + thumb +
", fileName='" + fileName + '\'' +
", mimetype='" + mimetype + '\'' +

View File

@ -7,16 +7,16 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief Represents the content of a contact message to be sent as the result of an inline query
* Represents the content of a contact message to be sent as the result of an inline query
* @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 InputContactMessageContent implements InputMessageContent {
private static final String PHONE_NUMBER_FIELD = "phone_number";
private static final String FIRST_NAME_FIELD = "first_name";
private static final String LAST_NAME_FIELD = "last_name";
private static final String VCARD_FIELD = "vcard";
@JsonProperty(PHONE_NUMBER_FIELD)
private String phoneNumber; ///< Contact's phone number
@ -24,6 +24,8 @@ public class InputContactMessageContent implements InputMessageContent {
private String firstName; ///< Contact's first name
@JsonProperty(LAST_NAME_FIELD)
private String lastName; ///< Optional. Contact's last name
@JsonProperty(VCARD_FIELD)
private String vCard; ///< Optional. Additional data about the contact in the form of a vCard, 0-2048 bytes
public InputContactMessageContent() {
super();
@ -56,6 +58,15 @@ public class InputContactMessageContent implements InputMessageContent {
return this;
}
public String getVCard() {
return vCard;
}
public InputContactMessageContent setVCard(String vCard) {
this.vCard = vCard;
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (phoneNumber == null || phoneNumber.isEmpty()) {
@ -72,6 +83,7 @@ public class InputContactMessageContent implements InputMessageContent {
"phoneNumber='" + phoneNumber + '\'' +
", firstName='" + firstName + '\'' +
", lastName='" + lastName + '\'' +
", vCard='" + vCard + '\'' +
'}';
}
}

View File

@ -7,10 +7,9 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief Represents the content of a venue message to be sent as the result of an inline query.
* Represents the content of a venue message to be sent as the result of an inline query.
* @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 InputVenueMessageContent implements InputMessageContent {
@ -18,7 +17,8 @@ public class InputVenueMessageContent implements InputMessageContent {
private static final String LONGITUDE_FIELD = "longitude";
private static final String TITLE_FIELD = "title";
private static final String ADDRESS_FIELD = "address";
private static final String FOURSQUARE_ID_FIELD = "foursquare_id";
private static final String FOURSQUAREID_FIELD = "foursquare_id";
private static final String FOURSQUARETYPE_FIELD = "foursquare_type";
@JsonProperty(LATITUDE_FIELD)
private Float latitude; ///< Latitude of the venue in degrees
@ -28,8 +28,11 @@ public class InputVenueMessageContent implements InputMessageContent {
private String title; ///< Name of the venue
@JsonProperty(ADDRESS_FIELD)
private String address; ///< Address of the venue
@JsonProperty(FOURSQUARE_ID_FIELD)
@JsonProperty(FOURSQUAREID_FIELD)
private String foursquareId; ///< Optional. Foursquare identifier of the venue, if known
@JsonProperty(FOURSQUARETYPE_FIELD)
private String foursquareType; ///< Optional. Foursquare type of the venue, if known.
public InputVenueMessageContent() {
super();
@ -80,6 +83,15 @@ public class InputVenueMessageContent implements InputMessageContent {
return this;
}
public String getFoursquareType() {
return foursquareType;
}
public InputVenueMessageContent setFoursquareType(String foursquareType) {
this.foursquareType = foursquareType;
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (latitude == null) {
@ -99,11 +111,12 @@ public class InputVenueMessageContent implements InputMessageContent {
@Override
public String toString() {
return "InputVenueMessageContent{" +
"latitude='" + latitude + '\'' +
", longitude='" + longitude + '\'' +
"latitude=" + latitude +
", longitude=" + longitude +
", title='" + title + '\'' +
", address='" + address + '\'' +
", foursquareId='" + foursquareId + '\'' +
", foursquareType='" + foursquareType + '\'' +
'}';
}
}

View File

@ -9,12 +9,11 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief Represents a contact with a phone number. By default, this contact will be sent by the
* Represents a contact with a phone number. By default, this contact will be sent by the
* user. Alternatively, you can use input_message_content to send a message with the specified
* content instead of the contact.
* @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 InlineQueryResultContact implements InlineQueryResult {
@ -28,6 +27,7 @@ public class InlineQueryResultContact implements InlineQueryResult {
private static final String THUMBURL_FIELD = "thumb_url";
private static final String THUMBWIDTH_FIELD = "thumb_width";
private static final String THUMBHEIGHT_FIELD = "thumb_height";
private static final String VCARD_FIELD = "vcard";
@JsonProperty(TYPE_FIELD)
private final String type = "contact"; ///< Type of the result, must be "contact"
@ -49,6 +49,8 @@ public class InlineQueryResultContact implements InlineQueryResult {
private Integer thumbWidth; ///< Optional. Thumbnail width
@JsonProperty(THUMBHEIGHT_FIELD)
private Integer thumbHeight; ///< Optional. Thumbnail height
@JsonProperty(VCARD_FIELD)
private String vCard; ///< Optional. Additional data about the contact in the form of a vCard, 0-2048 bytes
public InlineQueryResultContact() {
super();
@ -139,6 +141,15 @@ public class InlineQueryResultContact implements InlineQueryResult {
return this;
}
public String getvCard() {
return vCard;
}
public InlineQueryResultContact setvCard(String vCard) {
this.vCard = vCard;
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (id == null || id.isEmpty()) {
@ -165,12 +176,13 @@ public class InlineQueryResultContact implements InlineQueryResult {
", id='" + id + '\'' +
", phoneNumber='" + phoneNumber + '\'' +
", firstName='" + firstName + '\'' +
", thumbHeight=" + thumbHeight +
", thumbWidth=" + thumbWidth +
", thumbUrl='" + thumbUrl + '\'' +
", lastName='" + lastName + '\'' +
", inputMessageContent='" + inputMessageContent + '\'' +
", replyMarkup='" + replyMarkup + '\'' +
", replyMarkup=" + replyMarkup +
", inputMessageContent=" + inputMessageContent +
", thumbUrl='" + thumbUrl + '\'' +
", thumbWidth=" + thumbWidth +
", thumbHeight=" + thumbHeight +
", vCard='" + vCard + '\'' +
'}';
}
}

View File

@ -9,11 +9,10 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief Represents a venue. By default, the venue will be sent by the user. Alternatively, you can
* Represents a venue. By default, the venue will be sent by the user. Alternatively, you can
* use input_message_content to send a message with the specified content instead of the venue.
* @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 InlineQueryResultVenue implements InlineQueryResult {
@ -23,12 +22,14 @@ public class InlineQueryResultVenue implements InlineQueryResult {
private static final String LATITUDE_FIELD = "latitude";
private static final String LONGITUDE_FIELD = "longitude";
private static final String ADDRESS_FIELD = "address";
private static final String FOURSQUARE_ID_FIELD = "foursquare_id";
private static final String FOURSQUAREID_FIELD = "foursquare_id";
private static final String REPLY_MARKUP_FIELD = "reply_markup";
private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content";
private static final String THUMBURL_FIELD = "thumb_url";
private static final String THUMBWIDTH_FIELD = "thumb_width";
private static final String THUMBHEIGHT_FIELD = "thumb_height";
private static final String FOURSQUARETYPE_FIELD = "foursquare_type";
@JsonProperty(TYPE_FIELD)
private final String type = "venue"; ///< Type of the result, must be "venue"
@ -42,7 +43,7 @@ public class InlineQueryResultVenue implements InlineQueryResult {
private Float longitude; ///< Venue longitude in degrees
@JsonProperty(ADDRESS_FIELD)
private String address; ///< Address of the venue
@JsonProperty(FOURSQUARE_ID_FIELD)
@JsonProperty(FOURSQUAREID_FIELD)
private String foursquareId; ///< Optional. Foursquare identifier of the venue if known
@JsonProperty(REPLY_MARKUP_FIELD)
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
@ -54,6 +55,8 @@ public class InlineQueryResultVenue implements InlineQueryResult {
private Integer thumbWidth; ///< Optional. Thumbnail width
@JsonProperty(THUMBHEIGHT_FIELD)
private Integer thumbHeight; ///< Optional. Thumbnail height
@JsonProperty(FOURSQUARETYPE_FIELD)
private String foursquareType; ///< Optional. Foursquare type of the venue, if known.
public InlineQueryResultVenue() {
super();
@ -162,6 +165,15 @@ public class InlineQueryResultVenue implements InlineQueryResult {
return this;
}
public String getFoursquareType() {
return foursquareType;
}
public InlineQueryResultVenue setFoursquareType(String foursquareType) {
this.foursquareType = foursquareType;
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (id == null || id.isEmpty()) {
@ -193,16 +205,17 @@ public class InlineQueryResultVenue implements InlineQueryResult {
return "InlineQueryResultVenue{" +
"type='" + type + '\'' +
", id='" + id + '\'' +
", mimeType='" + latitude + '\'' +
", documentUrl='" + longitude + '\'' +
", thumbHeight=" + thumbHeight +
", thumbWidth=" + thumbWidth +
", thumbUrl='" + thumbUrl + '\'' +
", title='" + title + '\'' +
", foursquareId='" + foursquareId + '\'' +
", latitude=" + latitude +
", longitude=" + longitude +
", address='" + address + '\'' +
", inputMessageContent='" + inputMessageContent + '\'' +
", replyMarkup='" + replyMarkup + '\'' +
", foursquareId='" + foursquareId + '\'' +
", replyMarkup=" + replyMarkup +
", inputMessageContent=" + inputMessageContent +
", thumbUrl='" + thumbUrl + '\'' +
", thumbWidth=" + thumbWidth +
", thumbHeight=" + thumbHeight +
", foursquareType='" + foursquareType + '\'' +
'}';
}
}

View File

@ -2,6 +2,7 @@ package org.telegram.telegrambots.meta.api.objects.media;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.telegram.telegrambots.meta.api.interfaces.InputBotApiObject;
import org.telegram.telegrambots.meta.api.interfaces.Validable;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
@ -13,23 +14,25 @@ import java.io.InputStream;
* @author Ruben Bermudez
* @version 3.5
*/
@SuppressWarnings({"WeakerAccess", "unchecked"})
@JsonSerialize(using = InputMediaSerializer.class)
public abstract class InputMedia<T> implements InputBotApiObject, Validable {
protected static final String TYPE_FIELD = "type";
private static final String MEDIA_FIELD = "media";
private static final String CAPTION_FIELD = "caption";
private static final String PARSEMODE_FIELD = "parse_mode";
public static final String TYPE_FIELD = "type";
public static final String MEDIA_FIELD = "media";
public static final String CAPTION_FIELD = "caption";
public static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(MEDIA_FIELD)
/**
* File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended),
* pass an HTTP URL for Telegram to get a file from the Internet, or pass "attach://<file_attach_name>"
* to upload a new one using multipart/form-data under <file_attach_name> name.
*/
@JsonProperty(MEDIA_FIELD)
private String media;
@JsonProperty(CAPTION_FIELD)
private String caption; ///< Optional. Caption of the media to be sent, 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.
private String parseMode; ///< Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
@JsonIgnore
private boolean isNewMedia; ///< True to upload a new media, false to use a fileId or URL
@JsonIgnore
@ -140,4 +143,17 @@ public abstract class InputMedia<T> implements InputBotApiObject, Validable {
@JsonProperty(TYPE_FIELD)
public abstract String getType();
@Override
public String toString() {
return "InputMedia{" +
"media='" + media + '\'' +
", caption='" + caption + '\'' +
", parseMode='" + parseMode + '\'' +
", isNewMedia=" + isNewMedia +
", mediaName='" + mediaName + '\'' +
", newMediaFile=" + newMediaFile +
", newMediaStream=" + newMediaStream +
'}';
}
}

View File

@ -0,0 +1,100 @@
package org.telegram.telegrambots.meta.api.objects.media;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.api.objects.InputFile;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 4.0.0
*
* Represents an animation file (GIF or H.264/MPEG-4 AVC video without sound) to be sent.
*/
@SuppressWarnings("unused")
public class InputMediaAnimation extends InputMedia<InputMediaAnimation> {
private static final String TYPE = "animation";
public static final String WIDTH_FIELD = "width";
public static final String HEIGHT_FIELD = "height";
public static final String DURATION_FIELD = "duration";
public static final String THUMB_FIELD = "thumb";
@JsonProperty(WIDTH_FIELD)
private Integer width; ///< Optional. Animation width
@JsonProperty(HEIGHT_FIELD)
private Integer height; ///< Optional. Animation height
@JsonProperty(DURATION_FIELD)
private Integer duration; ///< Optional. Animation duration
/**
* Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size.
* A thumbnails width and height should not exceed 90.
* Ignored if the file is not uploaded using multipart/form-data.
* Thumbnails cant be reused and can be only uploaded as a new file, so you can pass attach://<file_attach_name>
* if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
*/
private InputFile thumb;
public InputMediaAnimation() {
super();
}
public InputMediaAnimation(String media, String caption) {
super(media, caption);
}
public Integer getWidth() {
return width;
}
public InputMediaAnimation setWidth(Integer width) {
this.width = width;
return this;
}
public Integer getHeight() {
return height;
}
public InputMediaAnimation setHeight(Integer height) {
this.height = height;
return this;
}
public Integer getDuration() {
return duration;
}
public InputMediaAnimation setDuration(Integer duration) {
this.duration = duration;
return this;
}
public InputFile getThumb() {
return thumb;
}
public InputMediaAnimation setThumb(InputFile thumb) {
this.thumb = thumb;
return this;
}
@Override
public String getType() {
return TYPE;
}
@Override
public void validate() throws TelegramApiValidationException {
super.validate();
}
@Override
public String toString() {
return "InputMediaAnimation{" +
"width=" + width +
", height=" + height +
", duration=" + duration +
", thumb=" + thumb +
"} " + super.toString();
}
}

View File

@ -0,0 +1,101 @@
package org.telegram.telegrambots.meta.api.objects.media;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.api.objects.InputFile;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 4.0.0
*
* Represents an audio file to be treated as music to be sent.
*/
@SuppressWarnings({"unused", "WeakerAccess"})
public class InputMediaAudio extends InputMedia<InputMediaAudio> {
private static final String TYPE = "audio";
public static final String DURATION_FIELD = "duration";
public static final String PERFORMER_FIELD = "performer";
public static final String TITLE_FIELD = "title";
public static final String THUMB_FIELD = "thumb";
@JsonProperty(DURATION_FIELD)
private Integer duration; ///< Optional. Duration of the audio in seconds
@JsonProperty(PERFORMER_FIELD)
private String performer; ///< Optional. Performer of the audio
@JsonProperty(TITLE_FIELD)
private String title; ///< Optional. Title of the audio
/**
* Optional. Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size.
* A thumbnails width and height should not exceed 90.
* Ignored if the file is not uploaded using multipart/form-data.
* Thumbnails cant be reused and can be only uploaded as a new file, so you can pass attach://<file_attach_name>
* if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
*/
private InputFile thumb;
public InputMediaAudio() {
super();
}
public InputMediaAudio(String media, String caption) {
super(media, caption);
}
public Integer getDuration() {
return duration;
}
public InputMediaAudio setDuration(Integer duration) {
this.duration = duration;
return this;
}
public String getPerformer() {
return performer;
}
public InputMediaAudio setPerformer(String performer) {
this.performer = performer;
return this;
}
public String getTitle() {
return title;
}
public InputMediaAudio setTitle(String title) {
this.title = title;
return this;
}
public InputFile getThumb() {
return thumb;
}
public InputMediaAudio setThumb(InputFile thumb) {
this.thumb = thumb;
return this;
}
@Override
public String getType() {
return TYPE;
}
@Override
public void validate() throws TelegramApiValidationException {
super.validate();
}
@Override
public String toString() {
return "InputMediaAudio{" +
"duration=" + duration +
", performer=" + performer +
", title=" + title +
", thumb=" + thumb +
"} " + super.toString();
}
}

View File

@ -0,0 +1,59 @@
package org.telegram.telegrambots.meta.api.objects.media;
import org.telegram.telegrambots.meta.api.objects.InputFile;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 4.0.0
*
* Represents a general file to be sent.
*/
@SuppressWarnings("unused")
public class InputMediaDocument extends InputMedia<InputMediaDocument> {
private static final String TYPE = "document";
public static final String THUMB_FIELD = "thumb";
/**
* Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size.
* A thumbnails width and height should not exceed 90.
* Ignored if the file is not uploaded using multipart/form-data.
* Thumbnails cant be reused and can be only uploaded as a new file, so you can pass attach://<file_attach_name>
* if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
*/
private InputFile thumb;
public InputMediaDocument() {
super();
}
public InputMediaDocument(String media, String caption) {
super(media, caption);
}
public InputFile getThumb() {
return thumb;
}
public InputMediaDocument setThumb(InputFile thumb) {
this.thumb = thumb;
return this;
}
@Override
public String getType() {
return TYPE;
}
@Override
public void validate() throws TelegramApiValidationException {
super.validate();
}
@Override
public String toString() {
return "InputMediaDocument{" +
"thumb=" + thumb +
"} " + super.toString();
}
}

View File

@ -29,4 +29,9 @@ public class InputMediaPhoto extends InputMedia<InputMediaPhoto> {
public void validate() throws TelegramApiValidationException {
super.validate();
}
@Override
public String toString() {
return "InputMediaPhoto{} " + super.toString();
}
}

View File

@ -0,0 +1,82 @@
package org.telegram.telegrambots.meta.api.objects.media;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
/**
* @author Ruben Bermudez
* @version 4.0.0
*
* JSON serializer for InputMedia type
*/
public class InputMediaSerializer extends JsonSerializer<InputMedia> {
@Override
public void serialize(InputMedia value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
gen.writeStartObject();
gen.writeStringField(InputMedia.MEDIA_FIELD, value.getMedia());
gen.writeStringField(InputMedia.TYPE_FIELD, value.getType());
if (value.getCaption() != null) {
gen.writeStringField(InputMedia.CAPTION_FIELD, value.getCaption());
}
if (value.getParseMode() != null) {
gen.writeStringField(InputMedia.PARSEMODE_FIELD, value.getParseMode());
}
if (value instanceof InputMediaAudio) {
InputMediaAudio audio = (InputMediaAudio) value;
if (audio.getThumb() != null) {
gen.writeStringField(InputMediaAudio.THUMB_FIELD, audio.getThumb().getAttachName());
}
if (audio.getDuration() != null) {
gen.writeNumberField(InputMediaAudio.DURATION_FIELD, audio.getDuration());
}
if (audio.getPerformer() != null) {
gen.writeStringField(InputMediaAudio.PERFORMER_FIELD, audio.getPerformer());
}
if (audio.getTitle() != null) {
gen.writeStringField(InputMediaAudio.TITLE_FIELD, audio.getTitle());
}
} else if (value instanceof InputMediaAnimation) {
InputMediaAnimation animation = (InputMediaAnimation) value;
if (animation.getThumb() != null) {
gen.writeStringField(InputMediaAnimation.THUMB_FIELD, animation.getThumb().getAttachName());
}
if (animation.getDuration() != null) {
gen.writeNumberField(InputMediaAnimation.DURATION_FIELD, animation.getDuration());
}
if (animation.getHeight() != null) {
gen.writeNumberField(InputMediaAnimation.HEIGHT_FIELD, animation.getHeight());
}
if (animation.getWidth() != null) {
gen.writeNumberField(InputMediaAnimation.WIDTH_FIELD, animation.getWidth());
}
} else if (value instanceof InputMediaDocument) {
InputMediaDocument document = (InputMediaDocument) value;
if (document.getThumb() != null) {
gen.writeStringField(InputMediaDocument.THUMB_FIELD, document.getThumb().getAttachName());
}
} else if (value instanceof InputMediaVideo) {
InputMediaVideo video = (InputMediaVideo) value;
if (video.getThumb() != null) {
gen.writeStringField(InputMediaVideo.THUMB_FIELD, video.getThumb().getAttachName());
}
if (video.getDuration() != null) {
gen.writeNumberField(InputMediaVideo.DURATION_FIELD, video.getDuration());
}
if (video.getHeight() != null) {
gen.writeNumberField(InputMediaVideo.HEIGHT_FIELD, video.getHeight());
}
if (video.getWidth() != null) {
gen.writeNumberField(InputMediaVideo.WIDTH_FIELD, video.getWidth());
}
if (video.getSupportsStreaming() != null) {
gen.writeBooleanField(InputMediaVideo.SUPPORTSSTREAMING_FIELD, video.getSupportsStreaming());
}
}
gen.writeEndObject();
}
}

View File

@ -1,6 +1,7 @@
package org.telegram.telegrambots.meta.api.objects.media;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.api.objects.InputFile;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
/**
@ -9,23 +10,33 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
*
* Represents a video.
*/
@SuppressWarnings("unused")
@SuppressWarnings({"unused", "WeakerAccess"})
public class InputMediaVideo extends InputMedia<InputMediaVideo> {
private static final String TYPE = "video";
private static final String WIDTH_FIELD = "width";
private static final String HEIGHT_FIELD = "height";
private static final String DURATION_FIELD = "duration";
private static final String SUPPORTSSTREAMING_FIELD = "supports_streaming";
public static final String WIDTH_FIELD = "width";
public static final String HEIGHT_FIELD = "height";
public static final String DURATION_FIELD = "duration";
public static final String SUPPORTSSTREAMING_FIELD = "supports_streaming";
public static final String THUMB_FIELD = "thumb";
@JsonProperty(WIDTH_FIELD)
private int width; ///< Optional. Video width
private Integer width; ///< Optional. Video width
@JsonProperty(HEIGHT_FIELD)
private int height; ///< Optional. Video height
private Integer height; ///< Optional. Video height
@JsonProperty(DURATION_FIELD)
private int duration; ///< Optional. Video duration
private Integer duration; ///< Optional. Video duration
@JsonProperty(SUPPORTSSTREAMING_FIELD)
private Boolean supportsStreaming; ///< Optional. Pass True, if the uploaded video is suitable for streaming
/**
* Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size.
* A thumbnails width and height should not exceed 90.
* Ignored if the file is not uploaded using multipart/form-data.
* Thumbnails cant be reused and can be only uploaded as a new file, so you can pass attach://<file_attach_name>
* if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
*/
@JsonProperty(THUMB_FIELD)
private InputFile thumb;
public InputMediaVideo() {
super();
@ -35,33 +46,51 @@ public class InputMediaVideo extends InputMedia<InputMediaVideo> {
super(media, caption);
}
public int getWidth() {
public Integer getWidth() {
return width;
}
public InputMediaVideo setWidth(int width) {
public InputMediaVideo setWidth(Integer width) {
this.width = width;
return this;
}
public int getHeight() {
public Integer getHeight() {
return height;
}
public InputMediaVideo setHeight(int height) {
public InputMediaVideo setHeight(Integer height) {
this.height = height;
return this;
}
public int getDuration() {
public Integer getDuration() {
return duration;
}
public InputMediaVideo setDuration(int duration) {
public InputMediaVideo setDuration(Integer duration) {
this.duration = duration;
return this;
}
public Boolean getSupportsStreaming() {
return supportsStreaming;
}
public InputMediaVideo setSupportsStreaming(Boolean supportsStreaming) {
this.supportsStreaming = supportsStreaming;
return this;
}
public InputFile getThumb() {
return thumb;
}
public InputMediaVideo setThumb(InputFile thumb) {
this.thumb = thumb;
return this;
}
@Override
public String getType() {
return TYPE;
@ -71,4 +100,14 @@ public class InputMediaVideo extends InputMedia<InputMediaVideo> {
public void validate() throws TelegramApiValidationException {
super.validate();
}
@Override
public String toString() {
return "InputMediaVideo{" +
"width=" + width +
", height=" + height +
", duration=" + duration +
", supportsStreaming=" + supportsStreaming +
"} " + super.toString();
}
}

View File

@ -0,0 +1,57 @@
package org.telegram.telegrambots.meta.api.objects.passport;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
/**
* @author Ruben Bermudez
* @version 4.0.0
* Contains data required for decrypting and authenticating EncryptedPassportElement.
* See the Telegram Passport Documentation for a complete description of the data decryption and authentication processes.
*/
public class EncryptedCredentials implements BotApiObject {
private static final String DATA_FIELD = "data";
private static final String HASH_FIELD = "hash";
private static final String SECRET_FIELD = "secret";
/**
* Base64-encoded encrypted JSON-serialized data with unique user's payload,
* data hashes and secrets required for EncryptedPassportElement decryption and authentication
*/
@JsonProperty(DATA_FIELD)
private String data;
@JsonProperty(HASH_FIELD)
private String hash; ///< Base64-encoded data hash for data authentication
@JsonProperty(SECRET_FIELD)
private String secret; ///< Base64-encoded secret, encrypted with the bot's public RSA key, required for data decryption
public EncryptedCredentials() {
}
public EncryptedCredentials(String data, String hash, String secret) {
this.data = data;
this.hash = hash;
this.secret = secret;
}
public String getData() {
return data;
}
public String getHash() {
return hash;
}
public String getSecret() {
return secret;
}
@Override
public String toString() {
return "EncryptedCredentials{" +
"data='" + data + '\'' +
", hash='" + hash + '\'' +
", secret='" + secret + '\'' +
'}';
}
}

View File

@ -0,0 +1,132 @@
package org.telegram.telegrambots.meta.api.objects.passport;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
import java.util.List;
/**
* @author Ruben Bermudez
* @version 4.0.0
* Contains information about documents or other Telegram Passport data shared with the bot by the user.
*/
@SuppressWarnings("unused")
public class EncryptedPassportElement implements BotApiObject {
private static final String TYPE_FIELD = "type";
private static final String DATA_FIELD = "data";
private static final String PHONENUMBER_FIELD = "phone_number";
private static final String EMAIL_FIELD = "email";
private static final String FILES_FIELD = "files";
private static final String FRONTSIDE_FIELD = "front_side";
private static final String REVERSESIDE_FIELD = "reverse_side";
private static final String SELFIE_FIELD = "selfie";
/**
* Data type. One of personal_details, passport, driver_license, identity_card, internal_passport,
* address, utility_bill, bank_statement, rental_agreement, passport_registration,
* temporary_registration, phone_number, email.
*/
@JsonProperty(TYPE_FIELD)
private String type;
/**
* Optional. Base64-encoded encrypted Telegram Passport data provided by the user,
* available for personal_details, passport, driver_license, identity_card,
* identity_passport and address types.
* Can be decrypted and verified using the accompanying EncryptedCredentials.
*/
@JsonProperty(DATA_FIELD)
private String data;
@JsonProperty(PHONENUMBER_FIELD)
private String phoneNumber; ///< Optional. User's verified phone number, available only for phone_number type
@JsonProperty(EMAIL_FIELD)
private String email; ///< Optional. User's verified email address, available only for email type
/**
* Optional. Array of files with encrypted documents, provided by the user, available for utility_bill,
* bank_statement, rental_agreement, passport_registration and temporary_registration types.
* Files can be decrypted and verified using the accompanying EncryptedCredentials.
*/
@JsonProperty(FILES_FIELD)
private List<PassportFile> files;
/**
* Optional. File with encrypted document's front side, provided by the user. Available for passport,
* driver_license, identity_card and internal_passport.
* The file can be decrypted and verified using the accompanying EncryptedCredentials.
*/
@JsonProperty(FRONTSIDE_FIELD)
private PassportFile frontSide;
/**
* Optional. File with encrypted document's reverse side, provided by the user. Available for
* driver_license and identity_card.
* The file can be decrypted and verified using the accompanying EncryptedCredentials.
*/
@JsonProperty(REVERSESIDE_FIELD)
private PassportFile reverseSide;
/**
* Optional. File with encrypted selfie of the user with a document, provided by the user,
* can be available for passport, driver_license, identity_card and internal_passport.
* The file can be decrypted and verified using the accompanying EncryptedCredentials.
*/
@JsonProperty(SELFIE_FIELD)
private PassportFile selfie;
public EncryptedPassportElement(String type, String data, String phoneNumber, String email, List<PassportFile> files,
PassportFile frontSide, PassportFile reverseSide, PassportFile selfie) {
this.type = type;
this.data = data;
this.phoneNumber = phoneNumber;
this.email = email;
this.files = files;
this.frontSide = frontSide;
this.reverseSide = reverseSide;
this.selfie = selfie;
}
public EncryptedPassportElement() {
}
public String getType() {
return type;
}
public String getData() {
return data;
}
public String getPhoneNumber() {
return phoneNumber;
}
public String getEmail() {
return email;
}
public List<PassportFile> getFiles() {
return files;
}
public PassportFile getFrontSide() {
return frontSide;
}
public PassportFile getReverseSide() {
return reverseSide;
}
public PassportFile getSelfie() {
return selfie;
}
@Override
public String toString() {
return "EncryptedPassportElement{" +
"type='" + type + '\'' +
", data='" + data + '\'' +
", phoneNumber='" + phoneNumber + '\'' +
", email='" + email + '\'' +
", files=" + files +
", frontSide=" + frontSide +
", reverseSide=" + reverseSide +
", selfie=" + selfie +
'}';
}
}

View File

@ -0,0 +1,45 @@
package org.telegram.telegrambots.meta.api.objects.passport;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
import java.util.List;
/**
* @author Ruben Bermudez
* @version 4.0.0
* Contains information about Telegram Passport data shared with the bot by the user.
*/
public class PassportData implements BotApiObject {
private static final String DATA_FIELD = "data";
private static final String CREDENTIALS_FIELD = "credentials";
@JsonProperty(DATA_FIELD)
private List<EncryptedPassportElement> data; ///< Array with information about documents and other Telegram Passport data that was shared with the bot
@JsonProperty(CREDENTIALS_FIELD)
private EncryptedCredentials credentials; ///< Array with information about documents and other Telegram Passport data shared with the bot.
public PassportData() {
}
public PassportData(List<EncryptedPassportElement> data, EncryptedCredentials credentials) {
this.data = data;
this.credentials = credentials;
}
public List<EncryptedPassportElement> getData() {
return data;
}
public EncryptedCredentials getCredentials() {
return credentials;
}
@Override
public String toString() {
return "PassportData{" +
"data=" + data +
", credentials=" + credentials +
'}';
}
}

View File

@ -0,0 +1,53 @@
package org.telegram.telegrambots.meta.api.objects.passport;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
/**
* @author Ruben Bermudez
* @version 4.0.0
* This object represents a file uploaded to Telegram Passport.
* Currently all Telegram Passport files are in JPEG format when decrypted and don't exceed 10MB.
*/
public class PassportFile implements BotApiObject {
private static final String FILEID_FIELD = "file_id";
private static final String FILESIZE_FIELD = "file_size";
private static final String FILEDATE_FIELD = "file_date";
@JsonProperty(FILEID_FIELD)
private String fileId; ///< Unique identifier for this file
@JsonProperty(FILESIZE_FIELD)
private Integer fileSize; ///< File size
@JsonProperty(FILEDATE_FIELD)
private Integer fileDate; ///< Unix time when the file was uploaded
public PassportFile() {
}
public PassportFile(String fileId, Integer fileSize, Integer fileDate) {
this.fileId = fileId;
this.fileSize = fileSize;
this.fileDate = fileDate;
}
public String getFileId() {
return fileId;
}
public Integer getFileSize() {
return fileSize;
}
public Integer getFileDate() {
return fileDate;
}
@Override
public String toString() {
return "PassportFile{" +
"fileId='" + fileId + '\'' +
", fileSize=" + fileSize +
", fileDate=" + fileDate +
'}';
}
}

View File

@ -0,0 +1,20 @@
package org.telegram.telegrambots.meta.api.objects.passport.dataerror;
import org.telegram.telegrambots.meta.api.interfaces.InputBotApiObject;
import org.telegram.telegrambots.meta.api.interfaces.Validable;
/**
* @author Ruben Bermudez
* @version 4.0.0
*
* This object represents an error in sent Passport Data that should be resolved by the user. It should be one of
*
* PassportElementErrorDataField
* PassportElementErrorFrontSide
* PassportElementErrorReverseSide
* PassportElementErrorSelfie
* PassportElementErrorFile
* PassportElementErrorFiles
*/
public interface PassportElementError extends InputBotApiObject, Validable {
}

View File

@ -0,0 +1,115 @@
package org.telegram.telegrambots.meta.api.objects.passport.dataerror;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 4.0.0
*
* Represents an error in a field of data provided by a user.
* The error is considered resolved when the field's value changes.
*/
public class PassportElementErrorDataField implements PassportElementError {
private static final String SOURCE_FIELD = "source";
private static final String TYPE_FIELD = "type";
private static final String FIELDNAME_FIELD = "field_name";
private static final String DATAHASH_FIELD = "data_hash";
private static final String MESSAGE_FIELD = "message";
@JsonProperty(SOURCE_FIELD)
private final String source = "data"; ///< Error source, must be data
/**
* Type of the Telegram Passport data with the error, one of personal_details, passport, driver_license,
* identity_card, internal_passport, address
*/
@JsonProperty(TYPE_FIELD)
private String type;
@JsonProperty(FIELDNAME_FIELD)
private String fieldName; ///< Name of the data field with the error
@JsonProperty(DATAHASH_FIELD)
private String dataHash; ///< Base64-encoded data hash
@JsonProperty(MESSAGE_FIELD)
private String message; ///< Error message
public PassportElementErrorDataField() {
super();
}
public PassportElementErrorDataField(String type, String fieldName, String dataHash, String message) {
super();
this.type = checkNotNull(type);
this.fieldName = checkNotNull(fieldName);
this.dataHash = checkNotNull(dataHash);
this.message = checkNotNull(message);
}
public String getType() {
return type;
}
public PassportElementErrorDataField setType(String type) {
this.type = checkNotNull(type);
return this;
}
public String getSource() {
return source;
}
public String getFieldName() {
return fieldName;
}
public PassportElementErrorDataField setFieldName(String fieldName) {
this.fieldName = checkNotNull(fieldName);
return this;
}
public String getDataHash() {
return dataHash;
}
public PassportElementErrorDataField setDataHash(String dataHash) {
this.dataHash = checkNotNull(dataHash);
return this;
}
public String getMessage() {
return message;
}
public PassportElementErrorDataField setMessage(String message) {
this.message = checkNotNull(message);
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (fieldName == null || fieldName.isEmpty()) {
throw new TelegramApiValidationException("Field Name parameter can't be empty", this);
}
if (dataHash == null || dataHash.isEmpty()) {
throw new TelegramApiValidationException("Data hash parameter can't be empty", this);
}
if (message == null || message.isEmpty()) {
throw new TelegramApiValidationException("Message parameter can't be empty", this);
}
if (type == null || type.isEmpty()) {
throw new TelegramApiValidationException("Type parameter can't be empty", this);
}
}
@Override
public String toString() {
return "PassportElementErrorDataField{" +
"source='" + source + '\'' +
", type='" + type + '\'' +
", fieldName='" + fieldName + '\'' +
", dataHash='" + dataHash + '\'' +
", message='" + message + '\'' +
'}';
}
}

View File

@ -0,0 +1,98 @@
package org.telegram.telegrambots.meta.api.objects.passport.dataerror;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 4.0.0
*
* Represents an error in a file.
* The error is considered resolved when the file changes.
*/
public class PassportElementErrorFile implements PassportElementError {
private static final String SOURCE_FIELD = "source";
private static final String TYPE_FIELD = "type";
private static final String FILEHASH_FIELD = "file_hash";
private static final String MESSAGE_FIELD = "message";
@JsonProperty(SOURCE_FIELD)
private final String source = "file"; ///< Error source, must be file
/**
* Type of the Telegram Passport data with the error, one of utility_bill,
* bank_statement, rental_agreement, passport_registration, temporary_registration
*/
@JsonProperty(TYPE_FIELD)
private String type;
@JsonProperty(FILEHASH_FIELD)
private String fileHash; ///< Base64-encoded file hash
@JsonProperty(MESSAGE_FIELD)
private String message; ///< Error message
public PassportElementErrorFile() {
super();
}
public PassportElementErrorFile(String type, String fileHash, String message) {
super();
this.type = checkNotNull(type);
this.fileHash = checkNotNull(fileHash);
this.message = checkNotNull(message);
}
public String getType() {
return type;
}
public PassportElementErrorFile setType(String type) {
this.type = checkNotNull(type);
return this;
}
public String getSource() {
return source;
}
public String getFileHash() {
return fileHash;
}
public PassportElementErrorFile setFileHash(String fileHash) {
this.fileHash = fileHash;
return this;
}
public String getMessage() {
return message;
}
public PassportElementErrorFile setMessage(String message) {
this.message = checkNotNull(message);
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (fileHash == null || fileHash.isEmpty()) {
throw new TelegramApiValidationException("File hash parameter can't be empty", this);
}
if (message == null || message.isEmpty()) {
throw new TelegramApiValidationException("Message parameter can't be empty", this);
}
if (type == null || type.isEmpty()) {
throw new TelegramApiValidationException("Type parameter can't be empty", this);
}
}
@Override
public String toString() {
return "PassportElementErrorFile{" +
"source='" + source + '\'' +
", type='" + type + '\'' +
", fileHash='" + fileHash + '\'' +
", message='" + message + '\'' +
'}';
}
}

View File

@ -0,0 +1,110 @@
package org.telegram.telegrambots.meta.api.objects.passport.dataerror;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.util.ArrayList;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 4.0.0
*
* Represents an error in a list of attached files.
* The error is considered resolved when the file list changes.
*/
public class PassportElementErrorFiles implements PassportElementError {
private static final String SOURCE_FIELD = "source";
private static final String TYPE_FIELD = "type";
private static final String FILEHASHES_FIELD = "file_hashes";
private static final String MESSAGE_FIELD = "message";
@JsonProperty(SOURCE_FIELD)
private final String source = "file"; ///< Error source, must be file
/**
* Type of the Telegram Passport data with the error, one of utility_bill,
* bank_statement, rental_agreement, passport_registration, temporary_registration
*/
@JsonProperty(TYPE_FIELD)
private String type;
@JsonProperty(FILEHASHES_FIELD)
private List<String> fileHashes; ///< List of base64-encoded file hashes
@JsonProperty(MESSAGE_FIELD)
private String message; ///< Error message
public PassportElementErrorFiles() {
super();
}
public PassportElementErrorFiles(String type, List<String> fileHashes, String message) {
super();
this.type = checkNotNull(type);
this.fileHashes = checkNotNull(fileHashes);
this.message = checkNotNull(message);
}
public String getType() {
return type;
}
public PassportElementErrorFiles setType(String type) {
this.type = checkNotNull(type);
return this;
}
public String getSource() {
return source;
}
public List<String> getFileHashes() {
return fileHashes;
}
public PassportElementErrorFiles setFileHashes(List<String> fileHashes) {
this.fileHashes = checkNotNull(fileHashes);
return this;
}
public PassportElementErrorFiles addFileHash(String fileHash) {
fileHash = checkNotNull(fileHash);
if (fileHashes == null) {
fileHashes = new ArrayList<>();
}
fileHashes.add(fileHash);
return this;
}
public String getMessage() {
return message;
}
public PassportElementErrorFiles setMessage(String message) {
this.message = checkNotNull(message);
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (fileHashes == null || fileHashes.isEmpty()) {
throw new TelegramApiValidationException("File hash parameter can't be empty", this);
}
if (message == null || message.isEmpty()) {
throw new TelegramApiValidationException("Message parameter can't be empty", this);
}
if (type == null || type.isEmpty()) {
throw new TelegramApiValidationException("Type parameter can't be empty", this);
}
}
@Override
public String toString() {
return "PassportElementErrorFile{" +
"source='" + source + '\'' +
", type='" + type + '\'' +
", fileHashes='" + fileHashes + '\'' +
", message='" + message + '\'' +
'}';
}
}

View File

@ -0,0 +1,98 @@
package org.telegram.telegrambots.meta.api.objects.passport.dataerror;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 4.0.0
*
* Represents an error in a file with a documents front side.
* The error is considered resolved when the file with the documents front side changes.
*/
public class PassportElementErrorFrontSide implements PassportElementError {
private static final String SOURCE_FIELD = "source";
private static final String TYPE_FIELD = "type";
private static final String FILEHASH_FIELD = "file_hash";
private static final String MESSAGE_FIELD = "message";
@JsonProperty(SOURCE_FIELD)
private final String source = "front_side"; ///< Error source, must be front_side
/**
* Type of the Telegram Passport data with the error, one of passport,
* driver_license, identity_card, internal_passport
*/
@JsonProperty(TYPE_FIELD)
private String type;
@JsonProperty(FILEHASH_FIELD)
private String fileHash; ///< Base64-encoded file with document's front side hash
@JsonProperty(MESSAGE_FIELD)
private String message; ///< Error message
public PassportElementErrorFrontSide() {
super();
}
public PassportElementErrorFrontSide(String type, String fileHash, String message) {
super();
this.type = checkNotNull(type);
this.fileHash = checkNotNull(fileHash);
this.message = checkNotNull(message);
}
public String getType() {
return type;
}
public PassportElementErrorFrontSide setType(String type) {
this.type = checkNotNull(type);
return this;
}
public String getSource() {
return source;
}
public String getFileHash() {
return fileHash;
}
public PassportElementErrorFrontSide setFileHash(String fileHash) {
this.fileHash = fileHash;
return this;
}
public String getMessage() {
return message;
}
public PassportElementErrorFrontSide setMessage(String message) {
this.message = checkNotNull(message);
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (fileHash == null || fileHash.isEmpty()) {
throw new TelegramApiValidationException("File hash parameter can't be empty", this);
}
if (message == null || message.isEmpty()) {
throw new TelegramApiValidationException("Message parameter can't be empty", this);
}
if (type == null || type.isEmpty()) {
throw new TelegramApiValidationException("Type parameter can't be empty", this);
}
}
@Override
public String toString() {
return "PassportElementErrorFrontSide{" +
"source='" + source + '\'' +
", type='" + type + '\'' +
", fileHash='" + fileHash + '\'' +
", message='" + message + '\'' +
'}';
}
}

View File

@ -0,0 +1,97 @@
package org.telegram.telegrambots.meta.api.objects.passport.dataerror;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 4.0.0
*
* Represents an error in a file with a documents reverse side.
* The error is considered resolved when the file with the documents reverse side changes.
*/
public class PassportElementErrorReverseSide implements PassportElementError {
private static final String SOURCE_FIELD = "source";
private static final String TYPE_FIELD = "type";
private static final String FILEHASH_FIELD = "file_hash";
private static final String MESSAGE_FIELD = "message";
@JsonProperty(SOURCE_FIELD)
private final String source = "reverse_side"; ///< Error source, must be reverse_side
/**
* Type of the Telegram Passport data with the error, one of driver_license, identity_card
*/
@JsonProperty(TYPE_FIELD)
private String type;
@JsonProperty(FILEHASH_FIELD)
private String fileHash; ///< Base64-encoded hash of file with document's reverse side
@JsonProperty(MESSAGE_FIELD)
private String message; ///< Error message
public PassportElementErrorReverseSide() {
super();
}
public PassportElementErrorReverseSide(String type, String fileHash, String message) {
super();
this.type = checkNotNull(type);
this.fileHash = checkNotNull(fileHash);
this.message = checkNotNull(message);
}
public String getType() {
return type;
}
public PassportElementErrorReverseSide setType(String type) {
this.type = checkNotNull(type);
return this;
}
public String getSource() {
return source;
}
public String getFileHash() {
return fileHash;
}
public PassportElementErrorReverseSide setFileHash(String fileHash) {
this.fileHash = fileHash;
return this;
}
public String getMessage() {
return message;
}
public PassportElementErrorReverseSide setMessage(String message) {
this.message = checkNotNull(message);
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (fileHash == null || fileHash.isEmpty()) {
throw new TelegramApiValidationException("File hash parameter can't be empty", this);
}
if (message == null || message.isEmpty()) {
throw new TelegramApiValidationException("Message parameter can't be empty", this);
}
if (type == null || type.isEmpty()) {
throw new TelegramApiValidationException("Type parameter can't be empty", this);
}
}
@Override
public String toString() {
return "PassportElementErrorReverseSide{" +
"source='" + source + '\'' +
", type='" + type + '\'' +
", fileHash='" + fileHash + '\'' +
", message='" + message + '\'' +
'}';
}
}

View File

@ -0,0 +1,98 @@
package org.telegram.telegrambots.meta.api.objects.passport.dataerror;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 4.0.0
*
* Represents an error in a file with a selfie.
* The error is considered resolved when the file with the selfie changes.
*/
public class PassportElementErrorSelfie implements PassportElementError {
private static final String SOURCE_FIELD = "source";
private static final String TYPE_FIELD = "type";
private static final String FILEHASH_FIELD = "file_hash";
private static final String MESSAGE_FIELD = "message";
@JsonProperty(SOURCE_FIELD)
private final String source = "selfie"; ///< Error source, must be selfie
/**
* Type of the Telegram Passport data with the error, one of passport,
* driver_license, identity_card, internal_passport
*/
@JsonProperty(TYPE_FIELD)
private String type;
@JsonProperty(FILEHASH_FIELD)
private String fileHash; ///< Base64-encoded hash of file with selfie
@JsonProperty(MESSAGE_FIELD)
private String message; ///< Error message
public PassportElementErrorSelfie() {
super();
}
public PassportElementErrorSelfie(String type, String fileHash, String message) {
super();
this.type = checkNotNull(type);
this.fileHash = checkNotNull(fileHash);
this.message = checkNotNull(message);
}
public String getType() {
return type;
}
public PassportElementErrorSelfie setType(String type) {
this.type = checkNotNull(type);
return this;
}
public String getSource() {
return source;
}
public String getFileHash() {
return fileHash;
}
public PassportElementErrorSelfie setFileHash(String fileHash) {
this.fileHash = fileHash;
return this;
}
public String getMessage() {
return message;
}
public PassportElementErrorSelfie setMessage(String message) {
this.message = checkNotNull(message);
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (fileHash == null || fileHash.isEmpty()) {
throw new TelegramApiValidationException("File hash parameter can't be empty", this);
}
if (message == null || message.isEmpty()) {
throw new TelegramApiValidationException("Message parameter can't be empty", this);
}
if (type == null || type.isEmpty()) {
throw new TelegramApiValidationException("Type parameter can't be empty", this);
}
}
@Override
public String toString() {
return "PassportElementErrorSelfie{" +
"source='" + source + '\'' +
", type='" + type + '\'' +
", fileHash='" + fileHash + '\'' +
", message='" + message + '\'' +
'}';
}
}

View File

@ -13,7 +13,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief This object represents one button of an inline keyboard. You must use exactly one of the
* This object represents one button of an inline keyboard. You must use exactly one of the
* optional fields.
* @note This will only work in Telegram versions released after 9 April, 2016. Older clients will
* display unsupported message.
@ -31,7 +31,7 @@ public class InlineKeyboardButton implements InputBotApiObject, Validable {
@JsonProperty(TEXT_FIELD)
private String text; ///< Label text on the button
@JsonProperty(URL_FIELD)
private String url; ///< Optional. HTTP url to be opened when button is pressed
private String url; ///< Optional. HTTP or tg:// url to be opened when button is pressed
@JsonProperty(CALLBACK_DATA_FIELD)
private String callbackData; ///< Optional. Data to be sent in a callback query to the bot when button is pressed
/**

View File

@ -25,11 +25,4 @@ public interface BotSession {
* @return True if the bot is running, false otherwise
*/
boolean isRunning();
/**
* @deprecated Use @link{{@link #stop()}} instead
*/
default void close() {
this.stop();
}
}

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-spring-boot-starter</artifactId>
<version>3.6.2</version>
<version>4.0.0</version>
<packaging>jar</packaging>
<name>Telegram Bots Spring Boot Starter</name>
@ -59,7 +59,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<bots.version>3.6.2</bots.version>
<bots.version>4.0.0</bots.version>
<spring-boot.version>2.0.2.RELEASE</spring-boot.version>
</properties>

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>3.6.2</version>
<version>4.0.0</version>
<packaging>jar</packaging>
<name>Telegram Bots</name>
@ -66,7 +66,7 @@
<jackson.version>2.8.7</jackson.version>
<jacksonanotation.version>2.8.0</jacksonanotation.version>
<commonio.version>2.5</commonio.version>
<bots.version>3.6.2</bots.version>
<bots.version>4.0.0</bots.version>
</properties>
<dependencyManagement>

View File

@ -1,5 +1,6 @@
package org.telegram.telegrambots.bots;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.io.FileUtils;
import org.apache.http.HttpEntity;
@ -12,20 +13,25 @@ import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;
import org.telegram.telegrambots.facilities.TelegramHttpClientBuilder;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.methods.groupadministration.SetChatPhoto;
import org.telegram.telegrambots.meta.api.methods.send.*;
import org.telegram.telegrambots.meta.api.methods.stickers.AddStickerToSet;
import org.telegram.telegrambots.meta.api.methods.stickers.CreateNewStickerSet;
import org.telegram.telegrambots.meta.api.methods.stickers.UploadStickerFile;
import org.telegram.telegrambots.meta.api.methods.updatingmessages.EditMessageMedia;
import org.telegram.telegrambots.meta.api.objects.File;
import org.telegram.telegrambots.meta.api.objects.InputFile;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.media.InputMedia;
import org.telegram.telegrambots.meta.api.objects.media.InputMediaAudio;
import org.telegram.telegrambots.meta.api.objects.media.InputMediaDocument;
import org.telegram.telegrambots.meta.api.objects.media.InputMediaVideo;
import org.telegram.telegrambots.meta.bots.AbsSender;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import org.telegram.telegrambots.facilities.TelegramHttpClientBuilder;
import org.telegram.telegrambots.meta.updateshandlers.DownloadFileCallback;
import org.telegram.telegrambots.meta.updateshandlers.SentCallback;
@ -44,10 +50,9 @@ import static org.telegram.telegrambots.Constants.SOCKET_TIMEOUT;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief Implementation of all the methods needed to interact with Telegram Servers
* @date 14 of January of 2016
* Implementation of all the methods needed to interact with Telegram Servers
*/
@SuppressWarnings("unused")
@SuppressWarnings({"unused", "WeakerAccess"})
public abstract class DefaultAbsSender extends AbsSender {
private static final ContentType TEXT_PLAIN_CONTENT_TYPE = ContentType.create("text/plain", StandardCharsets.UTF_8);
@ -59,6 +64,7 @@ public abstract class DefaultAbsSender extends AbsSender {
protected DefaultAbsSender(DefaultBotOptions options) {
super();
this.exe = Executors.newFixedThreadPool(options.getMaxThreads());
this.options = options;
@ -139,7 +145,7 @@ public abstract class DefaultAbsSender extends AbsSender {
// Specific Send Requests
@Override
public final Message sendDocument(SendDocument sendDocument) throws TelegramApiException {
public final Message execute(SendDocument sendDocument) throws TelegramApiException {
assertParamNotNull(sendDocument, "sendDocument");
sendDocument.validate();
@ -151,17 +157,9 @@ public abstract class DefaultAbsSender extends AbsSender {
builder.setLaxMode();
builder.setCharset(StandardCharsets.UTF_8);
builder.addTextBody(SendDocument.CHATID_FIELD, sendDocument.getChatId(), TEXT_PLAIN_CONTENT_TYPE);
if (sendDocument.isNewDocument()) {
if (sendDocument.getNewDocumentFile() != null) {
builder.addBinaryBody(SendDocument.DOCUMENT_FIELD, sendDocument.getNewDocumentFile());
} else if (sendDocument.getNewDocumentStream() != null) {
builder.addBinaryBody(SendDocument.DOCUMENT_FIELD, sendDocument.getNewDocumentStream(), ContentType.APPLICATION_OCTET_STREAM, sendDocument.getDocumentName());
} else {
builder.addBinaryBody(SendDocument.DOCUMENT_FIELD, new java.io.File(sendDocument.getDocument()), ContentType.APPLICATION_OCTET_STREAM, sendDocument.getDocumentName());
}
} else {
builder.addTextBody(SendDocument.DOCUMENT_FIELD, sendDocument.getDocument(), TEXT_PLAIN_CONTENT_TYPE);
}
addInputFile(builder, sendDocument.getDocument(), SendDocument.DOCUMENT_FIELD, true);
if (sendDocument.getReplyMarkup() != null) {
builder.addTextBody(SendDocument.REPLYMARKUP_FIELD, objectMapper.writeValueAsString(sendDocument.getReplyMarkup()), TEXT_PLAIN_CONTENT_TYPE);
}
@ -177,6 +175,12 @@ public abstract class DefaultAbsSender extends AbsSender {
if (sendDocument.getDisableNotification() != null) {
builder.addTextBody(SendDocument.DISABLENOTIFICATION_FIELD, sendDocument.getDisableNotification().toString(), TEXT_PLAIN_CONTENT_TYPE);
}
if (sendDocument.getThumb() != null) {
addInputFile(builder, sendDocument.getThumb(), SendDocument.THUMB_FIELD, false);
builder.addTextBody(SendDocument.THUMB_FIELD, sendDocument.getThumb().getAttachName(), TEXT_PLAIN_CONTENT_TYPE);
}
HttpEntity multipart = builder.build();
httppost.setEntity(multipart);
@ -187,7 +191,7 @@ public abstract class DefaultAbsSender extends AbsSender {
}
@Override
public final Message sendPhoto(SendPhoto sendPhoto) throws TelegramApiException {
public final Message execute(SendPhoto sendPhoto) throws TelegramApiException {
assertParamNotNull(sendPhoto, "sendPhoto");
sendPhoto.validate();
@ -199,17 +203,8 @@ public abstract class DefaultAbsSender extends AbsSender {
builder.setLaxMode();
builder.setCharset(StandardCharsets.UTF_8);
builder.addTextBody(SendPhoto.CHATID_FIELD, sendPhoto.getChatId(), TEXT_PLAIN_CONTENT_TYPE);
if (sendPhoto.isNewPhoto()) {
if (sendPhoto.getNewPhotoFile() != null) {
builder.addBinaryBody(SendPhoto.PHOTO_FIELD, sendPhoto.getNewPhotoFile());
} else if (sendPhoto.getNewPhotoStream() != null) {
builder.addBinaryBody(SendPhoto.PHOTO_FIELD, sendPhoto.getNewPhotoStream(), ContentType.APPLICATION_OCTET_STREAM, sendPhoto.getPhotoName());
} else {
builder.addBinaryBody(SendPhoto.PHOTO_FIELD, new java.io.File(sendPhoto.getPhoto()), ContentType.APPLICATION_OCTET_STREAM, sendPhoto.getPhotoName());
}
} else {
builder.addTextBody(SendPhoto.PHOTO_FIELD, sendPhoto.getPhoto(), TEXT_PLAIN_CONTENT_TYPE);
}
addInputFile(builder, sendPhoto.getPhoto(), SendPhoto.PHOTO_FIELD, true);
if (sendPhoto.getReplyMarkup() != null) {
builder.addTextBody(SendPhoto.REPLYMARKUP_FIELD, objectMapper.writeValueAsString(sendPhoto.getReplyMarkup()), TEXT_PLAIN_CONTENT_TYPE);
}
@ -235,7 +230,7 @@ public abstract class DefaultAbsSender extends AbsSender {
}
@Override
public final Message sendVideo(SendVideo sendVideo) throws TelegramApiException {
public final Message execute(SendVideo sendVideo) throws TelegramApiException {
assertParamNotNull(sendVideo, "sendVideo");
sendVideo.validate();
@ -247,17 +242,8 @@ public abstract class DefaultAbsSender extends AbsSender {
builder.setLaxMode();
builder.setCharset(StandardCharsets.UTF_8);
builder.addTextBody(SendVideo.CHATID_FIELD, sendVideo.getChatId(), TEXT_PLAIN_CONTENT_TYPE);
if (sendVideo.isNewVideo()) {
if (sendVideo.getNewVideoFile() != null) {
builder.addBinaryBody(SendVideo.VIDEO_FIELD, sendVideo.getNewVideoFile());
} else if (sendVideo.getNewVideoStream() != null) {
builder.addBinaryBody(SendVideo.VIDEO_FIELD, sendVideo.getNewVideoStream(), ContentType.APPLICATION_OCTET_STREAM, sendVideo.getVideoName());
} else {
builder.addBinaryBody(SendVideo.VIDEO_FIELD, new java.io.File(sendVideo.getVideo()), ContentType.APPLICATION_OCTET_STREAM, sendVideo.getVideoName());
}
} else {
builder.addTextBody(SendVideo.VIDEO_FIELD, sendVideo.getVideo(), TEXT_PLAIN_CONTENT_TYPE);
}
addInputFile(builder, sendVideo.getVideo(), SendVideo.VIDEO_FIELD, true);
if (sendVideo.getReplyMarkup() != null) {
builder.addTextBody(SendVideo.REPLYMARKUP_FIELD, objectMapper.writeValueAsString(sendVideo.getReplyMarkup()), TEXT_PLAIN_CONTENT_TYPE);
}
@ -285,6 +271,11 @@ public abstract class DefaultAbsSender extends AbsSender {
if (sendVideo.getDisableNotification() != null) {
builder.addTextBody(SendVideo.DISABLENOTIFICATION_FIELD, sendVideo.getDisableNotification().toString(), TEXT_PLAIN_CONTENT_TYPE);
}
if (sendVideo.getThumb() != null) {
addInputFile(builder, sendVideo.getThumb(), SendVideo.THUMB_FIELD, false);
builder.addTextBody(SendVideo.THUMB_FIELD, sendVideo.getThumb().getAttachName(), TEXT_PLAIN_CONTENT_TYPE);
}
HttpEntity multipart = builder.build();
httppost.setEntity(multipart);
@ -295,7 +286,7 @@ public abstract class DefaultAbsSender extends AbsSender {
}
@Override
public final Message sendVideoNote(SendVideoNote sendVideoNote) throws TelegramApiException {
public final Message execute(SendVideoNote sendVideoNote) throws TelegramApiException {
assertParamNotNull(sendVideoNote, "sendVideoNote");
sendVideoNote.validate();
@ -307,17 +298,8 @@ public abstract class DefaultAbsSender extends AbsSender {
builder.setLaxMode();
builder.setCharset(StandardCharsets.UTF_8);
builder.addTextBody(SendVideoNote.CHATID_FIELD, sendVideoNote.getChatId(), TEXT_PLAIN_CONTENT_TYPE);
if (sendVideoNote.isNewVideoNote()) {
if (sendVideoNote.getNewVideoNoteFile() != null) {
builder.addBinaryBody(SendVideoNote.VIDEONOTE_FIELD, sendVideoNote.getNewVideoNoteFile());
} else if (sendVideoNote.getNewVideoNoteStream() != null) {
builder.addBinaryBody(SendVideoNote.VIDEONOTE_FIELD, sendVideoNote.getNewVideoNoteStream(), ContentType.APPLICATION_OCTET_STREAM, sendVideoNote.getVideoNoteName());
} else {
builder.addBinaryBody(SendVideoNote.VIDEONOTE_FIELD, new java.io.File(sendVideoNote.getVideoNote()), ContentType.APPLICATION_OCTET_STREAM, sendVideoNote.getVideoNoteName());
}
} else {
builder.addTextBody(SendVideoNote.VIDEONOTE_FIELD, sendVideoNote.getVideoNote(), TEXT_PLAIN_CONTENT_TYPE);
}
addInputFile(builder, sendVideoNote.getVideoNote(), SendVideoNote.VIDEONOTE_FIELD, true);
if (sendVideoNote.getReplyMarkup() != null) {
builder.addTextBody(SendVideoNote.REPLYMARKUP_FIELD, objectMapper.writeValueAsString(sendVideoNote.getReplyMarkup()), TEXT_PLAIN_CONTENT_TYPE);
}
@ -333,6 +315,10 @@ public abstract class DefaultAbsSender extends AbsSender {
if (sendVideoNote.getDisableNotification() != null) {
builder.addTextBody(SendVideoNote.DISABLENOTIFICATION_FIELD, sendVideoNote.getDisableNotification().toString(), TEXT_PLAIN_CONTENT_TYPE);
}
if (sendVideoNote.getThumb() != null) {
addInputFile(builder, sendVideoNote.getThumb(), SendVideoNote.THUMB_FIELD, false);
builder.addTextBody(SendVideoNote.THUMB_FIELD, sendVideoNote.getThumb().getAttachName(), TEXT_PLAIN_CONTENT_TYPE);
}
HttpEntity multipart = builder.build();
httppost.setEntity(multipart);
@ -344,7 +330,7 @@ public abstract class DefaultAbsSender extends AbsSender {
}
@Override
public final Message sendSticker(SendSticker sendSticker) throws TelegramApiException {
public final Message execute(SendSticker sendSticker) throws TelegramApiException {
assertParamNotNull(sendSticker, "sendSticker");
sendSticker.validate();
@ -356,17 +342,8 @@ public abstract class DefaultAbsSender extends AbsSender {
builder.setLaxMode();
builder.setCharset(StandardCharsets.UTF_8);
builder.addTextBody(SendSticker.CHATID_FIELD, sendSticker.getChatId(), TEXT_PLAIN_CONTENT_TYPE);
if (sendSticker.isNewSticker()) {
if (sendSticker.getNewStickerFile() != null) {
builder.addBinaryBody(SendSticker.STICKER_FIELD, sendSticker.getNewStickerFile());
} else if (sendSticker.getNewStickerStream() != null) {
builder.addBinaryBody(SendSticker.STICKER_FIELD, sendSticker.getNewStickerStream(), ContentType.APPLICATION_OCTET_STREAM, sendSticker.getStickerName());
} else {
builder.addBinaryBody(SendSticker.STICKER_FIELD, new java.io.File(sendSticker.getSticker()), ContentType.APPLICATION_OCTET_STREAM, sendSticker.getStickerName());
}
} else {
builder.addTextBody(SendSticker.STICKER_FIELD, sendSticker.getSticker(), TEXT_PLAIN_CONTENT_TYPE);
}
addInputFile(builder, sendSticker.getSticker(), SendSticker.STICKER_FIELD, true);
if (sendSticker.getReplyMarkup() != null) {
builder.addTextBody(SendSticker.REPLYMARKUP_FIELD, objectMapper.writeValueAsString(sendSticker.getReplyMarkup()), TEXT_PLAIN_CONTENT_TYPE);
}
@ -392,7 +369,7 @@ public abstract class DefaultAbsSender extends AbsSender {
* @throws TelegramApiException If there is any error sending the audio
*/
@Override
public final Message sendAudio(SendAudio sendAudio) throws TelegramApiException {
public final Message execute(SendAudio sendAudio) throws TelegramApiException {
assertParamNotNull(sendAudio, "sendAudio");
sendAudio.validate();
try {
@ -402,17 +379,8 @@ public abstract class DefaultAbsSender extends AbsSender {
builder.setLaxMode();
builder.setCharset(StandardCharsets.UTF_8);
builder.addTextBody(SendAudio.CHATID_FIELD, sendAudio.getChatId(), TEXT_PLAIN_CONTENT_TYPE);
if (sendAudio.isNewAudio()) {
if (sendAudio.getNewAudioFile() != null) {
builder.addBinaryBody(SendAudio.AUDIO_FIELD, sendAudio.getNewAudioFile());
} else if (sendAudio.getNewAudioStream() != null) {
builder.addBinaryBody(SendAudio.AUDIO_FIELD, sendAudio.getNewAudioStream(), ContentType.APPLICATION_OCTET_STREAM, sendAudio.getAudioName());
} else {
builder.addBinaryBody(SendAudio.AUDIO_FIELD, new java.io.File(sendAudio.getAudio()), ContentType.create("audio/mpeg"), sendAudio.getAudioName());
}
} else {
builder.addTextBody(SendAudio.AUDIO_FIELD, sendAudio.getAudio());
}
addInputFile(builder, sendAudio.getAudio(), SendAudio.AUDIO_FIELD, true);
if (sendAudio.getReplyMarkup() != null) {
builder.addTextBody(SendAudio.REPLYMARKUP_FIELD, objectMapper.writeValueAsString(sendAudio.getReplyMarkup()), TEXT_PLAIN_CONTENT_TYPE);
}
@ -437,6 +405,11 @@ public abstract class DefaultAbsSender extends AbsSender {
builder.addTextBody(SendAudio.PARSEMODE_FIELD, sendAudio.getParseMode(), TEXT_PLAIN_CONTENT_TYPE);
}
}
if (sendAudio.getThumb() != null) {
addInputFile(builder, sendAudio.getThumb(), SendAudio.THUMB_FIELD, false);
builder.addTextBody(SendAudio.THUMB_FIELD, sendAudio.getThumb().getAttachName(), TEXT_PLAIN_CONTENT_TYPE);
}
HttpEntity multipart = builder.build();
httppost.setEntity(multipart);
@ -455,7 +428,7 @@ public abstract class DefaultAbsSender extends AbsSender {
* @throws TelegramApiException If there is any error sending the audio
*/
@Override
public final Message sendVoice(SendVoice sendVoice) throws TelegramApiException {
public final Message execute(SendVoice sendVoice) throws TelegramApiException {
assertParamNotNull(sendVoice, "sendVoice");
sendVoice.validate();
try {
@ -465,17 +438,8 @@ public abstract class DefaultAbsSender extends AbsSender {
builder.setLaxMode();
builder.setCharset(StandardCharsets.UTF_8);
builder.addTextBody(SendVoice.CHATID_FIELD, sendVoice.getChatId(), TEXT_PLAIN_CONTENT_TYPE);
if (sendVoice.isNewVoice()) {
if (sendVoice.getNewVoiceFile() != null) {
builder.addBinaryBody(SendVoice.VOICE_FIELD, sendVoice.getNewVoiceFile());
} else if (sendVoice.getNewVoiceStream() != null) {
builder.addBinaryBody(SendVoice.VOICE_FIELD, sendVoice.getNewVoiceStream(), ContentType.APPLICATION_OCTET_STREAM, sendVoice.getVoiceName());
} else {
builder.addBinaryBody(SendVoice.VOICE_FIELD, new java.io.File(sendVoice.getVoice()), ContentType.create("audio/ogg"), sendVoice.getVoiceName());
}
} else {
builder.addTextBody(SendVoice.VOICE_FIELD, sendVoice.getVoice(), TEXT_PLAIN_CONTENT_TYPE);
}
addInputFile(builder, sendVoice.getVoice(), SendVoice.VOICE_FIELD, true);
if (sendVoice.getReplyMarkup() != null) {
builder.addTextBody(SendVoice.REPLYMARKUP_FIELD, objectMapper.writeValueAsString(sendVoice.getReplyMarkup()), TEXT_PLAIN_CONTENT_TYPE);
}
@ -504,7 +468,7 @@ public abstract class DefaultAbsSender extends AbsSender {
}
@Override
public Boolean setChatPhoto(SetChatPhoto setChatPhoto) throws TelegramApiException {
public Boolean execute(SetChatPhoto setChatPhoto) throws TelegramApiException {
assertParamNotNull(setChatPhoto, "setChatPhoto");
setChatPhoto.validate();
@ -531,7 +495,7 @@ public abstract class DefaultAbsSender extends AbsSender {
}
@Override
public List<Message> sendMediaGroup(SendMediaGroup sendMediaGroup) throws TelegramApiException {
public List<Message> execute(SendMediaGroup sendMediaGroup) throws TelegramApiException {
assertParamNotNull(sendMediaGroup, "sendMediaGroup");
sendMediaGroup.validate();
@ -543,17 +507,7 @@ public abstract class DefaultAbsSender extends AbsSender {
builder.setLaxMode();
builder.setCharset(StandardCharsets.UTF_8);
builder.addTextBody(SendMediaGroup.CHATID_FIELD, sendMediaGroup.getChatId(), TEXT_PLAIN_CONTENT_TYPE);
builder.addTextBody(SendMediaGroup.MEDIA_FIELD, objectMapper.writeValueAsString(sendMediaGroup.getMedia()), TEXT_PLAIN_CONTENT_TYPE);
for (InputMedia inputMedia : sendMediaGroup.getMedia()) {
if (inputMedia.isNewMedia()) {
if (inputMedia.getMediaFile() != null) {
builder.addBinaryBody(inputMedia.getMediaName(), inputMedia.getMediaFile(), ContentType.APPLICATION_OCTET_STREAM, inputMedia.getMediaName());
} else if (inputMedia.getNewMediaStream() != null) {
builder.addBinaryBody(inputMedia.getMediaName(), inputMedia.getNewMediaStream(), ContentType.APPLICATION_OCTET_STREAM, inputMedia.getMediaName());
}
}
}
addInputData(builder, sendMediaGroup.getMedia(), SendMediaGroup.MEDIA_FIELD);
if (sendMediaGroup.getDisableNotification() != null) {
builder.addTextBody(SendMediaGroup.DISABLENOTIFICATION_FIELD, sendMediaGroup.getDisableNotification().toString(), TEXT_PLAIN_CONTENT_TYPE);
@ -573,9 +527,8 @@ public abstract class DefaultAbsSender extends AbsSender {
}
}
@Override
public Boolean addStickerToSet(AddStickerToSet addStickerToSet) throws TelegramApiException {
public Boolean execute(AddStickerToSet addStickerToSet) throws TelegramApiException {
assertParamNotNull(addStickerToSet, "addStickerToSet");
addStickerToSet.validate();
try {
@ -587,17 +540,8 @@ public abstract class DefaultAbsSender extends AbsSender {
builder.addTextBody(AddStickerToSet.USERID_FIELD, addStickerToSet.getUserId().toString(), TEXT_PLAIN_CONTENT_TYPE);
builder.addTextBody(AddStickerToSet.NAME_FIELD, addStickerToSet.getName(), TEXT_PLAIN_CONTENT_TYPE);
builder.addTextBody(AddStickerToSet.EMOJIS_FIELD, addStickerToSet.getEmojis(), TEXT_PLAIN_CONTENT_TYPE);
if (addStickerToSet.isNewPngSticker()) {
if (addStickerToSet.getPngStickerFile() != null) {
builder.addBinaryBody(AddStickerToSet.PNGSTICKER_FIELD, addStickerToSet.getPngStickerFile());
} else if (addStickerToSet.getPngStickerStream() != null) {
builder.addBinaryBody(AddStickerToSet.PNGSTICKER_FIELD, addStickerToSet.getPngStickerStream(), ContentType.APPLICATION_OCTET_STREAM, addStickerToSet.getPngStickerName());
} else {
builder.addBinaryBody(AddStickerToSet.PNGSTICKER_FIELD, new java.io.File(addStickerToSet.getPngSticker()), ContentType.create("image/png"), addStickerToSet.getPngStickerName());
}
} else {
builder.addTextBody(AddStickerToSet.PNGSTICKER_FIELD, addStickerToSet.getPngSticker(), TEXT_PLAIN_CONTENT_TYPE);
}
addInputFile(builder, addStickerToSet.getPngSticker(), AddStickerToSet.PNGSTICKER_FIELD, true);
if (addStickerToSet.getMaskPosition() != null) {
builder.addTextBody(AddStickerToSet.MASKPOSITION_FIELD, objectMapper.writeValueAsString(addStickerToSet.getMaskPosition()), TEXT_PLAIN_CONTENT_TYPE);
}
@ -611,7 +555,7 @@ public abstract class DefaultAbsSender extends AbsSender {
}
@Override
public Boolean createNewStickerSet(CreateNewStickerSet createNewStickerSet) throws TelegramApiException {
public Boolean execute(CreateNewStickerSet createNewStickerSet) throws TelegramApiException {
assertParamNotNull(createNewStickerSet, "createNewStickerSet");
createNewStickerSet.validate();
try {
@ -625,17 +569,8 @@ public abstract class DefaultAbsSender extends AbsSender {
builder.addTextBody(CreateNewStickerSet.TITLE_FIELD, createNewStickerSet.getTitle(), TEXT_PLAIN_CONTENT_TYPE);
builder.addTextBody(CreateNewStickerSet.EMOJIS_FIELD, createNewStickerSet.getEmojis(), TEXT_PLAIN_CONTENT_TYPE);
builder.addTextBody(CreateNewStickerSet.CONTAINSMASKS_FIELD, createNewStickerSet.getContainsMasks().toString(), TEXT_PLAIN_CONTENT_TYPE);
if (createNewStickerSet.isNewPngSticker()) {
if (createNewStickerSet.getPngStickerFile() != null) {
builder.addBinaryBody(CreateNewStickerSet.PNGSTICKER_FIELD, createNewStickerSet.getPngStickerFile());
} else if (createNewStickerSet.getPngStickerStream() != null) {
builder.addBinaryBody(CreateNewStickerSet.PNGSTICKER_FIELD, createNewStickerSet.getPngStickerStream(), ContentType.APPLICATION_OCTET_STREAM, createNewStickerSet.getPngStickerName());
} else {
builder.addBinaryBody(CreateNewStickerSet.PNGSTICKER_FIELD, new java.io.File(createNewStickerSet.getPngSticker()), ContentType.create("image/png"), createNewStickerSet.getPngStickerName());
}
} else {
builder.addTextBody(CreateNewStickerSet.PNGSTICKER_FIELD, createNewStickerSet.getPngSticker(), TEXT_PLAIN_CONTENT_TYPE);
}
addInputFile(builder, createNewStickerSet.getPngSticker(), CreateNewStickerSet.PNGSTICKER_FIELD, true);
if (createNewStickerSet.getMaskPosition() != null) {
builder.addTextBody(CreateNewStickerSet.MASKPOSITION_FIELD, objectMapper.writeValueAsString(createNewStickerSet.getMaskPosition()), TEXT_PLAIN_CONTENT_TYPE);
}
@ -649,7 +584,7 @@ public abstract class DefaultAbsSender extends AbsSender {
}
@Override
public File uploadStickerFile(UploadStickerFile uploadStickerFile) throws TelegramApiException {
public File execute(UploadStickerFile uploadStickerFile) throws TelegramApiException {
assertParamNotNull(uploadStickerFile, "uploadStickerFile");
uploadStickerFile.validate();
try {
@ -659,11 +594,7 @@ public abstract class DefaultAbsSender extends AbsSender {
builder.setLaxMode();
builder.setCharset(StandardCharsets.UTF_8);
builder.addTextBody(UploadStickerFile.USERID_FIELD, uploadStickerFile.getUserId().toString(), TEXT_PLAIN_CONTENT_TYPE);
if (uploadStickerFile.getNewPngStickerFile() != null) {
builder.addBinaryBody(UploadStickerFile.PNGSTICKER_FIELD, uploadStickerFile.getNewPngStickerFile());
} else if (uploadStickerFile.getNewPngStickerStream() != null) {
builder.addBinaryBody(UploadStickerFile.PNGSTICKER_FIELD, uploadStickerFile.getNewPngStickerStream(), ContentType.APPLICATION_OCTET_STREAM, uploadStickerFile.getNewPngStickerName());
}
addInputFile(builder, uploadStickerFile.getPngSticker(), UploadStickerFile.PNGSTICKER_FIELD, true);
HttpEntity multipart = builder.build();
httppost.setEntity(multipart);
@ -673,6 +604,38 @@ public abstract class DefaultAbsSender extends AbsSender {
}
}
@Override
public Serializable execute(EditMessageMedia editMessageMedia) throws TelegramApiException {
assertParamNotNull(editMessageMedia, "editMessageMedia");
editMessageMedia.validate();
try {
String url = getBaseUrl() + EditMessageMedia.PATH;
HttpPost httppost = configuredHttpPost(url);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setLaxMode();
builder.setCharset(StandardCharsets.UTF_8);
if (editMessageMedia.getInlineMessageId() == null) {
builder.addTextBody(EditMessageMedia.CHATID_FIELD, editMessageMedia.getChatId(), TEXT_PLAIN_CONTENT_TYPE);
builder.addTextBody(EditMessageMedia.MESSAGEID_FIELD, editMessageMedia.getMessageId().toString(), TEXT_PLAIN_CONTENT_TYPE);
} else {
builder.addTextBody(EditMessageMedia.INLINE_MESSAGE_ID_FIELD, editMessageMedia.getInlineMessageId(), TEXT_PLAIN_CONTENT_TYPE);
}
if (editMessageMedia.getReplyMarkup() != null) {
builder.addTextBody(EditMessageMedia.REPLYMARKUP_FIELD, objectMapper.writeValueAsString(editMessageMedia.getReplyMarkup()), TEXT_PLAIN_CONTENT_TYPE);
}
addInputData(builder, editMessageMedia.getMedia(), EditMessageMedia.MEDIA_FIELD, true);
HttpEntity multipart = builder.build();
httppost.setEntity(multipart);
return editMessageMedia.deserializeResponse(sendHttpPostRequest(httppost));
} catch (IOException e) {
throw new TelegramApiException("Unable to edit message media", e);
}
}
// Simplified methods
@Override
@ -761,6 +724,59 @@ public abstract class DefaultAbsSender extends AbsSender {
return httppost;
}
private void addInputData(MultipartEntityBuilder builder, InputMedia media, String mediaField, boolean addField) throws JsonProcessingException {
if (media.isNewMedia()) {
if (media.getMediaFile() != null) {
builder.addBinaryBody(media.getMediaName(), media.getMediaFile(), ContentType.APPLICATION_OCTET_STREAM, media.getMediaName());
} else if (media.getNewMediaStream() != null) {
builder.addBinaryBody(media.getMediaName(), media.getNewMediaStream(), ContentType.APPLICATION_OCTET_STREAM, media.getMediaName());
}
}
if (media instanceof InputMediaAudio) {
InputMediaAudio audio = (InputMediaAudio) media;
if (audio.getThumb() != null) {
addInputFile(builder, audio.getThumb(), InputMediaAudio.THUMB_FIELD, false);
}
} else if (media instanceof InputMediaDocument) {
InputMediaDocument document = (InputMediaDocument) media;
if (document.getThumb() != null) {
addInputFile(builder, document.getThumb(), InputMediaDocument.THUMB_FIELD, false);
}
} else if (media instanceof InputMediaVideo) {
InputMediaVideo video = (InputMediaVideo) media;
if (video.getThumb() != null) {
addInputFile(builder, video.getThumb(), InputMediaVideo.THUMB_FIELD, false);
}
}
if (addField) {
builder.addTextBody(mediaField, objectMapper.writeValueAsString(media), TEXT_PLAIN_CONTENT_TYPE);
}
}
private void addInputData(MultipartEntityBuilder builder, List<InputMedia> media, String mediaField) throws JsonProcessingException {
for (InputMedia inputMedia : media) {
addInputData(builder, inputMedia, null, false);
}
builder.addTextBody(mediaField, objectMapper.writeValueAsString(media), TEXT_PLAIN_CONTENT_TYPE);
}
private void addInputFile(MultipartEntityBuilder builder, InputFile file, String fileField, boolean addField) {
if (file.isNew()) {
if (file.getNewMediaFile() != null) {
builder.addBinaryBody(file.getMediaName(), file.getNewMediaFile(), ContentType.APPLICATION_OCTET_STREAM, file.getMediaName());
} else if (file.getNewMediaStream() != null) {
builder.addBinaryBody(file.getMediaName(), file.getNewMediaStream(), ContentType.APPLICATION_OCTET_STREAM, file.getMediaName());
}
}
if (addField) {
builder.addTextBody(fileField, file.getAttachName(), TEXT_PLAIN_CONTENT_TYPE);
}
}
protected String getBaseUrl() {
return options.getBaseUrl() + getBotToken() + "/";
}