Merge tag 'v6.4.0'

This commit is contained in:
Andrea Cavalli 2023-01-17 15:00:25 +01:00
commit 507c4dee41
43 changed files with 673 additions and 77 deletions

View File

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

View File

@ -1,3 +1,7 @@
### <a id="6.4.0"></a>6.4.0 ###
1. Update Api version [6.4](https://core.telegram.org/bots/api-changelog#december-30-2022)
2. Bug fixing: #1159
### <a id="6.3.0"></a>6.3.0 ###
1. Update Api version [6.3](https://core.telegram.org/bots/api-changelog#November-5-2022)
2. Bug fixing: #1116

View File

@ -11,13 +11,13 @@ First you need to acquire the library and add it to your project. There are seve
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>6.3.0</version>
<version>6.4.0</version>
</dependency>
```
* With **Gradle**:
```gradle
implementation 'org.telegram:telegrambots:6.3.0'
implementation 'org.telegram:telegrambots:6.4.0'
```
2. Don't like the **Maven Central Repository**? It can also be grabbed from [Jitpack](https://jitpack.io/#rubenlagus/TelegramBots).

View File

@ -9,12 +9,12 @@ As with any Java project, you will need to set your dependencies.
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-abilities</artifactId>
<version>6.3.0</version>
<version>6.4.0</version>
</dependency>
```
* **Gradle**
```gradle
implementation 'org.telegram:telegrambots-abilities:6.3.0'
implementation 'org.telegram:telegrambots-abilities:6.4.0'
```
* [JitPack](https://jitpack.io/#rubenlagus/TelegramBots)

View File

@ -7,7 +7,7 @@
<groupId>org.warp</groupId>
<artifactId>Bots</artifactId>
<packaging>pom</packaging>
<version>6.3.0</version>
<version>6.4.0</version>
<modules>
<module>telegrambots</module>
@ -74,7 +74,6 @@
<mockitojupiter.version>4.8.1</mockitojupiter.version>
<jacksonanotation.version>2.14.0</jacksonanotation.version>
<jackson.version>2.14.0</jackson.version>
<json.version>20220924</json.version>
<slf4j.version>2.0.3</slf4j.version>
<jakarta.annotation.version>2.1.1</jakarta.annotation.version>
<lombok.version>1.18.24</lombok.version>
@ -125,6 +124,11 @@
<artifactId>json</artifactId>
<version>${json.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<!-- Included to enforce common version-->
<dependency>
<groupId>jakarta.annotation</groupId>

View File

@ -18,14 +18,14 @@ Usage
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-abilities</artifactId>
<version>6.3.0</version>
<version>6.4.0</version>
</dependency>
```
**Gradle**
```gradle
implementation 'org.telegram:telegrambots-abilities:6.3.0'
implementation 'org.telegram:telegrambots-abilities:6.4.0'
```
**JitPack** - [JitPack](https://jitpack.io/#rubenlagus/TelegramBots/v5.0.1)

View File

@ -7,7 +7,7 @@
<parent>
<groupId>org.warp</groupId>
<artifactId>Bots</artifactId>
<version>6.3.0</version>
<version>6.4.0</version>
</parent>
<artifactId>telegrambots-abilities</artifactId>
@ -86,7 +86,7 @@
<dependency>
<groupId>org.warp</groupId>
<artifactId>telegrambots</artifactId>
<version>6.3.0</version>
<version>6.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>

View File

@ -3,7 +3,6 @@ package org.telegram.abilitybots.api.objects;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;
import org.json.JSONPropertyIgnore;
import java.io.Serializable;
import java.util.Objects;

View File

@ -15,14 +15,14 @@ Usage
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-chat-session-bot</artifactId>
<version>6.3.0</version>
<version>6.4.0</version>
</dependency>
```
**Gradle**
```gradle
implementation 'org.telegram:telegrambots-chat-session-bot:6.3.0'
implementation 'org.telegram:telegrambots-chat-session-bot:6.4.0'
```
Motivation

View File

@ -7,7 +7,7 @@
<parent>
<groupId>org.warp</groupId>
<artifactId>Bots</artifactId>
<version>6.3.0</version>
<version>6.4.0</version>
</parent>
<artifactId>telegrambots-chat-session-bot</artifactId>
@ -86,7 +86,7 @@
<dependency>
<groupId>org.warp</groupId>
<artifactId>telegrambots</artifactId>
<version>6.3.0</version>
<version>6.4.0</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>6.3.0</version>
<version>6.4.0</version>
</dependency>
```
2. Using Gradle:
```gradle
implementation 'org.telegram:telegrambotsextensions:6.3.0'
implementation 'org.telegram:telegrambotsextensions:6.4.0'
```

View File

@ -7,7 +7,7 @@
<parent>
<groupId>org.warp</groupId>
<artifactId>Bots</artifactId>
<version>6.3.0</version>
<version>6.4.0</version>
</parent>
<artifactId>telegrambotsextensions</artifactId>
@ -77,7 +77,7 @@
<dependency>
<groupId>org.warp</groupId>
<artifactId>telegrambots</artifactId>
<version>6.3.0</version>
<version>6.4.0</version>
</dependency>
</dependencies>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>org.warp</groupId>
<artifactId>Bots</artifactId>
<version>6.3.0</version>
<version>6.4.0</version>
</parent>
<artifactId>telegrambots-meta</artifactId>
@ -92,10 +92,6 @@
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>

View File

@ -0,0 +1,69 @@
package org.telegram.telegrambots.meta.api.methods.forum;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Tolerate;
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 6.4
* Use this method to close an open 'General' topic in a forum supergroup chat.
* The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights.
*
* Returns True on success.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class CloseGeneralForumTopic extends BotApiMethodBoolean {
public static final String PATH = "closeGeneralForumTopic";
private static final String CHATID_FIELD = "chat_id";
/**
* Unique identifier for the target chat or username
* of the target supergroup (in the format @supergroupusername)
*/
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId;
@Tolerate
public void setChatId(@NonNull Long chatId) {
this.chatId = chatId.toString();
}
@Override
public void validate() throws TelegramApiValidationException {
if (chatId.isEmpty()) {
throw new TelegramApiValidationException("ChatId can't be empty", this);
}
}
@Override
public String getMethod() {
return PATH;
}
public static class CloseGeneralForumTopicBuilder {
@Tolerate
public CloseGeneralForumTopicBuilder chatId(@NonNull Long chatId) {
this.chatId = chatId.toString();
return this;
}
}
}

View File

@ -51,18 +51,20 @@ public class EditForumTopic extends BotApiMethodBoolean {
@NonNull
private Integer messageThreadId;
/**
* Topic name, 1-128 characters
* Optional.
* New topic name, 0-128 characters.
* If not specified or empty, the current name of the topic will be kept
*/
@JsonProperty(NAME_FIELD)
@NonNull
private String name;
/**
* Optional.
* Unique identifier of the custom emoji shown as the topic icon.
* Use getForumTopicIconStickers to get all allowed custom emoji identifiers
* New unique identifier of the custom emoji shown as the topic icon.
* Use getForumTopicIconStickers to get all allowed custom emoji identifiers.
* Pass an empty string to remove the icon.
* If not specified, the current icon will be kept
*/
@JsonProperty(ICONCUSTOMEMOJIID_FIELD)
@NonNull
private String iconCustomEmojiId;
@Tolerate
@ -75,8 +77,10 @@ public class EditForumTopic extends BotApiMethodBoolean {
if (chatId.isEmpty()) {
throw new TelegramApiValidationException("ChatId can't be empty", this);
}
if (name.isEmpty() || name.length() > 128) {
throw new TelegramApiValidationException("Name must be between 1 and 128 characters", this);
if (name != null && !name.isEmpty()) {
if (name.length() > 128) {
throw new TelegramApiValidationException("Name must be less than 128 characters", this);
}
}
if (messageThreadId <= 0) {
throw new TelegramApiValidationException("Message Thread Id can't be empty", this);

View File

@ -0,0 +1,80 @@
package org.telegram.telegrambots.meta.api.methods.forum;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Tolerate;
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 6.4
* Use this method to edit the name of the 'General' topic in a forum supergroup chat.
* The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights.
*
* Returns True on success.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class EditGeneralForumTopic extends BotApiMethodBoolean {
public static final String PATH = "editGeneralForumTopic";
private static final String CHATID_FIELD = "chat_id";
private static final String NAME_FIELD = "name";
/**
* Unique identifier for the target chat or username
* of the target supergroup (in the format @supergroupusername)
*/
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId;
/**
* Optional.
* New topic name, 1-128 characters
*/
@JsonProperty(NAME_FIELD)
@NonNull
private String name;
@Tolerate
public void setChatId(@NonNull Long chatId) {
this.chatId = chatId.toString();
}
@Override
public void validate() throws TelegramApiValidationException {
if (chatId.isEmpty()) {
throw new TelegramApiValidationException("ChatId can't be empty", this);
}
if (name.isEmpty() || name.length() > 128) {
throw new TelegramApiValidationException("Name must be between 1 and 128 characters", this);
}
}
@Override
public String getMethod() {
return PATH;
}
public static class EditGeneralForumTopicBuilder {
@Tolerate
public EditGeneralForumTopicBuilder chatId(@NonNull Long chatId) {
this.chatId = chatId.toString();
return this;
}
}
}

View File

@ -0,0 +1,70 @@
package org.telegram.telegrambots.meta.api.methods.forum;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Tolerate;
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 6.4
* Use this method to hide the 'General' topic in a forum supergroup chat.
* The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights.
* The topic will be automatically closed if it was open.
*
* Returns True on success.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class HideGeneralForumTopic extends BotApiMethodBoolean {
public static final String PATH = "hideGeneralForumTopic";
private static final String CHATID_FIELD = "chat_id";
/**
* Unique identifier for the target chat or username
* of the target supergroup (in the format @supergroupusername)
*/
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId;
@Tolerate
public void setChatId(@NonNull Long chatId) {
this.chatId = chatId.toString();
}
@Override
public void validate() throws TelegramApiValidationException {
if (chatId.isEmpty()) {
throw new TelegramApiValidationException("ChatId can't be empty", this);
}
}
@Override
public String getMethod() {
return PATH;
}
public static class HideGeneralForumTopicBuilder {
@Tolerate
public HideGeneralForumTopicBuilder chatId(@NonNull Long chatId) {
this.chatId = chatId.toString();
return this;
}
}
}

View File

@ -0,0 +1,70 @@
package org.telegram.telegrambots.meta.api.methods.forum;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Tolerate;
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 6.4
* Use this method to reopen a closed 'General' topic in a forum supergroup chat.
* The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights.
* The topic will be automatically unhidden if it was hidden.
*
* Returns True on success.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class ReopenGeneralForumTopic extends BotApiMethodBoolean {
public static final String PATH = "reopenGeneralForumTopic";
private static final String CHATID_FIELD = "chat_id";
/**
* Unique identifier for the target chat or username
* of the target supergroup (in the format @supergroupusername)
*/
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId;
@Tolerate
public void setChatId(@NonNull Long chatId) {
this.chatId = chatId.toString();
}
@Override
public void validate() throws TelegramApiValidationException {
if (chatId.isEmpty()) {
throw new TelegramApiValidationException("ChatId can't be empty", this);
}
}
@Override
public String getMethod() {
return PATH;
}
public static class ReopenGeneralForumTopicBuilder {
@Tolerate
public ReopenGeneralForumTopicBuilder chatId(@NonNull Long chatId) {
this.chatId = chatId.toString();
return this;
}
}
}

View File

@ -0,0 +1,69 @@
package org.telegram.telegrambots.meta.api.methods.forum;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Tolerate;
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 6.4
* Use this method to unhide the 'General' topic in a forum supergroup chat.
* The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights.
*
* Returns True on success.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class UnhideGeneralForumTopic extends BotApiMethodBoolean {
public static final String PATH = "unhideGeneralForumTopic";
private static final String CHATID_FIELD = "chat_id";
/**
* Unique identifier for the target chat or username
* of the target supergroup (in the format @supergroupusername)
*/
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId;
@Tolerate
public void setChatId(@NonNull Long chatId) {
this.chatId = chatId.toString();
}
@Override
public void validate() throws TelegramApiValidationException {
if (chatId.isEmpty()) {
throw new TelegramApiValidationException("ChatId can't be empty", this);
}
}
@Override
public String getMethod() {
return PATH;
}
public static class UnhideGeneralForumTopicBuilder {
@Tolerate
public UnhideGeneralForumTopicBuilder chatId(@NonNull Long chatId) {
this.chatId = chatId.toString();
return this;
}
}
}

View File

@ -19,6 +19,7 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
* @author Ruben Bermudez
* @version 1.0
* Use this method to get information about a member of a chat.
* The method is guaranteed to work only if the bot is an administrator in the chat.
* Returns a ChatMember object on success.
*/
@EqualsAndHashCode(callSuper = false)

View File

@ -55,6 +55,7 @@ public class SendAnimation extends PartialBotApiMethod<Message> {
public static final String CAPTION_ENTITIES_FIELD = "caption_entities";
public static final String ALLOWSENDINGWITHOUTREPLY_FIELD = "allow_sending_without_reply";
public static final String PROTECTCONTENT_FIELD = "protect_content";
public static final String HASSPOILER_FIELD = "has_spoiler";
@NonNull
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
@ -91,6 +92,11 @@ public class SendAnimation extends PartialBotApiMethod<Message> {
private List<MessageEntity> captionEntities; ///< Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode
private Boolean allowSendingWithoutReply; ///< Optional Pass True, if the message should be sent even if the specified replied-to message is not found
private Boolean protectContent; ///< Optional. Protects the contents of sent messages from forwarding and saving
/**
* Optional.
* Pass True if the animation must be covered with a spoiler animation
*/
private Boolean hasSpoiler;
@Tolerate
public void setChatId(@NonNull Long chatId) {

View File

@ -35,6 +35,7 @@ public class SendChatAction extends BotApiMethodBoolean {
public static final String CHATID_FIELD = "chat_id";
private static final String ACTION_FIELD = "action";
private static final String MESSAGETHREADID_FIELD = "message_thread_id";
@JsonProperty(CHATID_FIELD)
@NonNull
@ -54,6 +55,12 @@ public class SendChatAction extends BotApiMethodBoolean {
@JsonProperty(ACTION_FIELD)
@NonNull
private String action;
/**
* Optional
* Unique identifier for the target message thread; supergroups only
*/
@JsonProperty(MESSAGETHREADID_FIELD)
private Integer messageThreadId;
@Tolerate
public void setChatId(@NonNull Long chatId) {

View File

@ -49,6 +49,7 @@ public class SendPhoto extends PartialBotApiMethod<Message> {
public static final String CAPTION_ENTITIES_FIELD = "caption_entities";
public static final String ALLOWSENDINGWITHOUTREPLY_FIELD = "allow_sending_without_reply";
public static final String PROTECTCONTENT_FIELD = "protect_content";
public static final String HASSPOILER_FIELD = "has_spoiler";
/**
* Unique identifier for the chat to send the message to (Or username for channels)
@ -98,6 +99,11 @@ public class SendPhoto extends PartialBotApiMethod<Message> {
* Optional. Protects the contents of sent messages from forwarding and saving
*/
private Boolean protectContent;
/**
* Optional.
* Pass True if the photo must be covered with a spoiler animation
*/
private Boolean hasSpoiler;
@Tolerate
public void setChatId(@NonNull Long chatId) {

View File

@ -54,6 +54,7 @@ public class SendVideo extends PartialBotApiMethod<Message> {
public static final String CAPTION_ENTITIES_FIELD = "caption_entities";
public static final String ALLOWSENDINGWITHOUTREPLY_FIELD = "allow_sending_without_reply";
public static final String PROTECTCONTENT_FIELD = "protect_content";
public static final String HASSPOILER_FIELD = "has_spoiler";
@NonNull
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
@ -86,6 +87,11 @@ public class SendVideo extends PartialBotApiMethod<Message> {
private List<MessageEntity> captionEntities; ///< Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode
private Boolean allowSendingWithoutReply; ///< Optional Pass True, if the message should be sent even if the specified replied-to message is not found
private Boolean protectContent; ///< Optional. Protects the contents of sent messages from forwarding and saving
/**
* Optional.
* Pass True if the video must be covered with a spoiler animation
*/
private Boolean hasSpoiler;
@Tolerate
public void setChatId(@NonNull Long chatId) {

View File

@ -55,6 +55,8 @@ public class Chat implements BotApiObject {
private static final String ISFORUM_FIELD = "is_forum";
private static final String ACTIVEUSERNAMES_FIELD = "active_usernames";
private static final String EMOJISTATUSCUSTOMEMOJIID_FIELD = "emoji_status_custom_emoji_id";
private static final String HASAGGRESSIVEANTISPAMENABLED_FIELD = "has_aggressive_anti_spam_enabled";
private static final String HASHIDDENMEMBERS_FIELD = "has_hidden_members";
private static final String USERCHATTYPE = "private";
private static final String GROUPCHATTYPE = "group";
@ -245,6 +247,21 @@ public class Chat implements BotApiObject {
*/
@JsonProperty(EMOJISTATUSCUSTOMEMOJIID_FIELD)
private String emojiStatusCustomEmojiId;
/**
* Optional.
* True, if aggressive anti-spam checks are enabled in the supergroup.
* The field is only available to chat administrators.
* Returned only in getChat.
*/
@JsonProperty(HASAGGRESSIVEANTISPAMENABLED_FIELD)
private Boolean hasAggressiveAntiSpamEnabled;
/**
* Optional.
* True, if non-administrators can only get the list of bots and administrators in the chat.
* Returned only in getChat.
*/
@JsonProperty(HASHIDDENMEMBERS_FIELD)
private Boolean hasHiddenMembers;
/**
* Optional. Extra.

View File

@ -11,7 +11,10 @@ import lombok.ToString;
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
import org.telegram.telegrambots.meta.api.objects.forum.ForumTopicClosed;
import org.telegram.telegrambots.meta.api.objects.forum.ForumTopicCreated;
import org.telegram.telegrambots.meta.api.objects.forum.ForumTopicEdited;
import org.telegram.telegrambots.meta.api.objects.forum.ForumTopicReopened;
import org.telegram.telegrambots.meta.api.objects.forum.GeneralForumTopicHidden;
import org.telegram.telegrambots.meta.api.objects.forum.GeneralForumTopicUnhidden;
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;
@ -105,6 +108,11 @@ public class Message implements BotApiObject {
private static final String FORUMTOPICCREATED_FIELD = "forum_topic_created";
private static final String FORUMTOPICCLOSED_FIELD = "forum_topic_closed";
private static final String FORUMTOPICREOPENED_FIELD = "forum_topic_reopened";
private static final String FORUMTOPICEDITED_FIELD = "forum_topic_edited";
private static final String GENERALFORUMTOPICHIDDEN_FIELD = "general_forum_topic_hidden";
private static final String GENERALFORUMTOPICUNHIDDEN_FIELD = "general_forum_topic_unhidden";
private static final String WRITEACCESSALLOWED_FIELD = "write_access_allowed";
private static final String HASMEDIASPOILER_FIELD = "has_media_spoiler";
private static final String VIEWS_FIELD = "views";
private static final String OUTGOING_FIELD = "outgoing";
@ -506,6 +514,36 @@ public class Message implements BotApiObject {
*/
@JsonProperty(FORUMTOPICREOPENED_FIELD)
private ForumTopicReopened forumTopicReopened;
/**
* Optional.
* Service message: forum topic edited
*/
@JsonProperty(FORUMTOPICEDITED_FIELD)
private ForumTopicEdited forumTopicEdited;
/**
* Optional.
* Service message: General forum topic hidden
*/
@JsonProperty(GENERALFORUMTOPICHIDDEN_FIELD)
private GeneralForumTopicHidden generalForumTopicHidden;
/**
* Optional.
* Service message: General forum topic unhidden
*/
@JsonProperty(GENERALFORUMTOPICUNHIDDEN_FIELD)
private GeneralForumTopicUnhidden generalForumTopicUnhidden;
/**
* Optional.
* Service message: the user allowed the bot added to the attachment menu to write messages
*/
@JsonProperty(WRITEACCESSALLOWED_FIELD)
private WriteAccessAllowed writeAccessAllowed;
/**
* Optional.
* True, if the message media is covered by a spoiler animation
*/
@JsonProperty(HASMEDIASPOILER_FIELD)
private Boolean hasMediaSpoiler;
@JsonProperty(OUTGOING_FIELD)
private Boolean outgoing; ///< Optional. Extra.

View File

@ -0,0 +1,22 @@
package org.telegram.telegrambots.meta.api.objects;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
/**
* This object represents a service message about a user allowing a bot added to the attachment menu to write messages.
* Currently holds no information.
* @author Ruben Bermudez
* @version 6.4
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@AllArgsConstructor
public class WriteAccessAllowed implements BotApiObject {
}

View File

@ -0,0 +1,42 @@
package org.telegram.telegrambots.meta.api.objects.forum;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
/**
* This object represents a service message about an edited forum topic.
* @author Ruben Bermudez
* @version 6.4
*/
@SuppressWarnings("WeakerAccess")
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class ForumTopicEdited implements BotApiObject {
private static final String NAME_FIELD = "name";
private static final String ICONCUSTOMEMOJIID_FIELD = "icon_custom_emoji_id";
/**
* Optional.
* New name of the topic, if it was edited
*/
@JsonProperty(NAME_FIELD)
private String name;
/**
* Optional.
* New identifier of the custom emoji shown as the topic icon, if it was edited;
* an empty string if the icon was removed
*/
@JsonProperty(ICONCUSTOMEMOJIID_FIELD)
private String iconCustomEmojiId;
}

View File

@ -0,0 +1,23 @@
package org.telegram.telegrambots.meta.api.objects.forum;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
/**
* This object represents a service message about General forum topic hidden in the chat.
* Currently holds no information.
* @author Ruben Bermudez
* @version 6.4
*/
@SuppressWarnings("WeakerAccess")
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@AllArgsConstructor
public class GeneralForumTopicHidden implements BotApiObject {
}

View File

@ -0,0 +1,23 @@
package org.telegram.telegrambots.meta.api.objects.forum;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
/**
* This object represents a service message about General forum topic hidden in the chat.
* Currently holds no information.
* @author Ruben Bermudez
* @version 6.4
*/
@SuppressWarnings("WeakerAccess")
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@AllArgsConstructor
public class GeneralForumTopicUnhidden implements BotApiObject {
}

View File

@ -35,6 +35,7 @@ public class InputMediaAnimation extends InputMedia {
public static final String HEIGHT_FIELD = "height";
public static final String DURATION_FIELD = "duration";
public static final String THUMB_FIELD = "thumb";
public static final String HASSPOILER_FIELD = "has_spoiler";
@JsonProperty(WIDTH_FIELD)
private Integer width; ///< Optional. Animation width
@ -50,6 +51,12 @@ public class InputMediaAnimation extends InputMedia {
* if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
*/
private InputFile thumb;
/**
* Optional.
* Pass True if the animation must be covered with a spoiler animation
*/
@JsonProperty(HASSPOILER_FIELD)
private Boolean hasSpoiler;
public InputMediaAnimation() {
super();
@ -60,12 +67,15 @@ public class InputMediaAnimation extends InputMedia {
}
@Builder
public InputMediaAnimation(@NonNull String media, String caption, String parseMode, List<MessageEntity> entities, boolean isNewMedia, String mediaName, File newMediaFile, InputStream newMediaStream, Integer width, Integer height, Integer duration, InputFile thumb) {
public InputMediaAnimation(@NonNull String media, String caption, String parseMode, List<MessageEntity> entities,
boolean isNewMedia, String mediaName, File newMediaFile, InputStream newMediaStream,
Integer width, Integer height, Integer duration, InputFile thumb, Boolean hasSpoiler) {
super(media, caption, parseMode, entities, isNewMedia, mediaName, newMediaFile, newMediaStream);
this.width = width;
this.height = height;
this.duration = duration;
this.thumb = thumb;
this.hasSpoiler = hasSpoiler;
}
@Override

View File

@ -1,5 +1,6 @@
package org.telegram.telegrambots.meta.api.objects.media;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import lombok.Builder;
import lombok.EqualsAndHashCode;
@ -29,6 +30,15 @@ import java.util.List;
public class InputMediaPhoto extends InputMedia {
private static final String TYPE = "photo";
public static final String HASSPOILER_FIELD = "has_spoiler";
/**
* Optional.
* Pass True if the photo must be covered with a spoiler animation
*/
@JsonProperty(HASSPOILER_FIELD)
private Boolean hasSpoiler;
public InputMediaPhoto() {
super();
}
@ -38,8 +48,11 @@ public class InputMediaPhoto extends InputMedia {
}
@Builder
public InputMediaPhoto(@NonNull String media, String caption, String parseMode, List<MessageEntity> entities, boolean isNewMedia, String mediaName, File newMediaFile, InputStream newMediaStream) {
public InputMediaPhoto(@NonNull String media, String caption, String parseMode, List<MessageEntity> entities,
boolean isNewMedia, String mediaName, File newMediaFile, InputStream newMediaStream,
Boolean hasSpoiler) {
super(media, caption, parseMode, entities, isNewMedia, mediaName, newMediaFile, newMediaStream);
this.hasSpoiler = hasSpoiler;
}
@Override

View File

@ -36,6 +36,7 @@ public class InputMediaVideo extends InputMedia {
public static final String DURATION_FIELD = "duration";
public static final String SUPPORTSSTREAMING_FIELD = "supports_streaming";
public static final String THUMB_FIELD = "thumb";
public static final String HASSPOILER_FIELD = "has_spoiler";
@JsonProperty(WIDTH_FIELD)
private Integer width; ///< Optional. Video width
@ -54,6 +55,12 @@ public class InputMediaVideo extends InputMedia {
*/
@JsonProperty(THUMB_FIELD)
private InputFile thumb;
/**
* Optional.
* Pass True if the video must be covered with a spoiler animation
*/
@JsonProperty(HASSPOILER_FIELD)
private Boolean hasSpoiler;
public InputMediaVideo() {
}
@ -63,13 +70,17 @@ public class InputMediaVideo extends InputMedia {
}
@Builder
public InputMediaVideo(@NonNull String media, String caption, String parseMode, List<MessageEntity> entities, boolean isNewMedia, String mediaName, File newMediaFile, InputStream newMediaStream, Integer width, Integer height, Integer duration, Boolean supportsStreaming, InputFile thumb) {
public InputMediaVideo(@NonNull String media, String caption, String parseMode, List<MessageEntity> entities,
boolean isNewMedia, String mediaName, File newMediaFile, InputStream newMediaStream,
Integer width, Integer height, Integer duration, Boolean supportsStreaming, InputFile thumb,
Boolean hasSpoiler) {
super(media, caption, parseMode, entities, isNewMedia, mediaName, newMediaFile, newMediaStream);
this.width = width;
this.height = height;
this.duration = duration;
this.supportsStreaming = supportsStreaming;
this.thumb = thumb;
this.hasSpoiler = hasSpoiler;
}
@Override

View File

@ -9,6 +9,7 @@ import org.telegram.telegrambots.meta.api.objects.media.InputMedia;
import org.telegram.telegrambots.meta.api.objects.media.InputMediaAnimation;
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.InputMediaPhoto;
import org.telegram.telegrambots.meta.api.objects.media.InputMediaVideo;
import java.io.IOException;
@ -67,11 +68,19 @@ public class InputMediaSerializer extends JsonSerializer<InputMedia> {
if (animation.getWidth() != null) {
gen.writeNumberField(InputMediaAnimation.WIDTH_FIELD, animation.getWidth());
}
if (animation.getHasSpoiler() != null) {
gen.writeBooleanField(InputMediaAnimation.HASSPOILER_FIELD, animation.getHasSpoiler());
}
} 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 InputMediaPhoto) {
InputMediaPhoto photo = (InputMediaPhoto) value;
if (photo.getHasSpoiler() != null) {
gen.writeBooleanField(InputMediaPhoto.HASSPOILER_FIELD, photo.getHasSpoiler());
}
} else if (value instanceof InputMediaVideo) {
InputMediaVideo video = (InputMediaVideo) value;
if (video.getThumb() != null) {
@ -89,6 +98,9 @@ public class InputMediaSerializer extends JsonSerializer<InputMedia> {
if (video.getSupportsStreaming() != null) {
gen.writeBooleanField(InputMediaVideo.SUPPORTSSTREAMING_FIELD, video.getSupportsStreaming());
}
if (video.getHasSpoiler() != null) {
gen.writeBooleanField(InputMediaVideo.HASSPOILER_FIELD, video.getHasSpoiler());
}
}
gen.writeEndObject();

View File

@ -38,6 +38,7 @@ public class ReplyKeyboardMarkup implements ReplyKeyboard {
private static final String ONETIMEKEYBOARD_FIELD = "one_time_keyboard";
private static final String SELECTIVE_FIELD = "selective";
private static final String INPUTFIELDPLACEHOLDER_FIELD = "input_field_placeholder";
private static final String ISPERSISTENT_FIELD = "is_persistent";
@JsonProperty(KEYBOARD_FIELD)
@NonNull
@ -63,7 +64,13 @@ public class ReplyKeyboardMarkup implements ReplyKeyboard {
*/
@JsonProperty(INPUTFIELDPLACEHOLDER_FIELD)
private String inputFieldPlaceholder;
/**
* Optional.
* Requests clients to always show the keyboard when the regular keyboard is hidden.
* Defaults to false, in which case the custom keyboard can be hidden and opened with a keyboard icon.
*/
@JsonProperty(ISPERSISTENT_FIELD)
private Boolean isPersistent;
@Override
public void validate() throws TelegramApiValidationException {
if (keyboard == null) {

View File

@ -36,7 +36,7 @@ public class StickerSet implements BotApiObject {
/**
* Type of stickers in the set, currently one of regular, mask, custom_emoji
*/
@JsonProperty(STICKERS_FIELD)
@JsonProperty(STICKERTYPE_FIELD)
private String stickerType;
/**
* Sticker set name

View File

@ -18,7 +18,6 @@
package org.telegram.telegrambots.meta.exceptions;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
@ -48,20 +47,7 @@ public class TelegramApiRequestException extends TelegramApiException {
super(message);
}
public TelegramApiRequestException(String message, JSONObject object) {
super(message);
apiResponse = object.getString(ERRORDESCRIPTIONFIELD);
errorCode = object.getInt(ERRORCODEFIELD);
if (object.has(PARAMETERSFIELD)) {
try {
parameters = OBJECT_MAPPER.readValue(object.getJSONObject(PARAMETERSFIELD).toString(), ResponseParameters.class);
} catch (IOException e) {
log.error(e.getLocalizedMessage(), e);
}
}
}
public TelegramApiRequestException(String message, ApiResponse response) {
public TelegramApiRequestException(String message, ApiResponse<?> response) {
super(message);
apiResponse = response.getErrorDescription();
errorCode = response.getErrorCode();

View File

@ -18,14 +18,14 @@ Usage
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-spring-boot-starter</artifactId>
<version>6.3.0</version>
<version>6.4.0</version>
</dependency>
```
**Gradle**
```gradle
implementation 'org.telegram:telegrambots-spring-boot-starter:6.3.0'
implementation 'org.telegram:telegrambots-spring-boot-starter:6.4.0'
```
Motivation

View File

@ -7,7 +7,7 @@
<parent>
<groupId>org.warp</groupId>
<artifactId>Bots</artifactId>
<version>6.3.0</version>
<version>6.4.0</version>
</parent>
<artifactId>telegrambots-spring-boot-starter</artifactId>
@ -72,7 +72,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<telegrambots.version>6.3.0</telegrambots.version>
<telegrambots.version>6.4.0</telegrambots.version>
<spring-boot.version>2.7.5</spring-boot.version>
<maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>org.warp</groupId>
<artifactId>Bots</artifactId>
<version>6.3.0</version>
<version>6.4.0</version>
</parent>
<artifactId>telegrambots</artifactId>
@ -93,7 +93,7 @@
<dependency>
<groupId>org.warp</groupId>
<artifactId>telegrambots-meta</artifactId>
<version>6.3.0</version>
<version>6.4.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
@ -208,10 +208,6 @@
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>

View File

@ -253,6 +253,9 @@ public abstract class DefaultAbsSender extends AbsSender {
if (sendPhoto.getCaptionEntities() != null) {
builder.addTextBody(SendPhoto.CAPTION_ENTITIES_FIELD, objectMapper.writeValueAsString(sendPhoto.getCaptionEntities()), TEXT_PLAIN_CONTENT_TYPE);
}
if (sendPhoto.getHasSpoiler() != null) {
builder.addTextBody(SendPhoto.HASSPOILER_FIELD, objectMapper.writeValueAsString(sendPhoto.getHasSpoiler()), TEXT_PLAIN_CONTENT_TYPE);
}
HttpEntity multipart = builder.build();
httppost.setEntity(multipart);
@ -320,6 +323,9 @@ public abstract class DefaultAbsSender extends AbsSender {
if (sendVideo.getCaptionEntities() != null) {
builder.addTextBody(SendVideo.CAPTION_ENTITIES_FIELD, objectMapper.writeValueAsString(sendVideo.getCaptionEntities()), TEXT_PLAIN_CONTENT_TYPE);
}
if (sendVideo.getHasSpoiler() != null) {
builder.addTextBody(SendVideo.HASSPOILER_FIELD, objectMapper.writeValueAsString(sendVideo.getHasSpoiler()), TEXT_PLAIN_CONTENT_TYPE);
}
HttpEntity multipart = builder.build();
httppost.setEntity(multipart);
@ -825,6 +831,9 @@ public abstract class DefaultAbsSender extends AbsSender {
if (sendAnimation.getCaptionEntities() != null) {
builder.addTextBody(SendAnimation.CAPTION_ENTITIES_FIELD, objectMapper.writeValueAsString(sendAnimation.getCaptionEntities()), TEXT_PLAIN_CONTENT_TYPE);
}
if (sendAnimation.getHasSpoiler() != null) {
builder.addTextBody(SendAnimation.HASSPOILER_FIELD, objectMapper.writeValueAsString(sendAnimation.getHasSpoiler()), TEXT_PLAIN_CONTENT_TYPE);
}
HttpEntity multipart = builder.build();
httppost.setEntity(multipart);

View File

@ -8,7 +8,6 @@ import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.telegram.telegrambots.bots.DefaultBotOptions;
@ -261,13 +260,9 @@ public class DefaultBotSession implements BotSession {
lock.wait(500);
}
} else {
try {
List<Update> updates = request.deserializeResponse(responseContent);
backOff.reset();
return updates;
} catch (JSONException e) {
log.error("Error deserializing update: " + responseContent, e);
}
List<Update> updates = request.deserializeResponse(responseContent);
backOff.reset();
return updates;
}
} catch (SocketException | InvalidObjectException | TelegramApiRequestException e) {
log.error(e.getLocalizedMessage(), e);

View File

@ -1,5 +1,7 @@
package org.telegram.telegrambots.util;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import org.apache.http.HttpEntity;
import org.apache.http.client.config.RequestConfig;
@ -9,8 +11,6 @@ import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.telegram.telegrambots.Constants;
import org.telegram.telegrambots.bots.DefaultAbsSender;
import org.telegram.telegrambots.bots.DefaultBotOptions;
@ -29,6 +29,7 @@ import static org.telegram.telegrambots.Constants.SOCKET_TIMEOUT;
public final class WebhookUtils {
private static final ContentType TEXT_PLAIN_CONTENT_TYPE = ContentType.create("text/plain", StandardCharsets.UTF_8);
private static final ObjectMapper objectMapper = new ObjectMapper();
private WebhookUtils() {
@ -66,7 +67,7 @@ public final class WebhookUtils {
builder.addTextBody(SetWebhook.MAXCONNECTIONS_FIELD, setWebhook.getMaxConnections().toString(), TEXT_PLAIN_CONTENT_TYPE);
}
if (setWebhook.getAllowedUpdates() != null) {
builder.addTextBody(SetWebhook.ALLOWEDUPDATES_FIELD, new JSONArray(setWebhook.getAllowedUpdates()).toString(), TEXT_PLAIN_CONTENT_TYPE);
builder.addTextBody(SetWebhook.ALLOWEDUPDATES_FIELD, objectMapper.writeValueAsString(setWebhook.getAllowedUpdates()), TEXT_PLAIN_CONTENT_TYPE);
}
if (setWebhook.getIpAddress() != null) {
builder.addTextBody(SetWebhook.IPADDRESS_FIELD, setWebhook.getIpAddress(), TEXT_PLAIN_CONTENT_TYPE);
@ -95,7 +96,7 @@ public final class WebhookUtils {
throw new TelegramApiRequestException("Error setting webhook:" + responseContent);
}
}
} catch (JSONException e) {
} catch (JsonProcessingException e) {
throw new TelegramApiRequestException("Error deserializing setWebhook method response", e);
} catch (IOException e) {
throw new TelegramApiRequestException("Error executing setWebook method", e);