Updated to v4.7

Conflicts:
	pom.xml
This commit is contained in:
Andrea Cavalli 2020-04-18 01:03:37 +02:00
commit 11a5722576
30 changed files with 748 additions and 80 deletions

View File

@ -22,10 +22,10 @@
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="telegrambots-meta" />
<module name="telegrambots-extensions" />
<module name="telegrambots" />
<module name="telegrambots-abilities" />
<module name="telegrambots-extensions" />
<module name="telegrambots-meta" />
<module name="telegrambots" />
<module name="telegrambots-chat-session-bot" />
<module name="telegrambots-spring-boot-starter" />
</profile>
@ -791,30 +791,6 @@
<option name="ITERATION_ELEMENTS_WRAPPING" value="chop_down_if_not_single" />
</formatting-settings>
</DBN-SQL>
<DBN-PSQL>
<case-options enabled="false">
<option name="KEYWORD_CASE" value="lower" />
<option name="FUNCTION_CASE" value="lower" />
<option name="PARAMETER_CASE" value="lower" />
<option name="DATATYPE_CASE" value="lower" />
<option name="OBJECT_CASE" value="preserve" />
</case-options>
<formatting-settings enabled="false" />
</DBN-PSQL>
<DBN-SQL>
<case-options enabled="false">
<option name="KEYWORD_CASE" value="lower" />
<option name="FUNCTION_CASE" value="lower" />
<option name="PARAMETER_CASE" value="lower" />
<option name="DATATYPE_CASE" value="lower" />
<option name="OBJECT_CASE" value="preserve" />
</case-options>
<formatting-settings enabled="false">
<option name="STATEMENT_SPACING" value="one_line" />
<option name="CLAUSE_CHOP_DOWN" value="chop_down_if_statement_long" />
<option name="ITERATION_ELEMENTS_WRAPPING" value="chop_down_if_not_single" />
</formatting-settings>
</DBN-SQL>
</code_scheme>
</component>
<component name="ProjectCodeStyleSettingsManager">
@ -876,6 +852,28 @@
<property name="settings.editor.selected.configurable" value="configurable.group.appearance" />
<property name="settings.editor.splitter.proportion" value="0.2" />
</component>
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="libs-release" />
<option name="url" value="http://18.184.80.197:8081/artifactory/libs-release" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="snapshots" />
<option name="name" value="libs-snapshot" />
<option name="url" value="http://18.184.80.197:8081/artifactory/libs-snapshot" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
@ -1423,37 +1421,37 @@
<root url="jar://$MAVEN_REPOSITORY$/org/codehaus/mojo/animal-sniffer-annotations/1.18/animal-sniffer-annotations-1.18-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: org.eclipse.collections:eclipse-collections-api:10.1.0">
<library name="Maven: org.eclipse.collections:eclipse-collections-api:10.2.0">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections-api/10.1.0/eclipse-collections-api-10.1.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections-api/10.2.0/eclipse-collections-api-10.2.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections-api/10.1.0/eclipse-collections-api-10.1.0-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections-api/10.2.0/eclipse-collections-api-10.2.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections-api/10.1.0/eclipse-collections-api-10.1.0-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections-api/10.2.0/eclipse-collections-api-10.2.0-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: org.eclipse.collections:eclipse-collections-forkjoin:10.1.0">
<library name="Maven: org.eclipse.collections:eclipse-collections-forkjoin:10.2.0">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections-forkjoin/10.1.0/eclipse-collections-forkjoin-10.1.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections-forkjoin/10.2.0/eclipse-collections-forkjoin-10.2.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections-forkjoin/10.1.0/eclipse-collections-forkjoin-10.1.0-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections-forkjoin/10.2.0/eclipse-collections-forkjoin-10.2.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections-forkjoin/10.1.0/eclipse-collections-forkjoin-10.1.0-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections-forkjoin/10.2.0/eclipse-collections-forkjoin-10.2.0-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: org.eclipse.collections:eclipse-collections:10.1.0">
<library name="Maven: org.eclipse.collections:eclipse-collections:10.2.0">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections/10.1.0/eclipse-collections-10.1.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections/10.2.0/eclipse-collections-10.2.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections/10.1.0/eclipse-collections-10.1.0-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections/10.2.0/eclipse-collections-10.2.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections/10.1.0/eclipse-collections-10.1.0-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/collections/eclipse-collections/10.2.0/eclipse-collections-10.2.0-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: org.glassfish.grizzly:grizzly-framework:2.4.4">

View File

@ -27,16 +27,16 @@ Just import add the library to your project with one of these options:
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>4.6</version>
<version>4.7</version>
</dependency>
```
```gradle
compile "org.telegram:telegrambots:4.6"
compile "org.telegram:telegrambots:4.7"
```
2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/4.6)
3. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/4.6)
2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/4.7)
3. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/4.7)
In order to use Long Polling mode, just create your own bot extending `org.telegram.telegrambots.bots.TelegramLongPollingBot`.

View File

@ -1,3 +1,6 @@
### <a id="4.7"></a>4.7 ###
1. Update Api version [4.7](https://core.telegram.org/bots/api-changelog#march-30-2020)
### <a id="4.6"></a>4.6 ###
1. Update Api version [4.6](https://core.telegram.org/bots/api-changelog#january-23-2020)

View File

@ -11,13 +11,13 @@ First you need ot get the library and add it to your project. There are few poss
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>4.6</version>
<version>4.7</version>
</dependency>
```
* With **Gradle**:
```groovy
compile group: 'org.telegram', name: 'telegrambots', version: '4.6'
compile group: 'org.telegram', name: 'telegrambots', version: '4.7'
```
2. Don't like **Maven Central Repository**? It can also be taken from [Jitpack](https://jitpack.io/#rubenlagus/TelegramBots).

View File

@ -9,7 +9,7 @@ As with any Java project, you will need to set your dependencies.
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-abilities</artifactId>
<version>4.6</version>
<version>4.7</version>
</dependency>
```
* **Gradle**

View File

@ -7,7 +7,7 @@
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<packaging>pom</packaging>
<version>4.6</version>
<version>4.7</version>
<modules>
<module>telegrambots</module>

View File

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

View File

@ -7,7 +7,7 @@
<parent>
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<version>4.6</version>
<version>4.7</version>
</parent>
<artifactId>telegrambots-abilities</artifactId>
@ -84,7 +84,7 @@
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>4.6</version>
<version>4.7</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>

View File

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

View File

@ -7,7 +7,7 @@
<parent>
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<version>4.6</version>
<version>4.7</version>
</parent>
<artifactId>telegrambots-chat-session-bot</artifactId>
@ -84,7 +84,7 @@
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>4.6</version>
<version>4.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.shiro/shiro-core -->

View File

@ -16,12 +16,12 @@ Just import add the library to your project with one of these options:
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambotsextensions</artifactId>
<version>4.6</version>
<version>4.7</version>
</dependency>
```
2. Using Gradle:
```gradle
compile "org.telegram:telegrambotsextensions:4.6"
compile "org.telegram:telegrambotsextensions:4.7"
```

View File

@ -7,7 +7,7 @@
<parent>
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<version>4.6</version>
<version>4.7</version>
</parent>
<artifactId>telegrambotsextensions</artifactId>
@ -75,7 +75,7 @@
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>4.6</version>
<version>4.7</version>
</dependency>
</dependencies>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<version>4.6</version>
<version>4.7</version>
</parent>
<artifactId>telegrambots-meta</artifactId>

View File

@ -0,0 +1,55 @@
package org.telegram.telegrambots.meta.api.methods.commands;
import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.commands.BotCommand;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.IOException;
import java.util.ArrayList;
/**
* @author Ruben Bermudez
* @version 4.7
* Use this method to get the current list of the bot's commands.
* Requires no parameters.
* Returns Array of BotCommand on success.
*/
public class GetMyCommands extends BotApiMethod<ArrayList<BotCommand>> {
public static final String PATH = "getMyCommands";
public GetMyCommands() {
super();
}
@Override
public String getMethod() {
return PATH;
}
@Override
public ArrayList<BotCommand> deserializeResponse(String answer) throws TelegramApiRequestException {
try {
ApiResponse<ArrayList<BotCommand>> result = OBJECT_MAPPER.readValue(answer,
new TypeReference<ApiResponse<ArrayList<BotCommand>>>(){});
if (result.getOk()) {
return result.getResult();
} else {
throw new TelegramApiRequestException("Error sending commands", result);
}
} catch (IOException e) {
throw new TelegramApiRequestException("Unable to deserialize response", e);
}
}
@Override
public void validate() throws TelegramApiValidationException {
}
@Override
public String toString() {
return "GetMyCommands{}";
}
}

View File

@ -0,0 +1,89 @@
package org.telegram.telegrambots.meta.api.methods.commands;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.commands.BotCommand;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.IOException;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 4.7
* Use this method to change the list of the bot's commands. Returns True on success.
*/
public class SetMyCommands extends BotApiMethod<Boolean> {
public static final String PATH = "setMyCommands";
private static final String COMMANDS_FIELD = "commands";
/**
* A JSON-serialized list of bot commands to be set as the list of the bot's commands.
* At most 100 commands can be specified.
*/
@JsonProperty(COMMANDS_FIELD)
private List<BotCommand> commands;
public SetMyCommands() {
super();
}
public SetMyCommands(List<BotCommand> commands) {
this.commands = checkNotNull(commands);
}
public List<BotCommand> getCommands() {
return commands;
}
public SetMyCommands setCommands(List<BotCommand> commands) {
this.commands = checkNotNull(commands);
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 sending commands", result);
}
} catch (IOException e) {
throw new TelegramApiRequestException("Unable to deserialize response", e);
}
}
@Override
public void validate() throws TelegramApiValidationException {
if (commands == null) {
throw new TelegramApiValidationException("Commands parameter can't be empty", this);
}
if (commands.size() > 100) {
throw new TelegramApiValidationException("No more than 100 commands are allowed", this);
}
for (BotCommand command : commands) {
command.validate();
}
}
@Override
public String toString() {
return "SetMyCommands{" +
"commands=" + commands +
'}';
}
}

View File

@ -0,0 +1,126 @@
package org.telegram.telegrambots.meta.api.methods.send;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.Message;
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.IOException;
/**
* @author Ruben Bermudez
* @version 4.7
* Use this method to send a dice, which will have a random value from 1 to 6. On success, the sent Message is returned.
* (Yes, we're aware of the proper singular of die. But it's awkward, and we decided to help it change. One dice at a time!)
*/
public class SendDice extends BotApiMethod<Message> {
public static final String PATH = "sendDice";
private static final String CHATID_FIELD = "chat_id";
private static final String DISABLENOTIFICATION_FIELD = "disable_notification";
private static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
private static final String REPLYMARKUP_FIELD = "reply_markup";
@JsonProperty(CHATID_FIELD)
private String chatId; ///< Unique identifier for the target chat or username of the target channel (in the format @channelusername)
@JsonProperty(DISABLENOTIFICATION_FIELD)
private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
@JsonProperty(REPLYTOMESSAGEID_FIELD)
private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message
@JsonProperty(REPLYMARKUP_FIELD)
private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
public SendDice() {
super();
}
public String getChatId() {
return chatId;
}
public SendDice setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public SendDice setChatId(Long chatId) {
this.chatId = chatId.toString();
return this;
}
public Integer getReplyToMessageId() {
return replyToMessageId;
}
public SendDice setReplyToMessageId(Integer replyToMessageId) {
this.replyToMessageId = replyToMessageId;
return this;
}
public ReplyKeyboard getReplyMarkup() {
return replyMarkup;
}
public SendDice setReplyMarkup(ReplyKeyboard replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
public Boolean getDisableNotification() {
return disableNotification;
}
public SendDice enableNotification() {
this.disableNotification = false;
return this;
}
public SendDice disableNotification() {
this.disableNotification = true;
return this;
}
@Override
public String getMethod() {
return PATH;
}
@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 dice", 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 (replyMarkup != null) {
replyMarkup.validate();
}
}
@Override
public String toString() {
return "SendDice{" +
"chatId='" + chatId + '\'' +
", disableNotification=" + disableNotification +
", replyToMessageId=" + replyToMessageId +
", replyMarkup=" + replyMarkup +
'}';
}
}

View File

@ -2,8 +2,8 @@ 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.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.InputFile;
import org.telegram.telegrambots.meta.api.objects.stickers.MaskPosition;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
@ -18,7 +18,12 @@ import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 1.0
* Use this method to add a new sticker to a set created by the bot. Returns True on success.
* Use this method to add a new sticker to a set created by the bot.
* You must use exactly one of the fields png_sticker or tgs_sticker.
* Animated stickers can be added to animated sticker sets and only to them.
* Animated sticker sets can have up to 50 stickers.
* Static sticker sets can have up to 120 stickers.
* Returns True on success.
*/
public class AddStickerToSet extends PartialBotApiMethod<Boolean> {
public static final String PATH = "addStickerToSet";
@ -26,6 +31,7 @@ public class AddStickerToSet extends PartialBotApiMethod<Boolean> {
public static final String USERID_FIELD = "user_id";
public static final String NAME_FIELD = "name";
public static final String PNGSTICKER_FIELD = "png_sticker";
public static final String TGSSTICKER_FIELD = "tgs_sticker";
public static final String EMOJIS_FIELD = "emojis";
public static final String MASKPOSITION_FIELD = "mask_position";
@ -40,6 +46,11 @@ public class AddStickerToSet extends PartialBotApiMethod<Boolean> {
* to get a file from the Internet, or upload a new one using multipart/form-data.
*/
private InputFile pngSticker;
/**
* TGS animation with the sticker, uploaded using multipart/form-data.
* See https://core.telegram.org/animated_stickers#technical-requirements for technical requirements
*/
private InputFile tgsSticker;
public AddStickerToSet() {
super();
@ -82,6 +93,20 @@ public class AddStickerToSet extends PartialBotApiMethod<Boolean> {
return this;
}
public AddStickerToSet setTgsSticker(File tgsSticker) {
this.tgsSticker = new InputFile(checkNotNull(tgsSticker), tgsSticker.getName());
return this;
}
public AddStickerToSet setTgsSticker(String tgsStickerName, InputStream tgsSticker) {
this.tgsSticker = new InputFile(checkNotNull(tgsSticker), checkNotNull(tgsStickerName));
return this;
}
public InputFile getTgsSticker() {
return tgsSticker;
}
public String getName() {
return name;
}
@ -136,11 +161,20 @@ public class AddStickerToSet extends PartialBotApiMethod<Boolean> {
throw new TelegramApiValidationException("emojis can't be empty", this);
}
if (pngSticker == null) {
throw new TelegramApiValidationException("PngSticker can't be empty", this);
if (pngSticker == null && tgsSticker == null) {
throw new TelegramApiValidationException("One of pngSticker or tgsSticker is needed", this);
}
pngSticker.validate();
if (pngSticker != null && tgsSticker != null) {
throw new TelegramApiValidationException("Only one of pngSticker or tgsSticker are allowed", this);
}
if (pngSticker != null) {
pngSticker.validate();
}
if (tgsSticker != null) {
tgsSticker.validate();
}
if (maskPosition != null) {
maskPosition.validate();
@ -155,6 +189,7 @@ public class AddStickerToSet extends PartialBotApiMethod<Boolean> {
", emojis='" + emojis + '\'' +
", maskPosition=" + maskPosition +
", pngSticker=" + pngSticker +
", tgsSticker=" + tgsSticker +
'}';
}
}

View File

@ -2,8 +2,8 @@ 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.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.InputFile;
import org.telegram.telegrambots.meta.api.objects.stickers.MaskPosition;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
@ -18,7 +18,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 1.0
* Use this method to create new sticker set owned by a user. The bot will be able to edit the created sticker set.
* Use this method to create a new sticker set owned by a user. The bot will be able to edit the sticker set thus created.
* You must use exactly one of the fields png_sticker or tgs_sticker.
* Returns True on success.
*/
public class CreateNewStickerSet extends PartialBotApiMethod<Boolean> {
@ -28,6 +29,7 @@ public class CreateNewStickerSet extends PartialBotApiMethod<Boolean> {
public static final String NAME_FIELD = "name";
public static final String TITLE_FIELD = "title";
public static final String PNGSTICKER_FIELD = "png_sticker";
public static final String TGSSTICKER_FIELD = "tgs_sticker";
public static final String EMOJIS_FIELD = "emojis";
public static final String CONTAINSMASKS_FIELD = "contains_masks";
public static final String MASKPOSITION_FIELD = "mask_position";
@ -53,6 +55,12 @@ public class CreateNewStickerSet extends PartialBotApiMethod<Boolean> {
*/
private InputFile pngSticker;
/**
* TGS animation with the sticker, uploaded using multipart/form-data.
* See https://core.telegram.org/animated_stickers#technical-requirements for technical requirements
*/
private InputFile tgsSticker;
public CreateNewStickerSet() {
super();
}
@ -100,6 +108,21 @@ public class CreateNewStickerSet extends PartialBotApiMethod<Boolean> {
return this;
}
public CreateNewStickerSet setTgsSticker(InputFile tgsSticker) {
this.tgsSticker = checkNotNull(tgsSticker);
return this;
}
public CreateNewStickerSet setTgsSticker(File tgsStickerFile) {
this.tgsSticker = new InputFile(checkNotNull(tgsStickerFile), tgsStickerFile.getName());;
return this;
}
public CreateNewStickerSet setTgsSticker(String tgsStickerName, InputStream tgsStickerStream) {
this.pngSticker = new InputFile(checkNotNull(tgsStickerStream), checkNotNull(tgsStickerName));
return this;
}
public String getName() {
return name;
}
@ -140,6 +163,10 @@ public class CreateNewStickerSet extends PartialBotApiMethod<Boolean> {
this.maskPosition = maskPosition;
}
public InputFile getTgsSticker() {
return tgsSticker;
}
@Override
public Boolean deserializeResponse(String answer) throws TelegramApiRequestException {
try {
@ -170,11 +197,20 @@ public class CreateNewStickerSet extends PartialBotApiMethod<Boolean> {
throw new TelegramApiValidationException("emojis can't be empty", this);
}
if (pngSticker == null) {
throw new TelegramApiValidationException("PngSticker parameter can't be empty", this);
if (pngSticker == null && tgsSticker == null) {
throw new TelegramApiValidationException("One of pngSticker or tgsSticker is needed", this);
}
pngSticker.validate();
if (pngSticker != null && tgsSticker != null) {
throw new TelegramApiValidationException("Only one of pngSticker or tgsSticker are allowed", this);
}
if (pngSticker != null) {
pngSticker.validate();
}
if (tgsSticker != null) {
tgsSticker.validate();
}
if (maskPosition != null) {
maskPosition.validate();
@ -191,6 +227,7 @@ public class CreateNewStickerSet extends PartialBotApiMethod<Boolean> {
", containsMasks=" + containsMasks +
", maskPosition=" + maskPosition +
", pngSticker=" + pngSticker +
", tgsSticker=" + tgsSticker +
'}';
}
}

View File

@ -0,0 +1,133 @@
package org.telegram.telegrambots.meta.api.methods.stickers;
import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.InputFile;
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 static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 1.0
* Use this method to set the thumbnail of a sticker set. Animated thumbnails can be set for animated sticker sets only.
* Returns True on success.
*/
public class SetStickerSetThumb extends BotApiMethod<Boolean> {
private static final String PATH = "setStickerSetThumb";
public static final String NAME_FIELD = "name";
public static final String USERID_FIELD = "user_id";
public static final String THUMB_FIELD = "thumb";
private String name; ///< Sticker set name
private Integer userId; ///< User identifier of the sticker set owner
/**
* A PNG image with the thumbnail, must be up to 128 kilobytes in size and have width and height exactly 100px,
* or a TGS animation with the thumbnail up to 32 kilobytes in size;
* see https://core.telegram.org/animated_stickers#technical-requirements for animated sticker technical requirements.
* Pass a file_id as a String to send a file 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.
* Animated sticker set thumbnail can't be uploaded via HTTP URL.
*/
private InputFile thumb;
public SetStickerSetThumb() {
super();
}
public SetStickerSetThumb(String name, Integer userId, InputFile thumb) {
this.name = name;
this.userId = userId;
this.thumb = thumb;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public InputFile getThumb() {
return thumb;
}
public SetStickerSetThumb setThumb(String thumb) {
this.thumb = new InputFile(thumb);
return this;
}
public SetStickerSetThumb setThumb(InputFile thumb) {
this.thumb = thumb;
return this;
}
public SetStickerSetThumb setThumb(File thumbFile) {
this.thumb = new InputFile(checkNotNull(thumbFile), thumbFile.getName());;
return this;
}
public SetStickerSetThumb setThumb(String thumbName, InputStream thumbStream) {
this.thumb = new InputFile(checkNotNull(thumbStream), checkNotNull(thumbName));
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 sticker thumb in set", result);
}
} catch (IOException e) {
throw new TelegramApiRequestException("Unable to deserialize response", e);
}
}
@Override
public void validate() throws TelegramApiValidationException {
if (name == null || name.isEmpty()) {
throw new TelegramApiValidationException("name can't be null", this);
}
if (userId == null || userId == 0) {
throw new TelegramApiValidationException("userId can't be null", this);
}
if (thumb == null) {
throw new TelegramApiValidationException("thumb can't be null", this);
}
thumb.validate();
}
@Override
public String toString() {
return "SetStickerSetThumb{" +
"name='" + name + '\'' +
", userId=" + userId +
", thumb=" + thumb +
'}';
}
}

View File

@ -0,0 +1,32 @@
package org.telegram.telegrambots.meta.api.objects;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
/**
* @author Ruben Bermudez
* @version 4.7
* This object represents a dice with random value from 1 to 6.
* (Yes, we're aware of the proper singular of die. But it's awkward, and we decided to help it change. One dice at a time!)
*/
public class Dice implements BotApiObject {
private static final String VALUE_FIELD = "value";
@JsonProperty(VALUE_FIELD)
private Integer value; ///< Value of the dice, 1-6
public Dice() {
super();
}
public Integer getValue() {
return value;
}
@Override
public String toString() {
return "Dice{" +
"value=" + value +
'}';
}
}

View File

@ -67,6 +67,7 @@ public class Message implements BotApiObject {
private static final String FORWARDSENDERNAME_FIELD = "forward_sender_name";
private static final String POLL_FIELD = "poll";
private static final String REPLY_MARKUP_FIELD = "reply_markup";
private static final String DICE_FIELD = "dice";
@JsonProperty(MESSAGEID_FIELD)
private Integer messageId; ///< Integer Unique message identifier
@ -207,6 +208,8 @@ public class Message implements BotApiObject {
*/
@JsonProperty(REPLY_MARKUP_FIELD)
private InlineKeyboardMarkup replyMarkup;
@JsonProperty(DICE_FIELD)
private Dice dice; // Optional. Message is a dice with random value from 1 to 6
public Message() {
super();
@ -510,6 +513,14 @@ public class Message implements BotApiObject {
return poll;
}
public Dice getDice() {
return dice;
}
public boolean hasDice() {
return dice != null;
}
public boolean hasReplyMarkup() {
return replyMarkup != null;
}

View File

@ -0,0 +1,71 @@
package org.telegram.telegrambots.meta.api.objects.commands;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
import org.telegram.telegrambots.meta.api.interfaces.Validable;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 4.7
* This object represents a bot command.
*/
public class BotCommand implements BotApiObject, Validable {
private static final String COMMAND_FIELD = "command";
private static final String DESCRIPTION_FIELD = "description";
/**
* Text of the command. Can contain only lowercase English letters, digits and underscores. 1-32 characters.
*/
@JsonProperty(COMMAND_FIELD)
private String command; ///< Value of the dice, 1-6
@JsonProperty(DESCRIPTION_FIELD)
private String description; ///< Description of the command, 3-256 characters.
public BotCommand() {
super();
}
public BotCommand(String command, String description) {
this.command = checkNotNull(command);
this.description = checkNotNull(description);
}
public String getCommand() {
return command;
}
public BotCommand setCommand(String command) {
this.command = command;
return this;
}
public String getDescription() {
return description;
}
public BotCommand setDescription(String description) {
this.description = description;
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (command == null || command.isEmpty()) {
throw new TelegramApiValidationException("Command parameter can't be empty", this);
}
if (description == null || description.isEmpty()) {
throw new TelegramApiValidationException("Description parameter can't be empty", this);
}
}
@Override
public String toString() {
return "BotCommand{" +
"command='" + command + '\'' +
", description='" + description + '\'' +
'}';
}
}

View File

@ -9,7 +9,7 @@ import java.util.Objects;
/**
* @author Ruben Bermudez
* @version 4.6
* @version 4.7
*
* This object represents an answer of a user in a non-anonymous poll.
*/

View File

@ -9,7 +9,7 @@ import java.util.Objects;
/**
* @author Ruben Bermudez
* @version 4.6
* @version 4.7
*
* This object represents type of a poll, which is allowed to be created and sent when the corresponding button is pressed.
*/

View File

@ -2,6 +2,7 @@ package org.telegram.telegrambots.meta.api.objects.stickers;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
import org.telegram.telegrambots.meta.api.objects.PhotoSize;
import java.util.List;
@ -16,6 +17,7 @@ public class StickerSet implements BotApiObject {
private static final String CONTAINSMASKS_FIELD = "contains_masks";
private static final String STICKERS_FIELD = "stickers";
private static final String ISANIMATED_FIELD = "is_animated";
private static final String THUMB_FIELD = "thumb";
@JsonProperty(NAME_FIELD)
private String name;
@ -27,6 +29,8 @@ public class StickerSet implements BotApiObject {
private List<Sticker> stickers;
@JsonProperty(ISANIMATED_FIELD)
private Boolean isAnimated;
@JsonProperty(THUMB_FIELD)
private PhotoSize thumb; ///< Optional. Sticker set thumbnail in the .WEBP or .TGS format
public StickerSet() {
super();
@ -52,6 +56,10 @@ public class StickerSet implements BotApiObject {
return isAnimated;
}
public PhotoSize getThumb() {
return thumb;
}
@Override
public String toString() {
return "StickerSet{" +
@ -60,6 +68,7 @@ public class StickerSet implements BotApiObject {
", containsMasks=" + containsMasks +
", stickers=" + stickers +
", isAnimated=" + isAnimated +
", thumb=" + thumb +
'}';
}
}

View File

@ -3,9 +3,18 @@ package org.telegram.telegrambots.meta.bots;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.methods.GetMe;
import org.telegram.telegrambots.meta.api.methods.groupadministration.SetChatPhoto;
import org.telegram.telegrambots.meta.api.methods.send.*;
import org.telegram.telegrambots.meta.api.methods.send.SendAnimation;
import org.telegram.telegrambots.meta.api.methods.send.SendAudio;
import org.telegram.telegrambots.meta.api.methods.send.SendDocument;
import org.telegram.telegrambots.meta.api.methods.send.SendMediaGroup;
import org.telegram.telegrambots.meta.api.methods.send.SendPhoto;
import org.telegram.telegrambots.meta.api.methods.send.SendSticker;
import org.telegram.telegrambots.meta.api.methods.send.SendVideo;
import org.telegram.telegrambots.meta.api.methods.send.SendVideoNote;
import org.telegram.telegrambots.meta.api.methods.send.SendVoice;
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.SetStickerSetThumb;
import org.telegram.telegrambots.meta.api.methods.stickers.UploadStickerFile;
import org.telegram.telegrambots.meta.api.methods.updates.GetWebhookInfo;
import org.telegram.telegrambots.meta.api.methods.updatingmessages.EditMessageMedia;
@ -126,6 +135,14 @@ public abstract class AbsSender {
*/
public abstract Boolean execute(AddStickerToSet addStickerToSet) throws TelegramApiException;
/**
* Set sticker set thumb (https://core.telegram.org/bots/api#setStickerSetThumb)
* @param setStickerSetThumb Information of the sticker to set
* @return If success, true is returned
* @throws TelegramApiException If there is any error setting the thumb to the set
*/
public abstract Boolean execute(SetStickerSetThumb setStickerSetThumb) throws TelegramApiException;
/**
* Creates a new sticker set (https://core.telegram.org/bots/api#createNewStickerSet)
* @param createNewStickerSet Information of the sticker set to create

View File

@ -7,7 +7,7 @@
<parent>
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<version>4.6</version>
<version>4.7</version>
</parent>
<artifactId>telegrambots-spring-boot-starter</artifactId>
@ -78,7 +78,7 @@
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>4.6</version>
<version>4.7</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>

21
telegrambots/LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2016 Ruben Bermudez
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -7,7 +7,7 @@
<parent>
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<version>4.6</version>
<version>4.7</version>
</parent>
<artifactId>telegrambots</artifactId>
@ -95,7 +95,7 @@
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-meta</artifactId>
<version>4.6</version>
<version>4.7</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>

View File

@ -26,6 +26,7 @@ import org.telegram.telegrambots.meta.api.methods.send.SendVideoNote;
import org.telegram.telegrambots.meta.api.methods.send.SendVoice;
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.SetStickerSetThumb;
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;
@ -548,7 +549,11 @@ 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);
addInputFile(builder, addStickerToSet.getPngSticker(), AddStickerToSet.PNGSTICKER_FIELD, true);
if (addStickerToSet.getPngSticker() != null) {
addInputFile(builder, addStickerToSet.getPngSticker(), AddStickerToSet.PNGSTICKER_FIELD, true);
} else {
addInputFile(builder, addStickerToSet.getTgsSticker(), AddStickerToSet.TGSSTICKER_FIELD, true);
}
if (addStickerToSet.getMaskPosition() != null) {
builder.addTextBody(AddStickerToSet.MASKPOSITION_FIELD, objectMapper.writeValueAsString(addStickerToSet.getMaskPosition()), TEXT_PLAIN_CONTENT_TYPE);
@ -562,6 +567,28 @@ public abstract class DefaultAbsSender extends AbsSender {
}
}
@Override
public Boolean execute(SetStickerSetThumb setStickerSetThumb) throws TelegramApiException {
assertParamNotNull(setStickerSetThumb, "setStickerSetThumb");
setStickerSetThumb.validate();
try {
String url = getBaseUrl() + AddStickerToSet.PATH;
HttpPost httppost = configuredHttpPost(url);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setLaxMode();
builder.setCharset(StandardCharsets.UTF_8);
builder.addTextBody(SetStickerSetThumb.USERID_FIELD, setStickerSetThumb.getUserId().toString(), TEXT_PLAIN_CONTENT_TYPE);
builder.addTextBody(SetStickerSetThumb.NAME_FIELD, setStickerSetThumb.getName(), TEXT_PLAIN_CONTENT_TYPE);
addInputFile(builder, setStickerSetThumb.getThumb(), SetStickerSetThumb.THUMB_FIELD, true);
HttpEntity multipart = builder.build();
httppost.setEntity(multipart);
return setStickerSetThumb.deserializeResponse(sendHttpPostRequest(httppost));
} catch (IOException e) {
throw new TelegramApiException("Unable to add sticker to set", e);
}
}
@Override
public Boolean execute(CreateNewStickerSet createNewStickerSet) throws TelegramApiException {
assertParamNotNull(createNewStickerSet, "createNewStickerSet");
@ -577,7 +604,11 @@ 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);
addInputFile(builder, createNewStickerSet.getPngSticker(), CreateNewStickerSet.PNGSTICKER_FIELD, true);
if (createNewStickerSet.getPngSticker() != null) {
addInputFile(builder, createNewStickerSet.getPngSticker(), CreateNewStickerSet.PNGSTICKER_FIELD, true);
} else {
addInputFile(builder, createNewStickerSet.getTgsSticker(), CreateNewStickerSet.TGSSTICKER_FIELD, true);
}
if (createNewStickerSet.getMaskPosition() != null) {
builder.addTextBody(CreateNewStickerSet.MASKPOSITION_FIELD, objectMapper.writeValueAsString(createNewStickerSet.getMaskPosition()), TEXT_PLAIN_CONTENT_TYPE);