Merge tag 'v6.1.0'
This commit is contained in:
commit
40006eabd3
38
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
38
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Desktop (please complete the following information):**
|
||||
- OS: [e.g. iOS]
|
||||
- Browser [e.g. chrome, safari]
|
||||
- Version [e.g. 22]
|
||||
|
||||
**Smartphone (please complete the following information):**
|
||||
- Device: [e.g. iPhone6]
|
||||
- OS: [e.g. iOS8.1]
|
||||
- Browser [e.g. stock browser, safari]
|
||||
- Version [e.g. 22]
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
@ -27,18 +27,18 @@ Just import add the library to your project with one of these options:
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots</artifactId>
|
||||
<version>6.0.1</version>
|
||||
<version>6.1.0</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
2. Using Gradle:
|
||||
|
||||
```gradle
|
||||
implementation 'org.telegram:telegrambots:6.0.1'
|
||||
implementation 'org.telegram:telegrambots:6.1.0'
|
||||
```
|
||||
|
||||
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/6.0.1)
|
||||
3. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/6.1.0)
|
||||
4. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/6.1.0)
|
||||
|
||||
In order to use Long Polling mode, just create your own bot extending `org.telegram.telegrambots.bots.TelegramLongPollingBot`.
|
||||
|
||||
|
@ -1,3 +1,10 @@
|
||||
### <a id="6.1.0"></a>6.1.0 ###
|
||||
1. Update Api version [6.1](https://core.telegram.org/bots/api-changelog#june-20-2022)
|
||||
2. Add support for Long when setting the chatId: #1065
|
||||
3. Bug fixing: #755, #1036, #1055, #1060, #1064, #1065, #1067, #1069, #1070, #1086, #1088
|
||||
|
||||
**[[How to update to version 6.1.0|How-To-Update#6.1.0]]**
|
||||
|
||||
### <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
|
||||
|
@ -11,13 +11,13 @@ First you need ot get the library and add it to your project. There are few poss
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots</artifactId>
|
||||
<version>6.0.1</version>
|
||||
<version>6.1.0</version>
|
||||
</dependency>
|
||||
```
|
||||
* With **Gradle**:
|
||||
|
||||
```gradle
|
||||
implementation 'org.telegram:telegrambots:6.0.1'
|
||||
implementation 'org.telegram:telegrambots:6.1.0'
|
||||
```
|
||||
|
||||
2. Don't like **Maven Central Repository**? It can also be taken from [Jitpack](https://jitpack.io/#rubenlagus/TelegramBots).
|
||||
|
@ -1,3 +1,7 @@
|
||||
### <a id="6.1.0"></a>To version 6.1.0 ###
|
||||
1. As per API guidelines, FileSize can now have 64 bits size, hence they are now using Long datatype instead of Integer.
|
||||
2. Methods accept chatId as Long or String.
|
||||
|
||||
### <a id="5.3.0"></a>To version 5.3.0 ###
|
||||
1. As per API guidelines, ChatMember method has been divided in different classed.
|
||||
Where used in your code, replace old import with new one
|
||||
|
@ -2,41 +2,48 @@
|
||||
You have around 100 abilities in your bot and you're looking for a way to refactor that mess into more modular classes. `AbillityExtension` is here to support just that! It's not a secret that AbilityBot uses refactoring backstage to be able to construct all of your abilities and map them accordingly. However, AbilityBot searches initially for all methods that return an `AbilityExtension` type. Then, those extensions will be used to search for declared abilities. Here's an example.
|
||||
```java
|
||||
public class MrGoodGuy implements AbilityExtension {
|
||||
public Ability nice() {
|
||||
return Ability.builder()
|
||||
.name("nice")
|
||||
.privacy(PUBLIC)
|
||||
.locality(ALL)
|
||||
.action(ctx -> silent.send("You're awesome!", ctx.chatId())
|
||||
);
|
||||
}
|
||||
private AbilityBot extensionUser;
|
||||
|
||||
public MrGoodGuy(AbilityBot extensionUser) { this.extensionUser = extensionUser; }
|
||||
|
||||
public Ability nice() {
|
||||
return Ability.builder()
|
||||
.name("nice")
|
||||
.privacy(PUBLIC)
|
||||
.locality(ALL)
|
||||
.action(ctx -> extensionUser.silent().send("You're awesome!", ctx.chatId())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public class MrBadGuy implements AbilityExtension {
|
||||
public Ability notnice() {
|
||||
return Ability.builder()
|
||||
.name("notnice")
|
||||
.privacy(PUBLIC)
|
||||
.locality(ALL)
|
||||
.action(ctx -> silent.send("You're horrible!", ctx.chatId())
|
||||
);
|
||||
}
|
||||
}
|
||||
private AbilityBot extensionUser;
|
||||
|
||||
public class YourAwesomeBot implements AbilityBot {
|
||||
public MrBadGuy(AbilityBot extensionUser) { this.extensionUser = extensionUser; }
|
||||
public Ability notnice() {
|
||||
return Ability.builder()
|
||||
.name("notnice")
|
||||
.privacy(PUBLIC)
|
||||
.locality(ALL)
|
||||
.action(ctx -> extensionUser.silent().send("You're horrible!", ctx.chatId())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public class YourAwesomeBot implements AbilityBot {
|
||||
|
||||
// Constructor for your bot
|
||||
|
||||
public AbilityExtension goodGuy() {
|
||||
return new MrGoodGuy();
|
||||
return new MrGoodGuy(this);
|
||||
}
|
||||
|
||||
public AbilityExtension badGuy() {
|
||||
return new MrBadGuy();
|
||||
return new MrBadGuy(this);
|
||||
}
|
||||
|
||||
// Override creatorId
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
It's also possible to add extensions in the constructor by using the `addExtension()` or `addExtensions()` method:
|
||||
@ -45,10 +52,10 @@ It's also possible to add extensions in the constructor by using the `addExtensi
|
||||
public class YourAwesomeBot implements AbilityBot {
|
||||
|
||||
public YourAwesomeBot() {
|
||||
super(/* pass required args ... */);
|
||||
addExtensions(new MrGoodGuy(), new MrBadGuy());
|
||||
super(/* pass required args ... */);
|
||||
addExtensions(new MrGoodGuy(this), new MrBadGuy(this));
|
||||
}
|
||||
|
||||
// Override creatorId
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -29,7 +29,7 @@ As an example, if you want to restrict the updates to photos only, then you may
|
||||
```java
|
||||
@Override
|
||||
public boolean checkGlobalFlags(Update update) {
|
||||
return Flag.PHOTO;
|
||||
return Flag.PHOTO.test(update);
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -9,12 +9,12 @@ As with any Java project, you will need to set your dependencies.
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots-abilities</artifactId>
|
||||
<version>6.0.1</version>
|
||||
<version>6.1.0</version>
|
||||
</dependency>
|
||||
```
|
||||
* **Gradle**
|
||||
```gradle
|
||||
implementation 'org.telegram:telegrambots-abilities:6.0.1'
|
||||
implementation 'org.telegram:telegrambots-abilities:6.1.0'
|
||||
```
|
||||
* [JitPack](https://jitpack.io/#rubenlagus/TelegramBots)
|
||||
|
||||
@ -109,6 +109,8 @@ Since you've implemented an AbilityBot, you get **factory abilities** as well. T
|
||||
* /demote @username - demotes bot admin to user
|
||||
* /ban @username - bans the user from accessing your bot commands and features
|
||||
* /unban @username - lifts the ban from the user
|
||||
* /stats - displays how many times were your abilities called
|
||||
* **This command returns empty String by default.** To use this command, add ```.setStatsEnabled(true)``` to your abilities. You'll then be able to view how many times each of them was called.
|
||||
|
||||
## Conclusion
|
||||
Congratulation on creating your first AbilityBot. What's next? So far we've only considered the case of commands, but what about images and inline replies? AbilityBots can also handle that! Oh and, did you know that all ability bots have an embedded database that you can use?
|
||||
|
16
pom.xml
16
pom.xml
@ -7,7 +7,7 @@
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>Bots</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>6.0.1</version>
|
||||
<version>6.1.0</version>
|
||||
|
||||
<modules>
|
||||
<module>telegrambots</module>
|
||||
@ -70,13 +70,13 @@
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
|
||||
<junit.version>5.8.2</junit.version>
|
||||
<mockito.version>4.5.1</mockito.version>
|
||||
<mockitojupiter.version>4.5.1</mockitojupiter.version>
|
||||
<mockito.version>4.6.1</mockito.version>
|
||||
<mockitojupiter.version>4.6.1</mockitojupiter.version>
|
||||
<jacksonanotation.version>2.13.2</jacksonanotation.version>
|
||||
<jackson.version>2.13.2.2</jackson.version>
|
||||
<json.version>20220320</json.version>
|
||||
<slf4j.version>1.7.36</slf4j.version>
|
||||
<jakarta.annotation.version>2.1.0</jakarta.annotation.version>
|
||||
<jakarta.annotation.version>2.1.1</jakarta.annotation.version>
|
||||
<lombok.version>1.18.24</lombok.version>
|
||||
<guava.version>31.1-jre</guava.version>
|
||||
</properties>
|
||||
@ -168,12 +168,12 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-site-plugin</artifactId>
|
||||
<version>3.8.2</version>
|
||||
<version>3.12.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<version>1.6</version>
|
||||
<version>3.0.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>sign-artifacts</id>
|
||||
@ -187,7 +187,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<version>3.4.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>aggregate</id>
|
||||
@ -205,7 +205,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-enforcer-plugin</artifactId>
|
||||
<version>3.0.0-M3</version>
|
||||
<version>3.0.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>enforce-versions</id>
|
||||
|
@ -18,14 +18,14 @@ Usage
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots-abilities</artifactId>
|
||||
<version>6.0.1</version>
|
||||
<version>6.1.0</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
**Gradle**
|
||||
|
||||
```gradle
|
||||
implementation 'org.telegram:telegrambots-abilities:6.0.1'
|
||||
implementation 'org.telegram:telegrambots-abilities:6.1.0'
|
||||
```
|
||||
|
||||
**JitPack** - [JitPack](https://jitpack.io/#rubenlagus/TelegramBots/v5.0.1)
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>Bots</artifactId>
|
||||
<version>6.0.1</version>
|
||||
<version>6.1.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>telegrambots-abilities</artifactId>
|
||||
@ -86,7 +86,7 @@
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots</artifactId>
|
||||
<version>6.0.1</version>
|
||||
<version>6.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
@ -116,7 +116,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.0.0-M5</version>
|
||||
<version>3.0.0-M6</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
@ -134,7 +134,7 @@
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>3.2.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>clean-project</id>
|
||||
@ -147,7 +147,7 @@
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<version>3.3.0</version>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
@ -166,7 +166,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>3.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
@ -178,7 +178,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>3.4.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
@ -193,7 +193,7 @@
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<version>0.8.4</version>
|
||||
<version>0.8.8</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
@ -230,7 +230,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<version>3.3.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy</id>
|
||||
@ -244,7 +244,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<version>3.10.1</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
|
@ -1,12 +1,18 @@
|
||||
package org.telegram.abilitybots.api.bot;
|
||||
|
||||
import com.google.common.collect.*;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableList.Builder;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.telegram.abilitybots.api.db.DBContext;
|
||||
import org.telegram.abilitybots.api.objects.*;
|
||||
import org.telegram.abilitybots.api.objects.Ability;
|
||||
import org.telegram.abilitybots.api.objects.Locality;
|
||||
import org.telegram.abilitybots.api.objects.MessageContext;
|
||||
import org.telegram.abilitybots.api.objects.Privacy;
|
||||
import org.telegram.abilitybots.api.objects.Reply;
|
||||
import org.telegram.abilitybots.api.objects.ReplyCollection;
|
||||
import org.telegram.abilitybots.api.objects.Stats;
|
||||
import org.telegram.abilitybots.api.sender.DefaultSender;
|
||||
import org.telegram.abilitybots.api.sender.MessageSender;
|
||||
import org.telegram.abilitybots.api.sender.SilentSender;
|
||||
@ -26,7 +32,12 @@ import org.telegram.telegrambots.meta.api.objects.chatmember.ChatMemberOwner;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
@ -44,12 +55,25 @@ import static java.util.Optional.ofNullable;
|
||||
import static java.util.regex.Pattern.CASE_INSENSITIVE;
|
||||
import static java.util.regex.Pattern.compile;
|
||||
import static java.util.stream.Collectors.toSet;
|
||||
import static org.telegram.abilitybots.api.objects.Locality.*;
|
||||
import static org.telegram.abilitybots.api.objects.Locality.ALL;
|
||||
import static org.telegram.abilitybots.api.objects.Locality.GROUP;
|
||||
import static org.telegram.abilitybots.api.objects.Locality.USER;
|
||||
import static org.telegram.abilitybots.api.objects.MessageContext.newContext;
|
||||
import static org.telegram.abilitybots.api.objects.Privacy.*;
|
||||
import static org.telegram.abilitybots.api.objects.Privacy.ADMIN;
|
||||
import static org.telegram.abilitybots.api.objects.Privacy.CREATOR;
|
||||
import static org.telegram.abilitybots.api.objects.Privacy.GROUP_ADMIN;
|
||||
import static org.telegram.abilitybots.api.objects.Privacy.PUBLIC;
|
||||
import static org.telegram.abilitybots.api.objects.Stats.createStats;
|
||||
import static org.telegram.abilitybots.api.util.AbilityMessageCodes.*;
|
||||
import static org.telegram.abilitybots.api.util.AbilityUtils.*;
|
||||
import static org.telegram.abilitybots.api.util.AbilityMessageCodes.CHECK_INPUT_FAIL;
|
||||
import static org.telegram.abilitybots.api.util.AbilityMessageCodes.CHECK_LOCALITY_FAIL;
|
||||
import static org.telegram.abilitybots.api.util.AbilityMessageCodes.CHECK_PRIVACY_FAIL;
|
||||
import static org.telegram.abilitybots.api.util.AbilityUtils.EMPTY_USER;
|
||||
import static org.telegram.abilitybots.api.util.AbilityUtils.getChatId;
|
||||
import static org.telegram.abilitybots.api.util.AbilityUtils.getLocalizedMessage;
|
||||
import static org.telegram.abilitybots.api.util.AbilityUtils.getUser;
|
||||
import static org.telegram.abilitybots.api.util.AbilityUtils.isGroupUpdate;
|
||||
import static org.telegram.abilitybots.api.util.AbilityUtils.isSuperGroupUpdate;
|
||||
import static org.telegram.abilitybots.api.util.AbilityUtils.isUserMessage;
|
||||
|
||||
/**
|
||||
* The <b>father</b> of all ability bots. Bots that need to utilize abilities need to extend this bot.
|
||||
@ -260,7 +284,7 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability
|
||||
}
|
||||
|
||||
public boolean isGroupAdmin(long chatId, long id) {
|
||||
GetChatAdministrators admins = GetChatAdministrators.builder().chatId(Long.toString(chatId)).build();
|
||||
GetChatAdministrators admins = GetChatAdministrators.builder().chatId(chatId).build();
|
||||
return silent.execute(admins)
|
||||
.orElse(new ArrayList<>())
|
||||
.stream()
|
||||
@ -673,8 +697,13 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability
|
||||
try {
|
||||
return callable.call();
|
||||
} catch(Exception ex) {
|
||||
log.error(format("Reply [%s] failed to check for conditions. " +
|
||||
"Make sure you're safeguarding against all possible updates.", name));
|
||||
String msg = format("Reply [%s] failed to check for conditions. " +
|
||||
"Make sure you're safeguarding against all possible updates.", name);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.error(msg, ex);
|
||||
} else {
|
||||
log.error(msg);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -224,7 +224,7 @@ public final class DefaultAbilities implements AbilityExtension {
|
||||
printStream.print(bot.db.backup());
|
||||
bot.sender.sendDocument(SendDocument.builder()
|
||||
.document(new InputFile(backup))
|
||||
.chatId(ctx.chatId().toString())
|
||||
.chatId(ctx.chatId())
|
||||
.build()
|
||||
);
|
||||
} catch (FileNotFoundException e) {
|
||||
|
@ -38,7 +38,7 @@ public class SilentSender {
|
||||
public Optional<Message> forceReply(String message, long id) {
|
||||
SendMessage msg = new SendMessage();
|
||||
msg.setText(message);
|
||||
msg.setChatId(Long.toString(id));
|
||||
msg.setChatId(id);
|
||||
ForceReplyKeyboard kb = new ForceReplyKeyboard();
|
||||
kb.setForceReply(true);
|
||||
kb.setSelective(true);
|
||||
@ -67,7 +67,7 @@ public class SilentSender {
|
||||
|
||||
private Optional<Message> doSendMessage(String txt, long groupId, boolean format) {
|
||||
SendMessage smsg = new SendMessage();
|
||||
smsg.setChatId(Long.toString(groupId));
|
||||
smsg.setChatId(groupId);
|
||||
smsg.setText(txt);
|
||||
smsg.enableMarkdown(format);
|
||||
|
||||
|
@ -4,10 +4,11 @@ import org.telegram.abilitybots.api.objects.Ability;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* This custom toggle can be used to customize default abilities supplied by the library. Users can call {@link CustomToggle#toggle} to
|
||||
* rename the default abilites or {@link CustomToggle#turnOff} to simply turn off the said ability.
|
||||
* rename the default abilities or {@link CustomToggle#turnOff} to simply turn off the said ability.
|
||||
*/
|
||||
public class CustomToggle implements AbilityToggle {
|
||||
public static final String OFF = "turn_off_base_ability";
|
||||
@ -53,4 +54,76 @@ public class CustomToggle implements AbilityToggle {
|
||||
baseMapping.put(ability, OFF);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param properties the abilities toggle definition
|
||||
* @return the toggle instance
|
||||
*/
|
||||
public CustomToggle config(Properties properties) {
|
||||
for (String key : properties.stringPropertyNames()) {
|
||||
String value = properties.getProperty(key);
|
||||
key = key.toLowerCase();
|
||||
|
||||
// compare with legal configuration names
|
||||
for (Property p: Property.values()) {
|
||||
if (key.equals(p.key())) {
|
||||
String ability = key.split("\\.")[1];
|
||||
if (key.contains("enabled") && value.equalsIgnoreCase("false")) {
|
||||
this.turnOff(ability);
|
||||
}else if (key.contains("toggle")) {
|
||||
this.toggle(ability, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* List of all the properties recognized by {@link CustomToggle}.
|
||||
* Can be used to programmatically get, set or remove default values.
|
||||
*/
|
||||
public enum Property{
|
||||
CLAIM_ENABLED("ability.claim.enabled"),
|
||||
CLAIM_TOGGLE("ability.claim.toggle"),
|
||||
|
||||
BAN_ENABLED("ability.ban.enabled"),
|
||||
BAN_TOGGLE("ability.ban.toggle"),
|
||||
|
||||
PROMOTE_ENABLED("ability.promote.enabled"),
|
||||
PROMOTE_TOGGLE("ability.promote.toggle"),
|
||||
|
||||
DEMOTE_ENABLED("ability.demote.enabled"),
|
||||
DEMOTE_TOGGLE("ability.demote.toggle"),
|
||||
|
||||
UNBAN_ENABLED("ability.unban.enabled"),
|
||||
UNBAN_TOGGLE("ability.unban.toggle"),
|
||||
|
||||
BACKUP_ENABLED("ability.backup.enabled"),
|
||||
BACKUP_TOGGLE("ability.backup.toggle"),
|
||||
|
||||
RECOVER_ENABLED("ability.recover.enabled"),
|
||||
RECOVER_TOGGLE("ability.recover.toggle"),
|
||||
|
||||
COMMANDS_ENABLED("ability.commands.enabled"),
|
||||
COMMANDS_TOGGLE("ability.commands.toggle"),
|
||||
|
||||
REPORT_ENABLED("ability.report.enabled"),
|
||||
REPORT_TOGGLE("ability.report.toggle"),
|
||||
|
||||
STATS_ENABLED("ability.stats.enabled"),
|
||||
STATS_TOGGLE("ability.stats.toggle")
|
||||
;
|
||||
|
||||
private final String key;
|
||||
|
||||
Property (final String key){
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String key() {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -52,6 +52,10 @@ class AbilityBotI18nTest {
|
||||
null
|
||||
);
|
||||
|
||||
class AbilityBotI18nTest {
|
||||
private static final User NO_LANGUAGE_USER = new User(1L, "first", false, "last", "username", null, false, false, false, false, false);
|
||||
private static final User ITALIAN_USER = new User(2L, "first", false, "last", "username", "it-IT", false, false, false, false, false);
|
||||
|
||||
private DBContext db;
|
||||
private NoPublicCommandsBot bot;
|
||||
private DefaultAbilities defaultAbs;
|
||||
|
@ -373,22 +373,7 @@ public class AbilityBotTest {
|
||||
String newFirstName = USER.getFirstName() + "-test";
|
||||
String newLastName = USER.getLastName() + "-test";
|
||||
long sameId = USER.getId();
|
||||
User changedUser = new User(sameId,
|
||||
newFirstName,
|
||||
false,
|
||||
newLastName,
|
||||
newUsername,
|
||||
"en",
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
);
|
||||
User changedUser = new User(sameId, newFirstName, false, newLastName, newUsername, "en", false, false, false, false, false);
|
||||
|
||||
mockAlternateUser(update, message, changedUser);
|
||||
|
||||
@ -397,7 +382,7 @@ public class AbilityBotTest {
|
||||
Map<String, Long> expectedUserIds = ImmutableMap.of(changedUser.getUserName(), changedUser.getId());
|
||||
Map<Long, User> expectedUsers = ImmutableMap.of(changedUser.getId(), changedUser);
|
||||
assertEquals(bot.userIds(), expectedUserIds, "User was not properly edited");
|
||||
assertEquals(expectedUsers, expectedUsers, "User was not properly edited");
|
||||
assertEquals(bot.users(), expectedUsers, "User was not properly edited");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -41,9 +41,13 @@ class ExtensionTest {
|
||||
}
|
||||
|
||||
public static class ExtensionUsingBot extends AbilityBot {
|
||||
/**
|
||||
* Constructor for ExtensionUsingBot
|
||||
*/
|
||||
ExtensionUsingBot() {
|
||||
// https://github.com/rubenlagus/TelegramBots/issues/834
|
||||
super("", "", offlineInstance("testing"));
|
||||
addExtension(new AbilityBotExtension("addedInConstructor"));
|
||||
addExtension(new AbilityBotExtension("addedInConstructor", this));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -51,42 +55,63 @@ class ExtensionTest {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for returning AbiltyExtension
|
||||
* @return AbilityBotExtension instance
|
||||
*/
|
||||
public AbilityBotExtension methodReturningExtensionSubClass() {
|
||||
return new AbilityBotExtension("returningSubClass");
|
||||
// https://github.com/rubenlagus/TelegramBots/issues/834
|
||||
return new AbilityBotExtension("returningSubClass", this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for returning AbilityExtension
|
||||
* @return AbiltyBotExtension instance
|
||||
*/
|
||||
public AbilityExtension methodReturningExtensionSuperClass() {
|
||||
return new AbilityBotExtension("returningSuperClass");
|
||||
// https://github.com/rubenlagus/TelegramBots/issues/834
|
||||
return new AbilityBotExtension("returningSuperClass", this);
|
||||
}
|
||||
|
||||
public Ability methodReturningAbility() {
|
||||
return Ability.builder()
|
||||
.name("direct")
|
||||
.info("Test ability")
|
||||
.locality(ALL)
|
||||
.privacy(PUBLIC)
|
||||
.action(messageContext -> {
|
||||
})
|
||||
.build();
|
||||
.name("direct")
|
||||
.info("Test ability")
|
||||
.locality(ALL)
|
||||
.privacy(PUBLIC)
|
||||
.action(messageContext -> {
|
||||
})
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
public static class AbilityBotExtension implements AbilityExtension {
|
||||
private String name;
|
||||
private AbilityBot extensionUser;
|
||||
|
||||
AbilityBotExtension(String name) {
|
||||
/**
|
||||
* https://github.com/rubenlagus/TelegramBots/issues/721
|
||||
* Constructor for AbilityBotExtension
|
||||
* @param name Name of the ability extension
|
||||
* @param extensionUser The AbilityBot that uses this AbilityExtension
|
||||
*/
|
||||
AbilityBotExtension(String name, AbilityBot extensionUser) {
|
||||
this.name = name;
|
||||
// https://github.com/rubenlagus/TelegramBots/issues/834
|
||||
this.extensionUser = extensionUser;
|
||||
}
|
||||
|
||||
public Ability abc() {
|
||||
return Ability.builder()
|
||||
.name(name + "0abc")
|
||||
.info("Test ability")
|
||||
.locality(ALL)
|
||||
.privacy(PUBLIC)
|
||||
.action(ctx -> {
|
||||
})
|
||||
.build();
|
||||
.name(name + "0abc")
|
||||
.info("Test ability")
|
||||
.locality(ALL)
|
||||
.privacy(PUBLIC)
|
||||
.action(ctx -> {
|
||||
// https://github.com/rubenlagus/TelegramBots/issues/834
|
||||
extensionUser.silent().send("This is a test message.", ctx.chatId());
|
||||
})
|
||||
.build();
|
||||
}
|
||||
}
|
||||
}
|
@ -11,6 +11,8 @@ import org.telegram.telegrambots.meta.api.objects.Update;
|
||||
import org.telegram.telegrambots.meta.api.objects.User;
|
||||
|
||||
public final class TestUtils {
|
||||
public static final User USER = new User(1L, "first", false, "last", "username", null, false, false, false, false, false);
|
||||
public static final User CREATOR = new User(1337L, "creatorFirst", false, "creatorLast", "creatorUsername", null, false, false, false, false, false);
|
||||
|
||||
public static final User USER = new User(1L,
|
||||
"first",
|
||||
|
@ -143,4 +143,17 @@ class MapDBContextTest {
|
||||
Var<User> changedVar = db.getVar(varName);
|
||||
assertEquals(changedVar.get(), USER);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToString() throws Exception {
|
||||
String varName = "somevar";
|
||||
Var<User> var = db.getVar(varName);
|
||||
var.set(CREATOR);
|
||||
db.commit();
|
||||
var = db.getVar(varName);
|
||||
var.set(USER);
|
||||
db.commit();
|
||||
Var<User> changedVar = db.getVar(varName);
|
||||
Assertions.assertEquals("MapDBVar{var=User(id=1, firstName=first, isBot=false, lastName=last, userName=username, languageCode=null, canJoinGroups=false, canReadAllGroupMessages=false, supportInlineQueries=false, isPremium=false, addedToAttachmentMenu=false)}", ((MapDBVar) (changedVar)).toString());
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,9 @@ import org.telegram.abilitybots.api.bot.DefaultAbilities;
|
||||
import org.telegram.abilitybots.api.bot.DefaultBot;
|
||||
import org.telegram.abilitybots.api.db.DBContext;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.EMPTY;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
@ -17,10 +19,12 @@ class CustomToggleTest {
|
||||
private DBContext db;
|
||||
private AbilityToggle toggle;
|
||||
private DefaultBot customBot;
|
||||
private String filename;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
db = offlineInstance("db");
|
||||
filename = "src/test/resources/toggle.properties";
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
@ -47,4 +51,37 @@ class CustomToggleTest {
|
||||
assertTrue(customBot.abilities().containsKey(targetName));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canTurnOffAbilitiesThroughProperties() {
|
||||
Properties properties = new Properties();
|
||||
try {
|
||||
properties.load(new FileInputStream(filename));
|
||||
toggle = new CustomToggle().config(properties);
|
||||
} catch (IOException e) {
|
||||
System.out.println("No such file");
|
||||
}
|
||||
|
||||
customBot = new DefaultBot(EMPTY, EMPTY, db, toggle);
|
||||
customBot.onRegister();
|
||||
|
||||
assertFalse(customBot.abilities().containsKey(DefaultAbilities.CLAIM));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canProcessAbilitiesThroughProperties() {
|
||||
Properties properties = new Properties();
|
||||
try {
|
||||
properties.load(new FileInputStream(filename));
|
||||
toggle = new CustomToggle().config(properties);
|
||||
} catch (IOException e) {
|
||||
System.out.println("No such file");
|
||||
}
|
||||
|
||||
customBot = new DefaultBot(EMPTY, EMPTY, db, toggle);
|
||||
customBot.onRegister();
|
||||
|
||||
String targetName = "restrict";
|
||||
assertTrue(customBot.abilities().containsKey(targetName));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
ability.claim.enabled=false
|
||||
ability.ban.toggle=restrict
|
@ -15,14 +15,14 @@ Usage
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots-chat-session-bot</artifactId>
|
||||
<version>6.0.1</version>
|
||||
<version>6.1.0</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
**Gradle**
|
||||
|
||||
```gradle
|
||||
implementation 'org.telegram:telegrambots-chat-session-bot:6.0.1'
|
||||
implementation 'org.telegram:telegrambots-chat-session-bot:6.1.0'
|
||||
```
|
||||
|
||||
Motivation
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>Bots</artifactId>
|
||||
<version>6.0.1</version>
|
||||
<version>6.1.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>telegrambots-chat-session-bot</artifactId>
|
||||
@ -86,7 +86,7 @@
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots</artifactId>
|
||||
<version>6.0.1</version>
|
||||
<version>6.1.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.shiro/shiro-core -->
|
||||
@ -113,7 +113,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.0.0-M5</version>
|
||||
<version>3.0.0-M6</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
@ -131,7 +131,7 @@
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>3.2.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>clean-project</id>
|
||||
@ -144,7 +144,7 @@
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<version>3.3.0</version>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
@ -163,7 +163,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>3.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
@ -175,7 +175,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>3.4.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
@ -190,7 +190,7 @@
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<version>0.8.4</version>
|
||||
<version>0.8.8</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
@ -227,7 +227,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<version>3.3.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy</id>
|
||||
@ -241,7 +241,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<version>3.10.1</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
|
@ -16,12 +16,12 @@ Just import add the library to your project with one of these options:
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambotsextensions</artifactId>
|
||||
<version>6.0.1</version>
|
||||
<version>6.1.0</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
2. Using Gradle:
|
||||
|
||||
```gradle
|
||||
implementation 'org.telegram:telegrambotsextensions:6.0.1'
|
||||
implementation 'org.telegram:telegrambotsextensions:6.1.0'
|
||||
```
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>Bots</artifactId>
|
||||
<version>6.0.1</version>
|
||||
<version>6.1.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>telegrambotsextensions</artifactId>
|
||||
@ -77,7 +77,7 @@
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots</artifactId>
|
||||
<version>6.0.1</version>
|
||||
<version>6.1.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@ -91,7 +91,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.0.0-M5</version>
|
||||
<version>3.0.0-M6</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
@ -109,7 +109,7 @@
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>3.2.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>clean-project</id>
|
||||
@ -122,7 +122,7 @@
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<version>3.3.0</version>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
@ -141,7 +141,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>3.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
@ -153,7 +153,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>3.4.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
@ -168,7 +168,7 @@
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<version>0.8.4</version>
|
||||
<version>0.8.8</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
@ -205,7 +205,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<version>3.3.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy</id>
|
||||
@ -219,7 +219,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<version>3.10.1</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
|
@ -0,0 +1,47 @@
|
||||
package org.telegram.telegrambots.extensions.bots.commandbot;
|
||||
|
||||
import org.telegram.telegrambots.meta.api.objects.Message;
|
||||
import org.telegram.telegrambots.meta.api.objects.Update;
|
||||
|
||||
/**
|
||||
* This interface represents common functions for command bots
|
||||
*
|
||||
* @author Andrey Korsakov (loolzaaa)
|
||||
*/
|
||||
public interface CommandBot {
|
||||
/**
|
||||
* Process all updates, that are not commands.
|
||||
*
|
||||
* @param update the update
|
||||
* @warning Commands that have valid syntax but are not registered on this bot,
|
||||
* won't be forwarded to this method <b>if a default action is present</b>.
|
||||
*/
|
||||
void processNonCommandUpdate(Update update);
|
||||
|
||||
/**
|
||||
* This method is called when user sends a not registered command. By default it will just call processNonCommandUpdate(),
|
||||
* override it in your implementation if you want your bot to do other things, such as sending an error message
|
||||
*
|
||||
* @param update Received update from Telegram
|
||||
*/
|
||||
default void processInvalidCommandUpdate(Update update) {
|
||||
processNonCommandUpdate(update);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this function in your bot implementation to filter messages with commands
|
||||
* <p>
|
||||
* For example, if you want to prevent commands execution incoming from group chat:
|
||||
* #
|
||||
* # return !message.getChat().isGroupChat();
|
||||
* #
|
||||
*
|
||||
* @param message Received message
|
||||
* @return true if the message must be ignored by the command bot and treated as a non command message,
|
||||
* false otherwise
|
||||
* @note Default implementation doesn't filter anything
|
||||
*/
|
||||
default boolean filter(Message message) {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -19,7 +19,7 @@ import java.util.function.BiConsumer;
|
||||
*
|
||||
* @author Timo Schulz (Mit0x2)
|
||||
*/
|
||||
public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingBot implements ICommandRegistry {
|
||||
public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingBot implements CommandBot, ICommandRegistry {
|
||||
private final CommandRegistry commandRegistry;
|
||||
|
||||
/**
|
||||
@ -70,34 +70,6 @@ public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingB
|
||||
processNonCommandUpdate(update);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when user sends a not registered command. By default it will just call processNonCommandUpdate(),
|
||||
* override it in your implementation if you want your bot to do other things, such as sending an error message
|
||||
*
|
||||
* @param update Received update from Telegram
|
||||
*/
|
||||
protected void processInvalidCommandUpdate(Update update) {
|
||||
processNonCommandUpdate(update);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Override this function in your bot implementation to filter messages with commands
|
||||
* <p>
|
||||
* For example, if you want to prevent commands execution incoming from group chat:
|
||||
* #
|
||||
* # return !message.getChat().isGroupChat();
|
||||
* #
|
||||
*
|
||||
* @param message Received message
|
||||
* @return true if the message must be ignored by the command bot and treated as a non command message,
|
||||
* false otherwise
|
||||
* @note Default implementation doesn't filter anything
|
||||
*/
|
||||
protected boolean filter(Message message) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean register(IBotCommand botCommand) {
|
||||
return commandRegistry.register(botCommand);
|
||||
@ -138,13 +110,4 @@ public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingB
|
||||
*/
|
||||
@Override
|
||||
public abstract String getBotUsername();
|
||||
|
||||
/**
|
||||
* Process all updates, that are not commands.
|
||||
*
|
||||
* @param update the update
|
||||
* @warning Commands that have valid syntax but are not registered on this bot,
|
||||
* won't be forwarded to this method <b>if a default action is present</b>.
|
||||
*/
|
||||
public abstract void processNonCommandUpdate(Update update);
|
||||
}
|
||||
|
@ -0,0 +1,109 @@
|
||||
package org.telegram.telegrambots.extensions.bots.commandbot;
|
||||
|
||||
|
||||
import org.telegram.telegrambots.bots.DefaultBotOptions;
|
||||
import org.telegram.telegrambots.bots.TelegramWebhookBot;
|
||||
import org.telegram.telegrambots.extensions.bots.commandbot.commands.CommandRegistry;
|
||||
import org.telegram.telegrambots.extensions.bots.commandbot.commands.IBotCommand;
|
||||
import org.telegram.telegrambots.extensions.bots.commandbot.commands.ICommandRegistry;
|
||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.Message;
|
||||
import org.telegram.telegrambots.meta.api.objects.Update;
|
||||
import org.telegram.telegrambots.meta.bots.AbsSender;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
/**
|
||||
* This class adds command functionality to the TelegramWebhookBot
|
||||
*
|
||||
* @author Andrey Korsakov (loolzaaa)
|
||||
*/
|
||||
public abstract class TelegramWebhookCommandBot extends TelegramWebhookBot implements CommandBot, ICommandRegistry {
|
||||
private final CommandRegistry commandRegistry;
|
||||
|
||||
/**
|
||||
* Creates a TelegramWebhookCommandBot using default options
|
||||
* Use ICommandRegistry's methods on this bot to register commands
|
||||
*
|
||||
*/
|
||||
public TelegramWebhookCommandBot() {
|
||||
this(new DefaultBotOptions());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a TelegramWebhookCommandBot with custom options and allowing commands with
|
||||
* usernames
|
||||
* Use ICommandRegistry's methods on this bot to register commands
|
||||
*
|
||||
* @param options Bot options
|
||||
*/
|
||||
public TelegramWebhookCommandBot(DefaultBotOptions options) {
|
||||
this(options, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a TelegramWebhookCommandBot
|
||||
* Use ICommandRegistry's methods on this bot to register commands
|
||||
*
|
||||
* @param options Bot options
|
||||
* @param allowCommandsWithUsername true to allow commands with parameters (default),
|
||||
* false otherwise
|
||||
*/
|
||||
public TelegramWebhookCommandBot(DefaultBotOptions options, boolean allowCommandsWithUsername) {
|
||||
super(options);
|
||||
this.commandRegistry = new CommandRegistry(allowCommandsWithUsername, this::getBotUsername);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BotApiMethod<?> onWebhookUpdateReceived(Update update) {
|
||||
if (update.hasMessage()) {
|
||||
Message message = update.getMessage();
|
||||
if (message.isCommand() && !filter(message)) {
|
||||
if (!commandRegistry.executeCommand(this, message)) {
|
||||
//we have received a not registered command, handle it as invalid
|
||||
processInvalidCommandUpdate(update);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
processNonCommandUpdate(update);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean register(IBotCommand botCommand) {
|
||||
return commandRegistry.register(botCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Map<IBotCommand, Boolean> registerAll(IBotCommand... botCommands) {
|
||||
return commandRegistry.registerAll(botCommands);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean deregister(IBotCommand botCommand) {
|
||||
return commandRegistry.deregister(botCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Map<IBotCommand, Boolean> deregisterAll(IBotCommand... botCommands) {
|
||||
return commandRegistry.deregisterAll(botCommands);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Collection<IBotCommand> getRegisteredCommands() {
|
||||
return commandRegistry.getRegisteredCommands();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerDefaultAction(BiConsumer<AbsSender, Message> defaultConsumer) {
|
||||
commandRegistry.registerDefaultAction(defaultConsumer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final IBotCommand getRegisteredCommand(String commandIdentifier) {
|
||||
return commandRegistry.getRegisteredCommand(commandIdentifier);
|
||||
}
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
package org.telegram.telegrambots.extensions.bots.commandbot.commands.helpCommand;
|
||||
|
||||
import org.telegram.telegrambots.extensions.bots.commandbot.commands.IBotCommand;
|
||||
import org.telegram.telegrambots.extensions.bots.commandbot.commands.ICommandRegistry;
|
||||
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
|
||||
import org.telegram.telegrambots.meta.api.objects.Chat;
|
||||
import org.telegram.telegrambots.meta.api.objects.User;
|
||||
import org.telegram.telegrambots.meta.bots.AbsSender;
|
||||
import org.telegram.telegrambots.extensions.bots.commandbot.commands.IBotCommand;
|
||||
import org.telegram.telegrambots.extensions.bots.commandbot.commands.ICommandRegistry;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
|
||||
|
||||
import java.util.Collection;
|
||||
@ -98,14 +98,14 @@ public class HelpCommand extends ManCommand {
|
||||
IBotCommand command = registry.getRegisteredCommand(arguments[0]);
|
||||
String reply = getManText(command);
|
||||
try {
|
||||
absSender.execute(SendMessage.builder().chatId(chat.getId().toString()).text(reply).parseMode("HTML").build());
|
||||
absSender.execute(SendMessage.builder().chatId(chat.getId()).text(reply).parseMode("HTML").build());
|
||||
} catch (TelegramApiException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
String reply = getHelpText(registry);
|
||||
try {
|
||||
absSender.execute(SendMessage.builder().chatId(chat.getId().toString()).text(reply).parseMode("HTML").build());
|
||||
absSender.execute(SendMessage.builder().chatId(chat.getId()).text(reply).parseMode("HTML").build());
|
||||
} catch (TelegramApiException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>Bots</artifactId>
|
||||
<version>6.0.1</version>
|
||||
<version>6.1.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>telegrambots-meta</artifactId>
|
||||
@ -127,7 +127,7 @@
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>3.2.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>clean-project</id>
|
||||
@ -140,7 +140,7 @@
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<version>3.3.0</version>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
@ -159,7 +159,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>3.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
@ -171,7 +171,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>3.4.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
@ -186,7 +186,7 @@
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<version>0.8.4</version>
|
||||
<version>0.8.8</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
@ -205,7 +205,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-enforcer-plugin</artifactId>
|
||||
<version>3.0.0-M3</version>
|
||||
<version>3.0.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>enforce</id>
|
||||
@ -223,7 +223,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<version>3.3.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy</id>
|
||||
@ -234,7 +234,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.0.0-M5</version>
|
||||
<version>3.0.0-M6</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<pluginManagement>
|
||||
@ -242,7 +242,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<version>3.10.1</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
|
@ -30,5 +30,7 @@ public interface Validable {
|
||||
* Validates that mandatory fields are filled and optional objects
|
||||
* @throws TelegramApiValidationException If any mandatory field is empty
|
||||
*/
|
||||
void validate() throws TelegramApiValidationException;
|
||||
default void validate() throws TelegramApiValidationException {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -11,11 +10,7 @@ import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
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 org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
@ -36,7 +31,7 @@ import java.io.IOException;
|
||||
@RequiredArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class AnswerCallbackQuery extends BotApiMethod<Boolean> {
|
||||
public class AnswerCallbackQuery extends BotApiMethodBoolean {
|
||||
public static final String PATH = "answercallbackquery";
|
||||
|
||||
private static final String CALLBACKQUERYID_FIELD = "callback_query_id";
|
||||
@ -73,26 +68,4 @@ public class AnswerCallbackQuery extends BotApiMethod<Boolean> {
|
||||
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 answering callback query", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (callbackQueryId == null) {
|
||||
throw new TelegramApiValidationException("CallbackQueryId can't be null", this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -12,12 +11,10 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.Singular;
|
||||
import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
|
||||
import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ -34,7 +31,7 @@ import java.util.regex.Pattern;
|
||||
@RequiredArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class AnswerInlineQuery extends BotApiMethod<Boolean> {
|
||||
public class AnswerInlineQuery extends BotApiMethodBoolean {
|
||||
public static final String PATH = "answerInlineQuery";
|
||||
|
||||
private static final String INLINEQUERYID_FIELD = "inline_query_id";
|
||||
@ -94,19 +91,4 @@ public class AnswerInlineQuery extends BotApiMethod<Boolean> {
|
||||
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 answering inline query", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -11,12 +10,9 @@ import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
@ -36,7 +32,7 @@ import java.io.IOException;
|
||||
@RequiredArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class AnswerPreCheckoutQuery extends BotApiMethod<Boolean> {
|
||||
public class AnswerPreCheckoutQuery extends BotApiMethodBoolean {
|
||||
public static final String PATH = "answerPreCheckoutQuery";
|
||||
|
||||
private static final String PRE_CHECKOUT_QUERY_ID_FIELD = "pre_checkout_query_id";
|
||||
@ -54,12 +50,9 @@ public class AnswerPreCheckoutQuery extends BotApiMethod<Boolean> {
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (preCheckoutQueryId == null || preCheckoutQueryId.isEmpty()) {
|
||||
if (preCheckoutQueryId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("PreCheckoutQueryId can't be empty", this);
|
||||
}
|
||||
if (ok == null) {
|
||||
throw new TelegramApiValidationException("Ok can't be null", this);
|
||||
}
|
||||
if (!ok) {
|
||||
if (errorMessage == null || errorMessage.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ErrorMessage can't be empty if not ok", this);
|
||||
@ -71,19 +64,4 @@ public class AnswerPreCheckoutQuery extends BotApiMethod<Boolean> {
|
||||
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 answering pre-checkout query", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -11,12 +10,10 @@ import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
|
||||
import org.telegram.telegrambots.meta.api.objects.payments.ShippingOption;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -37,7 +34,7 @@ import java.util.List;
|
||||
@RequiredArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class AnswerShippingQuery extends BotApiMethod<Boolean> {
|
||||
public class AnswerShippingQuery extends BotApiMethodBoolean {
|
||||
public static final String PATH = "answerShippingQuery";
|
||||
|
||||
private static final String SHIPPING_QUERY_ID_FIELD = "shipping_query_id";
|
||||
@ -82,19 +79,4 @@ public class AnswerShippingQuery extends BotApiMethod<Boolean> {
|
||||
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 answering shipping query", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
@ -12,14 +11,13 @@ import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.objects.MessageEntity;
|
||||
import org.telegram.telegrambots.meta.api.objects.MessageId;
|
||||
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -89,6 +87,16 @@ public class CopyMessage extends BotApiMethod<MessageId> {
|
||||
@JsonProperty(PROTECTCONTENT_FIELD)
|
||||
private Boolean protectContent; ///< Optional. Protects the contents of sent messages from forwarding and saving
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@Tolerate
|
||||
public void setFromChatId(@NonNull Long fromChatId) {
|
||||
this.fromChatId = fromChatId.toString();
|
||||
}
|
||||
|
||||
public void enableNotification() {
|
||||
this.disableNotification = null;
|
||||
}
|
||||
@ -128,30 +136,14 @@ public class CopyMessage extends BotApiMethod<MessageId> {
|
||||
|
||||
@Override
|
||||
public MessageId deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<MessageId> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<MessageId>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error copying message", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
return deserializeResponse(answer, MessageId.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
|
||||
}
|
||||
if (fromChatId == null) {
|
||||
throw new TelegramApiValidationException("FromChatId parameter can't be empty", this);
|
||||
}
|
||||
if (messageId == null) {
|
||||
throw new TelegramApiValidationException("MessageId parameter can't be empty", this);
|
||||
}
|
||||
|
||||
if (parseMode != null && (captionEntities != null && !captionEntities.isEmpty()) ) {
|
||||
throw new TelegramApiValidationException("Parse mode can't be enabled if Entities are provided", this);
|
||||
@ -160,4 +152,19 @@ public class CopyMessage extends BotApiMethod<MessageId> {
|
||||
replyMarkup.validate();
|
||||
}
|
||||
}
|
||||
|
||||
public static class CopyMessageBuilder {
|
||||
|
||||
@Tolerate
|
||||
public CopyMessageBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Tolerate
|
||||
public CopyMessageBuilder fromChatId(@NonNull Long fromChatId) {
|
||||
this.fromChatId = fromChatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -11,13 +10,10 @@ import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.api.objects.Message;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodMessage;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
@ -34,7 +30,7 @@ import java.io.IOException;
|
||||
@RequiredArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class ForwardMessage extends BotApiMethod<Message> {
|
||||
public class ForwardMessage extends BotApiMethodMessage {
|
||||
public static final String PATH = "forwardmessage";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
@ -63,17 +59,24 @@ public class ForwardMessage extends BotApiMethod<Message> {
|
||||
@JsonProperty(PROTECTCONTENT_FIELD)
|
||||
private Boolean protectContent; ///< Optional. Protects the contents of sent messages from forwarding and saving
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@Tolerate
|
||||
public void setFromChatId(@NonNull Long fromChatId) {
|
||||
this.fromChatId = fromChatId.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId can't be empty", this);
|
||||
}
|
||||
if (fromChatId == null || fromChatId.isEmpty()) {
|
||||
if (fromChatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("FromChatId can't be empty", this);
|
||||
}
|
||||
if (messageId == null) {
|
||||
throw new TelegramApiValidationException("MessageId can't be empty", this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -81,18 +84,18 @@ public class ForwardMessage extends BotApiMethod<Message> {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<Message> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<Message>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error forwarding message", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
public static class ForwardMessageBuilder {
|
||||
|
||||
@Tolerate
|
||||
public ForwardMessageBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Tolerate
|
||||
public ForwardMessageBuilder fromChatId(@NonNull Long fromChatId) {
|
||||
this.fromChatId = fromChatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -10,12 +9,8 @@ import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.api.objects.File;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
@ -44,13 +39,6 @@ public class GetFile extends BotApiMethod<File> {
|
||||
@NonNull
|
||||
private String fileId; ///< File identifier to get info about
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (fileId == null) {
|
||||
throw new TelegramApiValidationException("FileId can't be empty", this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
@ -58,16 +46,6 @@ public class GetFile extends BotApiMethod<File> {
|
||||
|
||||
@Override
|
||||
public File deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<File> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<File>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error getting file", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
return deserializeResponse(answer, File.class);
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,13 @@
|
||||
package org.telegram.telegrambots.meta.api.methods;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.api.objects.User;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
@ -36,21 +31,6 @@ public class GetMe extends BotApiMethod<User> {
|
||||
|
||||
@Override
|
||||
public User deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<User> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<User>>() {
|
||||
});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error getting me", result);
|
||||
}
|
||||
} catch (IOException e2) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e2);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
return deserializeResponse(answer, User.class);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -13,11 +11,7 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.api.objects.UserProfilePhotos;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
@ -60,23 +54,6 @@ public class GetUserProfilePhotos extends BotApiMethod<UserProfilePhotos> {
|
||||
|
||||
@Override
|
||||
public UserProfilePhotos deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<UserProfilePhotos> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<UserProfilePhotos>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error getting user profile photos", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (userId == null) {
|
||||
throw new TelegramApiValidationException("UserId parameter can't be empty", this);
|
||||
}
|
||||
return deserializeResponse(answer, UserProfilePhotos.class);
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,16 @@
|
||||
package org.telegram.telegrambots.meta.api.methods;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.databind.JavaType;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import com.fasterxml.jackson.databind.type.CollectionType;
|
||||
import org.telegram.telegrambots.meta.api.interfaces.Validable;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
@ -23,4 +27,33 @@ public abstract class PartialBotApiMethod<T extends Serializable> implements Val
|
||||
* @return Answer for the method
|
||||
*/
|
||||
public abstract T deserializeResponse(String answer) throws TelegramApiRequestException;
|
||||
|
||||
public T deserializeResponse(String answer, Class<T> returnClass) throws TelegramApiRequestException {
|
||||
JavaType type = OBJECT_MAPPER.getTypeFactory().constructType(returnClass);
|
||||
return deserializeResponseInternal(answer, type);
|
||||
}
|
||||
|
||||
public <K extends Serializable> T deserializeResponseArray(String answer, Class<K> returnClass) throws TelegramApiRequestException {
|
||||
CollectionType collectionType = OBJECT_MAPPER.getTypeFactory().constructCollectionType(ArrayList.class, returnClass);
|
||||
return deserializeResponseInternal(answer, collectionType);
|
||||
}
|
||||
|
||||
protected <K extends Serializable> T deserializeResponseSerializable(String answer, Class<K> returnClass) throws TelegramApiRequestException {
|
||||
JavaType type = OBJECT_MAPPER.getTypeFactory().constructType(returnClass);
|
||||
return deserializeResponseInternal(answer, type);
|
||||
}
|
||||
|
||||
private T deserializeResponseInternal(String answer, JavaType type) throws TelegramApiRequestException {
|
||||
try {
|
||||
JavaType responseType = OBJECT_MAPPER.getTypeFactory().constructParametricType(ApiResponse.class, type);
|
||||
ApiResponse<T> result = OBJECT_MAPPER.readValue(answer, responseType);
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException(String.format("Error executing %s query", this.getClass().getName()), result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -11,12 +10,10 @@ import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import lombok.Singular;
|
||||
import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
|
||||
import org.telegram.telegrambots.meta.api.objects.passport.dataerror.PassportElementError;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -33,7 +30,7 @@ import java.util.List;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class SetPassportDataErrors extends BotApiMethod<Boolean> {
|
||||
public class SetPassportDataErrors extends BotApiMethodBoolean {
|
||||
public static final String PATH = "setPassportDataErrors";
|
||||
|
||||
private static final String USERID_FIELD = "user_id";
|
||||
@ -52,27 +49,9 @@ public class SetPassportDataErrors extends BotApiMethod<Boolean> {
|
||||
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 passport data errors", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (userId == null) {
|
||||
throw new TelegramApiValidationException("User ID can't be empty", this);
|
||||
}
|
||||
if (errors == null || errors.isEmpty()) {
|
||||
if (errors.isEmpty()) {
|
||||
throw new TelegramApiValidationException("Errors can't be empty", this);
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodSerializable;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.api.objects.Message;
|
||||
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
|
||||
@ -32,7 +34,7 @@ import java.io.Serializable;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class StopMessageLiveLocation extends BotApiMethod<Serializable> {
|
||||
public class StopMessageLiveLocation extends BotApiMethodSerializable {
|
||||
public static final String PATH = "stopMessageLiveLocation";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
@ -59,6 +61,11 @@ public class StopMessageLiveLocation extends BotApiMethod<Serializable> {
|
||||
@JsonProperty(REPLYMARKUP_FIELD)
|
||||
private InlineKeyboardMarkup replyMarkup; ///< Optional. A JSON-serialized object for an inline keyboard.
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(Long chatId) {
|
||||
this.chatId = chatId == null ? null : chatId.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
@ -111,4 +118,13 @@ public class StopMessageLiveLocation extends BotApiMethod<Serializable> {
|
||||
replyMarkup.validate();
|
||||
}
|
||||
}
|
||||
|
||||
public static class StopMessageLiveLocationBuilder {
|
||||
|
||||
@Tolerate
|
||||
public StopMessageLiveLocationBuilder chatId(Long chatId) {
|
||||
this.chatId = chatId == null ? null : chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,16 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.adminrights;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
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.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
|
||||
@ -46,21 +47,6 @@ public class GetMyDefaultAdministratorRights extends BotApiMethod<ChatAdministra
|
||||
|
||||
@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 {
|
||||
|
||||
return deserializeResponse(answer, ChatAdministratorRights.class);
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,15 @@
|
||||
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 lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
|
||||
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
|
||||
@ -26,7 +25,7 @@ import java.io.IOException;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class SetMyDefaultAdministratorRights extends BotApiMethod<Boolean> {
|
||||
public class SetMyDefaultAdministratorRights extends BotApiMethodBoolean {
|
||||
public static final String PATH = "setMyDefaultAdministratorRights";
|
||||
|
||||
private static final String RIGHTS_FIELD = "rights";
|
||||
@ -51,24 +50,4 @@ public class SetMyDefaultAdministratorRights extends BotApiMethod<Boolean> {
|
||||
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 {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.botapimethods;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
*
|
||||
* A method of Telegram Bots Api that is fully supported in json format
|
||||
*/
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public abstract class BotApiMethodBoolean extends BotApiMethod<Boolean> {
|
||||
@Override
|
||||
public Boolean deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
return deserializeResponse(answer, Boolean.class);
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.botapimethods;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.Message;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
*
|
||||
* A method of Telegram Bots Api that is fully supported in json format
|
||||
*/
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public abstract class BotApiMethodMessage extends BotApiMethod<Message> {
|
||||
@Override
|
||||
public Message deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
return deserializeResponse(answer, Message.class);
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.botapimethods;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.Message;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
*
|
||||
* A method of Telegram Bots Api that is fully supported in json format
|
||||
*/
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public abstract class BotApiMethodSerializable extends BotApiMethod<Serializable> {
|
||||
public Serializable deserializeResponseMessageOrBoolean(String answer) throws TelegramApiRequestException {
|
||||
return deserializeResponseFromPossibilities(answer, Arrays.asList(Message.class, Boolean.class));
|
||||
}
|
||||
|
||||
public Serializable deserializeResponseFromPossibilities(String answer, List<Class<? extends Serializable>> possibleValues) throws TelegramApiRequestException {
|
||||
Throwable lastException = null;
|
||||
for (Class<? extends Serializable> possibleValue : possibleValues) {
|
||||
try {
|
||||
return deserializeResponseSerializable(answer, possibleValue);
|
||||
} catch (TelegramApiRequestException e) {
|
||||
if (e.getCause() instanceof IOException) {
|
||||
lastException = e.getCause();
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", lastException);
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.commands;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -9,14 +8,10 @@ import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
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.api.methods.botapimethods.BotApiMethodBoolean;
|
||||
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 5.3
|
||||
@ -32,7 +27,7 @@ import java.io.IOException;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class DeleteMyCommands extends BotApiMethod<Boolean> {
|
||||
public class DeleteMyCommands extends BotApiMethodBoolean {
|
||||
public static final String PATH = "deleteMyCommands";
|
||||
|
||||
private static final String SCOPE_FIELD = "scope";
|
||||
@ -58,21 +53,6 @@ public class DeleteMyCommands extends BotApiMethod<Boolean> {
|
||||
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 deleting commands", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (scope != null) {
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.commands;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -10,13 +9,11 @@ import lombok.NoArgsConstructor;
|
||||
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.api.objects.commands.BotCommand;
|
||||
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;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
@ -61,17 +58,7 @@ public class GetMyCommands extends BotApiMethod<ArrayList<BotCommand>> {
|
||||
|
||||
@Override
|
||||
public ArrayList<BotCommand> deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<ArrayList<BotCommand>> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<ArrayList<BotCommand>>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error sending commands", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
return deserializeResponseArray(answer, BotCommand.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.commands;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -11,14 +10,11 @@ import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import lombok.Singular;
|
||||
import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
|
||||
import org.telegram.telegrambots.meta.api.objects.commands.BotCommand;
|
||||
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;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -35,7 +31,7 @@ import java.util.List;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class SetMyCommands extends BotApiMethod<Boolean> {
|
||||
public class SetMyCommands extends BotApiMethodBoolean {
|
||||
public static final String PATH = "setMyCommands";
|
||||
|
||||
private static final String COMMANDS_FIELD = "commands";
|
||||
@ -70,27 +66,12 @@ public class SetMyCommands extends BotApiMethod<Boolean> {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<Boolean> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<Boolean>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error sending commands", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (languageCode != null && languageCode.isEmpty()) {
|
||||
throw new TelegramApiValidationException("LanguageCode parameter can't be empty string", this);
|
||||
}
|
||||
if (commands == null || commands.isEmpty()) {
|
||||
if (commands.isEmpty()) {
|
||||
throw new TelegramApiValidationException("Commands parameter can't be empty", this);
|
||||
}
|
||||
if (commands.size() > 100) {
|
||||
|
@ -17,8 +17,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.games;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -28,13 +26,12 @@ import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.games.GameHighScore;
|
||||
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.util.ArrayList;
|
||||
|
||||
/**
|
||||
@ -76,6 +73,11 @@ public class GetGameHighScores extends BotApiMethod<ArrayList<GameHighScore>> {
|
||||
@NonNull
|
||||
private Long userId; ///<Target user id
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(Long chatId) {
|
||||
this.chatId = chatId == null ? null : chatId.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
@ -83,24 +85,11 @@ public class GetGameHighScores extends BotApiMethod<ArrayList<GameHighScore>> {
|
||||
|
||||
@Override
|
||||
public ArrayList<GameHighScore> deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<ArrayList<GameHighScore>> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<ArrayList<GameHighScore>>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error getting game high scores", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
return deserializeResponseArray(answer, GameHighScore.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (userId == null) {
|
||||
throw new TelegramApiValidationException("UserId parameter can't be empty", this);
|
||||
}
|
||||
if (inlineMessageId == null) {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId parameter can't be empty if inlineMessageId is not present", this);
|
||||
@ -117,4 +106,13 @@ public class GetGameHighScores extends BotApiMethod<ArrayList<GameHighScore>> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class GetGameHighScoresBuilder {
|
||||
|
||||
@Tolerate
|
||||
public GetGameHighScoresBuilder chatId(Long chatId) {
|
||||
this.chatId = chatId == null ? null : chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,8 +18,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.games;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -29,13 +27,11 @@ 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.Message;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodSerializable;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
@ -56,7 +52,7 @@ import java.io.Serializable;
|
||||
@RequiredArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class SetGameScore extends BotApiMethod<Serializable> {
|
||||
public class SetGameScore extends BotApiMethodSerializable {
|
||||
public static final String PATH = "setGameScore";
|
||||
|
||||
private static final String USER_ID_FIELD = "user_id";
|
||||
@ -84,6 +80,11 @@ public class SetGameScore extends BotApiMethod<Serializable> {
|
||||
@JsonProperty(FORCE_FIELD)
|
||||
private Boolean force; ///< Optional. Pass True, if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(Long chatId) {
|
||||
this.chatId = chatId == null ? null : chatId.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
@ -91,38 +92,13 @@ public class SetGameScore extends BotApiMethod<Serializable> {
|
||||
|
||||
@Override
|
||||
public Serializable 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 game score", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
try {
|
||||
ApiResponse<Message> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<Message>>() {
|
||||
});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error setting game score", result);
|
||||
}
|
||||
} catch (IOException e2) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e2);
|
||||
}
|
||||
}
|
||||
return deserializeResponseMessageOrBoolean(answer);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (userId == null) {
|
||||
throw new TelegramApiValidationException("UserId parameter can't be empty", this);
|
||||
}
|
||||
if (score == null) {
|
||||
throw new TelegramApiValidationException("Score parameter can't be empty", this);
|
||||
}
|
||||
if (inlineMessageId == null) {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId parameter can't be empty if inlineMessageId is not present", this);
|
||||
@ -139,4 +115,13 @@ public class SetGameScore extends BotApiMethod<Serializable> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class SetGameScoreBuilder {
|
||||
|
||||
@Tolerate
|
||||
public SetGameScoreBuilder chatId(Long chatId) {
|
||||
this.chatId = chatId == null ? null : chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,18 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.groupadministration;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.*;
|
||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.4
|
||||
@ -24,7 +27,7 @@ import java.io.IOException;
|
||||
@NoArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
@Builder
|
||||
public class ApproveChatJoinRequest extends BotApiMethod<Boolean> {
|
||||
public class ApproveChatJoinRequest extends BotApiMethodBoolean {
|
||||
public static final String PATH = "approveChatJoinRequest";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
@ -37,24 +40,14 @@ public class ApproveChatJoinRequest extends BotApiMethod<Boolean> {
|
||||
@NonNull
|
||||
private Long userId; ///< Required. Unique identifier of the target user
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@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 approving chat join request", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -66,4 +59,13 @@ public class ApproveChatJoinRequest extends BotApiMethod<Boolean> {
|
||||
throw new TelegramApiValidationException("UserId can't be null or 0", this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ApproveChatJoinRequestBuilder {
|
||||
|
||||
@Tolerate
|
||||
public ApproveChatJoinRequestBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ 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;
|
||||
@ -12,12 +11,10 @@ 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 lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.ZonedDateTime;
|
||||
@ -41,7 +38,7 @@ import java.time.ZonedDateTime;
|
||||
@RequiredArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class BanChatMember extends BotApiMethod<Boolean> {
|
||||
public class BanChatMember extends BotApiMethodBoolean {
|
||||
public static final String PATH = "banChatMember";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
@ -69,6 +66,10 @@ public class BanChatMember extends BotApiMethod<Boolean> {
|
||||
@JsonProperty(REVOKEMESSAGES_FIELD)
|
||||
private Boolean revokeMessages;
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public void setUntilDateInstant(Instant instant) {
|
||||
@ -90,28 +91,23 @@ public class BanChatMember extends BotApiMethod<Boolean> {
|
||||
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()) {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId can't be empty", this);
|
||||
}
|
||||
if (userId == null || userId == 0) {
|
||||
if (userId == 0) {
|
||||
throw new TelegramApiValidationException("UserId can't be null or 0", this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class BanChatMemberBuilder {
|
||||
|
||||
@Tolerate
|
||||
public BanChatMemberBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -2,14 +2,19 @@ package org.telegram.telegrambots.meta.api.methods.groupadministration;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.*;
|
||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import 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 lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.ZonedDateTime;
|
||||
@ -31,7 +36,7 @@ import java.time.ZonedDateTime;
|
||||
@RequiredArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class BanChatSenderChat extends BotApiMethod<Boolean> {
|
||||
public class BanChatSenderChat extends BotApiMethodBoolean {
|
||||
public static final String PATH = "banChatSenderChat";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
@ -51,6 +56,11 @@ public class BanChatSenderChat extends BotApiMethod<Boolean> {
|
||||
@JsonProperty(UNTILDATE_FIELD)
|
||||
private Integer untilDate;
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public void setUntilDateInstant(Instant instant) {
|
||||
setUntilDate((int) instant.getEpochSecond());
|
||||
@ -71,21 +81,6 @@ public class BanChatSenderChat extends BotApiMethod<Boolean> {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<Boolean> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<Boolean>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error banning chat sender", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId.isEmpty()) {
|
||||
@ -95,4 +90,13 @@ public class BanChatSenderChat extends BotApiMethod<Boolean> {
|
||||
throw new TelegramApiValidationException("SenderChatId can't be null or 0", this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class BanChatSenderChatBuilder {
|
||||
|
||||
@Tolerate
|
||||
public BanChatSenderChatBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.groupadministration;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -11,14 +10,12 @@ import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.api.objects.ChatInviteLink;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.1
|
||||
@ -69,6 +66,10 @@ public class CreateChatInviteLink extends BotApiMethod<ChatInviteLink> {
|
||||
@JsonProperty(CREATESJOINREQUEST_FIELD)
|
||||
private Boolean createsJoinRequest;
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
@ -77,17 +78,7 @@ public class CreateChatInviteLink extends BotApiMethod<ChatInviteLink> {
|
||||
|
||||
@Override
|
||||
public ChatInviteLink deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<ChatInviteLink> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<ChatInviteLink>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error creating invite link", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
return deserializeResponse(answer, ChatInviteLink.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -105,4 +96,13 @@ public class CreateChatInviteLink extends BotApiMethod<ChatInviteLink> {
|
||||
throw new TelegramApiValidationException("MemberLimit must be between 1 and 99999", this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class CreateChatInviteLinkBuilder {
|
||||
|
||||
@Tolerate
|
||||
public CreateChatInviteLinkBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,18 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.groupadministration;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.*;
|
||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.4
|
||||
@ -24,7 +27,7 @@ import java.io.IOException;
|
||||
@NoArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
@Builder
|
||||
public class DeclineChatJoinRequest extends BotApiMethod<Boolean> {
|
||||
public class DeclineChatJoinRequest extends BotApiMethodBoolean {
|
||||
public static final String PATH = "declineChatJoinRequest";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
@ -37,24 +40,14 @@ public class DeclineChatJoinRequest extends BotApiMethod<Boolean> {
|
||||
@NonNull
|
||||
private Long userId; ///< Required. Unique identifier of the target user
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@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 declining chat join request", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -66,4 +59,13 @@ public class DeclineChatJoinRequest extends BotApiMethod<Boolean> {
|
||||
throw new TelegramApiValidationException("UserId can't be null or 0", this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class DeclineChatJoinRequestBuilder {
|
||||
|
||||
@Tolerate
|
||||
public DeclineChatJoinRequestBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.groupadministration;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -10,13 +9,10 @@ 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.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
@ -33,7 +29,7 @@ import java.io.IOException;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class DeleteChatPhoto extends BotApiMethod<Boolean> {
|
||||
public class DeleteChatPhoto extends BotApiMethodBoolean {
|
||||
public static final String PATH = "deleteChatPhoto";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
@ -42,30 +38,29 @@ public class DeleteChatPhoto extends BotApiMethod<Boolean> {
|
||||
@NonNull
|
||||
private String chatId; ///< Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@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 deleting chat photo", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId can't be null", this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class DeleteChatPhotoBuilder {
|
||||
|
||||
@Tolerate
|
||||
public DeleteChatPhotoBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.groupadministration;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -10,13 +9,10 @@ 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.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 3.4
|
||||
@ -32,7 +28,7 @@ import java.io.IOException;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class DeleteChatStickerSet extends BotApiMethod<Boolean> {
|
||||
public class DeleteChatStickerSet extends BotApiMethodBoolean {
|
||||
public static final String PATH = "deleteChatStickerSet";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
@ -41,30 +37,29 @@ public class DeleteChatStickerSet extends BotApiMethod<Boolean> {
|
||||
@NonNull
|
||||
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@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 deleting chat sticker set", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId can't be empty", this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class DeleteChatStickerSetBuilder {
|
||||
|
||||
@Tolerate
|
||||
public DeleteChatStickerSetBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.groupadministration;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.google.common.base.Strings;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
@ -12,14 +11,12 @@ import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.api.objects.ChatInviteLink;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.1
|
||||
@ -74,6 +71,10 @@ public class EditChatInviteLink extends BotApiMethod<ChatInviteLink> {
|
||||
@JsonProperty(CREATESJOINREQUEST_FIELD)
|
||||
private Boolean createsJoinRequest;
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
@ -82,17 +83,7 @@ public class EditChatInviteLink extends BotApiMethod<ChatInviteLink> {
|
||||
|
||||
@Override
|
||||
public ChatInviteLink deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<ChatInviteLink> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<ChatInviteLink>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error creating invite link", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
return deserializeResponse(answer, ChatInviteLink.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -113,4 +104,13 @@ public class EditChatInviteLink extends BotApiMethod<ChatInviteLink> {
|
||||
throw new TelegramApiValidationException("MemberLimit must be between 1 and 99999", this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class EditChatInviteLinkBuilder {
|
||||
|
||||
@Tolerate
|
||||
public EditChatInviteLinkBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.groupadministration;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -10,13 +9,11 @@ import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 3.1
|
||||
@ -47,6 +44,11 @@ public class ExportChatInviteLink extends BotApiMethod<String> {
|
||||
@NonNull
|
||||
private String chatId; ///< Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
@ -54,23 +56,22 @@ public class ExportChatInviteLink extends BotApiMethod<String> {
|
||||
|
||||
@Override
|
||||
public String deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<String> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<String>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error exporting invite link", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
return deserializeResponse(answer, String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId can't be empty", this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ExportChatInviteLinkBuilder {
|
||||
|
||||
@Tolerate
|
||||
public ExportChatInviteLinkBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.groupadministration;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -10,14 +9,12 @@ import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.api.objects.Chat;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
@ -44,25 +41,29 @@ public class GetChat extends BotApiMethod<Chat> {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Chat deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<Chat> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<Chat>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error getting chat", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
return deserializeResponse(answer, Chat.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId can't be empty", this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class GetChatBuilder {
|
||||
|
||||
@Tolerate
|
||||
public GetChatBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.groupadministration;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -10,13 +9,12 @@ import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.api.objects.chatmember.ChatMember;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
@ -44,6 +42,11 @@ public class GetChatAdministrators extends BotApiMethod<ArrayList<ChatMember>> {
|
||||
@NonNull
|
||||
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
@ -51,23 +54,22 @@ public class GetChatAdministrators extends BotApiMethod<ArrayList<ChatMember>> {
|
||||
|
||||
@Override
|
||||
public ArrayList<ChatMember> deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<ArrayList<ChatMember>> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<ArrayList<ChatMember>>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error getting chat administrators", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
return deserializeResponseArray(answer, ChatMember.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId can't be empty", this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class GetChatAdministratorsBuilder {
|
||||
|
||||
@Tolerate
|
||||
public GetChatAdministratorsBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.groupadministration;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -10,14 +9,12 @@ import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.api.objects.chatmember.ChatMember;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
@ -44,6 +41,11 @@ public class GetChatMember extends BotApiMethod<ChatMember> {
|
||||
@NonNull
|
||||
private Long userId; ///< Unique identifier of the target user
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
@ -51,26 +53,22 @@ public class GetChatMember extends BotApiMethod<ChatMember> {
|
||||
|
||||
@Override
|
||||
public ChatMember deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<ChatMember> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<ChatMember>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error getting chat member", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
return deserializeResponse(answer, ChatMember.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId can't be empty", this);
|
||||
}
|
||||
if (userId == null) {
|
||||
throw new TelegramApiValidationException("UserId can't be null", this);
|
||||
}
|
||||
|
||||
public static class GetChatMemberBuilder {
|
||||
|
||||
@Tolerate
|
||||
public GetChatMemberBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.groupadministration;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -10,13 +9,11 @@ import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.3
|
||||
@ -38,6 +35,11 @@ public class GetChatMemberCount extends BotApiMethod<Integer> {
|
||||
@NonNull
|
||||
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
@ -45,23 +47,22 @@ public class GetChatMemberCount extends BotApiMethod<Integer> {
|
||||
|
||||
@Override
|
||||
public Integer deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<Integer> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<Integer>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error getting chat members count", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
return deserializeResponse(answer, Integer.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId can't be empty", this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class GetChatMemberCountBuilder {
|
||||
|
||||
@Tolerate
|
||||
public GetChatMemberCountBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.groupadministration;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -10,13 +9,10 @@ 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.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
@ -29,7 +25,7 @@ import java.io.IOException;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class LeaveChat extends BotApiMethod<Boolean> {
|
||||
public class LeaveChat extends BotApiMethodBoolean {
|
||||
public static final String PATH = "leaveChat";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
@ -38,30 +34,29 @@ public class LeaveChat extends BotApiMethod<Boolean> {
|
||||
@NonNull
|
||||
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@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 leaving chat", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId can't be null", this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class LeaveChatBuilder {
|
||||
|
||||
@Tolerate
|
||||
public LeaveChatBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.groupadministration;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -11,13 +10,10 @@ 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 lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 3.1
|
||||
@ -34,7 +30,7 @@ import java.io.IOException;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class PromoteChatMember extends BotApiMethod<Boolean> {
|
||||
public class PromoteChatMember extends BotApiMethodBoolean {
|
||||
public static final String PATH = "promoteChatMember";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
@ -92,25 +88,14 @@ public class PromoteChatMember extends BotApiMethod<Boolean> {
|
||||
@JsonProperty(CANMANAGEVIDEOCHATS_FIELD)
|
||||
private Boolean canManageVideoChats;
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@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 promoting chat member", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -122,4 +107,14 @@ public class PromoteChatMember extends BotApiMethod<Boolean> {
|
||||
throw new TelegramApiValidationException("UserId can't be empty", this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class PromoteChatMemberBuilder {
|
||||
|
||||
@Tolerate
|
||||
public PromoteChatMemberBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ 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;
|
||||
@ -12,13 +11,11 @@ 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 lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
|
||||
import org.telegram.telegrambots.meta.api.objects.ChatPermissions;
|
||||
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;
|
||||
@ -40,7 +37,7 @@ import java.time.ZonedDateTime;
|
||||
@RequiredArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class RestrictChatMember extends BotApiMethod<Boolean> {
|
||||
public class RestrictChatMember extends BotApiMethodBoolean {
|
||||
public static final String PATH = "restrictchatmember";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
@ -70,6 +67,11 @@ public class RestrictChatMember extends BotApiMethod<Boolean> {
|
||||
@JsonProperty(UNTILDATE_FIELD)
|
||||
private Integer untilDate; ///< Optional. Date when restrictions will be lifted for the user, unix time. If user is restricted for more than 366 days or less than 30 seconds from the current time, they are considered to be banned forever
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public void setUntilDateInstant(Instant instant) {
|
||||
setUntilDate((int) instant.getEpochSecond());
|
||||
@ -91,30 +93,18 @@ public class RestrictChatMember extends BotApiMethod<Boolean> {
|
||||
}
|
||||
|
||||
@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 restricting chat member", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId can't be empty", this);
|
||||
}
|
||||
}
|
||||
|
||||
@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 empty", this);
|
||||
}
|
||||
if (permissions == null) {
|
||||
throw new TelegramApiValidationException("Permissions can't be empty", this);
|
||||
public static class RestrictChatMemberBuilder {
|
||||
|
||||
@Tolerate
|
||||
public RestrictChatMemberBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.groupadministration;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.google.common.base.Strings;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
@ -11,14 +10,12 @@ import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.api.objects.ChatInviteLink;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.1
|
||||
@ -51,6 +48,11 @@ public class RevokeChatInviteLink extends BotApiMethod<ChatInviteLink> {
|
||||
@NonNull
|
||||
private String inviteLink; ///< The invite link to revoke
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
@ -58,17 +60,7 @@ public class RevokeChatInviteLink extends BotApiMethod<ChatInviteLink> {
|
||||
|
||||
@Override
|
||||
public ChatInviteLink deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<ChatInviteLink> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<ChatInviteLink>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error creating invite link", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
return deserializeResponse(answer, ChatInviteLink.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -80,4 +72,13 @@ public class RevokeChatInviteLink extends BotApiMethod<ChatInviteLink> {
|
||||
throw new TelegramApiValidationException("InviteLink can't be empty", this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class RevokeChatInviteLinkBuilder {
|
||||
|
||||
@Tolerate
|
||||
public RevokeChatInviteLinkBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.groupadministration;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -10,13 +9,10 @@ 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.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 4.5
|
||||
@ -30,7 +26,7 @@ import java.io.IOException;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class SetChatAdministratorCustomTitle extends BotApiMethod<Boolean> {
|
||||
public class SetChatAdministratorCustomTitle extends BotApiMethodBoolean {
|
||||
public static final String PATH = "setChatAdministratorCustomTitle";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
@ -47,36 +43,32 @@ public class SetChatAdministratorCustomTitle extends BotApiMethod<Boolean> {
|
||||
@NonNull
|
||||
private String customTitle; ///< New custom title for the administrator; 0-16 characters, emoji are not allowed
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@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 description", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId can't be empty", this);
|
||||
}
|
||||
if (userId == 0) {
|
||||
throw new TelegramApiValidationException("UserId can't be empty", this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId can't be empty", this);
|
||||
}
|
||||
if (userId == null || userId == 0) {
|
||||
throw new TelegramApiValidationException("UserId can't be empty", this);
|
||||
}
|
||||
if (customTitle == null) {
|
||||
throw new TelegramApiValidationException("CustomTitle can't be null", this);
|
||||
public static class SetChatAdministratorCustomTitleBuilder {
|
||||
|
||||
@Tolerate
|
||||
public SetChatAdministratorCustomTitleBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.groupadministration;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -11,13 +10,10 @@ 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 lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 3.1
|
||||
@ -33,7 +29,7 @@ import java.io.IOException;
|
||||
@RequiredArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class SetChatDescription extends BotApiMethod<Boolean> {
|
||||
public class SetChatDescription extends BotApiMethodBoolean {
|
||||
public static final String PATH = "setChatDescription";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
@ -45,33 +41,32 @@ public class SetChatDescription extends BotApiMethod<Boolean> {
|
||||
@JsonProperty(DESCRIPTION_FIELD)
|
||||
private String description; ///< Optional. New chat description, 0-255 characters
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@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 description", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId can't be empty", this);
|
||||
}
|
||||
if (description == null) {
|
||||
throw new TelegramApiValidationException("Description can't be null", this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class SetChatDescriptionBuilder {
|
||||
|
||||
@Tolerate
|
||||
public SetChatDescriptionBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.groupadministration;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -10,14 +9,11 @@ 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.objects.ApiResponse;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
|
||||
import org.telegram.telegrambots.meta.api.objects.ChatPermissions;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 4.4
|
||||
@ -32,7 +28,7 @@ import java.io.IOException;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class SetChatPermissions extends BotApiMethod<Boolean> {
|
||||
public class SetChatPermissions extends BotApiMethodBoolean {
|
||||
public static final String PATH = "setChatPermissions";
|
||||
|
||||
private static final String CHAT_ID_FIELD = "chat_id";
|
||||
@ -45,33 +41,29 @@ public class SetChatPermissions extends BotApiMethod<Boolean> {
|
||||
@NonNull
|
||||
private ChatPermissions permissions; ///< New default chat permissions
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@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 description", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId can't be empty", this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId can't be empty", this);
|
||||
}
|
||||
if (permissions == null) {
|
||||
throw new TelegramApiValidationException("Permissions can't be null", this);
|
||||
public static class SetChatPermissionsBuilder {
|
||||
|
||||
@Tolerate
|
||||
public SetChatPermissionsBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.groupadministration;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -9,14 +8,12 @@ import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.api.objects.InputFile;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 3.1
|
||||
@ -44,28 +41,32 @@ public class SetChatPhoto extends PartialBotApiMethod<Boolean> {
|
||||
@NonNull
|
||||
private InputFile photo; ///< New chat photo as InputStream, uploaded using multipart/form-data
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@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 photo", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
return deserializeResponse(answer, Boolean.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId can't be empty", this);
|
||||
}
|
||||
if (photo == null || !photo.isNew()) {
|
||||
if (!photo.isNew()) {
|
||||
throw new TelegramApiValidationException("Photo parameter is required and must be a new file to upload", this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class SetChatPhotoBuilder {
|
||||
|
||||
@Tolerate
|
||||
public SetChatPhotoBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.groupadministration;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -10,13 +9,10 @@ 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.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
@ -32,7 +28,7 @@ import java.io.IOException;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class SetChatStickerSet extends BotApiMethod<Boolean> {
|
||||
public class SetChatStickerSet extends BotApiMethodBoolean {
|
||||
public static final String PATH = "setChatStickerSet";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
@ -45,33 +41,32 @@ public class SetChatStickerSet extends BotApiMethod<Boolean> {
|
||||
@NonNull
|
||||
private String stickerSetName; ///< Name of the sticker set to be set as the group sticker set
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@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 sticker set", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId can't be empty", this);
|
||||
}
|
||||
if (stickerSetName == null || stickerSetName.isEmpty()) {
|
||||
if (stickerSetName.isEmpty()) {
|
||||
throw new TelegramApiValidationException("StickerSetName can't be empty", this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class SetChatStickerSetBuilder {
|
||||
|
||||
@Tolerate
|
||||
public SetChatStickerSetBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.groupadministration;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -10,13 +9,10 @@ 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.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 3.1
|
||||
@ -33,7 +29,7 @@ import java.io.IOException;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class SetChatTitle extends BotApiMethod<Boolean> {
|
||||
public class SetChatTitle extends BotApiMethodBoolean {
|
||||
public static final String PATH = "setChatTitle";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
@ -46,33 +42,32 @@ public class SetChatTitle extends BotApiMethod<Boolean> {
|
||||
@NonNull
|
||||
private String title; ///< Required. New chat title, 1-255 characters
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@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 title", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId can't be empty", this);
|
||||
}
|
||||
if (title == null || title.isEmpty()) {
|
||||
if (title.isEmpty()) {
|
||||
throw new TelegramApiValidationException("Title can't be empty", this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class SetChatTitleBuilder {
|
||||
|
||||
@Tolerate
|
||||
public SetChatTitleBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.groupadministration;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -11,13 +10,10 @@ 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 lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
@ -38,7 +34,7 @@ import java.io.IOException;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class UnbanChatMember extends BotApiMethod<Boolean> {
|
||||
public class UnbanChatMember extends BotApiMethodBoolean {
|
||||
public static final String PATH = "unbanchatmember";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
@ -54,6 +50,10 @@ public class UnbanChatMember extends BotApiMethod<Boolean> {
|
||||
@JsonProperty(ONLYISBANNED_FIELD)
|
||||
private Boolean onlyIfBanned; ///< Optional. Do nothing if the user is not banned
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
@ -61,27 +61,18 @@ public class UnbanChatMember extends BotApiMethod<Boolean> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<Boolean> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<Boolean>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error unbanning chat member", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId can't be empty", this);
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
public static class UnbanChatMemberBuilder {
|
||||
|
||||
@Tolerate
|
||||
public UnbanChatMemberBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,18 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.groupadministration;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.*;
|
||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 5.5
|
||||
@ -25,7 +28,7 @@ import java.io.IOException;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class unbanChatSenderChat extends BotApiMethod<Boolean> {
|
||||
public class UnbanChatSenderChat extends BotApiMethodBoolean {
|
||||
public static final String PATH = "unbanChatSenderChat";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
@ -38,24 +41,14 @@ public class unbanChatSenderChat extends BotApiMethod<Boolean> {
|
||||
@NonNull
|
||||
private Long senderChatId; ///< Required. Unique identifier of the target sender chat
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<Boolean> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<Boolean>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error unbanning chat sender", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -67,4 +60,13 @@ public class unbanChatSenderChat extends BotApiMethod<Boolean> {
|
||||
throw new TelegramApiValidationException("SenderChatId can't be null or 0", this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class UnbanChatSenderChatBuilder {
|
||||
|
||||
@Tolerate
|
||||
public UnbanChatSenderChatBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,181 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.invoices;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.google.common.base.Strings;
|
||||
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.Singular;
|
||||
import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.api.objects.Message;
|
||||
import org.telegram.telegrambots.meta.api.objects.payments.LabeledPrice;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 6.1
|
||||
* Use this method to create a link for an invoice. On success, the created link is returned.
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@RequiredArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class CreateInvoiceLink extends BotApiMethod<Message> {
|
||||
public static final String PATH = "createInvoiceLink";
|
||||
|
||||
public static final String TITLE_FIELD = "title";
|
||||
public static final String DESCRIPTION_FIELD = "description";
|
||||
public static final String PAYLOAD_FIELD = "payload";
|
||||
public static final String PROVIDER_TOKEN_FIELD = "provider_token";
|
||||
public static final String CURRENCY_FIELD = "currency";
|
||||
public static final String PRICES_FIELD = "prices";
|
||||
public static final String MAXTIPAMOUNT_FIELD = "max_tip_amount";
|
||||
public static final String SUGGESTEDTIPAMOUNTS_FIELD = "suggested_tip_amounts";
|
||||
public static final String PROVIDER_DATA_FIELD = "provider_data";
|
||||
public static final String PHOTO_URL_FIELD = "photo_url";
|
||||
public static final String PHOTO_SIZE_FIELD = "photo_size";
|
||||
public static final String PHOTO_WIDTH_FIELD = "photo_width";
|
||||
public static final String PHOTO_HEIGHT_FIELD = "photo_height";
|
||||
public static final String NEED_NAME_FIELD = "need_name";
|
||||
public static final String NEED_PHONE_NUMBER_FIELD = "need_phone_number";
|
||||
public static final String NEED_EMAIL_FIELD = "need_email";
|
||||
public static final String NEED_SHIPPING_ADDRESS_FIELD = "need_shipping_address";
|
||||
public static final String SEND_PHONE_NUMBER_TO_PROVIDER_FIELD = "send_phone_number_to_provider";
|
||||
public static final String SEND_EMAIL_TO_PROVIDER_FIELD = "send_email_to_provider";
|
||||
public static final String IS_FLEXIBLE_FIELD = "is_flexible";
|
||||
|
||||
@JsonProperty(TITLE_FIELD)
|
||||
@NonNull
|
||||
private String title; ///< Product name, 1-32 characters
|
||||
@JsonProperty(DESCRIPTION_FIELD)
|
||||
@NonNull
|
||||
private String description; ///< Product description, 1-255 characters
|
||||
@JsonProperty(PAYLOAD_FIELD)
|
||||
@NonNull
|
||||
private String payload; ///< Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes.
|
||||
@JsonProperty(PROVIDER_TOKEN_FIELD)
|
||||
@NonNull
|
||||
private String providerToken; ///< Payment provider token, obtained via BotFather
|
||||
@JsonProperty(CURRENCY_FIELD)
|
||||
@NonNull
|
||||
private String currency; ///< Three-letter ISO 4217 currency code, see more on currencies
|
||||
@JsonProperty(PRICES_FIELD)
|
||||
@NonNull
|
||||
@Singular
|
||||
private List<LabeledPrice> prices; ///< Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)
|
||||
/**
|
||||
* Optional
|
||||
* URL of the product photo for the invoice.
|
||||
* Can be a photo of the goods or a marketing image for a service.
|
||||
*/
|
||||
@JsonProperty(PHOTO_URL_FIELD)
|
||||
private String photoUrl;
|
||||
@JsonProperty(PHOTO_SIZE_FIELD)
|
||||
private Integer photoSize; ///< Optional Photo size in bytes
|
||||
@JsonProperty(PHOTO_WIDTH_FIELD)
|
||||
private Integer photoWidth; ///< Optional Photo width
|
||||
@JsonProperty(PHOTO_HEIGHT_FIELD)
|
||||
private Integer photoHeight; ///< Optional Photo height
|
||||
@JsonProperty(NEED_NAME_FIELD)
|
||||
private Boolean needName; ///< Optional Pass True, if you require the user's full name to complete the order
|
||||
@JsonProperty(NEED_PHONE_NUMBER_FIELD)
|
||||
private Boolean needPhoneNumber; ///< Optional Pass True, if you require the user's phone number to complete the order
|
||||
@JsonProperty(NEED_EMAIL_FIELD)
|
||||
private Boolean needEmail; ///< Optional Pass True, if you require the user's email address to complete the order
|
||||
@JsonProperty(NEED_SHIPPING_ADDRESS_FIELD)
|
||||
private Boolean needShippingAddress; ///< Optional Pass True, if you require the user's shipping address to complete the order
|
||||
@JsonProperty(IS_FLEXIBLE_FIELD)
|
||||
private Boolean isFlexible; ///< Optional Pass True, if the final price depends on the shipping method
|
||||
@JsonProperty(SEND_PHONE_NUMBER_TO_PROVIDER_FIELD)
|
||||
private Boolean sendPhoneNumberToProvider; ///< Optional Pass True, if the user's phone number should be sent to the provider
|
||||
@JsonProperty(SEND_EMAIL_TO_PROVIDER_FIELD)
|
||||
private Boolean sendEmailToProvider; ///< Optional Pass True, if the user's email address should be sent to the provider
|
||||
/**
|
||||
* Optional
|
||||
* JSON-serialized data about the invoice, which will be shared with the payment provider.
|
||||
*
|
||||
* @apiNote A detailed description of required fields should be provided by the payment provider.
|
||||
*/
|
||||
@JsonProperty(PROVIDER_DATA_FIELD)
|
||||
private String providerData;
|
||||
/**
|
||||
* The maximum accepted amount for tips in the smallest units of the currency (integer, not float/double).
|
||||
* For example, for a maximum tip of US$ 1.45 pass max_tip_amount = 145.
|
||||
* Defaults to 0
|
||||
*/
|
||||
@JsonProperty(MAXTIPAMOUNT_FIELD)
|
||||
private Integer maxTipAmount;
|
||||
/**
|
||||
* Optional A JSON-serialized array of suggested amounts of tips in the smallest units of the currency (integer, not float/double).
|
||||
* At most 4 suggested tip amounts can be specified.
|
||||
* The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed max_tip_amount.
|
||||
*/
|
||||
@JsonProperty(SUGGESTEDTIPAMOUNTS_FIELD)
|
||||
@Singular
|
||||
private List<Integer> suggestedTipAmounts;
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<Message> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<Message>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error sending invoice", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (Strings.isNullOrEmpty(title) || title.length() > 32) {
|
||||
throw new TelegramApiValidationException("Title parameter can't be empty or longer than 32 chars", this);
|
||||
}
|
||||
if (Strings.isNullOrEmpty(description) || description.length() > 255) {
|
||||
throw new TelegramApiValidationException("Description parameter can't be empty or longer than 255 chars", this);
|
||||
}
|
||||
if (Strings.isNullOrEmpty(payload)) {
|
||||
throw new TelegramApiValidationException("Payload parameter can't be empty", this);
|
||||
}
|
||||
if (Strings.isNullOrEmpty(providerToken)) {
|
||||
throw new TelegramApiValidationException("ProviderToken parameter can't be empty", this);
|
||||
}
|
||||
if (Strings.isNullOrEmpty(currency)) {
|
||||
throw new TelegramApiValidationException("Currency parameter can't be empty", this);
|
||||
}
|
||||
if (prices.isEmpty()) {
|
||||
throw new TelegramApiValidationException("Prices parameter can't be empty", this);
|
||||
} else {
|
||||
for (LabeledPrice price : prices) {
|
||||
price.validate();
|
||||
}
|
||||
}
|
||||
if (suggestedTipAmounts != null && !suggestedTipAmounts.isEmpty() && suggestedTipAmounts.size() > 4) {
|
||||
throw new TelegramApiValidationException("No more that 4 suggested tips allowed", this);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,237 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.invoices;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.google.common.base.Strings;
|
||||
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.Singular;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.api.objects.Message;
|
||||
import org.telegram.telegrambots.meta.api.objects.payments.LabeledPrice;
|
||||
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
* Use this method to send an invoice. On success, the sent Message is returned.
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@RequiredArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class SendInvoice extends BotApiMethod<Message> {
|
||||
public static final String PATH = "sendinvoice";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
private static final String TITLE_FIELD = "title";
|
||||
private static final String DESCRIPTION_FIELD = "description";
|
||||
private static final String PAYLOAD_FIELD = "payload";
|
||||
private static final String PROVIDER_TOKEN_FIELD = "provider_token";
|
||||
private static final String START_PARAMETER_FIELD = "start_parameter";
|
||||
private static final String CURRENCY_FIELD = "currency";
|
||||
private static final String PRICES_FIELD = "prices";
|
||||
private static final String PHOTO_URL_FIELD = "photo_url";
|
||||
private static final String PHOTO_SIZE_FIELD = "photo_size";
|
||||
private static final String PHOTO_WIDTH_FIELD = "photo_width";
|
||||
private static final String PHOTO_HEIGHT_FIELD = "photo_height";
|
||||
private static final String NEED_NAME_FIELD = "need_name";
|
||||
private static final String NEED_PHONE_NUMBER_FIELD = "need_phone_number";
|
||||
private static final String NEED_EMAIL_FIELD = "need_email";
|
||||
private static final String NEED_SHIPPING_ADDRESS_FIELD = "need_shipping_address";
|
||||
private static final String SEND_PHONE_NUMBER_TO_PROVIDER_FIELD = "send_phone_number_to_provider";
|
||||
private static final String SEND_EMAIL_TO_PROVIDER_FIELD = "send_email_to_provider";
|
||||
private static final String IS_FLEXIBLE_FIELD = "is_flexible";
|
||||
private static final String DISABLE_NOTIFICATION_FIELD = "disable_notification";
|
||||
private static final String REPLY_TO_MESSAGE_ID_FIELD = "reply_to_message_id";
|
||||
private static final String REPLY_MARKUP_FIELD = "reply_markup";
|
||||
private static final String PROVIDER_DATA_FIELD = "provider_data";
|
||||
private static final String ALLOWSENDINGWITHOUTREPLY_FIELD = "allow_sending_without_reply";
|
||||
private static final String MAXTIPAMOUNT_FIELD = "max_tip_amount";
|
||||
private static final String SUGGESTEDTIPAMOUNTS_FIELD = "suggested_tip_amounts";
|
||||
private static final String PROTECTCONTENT_FIELD = "protect_content";
|
||||
|
||||
@JsonProperty(CHATID_FIELD)
|
||||
@NonNull
|
||||
private String chatId; ///< Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
@JsonProperty(TITLE_FIELD)
|
||||
@NonNull
|
||||
private String title; ///< Product name
|
||||
@JsonProperty(DESCRIPTION_FIELD)
|
||||
@NonNull
|
||||
private String description; ///< Product description
|
||||
@JsonProperty(PAYLOAD_FIELD)
|
||||
@NonNull
|
||||
private String payload; ///< Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes.
|
||||
@JsonProperty(PROVIDER_TOKEN_FIELD)
|
||||
@NonNull
|
||||
private String providerToken; ///< Payments provider token, obtained via Botfather
|
||||
/**
|
||||
* Optional
|
||||
* Unique deep-linking parameter. If left empty, forwarded copies of the sent message will have a Pay button,
|
||||
* allowing multiple users to pay directly from the forwarded message, using the same invoice.
|
||||
* If non-empty, forwarded copies of the sent message will have a URL button with a deep link to the bot (instead of a Pay button),
|
||||
* with the value used as the start parameter
|
||||
*/
|
||||
@JsonProperty(START_PARAMETER_FIELD)
|
||||
@NonNull
|
||||
private String startParameter;
|
||||
@JsonProperty(CURRENCY_FIELD)
|
||||
@NonNull
|
||||
private String currency; ///< 3-letter ISO 4217 currency code
|
||||
@JsonProperty(PRICES_FIELD)
|
||||
@NonNull
|
||||
@Singular
|
||||
private List<LabeledPrice> prices; ///< Price breakdown, a list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)
|
||||
/**
|
||||
* Optional. URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service.
|
||||
* People like it better when they see what they are paying for
|
||||
*/
|
||||
@JsonProperty(PHOTO_URL_FIELD)
|
||||
private String photoUrl;
|
||||
@JsonProperty(PHOTO_SIZE_FIELD)
|
||||
private Integer photoSize; ///< Optional. Photo size
|
||||
@JsonProperty(PHOTO_WIDTH_FIELD)
|
||||
private Integer photoWidth; ///< Optional. Photo width
|
||||
@JsonProperty(PHOTO_HEIGHT_FIELD)
|
||||
private Integer photoHeight; ///< Optional. Photo height
|
||||
@JsonProperty(NEED_NAME_FIELD)
|
||||
private Boolean needName; ///< Optional. Pass True, if you require the user's full name to complete the order
|
||||
@JsonProperty(NEED_PHONE_NUMBER_FIELD)
|
||||
private Boolean needPhoneNumber; ///< Optional. Pass True, if you require the user's phone number to complete the order
|
||||
@JsonProperty(NEED_EMAIL_FIELD)
|
||||
private Boolean needEmail; ///< Optional. Pass True, if you require the user's email to complete the order
|
||||
@JsonProperty(NEED_SHIPPING_ADDRESS_FIELD)
|
||||
private Boolean needShippingAddress; ///< Optional. Pass True, if you require the user's shipping address to complete the order
|
||||
@JsonProperty(IS_FLEXIBLE_FIELD)
|
||||
private Boolean isFlexible; ///< Optional. Pass True, if the final price depends on the shipping method
|
||||
@JsonProperty(DISABLE_NOTIFICATION_FIELD)
|
||||
private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
|
||||
@JsonProperty(REPLY_TO_MESSAGE_ID_FIELD)
|
||||
private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message
|
||||
|
||||
@JsonProperty(SEND_PHONE_NUMBER_TO_PROVIDER_FIELD)
|
||||
private Boolean sendPhoneNumberToProvider; ///< Optional. Pass True, if user's phone number should be sent to provider
|
||||
@JsonProperty(SEND_EMAIL_TO_PROVIDER_FIELD)
|
||||
private Boolean sendEmailToProvider; ///< Optional. Pass True, if user's email address should be sent to provider
|
||||
/**
|
||||
* Optional. A JSON-serialized object for an inline keyboard.
|
||||
*
|
||||
* @apiNote If empty, one 'Buy title' button will be shown. If not empty, the first button must be a Pay button.
|
||||
*/
|
||||
@JsonProperty(REPLY_MARKUP_FIELD)
|
||||
private InlineKeyboardMarkup replyMarkup;
|
||||
/**
|
||||
* Optional JSON-encoded data about the invoice, which will be shared with the payment provider.
|
||||
*
|
||||
* @apiNote A detailed description of required fields should be provided by the payment provider.
|
||||
*/
|
||||
@JsonProperty(PROVIDER_DATA_FIELD)
|
||||
private String providerData;
|
||||
@JsonProperty(ALLOWSENDINGWITHOUTREPLY_FIELD)
|
||||
private Boolean allowSendingWithoutReply; ///< Optional Pass True, if the message should be sent even if the specified replied-to message is not found
|
||||
/**
|
||||
* The maximum accepted amount for tips in the smallest units of the currency (integer, not float/double).
|
||||
* For example, for a maximum tip of US$ 1.45 pass max_tip_amount = 145.
|
||||
* Defaults to 0
|
||||
*/
|
||||
@JsonProperty(MAXTIPAMOUNT_FIELD)
|
||||
private Integer maxTipAmount;
|
||||
/**
|
||||
* A JSON-serialized array of suggested amounts of tips in the smallest units of the currency (integer, not float/double).
|
||||
* At most 4 suggested tip amounts can be specified.
|
||||
* The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed max_tip_amount.
|
||||
*/
|
||||
@JsonProperty(SUGGESTEDTIPAMOUNTS_FIELD)
|
||||
@Singular
|
||||
private List<Integer> suggestedTipAmounts;
|
||||
@JsonProperty(PROTECTCONTENT_FIELD)
|
||||
private Boolean protectContent; ///< Optional. Protects the contents of sent messages from forwarding and saving
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<Message> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<Message>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error sending invoice", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (Strings.isNullOrEmpty(chatId)) {
|
||||
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
|
||||
}
|
||||
if (Strings.isNullOrEmpty(title) || title.length() > 32) {
|
||||
throw new TelegramApiValidationException("Title parameter can't be empty or longer than 32 chars", this);
|
||||
}
|
||||
if (Strings.isNullOrEmpty(description) || description.length() > 255) {
|
||||
throw new TelegramApiValidationException("Description parameter can't be empty or longer than 255 chars", this);
|
||||
}
|
||||
if (Strings.isNullOrEmpty(payload)) {
|
||||
throw new TelegramApiValidationException("Payload parameter can't be empty", this);
|
||||
}
|
||||
if (Strings.isNullOrEmpty(providerToken)) {
|
||||
throw new TelegramApiValidationException("ProviderToken parameter can't be empty", this);
|
||||
}
|
||||
if (Strings.isNullOrEmpty(currency)) {
|
||||
throw new TelegramApiValidationException("Currency parameter can't be empty", this);
|
||||
}
|
||||
if (prices.isEmpty()) {
|
||||
throw new TelegramApiValidationException("Prices parameter can't be empty", this);
|
||||
} else {
|
||||
for (LabeledPrice price : prices) {
|
||||
price.validate();
|
||||
}
|
||||
}
|
||||
if (suggestedTipAmounts != null && !suggestedTipAmounts.isEmpty() && suggestedTipAmounts.size() > 4) {
|
||||
throw new TelegramApiValidationException("No more that 4 suggested tips allowed", this);
|
||||
}
|
||||
if (replyMarkup != null) {
|
||||
replyMarkup.validate();
|
||||
}
|
||||
}
|
||||
|
||||
public static class SendInvoiceBuilder {
|
||||
|
||||
@Tolerate
|
||||
public SendInvoiceBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,15 +1,18 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.menubutton;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
||||
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.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
@ -23,8 +26,8 @@ import java.io.IOException;
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class GetChatMenuButton extends BotApiMethod<MenuButton> {
|
||||
public static final String PATH = "getChatMenuButton";
|
||||
@ -39,9 +42,9 @@ public class GetChatMenuButton extends BotApiMethod<MenuButton> {
|
||||
@JsonProperty(CHATID_FIELD)
|
||||
private String chatId;
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -51,16 +54,15 @@ public class GetChatMenuButton extends BotApiMethod<MenuButton> {
|
||||
|
||||
@Override
|
||||
public MenuButton deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<MenuButton> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<MenuButton>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error getting chat menu button query", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
return deserializeResponse(answer, MenuButton.class);
|
||||
}
|
||||
|
||||
public static class GetChatMenuButtonBuilder {
|
||||
|
||||
@Tolerate
|
||||
public GetChatMenuButtonBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,19 @@
|
||||
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 lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
|
||||
import org.telegram.telegrambots.meta.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
|
||||
@ -28,7 +29,7 @@ import java.io.IOException;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class SetChatMenuButton extends BotApiMethod<Boolean> {
|
||||
public class SetChatMenuButton extends BotApiMethodBoolean {
|
||||
public static final String PATH = "setChatMenuButton";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
@ -49,6 +50,11 @@ public class SetChatMenuButton extends BotApiMethod<Boolean> {
|
||||
@JsonProperty(MENUBUTTON_FIELD)
|
||||
private MenuButton menuButton;
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (menuButton != null) {
|
||||
@ -61,18 +67,12 @@ public class SetChatMenuButton extends BotApiMethod<Boolean> {
|
||||
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);
|
||||
public static class SetChatMenuButtonBuilder {
|
||||
|
||||
@Tolerate
|
||||
public SetChatMenuButtonBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.pinnedmessages;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -11,13 +10,10 @@ 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 lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 3.1
|
||||
@ -35,7 +31,7 @@ import java.io.IOException;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class PinChatMessage extends BotApiMethod<Boolean> {
|
||||
public class PinChatMessage extends BotApiMethodBoolean {
|
||||
public static final String PATH = "pinChatMessage";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
@ -55,33 +51,29 @@ public class PinChatMessage extends BotApiMethod<Boolean> {
|
||||
@JsonProperty(DISABLENOTIFICATION_FIELD)
|
||||
private Boolean disableNotification;
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@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 pinning chat message", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
|
||||
}
|
||||
if (messageId == null) {
|
||||
throw new TelegramApiValidationException("MessageId parameter can't be null", this);
|
||||
public static class PinChatMessageBuilder {
|
||||
|
||||
@Tolerate
|
||||
public PinChatMessageBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.pinnedmessages;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -10,13 +9,10 @@ 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.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 3.1
|
||||
@ -34,7 +30,7 @@ import java.io.IOException;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class UnpinAllChatMessages extends BotApiMethod<Boolean> {
|
||||
public class UnpinAllChatMessages extends BotApiMethodBoolean {
|
||||
public static final String PATH = "unpinAllChatMessages";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
@ -43,30 +39,29 @@ public class UnpinAllChatMessages extends BotApiMethod<Boolean> {
|
||||
@NonNull
|
||||
private String chatId; ///< Required. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@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 unpinning chat message", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class UnpinAllChatMessagesBuilder {
|
||||
|
||||
@Tolerate
|
||||
public UnpinAllChatMessagesBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.pinnedmessages;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -11,13 +10,10 @@ 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 lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 3.1
|
||||
@ -36,7 +32,7 @@ import java.io.IOException;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class UnpinChatMessage extends BotApiMethod<Boolean> {
|
||||
public class UnpinChatMessage extends BotApiMethodBoolean {
|
||||
public static final String PATH = "unpinChatMessage";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
@ -54,30 +50,29 @@ public class UnpinChatMessage extends BotApiMethod<Boolean> {
|
||||
@JsonProperty(MESSAGEID_FIELD)
|
||||
private Integer messageId;
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@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 unpinning chat message", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class UnpinChatMessageBuilder {
|
||||
|
||||
@Tolerate
|
||||
public UnpinChatMessageBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.polls;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
@ -13,15 +12,12 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.Singular;
|
||||
import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.api.objects.Message;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodMessage;
|
||||
import org.telegram.telegrambots.meta.api.objects.MessageEntity;
|
||||
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -40,7 +36,7 @@ import java.util.List;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class SendPoll extends BotApiMethod<Message> {
|
||||
public class SendPoll extends BotApiMethodMessage {
|
||||
public static final String PATH = "sendPoll";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
@ -109,6 +105,11 @@ public class SendPoll extends BotApiMethod<Message> {
|
||||
@JsonProperty(PROTECTCONTENT_FIELD)
|
||||
private Boolean protectContent; ///< Optional. Protects the contents of sent messages from forwarding and saving
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
public void enableNotification() {
|
||||
this.disableNotification = null;
|
||||
}
|
||||
@ -122,31 +123,15 @@ public class SendPoll extends BotApiMethod<Message> {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<Message> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<Message>>() {
|
||||
});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error sending poll", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
|
||||
}
|
||||
if (question == null || question.isEmpty()) {
|
||||
if (question.isEmpty()) {
|
||||
throw new TelegramApiValidationException("Question parameter can't be empty", this);
|
||||
}
|
||||
if (options == null || options.size() < 2 || options.size() > 10) {
|
||||
if (options.size() < 2 || options.size() > 10) {
|
||||
throw new TelegramApiValidationException("Options parameter must be between 2 and 10 item", this);
|
||||
}
|
||||
if (openPeriod != null && closeDate != null) {
|
||||
@ -168,4 +153,14 @@ public class SendPoll extends BotApiMethod<Message> {
|
||||
replyMarkup.validate();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class SendPollBuilder {
|
||||
|
||||
@Tolerate
|
||||
public SendPollBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.polls;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -10,14 +9,12 @@ import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.api.objects.polls.Poll;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
@ -45,6 +42,11 @@ public class StopPoll extends BotApiMethod<Poll> {
|
||||
@NonNull
|
||||
private Integer messageId; ///< Identifier of the original message with the poll
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
@ -52,26 +54,26 @@ public class StopPoll extends BotApiMethod<Poll> {
|
||||
|
||||
@Override
|
||||
public Poll deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<Poll> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<Poll>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error stopping poll", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
return deserializeResponse(answer, Poll.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
|
||||
}
|
||||
if (messageId == null || messageId == 0) {
|
||||
if (messageId == 0) {
|
||||
throw new TelegramApiValidationException("Message Id parameter can't be empty", this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class StopPollBuilder {
|
||||
|
||||
@Tolerate
|
||||
public StopPollBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.send;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -12,8 +10,8 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.Singular;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.api.objects.InputFile;
|
||||
import org.telegram.telegrambots.meta.api.objects.Message;
|
||||
import org.telegram.telegrambots.meta.api.objects.MessageEntity;
|
||||
@ -21,7 +19,6 @@ import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -89,6 +86,11 @@ public class SendAnimation extends PartialBotApiMethod<Message> {
|
||||
private Boolean allowSendingWithoutReply; ///< Optional Pass True, if the message should be sent even if the specified replied-to message is not found
|
||||
private Boolean protectContent; ///< Optional. Protects the contents of sent messages from forwarding and saving
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
public void enableNotification() {
|
||||
this.disableNotification = false;
|
||||
}
|
||||
@ -99,29 +101,15 @@ public class SendAnimation extends PartialBotApiMethod<Message> {
|
||||
|
||||
@Override
|
||||
public Message deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<Message> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<Message>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error sending animation", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
return deserializeResponse(answer, Message.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
|
||||
}
|
||||
|
||||
if (animation == null) {
|
||||
throw new TelegramApiValidationException("Animation parameter can't be empty", this);
|
||||
}
|
||||
|
||||
if (parseMode != null && (captionEntities != null && !captionEntities.isEmpty()) ) {
|
||||
throw new TelegramApiValidationException("Parse mode can't be enabled if Entities are provided", this);
|
||||
}
|
||||
@ -135,4 +123,13 @@ public class SendAnimation extends PartialBotApiMethod<Message> {
|
||||
thumb.validate();
|
||||
}
|
||||
}
|
||||
|
||||
public static class SendAnimationBuilder {
|
||||
|
||||
@Tolerate
|
||||
public SendAnimationBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.send;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -12,8 +10,8 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.Singular;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.api.objects.InputFile;
|
||||
import org.telegram.telegrambots.meta.api.objects.Message;
|
||||
import org.telegram.telegrambots.meta.api.objects.MessageEntity;
|
||||
@ -21,7 +19,6 @@ import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -85,6 +82,11 @@ public class SendAudio extends PartialBotApiMethod<Message> {
|
||||
private Boolean allowSendingWithoutReply; ///< Optional Pass True, if the message should be sent even if the specified replied-to message is not found
|
||||
private Boolean protectContent; ///< Optional. Protects the contents of sent messages from forwarding and saving
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
public void enableNotification() {
|
||||
this.disableNotification = false;
|
||||
}
|
||||
@ -95,29 +97,15 @@ public class SendAudio extends PartialBotApiMethod<Message> {
|
||||
|
||||
@Override
|
||||
public Message deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<Message> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<Message>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error sending audio", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
return deserializeResponse(answer, Message.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
|
||||
}
|
||||
|
||||
if (audio == null) {
|
||||
throw new TelegramApiValidationException("Audio parameter can't be empty", this);
|
||||
}
|
||||
|
||||
if (parseMode != null && (captionEntities != null && !captionEntities.isEmpty()) ) {
|
||||
throw new TelegramApiValidationException("Parse mode can't be enabled if Entities are provided", this);
|
||||
}
|
||||
@ -132,4 +120,13 @@ public class SendAudio extends PartialBotApiMethod<Message> {
|
||||
replyMarkup.validate();
|
||||
}
|
||||
}
|
||||
|
||||
public static class SendAudioBuilder {
|
||||
|
||||
@Tolerate
|
||||
public SendAudioBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package org.telegram.telegrambots.meta.api.methods.send;
|
||||
|
||||
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;
|
||||
@ -11,14 +10,11 @@ import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.ActionType;
|
||||
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.api.methods.botapimethods.BotApiMethodBoolean;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
@ -33,7 +29,7 @@ import java.io.IOException;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class SendChatAction extends BotApiMethod<Boolean> {
|
||||
public class SendChatAction extends BotApiMethodBoolean {
|
||||
|
||||
public static final String PATH = "sendChatAction";
|
||||
|
||||
@ -59,6 +55,11 @@ public class SendChatAction extends BotApiMethod<Boolean> {
|
||||
@NonNull
|
||||
private String action;
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public ActionType getActionType() {
|
||||
return ActionType.get(action);
|
||||
@ -74,21 +75,6 @@ public class SendChatAction extends BotApiMethod<Boolean> {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<Boolean> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<Boolean>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error sending chat action", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId.isEmpty()) {
|
||||
@ -98,4 +84,13 @@ public class SendChatAction extends BotApiMethod<Boolean> {
|
||||
throw new TelegramApiValidationException("Action parameter can't be empty", this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class SendChatActionBuilder {
|
||||
|
||||
@Tolerate
|
||||
public SendChatActionBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.send;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -11,15 +10,11 @@ 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.api.objects.Message;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodMessage;
|
||||
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
@ -34,7 +29,7 @@ import java.io.IOException;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class SendContact extends BotApiMethod<Message> {
|
||||
public class SendContact extends BotApiMethodMessage {
|
||||
public static final String PATH = "sendContact";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
@ -72,6 +67,11 @@ public class SendContact extends BotApiMethod<Message> {
|
||||
@JsonProperty(PROTECTCONTENT_FIELD)
|
||||
private Boolean protectContent; ///< Optional. Protects the contents of sent messages from forwarding and saving
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
public void enableNotification() {
|
||||
this.disableNotification = false;
|
||||
}
|
||||
@ -85,34 +85,22 @@ public class SendContact extends BotApiMethod<Message> {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<Message> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<Message>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error sending contact", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
|
||||
}
|
||||
if (phoneNumber == null) {
|
||||
throw new TelegramApiValidationException("PhoneNumber parameter can't be empty", this);
|
||||
}
|
||||
if (firstName == null) {
|
||||
throw new TelegramApiValidationException("FirstName parameter can't be empty", this);
|
||||
}
|
||||
if (replyMarkup != null) {
|
||||
replyMarkup.validate();
|
||||
}
|
||||
}
|
||||
|
||||
public static class SendContactBuilder {
|
||||
|
||||
@Tolerate
|
||||
public SendContactBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.send;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -11,14 +10,11 @@ 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.api.objects.Message;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodMessage;
|
||||
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@ -36,7 +32,7 @@ import java.util.List;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class SendDice extends BotApiMethod<Message> {
|
||||
public class SendDice extends BotApiMethodMessage {
|
||||
private static final List<String> VALIDEMOJIS = Collections.unmodifiableList(Arrays.asList("🎲", "🎯", "🏀", "⚽", "🎳", "🎰"));
|
||||
|
||||
public static final String PATH = "sendDice";
|
||||
@ -76,6 +72,11 @@ public class SendDice extends BotApiMethod<Message> {
|
||||
@JsonProperty(PROTECTCONTENT_FIELD)
|
||||
private Boolean protectContent; ///< Optional. Protects the contents of sent messages from forwarding and saving
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
public void enableNotification() {
|
||||
this.disableNotification = false;
|
||||
}
|
||||
@ -89,24 +90,9 @@ public class SendDice extends BotApiMethod<Message> {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<Message> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<Message>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error sending dice", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
|
||||
}
|
||||
if (emoji != null && !VALIDEMOJIS.contains(emoji)) {
|
||||
@ -116,4 +102,13 @@ public class SendDice extends BotApiMethod<Message> {
|
||||
replyMarkup.validate();
|
||||
}
|
||||
}
|
||||
|
||||
public static class SendDiceBuilder {
|
||||
|
||||
@Tolerate
|
||||
public SendDiceBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.send;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -12,8 +10,8 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.Singular;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.api.objects.InputFile;
|
||||
import org.telegram.telegrambots.meta.api.objects.Message;
|
||||
import org.telegram.telegrambots.meta.api.objects.MessageEntity;
|
||||
@ -21,7 +19,6 @@ import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -77,6 +74,11 @@ public class SendDocument extends PartialBotApiMethod<Message> {
|
||||
private Boolean disableContentTypeDetection; ///< Optional Disables automatic server-side content type detection for files uploaded using multipart/form-data
|
||||
private Boolean protectContent; ///< Optional. Protects the contents of sent messages from forwarding and saving
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
public void enableNotification() {
|
||||
this.disableNotification = false;
|
||||
}
|
||||
@ -87,29 +89,14 @@ public class SendDocument extends PartialBotApiMethod<Message> {
|
||||
|
||||
@Override
|
||||
public Message deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<Message> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<Message>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error sending document", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
return deserializeResponse(answer, Message.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
|
||||
}
|
||||
|
||||
if (document == null) {
|
||||
throw new TelegramApiValidationException("Document parameter can't be empty", this);
|
||||
}
|
||||
|
||||
if (parseMode != null && (captionEntities != null && !captionEntities.isEmpty()) ) {
|
||||
throw new TelegramApiValidationException("Parse mode can't be enabled if Entities are provided", this);
|
||||
}
|
||||
@ -124,4 +111,13 @@ public class SendDocument extends PartialBotApiMethod<Message> {
|
||||
replyMarkup.validate();
|
||||
}
|
||||
}
|
||||
|
||||
public static class SendDocumentBuilder {
|
||||
|
||||
@Tolerate
|
||||
public SendDocumentBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.send;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -28,15 +27,11 @@ 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.api.objects.Message;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodMessage;
|
||||
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
@ -50,7 +45,7 @@ import java.io.IOException;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class SendGame extends BotApiMethod<Message> {
|
||||
public class SendGame extends BotApiMethodMessage {
|
||||
public static final String PATH = "sendGame";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
@ -78,6 +73,11 @@ public class SendGame extends BotApiMethod<Message> {
|
||||
@JsonProperty(PROTECTCONTENT_FIELD)
|
||||
private Boolean protectContent; ///< Optional. Protects the contents of sent messages from forwarding and saving
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
public void enableNotification() {
|
||||
this.disableNotification = null;
|
||||
}
|
||||
@ -91,31 +91,25 @@ public class SendGame extends BotApiMethod<Message> {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<Message> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<Message>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error sending game", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
|
||||
}
|
||||
if (gameShortName == null || gameShortName.isEmpty()) {
|
||||
if (gameShortName.isEmpty()) {
|
||||
throw new TelegramApiValidationException("GameShortName parameter can't be empty", this);
|
||||
}
|
||||
if (replyMarkup != null) {
|
||||
replyMarkup.validate();
|
||||
}
|
||||
}
|
||||
|
||||
public static class SendGameBuilder {
|
||||
|
||||
@Tolerate
|
||||
public SendGameBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.send;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.google.common.base.Strings;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
@ -13,21 +12,20 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.Singular;
|
||||
import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.api.objects.Message;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodMessage;
|
||||
import org.telegram.telegrambots.meta.api.objects.payments.LabeledPrice;
|
||||
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
* Use this method to send an invoice. On success, the sent Message is returned.
|
||||
*
|
||||
* @deprecated Use {@link org.telegram.telegrambots.meta.api.methods.invoices.SendInvoice}
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Getter
|
||||
@ -37,7 +35,8 @@ import java.util.List;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class SendInvoice extends BotApiMethod<Message> {
|
||||
@Deprecated
|
||||
public class SendInvoice extends BotApiMethodMessage {
|
||||
public static final String PATH = "sendinvoice";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
@ -165,24 +164,14 @@ public class SendInvoice extends BotApiMethod<Message> {
|
||||
@JsonProperty(PROTECTCONTENT_FIELD)
|
||||
private Boolean protectContent; ///< Optional. Protects the contents of sent messages from forwarding and saving
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<Message> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<Message>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error sending invoice", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -205,7 +194,7 @@ public class SendInvoice extends BotApiMethod<Message> {
|
||||
if (Strings.isNullOrEmpty(currency)) {
|
||||
throw new TelegramApiValidationException("Currency parameter can't be empty", this);
|
||||
}
|
||||
if (prices == null || prices.isEmpty()) {
|
||||
if (prices.isEmpty()) {
|
||||
throw new TelegramApiValidationException("Prices parameter can't be empty", this);
|
||||
} else {
|
||||
for (LabeledPrice price : prices) {
|
||||
@ -219,4 +208,13 @@ public class SendInvoice extends BotApiMethod<Message> {
|
||||
replyMarkup.validate();
|
||||
}
|
||||
}
|
||||
|
||||
public static class SendInvoiceBuilder {
|
||||
|
||||
@Tolerate
|
||||
public SendInvoiceBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.send;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -11,15 +10,11 @@ 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.api.objects.Message;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodMessage;
|
||||
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
@ -33,7 +28,7 @@ import java.io.IOException;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class SendLocation extends BotApiMethod<Message> {
|
||||
public class SendLocation extends BotApiMethodMessage {
|
||||
public static final String PATH = "sendlocation";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
@ -91,6 +86,11 @@ public class SendLocation extends BotApiMethod<Message> {
|
||||
@JsonProperty(PROTECTCONTENT_FIELD)
|
||||
private Boolean protectContent; ///< Optional. Protects the contents of sent messages from forwarding and saving
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
public void enableNotification() {
|
||||
this.disableNotification = false;
|
||||
}
|
||||
@ -104,32 +104,11 @@ public class SendLocation extends BotApiMethod<Message> {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<Message> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<Message>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error sending location", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
|
||||
}
|
||||
if (latitude == null) {
|
||||
throw new TelegramApiValidationException("Latitude parameter can't be empty", this);
|
||||
}
|
||||
if (longitude == null) {
|
||||
throw new TelegramApiValidationException("Longitude parameter can't be empty", this);
|
||||
}
|
||||
if (horizontalAccuracy != null && (horizontalAccuracy < 0 || horizontalAccuracy > 1500)) {
|
||||
throw new TelegramApiValidationException("Horizontal Accuracy parameter must be between 0 and 1500", this);
|
||||
}
|
||||
@ -146,4 +125,13 @@ public class SendLocation extends BotApiMethod<Message> {
|
||||
throw new TelegramApiValidationException("Live period parameter must be between 60 and 86400", this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class SendLocationBuilder {
|
||||
|
||||
@Tolerate
|
||||
public SendLocationBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.send;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -11,8 +10,8 @@ import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.api.objects.Message;
|
||||
import org.telegram.telegrambots.meta.api.objects.media.InputMedia;
|
||||
import org.telegram.telegrambots.meta.api.objects.media.InputMediaAnimation;
|
||||
@ -21,7 +20,6 @@ import org.telegram.telegrambots.meta.api.objects.media.InputMediaDocument;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -66,6 +64,11 @@ public class SendMediaGroup extends PartialBotApiMethod<ArrayList<Message>> {
|
||||
private Boolean allowSendingWithoutReply; ///< Optional Pass True, if the message should be sent even if the specified replied-to message is not found
|
||||
private Boolean protectContent; ///< Optional. Protects the contents of sent messages from forwarding and saving
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
public void enableNotification() {
|
||||
this.disableNotification = false;
|
||||
}
|
||||
@ -76,27 +79,16 @@ public class SendMediaGroup extends PartialBotApiMethod<ArrayList<Message>> {
|
||||
|
||||
@Override
|
||||
public ArrayList<Message> deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<ArrayList<Message>> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<ArrayList<Message>>>() {
|
||||
});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error sending media group", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
return deserializeResponseArray(answer, Message.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
|
||||
}
|
||||
|
||||
if (medias == null || medias.isEmpty()) {
|
||||
if (medias.isEmpty()) {
|
||||
throw new TelegramApiValidationException("Media parameter can't be empty", this);
|
||||
} else if (medias.size() < 2 || medias.size() > 10) {
|
||||
throw new TelegramApiValidationException("Number of media should be between 2 and 10", this);
|
||||
@ -122,4 +114,13 @@ public class SendMediaGroup extends PartialBotApiMethod<ArrayList<Message>> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class SendMediaGroupBuilder {
|
||||
|
||||
@Tolerate
|
||||
public SendMediaGroupBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.meta.api.methods.send;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
@ -12,16 +11,13 @@ import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.telegram.telegrambots.meta.api.methods.ParseMode;
|
||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||
import org.telegram.telegrambots.meta.api.objects.Message;
|
||||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodMessage;
|
||||
import org.telegram.telegrambots.meta.api.objects.MessageEntity;
|
||||
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -38,7 +34,7 @@ import java.util.List;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class SendMessage extends BotApiMethod<Message> {
|
||||
public class SendMessage extends BotApiMethodMessage {
|
||||
public static final String PATH = "sendmessage";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
@ -76,6 +72,11 @@ public class SendMessage extends BotApiMethod<Message> {
|
||||
@JsonProperty(PROTECTCONTENT_FIELD)
|
||||
private Boolean protectContent; ///< Optional. Protects the contents of sent messages from forwarding and saving
|
||||
|
||||
@Tolerate
|
||||
public void setChatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
}
|
||||
|
||||
public void disableWebPagePreview() {
|
||||
disableWebPagePreview = true;
|
||||
}
|
||||
@ -121,27 +122,12 @@ public class SendMessage extends BotApiMethod<Message> {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<Message> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<Message>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error sending message", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null || chatId.isEmpty()) {
|
||||
if (chatId.isEmpty()) {
|
||||
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
|
||||
}
|
||||
if (text == null || text.isEmpty()) {
|
||||
if (text.isEmpty()) {
|
||||
throw new TelegramApiValidationException("Text parameter can't be empty", this);
|
||||
}
|
||||
if (parseMode != null && (entities != null && !entities.isEmpty()) ) {
|
||||
@ -151,4 +137,13 @@ public class SendMessage extends BotApiMethod<Message> {
|
||||
replyMarkup.validate();
|
||||
}
|
||||
}
|
||||
|
||||
public static class SendMessageBuilder {
|
||||
|
||||
@Tolerate
|
||||
public SendMessageBuilder chatId(@NonNull Long chatId) {
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user