Compare commits

...

2 Commits

Author SHA1 Message Date
Andrea Cavalli 979d2e1d67 Merge commit '571d58e13f5c462dee449310909c760277476a91' 2020-04-25 16:34:54 +02:00
rubenlagus 571d58e13f Update version Api 4.8 2020-04-24 09:03:23 +01:00
18 changed files with 160 additions and 33 deletions

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.7</version>
<version>4.8</version>
</dependency>
```
```gradle
compile "org.telegram:telegrambots:4.7"
compile "org.telegram:telegrambots:4.8"
```
2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/4.7)
3. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/4.7)
2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/4.8)
3. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/4.8)
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.8"></a>4.8 ###
1. Update Api version [4.8](https://core.telegram.org/bots/api-changelog#april-24-2020)
### <a id="4.7"></a>4.7 ###
1. Update Api version [4.7](https://core.telegram.org/bots/api-changelog#march-30-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.7</version>
<version>4.8</version>
</dependency>
```
* With **Gradle**:
```groovy
compile group: 'org.telegram', name: 'telegrambots', version: '4.7'
compile group: 'org.telegram', name: 'telegrambots', version: '4.8'
```
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.7</version>
<version>4.8</version>
</dependency>
```
* **Gradle**

View File

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

View File

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

View File

@ -7,7 +7,7 @@
<parent>
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<version>4.7</version>
<version>4.8</version>
</parent>
<artifactId>telegrambots-abilities</artifactId>
@ -84,7 +84,7 @@
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>4.7</version>
<version>4.8</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.7</version>
<version>4.8</version>
</dependency>
```

View File

@ -7,7 +7,7 @@
<parent>
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<version>4.7</version>
<version>4.8</version>
</parent>
<artifactId>telegrambots-chat-session-bot</artifactId>
@ -84,7 +84,7 @@
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>4.7</version>
<version>4.8</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.7</version>
<version>4.8</version>
</dependency>
```
2. Using Gradle:
```gradle
compile "org.telegram:telegrambotsextensions:4.7"
compile "org.telegram:telegrambotsextensions:4.8"
```

View File

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

View File

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

View File

@ -39,6 +39,10 @@ public class SendPoll extends BotApiMethod<Message> {
private static final String DISABLENOTIFICATION_FIELD = "disable_notification";
private static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
private static final String REPLYMARKUP_FIELD = "reply_markup";
private static final String OPENPERIOD_FIELD = "open_period";
private static final String CLOSEDATE_FIELD = "close_date";
private static final String EXPLANATION_FIELD = "explanation";
private static final String EXPLANATIONPARSEMODE_FIELD = "explanation_parse_mode";
/**
* Unique identifier for the target chat or username of the target channel (in the format @channelusername).
@ -67,7 +71,14 @@ public class SendPoll extends BotApiMethod<Message> {
@JsonProperty(REPLYMARKUP_FIELD)
@JsonDeserialize()
private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
@JsonProperty(OPENPERIOD_FIELD)
private Integer openPeriod; ///< Optional. Amount of time in seconds the poll will be active after creation, 5-600. Can't be used together with close_date.
@JsonProperty(CLOSEDATE_FIELD)
private Integer closeDate; ///< Optional. Point in time (Unix timestamp) when the poll will be automatically closed. Must be at least 5 and no more than 600 seconds in the future. Can't be used together with open_period.
@JsonProperty(EXPLANATION_FIELD)
private String explanation; ///< Optional. Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters with at most 2 line feeds after entities parsing
@JsonProperty(EXPLANATIONPARSEMODE_FIELD)
private String explanationParseMode; ///< Optional. Mode for parsing entities in the explanation. See formatting options for more details.
public SendPoll() {
super();
@ -196,6 +207,42 @@ public class SendPoll extends BotApiMethod<Message> {
return this;
}
public Integer getOpenPeriod() {
return openPeriod;
}
public SendPoll setOpenPeriod(Integer openPeriod) {
this.openPeriod = openPeriod;
return this;
}
public Integer getCloseDate() {
return closeDate;
}
public SendPoll setCloseDate(Integer closeDate) {
this.closeDate = closeDate;
return this;
}
public String getExplanation() {
return explanation;
}
public SendPoll setExplanation(String explanation) {
this.explanation = explanation;
return this;
}
public String getExplanationParseMode() {
return explanationParseMode;
}
public SendPoll setExplanationParseMode(String explanationParseMode) {
this.explanationParseMode = explanationParseMode;
return this;
}
@Override
public String getMethod() {
return PATH;
@ -228,6 +275,15 @@ public class SendPoll extends BotApiMethod<Message> {
if (options == null || options.size() < 2 || options.size() > 10) {
throw new TelegramApiValidationException("Options parameter must be between 2 and 10 item", this);
}
if (openPeriod != null && closeDate != null) {
throw new TelegramApiValidationException("Only one of Open Period and Close Date are allowed", this);
}
if (openPeriod != null && (openPeriod < 5 || openPeriod > 600)) {
throw new TelegramApiValidationException("Open period can only be between 5 and 600", this);
}
if (explanation != null && explanation.length() > 200) {
throw new TelegramApiValidationException("Explanation can only have up to 200 characters", this);
}
if (options.parallelStream().anyMatch(x -> x.isEmpty() || x.length() > 100)) {
throw new TelegramApiValidationException("Options parameter values must be between 1 and 100 chars length", this);
}
@ -236,7 +292,6 @@ public class SendPoll extends BotApiMethod<Message> {
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
@ -252,13 +307,17 @@ public class SendPoll extends BotApiMethod<Message> {
Objects.equals(isClosed, sendPoll.isClosed) &&
Objects.equals(disableNotification, sendPoll.disableNotification) &&
Objects.equals(replyToMessageId, sendPoll.replyToMessageId) &&
Objects.equals(replyMarkup, sendPoll.replyMarkup);
Objects.equals(replyMarkup, sendPoll.replyMarkup) &&
Objects.equals(openPeriod, sendPoll.openPeriod) &&
Objects.equals(closeDate, sendPoll.closeDate) &&
Objects.equals(explanation, sendPoll.explanation) &&
Objects.equals(explanationParseMode, sendPoll.explanationParseMode);
}
@Override
public int hashCode() {
return Objects.hash(chatId, question, options, isAnonymous, type, allowMultipleAnswers, correctOptionId,
isClosed, disableNotification, replyToMessageId, replyMarkup);
return Objects.hash(chatId, question, options, isAnonymous, type, allowMultipleAnswers, correctOptionId, isClosed,
disableNotification, replyToMessageId, replyMarkup, openPeriod, closeDate, explanation, explanationParseMode);
}
@Override
@ -275,6 +334,10 @@ public class SendPoll extends BotApiMethod<Message> {
", disableNotification=" + disableNotification +
", replyToMessageId=" + replyToMessageId +
", replyMarkup=" + replyMarkup +
", openPeriod=" + openPeriod +
", closeDate=" + closeDate +
", explanation='" + explanation + '\'' +
", explanationParseMode='" + explanationParseMode + '\'' +
'}';
}
}

View File

@ -21,12 +21,15 @@ public class SendDice extends BotApiMethod<Message> {
public static final String PATH = "sendDice";
private static final String CHATID_FIELD = "chat_id";
private static final String EMOJI_FIELD = "emoji";
private static final String DISABLENOTIFICATION_FIELD = "disable_notification";
private static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
private static final String REPLYMARKUP_FIELD = "reply_markup";
@JsonProperty(CHATID_FIELD)
private String chatId; ///< Unique identifier for the target chat or username of the target channel (in the format @channelusername)
@JsonProperty(EMOJI_FIELD)
private String emoji; ///< Optional. Emoji on which the dice throw animation is based. Currently, must be one of “🎲” or “🎯”. Defauts to “🎲”
@JsonProperty(DISABLENOTIFICATION_FIELD)
private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
@JsonProperty(REPLYTOMESSAGEID_FIELD)
@ -84,6 +87,15 @@ public class SendDice extends BotApiMethod<Message> {
return this;
}
public String getEmoji() {
return emoji;
}
public SendDice setEmoji(String emoji) {
this.emoji = emoji;
return this;
}
@Override
public String getMethod() {
return PATH;
@ -109,6 +121,9 @@ public class SendDice extends BotApiMethod<Message> {
if (chatId == null) {
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
}
if (emoji != null && !emoji.equals("“\uD83C\uDFB2") && !emoji.equals("\uD83C\uDFAF")) {
throw new TelegramApiValidationException("Only \uD83C\uDFB2 and \uD83C\uDFAF are allowed in Emoji field ", this);
}
if (replyMarkup != null) {
replyMarkup.validate();
}
@ -118,6 +133,7 @@ public class SendDice extends BotApiMethod<Message> {
public String toString() {
return "SendDice{" +
"chatId='" + chatId + '\'' +
", emoji='" + emoji + '\'' +
", disableNotification=" + disableNotification +
", replyToMessageId=" + replyToMessageId +
", replyMarkup=" + replyMarkup +

View File

@ -11,9 +11,12 @@ import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
*/
public class Dice implements BotApiObject {
private static final String VALUE_FIELD = "value";
private static final String EMOJI_FIELD = "emoji";
@JsonProperty(VALUE_FIELD)
private Integer value; ///< Value of the dice, 1-6
@JsonProperty(EMOJI_FIELD)
private String emoji; ///< Emoji on which the dice throw animation is based
public Dice() {
super();
@ -23,10 +26,15 @@ public class Dice implements BotApiObject {
return value;
}
public String getEmoji() {
return emoji;
}
@Override
public String toString() {
return "Dice{" +
"value=" + value +
", emoji='" + emoji + '\'' +
'}';
}
}

View File

@ -2,6 +2,7 @@ package org.telegram.telegrambots.meta.api.objects.polls;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
import org.telegram.telegrambots.meta.api.objects.MessageEntity;
import java.util.List;
import java.util.Objects;
@ -22,6 +23,10 @@ public class Poll implements BotApiObject {
private static final String TYPE_FIELD = "type";
private static final String ALLOWSMULTIPLEANSWERS_FIELD = "allows_multiple_answers";
private static final String CORRECTOPTIONID_FIELD = "correct_option_id";
private static final String OPENPERIOD_FIELD = "open_period";
private static final String CLOSEDATE_FIELD = "close_date";
private static final String EXPLANATION_FIELD = "explanation";
private static final String EXPLANATIONENTITIES_FIELD = "explanation_entities";
@JsonProperty(ID_FIELD)
private String id; ///< Unique poll identifier
@ -47,6 +52,14 @@ public class Poll implements BotApiObject {
*/
@JsonProperty(CORRECTOPTIONID_FIELD)
private Integer correctOptionId; ///< True, if the poll allows multiple answers
@JsonProperty(OPENPERIOD_FIELD)
private Integer openPeriod; ///< Optional. Amount of time in seconds the poll will be active after creation
@JsonProperty(CLOSEDATE_FIELD)
private Integer closeDate; ///< Optional. Point in time (Unix timestamp) when the poll will be automatically closed
@JsonProperty(EXPLANATION_FIELD)
private String explanation; ///< Optional. Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters
@JsonProperty(EXPLANATIONENTITIES_FIELD)
private List<MessageEntity> explanationEntities; ///< Optional. Special entities like usernames, URLs, bot commands, etc. that appear in the explanation
public Poll() {
}
@ -123,6 +136,22 @@ public class Poll implements BotApiObject {
this.correctOptionId = correctOptionId;
}
public Integer getOpenPeriod() {
return openPeriod;
}
public Integer getCloseDate() {
return closeDate;
}
public String getExplanation() {
return explanation;
}
public List<MessageEntity> getExplanationEntities() {
return explanationEntities;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
@ -136,12 +165,16 @@ public class Poll implements BotApiObject {
Objects.equals(isAnonymous, poll.isAnonymous) &&
Objects.equals(type, poll.type) &&
Objects.equals(allowMultipleAnswers, poll.allowMultipleAnswers) &&
Objects.equals(correctOptionId, poll.correctOptionId);
Objects.equals(correctOptionId, poll.correctOptionId) &&
Objects.equals(openPeriod, poll.openPeriod) &&
Objects.equals(closeDate, poll.closeDate) &&
Objects.equals(explanation, poll.explanation) &&
Objects.equals(explanationEntities, poll.explanationEntities);
}
@Override
public int hashCode() {
return Objects.hash(id, question, options, totalVoterCount, isClosed, isAnonymous, type, allowMultipleAnswers, correctOptionId);
return Objects.hash(id, question, options, totalVoterCount, isClosed, isAnonymous, type, allowMultipleAnswers, correctOptionId, openPeriod, closeDate, explanation, explanationEntities);
}
@Override
@ -156,6 +189,10 @@ public class Poll implements BotApiObject {
", type='" + type + '\'' +
", allowMultipleAnswers=" + allowMultipleAnswers +
", correctOptionId=" + correctOptionId +
", openPeriod=" + openPeriod +
", closeDate=" + closeDate +
", explanation='" + explanation + '\'' +
", explanationEntities=" + explanationEntities +
'}';
}
}

View File

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

View File

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