Skip to content

Commit

Permalink
Api Version 5.5
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenlagus committed Dec 7, 2021
1 parent 2212afc commit 3eea18a
Show file tree
Hide file tree
Showing 20 changed files with 233 additions and 29 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>5.4.0.1</version>
<version>5.5.0</version>
</dependency>
```

2. Using Gradle:

```gradle
implementation 'org.telegram:telegrambots:5.4.0.1'
implementation 'org.telegram:telegrambots:5.5.0'
```

3. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/5.4.0.1)
4. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/5.4.0.1)
3. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/5.5.0)
4. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/5.5.0)

In order to use Long Polling mode, just create your own bot extending `org.telegram.telegrambots.bots.TelegramLongPollingBot`.

Expand Down
3 changes: 3 additions & 0 deletions TelegramBots.wiki/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### <a id="5.5.0"></a>5.5.0 ###
1. Update Api version [5.5](https://core.telegram.org/bots/api#december-7-2021)

### <a id="5.4.0.1"></a>5.4.0.1 ###
1. Bug fixing: #999, #1000

Expand Down
4 changes: 2 additions & 2 deletions TelegramBots.wiki/Getting-Started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>5.4.0.1</version>
<version>5.5.0</version>
</dependency>
```
* With **Gradle**:

```gradle
implementation 'org.telegram:telegrambots:5.4.0.1'
implementation 'org.telegram:telegrambots:5.5.0'
```

2. Don't like **Maven Central Repository**? It can also be taken from [Jitpack](https://jitpack.io/#rubenlagus/TelegramBots).
Expand Down
4 changes: 2 additions & 2 deletions TelegramBots.wiki/abilities/Simple-Example.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>5.4.0.1</version>
<version>5.5.0</version>
</dependency>
```
* **Gradle**
```gradle
implementation 'org.telegram:telegrambots-abilities:5.4.0.1'
implementation 'org.telegram:telegrambots-abilities:5.5.0'
```
* [JitPack](https://jitpack.io/#rubenlagus/TelegramBots)

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<packaging>pom</packaging>
<version>5.4.0.1</version>
<version>5.5.0</version>

<modules>
<module>telegrambots</module>
Expand Down
4 changes: 2 additions & 2 deletions telegrambots-abilities/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ Usage
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-abilities</artifactId>
<version>5.4.0.1</version>
<version>5.5.0</version>
</dependency>
```

**Gradle**

```gradle
implementation 'org.telegram:telegrambots-abilities:5.4.0.1'
implementation 'org.telegram:telegrambots-abilities:5.5.0'
```

**JitPack** - [JitPack](https://jitpack.io/#rubenlagus/TelegramBots/v5.0.1)
Expand Down
4 changes: 2 additions & 2 deletions telegrambots-abilities/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<version>5.4.0.1</version>
<version>5.5.0</version>
</parent>

<artifactId>telegrambots-abilities</artifactId>
Expand Down Expand Up @@ -84,7 +84,7 @@
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>5.4.0.1</version>
<version>5.5.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down
4 changes: 2 additions & 2 deletions telegrambots-chat-session-bot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ Usage
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-chat-session-bot</artifactId>
<version>5.4.0.1</version>
<version>5.5.0</version>
</dependency>
```

**Gradle**

```gradle
implementation 'org.telegram:telegrambots-chat-session-bot:5.4.0.1'
implementation 'org.telegram:telegrambots-chat-session-bot:5.5.0'
```

Motivation
Expand Down
4 changes: 2 additions & 2 deletions telegrambots-chat-session-bot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<version>5.4.0.1</version>
<version>5.5.0</version>
</parent>

<artifactId>telegrambots-chat-session-bot</artifactId>
Expand Down Expand Up @@ -84,7 +84,7 @@
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>5.4.0.1</version>
<version>5.5.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.shiro/shiro-core -->
Expand Down
4 changes: 2 additions & 2 deletions telegrambots-extensions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>5.4.0.1</version>
<version>5.5.0</version>
</dependency>
```

2. Using Gradle:

```gradle
implementation 'org.telegram:telegrambotsextensions:5.4.0.1'
implementation 'org.telegram:telegrambotsextensions:5.5.0'
```
4 changes: 2 additions & 2 deletions telegrambots-extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<version>5.4.0.1</version>
<version>5.5.0</version>
</parent>

<artifactId>telegrambotsextensions</artifactId>
Expand Down Expand Up @@ -75,7 +75,7 @@
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>5.4.0.1</version>
<version>5.5.0</version>
</dependency>
</dependencies>

Expand Down
2 changes: 1 addition & 1 deletion telegrambots-meta/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<version>5.4.0.1</version>
<version>5.5.0</version>
</parent>

<artifactId>telegrambots-meta</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package org.telegram.telegrambots.meta.api.methods.groupadministration;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.*;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;

import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
import java.time.ZonedDateTime;

/**
* @author Ruben Bermudez
* @version 5.5
* Use this method to ban a channel chat in a supergroup or a channel.
* The owner of the chat will not be able to send messages and join live streams on behalf of the chat, unless it is unbanned first.
* The bot must be an administrator in the supergroup or channel for this to work and must have the appropriate administrator rights.
* Returns True on success.
*
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@RequiredArgsConstructor
@AllArgsConstructor
@Builder
public class BanChatSenderChat extends BotApiMethod<Boolean> {
public static final String PATH = "banChatSenderChat";

private static final String CHATID_FIELD = "chat_id";
private static final String SENDER_CHAT_ID_FIELD = "sender_chat_id";
private static final String UNTILDATE_FIELD = "until_date";

@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId; ///< Required. Unique identifier for the chat to send the message to (Or username for channels)
@JsonProperty(SENDER_CHAT_ID_FIELD)
@NonNull
private Long senderChatId; ///< Required. Unique identifier of the target sender chat
/**
* Date when the sender chat will be unbanned, unix time.
* If the chat is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever.
*/
@JsonProperty(UNTILDATE_FIELD)
private Integer untilDate;

@JsonIgnore
public void setUntilDateInstant(Instant instant) {
setUntilDate((int) instant.getEpochSecond());
}

@JsonIgnore
public void setUntilDateDateTime(ZonedDateTime date) {
setUntilDateInstant(date.toInstant());
}

@JsonIgnore
public void forTimePeriodDuration(Duration duration) {
setUntilDateInstant(Instant.now().plusMillis(duration.toMillis()));
}

@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 banning chat sender", result);
}
} catch (IOException e) {
throw new TelegramApiRequestException("Unable to deserialize response", e);
}
}

@Override
public void validate() throws TelegramApiValidationException {
if (chatId.isEmpty()) {
throw new TelegramApiValidationException("ChatId can't be empty", this);
}
if (senderChatId == 0) {
throw new TelegramApiValidationException("SenderChatId can't be null or 0", this);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.telegram.telegrambots.meta.api.methods.groupadministration;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.*;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;

import java.io.IOException;

/**
* @author Ruben Bermudez
* @version 5.5
* Use this method to unban a previously banned channel chat in a supergroup or channel.
* The bot must be an administrator for this to work and must have the appropriate administrator rights.
* Returns True on success.
*
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class unbanChatSenderChat extends BotApiMethod<Boolean> {
public static final String PATH = "unbanChatSenderChat";

private static final String CHATID_FIELD = "chat_id";
private static final String SENDER_CHAT_ID_FIELD = "sender_chat_id";

@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId; ///< Required. Unique identifier for the chat to send the message to (Or username for channels)
@JsonProperty(SENDER_CHAT_ID_FIELD)
@NonNull
private Long senderChatId; ///< Required. Unique identifier of the target sender chat

@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 unbanning chat sender", result);
}
} catch (IOException e) {
throw new TelegramApiRequestException("Unable to deserialize response", e);
}
}

@Override
public void validate() throws TelegramApiValidationException {
if (chatId.isEmpty()) {
throw new TelegramApiValidationException("ChatId can't be empty", this);
}
if (senderChatId == 0) {
throw new TelegramApiValidationException("SenderChatId can't be null or 0", this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class Chat implements BotApiObject {
private static final String LINKEDCHATID_FIELD = "linked_chat_id";
private static final String LOCATION_FIELD = "location";
private static final String MESSAGEAUTODELETETIME_FIELD = "message_auto_delete_time";
private static final String ALLOWSAVINGCONTENT_FIELD = "allow_saving_content";
private static final String HASPRIVATEFORWARDS_FIELD = "has_private_forwards";

private static final String USERCHATTYPE = "private";
private static final String GROUPCHATTYPE = "group";
Expand Down Expand Up @@ -116,7 +118,21 @@ public class Chat implements BotApiObject {
private ChatLocation location; ///< Optional. For supergroups, the location to which the supergroup is connected. Returned only in getChat.
@JsonProperty(MESSAGEAUTODELETETIME_FIELD)
private Integer messageAutoDeleteTime; ///< Optional. The time after which all messages sent to the chat will be automatically deleted; in seconds. Returned only in getChat.

/**
* Optional.
* True, if messages from the chat can be forwarded to other chats.
* Returned only in getChat.
*/
@JsonProperty(ALLOWSAVINGCONTENT_FIELD)
private Boolean allowSavingContent;
/**
* Optional.
* True, if privacy settings of the other party in the private chat allows to use tg://user?id=<user_id>
* links only in chats with the user.
* Returned only in getChat.
*/
@JsonProperty(HASPRIVATEFORWARDS_FIELD)
private Boolean hasPrivateForwards;

@JsonIgnore
public Boolean isGroupChat() {
Expand Down
Loading

0 comments on commit 3eea18a

Please sign in to comment.