Merge remote-tracking branch 'TelegramBots/master'
This commit is contained in:
commit
ea4076b319
@ -27,18 +27,18 @@ Just import add the library to your project with one of these options:
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.telegram</groupId>
|
<groupId>org.telegram</groupId>
|
||||||
<artifactId>telegrambots</artifactId>
|
<artifactId>telegrambots</artifactId>
|
||||||
<version>5.7.1</version>
|
<version>6.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Using Gradle:
|
2. Using Gradle:
|
||||||
|
|
||||||
```gradle
|
```gradle
|
||||||
implementation 'org.telegram:telegrambots:5.7.1'
|
implementation 'org.telegram:telegrambots:6.0.1'
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/5.7.1)
|
3. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/6.0.1)
|
||||||
4. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/5.7.1)
|
4. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/6.0.1)
|
||||||
|
|
||||||
In order to use Long Polling mode, just create your own bot extending `org.telegram.telegrambots.bots.TelegramLongPollingBot`.
|
In order to use Long Polling mode, just create your own bot extending `org.telegram.telegrambots.bots.TelegramLongPollingBot`.
|
||||||
|
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
### <a id="6.0.1"></a>6.0.1 ###
|
||||||
|
1. Update Api version [6.0](https://core.telegram.org/bots/api-changelog#april-16-2022)
|
||||||
|
2. Removed all deprecated methods/classes with this major upgrade
|
||||||
|
|
||||||
### <a id="5.7.1"></a>5.7.1 ###
|
### <a id="5.7.1"></a>5.7.1 ###
|
||||||
1. Update Api version [5.7](https://core.telegram.org/bots/api-changelog#january-31-2022)
|
1. Update Api version [5.7](https://core.telegram.org/bots/api-changelog#january-31-2022)
|
||||||
2. Spring boot 2.5.8
|
2. Spring boot 2.5.8
|
||||||
|
@ -11,13 +11,13 @@ First you need ot get the library and add it to your project. There are few poss
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.telegram</groupId>
|
<groupId>org.telegram</groupId>
|
||||||
<artifactId>telegrambots</artifactId>
|
<artifactId>telegrambots</artifactId>
|
||||||
<version>5.7.1</version>
|
<version>6.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
* With **Gradle**:
|
* With **Gradle**:
|
||||||
|
|
||||||
```gradle
|
```gradle
|
||||||
implementation 'org.telegram:telegrambots:5.7.1'
|
implementation 'org.telegram:telegrambots:6.0.1'
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Don't like **Maven Central Repository**? It can also be taken from [Jitpack](https://jitpack.io/#rubenlagus/TelegramBots).
|
2. Don't like **Maven Central Repository**? It can also be taken from [Jitpack](https://jitpack.io/#rubenlagus/TelegramBots).
|
||||||
|
@ -9,12 +9,12 @@ As with any Java project, you will need to set your dependencies.
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.telegram</groupId>
|
<groupId>org.telegram</groupId>
|
||||||
<artifactId>telegrambots-abilities</artifactId>
|
<artifactId>telegrambots-abilities</artifactId>
|
||||||
<version>5.7.1</version>
|
<version>6.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
* **Gradle**
|
* **Gradle**
|
||||||
```gradle
|
```gradle
|
||||||
implementation 'org.telegram:telegrambots-abilities:5.7.1'
|
implementation 'org.telegram:telegrambots-abilities:6.0.1'
|
||||||
```
|
```
|
||||||
* [JitPack](https://jitpack.io/#rubenlagus/TelegramBots)
|
* [JitPack](https://jitpack.io/#rubenlagus/TelegramBots)
|
||||||
|
|
||||||
|
4
pom.xml
4
pom.xml
@ -7,7 +7,7 @@
|
|||||||
<groupId>org.telegram</groupId>
|
<groupId>org.telegram</groupId>
|
||||||
<artifactId>Bots</artifactId>
|
<artifactId>Bots</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<version>5.7.1</version>
|
<version>6.0.1</version>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>telegrambots</module>
|
<module>telegrambots</module>
|
||||||
@ -73,7 +73,7 @@
|
|||||||
<mockito.version>4.3.1</mockito.version>
|
<mockito.version>4.3.1</mockito.version>
|
||||||
<mockitojupiter.version>4.3.1</mockitojupiter.version>
|
<mockitojupiter.version>4.3.1</mockitojupiter.version>
|
||||||
<jacksonanotation.version>2.13.2</jacksonanotation.version>
|
<jacksonanotation.version>2.13.2</jacksonanotation.version>
|
||||||
<jackson.version>2.13.2</jackson.version>
|
<jackson.version>2.13.2.1</jackson.version>
|
||||||
<json.version>20180813</json.version>
|
<json.version>20180813</json.version>
|
||||||
<slf4j.version>1.7.36</slf4j.version>
|
<slf4j.version>1.7.36</slf4j.version>
|
||||||
<jakarta.annotation.version>2.1.0</jakarta.annotation.version>
|
<jakarta.annotation.version>2.1.0</jakarta.annotation.version>
|
||||||
|
@ -18,14 +18,14 @@ Usage
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.telegram</groupId>
|
<groupId>org.telegram</groupId>
|
||||||
<artifactId>telegrambots-abilities</artifactId>
|
<artifactId>telegrambots-abilities</artifactId>
|
||||||
<version>5.7.1</version>
|
<version>6.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
|
|
||||||
**Gradle**
|
**Gradle**
|
||||||
|
|
||||||
```gradle
|
```gradle
|
||||||
implementation 'org.telegram:telegrambots-abilities:5.7.1'
|
implementation 'org.telegram:telegrambots-abilities:6.0.1'
|
||||||
```
|
```
|
||||||
|
|
||||||
**JitPack** - [JitPack](https://jitpack.io/#rubenlagus/TelegramBots/v5.0.1)
|
**JitPack** - [JitPack](https://jitpack.io/#rubenlagus/TelegramBots/v5.0.1)
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.telegram</groupId>
|
<groupId>org.telegram</groupId>
|
||||||
<artifactId>Bots</artifactId>
|
<artifactId>Bots</artifactId>
|
||||||
<version>5.7.1</version>
|
<version>6.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>telegrambots-abilities</artifactId>
|
<artifactId>telegrambots-abilities</artifactId>
|
||||||
@ -86,7 +86,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.telegram</groupId>
|
<groupId>org.telegram</groupId>
|
||||||
<artifactId>telegrambots</artifactId>
|
<artifactId>telegrambots</artifactId>
|
||||||
<version>5.7.1</version>
|
<version>6.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
|
@ -215,16 +215,6 @@ public final class Ability {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Please use {@link #reply(BiConsumer, Predicate[])}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@SafeVarargs
|
|
||||||
public final AbilityBuilder reply(Consumer<Update> action, Predicate<Update>... conditions) {
|
|
||||||
replies.add(Reply.of(action, conditions));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public final AbilityBuilder reply(BiConsumer<BaseAbilityBot, Update> action, Predicate<Update>... conditions) {
|
public final AbilityBuilder reply(BiConsumer<BaseAbilityBot, Update> action, Predicate<Update>... conditions) {
|
||||||
replies.add(Reply.of(action, conditions));
|
replies.add(Reply.of(action, conditions));
|
||||||
|
@ -43,29 +43,6 @@ public class Reply {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Please use {@link #Reply(List, BiConsumer)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
Reply(List<Predicate<Update>> conditions, Consumer<Update> action) {
|
|
||||||
this.conditions = ImmutableList.<Predicate<Update>>builder()
|
|
||||||
.addAll(conditions)
|
|
||||||
.build();
|
|
||||||
this.action = ((baseAbilityBot, update) -> action.accept(update));
|
|
||||||
statsEnabled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Please use {@link #Reply(List, BiConsumer, String)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
Reply(List<Predicate<Update>> conditions, Consumer<Update> action, String name) {
|
|
||||||
this(conditions, action);
|
|
||||||
if (Objects.nonNull(name)) {
|
|
||||||
enableStats(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Reply of(BiConsumer<BaseAbilityBot, Update> action, List<Predicate<Update>> conditions) {
|
public static Reply of(BiConsumer<BaseAbilityBot, Update> action, List<Predicate<Update>> conditions) {
|
||||||
return new Reply(conditions, action);
|
return new Reply(conditions, action);
|
||||||
}
|
}
|
||||||
@ -75,23 +52,6 @@ public class Reply {
|
|||||||
return Reply.of(action, newArrayList(conditions));
|
return Reply.of(action, newArrayList(conditions));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Please use {@link #of(BiConsumer, List)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public static Reply of(Consumer<Update> action, List<Predicate<Update>> conditions) {
|
|
||||||
return new Reply(conditions, action);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Please use {@link #of(BiConsumer, Predicate[])}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@SafeVarargs
|
|
||||||
public static Reply of(Consumer<Update> action, Predicate<Update>... conditions) {
|
|
||||||
return Reply.of(action, newArrayList(conditions));
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isOkFor(Update update) {
|
public boolean isOkFor(Update update) {
|
||||||
// The following variable is required to avoid bug #JDK-8044546
|
// The following variable is required to avoid bug #JDK-8044546
|
||||||
BiFunction<Boolean, Predicate<Update>, Boolean> stateAnd = (state, cond) -> state && cond.test(update);
|
BiFunction<Boolean, Predicate<Update>, Boolean> stateAnd = (state, cond) -> state && cond.test(update);
|
||||||
|
@ -65,15 +65,6 @@ public class ReplyFlow extends Reply {
|
|||||||
this(db, replyCounter.getAndIncrement());
|
this(db, replyCounter.getAndIncrement());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Please use {@link #action(BiConsumer)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public ReplyFlowBuilder action(Consumer<Update> action) {
|
|
||||||
this.action = (bot, update) -> action.accept(update);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ReplyFlowBuilder action(BiConsumer<BaseAbilityBot, Update> action) {
|
public ReplyFlowBuilder action(BiConsumer<BaseAbilityBot, Update> action) {
|
||||||
this.action = action;
|
this.action = action;
|
||||||
return this;
|
return this;
|
||||||
|
@ -78,19 +78,20 @@ public class DefaultBot extends AbilityBot {
|
|||||||
|
|
||||||
public Reply channelPostReply() {
|
public Reply channelPostReply() {
|
||||||
return Reply.of(
|
return Reply.of(
|
||||||
(bot, upd) -> silent.send("test channel post", upd.getChannelPost().getChatId()), Flag.CHANNEL_POST
|
(bot, upd) -> silent.send("test channel post", upd.getChannelPost().getChatId()),
|
||||||
|
Flag.CHANNEL_POST
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReplyCollection createReplyCollection() {
|
public ReplyCollection createReplyCollection() {
|
||||||
return ReplyCollection.of(
|
return ReplyCollection.of(
|
||||||
Reply.of(
|
Reply.of(
|
||||||
upd -> silent.send("first reply answer", upd.getMessage().getChatId()),
|
(bot, upd) -> silent.send("first reply answer", upd.getMessage().getChatId()),
|
||||||
update -> update.getMessage().getText().equalsIgnoreCase(FIRST_REPLY_KEY_MESSAGE)
|
update -> update.getMessage().getText().equalsIgnoreCase(FIRST_REPLY_KEY_MESSAGE)
|
||||||
),
|
),
|
||||||
Reply.of(
|
Reply.of(
|
||||||
upd -> silent.send("second reply answer", upd.getMessage().getChatId()),
|
(bot, upd) -> silent.send("second reply answer", upd.getMessage().getChatId()),
|
||||||
update -> update.getMessage().getText().equalsIgnoreCase(SECOND_REPLY_KEY_MESSAGE)
|
update -> update.getMessage().getText().equalsIgnoreCase(SECOND_REPLY_KEY_MESSAGE)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -15,14 +15,14 @@ Usage
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.telegram</groupId>
|
<groupId>org.telegram</groupId>
|
||||||
<artifactId>telegrambots-chat-session-bot</artifactId>
|
<artifactId>telegrambots-chat-session-bot</artifactId>
|
||||||
<version>5.7.1</version>
|
<version>6.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
|
|
||||||
**Gradle**
|
**Gradle**
|
||||||
|
|
||||||
```gradle
|
```gradle
|
||||||
implementation 'org.telegram:telegrambots-chat-session-bot:5.7.1'
|
implementation 'org.telegram:telegrambots-chat-session-bot:6.0.1'
|
||||||
```
|
```
|
||||||
|
|
||||||
Motivation
|
Motivation
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.telegram</groupId>
|
<groupId>org.telegram</groupId>
|
||||||
<artifactId>Bots</artifactId>
|
<artifactId>Bots</artifactId>
|
||||||
<version>5.7.1</version>
|
<version>6.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>telegrambots-chat-session-bot</artifactId>
|
<artifactId>telegrambots-chat-session-bot</artifactId>
|
||||||
@ -86,7 +86,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.telegram</groupId>
|
<groupId>org.telegram</groupId>
|
||||||
<artifactId>telegrambots</artifactId>
|
<artifactId>telegrambots</artifactId>
|
||||||
<version>5.7.1</version>
|
<version>6.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- https://mvnrepository.com/artifact/org.apache.shiro/shiro-core -->
|
<!-- https://mvnrepository.com/artifact/org.apache.shiro/shiro-core -->
|
||||||
|
@ -16,12 +16,12 @@ Just import add the library to your project with one of these options:
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.telegram</groupId>
|
<groupId>org.telegram</groupId>
|
||||||
<artifactId>telegrambotsextensions</artifactId>
|
<artifactId>telegrambotsextensions</artifactId>
|
||||||
<version>5.7.1</version>
|
<version>6.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Using Gradle:
|
2. Using Gradle:
|
||||||
|
|
||||||
```gradle
|
```gradle
|
||||||
implementation 'org.telegram:telegrambotsextensions:5.7.1'
|
implementation 'org.telegram:telegrambotsextensions:6.0.1'
|
||||||
```
|
```
|
@ -7,7 +7,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.telegram</groupId>
|
<groupId>org.telegram</groupId>
|
||||||
<artifactId>Bots</artifactId>
|
<artifactId>Bots</artifactId>
|
||||||
<version>5.7.1</version>
|
<version>6.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>telegrambotsextensions</artifactId>
|
<artifactId>telegrambotsextensions</artifactId>
|
||||||
@ -77,7 +77,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.telegram</groupId>
|
<groupId>org.telegram</groupId>
|
||||||
<artifactId>telegrambots</artifactId>
|
<artifactId>telegrambots</artifactId>
|
||||||
<version>5.7.1</version>
|
<version>6.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.telegram</groupId>
|
<groupId>org.telegram</groupId>
|
||||||
<artifactId>Bots</artifactId>
|
<artifactId>Bots</artifactId>
|
||||||
<version>5.7.1</version>
|
<version>6.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>telegrambots-meta</artifactId>
|
<artifactId>telegrambots-meta</artifactId>
|
||||||
|
@ -9,20 +9,10 @@ public enum ActionType {
|
|||||||
TYPING("typing"),
|
TYPING("typing"),
|
||||||
RECORDVIDEO("record_video"),
|
RECORDVIDEO("record_video"),
|
||||||
RECORDVIDEONOTE("record_video_note"),
|
RECORDVIDEONOTE("record_video_note"),
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #RECORDVOICE} instead
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
RECORDAUDIO("record_audio"),
|
|
||||||
RECORDVOICE("record_voice"),
|
RECORDVOICE("record_voice"),
|
||||||
UPLOADPHOTO("upload_photo"),
|
UPLOADPHOTO("upload_photo"),
|
||||||
UPLOADVIDEO("upload_video"),
|
UPLOADVIDEO("upload_video"),
|
||||||
UPLOADVIDEONOTE("upload_video_note"),
|
UPLOADVIDEONOTE("upload_video_note"),
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #UPLOADVOICE} instead
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
UPLOADAUDIO("upload_audio"),
|
|
||||||
UPLOADVOICE("upload_voice"),
|
UPLOADVOICE("upload_voice"),
|
||||||
UPLOADDOCUMENT("upload_document"),
|
UPLOADDOCUMENT("upload_document"),
|
||||||
FINDLOCATION("find_location");
|
FINDLOCATION("find_location");
|
||||||
|
@ -0,0 +1,66 @@
|
|||||||
|
package org.telegram.telegrambots.meta.api.methods.adminrights;
|
||||||
|
|
||||||
|
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.api.objects.adminrights.ChatAdministratorRights;
|
||||||
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||||
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Ruben Bermudez
|
||||||
|
* @version 6.0
|
||||||
|
*
|
||||||
|
* Use this method to get the current default administrator rights of the bot.
|
||||||
|
*
|
||||||
|
* Returns ChatAdministratorRights on success.
|
||||||
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class GetMyDefaultAdministratorRights extends BotApiMethod<ChatAdministratorRights> {
|
||||||
|
public static final String PATH = "getMyDefaultAdministratorRights";
|
||||||
|
|
||||||
|
private static final String FORCHANNELS_FIELD = "for_channels";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional
|
||||||
|
* Pass True to change default administrator rights of the bot in channels.
|
||||||
|
* Otherwise, default administrator rights of the bot for groups and supergroups will be changed.
|
||||||
|
*/
|
||||||
|
@JsonProperty(FORCHANNELS_FIELD)
|
||||||
|
private Boolean forChannels;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMethod() {
|
||||||
|
return PATH;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChatAdministratorRights deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||||
|
try {
|
||||||
|
ApiResponse<ChatAdministratorRights> result = OBJECT_MAPPER.readValue(answer,
|
||||||
|
new TypeReference<ApiResponse<ChatAdministratorRights>>(){});
|
||||||
|
if (result.getOk()) {
|
||||||
|
return result.getResult();
|
||||||
|
} else {
|
||||||
|
throw new TelegramApiRequestException("Error getting default administrator rights", result);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validate() throws TelegramApiValidationException {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,74 @@
|
|||||||
|
package org.telegram.telegrambots.meta.api.methods.adminrights;
|
||||||
|
|
||||||
|
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.api.objects.adminrights.ChatAdministratorRights;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.commands.scope.BotCommandScope;
|
||||||
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||||
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Ruben Bermudez
|
||||||
|
* @version 6.0
|
||||||
|
*
|
||||||
|
* Use this method to change default administrator rights of the bot for adding it as an administrator to groups or channels.
|
||||||
|
* Returns True on success.
|
||||||
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class SetMyDefaultAdministratorRights extends BotApiMethod<Boolean> {
|
||||||
|
public static final String PATH = "setMyDefaultAdministratorRights";
|
||||||
|
|
||||||
|
private static final String RIGHTS_FIELD = "rights";
|
||||||
|
private static final String FORCHANNELS_FIELD = "for_channels";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional
|
||||||
|
* A JSON-serialized object, describing new default administrator rights.
|
||||||
|
* If not specified, the default administrator rights will be cleared.
|
||||||
|
*/
|
||||||
|
@JsonProperty(RIGHTS_FIELD)
|
||||||
|
private ChatAdministratorRights rights;
|
||||||
|
/**
|
||||||
|
* Optional
|
||||||
|
* Pass True to change default administrator rights of the bot in channels.
|
||||||
|
* Otherwise, default administrator rights of the bot for groups and supergroups will be changed.
|
||||||
|
*/
|
||||||
|
@JsonProperty(FORCHANNELS_FIELD)
|
||||||
|
private Boolean forChannels;
|
||||||
|
|
||||||
|
@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 default administrator rights", result);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validate() throws TelegramApiValidationException {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -66,7 +66,7 @@ public class DeleteMyCommands extends BotApiMethod<Boolean> {
|
|||||||
if (result.getOk()) {
|
if (result.getOk()) {
|
||||||
return result.getResult();
|
return result.getResult();
|
||||||
} else {
|
} else {
|
||||||
throw new TelegramApiRequestException("Error sending commands", result);
|
throw new TelegramApiRequestException("Error deleting commands", result);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||||
|
@ -1,120 +0,0 @@
|
|||||||
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.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.NonNull;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.Setter;
|
|
||||||
import lombok.ToString;
|
|
||||||
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 1.0
|
|
||||||
* Use this method to kick a user from a group, a supergroup or a channel. In the case of supergroups,
|
|
||||||
* the user will not be able to return to the group on their own using invite links, etc., unless
|
|
||||||
* unbanned first. The bot must be an administrator in the group for this to work. Returns True on
|
|
||||||
* success.
|
|
||||||
* @apiNote This will method only work if the ‘All Members Are Admins’ setting is off in the target
|
|
||||||
* group. Otherwise members may only be removed by the group's creator or by the member that added
|
|
||||||
* them.
|
|
||||||
*
|
|
||||||
* @deprecated Use {@link BanChatMember#BanChatMember()} instead
|
|
||||||
*/
|
|
||||||
@EqualsAndHashCode(callSuper = false)
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@ToString
|
|
||||||
@NoArgsConstructor
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
@Builder
|
|
||||||
@Deprecated
|
|
||||||
public class KickChatMember extends BotApiMethod<Boolean> {
|
|
||||||
public static final String PATH = "kickchatmember";
|
|
||||||
|
|
||||||
private static final String CHATID_FIELD = "chat_id";
|
|
||||||
private static final String USER_ID_FIELD = "user_id";
|
|
||||||
private static final String UNTILDATE_FIELD = "until_date";
|
|
||||||
private static final String REVOKEMESSAGES_FIELD = "revoke_messages";
|
|
||||||
|
|
||||||
@JsonProperty(CHATID_FIELD)
|
|
||||||
@NonNull
|
|
||||||
private String chatId; ///< Required. Unique identifier for the chat to send the message to (Or username for channels)
|
|
||||||
@JsonProperty(USER_ID_FIELD)
|
|
||||||
@NonNull
|
|
||||||
private Long userId; ///< Required. Unique identifier of the target user
|
|
||||||
@JsonProperty(UNTILDATE_FIELD)
|
|
||||||
private Integer untilDate; ///< Optional. Date when the user will be unbanned, unix time. If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever
|
|
||||||
/**
|
|
||||||
* Optional
|
|
||||||
*
|
|
||||||
* Pass True to delete all messages from the chat for the user that is being removed.
|
|
||||||
*
|
|
||||||
* If False, the user will be able to see messages in the group that were sent before the user was removed.
|
|
||||||
*
|
|
||||||
* Always True for supergroups and channels.
|
|
||||||
*/
|
|
||||||
@JsonProperty(REVOKEMESSAGES_FIELD)
|
|
||||||
private Boolean revokeMessages;
|
|
||||||
|
|
||||||
|
|
||||||
@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 kicking chat member", result);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void validate() throws TelegramApiValidationException {
|
|
||||||
if (chatId == null || chatId.isEmpty()) {
|
|
||||||
throw new TelegramApiValidationException("ChatId can't be empty", this);
|
|
||||||
}
|
|
||||||
if (userId == null) {
|
|
||||||
throw new TelegramApiValidationException("UserId can't be null", this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -49,7 +49,7 @@ public class PromoteChatMember extends BotApiMethod<Boolean> {
|
|||||||
private static final String CANPROMOTEMEMBERS_FIELD = "can_promote_members";
|
private static final String CANPROMOTEMEMBERS_FIELD = "can_promote_members";
|
||||||
private static final String ISANONYMOUS_FIELD = "is_anonymous";
|
private static final String ISANONYMOUS_FIELD = "is_anonymous";
|
||||||
private static final String CANMANAGECHAT_FIELD = "can_manage_chat";
|
private static final String CANMANAGECHAT_FIELD = "can_manage_chat";
|
||||||
private static final String CANMANAGEVOICECHATS_FIELD = "can_manage_voice_chats";
|
private static final String CANMANAGEVIDEOCHATS_FIELD = "can_manage_video_chats";
|
||||||
|
|
||||||
@JsonProperty(CHATID_FIELD)
|
@JsonProperty(CHATID_FIELD)
|
||||||
@NonNull
|
@NonNull
|
||||||
@ -86,12 +86,11 @@ public class PromoteChatMember extends BotApiMethod<Boolean> {
|
|||||||
@JsonProperty(CANMANAGECHAT_FIELD)
|
@JsonProperty(CANMANAGECHAT_FIELD)
|
||||||
private Boolean canManageChat;
|
private Boolean canManageChat;
|
||||||
/**
|
/**
|
||||||
* Optional.
|
* Optional
|
||||||
*
|
* Pass True, if the administrator can manage video chats
|
||||||
* Pass True, if the administrator can manage voice chats, supergroups only
|
|
||||||
*/
|
*/
|
||||||
@JsonProperty(CANMANAGEVOICECHATS_FIELD)
|
@JsonProperty(CANMANAGEVIDEOCHATS_FIELD)
|
||||||
private Boolean canManageVoiceChats;
|
private Boolean canManageVideoChats;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getMethod() {
|
public String getMethod() {
|
||||||
@ -116,11 +115,11 @@ public class PromoteChatMember extends BotApiMethod<Boolean> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void validate() throws TelegramApiValidationException {
|
public void validate() throws TelegramApiValidationException {
|
||||||
if (chatId == null || chatId.isEmpty()) {
|
if (chatId.isEmpty()) {
|
||||||
throw new TelegramApiValidationException("ChatId can't be empty", this);
|
throw new TelegramApiValidationException("ChatId can't be empty", this);
|
||||||
}
|
}
|
||||||
if (userId == null) {
|
if (userId == 0L) {
|
||||||
throw new TelegramApiValidationException("UserId can't be null", this);
|
throw new TelegramApiValidationException("UserId can't be empty", this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,11 @@
|
|||||||
package org.telegram.telegrambots.meta.api.methods.groupadministration;
|
package org.telegram.telegrambots.meta.api.methods.menubutton;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.*;
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.NonNull;
|
|
||||||
import lombok.Setter;
|
|
||||||
import lombok.ToString;
|
|
||||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
||||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.menubutton.MenuButton;
|
||||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||||
|
|
||||||
@ -19,10 +13,11 @@ import java.io.IOException;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Ruben Bermudez
|
* @author Ruben Bermudez
|
||||||
* @version 1.0
|
* @version 6.0
|
||||||
* Use this method to get the number of members in a chat. Returns Int on success.
|
|
||||||
*
|
*
|
||||||
* @deprecated Use {{@link GetChatMemberCount#GetChatMemberCount()}
|
* Use this method to get the current value of the bot's menu button in a private chat, or the default menu button.
|
||||||
|
*
|
||||||
|
* Returns MenuButton on success.
|
||||||
*/
|
*/
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
@Getter
|
@Getter
|
||||||
@ -31,15 +26,23 @@ import java.io.IOException;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Builder
|
@Builder
|
||||||
@Deprecated
|
public class GetChatMenuButton extends BotApiMethod<MenuButton> {
|
||||||
public class GetChatMembersCount extends BotApiMethod<Integer> {
|
public static final String PATH = "getChatMenuButton";
|
||||||
public static final String PATH = "getChatMembersCount";
|
|
||||||
|
|
||||||
private static final String CHATID_FIELD = "chat_id";
|
private static final String CHATID_FIELD = "chat_id";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional
|
||||||
|
* Unique identifier for the target private chat.
|
||||||
|
* If not specified, default bot's menu button will be returned
|
||||||
|
*/
|
||||||
@JsonProperty(CHATID_FIELD)
|
@JsonProperty(CHATID_FIELD)
|
||||||
@NonNull
|
private String chatId;
|
||||||
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
|
|
||||||
|
@Override
|
||||||
|
public void validate() throws TelegramApiValidationException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getMethod() {
|
public String getMethod() {
|
||||||
@ -47,24 +50,17 @@ public class GetChatMembersCount extends BotApiMethod<Integer> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer deserializeResponse(String answer) throws TelegramApiRequestException {
|
public MenuButton deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||||
try {
|
try {
|
||||||
ApiResponse<Integer> result = OBJECT_MAPPER.readValue(answer,
|
ApiResponse<MenuButton> result = OBJECT_MAPPER.readValue(answer,
|
||||||
new TypeReference<ApiResponse<Integer>>(){});
|
new TypeReference<ApiResponse<MenuButton>>(){});
|
||||||
if (result.getOk()) {
|
if (result.getOk()) {
|
||||||
return result.getResult();
|
return result.getResult();
|
||||||
} else {
|
} else {
|
||||||
throw new TelegramApiRequestException("Error getting chat members count", result);
|
throw new TelegramApiRequestException("Error getting chat menu button query", result);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void validate() throws TelegramApiValidationException {
|
|
||||||
if (chatId == null || chatId.isEmpty()) {
|
|
||||||
throw new TelegramApiValidationException("ChatId can't be empty", this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -0,0 +1,78 @@
|
|||||||
|
package org.telegram.telegrambots.meta.api.methods.menubutton;
|
||||||
|
|
||||||
|
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.api.objects.inlinequery.result.InlineQueryResult;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.menubutton.MenuButton;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.webapp.SentWebAppMessage;
|
||||||
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||||
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Ruben Bermudez
|
||||||
|
* @version 6.0
|
||||||
|
*
|
||||||
|
* Use this method to change bot's menu button in a private chat, or the default menu button.
|
||||||
|
*
|
||||||
|
* Returns True on success.
|
||||||
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class SetChatMenuButton extends BotApiMethod<Boolean> {
|
||||||
|
public static final String PATH = "setChatMenuButton";
|
||||||
|
|
||||||
|
private static final String CHATID_FIELD = "chat_id";
|
||||||
|
private static final String MENUBUTTON_FIELD = "menu_button";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional
|
||||||
|
* Unique identifier for the target private chat.
|
||||||
|
* If not specified, default bot's menu button will be changed
|
||||||
|
*/
|
||||||
|
@JsonProperty(CHATID_FIELD)
|
||||||
|
private String chatId;
|
||||||
|
/**
|
||||||
|
* Optional
|
||||||
|
* A JSON-serialized object for the new bot's menu button.
|
||||||
|
* Defaults to MenuButtonDefault
|
||||||
|
*/
|
||||||
|
@JsonProperty(MENUBUTTON_FIELD)
|
||||||
|
private MenuButton menuButton;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validate() throws TelegramApiValidationException {
|
||||||
|
if (menuButton != null) {
|
||||||
|
menuButton.validate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 chat menu button query", result);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,74 @@
|
|||||||
|
package org.telegram.telegrambots.meta.api.methods.webapp;
|
||||||
|
|
||||||
|
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.api.objects.inlinequery.result.InlineQueryResult;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.payments.ShippingOption;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.webapp.SentWebAppMessage;
|
||||||
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||||
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Ruben Bermudez
|
||||||
|
* @version 6.0
|
||||||
|
*
|
||||||
|
* Use this method to set result of interaction with web app and send corresponding
|
||||||
|
* message on behalf of the user to the chat from which the query originated.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* On success, SentWebAppMessage is returned.
|
||||||
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class AnswerWebAppQuery extends BotApiMethod<SentWebAppMessage> {
|
||||||
|
public static final String PATH = "answerWebAppQuery";
|
||||||
|
|
||||||
|
private static final String WEBAPPQUERYID_FIELD = "web_app_query_id";
|
||||||
|
private static final String RESULT_FIELD = "result";
|
||||||
|
|
||||||
|
@JsonProperty(WEBAPPQUERYID_FIELD)
|
||||||
|
@NonNull
|
||||||
|
private String webAppQueryId; ///< Unique identifier for the answered query
|
||||||
|
@JsonProperty(RESULT_FIELD)
|
||||||
|
@NonNull
|
||||||
|
private InlineQueryResult queryResult; ///< A JSON-serialized object with a description of the message to send
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validate() throws TelegramApiValidationException {
|
||||||
|
if (webAppQueryId.isEmpty()) {
|
||||||
|
throw new TelegramApiValidationException("WebAppQueryId can't be empty", this);
|
||||||
|
}
|
||||||
|
|
||||||
|
queryResult.validate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMethod() {
|
||||||
|
return PATH;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SentWebAppMessage deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||||
|
try {
|
||||||
|
ApiResponse<SentWebAppMessage> result = OBJECT_MAPPER.readValue(answer,
|
||||||
|
new TypeReference<ApiResponse<SentWebAppMessage>>(){});
|
||||||
|
if (result.getOk()) {
|
||||||
|
return result.getResult();
|
||||||
|
} else {
|
||||||
|
throw new TelegramApiRequestException("Error answering web app query query", result);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -17,10 +17,11 @@ import org.telegram.telegrambots.meta.api.objects.payments.SuccessfulPayment;
|
|||||||
import org.telegram.telegrambots.meta.api.objects.polls.Poll;
|
import org.telegram.telegrambots.meta.api.objects.polls.Poll;
|
||||||
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
|
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
|
||||||
import org.telegram.telegrambots.meta.api.objects.stickers.Sticker;
|
import org.telegram.telegrambots.meta.api.objects.stickers.Sticker;
|
||||||
import org.telegram.telegrambots.meta.api.objects.voicechat.VoiceChatEnded;
|
import org.telegram.telegrambots.meta.api.objects.videochat.VideoChatEnded;
|
||||||
import org.telegram.telegrambots.meta.api.objects.voicechat.VoiceChatParticipantsInvited;
|
import org.telegram.telegrambots.meta.api.objects.videochat.VideoChatParticipantsInvited;
|
||||||
import org.telegram.telegrambots.meta.api.objects.voicechat.VoiceChatScheduled;
|
import org.telegram.telegrambots.meta.api.objects.videochat.VideoChatScheduled;
|
||||||
import org.telegram.telegrambots.meta.api.objects.voicechat.VoiceChatStarted;
|
import org.telegram.telegrambots.meta.api.objects.videochat.VideoChatStarted;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.webapp.WebAppData;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -89,12 +90,13 @@ public class Message implements BotApiObject {
|
|||||||
private static final String SENDERCHAT_FIELD = "sender_chat";
|
private static final String SENDERCHAT_FIELD = "sender_chat";
|
||||||
private static final String PROXIMITYALERTTRIGGERED_FIELD = "proximity_alert_triggered";
|
private static final String PROXIMITYALERTTRIGGERED_FIELD = "proximity_alert_triggered";
|
||||||
private static final String MESSAGEAUTODELETETIMERCHANGED_FIELD = "message_auto_delete_timer_changed";
|
private static final String MESSAGEAUTODELETETIMERCHANGED_FIELD = "message_auto_delete_timer_changed";
|
||||||
private static final String VOICECHATSTARTED_FIELD = "voice_chat_started";
|
|
||||||
private static final String VOICECHATENDED_FIELD = "voice_chat_ended";
|
|
||||||
private static final String VOICECHATPARTICIPANTSINVITED_FIELD = "voice_chat_participants_invited";
|
|
||||||
private static final String VOICECHATSCHEDULED_FIELD = "voice_chat_scheduled";
|
|
||||||
private static final String ISAUTOMATICFORWARD_FIELD = "is_automatic_forward";
|
private static final String ISAUTOMATICFORWARD_FIELD = "is_automatic_forward";
|
||||||
private static final String HASPROTECTEDCONTENT_FIELD = "has_protected_content";
|
private static final String HASPROTECTEDCONTENT_FIELD = "has_protected_content";
|
||||||
|
private static final String WEBAPPDATA_FIELD = "web_app_data";
|
||||||
|
private static final String VIDEOCHATSCHEDULED_FIELD = "video_chat_scheduled";
|
||||||
|
private static final String VIDEOCHATSTARTED_FIELD = "video_chat_started";
|
||||||
|
private static final String VIDEOCHATENDED_FIELD = "video_chat_ended";
|
||||||
|
private static final String VIDEOCHATPARTICIPANTSINVITED_FIELD = "video_chat_participants_invited";
|
||||||
|
|
||||||
private static final String VIEWS_FIELD = "views";
|
private static final String VIEWS_FIELD = "views";
|
||||||
private static final String OUTGOING_FIELD = "outgoing";
|
private static final String OUTGOING_FIELD = "outgoing";
|
||||||
@ -267,14 +269,6 @@ public class Message implements BotApiObject {
|
|||||||
private ProximityAlertTriggered proximityAlertTriggered;
|
private ProximityAlertTriggered proximityAlertTriggered;
|
||||||
@JsonProperty(MESSAGEAUTODELETETIMERCHANGED_FIELD)
|
@JsonProperty(MESSAGEAUTODELETETIMERCHANGED_FIELD)
|
||||||
private MessageAutoDeleteTimerChanged messageAutoDeleteTimerChanged; ///< Optional. Service message: auto-delete timer settings changed in the chat
|
private MessageAutoDeleteTimerChanged messageAutoDeleteTimerChanged; ///< Optional. Service message: auto-delete timer settings changed in the chat
|
||||||
@JsonProperty(VOICECHATSTARTED_FIELD)
|
|
||||||
private VoiceChatStarted voiceChatStarted; ///< Optional. Service message: voice chat started
|
|
||||||
@JsonProperty(VOICECHATENDED_FIELD)
|
|
||||||
private VoiceChatEnded voiceChatEnded; ///< Optional. Service message: voice chat ended
|
|
||||||
@JsonProperty(VOICECHATPARTICIPANTSINVITED_FIELD)
|
|
||||||
private VoiceChatParticipantsInvited voiceChatParticipantsInvited; ///< Optional. Service message: new members invited to a voice chat
|
|
||||||
@JsonProperty(VOICECHATSCHEDULED_FIELD)
|
|
||||||
private VoiceChatScheduled voiceChatScheduled; ///< Optional. Service message: voice chat scheduled
|
|
||||||
@JsonProperty(ISAUTOMATICFORWARD_FIELD)
|
@JsonProperty(ISAUTOMATICFORWARD_FIELD)
|
||||||
/**
|
/**
|
||||||
* Optional.
|
* Optional.
|
||||||
@ -283,6 +277,16 @@ public class Message implements BotApiObject {
|
|||||||
private Boolean isAutomaticForward;
|
private Boolean isAutomaticForward;
|
||||||
@JsonProperty(HASPROTECTEDCONTENT_FIELD)
|
@JsonProperty(HASPROTECTEDCONTENT_FIELD)
|
||||||
private Boolean hasProtectedContent; ///< Optional. True, if the message can't be forwarded
|
private Boolean hasProtectedContent; ///< Optional. True, if the message can't be forwarded
|
||||||
|
@JsonProperty(WEBAPPDATA_FIELD)
|
||||||
|
private WebAppData webAppData; ///< Optional. Service message: data sent by a web app
|
||||||
|
@JsonProperty(VIDEOCHATSTARTED_FIELD)
|
||||||
|
private VideoChatStarted videoChatStarted; ///< Optional. Service message: video chat started
|
||||||
|
@JsonProperty(VIDEOCHATENDED_FIELD)
|
||||||
|
private VideoChatEnded videoChatEnded; ///< Optional. Service message: video chat ended
|
||||||
|
@JsonProperty(VIDEOCHATPARTICIPANTSINVITED_FIELD)
|
||||||
|
private VideoChatParticipantsInvited videoChatParticipantsInvited; ///< Optional. Service message: new participants invited to a video chat
|
||||||
|
@JsonProperty(VIDEOCHATSCHEDULED_FIELD)
|
||||||
|
private VideoChatScheduled videoChatScheduled; ///< Optional. Service message: video chat scheduled
|
||||||
|
|
||||||
@JsonProperty(OUTGOING_FIELD)
|
@JsonProperty(OUTGOING_FIELD)
|
||||||
private Boolean outgoing; ///< Optional. Extra.
|
private Boolean outgoing; ///< Optional. Extra.
|
||||||
@ -458,22 +462,27 @@ public class Message implements BotApiObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
private boolean hasVoiceChatStarted() {
|
private boolean hasWebAppData() {
|
||||||
return voiceChatStarted != null;
|
return webAppData != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
private boolean hasVoiceChatEnded() {
|
private boolean hasVideoChatStarted() {
|
||||||
return voiceChatEnded != null;
|
return videoChatStarted != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
private boolean hasVoiceChatScheduled() {
|
private boolean hasVideoChatEnded() {
|
||||||
return voiceChatScheduled != null;
|
return videoChatEnded != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
private boolean hasVoiceChatParticipantsInvited() {
|
private boolean hasVideoChatScheduled() {
|
||||||
return voiceChatParticipantsInvited != null;
|
return videoChatScheduled != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
private boolean hasVideoChatParticipantsInvited() {
|
||||||
|
return videoChatParticipantsInvited != null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ public class WebhookInfo implements BotApiObject {
|
|||||||
private static final String LASTERRORDATE_FIELD = "last_error_date";
|
private static final String LASTERRORDATE_FIELD = "last_error_date";
|
||||||
private static final String LASTERRORMESSAGE_FIELD = "last_error_message";
|
private static final String LASTERRORMESSAGE_FIELD = "last_error_message";
|
||||||
private static final String IPADDRESS_FIELD = "ip_address";
|
private static final String IPADDRESS_FIELD = "ip_address";
|
||||||
|
private static final String LASTSYNCHRONIZATIONERRORDATE_FIELD = "last_synchronization_error_date";
|
||||||
|
|
||||||
@JsonProperty(URL_FIELD)
|
@JsonProperty(URL_FIELD)
|
||||||
private String url; ///< Webhook URL, may be empty if webhook is not set up
|
private String url; ///< Webhook URL, may be empty if webhook is not set up
|
||||||
@ -49,4 +50,10 @@ public class WebhookInfo implements BotApiObject {
|
|||||||
private List<String> allowedUpdates; ///< Optional. A list of update types the bot is subscribed to. Defaults to all update types
|
private List<String> allowedUpdates; ///< Optional. A list of update types the bot is subscribed to. Defaults to all update types
|
||||||
@JsonProperty(IPADDRESS_FIELD)
|
@JsonProperty(IPADDRESS_FIELD)
|
||||||
private String ipAddress; ///< Optional. Currently used webhook IP address
|
private String ipAddress; ///< Optional. Currently used webhook IP address
|
||||||
|
/**
|
||||||
|
* Optional.
|
||||||
|
* Unix time of the most recent error that happened when trying to synchronize available updates with Telegram datacenters
|
||||||
|
*/
|
||||||
|
@JsonProperty(LASTSYNCHRONIZATIONERRORDATE_FIELD)
|
||||||
|
private Integer lastSynchronizationErrorDate;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,68 @@
|
|||||||
|
package org.telegram.telegrambots.meta.api.objects.adminrights;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.*;
|
||||||
|
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Ruben Bermudez
|
||||||
|
* @version 6.0
|
||||||
|
*
|
||||||
|
* Represents rights of an administrator in a chat.
|
||||||
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class ChatAdministratorRights implements BotApiObject {
|
||||||
|
|
||||||
|
private static final String ISANONYMOUS_FIELD = "is_anonymous";
|
||||||
|
private static final String CANMANAGECHAT_FIELD = "can_manage_chat";
|
||||||
|
private static final String CANDELETEMESSAGES_FIELD = "can_delete_messages";
|
||||||
|
private static final String CANMANAGEVIDEOCHATS_FIELD = "can_manage_video_chats";
|
||||||
|
private static final String CANRESTRICTMEMBERS_FIELD = "can_restrict_members";
|
||||||
|
private static final String CANPROMOTEMEMBERS_FIELD = "can_promote_members";
|
||||||
|
private static final String CANCHANGEINFO_FIELD = "can_change_info";
|
||||||
|
private static final String CANINVITEUSERS_FIELD = "can_invite_users";
|
||||||
|
private static final String CANPOSTMESSAGES_FIELD = "can_post_messages";
|
||||||
|
private static final String CANEDITMESSAGES_FIELD = "can_edit_messages";
|
||||||
|
private static final String CANPINMESSAGES_FIELD = "can_pin_messages";
|
||||||
|
|
||||||
|
@JsonProperty(ISANONYMOUS_FIELD)
|
||||||
|
private Boolean isAnonymous; ///< True, if the user's presence in the chat is hidden
|
||||||
|
/**
|
||||||
|
* True, if the administrator can access the chat event log, chat statistics,
|
||||||
|
* message statistics in channels, see channel members, see anonymous administrators
|
||||||
|
* in supergroups and ignore slow mode.
|
||||||
|
* Implied by any other administrator privilege
|
||||||
|
*/
|
||||||
|
@JsonProperty(CANMANAGECHAT_FIELD)
|
||||||
|
private Boolean canManageChat;
|
||||||
|
@JsonProperty(CANDELETEMESSAGES_FIELD)
|
||||||
|
private Boolean canDeleteMessages; ///< True, if the administrator can delete messages of other users
|
||||||
|
@JsonProperty(CANMANAGEVIDEOCHATS_FIELD)
|
||||||
|
private Boolean canManageVideoChats; ///< True, if the administrator can manage video chats
|
||||||
|
@JsonProperty(CANRESTRICTMEMBERS_FIELD)
|
||||||
|
private Boolean canRestrictMembers; ///< True, if the administrator can restrict, ban or unban chat members
|
||||||
|
/**
|
||||||
|
* True, if the administrator can add new administrators with a subset of
|
||||||
|
* their own privileges or demote administrators that he has promoted,
|
||||||
|
* directly or indirectly (promoted by administrators that were appointed by the user)
|
||||||
|
*/
|
||||||
|
@JsonProperty(CANPROMOTEMEMBERS_FIELD)
|
||||||
|
private Boolean canPromoteMembers;
|
||||||
|
@JsonProperty(CANCHANGEINFO_FIELD)
|
||||||
|
private Boolean canChangeInfo; ///< True, if the user is allowed to change the chat title, photo and other settings
|
||||||
|
@JsonProperty(CANINVITEUSERS_FIELD)
|
||||||
|
private Boolean canInviteUsers; ///< True, if the user is allowed to invite new users to the chat
|
||||||
|
@JsonProperty(CANPOSTMESSAGES_FIELD)
|
||||||
|
private Boolean canPostMessages; ///< Optional. True, if the administrator can post in the channel; channels only
|
||||||
|
@JsonProperty(CANEDITMESSAGES_FIELD)
|
||||||
|
private Boolean canEditMessages; ///< Optional. True, if the administrator can edit messages of other users and can pin messages; channels only
|
||||||
|
@JsonProperty(CANPINMESSAGES_FIELD)
|
||||||
|
private Boolean canPinMessages; ///< Optional. True, if the user is allowed to pin messages; groups and supergroups only
|
||||||
|
|
||||||
|
}
|
@ -37,12 +37,12 @@ public class ChatMemberAdministrator implements ChatMember {
|
|||||||
private static final String CANPOSTMESSAGES_FIELD = "can_post_messages";
|
private static final String CANPOSTMESSAGES_FIELD = "can_post_messages";
|
||||||
private static final String CANEDITMESSAGES_FIELD = "can_edit_messages";
|
private static final String CANEDITMESSAGES_FIELD = "can_edit_messages";
|
||||||
private static final String CANDELETEMESSAGES_FIELD = "can_delete_messages";
|
private static final String CANDELETEMESSAGES_FIELD = "can_delete_messages";
|
||||||
private static final String CANMANAGEVOICECHATS_FIELD = "can_manage_voice_chats";
|
|
||||||
private static final String CANRESTRICTMEMBERS_FIELD = "can_restrict_members";
|
private static final String CANRESTRICTMEMBERS_FIELD = "can_restrict_members";
|
||||||
private static final String CANPROMOTEMEMBERS_FIELD = "can_promote_members";
|
private static final String CANPROMOTEMEMBERS_FIELD = "can_promote_members";
|
||||||
private static final String CANCHANGEINFO_FIELD = "can_change_info";
|
private static final String CANCHANGEINFO_FIELD = "can_change_info";
|
||||||
private static final String CANINVITEUSERS_FIELD = "can_invite_users";
|
private static final String CANINVITEUSERS_FIELD = "can_invite_users";
|
||||||
private static final String CANPINMESSAGES_FIELD = "can_pin_messages";
|
private static final String CANPINMESSAGES_FIELD = "can_pin_messages";
|
||||||
|
private static final String CANMANAGEVIDEOCHATS_FIELD = "can_manage_video_chats";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The member's status in the chat, always “administrator”
|
* The member's status in the chat, always “administrator”
|
||||||
@ -92,11 +92,6 @@ public class ChatMemberAdministrator implements ChatMember {
|
|||||||
*/
|
*/
|
||||||
@JsonProperty(CANDELETEMESSAGES_FIELD)
|
@JsonProperty(CANDELETEMESSAGES_FIELD)
|
||||||
private Boolean canDeleteMessages;
|
private Boolean canDeleteMessages;
|
||||||
/**
|
|
||||||
* True, if the administrator can manage voice chats
|
|
||||||
*/
|
|
||||||
@JsonProperty(CANMANAGEVOICECHATS_FIELD)
|
|
||||||
private Boolean canManageVoiceChats;
|
|
||||||
/**
|
/**
|
||||||
* True, if the administrator can restrict, ban or unban chat members
|
* True, if the administrator can restrict, ban or unban chat members
|
||||||
*/
|
*/
|
||||||
@ -124,4 +119,9 @@ public class ChatMemberAdministrator implements ChatMember {
|
|||||||
*/
|
*/
|
||||||
@JsonProperty(CANPINMESSAGES_FIELD)
|
@JsonProperty(CANPINMESSAGES_FIELD)
|
||||||
private Boolean canPinMessages;
|
private Boolean canPinMessages;
|
||||||
|
/**
|
||||||
|
* True, if the administrator can manage video chats
|
||||||
|
*/
|
||||||
|
@JsonProperty(CANMANAGEVIDEOCHATS_FIELD)
|
||||||
|
private Boolean canManageVideoChats;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,45 @@
|
|||||||
|
package org.telegram.telegrambots.meta.api.objects.menubutton;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
|
import lombok.*;
|
||||||
|
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
|
||||||
|
import org.telegram.telegrambots.meta.api.interfaces.Validable;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.menubutton.serialization.MenuButtonDeserializer;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.menubutton.serialization.MenuButtonSerializer;
|
||||||
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Ruben Bermudez
|
||||||
|
* @version 5.3
|
||||||
|
*
|
||||||
|
* This object describes bot's menu button in a private chat. It should be one of
|
||||||
|
*
|
||||||
|
* MenuButtonCommands
|
||||||
|
* MenuButtonWebApp
|
||||||
|
* MenuButtonDefault
|
||||||
|
*
|
||||||
|
* If a menu button other than MenuButtonDefault is set for a private chat, then it is applied in the chat.
|
||||||
|
* Otherwise the default menu button is applied.
|
||||||
|
*
|
||||||
|
* By default, the menu button opens the list of bot's commands.
|
||||||
|
*/
|
||||||
|
@JsonSerialize(using = MenuButtonSerializer.class)
|
||||||
|
@JsonDeserialize(using = MenuButtonDeserializer.class)
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@NoArgsConstructor
|
||||||
|
public abstract class MenuButton implements BotApiObject, Validable {
|
||||||
|
public static final String TYPE_FIELD = "type";
|
||||||
|
|
||||||
|
@JsonProperty(TYPE_FIELD)
|
||||||
|
public abstract String getType();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validate() throws TelegramApiValidationException {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package org.telegram.telegrambots.meta.api.objects.menubutton;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||||
|
import lombok.*;
|
||||||
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Ruben Bermudez
|
||||||
|
* @version 6.0
|
||||||
|
*
|
||||||
|
* Represents menu button, which opens the list of bot's commands.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings({"unused"})
|
||||||
|
@JsonDeserialize
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@Builder
|
||||||
|
public class MenuButtonCommands extends MenuButton {
|
||||||
|
private static final String TYPE = "commands"; ///< Type of the button, must be commands
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validate() throws TelegramApiValidationException {
|
||||||
|
super.validate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return TYPE;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package org.telegram.telegrambots.meta.api.objects.menubutton;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||||
|
import lombok.*;
|
||||||
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Ruben Bermudez
|
||||||
|
* @version 6.0
|
||||||
|
*
|
||||||
|
* Describes that no specific value for the menu button was set.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings({"unused"})
|
||||||
|
@JsonDeserialize
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@Builder
|
||||||
|
public class MenuButtonDefault extends MenuButton {
|
||||||
|
private static final String TYPE = "default"; ///< Type of the button, must be default
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validate() throws TelegramApiValidationException {
|
||||||
|
super.validate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return TYPE;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
package org.telegram.telegrambots.meta.api.objects.menubutton;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||||
|
import lombok.*;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.webapp.WebAppInfo;
|
||||||
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Ruben Bermudez
|
||||||
|
* @version 6.0
|
||||||
|
*
|
||||||
|
* Represents menu button, which launches a web app.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings({"unused"})
|
||||||
|
@JsonDeserialize
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@Builder
|
||||||
|
public class MenuButtonWebApp extends MenuButton {
|
||||||
|
private static final String TYPE = "web_app"; ///< Type of the button, must be web_app
|
||||||
|
|
||||||
|
public static final String TEXT_FIELD = "text";
|
||||||
|
public static final String WEBAPP_FIELD = "web_app";
|
||||||
|
|
||||||
|
@JsonProperty(TEXT_FIELD)
|
||||||
|
@NonNull
|
||||||
|
private String text; ///< Text of the button
|
||||||
|
/**
|
||||||
|
* Description of the web app that will be launched when the user presses the button.
|
||||||
|
* The web app will be able to send an arbitrary message on behalf of the user using the method answerWebAppQuery.
|
||||||
|
*/
|
||||||
|
@JsonProperty(WEBAPP_FIELD)
|
||||||
|
@NonNull
|
||||||
|
private WebAppInfo webAppInfo;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validate() throws TelegramApiValidationException {
|
||||||
|
super.validate();
|
||||||
|
|
||||||
|
if (text.isEmpty()) {
|
||||||
|
throw new TelegramApiValidationException("Text can't be empty", this);
|
||||||
|
}
|
||||||
|
webAppInfo.validate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return TYPE;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
package org.telegram.telegrambots.meta.api.objects.menubutton.serialization;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.menubutton.MenuButton;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.menubutton.MenuButtonCommands;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.menubutton.MenuButtonDefault;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.menubutton.MenuButtonWebApp;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Ruben Bermudez
|
||||||
|
* @version 6.0
|
||||||
|
*
|
||||||
|
* JSON serializer for MenuButton type
|
||||||
|
*/
|
||||||
|
public class MenuButtonDeserializer extends StdDeserializer<MenuButton> {
|
||||||
|
|
||||||
|
private final ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
public MenuButtonDeserializer() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MenuButtonDeserializer(Class<?> vc) {
|
||||||
|
super(vc);
|
||||||
|
this.objectMapper = new ObjectMapper();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MenuButton deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
|
||||||
|
throws IOException, JsonProcessingException {
|
||||||
|
|
||||||
|
JsonNode node = jsonParser.getCodec().readTree(jsonParser);
|
||||||
|
switch (node.get("type").asText()) {
|
||||||
|
case "default":
|
||||||
|
return objectMapper.readValue(node.toString(),
|
||||||
|
new com.fasterxml.jackson.core.type.TypeReference<MenuButtonDefault>() {
|
||||||
|
});
|
||||||
|
case "web_app":
|
||||||
|
return objectMapper.readValue(node.toString(),
|
||||||
|
new com.fasterxml.jackson.core.type.TypeReference<MenuButtonWebApp>() {
|
||||||
|
});
|
||||||
|
case "commands":
|
||||||
|
return objectMapper.readValue(node.toString(),
|
||||||
|
new com.fasterxml.jackson.core.type.TypeReference<MenuButtonCommands>() {
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package org.telegram.telegrambots.meta.api.objects.menubutton.serialization;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
|
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||||
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
|
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.menubutton.MenuButton;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.menubutton.MenuButtonWebApp;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Ruben Bermudez
|
||||||
|
* @version 6.0
|
||||||
|
*
|
||||||
|
* JSON serializer for MenuButton type
|
||||||
|
*/
|
||||||
|
public class MenuButtonSerializer extends JsonSerializer<MenuButton> {
|
||||||
|
@Override
|
||||||
|
public void serialize(MenuButton value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
||||||
|
gen.writeStartObject();
|
||||||
|
gen.writeStringField(MenuButton.TYPE_FIELD, value.getType());
|
||||||
|
|
||||||
|
if (value instanceof MenuButtonWebApp) {
|
||||||
|
MenuButtonWebApp menuButtonWebApp = (MenuButtonWebApp) value;
|
||||||
|
|
||||||
|
gen.writeStringField(MenuButtonWebApp.TEXT_FIELD, menuButtonWebApp.getText());
|
||||||
|
gen.writeObjectField(MenuButtonWebApp.WEBAPP_FIELD, menuButtonWebApp.getWebAppInfo());
|
||||||
|
}
|
||||||
|
|
||||||
|
gen.writeEndObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serializeWithType(MenuButton value, JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException {
|
||||||
|
serialize(value, gen, serializers);
|
||||||
|
}
|
||||||
|
}
|
@ -14,6 +14,7 @@ import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
|
|||||||
import org.telegram.telegrambots.meta.api.interfaces.Validable;
|
import org.telegram.telegrambots.meta.api.interfaces.Validable;
|
||||||
import org.telegram.telegrambots.meta.api.objects.LoginUrl;
|
import org.telegram.telegrambots.meta.api.objects.LoginUrl;
|
||||||
import org.telegram.telegrambots.meta.api.objects.games.CallbackGame;
|
import org.telegram.telegrambots.meta.api.objects.games.CallbackGame;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.webapp.WebAppInfo;
|
||||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -42,6 +43,7 @@ public class InlineKeyboardButton implements Validable, BotApiObject {
|
|||||||
private static final String SWITCH_INLINE_QUERY_CURRENT_CHAT_FIELD = "switch_inline_query_current_chat";
|
private static final String SWITCH_INLINE_QUERY_CURRENT_CHAT_FIELD = "switch_inline_query_current_chat";
|
||||||
private static final String PAY_FIELD = "pay";
|
private static final String PAY_FIELD = "pay";
|
||||||
private static final String LOGIN_URL_FIELD = "login_url";
|
private static final String LOGIN_URL_FIELD = "login_url";
|
||||||
|
private static final String WEBAPP_FIELD = "web_app";
|
||||||
|
|
||||||
@JsonProperty(TEXT_FIELD)
|
@JsonProperty(TEXT_FIELD)
|
||||||
@NonNull
|
@NonNull
|
||||||
@ -98,13 +100,25 @@ public class InlineKeyboardButton implements Validable, BotApiObject {
|
|||||||
@JsonProperty(LOGIN_URL_FIELD)
|
@JsonProperty(LOGIN_URL_FIELD)
|
||||||
private LoginUrl loginUrl;
|
private LoginUrl loginUrl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional.
|
||||||
|
* Description of the web app that will be launched when the user presses the button.
|
||||||
|
* The web app will be able to send an arbitrary message on behalf of the user using the method answerWebAppQuery.
|
||||||
|
* Available only in private chats between users and the bot.
|
||||||
|
*/
|
||||||
|
@JsonProperty(WEBAPP_FIELD)
|
||||||
|
private WebAppInfo webApp;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void validate() throws TelegramApiValidationException {
|
public void validate() throws TelegramApiValidationException {
|
||||||
if (text == null || text.isEmpty()) {
|
if (text.isEmpty()) {
|
||||||
throw new TelegramApiValidationException("Text parameter can't be empty", this);
|
throw new TelegramApiValidationException("Text parameter can't be empty", this);
|
||||||
}
|
}
|
||||||
if (loginUrl != null) {
|
if (loginUrl != null) {
|
||||||
loginUrl.validate();
|
loginUrl.validate();
|
||||||
}
|
}
|
||||||
|
if (webApp != null) {
|
||||||
|
webApp.validate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import lombok.Setter;
|
|||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
|
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
|
||||||
import org.telegram.telegrambots.meta.api.interfaces.Validable;
|
import org.telegram.telegrambots.meta.api.interfaces.Validable;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.webapp.WebAppInfo;
|
||||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,6 +41,7 @@ public class KeyboardButton implements Validable, BotApiObject {
|
|||||||
private static final String REQUEST_CONTACT_FIELD = "request_contact";
|
private static final String REQUEST_CONTACT_FIELD = "request_contact";
|
||||||
private static final String REQUEST_LOCATION_FIELD = "request_location";
|
private static final String REQUEST_LOCATION_FIELD = "request_location";
|
||||||
private static final String REQUEST_POLL_FIELD = "request_poll";
|
private static final String REQUEST_POLL_FIELD = "request_poll";
|
||||||
|
private static final String WEBAPP_FIELD = "web_app";
|
||||||
/**
|
/**
|
||||||
* Text of the button.
|
* Text of the button.
|
||||||
* If none of the optional fields are used, it will be sent to the bot as a message when the button is pressed
|
* If none of the optional fields are used, it will be sent to the bot as a message when the button is pressed
|
||||||
@ -69,9 +71,17 @@ public class KeyboardButton implements Validable, BotApiObject {
|
|||||||
@JsonProperty(REQUEST_POLL_FIELD)
|
@JsonProperty(REQUEST_POLL_FIELD)
|
||||||
private KeyboardButtonPollType requestPoll;
|
private KeyboardButtonPollType requestPoll;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional. Description of the web app that will be launched when the user presses the button.
|
||||||
|
* The web app will be able to send a “web_app_data” service message.
|
||||||
|
* Available in private chats only.
|
||||||
|
*/
|
||||||
|
@JsonProperty(WEBAPP_FIELD)
|
||||||
|
private WebAppInfo webApp;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void validate() throws TelegramApiValidationException {
|
public void validate() throws TelegramApiValidationException {
|
||||||
if (text == null || text.isEmpty()) {
|
if (text.isEmpty()) {
|
||||||
throw new TelegramApiValidationException("Text parameter can't be empty", this);
|
throw new TelegramApiValidationException("Text parameter can't be empty", this);
|
||||||
}
|
}
|
||||||
if (requestContact != null && requestLocation != null && requestContact && requestLocation) {
|
if (requestContact != null && requestLocation != null && requestContact && requestLocation) {
|
||||||
@ -83,5 +93,8 @@ public class KeyboardButton implements Validable, BotApiObject {
|
|||||||
if (requestLocation != null && requestPoll != null && requestLocation) {
|
if (requestLocation != null && requestPoll != null && requestLocation) {
|
||||||
throw new TelegramApiValidationException("Cant request location and poll at the same time", this);
|
throw new TelegramApiValidationException("Cant request location and poll at the same time", this);
|
||||||
}
|
}
|
||||||
|
if (webApp != null) {
|
||||||
|
webApp.validate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,14 @@
|
|||||||
package org.telegram.telegrambots.meta.api.objects.voicechat;
|
package org.telegram.telegrambots.meta.api.objects.videochat;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.*;
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.Setter;
|
|
||||||
import lombok.ToString;
|
|
||||||
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
|
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Ruben Bermudez
|
* @author Ruben Bermudez
|
||||||
* @version 5.1
|
* @version 6.0
|
||||||
*
|
*
|
||||||
* This object represents a service message about a voice chat ended in the chat.
|
* This object represents a service message about a video chat ended in the chat.
|
||||||
*/
|
*/
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
@Getter
|
@Getter
|
||||||
@ -21,7 +16,7 @@ import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
|
|||||||
@ToString
|
@ToString
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class VoiceChatEnded implements BotApiObject {
|
public class VideoChatEnded implements BotApiObject {
|
||||||
private static final String DURATION_FIELD = "duration";
|
private static final String DURATION_FIELD = "duration";
|
||||||
|
|
||||||
@JsonProperty(DURATION_FIELD)
|
@JsonProperty(DURATION_FIELD)
|
@ -1,12 +1,7 @@
|
|||||||
package org.telegram.telegrambots.meta.api.objects.voicechat;
|
package org.telegram.telegrambots.meta.api.objects.videochat;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.*;
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.Setter;
|
|
||||||
import lombok.ToString;
|
|
||||||
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
|
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
|
||||||
import org.telegram.telegrambots.meta.api.objects.User;
|
import org.telegram.telegrambots.meta.api.objects.User;
|
||||||
|
|
||||||
@ -14,9 +9,9 @@ import java.util.List;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Ruben Bermudez
|
* @author Ruben Bermudez
|
||||||
* @version 5.1
|
* @version 6.0
|
||||||
*
|
*
|
||||||
* This object represents a service message about new members invited to a voice chat.
|
* This object represents a service message about new members invited to a video chat.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
@ -25,7 +20,7 @@ import java.util.List;
|
|||||||
@ToString
|
@ToString
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class VoiceChatParticipantsInvited implements BotApiObject {
|
public class VideoChatParticipantsInvited implements BotApiObject {
|
||||||
private static final String USERS_FIELD = "users";
|
private static final String USERS_FIELD = "users";
|
||||||
|
|
||||||
@JsonProperty(USERS_FIELD)
|
@JsonProperty(USERS_FIELD)
|
@ -1,20 +1,14 @@
|
|||||||
package org.telegram.telegrambots.meta.api.objects.voicechat;
|
package org.telegram.telegrambots.meta.api.objects.videochat;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.*;
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.NonNull;
|
|
||||||
import lombok.Setter;
|
|
||||||
import lombok.ToString;
|
|
||||||
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
|
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Ruben Bermudez
|
* @author Ruben Bermudez
|
||||||
* @version 5.2
|
* @version 6.0
|
||||||
*
|
*
|
||||||
* This object represents a service message about a voice chat scheduled in the chat.
|
* This object represents a service message about a video chat scheduled in the chat.
|
||||||
*/
|
*/
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
@Getter
|
@Getter
|
||||||
@ -22,7 +16,7 @@ import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
|
|||||||
@ToString
|
@ToString
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class VoiceChatScheduled implements BotApiObject {
|
public class VideoChatScheduled implements BotApiObject {
|
||||||
private static final String STARTDATE_FIELD = "start_date";
|
private static final String STARTDATE_FIELD = "start_date";
|
||||||
|
|
||||||
@JsonProperty(STARTDATE_FIELD)
|
@JsonProperty(STARTDATE_FIELD)
|
@ -0,0 +1,19 @@
|
|||||||
|
package org.telegram.telegrambots.meta.api.objects.videochat;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Ruben Bermudez
|
||||||
|
* @version 6.0
|
||||||
|
*
|
||||||
|
* This object represents a service message about a video chat started in the chat.
|
||||||
|
* Currently holds no information.
|
||||||
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class VideoChatStarted implements BotApiObject {
|
||||||
|
}
|
@ -1,24 +0,0 @@
|
|||||||
package org.telegram.telegrambots.meta.api.objects.voicechat;
|
|
||||||
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.Setter;
|
|
||||||
import lombok.ToString;
|
|
||||||
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Ruben Bermudez
|
|
||||||
* @version 5.1
|
|
||||||
*
|
|
||||||
* This object represents a service message about a voice chat started in the chat.
|
|
||||||
*
|
|
||||||
* Currently holds no information.
|
|
||||||
*/
|
|
||||||
@EqualsAndHashCode(callSuper = false)
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@ToString
|
|
||||||
@NoArgsConstructor
|
|
||||||
public class VoiceChatStarted implements BotApiObject {
|
|
||||||
}
|
|
@ -0,0 +1,28 @@
|
|||||||
|
package org.telegram.telegrambots.meta.api.objects.webapp;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||||
|
import lombok.*;
|
||||||
|
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
|
||||||
|
import org.telegram.telegrambots.meta.api.interfaces.Validable;
|
||||||
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Ruben Bermudez
|
||||||
|
* @version 6.0
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class SentWebAppMessage implements BotApiObject {
|
||||||
|
private static final String INLINEMESSAGEID_FIELD = "inline_message_id";
|
||||||
|
|
||||||
|
@JsonProperty(INLINEMESSAGEID_FIELD)
|
||||||
|
@NonNull
|
||||||
|
private String inlineMessageId;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package org.telegram.telegrambots.meta.api.objects.webapp;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.*;
|
||||||
|
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
|
||||||
|
import org.telegram.telegrambots.meta.api.interfaces.Validable;
|
||||||
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Ruben Bermudez
|
||||||
|
* @version 6.0
|
||||||
|
*
|
||||||
|
* Contains data sent from a web app to the bot.
|
||||||
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class WebAppData implements BotApiObject {
|
||||||
|
private static final String DATA_FIELD = "data";
|
||||||
|
private static final String BUTTONTEXT_FIELD = "button_text";
|
||||||
|
|
||||||
|
@JsonProperty(DATA_FIELD)
|
||||||
|
@NonNull
|
||||||
|
private String data; ///< The data
|
||||||
|
@JsonProperty(BUTTONTEXT_FIELD)
|
||||||
|
@NonNull
|
||||||
|
private String buttonText; ///< Text of the web_app keyboard button, from which the web app was opened
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package org.telegram.telegrambots.meta.api.objects.webapp;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||||
|
import lombok.*;
|
||||||
|
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
|
||||||
|
import org.telegram.telegrambots.meta.api.interfaces.Validable;
|
||||||
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Ruben Bermudez
|
||||||
|
* @version 6.0
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class WebAppInfo implements Validable, BotApiObject {
|
||||||
|
private static final String URL_FIELD = "url";
|
||||||
|
|
||||||
|
@JsonProperty(URL_FIELD)
|
||||||
|
@NonNull
|
||||||
|
private String url; ///< An HTTPS URL of a web app to be opened with additional data as specified at ...
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validate() throws TelegramApiValidationException {
|
||||||
|
if (url.isEmpty()) {
|
||||||
|
throw new TelegramApiValidationException("Url can't be empty", this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,76 @@
|
|||||||
|
package org.telegram.telegrambots.meta.api.methods.adminrights;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.telegram.telegrambots.meta.api.methods.groupadministration.PromoteChatMember;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.adminrights.ChatAdministratorRights;
|
||||||
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Ruben Bermudez
|
||||||
|
* @version 6.0
|
||||||
|
*/
|
||||||
|
public class GetMyDefaultAdministratorRightsTest {
|
||||||
|
@Test
|
||||||
|
public void testGetMyDefaultAdministratorRightsWithAllSetForChannel() {
|
||||||
|
GetMyDefaultAdministratorRights getMyDefaultAdministratorRights = GetMyDefaultAdministratorRights
|
||||||
|
.builder()
|
||||||
|
.forChannels(true)
|
||||||
|
.build();
|
||||||
|
assertEquals("getMyDefaultAdministratorRights", getMyDefaultAdministratorRights.getMethod());
|
||||||
|
assertDoesNotThrow(getMyDefaultAdministratorRights::validate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetMyDefaultAdministratorRightsWithAllSetForGroups() {
|
||||||
|
GetMyDefaultAdministratorRights getMyDefaultAdministratorRights = GetMyDefaultAdministratorRights
|
||||||
|
.builder()
|
||||||
|
.build();
|
||||||
|
assertEquals("getMyDefaultAdministratorRights", getMyDefaultAdministratorRights.getMethod());
|
||||||
|
assertDoesNotThrow(getMyDefaultAdministratorRights::validate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetMyDefaultAdministratorRightsDeserializeValidResponse() {
|
||||||
|
String responseText = "{\n" +
|
||||||
|
" \"ok\": true,\n" +
|
||||||
|
" \"result\": {\n" +
|
||||||
|
" \"is_anonymous\": true,\n" +
|
||||||
|
" \"can_manage_chat\": true,\n" +
|
||||||
|
" \"can_delete_messages\": true,\n" +
|
||||||
|
" \"can_manage_video_chats\": true,\n" +
|
||||||
|
" \"can_restrict_members\": true,\n" +
|
||||||
|
" \"can_promote_members\": true,\n" +
|
||||||
|
" \"can_change_info\": true,\n" +
|
||||||
|
" \"can_invite_users\": true,\n" +
|
||||||
|
" \"can_post_messages\": true,\n" +
|
||||||
|
" \"can_edit_messages\": true,\n" +
|
||||||
|
" \"can_pin_messages\": true\n" +
|
||||||
|
" }\n" +
|
||||||
|
"}";
|
||||||
|
|
||||||
|
GetMyDefaultAdministratorRights getMyDefaultAdministratorRights = GetMyDefaultAdministratorRights
|
||||||
|
.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try {
|
||||||
|
ChatAdministratorRights result = getMyDefaultAdministratorRights.deserializeResponse(responseText);
|
||||||
|
assertNotNull(result);
|
||||||
|
assertEquals(true, result.getIsAnonymous());
|
||||||
|
assertEquals(true, result.getCanManageChat());
|
||||||
|
assertEquals(true, result.getCanPostMessages());
|
||||||
|
assertEquals(true, result.getCanEditMessages());
|
||||||
|
assertEquals(true, result.getCanDeleteMessages());
|
||||||
|
assertEquals(true, result.getCanManageVideoChats());
|
||||||
|
assertEquals(true, result.getCanRestrictMembers());
|
||||||
|
assertEquals(true, result.getCanPromoteMembers());
|
||||||
|
assertEquals(true, result.getCanChangeInfo());
|
||||||
|
assertEquals(true, result.getCanInviteUsers());
|
||||||
|
assertEquals(true, result.getCanPinMessages());
|
||||||
|
} catch (TelegramApiRequestException e) {
|
||||||
|
fail(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,96 @@
|
|||||||
|
package org.telegram.telegrambots.meta.api.methods.adminrights;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.adminrights.ChatAdministratorRights;
|
||||||
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Ruben Bermudez
|
||||||
|
* @version 6.0
|
||||||
|
*/
|
||||||
|
public class SetMyDefaultAdministratorRightsTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetMyDefaultAdministratorRightsWithNone() {
|
||||||
|
SetMyDefaultAdministratorRights setMyDefaultAdministratorRights = SetMyDefaultAdministratorRights
|
||||||
|
.builder()
|
||||||
|
.build();
|
||||||
|
assertEquals("setMyDefaultAdministratorRights", setMyDefaultAdministratorRights.getMethod());
|
||||||
|
assertDoesNotThrow(setMyDefaultAdministratorRights::validate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetMyDefaultAdministratorRightsForChannels() {
|
||||||
|
SetMyDefaultAdministratorRights setMyDefaultAdministratorRights = SetMyDefaultAdministratorRights
|
||||||
|
.builder()
|
||||||
|
.forChannels(true)
|
||||||
|
.build();
|
||||||
|
assertEquals("setMyDefaultAdministratorRights", setMyDefaultAdministratorRights.getMethod());
|
||||||
|
assertDoesNotThrow(setMyDefaultAdministratorRights::validate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetMyDefaultAdministratorRightsWithAllSet() {
|
||||||
|
SetMyDefaultAdministratorRights setMyDefaultAdministratorRights = SetMyDefaultAdministratorRights
|
||||||
|
.builder()
|
||||||
|
.forChannels(true)
|
||||||
|
.rights(ChatAdministratorRights
|
||||||
|
.builder()
|
||||||
|
.isAnonymous(true)
|
||||||
|
.build())
|
||||||
|
.build();
|
||||||
|
assertEquals("setMyDefaultAdministratorRights", setMyDefaultAdministratorRights.getMethod());
|
||||||
|
assertDoesNotThrow(setMyDefaultAdministratorRights::validate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetMyDefaultAdministratorRightsDeserializeValidResponse() {
|
||||||
|
String responseText = "{\"ok\":true,\"result\": true}";
|
||||||
|
|
||||||
|
SetMyDefaultAdministratorRights setMyDefaultAdministratorRights = SetMyDefaultAdministratorRights
|
||||||
|
.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try {
|
||||||
|
boolean result = setMyDefaultAdministratorRights.deserializeResponse(responseText);
|
||||||
|
assertTrue(result);
|
||||||
|
} catch (TelegramApiRequestException e) {
|
||||||
|
fail(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetMyDefaultAdministratorRightsDeserializeErrorResponse() {
|
||||||
|
String responseText = "{\"ok\":false,\"error_code\": 404,\"description\": \"Error message\"}";
|
||||||
|
|
||||||
|
SetMyDefaultAdministratorRights setMyDefaultAdministratorRights = SetMyDefaultAdministratorRights
|
||||||
|
.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try {
|
||||||
|
setMyDefaultAdministratorRights.deserializeResponse(responseText);
|
||||||
|
fail();
|
||||||
|
} catch (TelegramApiRequestException e) {
|
||||||
|
assertEquals(404, e.getErrorCode());
|
||||||
|
assertEquals("Error message", e.getApiResponse());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetMyDefaultAdministratorRightsDeserializeWithWrongObject() {
|
||||||
|
String responseText = "{\"ok\":false\"error_code\": 404,\"description\": \"Error message\"}";
|
||||||
|
|
||||||
|
SetMyDefaultAdministratorRights setMyDefaultAdministratorRights = SetMyDefaultAdministratorRights
|
||||||
|
.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try {
|
||||||
|
setMyDefaultAdministratorRights.deserializeResponse(responseText);
|
||||||
|
fail();
|
||||||
|
} catch (TelegramApiRequestException e) {
|
||||||
|
assertEquals("Unable to deserialize response", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,103 @@
|
|||||||
|
package org.telegram.telegrambots.meta.api.methods.groupadministration;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||||
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Ruben Bermudez
|
||||||
|
* @version 6.0
|
||||||
|
*/
|
||||||
|
public class PromoteChatMemberTest {
|
||||||
|
@Test
|
||||||
|
public void testPromoteChatMemberWithAllSet() {
|
||||||
|
PromoteChatMember promoteChatMember = PromoteChatMember
|
||||||
|
.builder()
|
||||||
|
.chatId("12345")
|
||||||
|
.userId(12345L)
|
||||||
|
.build();
|
||||||
|
assertEquals("promoteChatMember", promoteChatMember.getMethod());
|
||||||
|
assertDoesNotThrow(promoteChatMember::validate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPromoteChatMemberWithEmptyChatId() {
|
||||||
|
PromoteChatMember promoteChatMember = PromoteChatMember
|
||||||
|
.builder()
|
||||||
|
.chatId("")
|
||||||
|
.userId(12345L)
|
||||||
|
.build();
|
||||||
|
assertEquals("promoteChatMember", promoteChatMember.getMethod());
|
||||||
|
Throwable thrown = assertThrows(TelegramApiValidationException.class, promoteChatMember::validate);
|
||||||
|
assertEquals("ChatId can't be empty", thrown.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPromoteChatMemberWithEmptyUserId() {
|
||||||
|
PromoteChatMember promoteChatMember = PromoteChatMember
|
||||||
|
.builder()
|
||||||
|
.chatId("12345")
|
||||||
|
.userId(0L)
|
||||||
|
.build();
|
||||||
|
assertEquals("promoteChatMember", promoteChatMember.getMethod());
|
||||||
|
Throwable thrown = assertThrows(TelegramApiValidationException.class, promoteChatMember::validate);
|
||||||
|
assertEquals("UserId can't be empty", thrown.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPromoteChatMemberDeserializeValidResponse() {
|
||||||
|
String responseText = "{\"ok\":true,\"result\": true}";
|
||||||
|
|
||||||
|
PromoteChatMember promoteChatMember = PromoteChatMember
|
||||||
|
.builder()
|
||||||
|
.chatId("12345")
|
||||||
|
.userId(123456L)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try {
|
||||||
|
boolean result = promoteChatMember.deserializeResponse(responseText);
|
||||||
|
assertTrue(result);
|
||||||
|
} catch (TelegramApiRequestException e) {
|
||||||
|
fail(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPromoteChatMemberDeserializeErrorResponse() {
|
||||||
|
String responseText = "{\"ok\":false,\"error_code\": 404,\"description\": \"Error message\"}";
|
||||||
|
|
||||||
|
PromoteChatMember promoteChatMember = PromoteChatMember
|
||||||
|
.builder()
|
||||||
|
.chatId("12345")
|
||||||
|
.userId(123456L)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try {
|
||||||
|
promoteChatMember.deserializeResponse(responseText);
|
||||||
|
fail();
|
||||||
|
} catch (TelegramApiRequestException e) {
|
||||||
|
assertEquals(404, e.getErrorCode());
|
||||||
|
assertEquals("Error message", e.getApiResponse());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPromoteChatMemberDeserializeWithWrongObject() {
|
||||||
|
String responseText = "{\"ok\":false\"error_code\": 404,\"description\": \"Error message\"}";
|
||||||
|
|
||||||
|
PromoteChatMember promoteChatMember = PromoteChatMember
|
||||||
|
.builder()
|
||||||
|
.chatId("12345")
|
||||||
|
.userId(123456L)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try {
|
||||||
|
promoteChatMember.deserializeResponse(responseText);
|
||||||
|
fail();
|
||||||
|
} catch (TelegramApiRequestException e) {
|
||||||
|
assertEquals("Unable to deserialize response", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,86 @@
|
|||||||
|
package org.telegram.telegrambots.meta.api.methods.menubutton;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.menubutton.MenuButton;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.menubutton.MenuButtonDefault;
|
||||||
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Ruben Bermudez
|
||||||
|
* @version 6.0
|
||||||
|
*/
|
||||||
|
public class GetChatMenuButtonTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetChatMenuButtonAsDefault() {
|
||||||
|
GetChatMenuButton getChatMenuButton = GetChatMenuButton
|
||||||
|
.builder()
|
||||||
|
.build();
|
||||||
|
assertEquals("getChatMenuButton", getChatMenuButton.getMethod());
|
||||||
|
assertDoesNotThrow(getChatMenuButton::validate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetChatMenuButtonForChat() {
|
||||||
|
GetChatMenuButton getChatMenuButton = GetChatMenuButton
|
||||||
|
.builder()
|
||||||
|
.chatId("123456")
|
||||||
|
.build();
|
||||||
|
assertEquals("getChatMenuButton", getChatMenuButton.getMethod());
|
||||||
|
assertDoesNotThrow(getChatMenuButton::validate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetChatMenuButtonDeserializeValidResponse() {
|
||||||
|
String responseText = "{\"ok\":true,\"result\":{\"type\": \"default\"}}";
|
||||||
|
|
||||||
|
GetChatMenuButton getChatMenuButton = GetChatMenuButton
|
||||||
|
.builder()
|
||||||
|
.chatId("12345")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try {
|
||||||
|
MenuButton result = getChatMenuButton.deserializeResponse(responseText);
|
||||||
|
assertNotNull(result);
|
||||||
|
assertTrue(result instanceof MenuButtonDefault);
|
||||||
|
} catch (TelegramApiRequestException e) {
|
||||||
|
fail(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetChatMenuButtonErrorResponse() {
|
||||||
|
String responseText = "{\"ok\":false,\"error_code\": 404,\"description\": \"Error message\"}";
|
||||||
|
|
||||||
|
GetChatMenuButton getChatMenuButton = GetChatMenuButton
|
||||||
|
.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try {
|
||||||
|
getChatMenuButton.deserializeResponse(responseText);
|
||||||
|
fail();
|
||||||
|
} catch (TelegramApiRequestException e) {
|
||||||
|
assertEquals(404, e.getErrorCode());
|
||||||
|
assertEquals("Error message", e.getApiResponse());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetChatMenuButtonDeserializeWithWrongObject() {
|
||||||
|
String responseText = "{\"ok\":false\"error_code\": 404,\"description\": \"Error message\"}";
|
||||||
|
|
||||||
|
GetChatMenuButton getChatMenuButton = GetChatMenuButton
|
||||||
|
.builder()
|
||||||
|
.chatId("12345")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try {
|
||||||
|
getChatMenuButton.deserializeResponse(responseText);
|
||||||
|
fail();
|
||||||
|
} catch (TelegramApiRequestException e) {
|
||||||
|
assertEquals("Unable to deserialize response", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,149 @@
|
|||||||
|
package org.telegram.telegrambots.meta.api.methods.menubutton;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.menubutton.MenuButton;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.menubutton.MenuButtonCommands;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.menubutton.MenuButtonDefault;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.menubutton.MenuButtonWebApp;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.webapp.WebAppInfo;
|
||||||
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||||
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Ruben Bermudez
|
||||||
|
* @version 6.0
|
||||||
|
*/
|
||||||
|
public class SetChatMenuButtonTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetChatMenuButtonAsDefault() {
|
||||||
|
SetChatMenuButton setChatMenuButton = SetChatMenuButton
|
||||||
|
.builder()
|
||||||
|
.menuButton(MenuButtonDefault.builder().build())
|
||||||
|
.build();
|
||||||
|
assertEquals("setChatMenuButton", setChatMenuButton.getMethod());
|
||||||
|
assertDoesNotThrow(setChatMenuButton::validate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetChatMenuButtonAsCommands() {
|
||||||
|
SetChatMenuButton setChatMenuButton = SetChatMenuButton
|
||||||
|
.builder()
|
||||||
|
.chatId("123456")
|
||||||
|
.menuButton(MenuButtonCommands.builder().build())
|
||||||
|
.build();
|
||||||
|
assertEquals("setChatMenuButton", setChatMenuButton.getMethod());
|
||||||
|
assertDoesNotThrow(setChatMenuButton::validate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetChatMenuButtonAsWebApp() {
|
||||||
|
SetChatMenuButton setChatMenuButton = SetChatMenuButton
|
||||||
|
.builder()
|
||||||
|
.chatId("123456")
|
||||||
|
.menuButton(MenuButtonWebApp
|
||||||
|
.builder()
|
||||||
|
.text("Web app text")
|
||||||
|
.webAppInfo(WebAppInfo.builder().url("My url").build())
|
||||||
|
.build())
|
||||||
|
.build();
|
||||||
|
assertEquals("setChatMenuButton", setChatMenuButton.getMethod());
|
||||||
|
assertDoesNotThrow(setChatMenuButton::validate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetChatMenuButtonAsWebAppWithEmptyText() {
|
||||||
|
SetChatMenuButton setChatMenuButton = SetChatMenuButton
|
||||||
|
.builder()
|
||||||
|
.chatId("123456")
|
||||||
|
.menuButton(MenuButtonWebApp
|
||||||
|
.builder()
|
||||||
|
.text("")
|
||||||
|
.webAppInfo(WebAppInfo.builder().url("My url").build())
|
||||||
|
.build())
|
||||||
|
.build();
|
||||||
|
assertEquals("setChatMenuButton", setChatMenuButton.getMethod());
|
||||||
|
Throwable thrown = assertThrows(TelegramApiValidationException.class, setChatMenuButton::validate);
|
||||||
|
assertEquals("Text can't be empty", thrown.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetChatMenuButtonAsWebAppWithEmptyWebUrl() {
|
||||||
|
SetChatMenuButton setChatMenuButton = SetChatMenuButton
|
||||||
|
.builder()
|
||||||
|
.chatId("123456")
|
||||||
|
.menuButton(MenuButtonWebApp
|
||||||
|
.builder()
|
||||||
|
.text("Text")
|
||||||
|
.webAppInfo(WebAppInfo.builder().url("").build())
|
||||||
|
.build())
|
||||||
|
.build();
|
||||||
|
assertEquals("setChatMenuButton", setChatMenuButton.getMethod());
|
||||||
|
Throwable thrown = assertThrows(TelegramApiValidationException.class, setChatMenuButton::validate);
|
||||||
|
assertEquals("Url can't be empty", thrown.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetChatMenuButtonForChat() {
|
||||||
|
SetChatMenuButton setChatMenuButton = SetChatMenuButton
|
||||||
|
.builder()
|
||||||
|
.chatId("123456")
|
||||||
|
.menuButton(MenuButtonDefault.builder().build())
|
||||||
|
.build();
|
||||||
|
assertEquals("setChatMenuButton", setChatMenuButton.getMethod());
|
||||||
|
assertDoesNotThrow(setChatMenuButton::validate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetChatMenuButtonDeserializeValidResponse() {
|
||||||
|
String responseText = "{\"ok\":true,\"result\": true}";
|
||||||
|
|
||||||
|
SetChatMenuButton setChatMenuButton = SetChatMenuButton
|
||||||
|
.builder()
|
||||||
|
.chatId("12345")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try {
|
||||||
|
boolean result = setChatMenuButton.deserializeResponse(responseText);
|
||||||
|
assertTrue(result);
|
||||||
|
} catch (TelegramApiRequestException e) {
|
||||||
|
fail(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetChatMenuButtonErrorResponse() {
|
||||||
|
String responseText = "{\"ok\":false,\"error_code\": 404,\"description\": \"Error message\"}";
|
||||||
|
|
||||||
|
SetChatMenuButton setChatMenuButton = SetChatMenuButton
|
||||||
|
.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try {
|
||||||
|
setChatMenuButton.deserializeResponse(responseText);
|
||||||
|
fail();
|
||||||
|
} catch (TelegramApiRequestException e) {
|
||||||
|
assertEquals(404, e.getErrorCode());
|
||||||
|
assertEquals("Error message", e.getApiResponse());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetChatMenuButtonDeserializeWithWrongObject() {
|
||||||
|
String responseText = "{\"ok\":false\"error_code\": 404,\"description\": \"Error message\"}";
|
||||||
|
|
||||||
|
SetChatMenuButton setChatMenuButton = SetChatMenuButton
|
||||||
|
.builder()
|
||||||
|
.chatId("12345")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try {
|
||||||
|
setChatMenuButton.deserializeResponse(responseText);
|
||||||
|
fail();
|
||||||
|
} catch (TelegramApiRequestException e) {
|
||||||
|
assertEquals("Unable to deserialize response", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,159 @@
|
|||||||
|
package org.telegram.telegrambots.meta.api.methods.webapp;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.telegram.telegrambots.meta.api.methods.groupadministration.PromoteChatMember;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputTextMessageContent;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResultArticle;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.webapp.SentWebAppMessage;
|
||||||
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||||
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Ruben Bermudez
|
||||||
|
* @version 6.0
|
||||||
|
*/
|
||||||
|
public class AnswerWebAppQueryTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAnswerWebAppQueryWithAllSet() {
|
||||||
|
AnswerWebAppQuery answerWebAppQuery = AnswerWebAppQuery
|
||||||
|
.builder()
|
||||||
|
.webAppQueryId("123456789")
|
||||||
|
.queryResult(InlineQueryResultArticle
|
||||||
|
.builder()
|
||||||
|
.id("MyId")
|
||||||
|
.title("Text")
|
||||||
|
.inputMessageContent(InputTextMessageContent
|
||||||
|
.builder()
|
||||||
|
.messageText("My own text")
|
||||||
|
.build())
|
||||||
|
.build())
|
||||||
|
.build();
|
||||||
|
assertEquals("answerWebAppQuery", answerWebAppQuery.getMethod());
|
||||||
|
assertDoesNotThrow(answerWebAppQuery::validate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAnswerWebAppQueryWithEmptyId() {
|
||||||
|
AnswerWebAppQuery answerWebAppQuery = AnswerWebAppQuery
|
||||||
|
.builder()
|
||||||
|
.webAppQueryId("")
|
||||||
|
.queryResult(InlineQueryResultArticle
|
||||||
|
.builder()
|
||||||
|
.id("MyId")
|
||||||
|
.title("Text")
|
||||||
|
.inputMessageContent(InputTextMessageContent
|
||||||
|
.builder()
|
||||||
|
.messageText("My own text")
|
||||||
|
.build())
|
||||||
|
.build())
|
||||||
|
.build();
|
||||||
|
assertEquals("answerWebAppQuery", answerWebAppQuery.getMethod());
|
||||||
|
Throwable thrown = assertThrows(TelegramApiValidationException.class, answerWebAppQuery::validate);
|
||||||
|
assertEquals("WebAppQueryId can't be empty", thrown.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAnswerWebAppQueryWithInvalidResult() {
|
||||||
|
AnswerWebAppQuery answerWebAppQuery = AnswerWebAppQuery
|
||||||
|
.builder()
|
||||||
|
.webAppQueryId("123456789")
|
||||||
|
.queryResult(InlineQueryResultArticle
|
||||||
|
.builder()
|
||||||
|
.id("")
|
||||||
|
.title("Text")
|
||||||
|
.inputMessageContent(InputTextMessageContent
|
||||||
|
.builder()
|
||||||
|
.messageText("My own text")
|
||||||
|
.build())
|
||||||
|
.build())
|
||||||
|
.build();
|
||||||
|
assertEquals("answerWebAppQuery", answerWebAppQuery.getMethod());
|
||||||
|
Throwable thrown = assertThrows(TelegramApiValidationException.class, answerWebAppQuery::validate);
|
||||||
|
assertEquals("ID parameter can't be empty", thrown.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAnswerWebAppQueryDeserializeValidResponse() {
|
||||||
|
String responseText = "{\"ok\":true,\"result\": { \"inline_message_id\": \"123456\" } }";
|
||||||
|
|
||||||
|
AnswerWebAppQuery answerWebAppQuery = AnswerWebAppQuery
|
||||||
|
.builder()
|
||||||
|
.webAppQueryId("123456789")
|
||||||
|
.queryResult(InlineQueryResultArticle
|
||||||
|
.builder()
|
||||||
|
.id("")
|
||||||
|
.title("Text")
|
||||||
|
.inputMessageContent(InputTextMessageContent
|
||||||
|
.builder()
|
||||||
|
.messageText("My own text")
|
||||||
|
.build())
|
||||||
|
.build())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try {
|
||||||
|
SentWebAppMessage result = answerWebAppQuery.deserializeResponse(responseText);
|
||||||
|
assertNotNull(result);
|
||||||
|
assertEquals("123456", result.getInlineMessageId());
|
||||||
|
} catch (TelegramApiRequestException e) {
|
||||||
|
fail(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAnswerWebAppQueryDeserializeErrorResponse() {
|
||||||
|
String responseText = "{\"ok\":false,\"error_code\": 404,\"description\": \"Error message\"}";
|
||||||
|
|
||||||
|
AnswerWebAppQuery answerWebAppQuery = AnswerWebAppQuery
|
||||||
|
.builder()
|
||||||
|
.webAppQueryId("123456789")
|
||||||
|
.queryResult(InlineQueryResultArticle
|
||||||
|
.builder()
|
||||||
|
.id("")
|
||||||
|
.title("Text")
|
||||||
|
.inputMessageContent(InputTextMessageContent
|
||||||
|
.builder()
|
||||||
|
.messageText("My own text")
|
||||||
|
.build())
|
||||||
|
.build())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try {
|
||||||
|
answerWebAppQuery.deserializeResponse(responseText);
|
||||||
|
fail();
|
||||||
|
} catch (TelegramApiRequestException e) {
|
||||||
|
assertEquals(404, e.getErrorCode());
|
||||||
|
assertEquals("Error message", e.getApiResponse());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAnswerWebAppQueryDeserializeWithWrongObject() {
|
||||||
|
String responseText = "{\"ok\":false\"error_code\": 404,\"description\": \"Error message\"}";
|
||||||
|
|
||||||
|
AnswerWebAppQuery answerWebAppQuery = AnswerWebAppQuery
|
||||||
|
.builder()
|
||||||
|
.webAppQueryId("123456789")
|
||||||
|
.queryResult(InlineQueryResultArticle
|
||||||
|
.builder()
|
||||||
|
.id("")
|
||||||
|
.title("Text")
|
||||||
|
.inputMessageContent(InputTextMessageContent
|
||||||
|
.builder()
|
||||||
|
.messageText("My own text")
|
||||||
|
.build())
|
||||||
|
.build())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try {
|
||||||
|
answerWebAppQuery.deserializeResponse(responseText);
|
||||||
|
fail();
|
||||||
|
} catch (TelegramApiRequestException e) {
|
||||||
|
assertEquals("Unable to deserialize response", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -122,7 +122,7 @@ public class ChatMemberTest {
|
|||||||
" \"can_post_messages\": true,\n" +
|
" \"can_post_messages\": true,\n" +
|
||||||
" \"can_edit_messages\": true,\n" +
|
" \"can_edit_messages\": true,\n" +
|
||||||
" \"can_delete_messages\": true,\n" +
|
" \"can_delete_messages\": true,\n" +
|
||||||
" \"can_manage_voice_chats\": true,\n" +
|
" \"can_manage_video_chats\": true,\n" +
|
||||||
" \"can_restrict_members\": true,\n" +
|
" \"can_restrict_members\": true,\n" +
|
||||||
" \"can_promote_members\": true,\n" +
|
" \"can_promote_members\": true,\n" +
|
||||||
" \"can_change_info\": true,\n" +
|
" \"can_change_info\": true,\n" +
|
||||||
@ -141,7 +141,7 @@ public class ChatMemberTest {
|
|||||||
assertEquals(true, chatMemberAdministrator.getCanPostMessages());
|
assertEquals(true, chatMemberAdministrator.getCanPostMessages());
|
||||||
assertEquals(true, chatMemberAdministrator.getCanEditMessages());
|
assertEquals(true, chatMemberAdministrator.getCanEditMessages());
|
||||||
assertEquals(true, chatMemberAdministrator.getCanDeleteMessages());
|
assertEquals(true, chatMemberAdministrator.getCanDeleteMessages());
|
||||||
assertEquals(true, chatMemberAdministrator.getCanManageVoiceChats());
|
assertEquals(true, chatMemberAdministrator.getCanManageVideoChats());
|
||||||
assertEquals(true, chatMemberAdministrator.getCanRestrictMembers());
|
assertEquals(true, chatMemberAdministrator.getCanRestrictMembers());
|
||||||
assertEquals(true, chatMemberAdministrator.getCanPromoteMembers());
|
assertEquals(true, chatMemberAdministrator.getCanPromoteMembers());
|
||||||
assertEquals(true, chatMemberAdministrator.getCanChangeInfo());
|
assertEquals(true, chatMemberAdministrator.getCanChangeInfo());
|
||||||
|
@ -85,7 +85,7 @@ class TestDeserialization {
|
|||||||
Integer updateId = update.getUpdateId();
|
Integer updateId = update.getUpdateId();
|
||||||
JsonNode realUpdate = updateMap.get(updateId);
|
JsonNode realUpdate = updateMap.get(updateId);
|
||||||
JsonNode handledUpdate = mapper.readTree(mapper.writeValueAsString(update));
|
JsonNode handledUpdate = mapper.readTree(mapper.writeValueAsString(update));
|
||||||
assertEquals(realUpdate, handledUpdate);
|
assertEquals(realUpdate, handledUpdate, String.format("Error with update %d", updateId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,10 +111,10 @@ class TestDeserialization {
|
|||||||
String updateText = "{\"ok\":true,\"result\":[{\"update_id\":259894302,\n" +
|
String updateText = "{\"ok\":true,\"result\":[{\"update_id\":259894302,\n" +
|
||||||
"\"message\":{\"message_id\":105,\"from\":{\"id\":12345678,\"is_bot\":false,\"first_name\":\"FirstName\",\"username\":\"Username\"},\"chat\":{\"id\":12345678,\"first_name\":\"FirstName\",\"username\":\"Username\",\"type\":\"private\"},\"date\":1604226451,\"text\":\"/start\",\"entities\":[{\"offset\":0,\"length\":6,\"type\":\"bot_command\"}]}},{\"update_id\":259894303,\n" +
|
"\"message\":{\"message_id\":105,\"from\":{\"id\":12345678,\"is_bot\":false,\"first_name\":\"FirstName\",\"username\":\"Username\"},\"chat\":{\"id\":12345678,\"first_name\":\"FirstName\",\"username\":\"Username\",\"type\":\"private\"},\"date\":1604226451,\"text\":\"/start\",\"entities\":[{\"offset\":0,\"length\":6,\"type\":\"bot_command\"}]}},{\"update_id\":259894303,\n" +
|
||||||
"\"message\":{\"message_id\":106,\"from\":{\"id\":12345678,\"is_bot\":false,\"first_name\":\"FirstName\",\"username\":\"Username\",\"language_code\":\"en\"},\"chat\":{\"id\":12345678,\"first_name\":\"FirstName\",\"username\":\"Username\",\"type\":\"private\"},\"date\":1604226480,\"document\":{\"file_name\":\"aaa.txt\",\"mime_type\":\"text/plain\",\"file_id\":\"FILEID\",\"file_unique_id\":\"AgADiQEAAjTe-VQ\",\"file_size\":2}}},{\"update_id\":259894304,\n" +
|
"\"message\":{\"message_id\":106,\"from\":{\"id\":12345678,\"is_bot\":false,\"first_name\":\"FirstName\",\"username\":\"Username\",\"language_code\":\"en\"},\"chat\":{\"id\":12345678,\"first_name\":\"FirstName\",\"username\":\"Username\",\"type\":\"private\"},\"date\":1604226480,\"document\":{\"file_name\":\"aaa.txt\",\"mime_type\":\"text/plain\",\"file_id\":\"FILEID\",\"file_unique_id\":\"AgADiQEAAjTe-VQ\",\"file_size\":2}}},{\"update_id\":259894304,\n" +
|
||||||
"\"message\":{\"message_id\":107,\"from\":{\"id\":12345678,\"is_bot\":false,\"first_name\":\"FirstName\",\"username\":\"FirstName\",\"language_code\":\"en\"},\"chat\":{\"id\":-10011869112345,\"title\":\"My new test group\",\"type\":\"group\",\"all_members_are_administrators\":true},\"date\":1604281682,\"new_chat_members\":[{\"id\":123455678,\"is_bot\":true,\"first_name\":\"Testing Telegram Bots\",\"username\":\"TestingRanBot\"}]}},{\"update_id\":259894305,\n" +
|
"\"message\":{\"message_id\":107,\"from\":{\"id\":12345678,\"is_bot\":false,\"first_name\":\"FirstName\",\"username\":\"FirstName\",\"language_code\":\"en\"},\"chat\":{\"id\":-10011869112345,\"title\":\"My new test group\",\"type\":\"group\"},\"date\":1604281682,\"new_chat_members\":[{\"id\":123455678,\"is_bot\":true,\"first_name\":\"Testing Telegram Bots\",\"username\":\"TestingRanBot\"}]}},{\"update_id\":259894305,\n" +
|
||||||
"\"message\":{\"message_id\":108,\"from\":{\"id\":12345678,\"is_bot\":false,\"first_name\":\"FirstName\",\"username\":\"FirstName\",\"language_code\":\"en\"},\"chat\":{\"id\":-10011869112345,\"title\":\"My new test group\",\"type\":\"group\",\"all_members_are_administrators\":true},\"date\":1604281713,\"left_chat_member\":{\"id\":123455678,\"is_bot\":true,\"first_name\":\"Testing Telegram Bots\",\"username\":\"TestingRanBot\"}}},{\"update_id\":259894306,\n" +
|
"\"message\":{\"message_id\":108,\"from\":{\"id\":12345678,\"is_bot\":false,\"first_name\":\"FirstName\",\"username\":\"FirstName\",\"language_code\":\"en\"},\"chat\":{\"id\":-10011869112345,\"title\":\"My new test group\",\"type\":\"group\"},\"date\":1604281713,\"left_chat_member\":{\"id\":123455678,\"is_bot\":true,\"first_name\":\"Testing Telegram Bots\",\"username\":\"TestingRanBot\"}}},{\"update_id\":259894306,\n" +
|
||||||
"\"message\":{\"message_id\":109,\"from\":{\"id\":12345678,\"is_bot\":false,\"first_name\":\"FirstName\",\"username\":\"FirstName\",\"language_code\":\"en\"},\"chat\":{\"id\":-10011869112345,\"title\":\"My new test group\",\"type\":\"group\",\"all_members_are_administrators\":true},\"date\":1604281720,\"new_chat_members\":[{\"id\":123455678,\"is_bot\":true,\"first_name\":\"Testing Telegram Bots\",\"username\":\"TestingRanBot\"}]}},{\"update_id\":259894307,\n" +
|
"\"message\":{\"message_id\":109,\"from\":{\"id\":12345678,\"is_bot\":false,\"first_name\":\"FirstName\",\"username\":\"FirstName\",\"language_code\":\"en\"},\"chat\":{\"id\":-10011869112345,\"title\":\"My new test group\",\"type\":\"group\"},\"date\":1604281720,\"new_chat_members\":[{\"id\":123455678,\"is_bot\":true,\"first_name\":\"Testing Telegram Bots\",\"username\":\"TestingRanBot\"}]}},{\"update_id\":259894307,\n" +
|
||||||
"\"message\":{\"message_id\":110,\"from\":{\"id\":12345678,\"is_bot\":false,\"first_name\":\"FirstName\",\"username\":\"FirstName\",\"language_code\":\"en\"},\"chat\":{\"id\":-10011869112345,\"title\":\"My new test group\",\"type\":\"group\",\"all_members_are_administrators\":false},\"date\":1604281763,\"migrate_to_chat_id\":-10011869112345}},{\"update_id\":259894308,\n" +
|
"\"message\":{\"message_id\":110,\"from\":{\"id\":12345678,\"is_bot\":false,\"first_name\":\"FirstName\",\"username\":\"FirstName\",\"language_code\":\"en\"},\"chat\":{\"id\":-10011869112345,\"title\":\"My new test group\",\"type\":\"group\"},\"date\":1604281763,\"migrate_to_chat_id\":-10011869112345}},{\"update_id\":259894308,\n" +
|
||||||
"\"message\":{\"message_id\":1,\"from\":{\"id\":12345678,\"is_bot\":true,\"first_name\":\"Group\",\"username\":\"GroupAnonymousBot\"},\"sender_chat\":{\"id\":-10011869112345,\"title\":\"My new test group\",\"type\":\"supergroup\"},\"chat\":{\"id\":-10011869112345,\"title\":\"My new test group\",\"type\":\"supergroup\"},\"date\":1604281763,\"migrate_from_chat_id\":-10011869112345}},{\"update_id\":259894309,\n" +
|
"\"message\":{\"message_id\":1,\"from\":{\"id\":12345678,\"is_bot\":true,\"first_name\":\"Group\",\"username\":\"GroupAnonymousBot\"},\"sender_chat\":{\"id\":-10011869112345,\"title\":\"My new test group\",\"type\":\"supergroup\"},\"chat\":{\"id\":-10011869112345,\"title\":\"My new test group\",\"type\":\"supergroup\"},\"date\":1604281763,\"migrate_from_chat_id\":-10011869112345}},{\"update_id\":259894309,\n" +
|
||||||
"\"message\":{\"message_id\":2,\"from\":{\"id\":12345678,\"is_bot\":false,\"first_name\":\"FirstName\",\"username\":\"FirstName\",\"language_code\":\"en\"},\"chat\":{\"id\":-10011869112345,\"title\":\"My new test group\",\"type\":\"supergroup\"},\"date\":1604281985,\"sticker\":{\"width\":512,\"height\":512,\"emoji\":\"\\ud83e\\udd2c\",\"set_name\":\"ShadowKitty\",\"is_animated\":true,\"thumb\":{\"file_id\":\"FILEID\",\"file_unique_id\":\"FILEID\",\"file_size\":7546,\"width\":128,\"height\":128},\"file_id\":\"FILEID\",\"file_unique_id\":\"FILEID\",\"file_size\":13187}}},{\"update_id\":259894310,\n" +
|
"\"message\":{\"message_id\":2,\"from\":{\"id\":12345678,\"is_bot\":false,\"first_name\":\"FirstName\",\"username\":\"FirstName\",\"language_code\":\"en\"},\"chat\":{\"id\":-10011869112345,\"title\":\"My new test group\",\"type\":\"supergroup\"},\"date\":1604281985,\"sticker\":{\"width\":512,\"height\":512,\"emoji\":\"\\ud83e\\udd2c\",\"set_name\":\"ShadowKitty\",\"is_animated\":true,\"thumb\":{\"file_id\":\"FILEID\",\"file_unique_id\":\"FILEID\",\"file_size\":7546,\"width\":128,\"height\":128},\"file_id\":\"FILEID\",\"file_unique_id\":\"FILEID\",\"file_size\":13187}}},{\"update_id\":259894310,\n" +
|
||||||
"\"message\":{\"message_id\":3,\"from\":{\"id\":12345678,\"is_bot\":false,\"first_name\":\"FirstName\",\"username\":\"FirstName\",\"language_code\":\"en\"},\"chat\":{\"id\":-10011869112345,\"title\":\"My new test group\",\"type\":\"supergroup\"},\"date\":1604281993,\"photo\":[{\"file_id\":\"FILEID\",\"file_unique_id\":\"AQADL3I6J10AAzbcAQAB\",\"file_size\":15207,\"width\":148,\"height\":320},{\"file_id\":\"FILEID\",\"file_unique_id\":\"FILEID\",\"file_size\":64579,\"width\":369,\"height\":800},{\"file_id\":\"FILEID\",\"file_unique_id\":\"FILEID\",\"file_size\":93424,\"width\":591,\"height\":1280}]}},{\"update_id\":259894311,\n" +
|
"\"message\":{\"message_id\":3,\"from\":{\"id\":12345678,\"is_bot\":false,\"first_name\":\"FirstName\",\"username\":\"FirstName\",\"language_code\":\"en\"},\"chat\":{\"id\":-10011869112345,\"title\":\"My new test group\",\"type\":\"supergroup\"},\"date\":1604281993,\"photo\":[{\"file_id\":\"FILEID\",\"file_unique_id\":\"AQADL3I6J10AAzbcAQAB\",\"file_size\":15207,\"width\":148,\"height\":320},{\"file_id\":\"FILEID\",\"file_unique_id\":\"FILEID\",\"file_size\":64579,\"width\":369,\"height\":800},{\"file_id\":\"FILEID\",\"file_unique_id\":\"FILEID\",\"file_size\":93424,\"width\":591,\"height\":1280}]}},{\"update_id\":259894311,\n" +
|
||||||
@ -183,8 +183,7 @@ class TestDeserialization {
|
|||||||
" \"chat\": {\n" +
|
" \"chat\": {\n" +
|
||||||
" \"id\": -552721116,\n" +
|
" \"id\": -552721116,\n" +
|
||||||
" \"title\": \"Random test\",\n" +
|
" \"title\": \"Random test\",\n" +
|
||||||
" \"type\": \"group\",\n" +
|
" \"type\": \"group\"\n" +
|
||||||
" \"all_members_are_administrators\": false\n" +
|
|
||||||
" },\n" +
|
" },\n" +
|
||||||
" \"date\": 1615072605,\n" +
|
" \"date\": 1615072605,\n" +
|
||||||
" \"group_chat_created\": true\n" +
|
" \"group_chat_created\": true\n" +
|
||||||
@ -203,8 +202,7 @@ class TestDeserialization {
|
|||||||
" \"chat\": {\n" +
|
" \"chat\": {\n" +
|
||||||
" \"id\": -552721116,\n" +
|
" \"id\": -552721116,\n" +
|
||||||
" \"title\": \"Random test\",\n" +
|
" \"title\": \"Random test\",\n" +
|
||||||
" \"type\": \"group\",\n" +
|
" \"type\": \"group\"\n" +
|
||||||
" \"all_members_are_administrators\": false\n" +
|
|
||||||
" },\n" +
|
" },\n" +
|
||||||
" \"date\": 1615072631,\n" +
|
" \"date\": 1615072631,\n" +
|
||||||
" \"migrate_to_chat_id\": -1001308316775\n" +
|
" \"migrate_to_chat_id\": -1001308316775\n" +
|
||||||
@ -226,7 +224,7 @@ class TestDeserialization {
|
|||||||
" \"type\": \"supergroup\"\n" +
|
" \"type\": \"supergroup\"\n" +
|
||||||
" },\n" +
|
" },\n" +
|
||||||
" \"date\": 1615072662,\n" +
|
" \"date\": 1615072662,\n" +
|
||||||
" \"voice_chat_started\": {}\n" +
|
" \"video_chat_started\": {}\n" +
|
||||||
" }\n" +
|
" }\n" +
|
||||||
" },\n" +
|
" },\n" +
|
||||||
" {\n" +
|
" {\n" +
|
||||||
@ -245,7 +243,7 @@ class TestDeserialization {
|
|||||||
" \"type\": \"supergroup\"\n" +
|
" \"type\": \"supergroup\"\n" +
|
||||||
" },\n" +
|
" },\n" +
|
||||||
" \"date\": 1615072671,\n" +
|
" \"date\": 1615072671,\n" +
|
||||||
" \"voice_chat_participants_invited\": {\n" +
|
" \"video_chat_participants_invited\": {\n" +
|
||||||
" \"users\": [\n" +
|
" \"users\": [\n" +
|
||||||
" {\n" +
|
" {\n" +
|
||||||
" \"id\": 222222222222222,\n" +
|
" \"id\": 222222222222222,\n" +
|
||||||
@ -274,7 +272,7 @@ class TestDeserialization {
|
|||||||
" \"type\": \"supergroup\"\n" +
|
" \"type\": \"supergroup\"\n" +
|
||||||
" },\n" +
|
" },\n" +
|
||||||
" \"date\": 1615072919,\n" +
|
" \"date\": 1615072919,\n" +
|
||||||
" \"voice_chat_ended\": {\n" +
|
" \"video_chat_ended\": {\n" +
|
||||||
" \"duration\": 257\n" +
|
" \"duration\": 257\n" +
|
||||||
" }\n" +
|
" }\n" +
|
||||||
" }\n" +
|
" }\n" +
|
||||||
|
@ -18,14 +18,14 @@ Usage
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.telegram</groupId>
|
<groupId>org.telegram</groupId>
|
||||||
<artifactId>telegrambots-spring-boot-starter</artifactId>
|
<artifactId>telegrambots-spring-boot-starter</artifactId>
|
||||||
<version>5.7.1</version>
|
<version>6.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
|
|
||||||
**Gradle**
|
**Gradle**
|
||||||
|
|
||||||
```gradle
|
```gradle
|
||||||
implementation 'org.telegram:telegrambots-spring-boot-starter:5.7.1'
|
implementation 'org.telegram:telegrambots-spring-boot-starter:6.0.1'
|
||||||
```
|
```
|
||||||
|
|
||||||
Motivation
|
Motivation
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.telegram</groupId>
|
<groupId>org.telegram</groupId>
|
||||||
<artifactId>Bots</artifactId>
|
<artifactId>Bots</artifactId>
|
||||||
<version>5.7.1</version>
|
<version>6.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>telegrambots-spring-boot-starter</artifactId>
|
<artifactId>telegrambots-spring-boot-starter</artifactId>
|
||||||
@ -72,7 +72,7 @@
|
|||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
|
|
||||||
<telegrambots.version>5.7.1</telegrambots.version>
|
<telegrambots.version>6.0.1</telegrambots.version>
|
||||||
<spring-boot.version>2.6.6</spring-boot.version>
|
<spring-boot.version>2.6.6</spring-boot.version>
|
||||||
|
|
||||||
<maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>
|
<maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.telegram</groupId>
|
<groupId>org.telegram</groupId>
|
||||||
<artifactId>Bots</artifactId>
|
<artifactId>Bots</artifactId>
|
||||||
<version>5.7.1</version>
|
<version>6.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>telegrambots</artifactId>
|
<artifactId>telegrambots</artifactId>
|
||||||
@ -93,7 +93,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.telegram</groupId>
|
<groupId>org.telegram</groupId>
|
||||||
<artifactId>telegrambots-meta</artifactId>
|
<artifactId>telegrambots-meta</artifactId>
|
||||||
<version>5.7.1</version>
|
<version>6.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
|
@ -102,59 +102,6 @@ public final class WebhookUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {{@link #setWebhook(DefaultAbsSender, WebhookBot, SetWebhook)}} instead
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public static void setWebhook(DefaultAbsSender bot, WebhookBot webhookBot, String url, String publicCertificatePath) throws TelegramApiRequestException {
|
|
||||||
DefaultBotOptions botOptions = bot.getOptions();
|
|
||||||
|
|
||||||
try (CloseableHttpClient httpclient = TelegramHttpClientBuilder.build(botOptions)) {
|
|
||||||
String requestUrl = bot.getBaseUrl() + SetWebhook.PATH;
|
|
||||||
|
|
||||||
RequestConfig requestConfig = botOptions.getRequestConfig();
|
|
||||||
if (requestConfig == null) {
|
|
||||||
requestConfig = RequestConfig.copy(RequestConfig.custom().build())
|
|
||||||
.setSocketTimeout(SOCKET_TIMEOUT)
|
|
||||||
.setConnectTimeout(SOCKET_TIMEOUT)
|
|
||||||
.setConnectionRequestTimeout(SOCKET_TIMEOUT).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
HttpPost httppost = new HttpPost(requestUrl);
|
|
||||||
httppost.setConfig(requestConfig);
|
|
||||||
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
|
|
||||||
builder.addTextBody(SetWebhook.URL_FIELD, getBotUrl(url, webhookBot.getBotPath()));
|
|
||||||
if (botOptions.getMaxWebhookConnections() != null) {
|
|
||||||
builder.addTextBody(SetWebhook.MAXCONNECTIONS_FIELD, botOptions.getMaxWebhookConnections().toString());
|
|
||||||
}
|
|
||||||
if (botOptions.getAllowedUpdates() != null) {
|
|
||||||
builder.addTextBody(SetWebhook.ALLOWEDUPDATES_FIELD, new JSONArray(botOptions.getAllowedUpdates()).toString());
|
|
||||||
}
|
|
||||||
if (botOptions.getAllowedUpdates() != null) {
|
|
||||||
builder.addTextBody(SetWebhook.ALLOWEDUPDATES_FIELD, new JSONArray(botOptions.getAllowedUpdates()).toString());
|
|
||||||
}
|
|
||||||
if (publicCertificatePath != null) {
|
|
||||||
File certificate = new File(publicCertificatePath);
|
|
||||||
if (certificate.exists()) {
|
|
||||||
builder.addBinaryBody(SetWebhook.CERTIFICATE_FIELD, certificate, ContentType.TEXT_PLAIN, certificate.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
HttpEntity multipart = builder.build();
|
|
||||||
httppost.setEntity(multipart);
|
|
||||||
try (CloseableHttpResponse response = httpclient.execute(httppost, botOptions.getHttpContext())) {
|
|
||||||
String responseContent = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
|
|
||||||
JSONObject jsonObject = new JSONObject(responseContent);
|
|
||||||
if (!jsonObject.getBoolean(ApiConstants.RESPONSE_FIELD_OK)) {
|
|
||||||
throw new TelegramApiRequestException("Error setting webhook", jsonObject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
throw new TelegramApiRequestException("Error deserializing setWebhook method response", e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new TelegramApiRequestException("Error executing setWebook method", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void clearWebhook(DefaultAbsSender bot) throws TelegramApiRequestException {
|
public static void clearWebhook(DefaultAbsSender bot) throws TelegramApiRequestException {
|
||||||
try {
|
try {
|
||||||
boolean result = bot.execute(new DeleteWebhook());
|
boolean result = bot.execute(new DeleteWebhook());
|
||||||
|
Loading…
Reference in New Issue
Block a user