Merge pull request #15 from rubenlagus/dev

Dev
This commit is contained in:
Andy Costanza 2021-01-29 11:23:35 +01:00 committed by GitHub
commit fe464e0092
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
252 changed files with 5953 additions and 12342 deletions

View File

@ -27,16 +27,16 @@ Just import add the library to your project with one of these options:
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>4.9.2</version>
<version>5.0.1</version>
</dependency>
```
```gradle
compile "org.telegram:telegrambots:4.9.2"
compile "org.telegram:telegrambots:5.0.1"
```
2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/4.9.2)
3. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/4.9.2)
2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/5.0.1)
3. Download the jar(including all dependencies) from [here](https://mvnrepository.com/artifact/org.telegram/telegrambots/5.0.1)
In order to use Long Polling mode, just create your own bot extending `org.telegram.telegrambots.bots.TelegramLongPollingBot`.
@ -50,9 +50,8 @@ Once done, you just need to create a `org.telegram.telegrambots.meta.TelegramBot
// Example taken from https://github.com/rubenlagus/TelegramBotsExample
public class Main {
public static void main(String[] args) {
ApiContextInitializer.init();
TelegramBotsApi telegramBotsApi = new TelegramBotsApi();
try {
TelegramBotsApi telegramBotsApi = new TelegramBotsApi(DefaultBotSession.class);
telegramBotsApi.registerBot(new ChannelHandlers());
telegramBotsApi.registerBot(new DirectionsHandlers());
telegramBotsApi.registerBot(new RaeHandlers());

View File

@ -1,3 +1,25 @@
### <a id="5.0.1"></a>5.0.1 ###
1. Fixing couple of bugs from 5.0.0
2. Buf fixing: #794
3. Docs updated to reflect usage for version 5.0.0
4. EditMessageText setChatIId(Long) is removed to keep consistency
### <a id="5.0.0"></a>5.0.0 ###
1. Update Api version [5.0](https://core.telegram.org/bots/api-changelog#november-4-2020)
2. Added Builders for many of the API methods and objects (hopefully all of them unless I missed something)
3. Some setters/getters may have change name. They no longer return a reference to itself, use Builder for that.
4. Simplified methods to set files in methods. Only InputFile is available now (this class contains constructors for all the cases)
5. Locations now use Double instead of Float to avoid rounding.
6. When using a TelegramApi for webhook usage, a Webhook instance has to be provided in constructor (i.e. DefaultWebhook class)
6. When registering a Webhook Bot, a SetWebhook object must be provided.
7. When using Webhook with Spring, extends class SpringWebhookBot instead of WebhookBot
8. New Async methods returning CompletableFutures (yes, we still have the existing callback methods)
9. Added new Async methods for missing cases returning CompletableFutures. Like for sendAudio or sendVideo.
10. No more Guice to define custom class
11. Bug fixes: #795
**[[How to update to version 5.0.0|How-To-Update#5.0.0]]**
### <a id="4.9.2"></a>4.9.2 ###
1. Bug fixing: #792, #801, #804, #810, #812, #813, #820 and #814

View File

@ -4,10 +4,3 @@
## <a id="terminted_by_other"></a>Terminated by other long poll or webhook ##
It means that you have already a running instance of your bot. To solve it, close all running ones and then you can start a new instance.
## <a id="no_implementation_was_bound"></a>No implementation for org.telegram.meta.telegrambots.generics.BotSession was bound ##
Please follow the steps as explained [here](https://github.com/rubenlagus/TelegramBots/wiki/How-To-Update#to-version-243) in "How To Update"
> At the beginning of your program (before creating your TelegramBotsApi instance, add the following line:
```
ApiContextInitializer.init();
```

View File

@ -79,29 +79,29 @@ Quick example here that is showing ChactActions for commands like "/type" or "/r
```java
if (update.hasMessage() && update.getMessage().hasText()) {
String text = update.getMessage().getText();
String text = update.getMessage().getText();
SendChatAction sendChatAction = new SendChatAction();
sendChatAction.setChatId(update.getMessage().getChatId());
SendChatAction sendChatAction = new SendChatAction();
sendChatAction.setChatId(update.getMessage().getChatId());
if (text.equals("/type")) {
// -> "typing"
sendChatAction.setAction(ActionType.TYPING);
// -> "recording a voice message"
} else if (text.equals("/record_audio")) {
sendChatAction.setAction(ActionType.RECORDAUDIO);
} else {
// -> more actions in the Enum ActionType
// For information: https://core.telegram.org/bots/api#sendchataction
sendChatAction.setAction(ActionType.UPLOADDOCUMENT);
}
if (text.equals("/type")) {
// -> "typing"
sendChatAction.setAction(ActionType.TYPING);
// -> "recording a voice message"
} else if (text.equals("/record_audio")) {
sendChatAction.setAction(ActionType.RECORDAUDIO);
} else {
// -> more actions in the Enum ActionType
// For information: https://core.telegram.org/bots/api#sendchataction
sendChatAction.setAction(ActionType.UPLOADDOCUMENT);
}
try {
Boolean wasSuccessfull = execute(sendChatAction);
} catch (TelegramApiException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
Boolean wasSuccessfull = execute(sendChatAction);
} catch (TelegramApiException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
```
@ -116,7 +116,7 @@ There are several method to send a photo to an user using `sendPhoto` method: Wi
// Set destination chat id
sendPhotoRequest.setChatId(chatId);
// Set the photo url as a simple photo
sendPhotoRequest.setPhoto(url);
sendPhotoRequest.setPhoto(new InputFile(url));
try {
// Execute the method
execute(sendPhotoRequest);
@ -131,7 +131,7 @@ There are several method to send a photo to an user using `sendPhoto` method: Wi
// Set destination chat id
sendPhotoRequest.setChatId(chatId);
// Set the photo url as a simple photo
sendPhotoRequest.setPhoto(fileId);
sendPhotoRequest.setPhoto(new InputFile(fileId));
try {
// Execute the method
execute(sendPhotoRequest);
@ -145,8 +145,8 @@ There are several method to send a photo to an user using `sendPhoto` method: Wi
SendPhoto sendPhotoRequest = new SendPhoto();
// Set destination chat id
sendPhotoRequest.setChatId(chatId);
// Set the photo file as a new photo (You can also use InputStream with a method overload)
sendPhotoRequest.setNewPhoto(new File(filePath));
// Set the photo file as a new photo (You can also use InputStream with a constructor overload)
sendPhotoRequest.setPhoto(new InputFile(new File(filePath)));
try {
// Execute the method
execute(sendPhotoRequest);
@ -162,24 +162,23 @@ In this example we will check if user sends to bot a photo, if it is, get Photo'
```java
// If it is a photo
if (update.hasMessage() && update.getMessage().hasPhoto()) {
// Array with photos
List<PhotoSize> photos = update.getMessage().getPhoto();
// Get largest photo's file_id
String f_id = photos.stream()
.sorted(Comparator.comparing(PhotoSize::getFileSize).reversed())
.findFirst()
.orElse(null).getFileId();
// Send photo by file_id we got before
SendPhoto msg = new SendPhoto()
.setChatId(update.getMessage().getChatId())
.setPhoto(f_id)
.setCaption("Photo");
try {
execute(msg); // Call method to send the photo
} catch (TelegramApiException e) {
e.printStackTrace();
}
}
// Array with photos
List<PhotoSize> photos = update.getMessage().getPhoto();
// Get largest photo's file_id
String f_id = photos.stream()
.max(Comparator.comparing(PhotoSize::getFileSize))
.orElseThrow().getFileId();
// Send photo by file_id we got before
SendPhoto msg = new SendPhoto()
.setChatId(update.getMessage().getChatId())
.setPhoto(new InputFile(f_id))
.setCaption("Photo");
try {
execute(msg); // Call method to send the photo
} catch (TelegramApiException e) {
e.printStackTrace();
}
}
```
## <a id="how_to_use_custom_keyboards"></a>How to use custom keyboards? ##
@ -264,12 +263,9 @@ Your main spring boot class should look like this:
@SpringBootApplication
public class YourApplicationMainClass {
public static void main(String[] args) {
//Add this line to initialize bots context
ApiContextInitializer.init();
SpringApplication.run(YourApplicationMainClass.class, args);
}
public static void main(String[] args) {
SpringApplication.run(YourApplicationMainClass.class, args);
}
}
```

View File

@ -11,13 +11,13 @@ First you need ot get the library and add it to your project. There are few poss
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>4.9.2</version>
<version>5.0.1</version>
</dependency>
```
* With **Gradle**:
```groovy
compile group: 'org.telegram', name: 'telegrambots', version: '4.9.2'
compile group: 'org.telegram', name: 'telegrambots', version: '5.0.1'
```
2. Don't like **Maven Central Repository**? It can also be taken from [Jitpack](https://jitpack.io/#rubenlagus/TelegramBots).
@ -98,15 +98,13 @@ Now that we have the library, we can start coding. There are few steps to follow
```
2. **Instantiate `TelegramBotsApi` and register our new bot:**
For this part, we need to actually perform 3 steps: _Initialize Api Context_, _Instantiate Telegram Api_ and _Register our Bot_. In this tutorial, we are going to make it in our `main` method:
For this part, we need to actually perform 2 steps: _Instantiate Telegram Api_ and _Register our Bot_. In this tutorial, we are going to make it in our `main` method:
```java
public class Main {
public static void main(String[] args) {
// TODO Initialize Api Context
// TODO Instantiate Telegram Bots API
// TODO Register our bot
@ -115,33 +113,14 @@ Now that we have the library, we can start coding. There are few steps to follow
```
* **Initialize Api Context**: This can be easily done calling the only method present in `ApiContextInitializer`:
```java
public class Main {
public static void main(String[] args) {
ApiContextInitializer.init();
// TODO Instantiate Telegram Bots API
// TODO Register our bot
}
}
```
* **Instantiate Telegram Bots API**: Easy as well, just create a new instance. Remember that a single instance can handle different bots but each bot can run only once (Telegram doesn't support concurrent calls to `GetUpdates`):
```java
public class Main {
public static void main(String[] args) {
ApiContextInitializer.init();
TelegramBotsApi botsApi = new TelegramBotsApi();
// You can use your own BotSession implementation if needed.
TelegramBotsApi botsApi = new TelegramBotsApi(DefaultBotSession.class);
// TODO Register our bot
}
@ -156,11 +135,8 @@ Now that we have the library, we can start coding. There are few steps to follow
public class Main {
public static void main(String[] args) {
ApiContextInitializer.init();
TelegramBotsApi botsApi = new TelegramBotsApi();
try {
TelegramBotsApi botsApi = new TelegramBotsApi(DefaultBotSession.class);
botsApi.registerBot(new MyAmazingBot());
} catch (TelegramApiException e) {
e.printStackTrace();

View File

@ -1,3 +1,111 @@
### <a id="5.0.0"></a>To version 5.0.0 ###
1. ApiContextInitializer.init(); has been removed and is not required anymore, instead:
```java
TelegramBotsApi telegramBotsApi = new TelegramBotsApi(DefaultBotSession.class);
// When using webhook, create your own version of DefaultWebhook with all your parameters set.
TelegramBotsApi telegramBotsApi = new TelegramBotsApi(DefaultBotSession.class, defaultWebhookInstance);
```
2. For location related class, change from Float to Double type, i.e:
```java
Double latitude = location.getLatitude()
```
3. Instead of chain set method, use builder pattern:
```java
// Before
new SendMessage()
.setChatId("@test")
.setText("Hithere")
.setReplyToMessageId(12)
.setParseMode(ParseMode.HTML)
.setReplyMarkup(new ForceReplyKeyboard())
// After
SendMessage
.builder()
.chatId("@test")
.text("Hithere")
.replyToMessageId(12)
.parseMode(ParseMode.HTML)
.replyMarkup(new ForceReplyKeyboard())
.build();
```
4. Method doesn't accept chatId as Long any more, only as a String. Use Long.toString(...) when needed I.e:
```java
Long chatIdLong = message.getChatId();
SendMessage
.builder()
.chatId(Long.toString(chatIdLong))
.text("Hithere")
.build();
```
5. When registering a Webhook bot, provide the SetWebhook method object:
```java
TelegramBotsApi telegramBotsApi = new TelegramBotsApi(DefaultBotSession.class, defaultWebhookInstance);
telegramApi.registerBot(myWebhookBot, mySetWebhook);
```
6. When using Spring with a webhook bot, make your bot inherit form SpringWebhookBot instead of WebhookBot and provide your SetWebhook method in the constructor:
```java
// Extend correct class
public class TestSpringWebhookBot extends SpringWebhookBot {
public TestSpringWebhookBot(SetWebhook setWebhook) {
super(setWebhook);
}
public TestSpringWebhookBot(DefaultBotOptions options, SetWebhook setWebhook) {
super(options, setWebhook);
}
@Override
public String getBotUsername() {
return null;
}
@Override
public String getBotToken() {
return null;
}
@Override
public BotApiMethod onWebhookUpdateReceived(Update update) {
return null;
}
@Override
public String getBotPath() {
return null;
}
}
// Create your SetWebhook method
@Bean
public SetWebhook setWebhookInstance() {
return SetWebhook.builder()....build();
}
// Create it as
@Bean
public TestSpringWebhookBot testSpringWebhookBot(SetWebhook setWebhookInstance) {
return new TestSpringWebhookBot(setWebhookInstance);
}
```
7. Use InputFile to set files to upload instead of different setters, i.e:
```java
// With a file
SendDocument
.builder()
.chatId("123456")
.document(new InputFile(new File("Filename.pdf")))
.build()
// With a Stream
SendDocument
.builder()
.chatId("123456")
.document(new InputFile("FileName", new FileInputStream("Filename.pdf")))
.build()
```
### <a id="4.4.0.2"></a>To version 4.4.0.2 ###
1. Logging framework has been replaced by slf4j, so now you'll need to manage your own implementation.

View File

@ -44,14 +44,11 @@ public class Main {
public static void main(String[] args) {
try {
ApiContextInitializer.init();
// Create the TelegramBotsApi object to register your bots
TelegramBotsApi botsApi = new TelegramBotsApi();
TelegramBotsApi botsApi = new TelegramBotsApi(DefaultBotSessioin.class);
// Set up Http proxy
DefaultBotOptions botOptions = ApiContext.getInstance(DefaultBotOptions.class);
DefaultBotOptions botOptions = new DefaultBotOptions());
botOptions.setProxyHost(PROXY_HOST);
botOptions.setProxyPort(PROXY_PORT);
@ -96,13 +93,11 @@ public class Main {
}
});
ApiContextInitializer.init();
// Create the TelegramBotsApi object to register your bots
TelegramBotsApi botsApi = new TelegramBotsApi();
TelegramBotsApi botsApi = new TelegramBotsApi(DefaultBotSession.class);
// Set up Http proxy
DefaultBotOptions botOptions = ApiContext.getInstance(DefaultBotOptions.class);
DefaultBotOptions botOptions = new DefaultBotOptions();
botOptions.setProxyHost(PROXY_HOST);
botOptions.setProxyPort(PROXY_PORT);

View File

@ -9,12 +9,12 @@ As with any Java project, you will need to set your dependencies.
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-abilities</artifactId>
<version>4.9.2</version>
<version>5.0.1</version>
</dependency>
```
* **Gradle**
```groovy
implementation group: 'org.telegram', name: 'telegrambots-abilities', version: '4.9.2'
implementation group: 'org.telegram', name: 'telegrambots-abilities', version: '5.0.1'
```
* [JitPack](https://jitpack.io/#rubenlagus/TelegramBots)
@ -81,13 +81,10 @@ Running the bot is just like running the regular Telegram bots. Create a Java cl
```java
public class Application {
public static void main(String[] args) {
// Initializes dependencies necessary for the base bot - Guice
ApiContextInitializer.init();
// Create the TelegramBotsApi object to register your bots
TelegramBotsApi botsApi = new TelegramBotsApi();
try {
// Create the TelegramBotsApi object to register your bots
TelegramBotsApi botsApi = new TelegramBotsApi(DefaultBotSession.class);
// Register your newly created AbilityBot
botsApi.registerBot(new HelloBot());
} catch (TelegramApiException e) {

42
pom.xml
View File

@ -7,7 +7,7 @@
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<packaging>pom</packaging>
<version>4.9.2</version>
<version>5.0.1</version>
<modules>
<module>telegrambots</module>
@ -67,17 +67,26 @@
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<junit.version>5.5.2</junit.version>
<mockito.version>3.1.0</mockito.version>
<mockitojupiter.version>3.1.0</mockitojupiter.version>
<jacksonbase.version>2.10.1</jacksonbase.version>
<jackson.version>2.10.1</jackson.version>
<slf4j.version>1.7.29</slf4j.version>
<junit.version>5.7.0</junit.version>
<mockito.version>3.6.0</mockito.version>
<mockitojupiter.version>3.6.0</mockitojupiter.version>
<jacksonanotation.version>2.11.3</jacksonanotation.version>
<jackson.version>2.11.3</jackson.version>
<json.version>20180813</json.version>
<slf4j.version>1.7.30</slf4j.version>
<jakarta.annotation.version>1.3.5</jakarta.annotation.version>
<lombok.version>1.18.16</lombok.version>
<guava.version>30.0-jre</guava.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
@ -99,12 +108,22 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jacksonbase.version}</version>
<version>${jacksonanotation.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jaxb-annotations</artifactId>
<version>${jacksonbase.version}</version>
<version>${jacksonanotation.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>${jacksonanotation.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
@ -116,6 +135,11 @@
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>${json.version}</version>
</dependency>
<!-- Included to enforce common version-->
<dependency>
<groupId>jakarta.annotation</groupId>

View File

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

View File

@ -7,7 +7,7 @@
<parent>
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<version>4.9.2</version>
<version>5.0.1</version>
</parent>
<artifactId>telegrambots-abilities</artifactId>
@ -76,15 +76,15 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<commonslang.version>3.9</commonslang.version>
<mapdb.version>3.0.7</mapdb.version>
<commonslang.version>3.11</commonslang.version>
<mapdb.version>3.0.8</mapdb.version>
</properties>
<dependencies>
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>4.9.2</version>
<version>5.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>

View File

@ -3,11 +3,12 @@ package org.telegram.abilitybots.api.bot;
import org.telegram.abilitybots.api.db.DBContext;
import org.telegram.abilitybots.api.toggle.AbilityToggle;
import org.telegram.abilitybots.api.toggle.DefaultToggle;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.bots.DefaultBotOptions;
import org.telegram.telegrambots.bots.TelegramWebhookBot;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.methods.updates.SetWebhook;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.meta.generics.WebhookBot;
import org.telegram.telegrambots.util.WebhookUtils;
@ -63,8 +64,8 @@ public abstract class AbilityWebhookBot extends BaseAbilityBot implements Webhoo
}
@Override
public void setWebhook(String url, String publicCertificatePath) throws TelegramApiRequestException {
WebhookUtils.setWebhook(this, url, publicCertificatePath);
public void setWebhook(SetWebhook setWebhook) throws TelegramApiException {
WebhookUtils.setWebhook(this, setWebhook);
}
@Override

View File

@ -258,7 +258,7 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability
}
public boolean isGroupAdmin(long chatId, int id) {
GetChatAdministrators admins = new GetChatAdministrators().setChatId(chatId);
GetChatAdministrators admins = GetChatAdministrators.builder().chatId(Long.toString(chatId)).build();
return silent.execute(admins)
.orElse(new ArrayList<>()).stream()
.anyMatch(member -> member.getUser().getId() == id);

View File

@ -14,6 +14,7 @@ import org.telegram.abilitybots.api.util.AbilityUtils;
import org.telegram.abilitybots.api.util.Pair;
import org.telegram.telegrambots.meta.api.methods.GetFile;
import org.telegram.telegrambots.meta.api.methods.send.SendDocument;
import org.telegram.telegrambots.meta.api.objects.InputFile;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.api.objects.User;
@ -221,9 +222,10 @@ public final class DefaultAbilities implements AbilityExtension {
try (PrintStream printStream = new PrintStream(backup)) {
printStream.print(bot.db.backup());
bot.sender.sendDocument(new SendDocument()
.setDocument(backup)
.setChatId(ctx.chatId())
bot.sender.sendDocument(SendDocument.builder()
.document(new InputFile(backup))
.chatId(ctx.chatId().toString())
.build()
);
} catch (FileNotFoundException e) {
log.error("Error while fetching backup", e);
@ -472,6 +474,6 @@ public final class DefaultAbilities implements AbilityExtension {
}
protected File downloadFileWithId(String fileId) throws TelegramApiException {
return bot.sender.downloadFile(bot.sender.execute(new GetFile().setFileId(fileId)));
return bot.sender.downloadFile(bot.sender.execute(GetFile.builder().fileId(fileId).build()));
}
}

View File

@ -38,7 +38,7 @@ public class SilentSender {
public Optional<Message> forceReply(String message, long id) {
SendMessage msg = new SendMessage();
msg.setText(message);
msg.setChatId(id);
msg.setChatId(Long.toString(id));
msg.setReplyMarkup(new ForceReplyKeyboard());
return execute(msg);
@ -64,7 +64,7 @@ public class SilentSender {
private Optional<Message> doSendMessage(String txt, long groupId, boolean format) {
SendMessage smsg = new SendMessage();
smsg.setChatId(groupId);
smsg.setChatId(Long.toString(groupId));
smsg.setText(txt);
smsg.enableMarkdown(format);

View File

@ -25,7 +25,7 @@ import static org.telegram.abilitybots.api.objects.Flag.*;
* Helper and utility methods
*/
public final class AbilityUtils {
public static User EMPTY_USER = new User(0, "", false, "", "", "");
public static User EMPTY_USER = new User(0, "", false);
private AbilityUtils() {
@ -37,7 +37,7 @@ public final class AbilityUtils {
*/
public static String stripTag(String username) {
String lowerCase = username.toLowerCase();
return lowerCase.startsWith("@") ? lowerCase.substring(1, lowerCase.length()) : lowerCase;
return lowerCase.startsWith("@") ? lowerCase.substring(1) : lowerCase;
}
/**
@ -252,7 +252,7 @@ public final class AbilityUtils {
* The full name is identified as the concatenation of the first and last name, separated by a space.
* This method can return an empty name if both first and last name are empty.
*
* @param user
* @param user User to use
* @return the full name of the user
*/
public static String fullName(User user) {

View File

@ -19,8 +19,8 @@ import static org.telegram.abilitybots.api.bot.TestUtils.mockContext;
import static org.telegram.abilitybots.api.db.MapDBContext.offlineInstance;
class AbilityBotI18nTest {
private static final User NO_LANGUAGE_USER = new User(1, "first", false, "last", "username", null);
private static final User ITALIAN_USER = new User(2, "first", false, "last", "username", "it-IT");
private static final User NO_LANGUAGE_USER = new User(1, "first", false, "last", "username", null, false, false, false);
private static final User ITALIAN_USER = new User(2, "first", false, "last", "username", "it-IT", false, false, false);
private DBContext db;
private NoPublicCommandsBot bot;

View File

@ -351,7 +351,7 @@ public class AbilityBotTest {
String newFirstName = USER.getFirstName() + "-test";
String newLastName = USER.getLastName() + "-test";
int sameId = USER.getId();
User changedUser = new User(sameId, newFirstName, false, newLastName, newUsername, null);
User changedUser = new User(sameId, newFirstName, false, newLastName, newUsername, "en", false, false, false);
mockAlternateUser(update, message, changedUser);
@ -515,6 +515,7 @@ public class AbilityBotTest {
assertTrue(bot.checkGlobalFlags(update), "Unexpected result when checking for the default global flags");
}
@SuppressWarnings({"NumericOverflow", "divzero"})
@Test
void canConsumeUpdate() {
Ability ability = getDefaultBuilder()
@ -701,6 +702,7 @@ public class AbilityBotTest {
Message botMessage = mock(Message.class);
Document document = mock(Document.class);
when(document.getFileId()).thenReturn("FAKEFILEID");
when(message.getFrom()).thenReturn(CREATOR);
when(update.getMessage()).thenReturn(message);
when(message.getDocument()).thenReturn(document);

View File

@ -22,7 +22,7 @@ import static org.telegram.abilitybots.api.objects.Locality.ALL;
import static org.telegram.abilitybots.api.objects.Privacy.PUBLIC;
public class ContinuousTextTest {
private static final User USER = new User(1, "first", false, "last", "username", null);
private static final User USER = new User(1, "first", false);
private DBContext db;

View File

@ -11,8 +11,8 @@ import static org.mockito.Mockito.when;
import static org.telegram.abilitybots.api.objects.MessageContext.newContext;
public final class TestUtils {
public static final User USER = new User(1, "first", false, "last", "username", null);
public static final User CREATOR = new User(1337, "creatorFirst", false, "creatorLast", "creatorUsername", null);
public static final User USER = new User(1, "first", false, "last", "username", null, false, false, false);
public static final User CREATOR = new User(1337, "creatorFirst", false, "creatorLast", "creatorUsername", null, false, false, false);
private TestUtils() {

View File

@ -15,7 +15,7 @@ Usage
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-chat-session-bot</artifactId>
<version>4.9.2</version>
<version>5.0.1</version>
</dependency>
```

View File

@ -7,7 +7,7 @@
<parent>
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<version>4.9.2</version>
<version>5.0.1</version>
</parent>
<artifactId>telegrambots-chat-session-bot</artifactId>
@ -76,7 +76,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<shiro.version>1.4.2</shiro.version>
<shiro.version>1.7.0</shiro.version>
</properties>
<dependencies>
@ -84,7 +84,7 @@
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>4.9.2</version>
<version>5.0.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.shiro/shiro-core -->

View File

@ -6,7 +6,6 @@ import org.apache.shiro.session.mgt.DefaultSessionManager;
import org.apache.shiro.session.mgt.SessionContext;
import org.apache.shiro.session.mgt.eis.AbstractSessionDAO;
import org.telegram.telegrambots.bots.DefaultBotOptions;
import org.telegram.telegrambots.meta.ApiContext;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
@ -24,7 +23,7 @@ public abstract class TelegramLongPollingSessionBot extends TelegramLongPollingB
}
public TelegramLongPollingSessionBot(ChatIdConverter chatIdConverter){
this(chatIdConverter, ApiContext.getInstance(DefaultBotOptions.class));
this(chatIdConverter, new DefaultBotOptions());
}
public TelegramLongPollingSessionBot(ChatIdConverter chatIdConverter, DefaultBotOptions defaultBotOptions){

View File

@ -16,12 +16,12 @@ Just import add the library to your project with one of these options:
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambotsextensions</artifactId>
<version>4.9.2</version>
<version>5.0.1</version>
</dependency>
```
2. Using Gradle:
```gradle
compile "org.telegram:telegrambotsextensions:4.9.2"
compile "org.telegram:telegrambotsextensions:5.0.1"
```

View File

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

View File

@ -1,7 +1,6 @@
package org.telegram.telegrambots.extensions.bots.commandbot;
import org.telegram.telegrambots.meta.ApiContext;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.bots.AbsSender;
@ -29,7 +28,7 @@ public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingB
*
*/
public TelegramLongPollingCommandBot() {
this(ApiContext.getInstance(DefaultBotOptions.class));
this(new DefaultBotOptions());
}
/**

View File

@ -24,21 +24,6 @@ public final class CommandRegistry implements ICommandRegistry {
private final Supplier<String> botUsernameSupplier;
private BiConsumer<AbsSender, Message> defaultConsumer;
/**
* Creates a Command registry
*
* @param allowCommandsWithUsername True to allow commands with username, false otherwise
* @param botUsername Bot username
* @throws java.lang.NullPointerException if {@code botUsername} is {@code null}
* @deprecated Use {@link #CommandRegistry(boolean, java.util.function.Supplier)} instead
*/
@Deprecated
public CommandRegistry(boolean allowCommandsWithUsername, String botUsername) {
Objects.requireNonNull(botUsername, "Bot username must not be null");
this.allowCommandsWithUsername = allowCommandsWithUsername;
this.botUsernameSupplier = () -> botUsername;
}
/**
* Creates a Command registry
* @param allowCommandsWithUsername True to allow commands with username, false otherwise
@ -103,7 +88,7 @@ public final class CommandRegistry implements ICommandRegistry {
/**
* Executes a command action if the command is registered.
*
* @note If the command is not registered and there is a default consumer,
* @apiNote If the command is not registered and there is a default consumer,
* that action will be performed
*
* @param absSender absSender

View File

@ -98,14 +98,14 @@ public class HelpCommand extends ManCommand {
IBotCommand command = registry.getRegisteredCommand(arguments[0]);
String reply = getManText(command);
try {
absSender.execute(new SendMessage(chat.getId(), reply).setParseMode("HTML"));
absSender.execute(SendMessage.builder().chatId(chat.getId().toString()).text(reply).parseMode("HTML").build());
} catch (TelegramApiException e) {
e.printStackTrace();
}
} else {
String reply = getHelpText(registry);
try {
absSender.execute(new SendMessage(chat.getId(), reply).setParseMode("HTML"));
absSender.execute(SendMessage.builder().chatId(chat.getId().toString()).text(reply).parseMode("HTML").build());
} catch (TelegramApiException e) {
e.printStackTrace();
}

View File

@ -11,9 +11,9 @@ import java.util.concurrent.atomic.AtomicBoolean;
* Created by Daniil Nikanov aka JetCoder
*/
@SuppressWarnings("unused")
public abstract class TimedSendLongPollingBot extends TelegramLongPollingBot
{
private static final long MANY_CHATS_SEND_INTERVAL = 33;
private static final long ONE_CHAT_SEND_INTERVAL = 1000;
private static final long CHAT_INACTIVE_INTERVAL = 1000 * 60 * 10;
private final Timer mSendTimer = new Timer(true);
@ -21,29 +21,85 @@ public abstract class TimedSendLongPollingBot extends TelegramLongPollingBot
private final ArrayList<MessageQueue> mSendQueues = new ArrayList<>();
private final AtomicBoolean mSendRequested = new AtomicBoolean(false);
private final class MessageSenderTask extends TimerTask
{
@Override
public void run()
{
//mSendRequested used for optimisation to not traverse all mMessagesMap 30 times per second all the time
if (!mSendRequested.getAndSet(false))
return;
long currentTime = System.currentTimeMillis();
mSendQueues.clear();
boolean processNext = false;
//First step - find all chats in which already allowed to send message (passed more than 1000 ms from previuos send)
Iterator<Map.Entry<Long,MessageQueue>> it = mMessagesMap.entrySet().iterator();
while (it.hasNext())
{
MessageQueue queue = it.next().getValue();
int state = queue.getCurrentState(currentTime); //Actual check here
if (state == MessageQueue.GET_MESSAGE)
{
mSendQueues.add(queue);
processNext = true;
}
else if (state == MessageQueue.WAIT)
{
processNext = true;
}
else if (state == MessageQueue.DELETE)
{
it.remove();
}
}
//If any of chats are in state WAIT or GET_MESSAGE, request another iteration
if (processNext)
mSendRequested.set(true);
//Second step - find oldest waiting queue and peek it's message
MessageQueue sendQueue = null;
long oldestPutTime = Long.MAX_VALUE;
for (MessageQueue queue : mSendQueues) {
long putTime = queue.getPutTime();
if (putTime < oldestPutTime) {
oldestPutTime = putTime;
sendQueue = queue;
}
}
if (sendQueue == null) //Possible if on first step wasn't found any chats in state GET_MESSAGE
return;
//Invoke the send callback. ChatId is passed for possible additional processing
sendMessageCallback(sendQueue.getChatId(), sendQueue.getMessage(currentTime));
}
}
private static class MessageQueue
{
static final int EMPTY = 0; //Queue is empty
static final int WAIT = 1; //Queue has message(s) but not yet allowed to send
static final int DELETE = 2; //No one message of given queue was sent longer than CHAT_INACTIVE_INTERVAL, delete for optimisation
static final int GET_MESSAGE = 3; //Queue has message(s) and ready to send
public static final int EMPTY = 0; //Queue is empty
public static final int WAIT = 1; //Queue has message(s) but not yet allowed to send
public static final int DELETE = 2; //No one message of given queue was sent longer than CHAT_INACTIVE_INTERVAL, delete for optimisation
public static final int GET_MESSAGE = 3; //Queue has message(s) and ready to send
private final ConcurrentLinkedQueue<Object> mQueue = new ConcurrentLinkedQueue<>();
private final Long mChatId;
private long mLastSendTime; //Time of last peek from queue
private volatile long mLastPutTime; //Time of last put into queue
MessageQueue(Long chatId)
public MessageQueue(Long chatId)
{
mChatId = chatId;
}
synchronized void putMessage(Object msg)
public synchronized void putMessage(Object msg)
{
mQueue.add(msg);
mLastPutTime = System.currentTimeMillis();
}
synchronized int getCurrentState(long currentTime)
public synchronized int getCurrentState(long currentTime)
{
//currentTime is passed as parameter for optimisation to do not recall currentTimeMillis() many times
long interval = currentTime - mLastSendTime;
@ -58,23 +114,29 @@ public abstract class TimedSendLongPollingBot extends TelegramLongPollingBot
return WAIT;
}
synchronized Object getMessage(long currentTime)
public synchronized Object getMessage(long currentTime)
{
mLastSendTime = currentTime;
return mQueue.poll();
}
long getPutTime()
public long getPutTime()
{
return mLastPutTime;
}
Long getChatId()
public Long getChatId()
{
return mChatId;
}
}
//Constructor
protected TimedSendLongPollingBot()
{
mSendTimer.schedule(new MessageSenderTask(), MANY_CHATS_SEND_INTERVAL, MANY_CHATS_SEND_INTERVAL);
}
//Something like destructor
public void finish()
{
@ -149,5 +211,5 @@ public abstract class TimedSendLongPollingBot extends TelegramLongPollingBot
}
}
*/
abstract void sendMessageCallback(Long chatId, Object messageRequest);
public abstract void sendMessageCallback(Long chatId, Object messageRequest);
}

View File

@ -8,15 +8,6 @@ import org.telegram.telegrambots.meta.bots.AbsSender;
class CommandRegistryTest {
@Test
void should_create_registry() {
CommandRegistry registry = new CommandRegistry(true, "BotUsername");
Assertions.assertNotNull(registry, "CommandRegistry is not created");
NullPointerException exception = Assertions.assertThrows(NullPointerException.class,
() -> new CommandRegistry(true, (String) null));
Assertions.assertEquals("Bot username must not be null", exception.getMessage(), "Invalid exception message");
}
@Test
void should_executes_commandWithBotUsername() {
CommandRegistry registry = new CommandRegistry(true, () -> "BotUsername");

View File

@ -7,7 +7,7 @@
<parent>
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<version>4.9.2</version>
<version>5.0.1</version>
</parent>
<artifactId>telegrambots-meta</artifactId>
@ -69,29 +69,12 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<guice.version>4.2.2</guice.version>
<jackson.version>2.10.1</jackson.version>
<jacksonanotation.version>2.10.1</jacksonanotation.version>
<json.version>20180813</json.version>
<guava.version>28.1-jre</guava.version>
</properties>
<dependencies>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>${guice.version}</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
@ -102,18 +85,21 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jacksonanotation.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>${json.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>

View File

@ -1,67 +0,0 @@
package org.telegram.telegrambots.meta;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Singleton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
/**
* @author Ruben Bermudez
* @version 1.0
*/
public class ApiContext {
private static final Logger log = LoggerFactory.getLogger(ApiContext.class);
private static final Object lock = new Object();
private static Injector INJECTOR;
private static Map<Class, Class> bindings = new HashMap<>();
private static Map<Class, Class> singletonBindings = new HashMap<>();
public static <T> T getInstance(Class<T> type) {
return getInjector().getInstance(type);
}
public static <T, S extends T> void register(Class<T> type, Class<S> implementation) {
if (bindings.containsKey(type)) {
log.debug(MessageFormat.format("Class {0} already registered", type.getName()));
}
bindings.put(type, implementation);
}
public static <T, S extends T> void registerSingleton(Class<T> type, Class<S> implementation) {
if (singletonBindings.containsKey(type)) {
log.debug(MessageFormat.format("Class {0} already registered", type.getName()));
}
singletonBindings.put(type, implementation);
}
private static Injector getInjector() {
if (INJECTOR == null) {
synchronized (lock) {
if (INJECTOR == null) {
INJECTOR = Guice.createInjector(new ApiModule());
}
}
}
return INJECTOR;
}
@SuppressWarnings("unchecked")
private static class ApiModule extends AbstractModule {
@Override
protected void configure() {
for (Map.Entry<Class, Class> binding : bindings.entrySet()) {
bind(binding.getKey()).to(binding.getValue());
}
for (Map.Entry<Class, Class> binding : singletonBindings.entrySet()) {
bind(binding.getKey()).to(binding.getValue()).in(Singleton.class);
}
}
}
}

View File

@ -1,125 +1,68 @@
package org.telegram.telegrambots.meta;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.api.methods.updates.SetWebhook;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.meta.generics.BotSession;
import org.telegram.telegrambots.meta.generics.LongPollingBot;
import org.telegram.telegrambots.meta.generics.Webhook;
import org.telegram.telegrambots.meta.generics.WebhookBot;
import java.text.MessageFormat;
import java.lang.reflect.InvocationTargetException;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief Bots manager
* @date 14 of January of 2016
* Bots manager
*/
public class TelegramBotsApi {
private static final String webhookUrlFormat = "{0}callback/";
Class<? extends BotSession> botSessionClass;
private boolean useWebhook; ///< True to enable webhook usage
private Webhook webhook; ///< Webhook instance
private String externalUrl; ///< External url of the bots
private String pathToCertificate; ///< Path to public key certificate
/**
*
*/
public TelegramBotsApi() {
public TelegramBotsApi(Class<? extends BotSession> botSessionClass) throws TelegramApiException {
if (botSessionClass == null) {
throw new TelegramApiException("Parameter botSessionClass can not be null or empty");
}
this.botSessionClass = botSessionClass;
}
/**
* Creates an HTTP server to receive webhook request
* @param externalUrl External base url for the webhook
* @param internalUrl Internal base url for the webhook
* @param webhook Webhook class
*
* @implSpec This option requires externally handled HTTPS support (i.e. via proxy)
* @implSpec This option may require externally handled HTTPS support (i.e. via proxy)
*/
public TelegramBotsApi(String externalUrl, String internalUrl) throws TelegramApiRequestException {
if (externalUrl == null || externalUrl.isEmpty()) {
throw new TelegramApiRequestException("Parameter externalUrl can not be null or empty");
public TelegramBotsApi(Class<? extends BotSession> botSessionClass, Webhook webhook) throws TelegramApiException {
if (botSessionClass == null) {
throw new TelegramApiException("Parameter botSessionClass can not be null or empty");
}
if (internalUrl == null || internalUrl.isEmpty()) {
throw new TelegramApiRequestException("Parameter internalUrl can not be null or empty");
if (webhook == null) {
throw new TelegramApiException("Parameter webhook can not be null or empty");
}
this.botSessionClass = botSessionClass;
this.useWebhook = true;
this.externalUrl = fixExternalUrl(externalUrl);
webhook = ApiContext.getInstance(Webhook.class);
webhook.setInternalUrl(internalUrl);
webhook.startServer();
}
/**
* Creates an HTTPS server to receive webhook request
* @param keyStore KeyStore for the server
* @param keyStorePassword Key store password for the server
* @param externalUrl External base url for the webhook
* @param internalUrl Internal base url for the webhook
*/
public TelegramBotsApi(String keyStore, String keyStorePassword, String externalUrl, String internalUrl) throws TelegramApiRequestException {
if (externalUrl == null || externalUrl.isEmpty()) {
throw new TelegramApiRequestException("Parameter externalUrl can not be null or empty");
}
if (internalUrl == null || internalUrl.isEmpty()) {
throw new TelegramApiRequestException("Parameter internalUrl can not be null or empty");
}
if (keyStore == null || keyStore.isEmpty()) {
throw new TelegramApiRequestException("Parameter keyStore can not be null or empty");
}
if (keyStorePassword == null || keyStorePassword.isEmpty()) {
throw new TelegramApiRequestException("Parameter keyStorePassword can not be null or empty");
}
this.useWebhook = true;
this.externalUrl = fixExternalUrl(externalUrl);
webhook = ApiContext.getInstance(Webhook.class);
webhook.setInternalUrl(internalUrl);
webhook.setKeyStore(keyStore, keyStorePassword);
webhook.startServer();
}
/**
* Creates an HTTPS server with self-signed certificate to receive webhook request
* @param keyStore KeyStore for the server
* @param keyStorePassword Key store password for the server
* @param externalUrl External base url for the webhook
* @param internalUrl Internal base url for the webhook
* @param pathToCertificate Full path until .pem public certificate keys
*/
public TelegramBotsApi(String keyStore, String keyStorePassword, String externalUrl, String internalUrl, String pathToCertificate) throws TelegramApiRequestException {
if (externalUrl == null || externalUrl.isEmpty()) {
throw new TelegramApiRequestException("Parameter externalUrl can not be null or empty");
}
if (internalUrl == null || internalUrl.isEmpty()) {
throw new TelegramApiRequestException("Parameter internalUrl can not be null or empty");
}
if (keyStore == null || keyStore.isEmpty()) {
throw new TelegramApiRequestException("Parameter keyStore can not be null or empty");
}
if (keyStorePassword == null || keyStorePassword.isEmpty()) {
throw new TelegramApiRequestException("Parameter keyStorePassword can not be null or empty");
}
if (pathToCertificate == null || pathToCertificate.isEmpty()) {
throw new TelegramApiRequestException("Parameter pathToCertificate can not be null or empty");
}
this.useWebhook = true;
this.externalUrl = fixExternalUrl(externalUrl);
this.pathToCertificate = pathToCertificate;
webhook = ApiContext.getInstance(Webhook.class);
webhook.setInternalUrl(internalUrl);
webhook.setKeyStore(keyStore, keyStorePassword);
webhook.startServer();
this.webhook = webhook;
this.webhook.startServer();
}
/**
* Register a bot. The Bot Session is started immediately, and may be disconnected by calling close.
* @param bot the bot to register
*/
public BotSession registerBot(LongPollingBot bot) throws TelegramApiRequestException {
public BotSession registerBot(LongPollingBot bot) throws TelegramApiException {
bot.onRegister();
bot.clearWebhook();
BotSession session = ApiContext.getInstance(BotSession.class);
BotSession session;
try {
session = botSessionClass.getConstructor().newInstance();
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) {
throw new TelegramApiException(e);
}
session.setToken(bot.getBotToken());
session.setOptions(bot.getOptions());
session.setCallback(bot);
@ -130,19 +73,19 @@ public class TelegramBotsApi {
/**
* Register a bot in the api that will receive updates using webhook method
* @param bot Bot to register
* @param setWebhook Set webhook request to initialize the bot
*/
public void registerBot(WebhookBot bot) throws TelegramApiRequestException {
public void registerBot(WebhookBot bot, SetWebhook setWebhook) throws TelegramApiException {
if (setWebhook == null) {
throw new TelegramApiException("Parameter setWebhook can not be null or empty");
}
if (useWebhook) {
if (webhook == null) {
throw new TelegramApiException("This instance doesn't support Webhook bot, use correct constructor");
}
bot.onRegister();
webhook.registerWebhook(bot);
bot.setWebhook(externalUrl + bot.getBotPath(), pathToCertificate);
bot.setWebhook(setWebhook);
}
}
private static String fixExternalUrl(String externalUrl) {
if (externalUrl != null && !externalUrl.endsWith("/")) {
externalUrl = externalUrl + "/";
}
return MessageFormat.format(webhookUrlFormat, externalUrl);
}
}

View File

@ -1,17 +0,0 @@
package org.telegram.telegrambots.meta.api.interfaces;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
/**
* @author Ruben Bermudez
* @version 1.0
* An object used in the Bots API to answer updates
*
* @deprecated Please, use BotApiObject directly
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
@Deprecated
public interface InputBotApiObject extends BotApiObject {
}

View File

@ -2,7 +2,15 @@ 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;
import lombok.Getter;
import lombok.NoArgsConstructor;
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;
@ -16,10 +24,18 @@ import java.io.IOException;
* will be displayed to the user as a notification at the top of the chat screen or as an alert. On
* success, True is returned.
*
* @note Alternatively, the user can be redirected to the specified URL. For this option to work,
* @apiNote Alternatively, the user can be redirected to the specified URL. For this option to work,
* you must enable /setcustomurls for your bot via BotFather and accept the terms.
*
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@RequiredArgsConstructor
@AllArgsConstructor
@Builder
public class AnswerCallbackQuery extends BotApiMethod<Boolean> {
public static final String PATH = "answercallbackquery";
@ -30,6 +46,7 @@ public class AnswerCallbackQuery extends BotApiMethod<Boolean> {
private static final String CACHETIME_FIELD = "cache_time";
@JsonProperty(CALLBACKQUERYID_FIELD)
@NonNull
private String callbackQueryId; ///< Unique identifier for the query to be answered
@JsonProperty(TEXT_FIELD)
private String text; ///< Optional Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters
@ -47,60 +64,11 @@ public class AnswerCallbackQuery extends BotApiMethod<Boolean> {
* Optional The maximum amount of time in seconds that the result of the callback query
* may be cached client-side.
*
* @note Telegram apps will support caching starting in version 3.14. Defaults to 0.
* @apiNote Telegram apps will support caching starting in version 3.14. Defaults to 0.
*/
@JsonProperty(CACHETIME_FIELD)
private Integer cacheTime;
public AnswerCallbackQuery() {
super();
}
public String getCallbackQueryId() {
return this.callbackQueryId;
}
public AnswerCallbackQuery setCallbackQueryId(String callbackQueryId) {
this.callbackQueryId = callbackQueryId;
return this;
}
public String getText() {
return this.text;
}
public AnswerCallbackQuery setText(String text) {
this.text = text;
return this;
}
public Boolean getShowAlert() {
return this.showAlert;
}
public AnswerCallbackQuery setShowAlert(Boolean showAlert) {
this.showAlert = showAlert;
return this;
}
public String getUrl() {
return url;
}
public AnswerCallbackQuery setUrl(String url) {
this.url = url;
return this;
}
public Integer getCacheTime() {
return cacheTime;
}
public AnswerCallbackQuery setCacheTime(Integer cacheTime) {
this.cacheTime = cacheTime;
return this;
}
@Override
public String getMethod() {
return PATH;
@ -127,15 +95,4 @@ public class AnswerCallbackQuery extends BotApiMethod<Boolean> {
throw new TelegramApiValidationException("CallbackQueryId can't be null", this);
}
}
@Override
public String toString() {
return "AnswerCallbackQuery{" +
"callbackQueryId='" + callbackQueryId + '\'' +
", text='" + text + '\'' +
", showAlert=" + showAlert +
", url='" + url + '\'' +
", cacheTime=" + cacheTime +
'}';
}
}

View File

@ -1,16 +1,23 @@
package org.telegram.telegrambots.meta.api.methods;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
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.RequiredArgsConstructor;
import lombok.Setter;
import lombok.Singular;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
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.Arrays;
import java.util.List;
import java.util.regex.Pattern;
@ -19,6 +26,14 @@ import java.util.regex.Pattern;
* @version 1.0
* Use this method to send answers to an inline query. On success, True is returned.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@RequiredArgsConstructor
@AllArgsConstructor
@Builder
public class AnswerInlineQuery extends BotApiMethod<Boolean> {
public static final String PATH = "answerInlineQuery";
@ -31,8 +46,11 @@ public class AnswerInlineQuery extends BotApiMethod<Boolean> {
private static final String SWITCH_PM_PARAMETER_FIELD = "switch_pm_parameter";
@JsonProperty(INLINEQUERYID_FIELD)
@NonNull
private String inlineQueryId; ///< Unique identifier for answered query
@JsonProperty(RESULTS_FIELD)
@Singular
@NonNull
private List<InlineQueryResult> results; ///< A JSON-serialized array of results for the inline query
@JsonProperty(CACHETIME_FIELD)
private Integer cacheTime; ///< Optional The maximum amount of time the result of the inline query may be cached on the server
@ -45,79 +63,6 @@ public class AnswerInlineQuery extends BotApiMethod<Boolean> {
@JsonProperty(SWITCH_PM_PARAMETER_FIELD)
private String switchPmParameter; ///< Optional. Parameter for the start message sent to the bot when user presses the switch button
public AnswerInlineQuery() {
super();
}
public String getInlineQueryId() {
return inlineQueryId;
}
public AnswerInlineQuery setInlineQueryId(String inlineQueryId) {
this.inlineQueryId = inlineQueryId;
return this;
}
public List<InlineQueryResult> getResults() {
return results;
}
public AnswerInlineQuery setResults(List<InlineQueryResult> results) {
this.results = results;
return this;
}
@JsonIgnore
public AnswerInlineQuery setResults(InlineQueryResult... results) {
this.results = Arrays.asList(results);
return this;
}
public Integer getCacheTime() {
return cacheTime;
}
public AnswerInlineQuery setCacheTime(Integer cacheTime) {
this.cacheTime = cacheTime;
return this;
}
public Boolean isPersonal() {
return isPersonal;
}
public AnswerInlineQuery setPersonal(Boolean personal) {
isPersonal = personal;
return this;
}
public String getNextOffset() {
return nextOffset;
}
public AnswerInlineQuery setNextOffset(String nextOffset) {
this.nextOffset = nextOffset;
return this;
}
public String getSwitchPmText() {
return switchPmText;
}
public AnswerInlineQuery setSwitchPmText(String switchPmText) {
this.switchPmText = switchPmText;
return this;
}
public String getSwitchPmParameter() {
return switchPmParameter;
}
public AnswerInlineQuery setSwitchPmParameter(String switchPmParameter) {
this.switchPmParameter = switchPmParameter;
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (inlineQueryId == null || inlineQueryId.isEmpty()) {
@ -164,17 +109,4 @@ public class AnswerInlineQuery extends BotApiMethod<Boolean> {
throw new TelegramApiRequestException("Unable to deserialize response", e);
}
}
@Override
public String toString() {
return "AnswerInlineQuery{" +
"inlineQueryId='" + inlineQueryId + '\'' +
", results=" + results +
", cacheTime=" + cacheTime +
", isPersonal=" + isPersonal +
", switchPmText=" + switchPmText +
", switchPmParameter=" + switchPmParameter +
", nextOffset='" + nextOffset + '\'' +
'}';
}
}

View File

@ -2,14 +2,21 @@ 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;
import lombok.Getter;
import lombok.NoArgsConstructor;
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 static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 1.0
@ -21,6 +28,14 @@ import static com.google.common.base.Preconditions.checkNotNull;
*
* @apiNote The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@RequiredArgsConstructor
@AllArgsConstructor
@Builder
public class AnswerPreCheckoutQuery extends BotApiMethod<Boolean> {
public static final String PATH = "answerPreCheckoutQuery";
@ -29,56 +44,14 @@ public class AnswerPreCheckoutQuery extends BotApiMethod<Boolean> {
private static final String ERROR_MESSAGE_FIELD = "error_message";
@JsonProperty(PRE_CHECKOUT_QUERY_ID_FIELD)
@NonNull
private String preCheckoutQueryId; ///< Unique identifier for the query to be answered
@JsonProperty(OK_FIELD)
@NonNull
private Boolean ok; ///< Specify True if everything is alright (goods are available, etc.) and the bot is ready to proceed with the order. Use False if there are any problems.
@JsonProperty(ERROR_MESSAGE_FIELD)
private String errorMessage; ///< Optional. Required if ok is False. Error message in human readable form that explains the reason for failure to proceed with the checkout
/**
* Creates an empty answer pre-checkout query
*/
public AnswerPreCheckoutQuery() {
super();
}
/**
* Creates an answer pre-checkout query with mandatory parameters
* @param preCheckoutQueryId Unique identifier for the query to be answered
* @param ok Specify True if delivery to the specified address is possible and False if there are any problems
*/
public AnswerPreCheckoutQuery(String preCheckoutQueryId, Boolean ok) {
this.preCheckoutQueryId = checkNotNull(preCheckoutQueryId);
this.ok = checkNotNull(ok);
}
public String getPreCheckoutQueryId() {
return preCheckoutQueryId;
}
public AnswerPreCheckoutQuery setPreCheckoutQueryId(String preCheckoutQueryId) {
this.preCheckoutQueryId = checkNotNull(preCheckoutQueryId);
return this;
}
public Boolean getOk() {
return ok;
}
public AnswerPreCheckoutQuery setOk(Boolean ok) {
this.ok = checkNotNull(ok);
return this;
}
public String getErrorMessage() {
return errorMessage;
}
public AnswerPreCheckoutQuery setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (preCheckoutQueryId == null || preCheckoutQueryId.isEmpty()) {
@ -113,13 +86,4 @@ public class AnswerPreCheckoutQuery extends BotApiMethod<Boolean> {
throw new TelegramApiRequestException("Unable to deserialize response", e);
}
}
@Override
public String toString() {
return "AnswerPreCheckoutQuery{" +
"preCheckoutQueryId='" + preCheckoutQueryId + '\'' +
", ok=" + ok +
", errorMessage='" + errorMessage + '\'' +
'}';
}
}

View File

@ -2,16 +2,23 @@ package org.telegram.telegrambots.meta.api.methods;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.meta.api.objects.payments.ShippingOption;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
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;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 1.0
@ -22,6 +29,14 @@ import static com.google.common.base.Preconditions.checkNotNull;
*
* On success, True is returned
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@RequiredArgsConstructor
@AllArgsConstructor
@Builder
public class AnswerShippingQuery extends BotApiMethod<Boolean> {
public static final String PATH = "answerShippingQuery";
@ -31,67 +46,16 @@ public class AnswerShippingQuery extends BotApiMethod<Boolean> {
private static final String ERROR_MESSAGE_FIELD = "error_message";
@JsonProperty(SHIPPING_QUERY_ID_FIELD)
@NonNull
private String shippingQueryId; ///< Unique identifier for the query to be answered
@JsonProperty(OK_FIELD)
@NonNull
private Boolean ok; ///< Specify True if delivery to the specified address is possible and False if there are any problems
@JsonProperty(SHIPPING_OPTIONS_FIELD)
private List<ShippingOption> shippingOptions; ///< Optional. Required if ok is True. A JSON-serialized array of available shipping options.
@JsonProperty(ERROR_MESSAGE_FIELD)
private String errorMessage; ///< Optional. Required if ok is False. Error message in human readable form that explains why it is impossible to complete the order (e.g. "Sorry, delivery to your desired address is unavailable').
/**
* Creates an empty answer shipping query
*/
public AnswerShippingQuery() {
super();
}
/**
* Creates an answer shipping query with mandatory parameters
* @param shippingQueryId Unique identifier for the query to be answered
* @param ok Specify True if delivery to the specified address is possible and False if there are any problems
*/
public AnswerShippingQuery(String shippingQueryId, Boolean ok) {
this.shippingQueryId = checkNotNull(shippingQueryId);
this.ok = checkNotNull(ok);
}
public String getShippingQueryId() {
return shippingQueryId;
}
public AnswerShippingQuery setShippingQueryId(String shippingQueryId) {
this.shippingQueryId = checkNotNull(shippingQueryId);
return this;
}
public Boolean getOk() {
return ok;
}
public AnswerShippingQuery setOk(Boolean ok) {
this.ok = checkNotNull(ok);
return this;
}
public List<ShippingOption> getShippingOptions() {
return shippingOptions;
}
public AnswerShippingQuery setShippingOptions(List<ShippingOption> shippingOptions) {
this.shippingOptions = shippingOptions;
return this;
}
public String getErrorMessage() {
return errorMessage;
}
public AnswerShippingQuery setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (shippingQueryId == null || shippingQueryId.isEmpty()) {
@ -133,14 +97,4 @@ public class AnswerShippingQuery extends BotApiMethod<Boolean> {
throw new TelegramApiRequestException("Unable to deserialize response", e);
}
}
@Override
public String toString() {
return "AnswerShippingQuery{" +
"shippingQueryId='" + shippingQueryId + '\'' +
", ok=" + ok +
", shippingOptions=" + shippingOptions +
", errorMessage='" + errorMessage + '\'' +
'}';
}
}

View File

@ -0,0 +1,158 @@
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;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
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;
/**
* @author Ruben Bermudez
* @version 1.0
* Use this method to copy messages of any kind. The method is analogous to the method forwardMessages,
* but the copied message doesn't have a link to the original message.
* Returns the MessageId of the sent message on success.
*/
@SuppressWarnings("unused")
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class CopyMessage extends BotApiMethod<MessageId> {
public static final String PATH = "copyMessage";
private static final String CHATID_FIELD = "chat_id";
private static final String FROMCHATID_FIELD = "from_chat_id";
private static final String MESSAGEID_FIELD = "message_id";
private static final String CAPTION_FIELD = "caption";
private static final String PARSEMODE_FIELD = "parse_mode";
private static final String CAPTIONENTITIES_FIELD = "caption_entities";
private static final String DISABLENOTIFICATION_FIELD = "disable_notification";
private static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
private static final String ALLOWSENDINGWITHOUTREPLY_FIELD = "allow_sending_without_reply";
private static final String REPLYMARKUP_FIELD = "reply_markup";
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId; ///< Unique identifier for the target chat or username of the target channel (in the format @channelusername)
@JsonProperty(FROMCHATID_FIELD)
@NonNull
private String fromChatId; ///< Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername)
@JsonProperty(MESSAGEID_FIELD)
@NonNull
private Integer messageId; ///< Message identifier in the chat specified in from_chat_id
@JsonProperty(CAPTION_FIELD)
private String caption; ///< Optional. New caption for media, 0-1024 characters after entities parsing. If not specified, the original caption is kept
@JsonProperty(PARSEMODE_FIELD)
private String parseMode; ///< Optional. Mode for parsing entities in the new caption. See formatting options for more details.
@JsonProperty(CAPTIONENTITIES_FIELD)
private List<MessageEntity> captionEntities; ///< Optional. List of special entities that appear in the new caption, which can be specified instead of parse_mode
@JsonProperty(DISABLENOTIFICATION_FIELD)
private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
@JsonProperty(REPLYTOMESSAGEID_FIELD)
private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message
@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
/**
* Optional.
*
* Additional interface options.
* A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or
* to force a reply from the user.
*/
@JsonProperty(REPLYMARKUP_FIELD)
@JsonDeserialize()
private ReplyKeyboard replyMarkup;
public void enableNotification() {
this.disableNotification = null;
}
public void disableNotification() {
this.disableNotification = true;
}
public void enableMarkdown(boolean enable) {
if (enable) {
this.parseMode = ParseMode.MARKDOWN;
} else {
this.parseMode = null;
}
}
public void enableHtml(boolean enable) {
if (enable) {
this.parseMode = ParseMode.HTML;
} else {
this.parseMode = null;
}
}
public void enableMarkdownV2(boolean enable) {
if (enable) {
this.parseMode = ParseMode.MARKDOWNV2;
} else {
this.parseMode = null;
}
}
@Override
public String getMethod() {
return PATH;
}
@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);
}
}
@Override
public void validate() throws TelegramApiValidationException {
if (chatId == null) {
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);
}
if (replyMarkup != null) {
replyMarkup.validate();
}
}
}

View File

@ -2,20 +2,35 @@ package org.telegram.telegrambots.meta.api.methods;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.meta.api.objects.Message;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.IOException;
import java.util.Objects;
/**
* @author Ruben Bermudez
* @version 1.0
* Use this method to send text messages. On success, the sent Message is returned.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@RequiredArgsConstructor
@AllArgsConstructor
@Builder
public class ForwardMessage extends BotApiMethod<Message> {
public static final String PATH = "forwardmessage";
@ -25,10 +40,13 @@ public class ForwardMessage extends BotApiMethod<Message> {
private static final String DISABLENOTIFICATION_FIELD = "disable_notification";
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId; ///< Unique identifier for the chat to send the message to (or username for channels)
@JsonProperty(FROMCHATID_FIELD)
@NonNull
private String fromChatId; ///< Unique identifier for the chat where the original message was sent User or GroupChat id
@JsonProperty(MESSAGEID_FIELD)
@NonNull
private Integer messageId; ///< Unique message identifier
/**
* Optional. Sends the message silently.
@ -39,99 +57,6 @@ public class ForwardMessage extends BotApiMethod<Message> {
@JsonProperty(DISABLENOTIFICATION_FIELD)
private Boolean disableNotification;
public ForwardMessage() {
super();
}
public ForwardMessage(String chatId, String fromChatId, Integer messageId) {
this();
Objects.requireNonNull(chatId);
Objects.requireNonNull(fromChatId);
this.chatId = chatId;
this.fromChatId = fromChatId;
this.messageId = messageId;
}
public ForwardMessage(String chatId, Long fromChatId, Integer messageId) {
this();
Objects.requireNonNull(chatId);
Objects.requireNonNull(fromChatId);
this.chatId = chatId;
this.fromChatId = fromChatId.toString();
this.messageId = messageId;
}
public ForwardMessage(Long chatId, String fromChatId, Integer messageId) {
this();
Objects.requireNonNull(chatId);
Objects.requireNonNull(fromChatId);
this.chatId = chatId.toString();
this.fromChatId = fromChatId;
this.messageId = messageId;
}
public ForwardMessage(Long chatId, Long fromChatId, Integer messageId) {
this();
Objects.requireNonNull(chatId);
Objects.requireNonNull(fromChatId);
this.chatId = chatId.toString();
this.fromChatId = fromChatId.toString();
this.messageId = messageId;
}
public String getChatId() {
return chatId;
}
public ForwardMessage setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public ForwardMessage setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
public String getFromChatId() {
return fromChatId;
}
public ForwardMessage setFromChatId(String fromChatId) {
this.fromChatId = fromChatId;
return this;
}
public ForwardMessage setFromChatId(Long fromChatId) {
Objects.requireNonNull(fromChatId);
this.fromChatId = fromChatId.toString();
return this;
}
public Integer getMessageId() {
return messageId;
}
public ForwardMessage setMessageId(Integer messageId) {
this.messageId = messageId;
return this;
}
public Boolean getDisableNotification() {
return disableNotification;
}
public ForwardMessage enableNotification() {
this.disableNotification = false;
return this;
}
public ForwardMessage disableNotification() {
this.disableNotification = true;
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (chatId == null || chatId.isEmpty()) {
@ -164,14 +89,4 @@ public class ForwardMessage extends BotApiMethod<Message> {
throw new TelegramApiRequestException("Unable to deserialize response", e);
}
}
@Override
public String toString() {
return "ForwardMessage{" +
"chatId='" + chatId + '\'' +
", fromChatId='" + fromChatId + '\'' +
", messageId=" + messageId +
", disableNotification=" + disableNotification +
'}';
}
}

View File

@ -2,9 +2,16 @@ package org.telegram.telegrambots.meta.api.methods;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.meta.api.objects.File;
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 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;
@ -21,27 +28,22 @@ import java.io.IOException;
* It is guaranteed that the link will be valid for at least 1 hour.
* When the link expires, a new one can be requested by calling getFile again.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class GetFile extends BotApiMethod<File> {
public static final String PATH = "getFile";
private static final String FILEID_FIELD = "file_id";
@JsonProperty(FILEID_FIELD)
@NonNull
private String fileId; ///< File identifier to get info about
public GetFile() {
super();
}
public String getFileId() {
return fileId;
}
public GetFile setFileId(String fileId) {
this.fileId = fileId;
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (fileId == null) {
@ -68,11 +70,4 @@ public class GetFile extends BotApiMethod<File> {
throw new TelegramApiRequestException("Unable to deserialize response", e);
}
}
@Override
public String toString() {
return "GetFile{" +
"fileId='" + fileId + '\'' +
'}';
}
}

View File

@ -1,9 +1,14 @@
package org.telegram.telegrambots.meta.api.methods;
import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.meta.api.objects.User;
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;
@ -15,13 +20,15 @@ import java.io.IOException;
* A simple method for testing your bot's auth token. Requires no parameters.
* Returns basic information about the bot in form of a User object
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@AllArgsConstructor
@Builder
public class GetMe extends BotApiMethod<User> {
public static final String PATH = "getme";
public GetMe() {
super();
}
@Override
public String getMethod() {
return PATH;

View File

@ -3,6 +3,15 @@ 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;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
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;
@ -15,6 +24,14 @@ import java.io.IOException;
* @version 1.0
* Use this method to get a list of profile pictures for a user. Returns a UserProfilePhotos object.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@RequiredArgsConstructor
@AllArgsConstructor
@Builder
public class GetUserProfilePhotos extends BotApiMethod<UserProfilePhotos> {
public static final String PATH = "getuserprofilephotos";
@ -23,9 +40,10 @@ public class GetUserProfilePhotos extends BotApiMethod<UserProfilePhotos> {
private static final String LIMIT_FIELD = "limit";
@JsonProperty(USERID_FIELD)
@NonNull
private Integer userId; ///< Unique identifier of the target user
/**
* Sequential number of the first photo to be returned. By default, all photos are returned.
* Optional. Sequential number of the first photo to be returned. By default, all photos are returned.
*/
@JsonProperty(OFFSET_FIELD)
private Integer offset;
@ -35,37 +53,6 @@ public class GetUserProfilePhotos extends BotApiMethod<UserProfilePhotos> {
@JsonProperty(LIMIT_FIELD)
private Integer limit;
public GetUserProfilePhotos() {
super();
}
public Integer getUserId() {
return userId;
}
public GetUserProfilePhotos setUserId(Integer userId) {
this.userId = userId;
return this;
}
public Integer getOffset() {
return offset;
}
public GetUserProfilePhotos setOffset(Integer offset) {
this.offset = offset;
return this;
}
public Integer getLimit() {
return limit;
}
public GetUserProfilePhotos setLimit(Integer limit) {
this.limit = limit;
return this;
}
@Override
public String getMethod() {
return PATH;
@ -92,13 +79,4 @@ public class GetUserProfilePhotos extends BotApiMethod<UserProfilePhotos> {
throw new TelegramApiValidationException("UserId parameter can't be empty", this);
}
}
@Override
public String toString() {
return "GetUserProfilePhotos{" +
"userId=" + userId +
", offset=" + offset +
", limit=" + limit +
'}';
}
}

View File

@ -2,17 +2,23 @@ package org.telegram.telegrambots.meta.api.methods;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.meta.api.objects.passport.dataerror.PassportElementError;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
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.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.ArrayList;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 4.0.0
@ -20,6 +26,13 @@ import static com.google.common.base.Preconditions.checkNotNull;
* Informs a user that some Telegram Passport data contains errors.
* The user will not be able to resend data, until the errors are fixed
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SetPassportDataErrors extends BotApiMethod<Boolean> {
public static final String PATH = "setPassportDataErrors";
@ -27,47 +40,13 @@ public class SetPassportDataErrors extends BotApiMethod<Boolean> {
private static final String ERRORS_FIELD = "errors";
@JsonProperty(USERID_FIELD)
@NonNull
private Integer userId; ///< User identifier
@JsonProperty(ERRORS_FIELD)
@NonNull
@Singular
private List<PassportElementError> errors; ///< A JSON-serialized array describing the errors
public SetPassportDataErrors(Integer userId, List<PassportElementError> errors) {
super();
this.userId = checkNotNull(userId);
this.errors = checkNotNull(errors);
}
public SetPassportDataErrors() {
super();
}
public Integer getUserId() {
return userId;
}
public SetPassportDataErrors setUserId(Integer userId) {
this.userId = userId;
return this;
}
public List<PassportElementError> getErrors() {
return errors;
}
public SetPassportDataErrors setErrors(List<PassportElementError> errors) {
this.errors = errors;
return this;
}
public SetPassportDataErrors addError(PassportElementError error) {
error = checkNotNull(error);
if (this.errors == null) {
this.errors = new ArrayList<>();
}
this.errors.add(error);
return this;
}
@Override
public String getMethod() {
return PATH;

View File

@ -2,8 +2,15 @@ package org.telegram.telegrambots.meta.api.methods;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.meta.api.objects.Message;
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.objects.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
@ -18,6 +25,13 @@ import java.io.Serializable;
* before live_period expires. On success, if the message was sent by the bot, the sent Message is returned,
* otherwise True is returned.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class StopMessageLiveLocation extends BotApiMethod<Serializable> {
public static final String PATH = "stopMessageLiveLocation";
@ -45,51 +59,6 @@ public class StopMessageLiveLocation extends BotApiMethod<Serializable> {
@JsonProperty(REPLYMARKUP_FIELD)
private InlineKeyboardMarkup replyMarkup; ///< Optional. A JSON-serialized object for an inline keyboard.
public StopMessageLiveLocation() {
super();
}
public String getChatId() {
return chatId;
}
public StopMessageLiveLocation setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public StopMessageLiveLocation setChatId(Long chatId) {
this.chatId = chatId.toString();
return this;
}
public Integer getMessageId() {
return messageId;
}
public StopMessageLiveLocation setMessageId(Integer messageId) {
this.messageId = messageId;
return this;
}
public String getInlineMessageId() {
return inlineMessageId;
}
public StopMessageLiveLocation setInlineMessageId(String inlineMessageId) {
this.inlineMessageId = inlineMessageId;
return this;
}
public InlineKeyboardMarkup getReplyMarkup() {
return replyMarkup;
}
public StopMessageLiveLocation setReplyMarkup(InlineKeyboardMarkup replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
@Override
public String getMethod() {
return PATH;
@ -142,14 +111,4 @@ public class StopMessageLiveLocation extends BotApiMethod<Serializable> {
replyMarkup.validate();
}
}
@Override
public String toString() {
return "StopMessageLiveLocation{" +
"chatId='" + chatId + '\'' +
", messageId=" + messageId +
", inlineMessageId='" + inlineMessageId + '\'' +
", replyMarkup=" + replyMarkup +
'}';
}
}

View File

@ -1,6 +1,12 @@
package org.telegram.telegrambots.meta.api.methods.commands;
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.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.commands.BotCommand;
@ -17,13 +23,15 @@ import java.util.ArrayList;
* Requires no parameters.
* Returns Array of BotCommand on success.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@AllArgsConstructor
@Builder
public class GetMyCommands extends BotApiMethod<ArrayList<BotCommand>> {
public static final String PATH = "getMyCommands";
public GetMyCommands() {
super();
}
@Override
public String getMethod() {
return PATH;
@ -47,9 +55,4 @@ public class GetMyCommands extends BotApiMethod<ArrayList<BotCommand>> {
@Override
public void validate() throws TelegramApiValidationException {
}
@Override
public String toString() {
return "GetMyCommands{}";
}
}

View File

@ -2,6 +2,15 @@ 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;
import lombok.Getter;
import lombok.NoArgsConstructor;
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.objects.commands.BotCommand;
@ -11,13 +20,18 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.IOException;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 4.7
* Use this method to change the list of the bot's commands. Returns True on success.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SetMyCommands extends BotApiMethod<Boolean> {
public static final String PATH = "setMyCommands";
@ -28,25 +42,10 @@ public class SetMyCommands extends BotApiMethod<Boolean> {
* At most 100 commands can be specified.
*/
@JsonProperty(COMMANDS_FIELD)
@Singular
@NonNull
private List<BotCommand> commands;
public SetMyCommands() {
super();
}
public SetMyCommands(List<BotCommand> commands) {
this.commands = checkNotNull(commands);
}
public List<BotCommand> getCommands() {
return commands;
}
public SetMyCommands setCommands(List<BotCommand> commands) {
this.commands = checkNotNull(commands);
return this;
}
@Override
public String getMethod() {
return PATH;
@ -79,11 +78,4 @@ public class SetMyCommands extends BotApiMethod<Boolean> {
command.validate();
}
}
@Override
public String toString() {
return "SetMyCommands{" +
"commands=" + commands +
'}';
}
}

View File

@ -19,6 +19,15 @@ 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;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.games.GameHighScore;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
@ -35,12 +44,20 @@ import java.util.ArrayList;
* Will return the score of the specified user and several of his neighbors in a game.
* On success, returns an Array of GameHighScore objects.
*
* @note This method will currently return scores for the target user,
* @apiNote This method will currently return scores for the target user,
* plus two of his closest neighbors on each side. Will also return the top three users
* if the user and his neighbors are not among them.
* Please note that this behavior is subject to change.
*
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@RequiredArgsConstructor
@AllArgsConstructor
@Builder
public class GetGameHighScores extends BotApiMethod<ArrayList<GameHighScore>> {
public static final String PATH = "getGameHighScores";
@ -56,53 +73,9 @@ public class GetGameHighScores extends BotApiMethod<ArrayList<GameHighScore>> {
@JsonProperty(INLINE_MESSAGE_ID_FIELD)
private String inlineMessageId; ///< Optional Required if chat_id and message_id are not specified. Identifier of the inline message
@JsonProperty(USER_ID_FIELD)
@NonNull
private Integer userId; ///<Target user id
public GetGameHighScores() {
super();
}
public String getChatId() {
return chatId;
}
public Integer getMessageId() {
return messageId;
}
public String getInlineMessageId() {
return inlineMessageId;
}
public Integer getUserId() {
return userId;
}
public GetGameHighScores setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public GetGameHighScores setChatId(Long chatId) {
this.chatId = chatId.toString();
return this;
}
public GetGameHighScores setMessageId(Integer messageId) {
this.messageId = messageId;
return this;
}
public GetGameHighScores setInlineMessageId(String inlineMessageId) {
this.inlineMessageId = inlineMessageId;
return this;
}
public GetGameHighScores setUserId(Integer userId) {
this.userId = userId;
return this;
}
@Override
public String getMethod() {
return PATH;
@ -144,14 +117,4 @@ public class GetGameHighScores extends BotApiMethod<ArrayList<GameHighScore>> {
}
}
}
@Override
public String toString() {
return "GetGameHighScores{" +
"chatId='" + chatId + '\'' +
", messageId=" + messageId +
", inlineMessageId='" + inlineMessageId + '\'' +
", userId=" + userId +
'}';
}
}

View File

@ -20,6 +20,15 @@ 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;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
@ -39,6 +48,14 @@ import java.io.Serializable;
* Returns an error, if the new score is not greater than the user's current score in
* the chat and force is False.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@RequiredArgsConstructor
@AllArgsConstructor
@Builder
public class SetGameScore extends BotApiMethod<Serializable> {
public static final String PATH = "setGameScore";
@ -59,84 +76,14 @@ public class SetGameScore extends BotApiMethod<Serializable> {
@JsonProperty(DISABLEEDITMESSAGE_FIELD)
private Boolean disableEditMessage; ///< Optional Pass True, if the game message should not be automatically edited to include the current scoreboard. Defaults to False
@JsonProperty(USER_ID_FIELD)
@NonNull
private Integer userId; ///< User identifier
@JsonProperty(SCORE_FIELD)
@NonNull
private Integer score; ///< New score, must be positive
@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
public SetGameScore() {
super();
}
public String getChatId() {
return chatId;
}
public Integer getMessageId() {
return messageId;
}
public String getInlineMessageId() {
return inlineMessageId;
}
public Boolean getDisableEditMessage() {
return disableEditMessage;
}
public Integer getUserId() {
return userId;
}
public Integer getScore() {
return score;
}
public Boolean getForce() {
return force;
}
public SetGameScore setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public SetGameScore setChatId(Long chatId) {
this.chatId = chatId.toString();
return this;
}
public SetGameScore setMessageId(Integer messageId) {
this.messageId = messageId;
return this;
}
public SetGameScore setInlineMessageId(String inlineMessageId) {
this.inlineMessageId = inlineMessageId;
return this;
}
public SetGameScore setDisableEditMessage(Boolean disableEditMessage) {
this.disableEditMessage = disableEditMessage;
return this;
}
public SetGameScore setUserId(Integer userId) {
this.userId = userId;
return this;
}
public SetGameScore setScore(Integer score) {
this.score = score;
return this;
}
public SetGameScore setForce(Boolean force) {
this.force = force;
return this;
}
@Override
public String getMethod() {
return PATH;
@ -192,17 +139,4 @@ public class SetGameScore extends BotApiMethod<Serializable> {
}
}
}
@Override
public String toString() {
return "SetGameScore{" +
"chatId='" + chatId + '\'' +
", messageId=" + messageId +
", inlineMessageId='" + inlineMessageId + '\'' +
", disableEditMessage=" + disableEditMessage +
", userId=" + userId +
", score=" + score +
", force=" + force +
'}';
}
}

View File

@ -2,15 +2,20 @@ 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;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.IOException;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
@ -21,43 +26,22 @@ import static com.google.common.base.Preconditions.checkNotNull;
*
* @apiNote In regular groups (non-supergroups), this method will only work if the All Members Are Admins setting is off in the target group.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class DeleteChatPhoto extends BotApiMethod<Boolean> {
public static final String PATH = "deleteChatPhoto";
private static final String CHATID_FIELD = "chat_id";
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId; ///< Unique identifier for the target chat or username of the target channel (in the format @channelusername)
public DeleteChatPhoto() {
super();
}
public DeleteChatPhoto(String chatId) {
super();
this.chatId = checkNotNull(chatId);
}
public DeleteChatPhoto(Long chatId) {
super();
this.chatId = checkNotNull(chatId).toString();
}
public String getChatId() {
return chatId;
}
public DeleteChatPhoto setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public DeleteChatPhoto setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
@Override
public String getMethod() {
return PATH;
@ -84,11 +68,4 @@ public class DeleteChatPhoto extends BotApiMethod<Boolean> {
throw new TelegramApiValidationException("ChatId can't be null", this);
}
}
@Override
public String toString() {
return "DeleteChatPhoto{" +
"chatId='" + chatId + '\'' +
'}';
}
}

View File

@ -2,15 +2,20 @@ 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;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.IOException;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
@ -20,43 +25,22 @@ import static com.google.common.base.Preconditions.checkNotNull;
* Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method.
* Returns True on success.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class DeleteChatStickerSet extends BotApiMethod<Boolean> {
public static final String PATH = "deleteChatStickerSet";
private static final String CHATID_FIELD = "chat_id";
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
public DeleteChatStickerSet() {
super();
}
public DeleteChatStickerSet(String chatId) {
super();
this.chatId = checkNotNull(chatId);
}
public DeleteChatStickerSet(Long chatId) {
super();
this.chatId = checkNotNull(chatId).toString();
}
public String getChatId() {
return chatId;
}
public DeleteChatStickerSet setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public DeleteChatStickerSet setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
@Override
public String getMethod() {
return PATH;
@ -83,11 +67,4 @@ public class DeleteChatStickerSet extends BotApiMethod<Boolean> {
throw new TelegramApiValidationException("ChatId can't be empty", this);
}
}
@Override
public String toString() {
return "DeleteChatStickerSet{" +
"chatId='" + chatId + '\'' +
'}';
}
}

View File

@ -1,14 +0,0 @@
package org.telegram.telegrambots.meta.api.methods.groupadministration;
/**
* @author Ruben Bermudez
* @version 3.4
* Use this method to delete a group sticker set from a supergroup.
* The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
* Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method.
* Returns True on success.
* @deprecated Replaced by {@link DeleteChatStickerSet}
*/
@Deprecated
public class DeleteStickerSetName extends DeleteChatStickerSet {
}

View File

@ -2,15 +2,20 @@ 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;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.IOException;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
@ -18,43 +23,22 @@ import static com.google.common.base.Preconditions.checkNotNull;
* Use this method to export an invite link to a supergroup or a channel. The bot must be an administrator in the
* chat for this to work and must have the appropriate admin rights. Returns exported invite link as String on success.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class ExportChatInviteLink extends BotApiMethod<String> {
public static final String PATH = "exportChatInviteLink";
private static final String CHATID_FIELD = "chat_id";
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
public ExportChatInviteLink() {
super();
}
public ExportChatInviteLink(String chatId) {
super();
this.chatId = checkNotNull(chatId);
}
public ExportChatInviteLink(Long chatId) {
super();
this.chatId = checkNotNull(chatId).toString();
}
public String getChatId() {
return chatId;
}
public ExportChatInviteLink setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public ExportChatInviteLink setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
@Override
public String getMethod() {
return PATH;
@ -81,11 +65,4 @@ public class ExportChatInviteLink extends BotApiMethod<String> {
throw new TelegramApiValidationException("ChatId can't be empty", this);
}
}
@Override
public String toString() {
return "ExportChatInviteLink{" +
"chatId='" + chatId + '\'' +
'}';
}
}

View File

@ -2,60 +2,43 @@ 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;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.Chat;
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;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 1.0
* Use this method to get information about the chat. Returns Chat object on success.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class GetChat extends BotApiMethod<Chat> {
public static final String PATH = "getChat";
private static final String CHATID_FIELD = "chat_id";
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
public GetChat() {
super();
}
public GetChat(String chatId) {
super();
this.chatId = checkNotNull(chatId);
}
public GetChat(Long chatId) {
super();
this.chatId = checkNotNull(chatId).toString();
}
public String getChatId() {
return chatId;
}
public GetChat setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public GetChat setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
@Override
public String getMethod() {
return PATH;
@ -82,11 +65,4 @@ public class GetChat extends BotApiMethod<Chat> {
throw new TelegramApiValidationException("ChatId can't be empty", this);
}
}
@Override
public String toString() {
return "GetChat{" +
"chatId='" + chatId + '\'' +
'}';
}
}

View File

@ -2,16 +2,22 @@ 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;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ChatMember;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.ChatMember;
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.Objects;
/**
* @author Ruben Bermudez
@ -22,33 +28,22 @@ import java.util.Objects;
* If the chat is a group or a supergroup and no administrators were appointed,
* only the creator will be returned.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class GetChatAdministrators extends BotApiMethod<ArrayList<ChatMember>> {
public static final String PATH = "getChatAdministrators";
private static final String CHATID_FIELD = "chat_id";
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
public GetChatAdministrators() {
super();
}
public String getChatId() {
return chatId;
}
public GetChatAdministrators setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public GetChatAdministrators setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
@Override
public String getMethod() {
return PATH;
@ -75,11 +70,4 @@ public class GetChatAdministrators extends BotApiMethod<ArrayList<ChatMember>> {
throw new TelegramApiValidationException("ChatId can't be empty", this);
}
}
@Override
public String toString() {
return "GetChatAdministrators{" +
"chatId='" + chatId + '\'' +
'}';
}
}

View File

@ -2,15 +2,21 @@ 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;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ChatMember;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.ChatMember;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.IOException;
import java.util.Objects;
/**
* @author Ruben Bermudez
@ -18,6 +24,13 @@ import java.util.Objects;
* Use this method to get information about a member of a chat.
* Returns a ChatMember object on success.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class GetChatMember extends BotApiMethod<ChatMember> {
public static final String PATH = "getChatMember";
@ -25,38 +38,12 @@ public class GetChatMember extends BotApiMethod<ChatMember> {
private static final String USERID_FIELD = "user_id";
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
@JsonProperty(USERID_FIELD)
@NonNull
private Integer userId; ///< Unique identifier of the target user
public GetChatMember() {
super();
}
public String getChatId() {
return chatId;
}
public GetChatMember setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public GetChatMember setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
public Integer getUserId() {
return userId;
}
public GetChatMember setUserId(Integer userId) {
this.userId = userId;
return this;
}
@Override
public String getMethod() {
return PATH;
@ -86,12 +73,4 @@ public class GetChatMember extends BotApiMethod<ChatMember> {
throw new TelegramApiValidationException("UserId can't be null", this);
}
}
@Override
public String toString() {
return "GetChatMember{" +
"chatId='" + chatId + '\'' +
", userId='" + userId + '\'' +
'}';
}
}

View File

@ -1,11 +0,0 @@
package org.telegram.telegrambots.meta.api.methods.groupadministration;
/**
* @author Ruben Bermudez
* @version 1.0
* Use this method to get the number of members in a chat. Returns Int on success.
* @deprecated Replaced by {@link GetChatMembersCount}
*/
@Deprecated
public class GetChatMemberCount extends GetChatMembersCount {
}

View File

@ -2,46 +2,42 @@ 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;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.IOException;
import java.util.Objects;
/**
* @author Ruben Bermudez
* @version 1.0
* Use this method to get the number of members in a chat. Returns Int on success.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class GetChatMembersCount extends BotApiMethod<Integer> {
public static final String PATH = "getChatMembersCount";
private static final String CHATID_FIELD = "chat_id";
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
public GetChatMembersCount() {
super();
}
public String getChatId() {
return chatId;
}
public GetChatMembersCount setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public GetChatMembersCount setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
@Override
public String getMethod() {
return PATH;
@ -68,11 +64,4 @@ public class GetChatMembersCount extends BotApiMethod<Integer> {
throw new TelegramApiValidationException("ChatId can't be empty", this);
}
}
@Override
public String toString() {
return "GetChatMembersCount{" +
"chatId='" + chatId + '\'' +
'}';
}
}

View File

@ -3,7 +3,15 @@ package org.telegram.telegrambots.meta.api.methods.groupadministration;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
@ -13,9 +21,6 @@ import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
import java.time.ZonedDateTime;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
@ -28,6 +33,14 @@ import static com.google.common.base.Preconditions.checkNotNull;
* group. Otherwise members may only be removed by the group's creator or by the member that added
* them.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@RequiredArgsConstructor
@AllArgsConstructor
@Builder
public class KickChatMember extends BotApiMethod<Boolean> {
public static final String PATH = "kickchatmember";
@ -36,72 +49,27 @@ public class KickChatMember extends BotApiMethod<Boolean> {
private static final String UNTILDATE_FIELD = "until_date";
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId; ///< Required. Unique identifier for the chat to send the message to (Or username for channels)
@JsonProperty(USER_ID_FIELD)
@NonNull
private Integer userId; ///< Required. Unique identifier of the target user
@JsonProperty(UNTILDATE_FIELD)
private Integer untilDate; ///< Date when the user will be unbanned, unix time. If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever
private Integer untilDate; ///< Optional. Date when the user will be unbanned, unix time. If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever
public KickChatMember() {
super();
}
public KickChatMember(String chatId, Integer userId) {
this.chatId = checkNotNull(chatId);
this.userId = checkNotNull(userId);
}
public KickChatMember(Long chatId, Integer userId) {
this.chatId = checkNotNull(chatId).toString();
this.userId = checkNotNull(userId);
}
public String getChatId() {
return chatId;
}
public KickChatMember setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public KickChatMember setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
public Integer getUserId() {
return userId;
}
public KickChatMember setUserId(Integer userId) {
this.userId = userId;
return this;
}
public Integer getUntilDate() {
return untilDate;
}
public KickChatMember setUntilDate(Integer untilDateInSeconds) {
this.untilDate = untilDateInSeconds;
return this;
@JsonIgnore
public void setUntilDateInstant(Instant instant) {
setUntilDate((int) instant.getEpochSecond());
}
@JsonIgnore
public KickChatMember setUntilDate(Instant instant) {
return setUntilDate((int) instant.getEpochSecond());
public void setUntilDateDateTime(ZonedDateTime date) {
setUntilDateInstant(date.toInstant());
}
@JsonIgnore
public KickChatMember setUntilDate(ZonedDateTime date) {
return setUntilDate(date.toInstant());
}
public KickChatMember forTimePeriod(Duration duration) {
return setUntilDate(Instant.now().plusMillis(duration.toMillis()));
public void forTimePeriodDuration(Duration duration) {
setUntilDateInstant(Instant.now().plusMillis(duration.toMillis()));
}
@Override
@ -133,13 +101,4 @@ public class KickChatMember extends BotApiMethod<Boolean> {
throw new TelegramApiValidationException("UserId can't be null", this);
}
}
@Override
public String toString() {
return "KickChatMember{" +
"chatId='" + chatId + '\'' +
", userId=" + userId +
", untilDate=" + untilDate +
'}';
}
}

View File

@ -2,47 +2,42 @@ 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;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.IOException;
import java.util.Objects;
/**
* @author Ruben Bermudez
* @version 1.0
* Use this method for your bot to leave a group, supergroup or channel. Returns True on success.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class LeaveChat extends BotApiMethod<Boolean> {
public static final String PATH = "leaveChat";
private static final String CHATID_FIELD = "chat_id";
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
public LeaveChat() {
super();
}
public String getChatId() {
return chatId;
}
public LeaveChat setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public LeaveChat setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
@Override
public String getMethod() {
return PATH;
@ -69,11 +64,4 @@ public class LeaveChat extends BotApiMethod<Boolean> {
throw new TelegramApiValidationException("ChatId can't be null", this);
}
}
@Override
public String toString() {
return "LeaveChat{" +
"chatId='" + chatId + '\'' +
'}';
}
}

View File

@ -2,15 +2,21 @@ 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;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.IOException;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
@ -20,6 +26,14 @@ import static com.google.common.base.Preconditions.checkNotNull;
* Pass False for all boolean parameters to demote a user. Returns True on success.
*
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class PromoteChatMember extends BotApiMethod<Boolean> {
public static final String PATH = "promoteChatMember";
@ -33,137 +47,32 @@ public class PromoteChatMember extends BotApiMethod<Boolean> {
private static final String CANRESTRICTMEMBERS_FIELD = "can_restrict_members";
private static final String CANPINMESSAGES_FIELD = "can_pin_messages";
private static final String CANPROMOTEMEMBERS_FIELD = "can_promote_members";
private static final String ISANONYMOUS_FIELD = "is_anonymous";
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId; ///< Required. Unique identifier for the chat to send the message to (Or username for channels)
@JsonProperty(USER_ID_FIELD)
@NonNull
private Integer userId; ///< Required. Unique identifier of the target user
@JsonProperty(CANCHANGEINFORMATION_FIELD)
private Boolean canChangeInformation; ///< Pass True, if the administrator can change chat title, photo and other settings
private Boolean canChangeInformation; ///< Optional. Pass True, if the administrator can change chat title, photo and other settings
@JsonProperty(CANPOSTMESSAGES_FIELD)
private Boolean canPostMessages; ///< Pass True, if the administrator can create channel posts, channels only
private Boolean canPostMessages; ///< Optional. Pass True, if the administrator can create channel posts, channels only
@JsonProperty(CANEDITMESSAGES_FIELD)
private Boolean canEditMessages; ///< Pass True, if the administrator can edit messages of other users, channels only
private Boolean canEditMessages; ///< Optional. Pass True, if the administrator can edit messages of other users, channels only
@JsonProperty(CANDELETEMESSAGES_FIELD)
private Boolean canDeleteMessages; ///< Pass True, if the administrator can delete messages of other users
private Boolean canDeleteMessages; ///< Optional. Pass True, if the administrator can delete messages of other users
@JsonProperty(CANINVITEUSERS_FIELD)
private Boolean canInviteUsers; ///< Pass True, if the administrator can invite new users to the chat
private Boolean canInviteUsers; ///< Optional. Pass True, if the administrator can invite new users to the chat
@JsonProperty(CANRESTRICTMEMBERS_FIELD)
private Boolean canRestrictMembers; ///< Pass True, if the administrator can restrict, ban or unban chat members
private Boolean canRestrictMembers; ///< Optional. Pass True, if the administrator can restrict, ban or unban chat members
@JsonProperty(CANPINMESSAGES_FIELD)
private Boolean canPinMessages; ///< Pass True, if the administrator can pin messages
private Boolean canPinMessages; ///< Optional. Pass True, if the administrator can pin messages
@JsonProperty(CANPROMOTEMEMBERS_FIELD)
private Boolean canPromoteMembers; ///< Pass True, if the administrator can add new administrators with a subset of his own privileges or demote administrators that he has promoted, directly or indirectly (promoted by administators that were appointed by the him)
public PromoteChatMember() {
super();
}
public PromoteChatMember(String chatId, Integer userId) {
this.chatId = checkNotNull(chatId);
this.userId = checkNotNull(userId);
}
public PromoteChatMember(Long chatId, Integer userId) {
this.chatId = checkNotNull(chatId).toString();
this.userId = checkNotNull(userId);
}
public String getChatId() {
return chatId;
}
public PromoteChatMember setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public PromoteChatMember setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
public Integer getUserId() {
return userId;
}
public PromoteChatMember setUserId(Integer userId) {
this.userId = userId;
return this;
}
public Boolean getCanChangeInformation() {
return canChangeInformation;
}
public PromoteChatMember setCanChangeInformation(Boolean canChangeInformation) {
this.canChangeInformation = canChangeInformation;
return this;
}
public Boolean getCanPostMessages() {
return canPostMessages;
}
public PromoteChatMember setCanPostMessages(Boolean canPostMessages) {
this.canPostMessages = canPostMessages;
return this;
}
public Boolean getCanEditMessages() {
return canEditMessages;
}
public PromoteChatMember setCanEditMessages(Boolean canEditMessages) {
this.canEditMessages = canEditMessages;
return this;
}
public Boolean getCanDeleteMessages() {
return canDeleteMessages;
}
public PromoteChatMember setCanDeleteMessages(Boolean canDeleteMessages) {
this.canDeleteMessages = canDeleteMessages;
return this;
}
public Boolean getCanInviteUsers() {
return canInviteUsers;
}
public PromoteChatMember setCanInviteUsers(Boolean canInviteUsers) {
this.canInviteUsers = canInviteUsers;
return this;
}
public Boolean getCanRestrictMembers() {
return canRestrictMembers;
}
public PromoteChatMember setCanRestrictMembers(Boolean canRestrictMembers) {
this.canRestrictMembers = canRestrictMembers;
return this;
}
public Boolean getCanPinMessages() {
return canPinMessages;
}
public PromoteChatMember setCanPinMessages(Boolean canPinMessages) {
this.canPinMessages = canPinMessages;
return this;
}
public Boolean getCanPromoteMembers() {
return canPromoteMembers;
}
public PromoteChatMember setCanPromoteMembers(Boolean canPromoteMembers) {
this.canPromoteMembers = canPromoteMembers;
return this;
}
private Boolean canPromoteMembers; ///< Optional. Pass True, if the administrator can add new administrators with a subset of his own privileges or demote administrators that he has promoted, directly or indirectly (promoted by administators that were appointed by the him)
@JsonProperty(ISANONYMOUS_FIELD)
private Boolean isAnonymous; ///< Optional. Pass True, if the administrator's presence in the chat is hidden
@Override
public String getMethod() {
@ -195,20 +104,4 @@ public class PromoteChatMember extends BotApiMethod<Boolean> {
throw new TelegramApiValidationException("UserId can't be null", this);
}
}
@Override
public String toString() {
return "PromoteChatMember{" +
"chatId='" + chatId + '\'' +
", userId=" + userId +
", canChangeInformation=" + canChangeInformation +
", canPostMessages=" + canPostMessages +
", canEditMessages=" + canEditMessages +
", canDeleteMessages=" + canDeleteMessages +
", canInviteUsers=" + canInviteUsers +
", canRestrictMembers=" + canRestrictMembers +
", canPinMessages=" + canPinMessages +
", canPromoteMembers=" + canPromoteMembers +
'}';
}
}

View File

@ -3,6 +3,15 @@ package org.telegram.telegrambots.meta.api.methods.groupadministration;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.ChatPermissions;
@ -13,9 +22,6 @@ import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
import java.time.ZonedDateTime;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
@ -26,6 +32,14 @@ import static com.google.common.base.Preconditions.checkNotNull;
*
*/
@SuppressWarnings("WeakerAccess")
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@RequiredArgsConstructor
@AllArgsConstructor
@Builder
public class RestrictChatMember extends BotApiMethod<Boolean> {
public static final String PATH = "restrictchatmember";
@ -39,19 +53,11 @@ public class RestrictChatMember extends BotApiMethod<Boolean> {
private static final String PERMISSIONS_FIELD = "permissions";
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId; ///< Required. Unique identifier for the chat to send the message to (Or username for channels)
@JsonProperty(USER_ID_FIELD)
@NonNull
private Integer userId; ///< Required. Unique identifier of the target user
@JsonProperty(UNTILDATE_FIELD)
private Integer untilDate; ///< 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
@JsonProperty(CANSENDMESSAGES_FIELD)
private Boolean canSendMessages; ///< Pass True, if the user can send text messages, contacts, locations and venues
@JsonProperty(CANSENDMEDIAMESSAGES_FIELD)
private Boolean canSendMediaMessages; ///< Pass True, if the user can send audios, documents, photos, videos, video notes and voice notes, implies can_send_messages
@JsonProperty(CANSENDOTHERMESSAGES_FIELD)
private Boolean canSendOtherMessages; ///< Pass True, if the user can send animations, games, stickers and use inline bots, implies can_send_media_messages
@JsonProperty(CANADDWEBPAGEPREVIEWS_FIELD)
private Boolean canAddWebPagePreviews; ///< Pass True, if the user may add web page previews to their messages, implies can_send_messages
/**
* Optional
* Date when restrictions will be lifted for the user, unix time.
@ -59,144 +65,24 @@ public class RestrictChatMember extends BotApiMethod<Boolean> {
* from the current time, they are considered to be restricted forever
*/
@JsonProperty(PERMISSIONS_FIELD)
@NonNull
private ChatPermissions permissions;
@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
public RestrictChatMember() {
super();
}
public RestrictChatMember(String chatId, Integer userId) {
this.chatId = checkNotNull(chatId);
this.userId = checkNotNull(userId);
}
public RestrictChatMember(Long chatId, Integer userId) {
this.chatId = checkNotNull(chatId).toString();
this.userId = checkNotNull(userId);
}
public String getChatId() {
return chatId;
}
public RestrictChatMember setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public RestrictChatMember setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
public Integer getUserId() {
return userId;
}
public RestrictChatMember setUserId(Integer userId) {
this.userId = userId;
return this;
}
public Integer getUntilDate() {
return untilDate;
}
public RestrictChatMember setUntilDate(Integer untilDateInSeconds) {
this.untilDate = untilDateInSeconds;
return this;
@JsonIgnore
public void setUntilDateInstant(Instant instant) {
setUntilDate((int) instant.getEpochSecond());
}
@JsonIgnore
public RestrictChatMember setUntilDate(Instant instant) {
return setUntilDate((int) instant.getEpochSecond());
public void setUntilDateDateTime(ZonedDateTime date) {
setUntilDateInstant(date.toInstant());
}
@JsonIgnore
public RestrictChatMember setUntilDate(ZonedDateTime date) {
return setUntilDate(date.toInstant());
}
@JsonIgnore
public RestrictChatMember forTimePeriod(Duration duration) {
return setUntilDate(Instant.now().plusMillis(duration.toMillis()));
}
/**
* @deprecated Use {@link #getPermissions()} instead
*/
@Deprecated
public Boolean getCanSendMessages() {
return canSendMessages;
}
/**
* @deprecated Use {@link #setPermissions(ChatPermissions)} instead
*/
@Deprecated
public RestrictChatMember setCanSendMessages(Boolean canSendMessages) {
this.canSendMessages = canSendMessages;
return this;
}
/**
* @deprecated Use {@link #getPermissions()} instead
*/
@Deprecated
public Boolean getCanSendMediaMessages() {
return canSendMediaMessages;
}
/**
* @deprecated Use {@link #setPermissions(ChatPermissions)} instead
*/
@Deprecated
public RestrictChatMember setCanSendMediaMessages(Boolean canSendMediaMessages) {
this.canSendMediaMessages = canSendMediaMessages;
return this;
}
/**
* @deprecated Use {@link #getPermissions()} instead
*/
@Deprecated
public Boolean getCanSendOtherMessages() {
return canSendOtherMessages;
}
/**
* @deprecated Use {@link #setPermissions(ChatPermissions)} instead
*/
@Deprecated
public RestrictChatMember setCanSendOtherMessages(Boolean canSendOtherMessages) {
this.canSendOtherMessages = canSendOtherMessages;
return this;
}
/**
* @deprecated Use {@link #getPermissions()} instead
*/
@Deprecated
public Boolean getCanAddWebPagePreviews() {
return canAddWebPagePreviews;
}
/**
* @deprecated Use {@link #setPermissions(ChatPermissions)} instead
*/
@Deprecated
public RestrictChatMember setCanAddWebPagePreviews(Boolean canAddWebPagePreviews) {
this.canAddWebPagePreviews = canAddWebPagePreviews;
return this;
}
public ChatPermissions getPermissions() {
return permissions;
}
public void setPermissions(ChatPermissions permissions) {
this.permissions = permissions;
public void forTimePeriodDuration(Duration duration) {
setUntilDateInstant(Instant.now().plusMillis(duration.toMillis()));
}
@Override
@ -231,18 +117,4 @@ public class RestrictChatMember extends BotApiMethod<Boolean> {
throw new TelegramApiValidationException("Permissions can't be empty", this);
}
}
@Override
public String toString() {
return "RestrictChatMember{" +
"chatId='" + chatId + '\'' +
", userId=" + userId +
", untilDate=" + untilDate +
", canSendMessages=" + canSendMessages +
", canSendMediaMessages=" + canSendMediaMessages +
", canSendOtherMessages=" + canSendOtherMessages +
", canAddWebPagePreviews=" + canAddWebPagePreviews +
", permissions=" + permissions +
'}';
}
}

View File

@ -2,15 +2,20 @@ 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;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.IOException;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
@ -18,6 +23,13 @@ import static com.google.common.base.Preconditions.checkNotNull;
* Use this method to set a custom title for an administrator in a supergroup promoted by the bot.
* Returns True on success.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SetChatAdministratorCustomTitle extends BotApiMethod<Boolean> {
public static final String PATH = "setChatAdministratorCustomTitle";
@ -26,65 +38,15 @@ public class SetChatAdministratorCustomTitle extends BotApiMethod<Boolean> {
private static final String CUSTOMTITLE_FIELD = "custom_title";
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId; ///< Unique identifier for the target chat or username of the target channel (in the format @channelusername)
@JsonProperty(USERID_FIELD)
@NonNull
private Integer userId; ///< Unique identifier of the target user
@JsonProperty(CUSTOMTITLE_FIELD)
@NonNull
private String customTitle; ///< New custom title for the administrator; 0-16 characters, emoji are not allowed
public SetChatAdministratorCustomTitle() {
super();
}
public SetChatAdministratorCustomTitle(String chatId, Integer userId, String customTitle) {
super();
this.chatId = checkNotNull(chatId);
this.userId = checkNotNull(userId);
this.customTitle = checkNotNull(customTitle);
}
public SetChatAdministratorCustomTitle(Long chatId, Integer userId, String customTitle) {
super();
this.chatId = checkNotNull(chatId).toString();
this.userId = checkNotNull(userId);
this.customTitle = checkNotNull(customTitle);
}
public String getChatId() {
return chatId;
}
public SetChatAdministratorCustomTitle setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public SetChatAdministratorCustomTitle setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
public Integer getUserId() {
return userId;
}
public SetChatAdministratorCustomTitle setUserId(Integer userId) {
checkNotNull(userId);
this.userId = userId;
return this;
}
public String getCustomTitle() {
return customTitle;
}
public SetChatAdministratorCustomTitle setCustomTitle(String customTitle) {
checkNotNull(customTitle);
this.customTitle = customTitle;
return this;
}
@Override
public String getMethod() {
return PATH;
@ -117,13 +79,4 @@ public class SetChatAdministratorCustomTitle extends BotApiMethod<Boolean> {
throw new TelegramApiValidationException("CustomTitle can't be null", this);
}
}
@Override
public String toString() {
return "SetChatDescription{" +
"chatId='" + chatId + '\'' +
"userId='" + userId + '\'' +
", customTitle='" + customTitle + '\'' +
'}';
}
}

View File

@ -2,15 +2,21 @@ 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;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.IOException;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
@ -19,6 +25,14 @@ import static com.google.common.base.Preconditions.checkNotNull;
* The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
* Returns True on success.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@RequiredArgsConstructor
@AllArgsConstructor
@Builder
public class SetChatDescription extends BotApiMethod<Boolean> {
public static final String PATH = "setChatDescription";
@ -26,50 +40,10 @@ public class SetChatDescription extends BotApiMethod<Boolean> {
private static final String DESCRIPTION_FIELD = "description";
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId; ///< Unique identifier for the target chat or username of the target channel (in the format @channelusername)
@JsonProperty(DESCRIPTION_FIELD)
private String description; ///< New chat description, 0-255 characters
public SetChatDescription() {
super();
}
public SetChatDescription(String chatId, String description) {
super();
this.chatId = checkNotNull(chatId);
this.description = checkNotNull(description);
}
public SetChatDescription(Long chatId, String description) {
super();
this.chatId = checkNotNull(chatId).toString();
this.description = checkNotNull(description);
}
public String getChatId() {
return chatId;
}
public SetChatDescription setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public SetChatDescription setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
public String getDescription() {
return description;
}
public SetChatDescription setDescription(String description) {
Objects.requireNonNull(description);
this.description = description;
return this;
}
private String description; ///< Optional. New chat description, 0-255 characters
@Override
public String getMethod() {
@ -100,12 +74,4 @@ public class SetChatDescription extends BotApiMethod<Boolean> {
throw new TelegramApiValidationException("Description can't be null", this);
}
}
@Override
public String toString() {
return "SetChatDescription{" +
"chatId='" + chatId + '\'' +
", description='" + description + '\'' +
'}';
}
}

View File

@ -2,6 +2,14 @@ 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;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.ChatPermissions;
@ -9,9 +17,6 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.IOException;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
@ -20,6 +25,13 @@ import static com.google.common.base.Preconditions.checkNotNull;
* The bot must be an administrator in the group or a supergroup
* for this to work and must have the can_restrict_members admin rights.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SetChatPermissions extends BotApiMethod<Boolean> {
public static final String PATH = "setChatPermissions";
@ -27,51 +39,12 @@ public class SetChatPermissions extends BotApiMethod<Boolean> {
private static final String PERMISSIONS_FIELD = "permissions";
@JsonProperty(CHAT_ID_FIELD)
@NonNull
private String chatId; ///< Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
@JsonProperty(PERMISSIONS_FIELD)
@NonNull
private ChatPermissions permissions; ///< New default chat permissions
public SetChatPermissions() {
super();
}
public SetChatPermissions(String chatId, ChatPermissions permissions) {
super();
this.chatId = checkNotNull(chatId);
this.permissions = checkNotNull(permissions);
}
public SetChatPermissions(Long chatId, ChatPermissions permissions) {
super();
this.chatId = checkNotNull(chatId).toString();
this.permissions = checkNotNull(permissions);
}
public String getChatId() {
return chatId;
}
public SetChatPermissions setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public SetChatPermissions setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
public ChatPermissions getPermissions() {
return permissions;
}
public SetChatPermissions setPermissions(ChatPermissions permissions) {
Objects.requireNonNull(permissions);
this.permissions = permissions;
return this;
}
@Override
public String getMethod() {
return PATH;
@ -101,12 +74,4 @@ public class SetChatPermissions extends BotApiMethod<Boolean> {
throw new TelegramApiValidationException("Permissions can't be null", this);
}
}
@Override
public String toString() {
return "SetChatPermissions{" +
"chatId='" + chatId + '\'' +
", permissions=" + permissions +
'}';
}
}

View File

@ -1,17 +1,21 @@
package org.telegram.telegrambots.meta.api.methods.groupadministration;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
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.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
@ -22,87 +26,23 @@ import static com.google.common.base.Preconditions.checkNotNull;
*
* @apiNote In regular groups (non-supergroups), this method will only work if the All Members Are Admins setting is off in the target group.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SetChatPhoto extends PartialBotApiMethod<Boolean> {
public static final String PATH = "setChatPhoto";
public static final String CHATID_FIELD = "chat_id";
public static final String PHOTO_FIELD = "photo";
@NonNull
private String chatId; ///< Unique identifier for the target chat or username of the target channel (in the format @channelusername)
private String photoName; ///< Name of new chat photo
private InputStream photoStream; ///< New chat photo as InputStream, uploaded using multipart/form-data
private File photo; ///< New chat photo as File, uploaded using multipart/form-data
public SetChatPhoto() {
super();
}
public SetChatPhoto(String chatId, File photo) {
super();
this.chatId = checkNotNull(chatId);
this.photo = checkNotNull(photo);
}
public SetChatPhoto(String chatId, InputStream photoStream, String photoName) {
super();
this.chatId = checkNotNull(chatId);
this.photoStream = checkNotNull(photoStream);
this.photoName = checkNotNull(photoName);
}
public SetChatPhoto(Long chatId, File photo) {
super();
this.chatId = checkNotNull(chatId).toString();
this.photo = checkNotNull(photo);
}
public SetChatPhoto(Long chatId, InputStream photoStream, String photoName) {
super();
this.chatId = checkNotNull(chatId).toString();
this.photoStream = checkNotNull(photoStream);
this.photoName = checkNotNull(photoName);
}
public String getChatId() {
return chatId;
}
public SetChatPhoto setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public SetChatPhoto setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
public SetChatPhoto setPhoto(File file) {
this.photo = file;
return this;
}
public SetChatPhoto setNewPhoto(String photoName, InputStream inputStream) {
Objects.requireNonNull(photoName, "photoName cannot be null!");
Objects.requireNonNull(inputStream, "inputStream cannot be null!");
this.photoName = photoName;
this.photoStream = inputStream;
return this;
}
public String getPhotoName() {
return photoName;
}
public InputStream getPhotoStream() {
return photoStream;
}
public File getPhoto() {
return photo;
}
@NonNull
private InputFile photo; ///< New chat photo as InputStream, uploaded using multipart/form-data
@Override
public Boolean deserializeResponse(String answer) throws TelegramApiRequestException {
@ -124,22 +64,8 @@ public class SetChatPhoto extends PartialBotApiMethod<Boolean> {
if (chatId == null || chatId.isEmpty()) {
throw new TelegramApiValidationException("ChatId can't be empty", this);
}
if (photo == null) {
if (photoStream == null) {
throw new TelegramApiValidationException("Photo parameter is required", this);
} else if (photoName == null || photoName.isEmpty()){
throw new TelegramApiValidationException("Photo name can't be empty", this);
}
if (photo == null || !photo.isNew()) {
throw new TelegramApiValidationException("Photo parameter is required and must be a new file to upload", this);
}
}
@Override
public String toString() {
return "SetChatPhoto{" +
"chatId='" + chatId + '\'' +
", photoName='" + photoName + '\'' +
", photoStream=" + photoStream +
", photo=" + photo +
'}';
}
}

View File

@ -2,15 +2,20 @@ 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;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.IOException;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
@ -20,6 +25,13 @@ import static com.google.common.base.Preconditions.checkNotNull;
* Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method.
* Returns True on success.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SetChatStickerSet extends BotApiMethod<Boolean> {
public static final String PATH = "setChatStickerSet";
@ -27,50 +39,12 @@ public class SetChatStickerSet extends BotApiMethod<Boolean> {
private static final String STICKERSETNAME_FIELD = "sticker_set_name";
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
@JsonProperty(STICKERSETNAME_FIELD)
@NonNull
private String stickerSetName; ///< Name of the sticker set to be set as the group sticker set
public SetChatStickerSet() {
super();
}
public SetChatStickerSet(String chatId, String stickerSetName) {
super();
this.chatId = checkNotNull(chatId);
this.stickerSetName = checkNotNull(stickerSetName);
}
public SetChatStickerSet(Long chatId) {
super();
this.chatId = checkNotNull(chatId).toString();
}
public String getChatId() {
return chatId;
}
public SetChatStickerSet setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public SetChatStickerSet setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
public String getStickerSetName() {
return stickerSetName;
}
public SetChatStickerSet setStickerSetName(String stickerSetName) {
Objects.requireNonNull(stickerSetName);
this.stickerSetName = stickerSetName;
return this;
}
@Override
public String getMethod() {
return PATH;
@ -100,12 +74,4 @@ public class SetChatStickerSet extends BotApiMethod<Boolean> {
throw new TelegramApiValidationException("StickerSetName can't be empty", this);
}
}
@Override
public String toString() {
return "SetChatStickerSet{" +
"chatId='" + chatId + '\'' +
", stickerSetName='" + stickerSetName + '\'' +
'}';
}
}

View File

@ -2,15 +2,20 @@ 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;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.IOException;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
@ -21,6 +26,13 @@ import static com.google.common.base.Preconditions.checkNotNull;
*
* @apiNote In regular groups (non-supergroups), this method will only work if the All Members Are Admins setting is off in the target group.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SetChatTitle extends BotApiMethod<Boolean> {
public static final String PATH = "setChatTitle";
@ -28,51 +40,12 @@ public class SetChatTitle extends BotApiMethod<Boolean> {
private static final String TITLE_FIELD = "title";
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId; ///< Required. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
@JsonProperty(TITLE_FIELD)
@NonNull
private String title; ///< Required. New chat title, 1-255 characters
public SetChatTitle() {
super();
}
public SetChatTitle(String chatId, String title) {
super();
this.chatId = checkNotNull(chatId);
this.title = checkNotNull(title);
}
public SetChatTitle(Long chatId, String title) {
super();
this.chatId = checkNotNull(chatId).toString();
this.title = checkNotNull(title);
}
public String getChatId() {
return chatId;
}
public SetChatTitle setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public SetChatTitle setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
public String getTitle() {
return title;
}
public SetChatTitle setTitle(String title) {
Objects.requireNonNull(title);
this.title = title;
return this;
}
@Override
public String getMethod() {
return PATH;
@ -102,12 +75,4 @@ public class SetChatTitle extends BotApiMethod<Boolean> {
throw new TelegramApiValidationException("Title can't be empty", this);
}
}
@Override
public String toString() {
return "SetChatTitle{" +
"chatId='" + chatId + '\'' +
", title='" + title + '\'' +
'}';
}
}

View File

@ -2,74 +2,58 @@ 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;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.IOException;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 1.0
* Use this method to unban a previously kicked user in a supergroup. The user will not
* return to the group automatically, but will be able to join via link, etc. The bot must be an
* administrator in the group for this to work. Returns True on success.
* Use this method to unban a previously kicked user in a supergroup or channel.
* Returns True on success.
*
* @apiNote The user will not return to the group or channel automatically, but will be able to join via link, etc.
* @apiNote The bot must be an administrator for this to work.
* @apiNote By default, this method guarantees that after the call the user is not a member of the chat,
* but will be able to join it.
* @apiNote So if the user is a member of the chat they will also be removed from the chat. If you don't want this, use the parameter only_if_banned.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class UnbanChatMember extends BotApiMethod<Boolean> {
public static final String PATH = "unbanchatmember";
private static final String CHATID_FIELD = "chat_id";
private static final String USER_ID_FIELD = "user_id";
private static final String USERID_FIELD = "user_id";
private static final String ONLYISBANNED_FIELD = "only_if_banned";
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId; ///< Required. Unique identifier for the chat to send the message to (Or username for channels)
@JsonProperty(USER_ID_FIELD)
@JsonProperty(USERID_FIELD)
@NonNull
private Integer userId; ///< Required. Unique identifier of the target user
@JsonProperty(ONLYISBANNED_FIELD)
private Boolean onlyIfBanned; ///< Optional. Do nothing if the user is not banned
public UnbanChatMember() {
super();
}
public UnbanChatMember(String chatId, Integer userId) {
super();
this.chatId = checkNotNull(chatId);
this.userId = checkNotNull(userId);
}
public UnbanChatMember(Long chatId, Integer userId) {
super();
this.chatId = checkNotNull(chatId).toString();
this.userId = checkNotNull(userId);
}
public String getChatId() {
return chatId;
}
public UnbanChatMember setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public UnbanChatMember setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
public Integer getUserId() {
return userId;
}
public UnbanChatMember setUserId(Integer userId) {
this.userId = userId;
return this;
}
@Override
public String getMethod() {
@ -100,12 +84,4 @@ public class UnbanChatMember extends BotApiMethod<Boolean> {
throw new TelegramApiValidationException("UserId can't be null", this);
}
}
@Override
public String toString() {
return "UnbanChatMember{" +
"chatId='" + chatId + '\'' +
", userId='" + userId +
'}';
}
}

View File

@ -2,24 +2,39 @@ 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;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.IOException;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 3.1
* Use this method to pin a message in a group, a supergroup or a channel.
* The bot must be an administrator in the chat for this to work and must
* have the can_pin_messages admin right in the supergroup or can_edit_messages
* admin right in the channel. Returns True on success.
* Use this method to add a message to the list of pinned messages in a chat.
* Returns True on success.
*
* @apiNote If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must
* have the 'can_pin_messages' admin right in a supergroup or 'can_edit_messages' admin right in a channel.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class PinChatMessage extends BotApiMethod<Boolean> {
public static final String PATH = "pinChatMessage";
@ -28,8 +43,10 @@ public class PinChatMessage extends BotApiMethod<Boolean> {
private static final String DISABLENOTIFICATION_FIELD = "disable_notification";
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId; ///< Required. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
@JsonProperty(MESSAGEID_FIELD)
@NonNull
private Integer messageId; ///< Required. Identifier of a message to pin
/**
* Pass True, if it is not necessary to send a notification to all chat members about the new pinned message.
@ -38,56 +55,6 @@ public class PinChatMessage extends BotApiMethod<Boolean> {
@JsonProperty(DISABLENOTIFICATION_FIELD)
private Boolean disableNotification;
public PinChatMessage() {
super();
}
public PinChatMessage(String chatId, Integer messageId) {
super();
this.chatId = checkNotNull(chatId);
this.messageId = checkNotNull(messageId);
}
public PinChatMessage(Long chatId, Integer messageId) {
super();
this.chatId = checkNotNull(chatId).toString();
this.messageId = checkNotNull(messageId);
}
public String getChatId() {
return chatId;
}
public PinChatMessage setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public PinChatMessage setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
public Integer getMessageId() {
return messageId;
}
public PinChatMessage setMessageId(Integer messageId) {
Objects.requireNonNull(messageId);
this.messageId = messageId;
return this;
}
public Boolean getDisableNotification() {
return disableNotification;
}
public PinChatMessage setDisableNotification(Boolean disableNotification) {
this.disableNotification = disableNotification;
return this;
}
@Override
public String getMethod() {
return PATH;
@ -117,13 +84,4 @@ public class PinChatMessage extends BotApiMethod<Boolean> {
throw new TelegramApiValidationException("MessageId parameter can't be null", this);
}
}
@Override
public String toString() {
return "PinChatMessage{" +
"chatId='" + chatId + '\'' +
", messageId=" + messageId +
", disableNotification=" + disableNotification +
'}';
}
}

View File

@ -0,0 +1,72 @@
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;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.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
* Use this method to clear the list of pinned messages in a chat.
* Returns True on success.
*
* @apiNote If the chat is not a private chat, the bot must be an administrator in the chat for this to
* work and must have the 'can_pin_messages' admin right in a supergroup or 'can_edit_messages' admin
* right in a channel.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class UnpinAllChatMessages extends BotApiMethod<Boolean> {
public static final String PATH = "unpinAllChatMessages";
private static final String CHATID_FIELD = "chat_id";
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId; ///< Required. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
@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()) {
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
}
}
}

View File

@ -2,60 +2,57 @@ 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;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.IOException;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 3.1
* Use this method to unpin a message in a group, a supergroup or a channel.
* The bot must be an administrator in the chat for this to work and must have
* the can_pin_messages admin right in the supergroup or can_edit_messages
* admin right in the channel. Returns True on success.
* Use this method to remove a message from the list of pinned messages in a chat.
* Returns True on success.
*
* @apiNote If the chat is not a private chat, the bot must be an administrator in the chat for this to work
* and must have the 'can_pin_messages' admin right in a supergroup or 'can_edit_messages'
* admin right in a channel.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class UnpinChatMessage extends BotApiMethod<Boolean> {
public static final String PATH = "unpinChatMessage";
private static final String CHATID_FIELD = "chat_id";
private static final String MESSAGEID_FIELD = "message_id";
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId; ///< Required. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
public UnpinChatMessage() {
super();
}
public UnpinChatMessage(String chatId) {
super();
this.chatId = checkNotNull(chatId);
}
public UnpinChatMessage(Long chatId) {
super();
this.chatId = checkNotNull(chatId).toString();
}
public String getChatId() {
return chatId;
}
public UnpinChatMessage setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public UnpinChatMessage setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
/**
* Optional.
* Identifier of a message to unpin.
*
* @apiNote If not specified, the most recent pinned message (by send date) will be unpinned.
*/
@JsonProperty(MESSAGEID_FIELD)
private Integer messageId;
@Override
public String getMethod() {
@ -83,11 +80,4 @@ public class UnpinChatMessage extends BotApiMethod<Boolean> {
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
}
}
@Override
public String toString() {
return "UnpinChatMessage{" +
"chatId='" + chatId + '\'' +
'}';
}
}

View File

@ -3,19 +3,26 @@ 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;
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.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.ArrayList;
import java.util.List;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
@ -25,6 +32,14 @@ import static com.google.common.base.Preconditions.checkNotNull;
*
* On success, the sent Message is returned.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SendPoll extends BotApiMethod<Message> {
public static final String PATH = "sendPoll";
@ -43,17 +58,23 @@ public class SendPoll extends BotApiMethod<Message> {
private static final String CLOSEDATE_FIELD = "close_date";
private static final String EXPLANATION_FIELD = "explanation";
private static final String EXPLANATIONPARSEMODE_FIELD = "explanation_parse_mode";
private static final String EXPLANATION_ENTITIES_FIELD = "explanation_entities";
private static final String ALLOWSENDINGWITHOUTREPLY_FIELD = "allow_sending_without_reply";
/**
* Unique identifier for the target chat or username of the target channel (in the format @channelusername).
* A native poll can't be sent to a private chat.
*/
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId; ///< Unique identifier for the target chat or username of the target channel (in the format @channelusername)
@JsonProperty(QUESTION_FIELD)
private String question; ///< Poll question, 1-255 characters
@NonNull
private String question; ///< Poll question, 1-300 characters
@JsonProperty(OPTIONS_FIELD)
private List<String> options = new ArrayList<>(); ///< List of answer options, 2-10 strings 1-100 characters each
@Singular
@NonNull
private List<String> options; ///< List of answer options, 2-10 strings 1-100 characters each
@JsonProperty(ISANONYMOUS_FIELD)
private Boolean isAnonymous; ///< Optional True, if the poll needs to be anonymous, defaults to True
@JsonProperty(TYPE_FIELD)
@ -79,168 +100,18 @@ public class SendPoll extends BotApiMethod<Message> {
private String explanation; ///< Optional. Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters with at most 2 line feeds after entities parsing
@JsonProperty(EXPLANATIONPARSEMODE_FIELD)
private String explanationParseMode; ///< Optional. Mode for parsing entities in the explanation. See formatting options for more details.
@JsonProperty(EXPLANATION_ENTITIES_FIELD)
@Singular
private List<MessageEntity> explanationEntities; ///< Optional. List of special entities that appear in the poll explanation, which can be specified instead of parse_mode
@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
public SendPoll() {
super();
}
public SendPoll(String chatId, String question, List<String> options) {
this.chatId = checkNotNull(chatId);
this.question = checkNotNull(question);
this.options = checkNotNull(options);
}
public SendPoll(Long chatId, String question, List<String> options) {
this.chatId = checkNotNull(chatId).toString();
this.question = checkNotNull(question);
this.options = checkNotNull(options);
}
public String getChatId() {
return chatId;
}
public SendPoll setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public SendPoll setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
public String getQuestion() {
return question;
}
public SendPoll setQuestion(String question) {
this.question = question;
return this;
}
public List<String> getOptions() {
return options;
}
public SendPoll setOptions(List<String> options) {
this.options = options;
return this;
}
public Integer getReplyToMessageId() {
return replyToMessageId;
}
public SendPoll setReplyToMessageId(Integer replyToMessageId) {
this.replyToMessageId = replyToMessageId;
return this;
}
public ReplyKeyboard getReplyMarkup() {
return replyMarkup;
}
public SendPoll setReplyMarkup(ReplyKeyboard replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
public Boolean getDisableNotification() {
return disableNotification;
}
public SendPoll enableNotification() {
public void enableNotification() {
this.disableNotification = null;
return this;
}
public SendPoll disableNotification() {
public void disableNotification() {
this.disableNotification = true;
return this;
}
public Boolean getAnonymous() {
return isAnonymous;
}
public SendPoll setAnonymous(Boolean anonymous) {
isAnonymous = anonymous;
return this;
}
public String getType() {
return type;
}
public SendPoll setType(String type) {
this.type = type;
return this;
}
public Boolean getAllowMultipleAnswers() {
return allowMultipleAnswers;
}
public SendPoll setAllowMultipleAnswers(Boolean allowMultipleAnswers) {
this.allowMultipleAnswers = allowMultipleAnswers;
return this;
}
public Integer getCorrectOptionId() {
return correctOptionId;
}
public SendPoll setCorrectOptionId(Integer correctOptionId) {
this.correctOptionId = correctOptionId;
return this;
}
public Boolean getClosed() {
return isClosed;
}
public SendPoll setClosed(Boolean closed) {
isClosed = closed;
return this;
}
public Integer getOpenPeriod() {
return openPeriod;
}
public SendPoll setOpenPeriod(Integer openPeriod) {
this.openPeriod = openPeriod;
return this;
}
public Integer getCloseDate() {
return closeDate;
}
public SendPoll setCloseDate(Integer closeDate) {
this.closeDate = closeDate;
return this;
}
public String getExplanation() {
return explanation;
}
public SendPoll setExplanation(String explanation) {
this.explanation = explanation;
return this;
}
public String getExplanationParseMode() {
return explanationParseMode;
}
public SendPoll setExplanationParseMode(String explanationParseMode) {
this.explanationParseMode = explanationParseMode;
return this;
}
@Override
@ -287,57 +158,11 @@ public class SendPoll extends BotApiMethod<Message> {
if (options.parallelStream().anyMatch(x -> x.isEmpty() || x.length() > 100)) {
throw new TelegramApiValidationException("Options parameter values must be between 1 and 100 chars length", this);
}
if (explanationParseMode != null && (explanationEntities != null && !explanationEntities.isEmpty()) ) {
throw new TelegramApiValidationException("Parse mode can't be enabled if Entities are provided", this);
}
if (replyMarkup != null) {
replyMarkup.validate();
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof SendPoll)) return false;
SendPoll sendPoll = (SendPoll) o;
return Objects.equals(chatId, sendPoll.chatId) &&
Objects.equals(question, sendPoll.question) &&
Objects.equals(options, sendPoll.options) &&
Objects.equals(isAnonymous, sendPoll.isAnonymous) &&
Objects.equals(type, sendPoll.type) &&
Objects.equals(allowMultipleAnswers, sendPoll.allowMultipleAnswers) &&
Objects.equals(correctOptionId, sendPoll.correctOptionId) &&
Objects.equals(isClosed, sendPoll.isClosed) &&
Objects.equals(disableNotification, sendPoll.disableNotification) &&
Objects.equals(replyToMessageId, sendPoll.replyToMessageId) &&
Objects.equals(replyMarkup, sendPoll.replyMarkup) &&
Objects.equals(openPeriod, sendPoll.openPeriod) &&
Objects.equals(closeDate, sendPoll.closeDate) &&
Objects.equals(explanation, sendPoll.explanation) &&
Objects.equals(explanationParseMode, sendPoll.explanationParseMode);
}
@Override
public int hashCode() {
return Objects.hash(chatId, question, options, isAnonymous, type, allowMultipleAnswers, correctOptionId, isClosed,
disableNotification, replyToMessageId, replyMarkup, openPeriod, closeDate, explanation, explanationParseMode);
}
@Override
public String toString() {
return "SendPoll{" +
"chatId='" + chatId + '\'' +
", question='" + question + '\'' +
", options=" + options +
", isAnonymous=" + isAnonymous +
", type='" + type + '\'' +
", allowMultipleAnswers=" + allowMultipleAnswers +
", correctOptionId=" + correctOptionId +
", isClosed=" + isClosed +
", disableNotification=" + disableNotification +
", replyToMessageId=" + replyToMessageId +
", replyMarkup=" + replyMarkup +
", openPeriod=" + openPeriod +
", closeDate=" + closeDate +
", explanation='" + explanation + '\'' +
", explanationParseMode='" + explanationParseMode + '\'' +
'}';
}
}

View File

@ -2,16 +2,21 @@ 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;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.polls.Poll;
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;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
@ -20,6 +25,13 @@ import static com.google.common.base.Preconditions.checkNotNull;
*
* On success, the stopped Poll with the final results is returned.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class StopPoll extends BotApiMethod<Poll> {
public static final String PATH = "stopPoll";
@ -27,48 +39,12 @@ public class StopPoll extends BotApiMethod<Poll> {
private static final String MESSAGEID_FIELD = "message_id";
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId; ///< Unique identifier for the target chat or username of the target channel (in the format @channelusername)
@JsonProperty(MESSAGEID_FIELD)
@NonNull
private Integer messageId; ///< Identifier of the original message with the poll
public StopPoll() {
super();
}
public StopPoll(String chatId, Integer messageId) {
this.chatId = checkNotNull(chatId);
this.messageId = checkNotNull(messageId);
}
public StopPoll(Long chatId, Integer messageId) {
this.chatId = checkNotNull(chatId).toString();
this.messageId = checkNotNull(messageId);
}
public String getChatId() {
return chatId;
}
public StopPoll setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public StopPoll setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
public Integer getMessageId() {
return messageId;
}
public StopPoll setMessageId(Integer messageId) {
this.messageId = messageId;
return this;
}
@Override
public String getMethod() {
return PATH;
@ -98,31 +74,4 @@ public class StopPoll extends BotApiMethod<Poll> {
throw new TelegramApiValidationException("Message Id parameter can't be empty", this);
}
}
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof StopPoll)) {
return false;
}
StopPoll sendMessage = (StopPoll) o;
return Objects.equals(chatId, sendMessage.chatId)
&& Objects.equals(messageId, sendMessage.messageId)
;
}
@Override
public int hashCode() {
return Objects.hash(
chatId,
messageId);
}
@Override
public String toString() {
return "StopPoll{" +
"chatId='" + chatId + '\'' +
", messageId=" + messageId +
'}';
}
}

View File

@ -1,18 +1,27 @@
package org.telegram.telegrambots.meta.api.methods.send;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.Singular;
import lombok.ToString;
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.ApiResponse;
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.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;
import java.util.List;
/**
* @author Ruben Bermudez
@ -22,6 +31,14 @@ import java.util.Objects;
*
* Bots can currently send animation files of up to 50 MB in size, this limit may be changed in the future.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SendAnimation extends PartialBotApiMethod<Message> {
public static final String PATH = "sendAnimation";
@ -36,14 +53,17 @@ public class SendAnimation extends PartialBotApiMethod<Message> {
public static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
public static final String REPLYMARKUP_FIELD = "reply_markup";
public static final String THUMB_FIELD = "thumb";
public static final String CAPTION_ENTITIES_FIELD = "caption_entities";
public static final String ALLOWSENDINGWITHOUTREPLY_FIELD = "allow_sending_without_reply";
@NonNull
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
/**
* Animation to send. Pass a file_id as String to send an animation that exists on the
* Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get an animation
* from the Internet, or upload a new animation using multipart/form-data.
*/
@NonNull
private InputFile animation;
private Integer duration; ///< Optional. Duration of sent animation in seconds
private String caption; ///< Optional. Animation caption (may also be used when resending videos by file_id).
@ -54,6 +74,7 @@ public class SendAnimation extends PartialBotApiMethod<Message> {
private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
private String parseMode; ///< Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
/**
* Optional.
* Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size.
* A thumbnails width and height should not exceed 320.
* Ignored if the file is not uploaded using multipart/form-data.
@ -61,137 +82,16 @@ public class SendAnimation extends PartialBotApiMethod<Message> {
* if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
*/
private InputFile thumb;
@Singular
private List<MessageEntity> captionEntities; ///< Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode
private Boolean allowSendingWithoutReply; ///< Optional Pass True, if the message should be sent even if the specified replied-to message is not found
public SendAnimation() {
super();
}
public String getChatId() {
return chatId;
}
public SendAnimation setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public InputFile getAnimation() {
return animation;
}
public SendAnimation setAnimation(String animation) {
this.animation = new InputFile(animation);
return this;
}
public SendAnimation setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
public Integer getDuration() {
return duration;
}
public SendAnimation setDuration(Integer duration) {
this.duration = duration;
return this;
}
public String getCaption() {
return caption;
}
public SendAnimation setCaption(String caption) {
this.caption = caption;
return this;
}
public Integer getReplyToMessageId() {
return replyToMessageId;
}
public SendAnimation setReplyToMessageId(Integer replyToMessageId) {
this.replyToMessageId = replyToMessageId;
return this;
}
public ReplyKeyboard getReplyMarkup() {
return replyMarkup;
}
public SendAnimation setReplyMarkup(ReplyKeyboard replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
public Boolean getDisableNotification() {
return disableNotification;
}
public SendAnimation enableNotification() {
public void enableNotification() {
this.disableNotification = false;
return this;
}
public SendAnimation disableNotification() {
public void disableNotification() {
this.disableNotification = true;
return this;
}
public Integer getWidth() {
return width;
}
public SendAnimation setWidth(Integer width) {
this.width = width;
return this;
}
public Integer getHeight() {
return height;
}
public SendAnimation setHeight(Integer height) {
this.height = height;
return this;
}
public SendAnimation setAnimation(File file) {
this.animation = new InputFile(file, file.getName());
return this;
}
public SendAnimation setAnimation(String animationName, InputStream inputStream) {
Objects.requireNonNull(animationName, "animationName cannot be null!");
Objects.requireNonNull(inputStream, "inputStream cannot be null!");
this.animation = new InputFile(inputStream, animationName);
return this;
}
public SendAnimation setAnimation(InputFile animation) {
Objects.requireNonNull(animation, "animation cannot be null!");
this.animation = animation;
return this;
}
public String getParseMode() {
return parseMode;
}
public SendAnimation setParseMode(String parseMode) {
this.parseMode = parseMode;
return this;
}
public InputFile getThumb() {
return thumb;
}
public SendAnimation setThumb(InputFile thumb) {
this.thumb = thumb;
return this;
}
@Override
@ -219,6 +119,10 @@ public class SendAnimation extends PartialBotApiMethod<Message> {
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);
}
animation.validate();
if (replyMarkup != null) {
@ -228,20 +132,4 @@ public class SendAnimation extends PartialBotApiMethod<Message> {
thumb.validate();
}
}
@Override
public String toString() {
return "SendAnimation{" + "chatId='" + chatId + '\'' +
", animation=" + animation +
", duration=" + duration +
", caption='" + caption + '\'' +
", width=" + width +
", height=" + height +
", disableNotification=" + disableNotification +
", replyToMessageId=" + replyToMessageId +
", replyMarkup=" + replyMarkup +
", parseMode='" + parseMode + '\'' +
", thumb=" + thumb +
'}';
}
}

View File

@ -1,18 +1,27 @@
package org.telegram.telegrambots.meta.api.methods.send;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.Singular;
import lombok.ToString;
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.ApiResponse;
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.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;
import java.util.List;
/**
* @author Ruben Bermudez
@ -21,8 +30,16 @@ import java.util.Objects;
* Telegram clients to display them in the music player. Your audio must be in an .mp3 format. On
* success, the sent Message is returned. Bots can currently send audio files of up to 50 MB in
* size, this limit may be changed in the future.
* @note For sending voice notes, use sendVoice method instead.
* @apiNote For sending voice notes, use sendVoice method instead.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SendAudio extends PartialBotApiMethod<Message> {
public static final String PATH = "sendaudio";
@ -37,9 +54,14 @@ public class SendAudio extends PartialBotApiMethod<Message> {
public static final String CAPTION_FIELD = "caption";
public static final String PARSEMODE_FIELD = "parse_mode";
public static final String THUMB_FIELD = "thumb";
public static final String CAPTION_ENTITIES_FIELD = "caption_entities";
public static final String ALLOWSENDINGWITHOUTREPLY_FIELD = "allow_sending_without_reply";
@NonNull
private Integer duration; ///< Integer Duration of the audio in seconds as defined by sender
@NonNull
private String chatId; ///< Unique identifier for the chat to send the message to (or Username fro channels)
@NonNull
private InputFile audio; ///< Audio file to send. file_id as String to resend an audio that is already on the Telegram servers or Url to upload it
private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message
private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
@ -47,8 +69,9 @@ public class SendAudio extends PartialBotApiMethod<Message> {
private String performer; ///< Optional. Performer of sent audio
private String title; ///< Optional. Title of sent audio
private String caption; ///< Optional. Audio caption (may also be used when resending documents by file_id), 0-200 characters
private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
private String parseMode; ///< Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
/**
* Optional.
* Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size.
* A thumbnails width and height should not exceed 320.
* Ignored if the file is not uploaded using multipart/form-data.
@ -56,149 +79,16 @@ public class SendAudio extends PartialBotApiMethod<Message> {
* attach://<file_attach_name> if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
*/
private InputFile thumb;
@Singular
private List<MessageEntity> captionEntities; ///< Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode
private Boolean allowSendingWithoutReply; ///< Optional Pass True, if the message should be sent even if the specified replied-to message is not found
public SendAudio() {
super();
}
public Integer getDuration() {
return this.duration;
}
public SendAudio setDuration(Integer duration) {
this.duration = duration;
return this;
}
public String getChatId() {
return chatId;
}
public SendAudio setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public SendAudio setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
public InputFile getAudio() {
return audio;
}
/**
* Use this method to set the audio to an audio existing in Telegram system
*
* @param audio File_id of the audio to send
* @note The file_id must have already been received or sent by your bot
*/
public SendAudio setAudio(String audio) {
this.audio = new InputFile(audio);
return this;
}
/**
* Use this method to set the audio to a new file
*
* @param file New audio file
*/
public SendAudio setAudio(File file) {
Objects.requireNonNull(file, "file cannot be null!");
this.audio = new InputFile(file, file.getName());
return this;
}
public SendAudio setAudio(String audioName, InputStream inputStream) {
Objects.requireNonNull(audioName, "audioName cannot be null!");
Objects.requireNonNull(inputStream, "inputStream cannot be null!");
this.audio = new InputFile(inputStream, audioName);
return this;
}
public SendAudio setAudio(InputFile audio) {
Objects.requireNonNull(audio, "audio cannot be null!");
this.audio = audio;
return this;
}
public Integer getReplyToMessageId() {
return replyToMessageId;
}
public SendAudio setReplyToMessageId(Integer replyToMessageId) {
this.replyToMessageId = replyToMessageId;
return this;
}
public ReplyKeyboard getReplyMarkup() {
return replyMarkup;
}
public SendAudio setReplyMarkup(ReplyKeyboard replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
public String getPerformer() {
return performer;
}
public SendAudio setPerformer(String performer) {
this.performer = performer;
return this;
}
public String getTitle() {
return title;
}
public SendAudio setTitle(String title) {
this.title = title;
return this;
}
public Boolean getDisableNotification() {
return disableNotification;
}
public SendAudio enableNotification() {
public void enableNotification() {
this.disableNotification = false;
return this;
}
public SendAudio disableNotification() {
public void disableNotification() {
this.disableNotification = true;
return this;
}
public String getCaption() {
return caption;
}
public SendAudio setCaption(String caption) {
this.caption = caption;
return this;
}
public String getParseMode() {
return parseMode;
}
public SendAudio setParseMode(String parseMode) {
this.parseMode = parseMode;
return this;
}
public InputFile getThumb() {
return thumb;
}
public SendAudio setThumb(InputFile thumb) {
this.thumb = thumb;
return this;
}
@Override
@ -226,6 +116,10 @@ public class SendAudio extends PartialBotApiMethod<Message> {
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);
}
audio.validate();
if (thumb != null) {
@ -236,21 +130,4 @@ public class SendAudio extends PartialBotApiMethod<Message> {
replyMarkup.validate();
}
}
@Override
public String toString() {
return "SendAudio{" +
"duration=" + duration +
", chatId='" + chatId + '\'' +
", audio=" + audio +
", replyToMessageId=" + replyToMessageId +
", disableNotification=" + disableNotification +
", replyMarkup=" + replyMarkup +
", performer='" + performer + '\'' +
", title='" + title + '\'' +
", caption='" + caption + '\'' +
", parseMode='" + parseMode + '\'' +
", thumb=" + thumb +
'}';
}
}

View File

@ -3,7 +3,14 @@ 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;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.ActionType;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
@ -11,9 +18,6 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.IOException;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
@ -22,6 +26,13 @@ import static com.google.common.base.Preconditions.checkNotNull;
* side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram
* clients clear its typing status).
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SendChatAction extends BotApiMethod<Boolean> {
public static final String PATH = "sendChatAction";
@ -30,6 +41,7 @@ public class SendChatAction extends BotApiMethod<Boolean> {
private static final String ACTION_FIELD = "action";
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
/**
* Type of action to broadcast. Choose one, depending on what the user is about to receive: typing for text messages,
@ -38,46 +50,17 @@ public class SendChatAction extends BotApiMethod<Boolean> {
* record_video_note or upload_video_note for video notes.
*/
@JsonProperty(ACTION_FIELD)
@NonNull
private String action;
public SendChatAction() {
super();
}
public SendChatAction(String chatId, String action) {
this.chatId = checkNotNull(chatId);
this.action = checkNotNull(action);
}
public SendChatAction(Long chatId, String action) {
this.chatId = checkNotNull(chatId).toString();
this.action = checkNotNull(action);
}
public String getChatId() {
return chatId;
}
@JsonIgnore
public ActionType getAction() {
public ActionType getActionType() {
return ActionType.get(action);
}
public SendChatAction setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public SendChatAction setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
@JsonIgnore
public SendChatAction setAction(ActionType action) {
public void setAction(ActionType action) {
this.action = action.toString();
return this;
}
@Override
@ -109,12 +92,4 @@ public class SendChatAction extends BotApiMethod<Boolean> {
throw new TelegramApiValidationException("Action parameter can't be empty", this);
}
}
@Override
public String toString() {
return "SendChatAction{" +
"chatId='" + chatId + '\'' +
", action='" + action + '\'' +
'}';
}
}

View File

@ -2,16 +2,23 @@ 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;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.Message;
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.Objects;
/**
* @author Ruben Bermudez
@ -19,6 +26,14 @@ import java.util.Objects;
* Use this method to send information about user contact. On success, the sent Message is
* returned.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SendContact extends BotApiMethod<Message> {
public static final String PATH = "sendContact";
@ -30,12 +45,16 @@ public class SendContact extends BotApiMethod<Message> {
private static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
private static final String REPLYMARKUP_FIELD = "reply_markup";
private static final String VCARD_FIELD = "vcard";
private static final String ALLOWSENDINGWITHOUTREPLY_FIELD = "allow_sending_without_reply";
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
@JsonProperty(PHONE_NUMBER_FIELD)
@NonNull
private String phoneNumber; ///< User's phone number
@JsonProperty(FIRST_NAME_FIELD)
@NonNull
private String firstName; ///< User's first name
@JsonProperty(LAST_NAME_FIELD)
private String lastName; ///< Optional. User's last name
@ -47,91 +66,15 @@ public class SendContact extends BotApiMethod<Message> {
private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
@JsonProperty(VCARD_FIELD)
private String vCard; ///< Optional. Additional data about the contact in the form of a vCard
@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
public SendContact() {
super();
}
public String getChatId() {
return chatId;
}
public SendContact setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public SendContact setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
public Integer getReplyToMessageId() {
return replyToMessageId;
}
public SendContact setReplyToMessageId(Integer replyToMessageId) {
this.replyToMessageId = replyToMessageId;
return this;
}
public ReplyKeyboard getReplyMarkup() {
return replyMarkup;
}
public SendContact setReplyMarkup(ReplyKeyboard replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
public Boolean getDisableNotification() {
return disableNotification;
}
public SendContact enableNotification() {
public void enableNotification() {
this.disableNotification = false;
return this;
}
public SendContact disableNotification() {
public void disableNotification() {
this.disableNotification = true;
return this;
}
public String getPhoneNumber() {
return phoneNumber;
}
public SendContact setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
return this;
}
public String getFirstName() {
return firstName;
}
public SendContact setFirstName(String firstName) {
this.firstName = firstName;
return this;
}
public String getLastName() {
return lastName;
}
public SendContact setLastName(String lastName) {
this.lastName = lastName;
return this;
}
public String getvCard() {
return vCard;
}
public void setvCard(String vCard) {
this.vCard = vCard;
}
@Override
@ -169,18 +112,4 @@ public class SendContact extends BotApiMethod<Message> {
replyMarkup.validate();
}
}
@Override
public String toString() {
return "SendContact{" +
"chatId='" + chatId + '\'' +
", phoneNumber='" + phoneNumber + '\'' +
", firstName='" + firstName + '\'' +
", lastName='" + lastName + '\'' +
", disableNotification=" + disableNotification +
", replyToMessageId=" + replyToMessageId +
", replyMarkup=" + replyMarkup +
", vCard='" + vCard + '\'' +
'}';
}
}

View File

@ -2,6 +2,15 @@ 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;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.Message;
@ -19,8 +28,16 @@ import java.util.List;
* @version 4.7
* Use this method to send an animated emoji that will display a random value. On success, the sent Message is returned.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SendDice extends BotApiMethod<Message> {
private static final List<String> VALIDEMOJIS = Collections.unmodifiableList(Arrays.asList("\uD83C\uDFB2", "\uD83C\uDFAF", "\uD83C\uDFC0"));
private static final List<String> VALIDEMOJIS = Collections.unmodifiableList(Arrays.asList("🎲", "🎯", "🏀", "", "🎰"));
public static final String PATH = "sendDice";
@ -29,14 +46,19 @@ public class SendDice extends BotApiMethod<Message> {
private static final String DISABLENOTIFICATION_FIELD = "disable_notification";
private static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
private static final String REPLYMARKUP_FIELD = "reply_markup";
private static final String ALLOWSENDINGWITHOUTREPLY_FIELD = "allow_sending_without_reply";
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId; ///< Unique identifier for the target chat or username of the target channel (in the format @channelusername)
/**
* Emoji on which the dice throw animation is based. Currently, must be one of 🎲, 🎯, or 🏀.
* Dice can have values 1-6 for 🎲 and 🎯, and values 1-5 for 🏀. Defauts to 🎲
* Emoji on which the dice throw animation is based.
* Currently, must be one of 🎲, 🎯, 🏀, , or 🎰.
* Dice can have values 1-6 for 🎲 and 🎯, values 1-5 for 🏀 and , and values 1-64 for 🎰.
* Defaults to 🎲
*/
@JsonProperty(EMOJI_FIELD)
@NonNull
private String emoji;
@JsonProperty(DISABLENOTIFICATION_FIELD)
private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
@ -44,64 +66,15 @@ public class SendDice extends BotApiMethod<Message> {
private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message
@JsonProperty(REPLYMARKUP_FIELD)
private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
@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
public SendDice() {
super();
}
public String getChatId() {
return chatId;
}
public SendDice setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public SendDice setChatId(Long chatId) {
this.chatId = chatId.toString();
return this;
}
public Integer getReplyToMessageId() {
return replyToMessageId;
}
public SendDice setReplyToMessageId(Integer replyToMessageId) {
this.replyToMessageId = replyToMessageId;
return this;
}
public ReplyKeyboard getReplyMarkup() {
return replyMarkup;
}
public SendDice setReplyMarkup(ReplyKeyboard replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
public Boolean getDisableNotification() {
return disableNotification;
}
public SendDice enableNotification() {
public void enableNotification() {
this.disableNotification = false;
return this;
}
public SendDice disableNotification() {
public void disableNotification() {
this.disableNotification = true;
return this;
}
public String getEmoji() {
return emoji;
}
public SendDice setEmoji(String emoji) {
this.emoji = emoji;
return this;
}
@Override
@ -130,21 +103,10 @@ public class SendDice extends BotApiMethod<Message> {
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
}
if (emoji != null && !VALIDEMOJIS.contains(emoji)) {
throw new TelegramApiValidationException("Only \uD83C\uDFB2, \uD83C\uDFAF or \uD83C\uDFC0 are allowed in Emoji field ", this);
throw new TelegramApiValidationException("Only \"\uD83C\uDFB2\", \"\uD83C\uDFAF\", \"\uD83C\uDFC0\", \"\", \"\uD83C\uDFB0\" are allowed in Emoji field ", this);
}
if (replyMarkup != null) {
replyMarkup.validate();
}
}
@Override
public String toString() {
return "SendDice{" +
"chatId='" + chatId + '\'' +
", emoji='" + emoji + '\'' +
", disableNotification=" + disableNotification +
", replyToMessageId=" + replyToMessageId +
", replyMarkup=" + replyMarkup +
'}';
}
}

View File

@ -1,24 +1,41 @@
package org.telegram.telegrambots.meta.api.methods.send;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.Singular;
import lombok.ToString;
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.ApiResponse;
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.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;
import java.util.List;
/**
* @author Ruben Bermudez
* @version 1.0
* Use this method to send general files. On success, the sent Message is returned.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SendDocument extends PartialBotApiMethod<Message> {
public static final String PATH = "senddocument";
@ -30,15 +47,21 @@ public class SendDocument extends PartialBotApiMethod<Message> {
public static final String REPLYMARKUP_FIELD = "reply_markup";
public static final String PARSEMODE_FIELD = "parse_mode";
public static final String THUMB_FIELD = "thumb";
public static final String CAPTION_ENTITIES_FIELD = "caption_entities";
public static final String ALLOWSENDINGWITHOUTREPLY_FIELD = "allow_sending_without_reply";
public static final String DISABLECONTENTTYPEDETECTION_FIELD = "disable_content_type_detection";
@NonNull
private String chatId; ///< Unique identifier for the chat to send the message to or Username for the channel to send the message to
@NonNull
private InputFile document; ///< File file to send. file_id as String to resend a file that is already on the Telegram servers or Url to upload it
private String caption; ///< Optional. Document caption (may also be used when resending documents by file_id), 0-200 characters
private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message
private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
private String parseMode; ///< Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
/**
* Optional.
* Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size.
* A thumbnails width and height should not exceed 320.
* Ignored if the file is not uploaded using multipart/form-data.
@ -46,122 +69,17 @@ public class SendDocument extends PartialBotApiMethod<Message> {
* if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
*/
private InputFile thumb;
@Singular
private List<MessageEntity> captionEntities; ///< Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode
private Boolean allowSendingWithoutReply; ///< Optional Pass True, if the message should be sent even if the specified replied-to message is not found
private Boolean disableContentTypeDetection; ///< Optional Disables automatic server-side content type detection for files uploaded using multipart/form-data
public SendDocument() {
super();
}
public String getChatId() {
return chatId;
}
public SendDocument setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public SendDocument setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
public InputFile getDocument() {
return document;
}
/**
* Use this method to set the document to an document existing in Telegram system
*
* @param document File_id of the document to send
* @note The file_id must have already been received or sent by your bot
*/
public SendDocument setDocument(String document) {
this.document = new InputFile(document);
return this;
}
/**
* Use this method to set the document to a new file
*
* @param file New document file
*/
public SendDocument setDocument(File file) {
Objects.requireNonNull(file, "documentName cannot be null!");
this.document = new InputFile(file, file.getName());
return this;
}
public SendDocument setDocument(InputFile document) {
Objects.requireNonNull(document, "document cannot be null!");
this.document = document;
return this;
}
public SendDocument setDocument(String documentName, InputStream inputStream) {
Objects.requireNonNull(documentName, "documentName cannot be null!");
Objects.requireNonNull(inputStream, "inputStream cannot be null!");
this.document = new InputFile(inputStream, documentName);
return this;
}
public Integer getReplyToMessageId() {
return replyToMessageId;
}
public SendDocument setReplyToMessageId(Integer replyToMessageId) {
this.replyToMessageId = replyToMessageId;
return this;
}
public Boolean getDisableNotification() {
return disableNotification;
}
public SendDocument enableNotification() {
public void enableNotification() {
this.disableNotification = false;
return this;
}
public SendDocument disableNotification() {
public void disableNotification() {
this.disableNotification = true;
return this;
}
public String getCaption() {
return caption;
}
public SendDocument setCaption(String caption) {
this.caption = caption;
return this;
}
public ReplyKeyboard getReplyMarkup() {
return replyMarkup;
}
public SendDocument setReplyMarkup(ReplyKeyboard replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
public String getParseMode() {
return parseMode;
}
public SendDocument setParseMode(String parseMode) {
this.parseMode = parseMode;
return this;
}
public InputFile getThumb() {
return thumb;
}
public SendDocument setThumb(InputFile thumb) {
this.thumb = thumb;
return this;
}
@Override
@ -189,6 +107,10 @@ public class SendDocument extends PartialBotApiMethod<Message> {
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);
}
document.validate();
if (thumb != null) {
@ -199,18 +121,4 @@ public class SendDocument extends PartialBotApiMethod<Message> {
replyMarkup.validate();
}
}
@Override
public String toString() {
return "SendDocument{" +
"chatId='" + chatId + '\'' +
", document=" + document +
", caption='" + caption + '\'' +
", disableNotification=" + disableNotification +
", replyToMessageId=" + replyToMessageId +
", replyMarkup=" + replyMarkup +
", parseMode='" + parseMode + '\'' +
", thumb=" + thumb +
'}';
}
}

View File

@ -19,22 +19,37 @@ 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;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.Message;
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.Objects;
/**
* @author Ruben Bermudez
* @version 1.0
* Use this method to send a game. On success, the sent Message is returned.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SendGame extends BotApiMethod<Message> {
public static final String PATH = "sendGame";
@ -43,10 +58,13 @@ public class SendGame extends BotApiMethod<Message> {
private static final String DISABLENOTIFICATION_FIELD = "disable_notification";
private static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
private static final String REPLYMARKUP_FIELD = "reply_markup";
private static final String ALLOWSENDINGWITHOUTREPLY_FIELD = "allow_sending_without_reply";
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
@JsonProperty(GAMESHORTNAME_FIELD)
@NonNull
private String gameShortName; ///< Short name of the game
@JsonProperty(DISABLENOTIFICATION_FIELD)
private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
@ -54,65 +72,15 @@ public class SendGame extends BotApiMethod<Message> {
private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message
@JsonProperty(REPLYMARKUP_FIELD)
private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
@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
public SendGame() {
super();
}
public String getChatId() {
return chatId;
}
public SendGame setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public SendGame setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
public Integer getReplyToMessageId() {
return replyToMessageId;
}
public SendGame setReplyToMessageId(Integer replyToMessageId) {
this.replyToMessageId = replyToMessageId;
return this;
}
public ReplyKeyboard getReplyMarkup() {
return replyMarkup;
}
public SendGame setReplyMarkup(ReplyKeyboard replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
public Boolean getDisableNotification() {
return disableNotification;
}
public SendGame enableNotification() {
public void enableNotification() {
this.disableNotification = null;
return this;
}
public SendGame disableNotification() {
public void disableNotification() {
this.disableNotification = true;
return this;
}
public String getGameShortName() {
return gameShortName;
}
public SendGame setGameShortName(String gameShortName) {
this.gameShortName = gameShortName;
return this;
}
@Override
@ -147,15 +115,4 @@ public class SendGame extends BotApiMethod<Message> {
replyMarkup.validate();
}
}
@Override
public String toString() {
return "SendGame{" +
"chatId='" + chatId + '\'' +
", gameShortName='" + gameShortName + '\'' +
", disableNotification=" + disableNotification +
", replyToMessageId=" + replyToMessageId +
", replyMarkup=" + replyMarkup +
'}';
}
}

View File

@ -2,10 +2,19 @@ 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;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.payments.LabeledPrice;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
@ -13,13 +22,19 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.IOException;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @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";
@ -46,22 +61,31 @@ public class SendInvoice extends BotApiMethod<Message> {
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";
@JsonProperty(CHATID_FIELD)
@NonNull
private Integer chatId; ///< Unique identifier for the target private chat
@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
@JsonProperty(START_PARAMETER_FIELD)
@NonNull
private String startParameter; ///< Unique deep-linking parameter that can be used to generate this invoice when used as a start parameter.
@JsonProperty(CURRENCY_FIELD)
@NonNull
private String currency; ///< 3-letter ISO 4217 currency code
@JsonProperty(PRICES_FIELD)
@NonNull
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.
@ -97,250 +121,19 @@ public class SendInvoice extends BotApiMethod<Message> {
/**
* Optional. A JSON-serialized object for an inline keyboard.
*
* @note If empty, one 'Buy title' button will be shown. If not empty, the first button must be a Pay button.
* @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.
*
* @note A detailed description of required fields should be provided by the payment provider.
* @apiNote A detailed description of required fields should be provided by the payment provider.
*/
@JsonProperty(PROVIDER_DATA_FIELD)
private String providerData;
/**
* Build an empty SendInvoice object
*/
public SendInvoice() {
super();
}
/**
* Build a SendInvoice object with empty parameters
* @param chatId Unique identifier for the target private chat
* @param title Product name
* @param description Product description
* @param payload Bot defined invoice payload, 1-128 bytes.
* @param providerToken Payments provider token
* @param startParameter Unique deep-linking parameter.
* @param currency 3-letter ISO 4217 currency code
* @param prices Price breakdown, a list of components
*/
public SendInvoice(Integer chatId, String title, String description, String payload, String providerToken,
String startParameter, String currency, List<LabeledPrice> prices) {
this.chatId = checkNotNull(chatId);
this.title = checkNotNull(title);
this.description = checkNotNull(description);
this.payload = checkNotNull(payload);
this.providerToken = checkNotNull(providerToken);
this.startParameter = checkNotNull(startParameter);
this.currency = checkNotNull(currency);
this.prices = checkNotNull(prices);
}
public Integer getChatId() {
return chatId;
}
public SendInvoice setChatId(Integer chatId) {
this.chatId = checkNotNull(chatId);
return this;
}
public String getTitle() {
return title;
}
public SendInvoice setTitle(String title) {
this.title = checkNotNull(title);
return this;
}
public String getDescription() {
return description;
}
public SendInvoice setDescription(String description) {
this.description = checkNotNull(description);
return this;
}
public String getPayload() {
return payload;
}
public SendInvoice setPayload(String payload) {
this.payload = checkNotNull(payload);
return this;
}
public String getProviderToken() {
return providerToken;
}
public SendInvoice setProviderToken(String providerToken) {
this.providerToken = checkNotNull(providerToken);
return this;
}
public String getStartParameter() {
return startParameter;
}
public SendInvoice setStartParameter(String startParameter) {
this.startParameter = checkNotNull(startParameter);
return this;
}
public String getCurrency() {
return currency;
}
public SendInvoice setCurrency(String currency) {
this.currency = checkNotNull(currency);
return this;
}
public List<LabeledPrice> getPrices() {
return prices;
}
public SendInvoice setPrices(List<LabeledPrice> prices) {
this.prices = checkNotNull(prices);
return this;
}
public String getPhotoUrl() {
return photoUrl;
}
public SendInvoice setPhotoUrl(String photoUrl) {
this.photoUrl = photoUrl;
return this;
}
public Integer getPhotoSize() {
return photoSize;
}
public SendInvoice setPhotoSize(Integer photoSize) {
this.photoSize = photoSize;
return this;
}
public Integer getPhotoWidth() {
return photoWidth;
}
public SendInvoice setPhotoWidth(Integer photoWidth) {
this.photoWidth = photoWidth;
return this;
}
public Integer getPhotoHeight() {
return photoHeight;
}
public SendInvoice setPhotoHeight(Integer photoHeight) {
this.photoHeight = photoHeight;
return this;
}
public Boolean getNeedName() {
return needName;
}
public SendInvoice setNeedName(Boolean needName) {
this.needName = needName;
return this;
}
public Boolean getNeedPhoneNumber() {
return needPhoneNumber;
}
public SendInvoice setNeedPhoneNumber(Boolean needPhoneNumber) {
this.needPhoneNumber = needPhoneNumber;
return this;
}
public Boolean getNeedEmail() {
return needEmail;
}
public SendInvoice setNeedEmail(Boolean needEmail) {
this.needEmail = needEmail;
return this;
}
public Boolean getNeedShippingAddress() {
return needShippingAddress;
}
public SendInvoice setNeedShippingAddress(Boolean needShippingAddress) {
this.needShippingAddress = needShippingAddress;
return this;
}
public Boolean getSendPhoneNumberToProvider() { return sendPhoneNumberToProvider; }
public SendInvoice setSendPhoneNumberToProvider(Boolean sendPhoneNumberToProvider) {
this.sendPhoneNumberToProvider = sendPhoneNumberToProvider;
return this;
}
public Boolean getSendEmailToProvider() { return sendEmailToProvider; }
public SendInvoice setSendEmailToProvider(Boolean sendEmailToProvider) {
this.sendEmailToProvider = sendEmailToProvider;
return this;
}
public Boolean getFlexible() {
return isFlexible;
}
public SendInvoice setFlexible(Boolean flexible) {
isFlexible = flexible;
return this;
}
public Boolean getDisableNotification() {
return disableNotification;
}
public SendInvoice setDisableNotification(Boolean disableNotification) {
this.disableNotification = disableNotification;
return this;
}
public Integer getReplyToMessageId() {
return replyToMessageId;
}
public SendInvoice setReplyToMessageId(Integer replyToMessageId) {
this.replyToMessageId = replyToMessageId;
return this;
}
public InlineKeyboardMarkup getReplyMarkup() {
return replyMarkup;
}
public SendInvoice setReplyMarkup(InlineKeyboardMarkup replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
public String getProviderData() {
return providerData;
}
public SendInvoice setProviderData(String providerData) {
this.providerData = providerData;
return this;
}
@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
@Override
public String getMethod() {
@ -396,33 +189,4 @@ public class SendInvoice extends BotApiMethod<Message> {
replyMarkup.validate();
}
}
@Override
public String toString() {
return "SendInvoice{" +
"chatId=" + chatId +
", title='" + title + '\'' +
", description='" + description + '\'' +
", payload='" + payload + '\'' +
", providerToken='" + providerToken + '\'' +
", startParameter='" + startParameter + '\'' +
", currency='" + currency + '\'' +
", prices=" + prices +
", photoUrl='" + photoUrl + '\'' +
", photoSize=" + photoSize +
", photoWidth=" + photoWidth +
", photoHeight=" + photoHeight +
", needName=" + needName +
", needPhoneNumber=" + needPhoneNumber +
", needEmail=" + needEmail +
", needShippingAddress=" + needShippingAddress +
", sendPhoneNumberToProvider=" + sendPhoneNumberToProvider +
", sendEmailToProvider=" + sendEmailToProvider +
", isFlexible=" + isFlexible +
", disableNotification=" + disableNotification +
", replyToMessageId=" + replyToMessageId +
", replyMarkup=" + replyMarkup +
", providerData='" + providerData + '\'' +
'}';
}
}

View File

@ -2,23 +2,37 @@ 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;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.Message;
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.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 1.0
* Use this method to send point on the map. On success, the sent Message is returned.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SendLocation extends BotApiMethod<Message> {
public static final String PATH = "sendlocation";
@ -29,13 +43,20 @@ public class SendLocation extends BotApiMethod<Message> {
private static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
private static final String REPLYMARKUP_FIELD = "reply_markup";
private static final String LIVEPERIOD_FIELD = "live_period";
private static final String ALLOWSENDINGWITHOUTREPLY_FIELD = "allow_sending_without_reply";
private static final String HORIZONTALACCURACY_FIELD = "horizontal_accuracy";
private static final String HEADING_FIELD = "heading";
private static final String PROXIMITYALERTRADIUS_FIELD = "proximity_alert_radius";
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
@JsonProperty(LATITUDE_FIELD)
private Float latitude; ///< Latitude of location
@NonNull
private Double latitude; ///< Latitude of location
@JsonProperty(LONGITUDE_FIELD)
private Float longitude; ///< Longitude of location
@NonNull
private Double longitude; ///< Longitude of location
@JsonProperty(DISABLENOTIFICATION_FIELD)
private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
@JsonProperty(REPLYTOMESSAGEID_FIELD)
@ -44,91 +65,35 @@ public class SendLocation extends BotApiMethod<Message> {
private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
@JsonProperty(LIVEPERIOD_FIELD)
private Integer livePeriod; ///< Optional. Period in seconds for which the location will be updated (see Live Locations), should be between 60 and 86400.
@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
/**
* Optional.
* The radius of uncertainty for the location, measured in meters; 0-1500
*/
@JsonProperty(HORIZONTALACCURACY_FIELD)
private Double horizontalAccuracy;
/**
* Optional.
* For live locations, a direction in which the user is moving, in degrees.
* Must be between 1 and 360 if specified.
*/
@JsonProperty(HEADING_FIELD)
private Integer heading;
/**
* Optional.
* For live locations, a maximum distance for proximity alerts about approaching another chat member, in meters.
* Must be between 1 and 100000 if specified.
*/
@JsonProperty(PROXIMITYALERTRADIUS_FIELD)
private Integer proximityAlertRadius;
public SendLocation() {
super();
}
public SendLocation(Float latitude, Float longitude) {
super();
this.latitude = checkNotNull(latitude);
this.longitude = checkNotNull(longitude);
}
public String getChatId() {
return chatId;
}
public SendLocation setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public SendLocation setChatId(Long chatId) {
this.chatId = chatId.toString();
return this;
}
public Float getLatitude() {
return latitude;
}
public SendLocation setLatitude(Float latitude) {
Objects.requireNonNull(latitude);
this.latitude = latitude;
return this;
}
public Float getLongitude() {
return longitude;
}
public SendLocation setLongitude(Float longitude) {
Objects.requireNonNull(longitude);
this.longitude = longitude;
return this;
}
public Integer getReplyToMessageId() {
return replyToMessageId;
}
public SendLocation setReplyToMessageId(Integer replyToMessageId) {
this.replyToMessageId = replyToMessageId;
return this;
}
public ReplyKeyboard getReplyMarkup() {
return replyMarkup;
}
public SendLocation setReplyMarkup(ReplyKeyboard replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
public Boolean getDisableNotification() {
return disableNotification;
}
public SendLocation enableNotification() {
public void enableNotification() {
this.disableNotification = false;
return this;
}
public SendLocation disableNotification() {
public void disableNotification() {
this.disableNotification = true;
return this;
}
public Integer getLivePeriod() {
return livePeriod;
}
public SendLocation setLivePeriod(Integer livePeriod) {
this.livePeriod = livePeriod;
return this;
}
@Override
@ -162,6 +127,15 @@ public class SendLocation extends BotApiMethod<Message> {
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);
}
if (heading != null && (heading < 1 || heading > 360)) {
throw new TelegramApiValidationException("Heading Accuracy parameter must be between 1 and 360", this);
}
if (proximityAlertRadius != null && (proximityAlertRadius < 1 || proximityAlertRadius > 100000)) {
throw new TelegramApiValidationException("Proximity alert radius parameter must be between 1 and 100000", this);
}
if (replyMarkup != null) {
replyMarkup.validate();
}
@ -169,17 +143,4 @@ public class SendLocation extends BotApiMethod<Message> {
throw new TelegramApiValidationException("Live period parameter must be between 60 and 86400", this);
}
}
@Override
public String toString() {
return "SendLocation{" +
"chatId='" + chatId + '\'' +
", latitude=" + latitude +
", longitude=" + longitude +
", disableNotification=" + disableNotification +
", replyToMessageId=" + replyToMessageId +
", replyMarkup=" + replyMarkup +
", livePeriod=" + livePeriod +
'}';
}
}

View File

@ -2,12 +2,22 @@ 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;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.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.InputMediaPhoto;
import org.telegram.telegrambots.meta.api.objects.media.InputMediaVideo;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.media.InputMediaAnimation;
import org.telegram.telegrambots.meta.api.objects.media.InputMediaAudio;
import org.telegram.telegrambots.meta.api.objects.media.InputMediaDocument;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
@ -15,16 +25,23 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 3.5
*
* Use this method to send a group of photos or videos as an album.
* On success, an array of the sent Messages is returned.
* Use this method to send a group of photos, videos, documents or audios as an album.
* Documents and audio files can be only group in an album with messages of the same type.
* On success, an array of Messages that were sent is returned.
*/
@SuppressWarnings("unused")
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SendMediaGroup extends PartialBotApiMethod<ArrayList<Message>> {
public static final String PATH = "sendMediaGroup";
@ -32,75 +49,27 @@ public class SendMediaGroup extends PartialBotApiMethod<ArrayList<Message>> {
public static final String MEDIA_FIELD = "media";
public static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
public static final String DISABLENOTIFICATION_FIELD = "disable_notification";
public static final String ALLOWSENDINGWITHOUTREPLY_FIELD = "allow_sending_without_reply";
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId; ///< Unique identifier for the target chat or username of the target channel (in the format @channelusername)
@JsonProperty(MEDIA_FIELD)
private List<InputMedia> media; ///< A JSON-serialized array describing photos and videos to be sent, must include 210 items
@NonNull
private List<InputMedia> medias; ///< A JSON-serialized array describing photos and videos to be sent, must include 210 items
@JsonProperty(REPLYTOMESSAGEID_FIELD)
private Integer replyToMessageId; ///< Optional. If the messages are a reply, ID of the original message
@JsonProperty(DISABLENOTIFICATION_FIELD)
private Boolean disableNotification; ///< Optional. Sends the messages silently. Users will receive a notification with no sound.
@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
public SendMediaGroup() {
super();
}
public SendMediaGroup(String chatId, List<InputMedia> media) {
super();
this.chatId = checkNotNull(chatId);
this.media = checkNotNull(media);
}
public SendMediaGroup(Long chatId, List<InputMedia> media) {
super();
this.chatId = checkNotNull(chatId).toString();
this.media = checkNotNull(media);
}
public String getChatId() {
return chatId;
}
public SendMediaGroup setChatId(String chatId) {
this.chatId = checkNotNull(chatId);
return this;
}
public SendMediaGroup setChatId(Long chatId) {
this.chatId = checkNotNull(chatId).toString();
return this;
}
public Integer getReplyToMessageId() {
return replyToMessageId;
}
public SendMediaGroup setReplyToMessageId(Integer replyToMessageId) {
this.replyToMessageId = replyToMessageId;
return this;
}
public Boolean getDisableNotification() {
return disableNotification;
}
public SendMediaGroup enableNotification() {
public void enableNotification() {
this.disableNotification = false;
return this;
}
public SendMediaGroup disableNotification() {
public void disableNotification() {
this.disableNotification = true;
return this;
}
public List<InputMedia> getMedia() {
return media;
}
public void setMedia(List<InputMedia> media) {
this.media = media;
}
@Override
@ -125,26 +94,30 @@ public class SendMediaGroup extends PartialBotApiMethod<ArrayList<Message>> {
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
}
if (media == null || media.isEmpty()) {
if (medias == null || 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);
}
for (InputMedia inputMedia : media) {
if (inputMedia instanceof InputMediaPhoto || inputMedia instanceof InputMediaVideo) {
inputMedia.validate();
for (InputMedia inputMedia : medias) {
if (inputMedia == null) {
throw new TelegramApiValidationException("Media parameter can not be empty", this);
} else if (inputMedia instanceof InputMediaAnimation) {
throw new TelegramApiValidationException("Media parameter can not be an Animation", this);
} else {
throw new TelegramApiValidationException("Media parameter can only be Photo or Video", this);
inputMedia.validate();
}
}
if (medias.stream().anyMatch(x -> x instanceof InputMediaAudio)) {
if (!medias.stream().allMatch(x -> x instanceof InputMediaAudio)) {
throw new TelegramApiValidationException("Media parameter containing Audio can not have other types", this);
}
} else if (medias.stream().anyMatch(x -> x instanceof InputMediaDocument)) {
if (!medias.stream().allMatch(x -> x instanceof InputMediaDocument)) {
throw new TelegramApiValidationException("Media parameter containing Document can not have other types", this);
}
}
}
@Override
public String toString() {
return "SendMediaGroup{" +
"chatId='" + chatId + '\'' +
", media=" + media +
", replyToMessageId=" + replyToMessageId +
", disableNotification=" + disableNotification +
'}';
}
}

View File

@ -3,24 +3,41 @@ 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;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.methods.ParseMode;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.Message;
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.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.List;
/**
* @author Ruben Bermudez
* @version 1.0
* Use this method to send text messages. On success, the sent Message is returned.
*/
@SuppressWarnings("unused")
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SendMessage extends BotApiMethod<Message> {
public static final String PATH = "sendmessage";
@ -31,10 +48,14 @@ public class SendMessage extends BotApiMethod<Message> {
private static final String DISABLENOTIFICATION_FIELD = "disable_notification";
private static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
private static final String REPLYMARKUP_FIELD = "reply_markup";
private static final String ENTITIES_FIELD = "entities";
private static final String ALLOWSENDINGWITHOUTREPLY_FIELD = "allow_sending_without_reply";
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
@JsonProperty(TEXT_FIELD)
@NonNull
private String text; ///< Text of the message to be sent
@JsonProperty(PARSEMODE_FIELD)
private String parseMode; ///< Optional. Send Markdown, if you want Telegram apps to show bold, italic and URL text in your bot's message.
@ -47,121 +68,49 @@ public class SendMessage extends BotApiMethod<Message> {
@JsonProperty(REPLYMARKUP_FIELD)
@JsonDeserialize()
private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
@JsonProperty(ENTITIES_FIELD)
private List<MessageEntity> entities; ///< Optional. List of special entities that appear in message text, which can be specified instead of parse_mode
@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
public SendMessage() {
super();
}
public SendMessage(String chatId, String text) {
this.chatId = checkNotNull(chatId);
this.text = checkNotNull(text);
}
public SendMessage(Long chatId, String text) {
this.chatId = checkNotNull(chatId).toString();
this.text = checkNotNull(text);
}
public String getChatId() {
return chatId;
}
public SendMessage setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public SendMessage setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
public String getText() {
return text;
}
public SendMessage setText(String text) {
this.text = text;
return this;
}
public Integer getReplyToMessageId() {
return replyToMessageId;
}
public SendMessage setReplyToMessageId(Integer replyToMessageId) {
this.replyToMessageId = replyToMessageId;
return this;
}
public ReplyKeyboard getReplyMarkup() {
return replyMarkup;
}
public SendMessage setReplyMarkup(ReplyKeyboard replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
public Boolean getDisableWebPagePreview() {
return disableWebPagePreview;
}
public Boolean getDisableNotification() {
return disableNotification;
}
public SendMessage disableWebPagePreview() {
public void disableWebPagePreview() {
disableWebPagePreview = true;
return this;
}
public SendMessage enableWebPagePreview() {
public void enableWebPagePreview() {
disableWebPagePreview = null;
return this;
}
public SendMessage enableNotification() {
public void enableNotification() {
this.disableNotification = null;
return this;
}
public SendMessage disableNotification() {
public void disableNotification() {
this.disableNotification = true;
return this;
}
public SendMessage setParseMode(String parseMode) {
this.parseMode = parseMode;
return this;
}
public SendMessage enableMarkdown(boolean enable) {
public void enableMarkdown(boolean enable) {
if (enable) {
this.parseMode = ParseMode.MARKDOWN;
} else {
this.parseMode = null;
}
return this;
}
public SendMessage enableHtml(boolean enable) {
public void enableHtml(boolean enable) {
if (enable) {
this.parseMode = ParseMode.HTML;
} else {
this.parseMode = null;
}
return this;
}
public SendMessage enableMarkdownV2(boolean enable) {
public void enableMarkdownV2(boolean enable) {
if (enable) {
this.parseMode = ParseMode.MARKDOWNV2;
} else {
this.parseMode = null;
}
return this;
}
@Override
@ -192,50 +141,11 @@ public class SendMessage extends BotApiMethod<Message> {
if (text == null || text.isEmpty()) {
throw new TelegramApiValidationException("Text parameter can't be empty", this);
}
if (parseMode != null && (entities != null && !entities.isEmpty()) ) {
throw new TelegramApiValidationException("Parse mode can't be enabled if Entities are provided", this);
}
if (replyMarkup != null) {
replyMarkup.validate();
}
}
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof SendMessage)) {
return false;
}
SendMessage sendMessage = (SendMessage) o;
return Objects.equals(chatId, sendMessage.chatId)
&& Objects.equals(disableNotification, sendMessage.disableNotification)
&& Objects.equals(disableWebPagePreview, sendMessage.disableWebPagePreview)
&& Objects.equals(parseMode, sendMessage.parseMode)
&& Objects.equals(replyMarkup, sendMessage.replyMarkup)
&& Objects.equals(replyToMessageId, sendMessage.replyToMessageId)
&& Objects.equals(text, sendMessage.text)
;
}
@Override
public int hashCode() {
return Objects.hash(
chatId,
disableNotification,
disableWebPagePreview,
parseMode,
replyMarkup,
replyToMessageId,
text);
}
@Override
public String toString() {
return "SendMessage{" +
"chatId='" + chatId + '\'' +
", text='" + text + '\'' +
", parseMode='" + parseMode + '\'' +
", disableNotification='" + disableNotification + '\'' +
", disableWebPagePreview=" + disableWebPagePreview +
", replyToMessageId=" + replyToMessageId +
", replyMarkup=" + replyMarkup +
'}';
}
}

View File

@ -1,17 +1,27 @@
package org.telegram.telegrambots.meta.api.methods.send;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.Singular;
import lombok.ToString;
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.ApiResponse;
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.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Objects;
/**
@ -19,6 +29,14 @@ import java.util.Objects;
* @version 1.0
* Use this method to send photos. On success, the sent Message is returned.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SendPhoto extends PartialBotApiMethod<Message> {
public static final String PATH = "sendphoto";
@ -29,110 +47,33 @@ public class SendPhoto extends PartialBotApiMethod<Message> {
public static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
public static final String REPLYMARKUP_FIELD = "reply_markup";
public static final String PARSEMODE_FIELD = "parse_mode";
public static final String CAPTION_ENTITIES_FIELD = "caption_entities";
public static final String ALLOWSENDINGWITHOUTREPLY_FIELD = "allow_sending_without_reply";
@NonNull
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
@NonNull
private InputFile photo; ///< Photo to send. file_id as String to resend a photo that is already on the Telegram servers or URL to upload it
private String caption; ///< Optional Photo caption (may also be used when resending photos by file_id).
private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message
private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
private String parseMode; ///< Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
@Singular
private List<MessageEntity> captionEntities; ///< Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode
private Boolean allowSendingWithoutReply; ///< Optional Pass True, if the message should be sent even if the specified replied-to message is not found
public SendPhoto() {
super();
}
public String getChatId() {
return chatId;
}
public SendPhoto setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public SendPhoto setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
public InputFile getPhoto() {
return photo;
}
public SendPhoto setPhoto(String photo) {
this.photo = new InputFile(photo);
return this;
}
public String getCaption() {
return caption;
}
public SendPhoto setCaption(String caption) {
this.caption = caption;
return this;
}
public Integer getReplyToMessageId() {
return replyToMessageId;
}
public SendPhoto setReplyToMessageId(Integer replyToMessageId) {
this.replyToMessageId = replyToMessageId;
return this;
}
public ReplyKeyboard getReplyMarkup() {
return replyMarkup;
}
public SendPhoto setReplyMarkup(ReplyKeyboard replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
public Boolean getDisableNotification() {
return disableNotification;
}
public SendPhoto enableNotification() {
public void enableNotification() {
this.disableNotification = false;
return this;
}
public SendPhoto disableNotification() {
public void disableNotification() {
this.disableNotification = true;
return this;
}
public SendPhoto setPhoto(File file) {
Objects.requireNonNull(file, "file cannot be null!");
this.photo = new InputFile(file, file.getName());
return this;
}
public SendPhoto setPhoto(InputFile photo) {
public void setPhoto(InputFile photo) {
Objects.requireNonNull(photo, "photo cannot be null!");
this.photo = photo;
return this;
}
public SendPhoto setPhoto(String photoName, InputStream inputStream) {
Objects.requireNonNull(photoName, "photoName cannot be null!");
Objects.requireNonNull(inputStream, "inputStream cannot be null!");
this.photo = new InputFile(inputStream, photoName);
return this;
}
public String getParseMode() {
return parseMode;
}
public SendPhoto setParseMode(String parseMode) {
this.parseMode = parseMode;
return this;
}
@Override
@ -160,23 +101,13 @@ public class SendPhoto extends PartialBotApiMethod<Message> {
throw new TelegramApiValidationException("Photo 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);
}
photo.validate();
if (replyMarkup != null) {
replyMarkup.validate();
}
}
@Override
public String toString() {
return "SendPhoto{" +
"chatId='" + chatId + '\'' +
", photo=" + photo +
", caption='" + caption + '\'' +
", disableNotification=" + disableNotification +
", replyToMessageId=" + replyToMessageId +
", replyMarkup=" + replyMarkup +
", parseMode='" + parseMode + '\'' +
'}';
}
}

View File

@ -1,24 +1,38 @@
package org.telegram.telegrambots.meta.api.methods.send;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.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.ApiResponse;
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.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;
/**
* @author Ruben Bermudez
* @version 1.0
* Use this method to send .webp stickers. On success, the sent Message is returned.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SendSticker extends PartialBotApiMethod<Message> {
public static final String PATH = "sendsticker";
@ -27,89 +41,27 @@ public class SendSticker extends PartialBotApiMethod<Message> {
public static final String DISABLENOTIFICATION_FIELD = "disable_notification";
public static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
public static final String REPLYMARKUP_FIELD = "reply_markup";
public static final String ALLOWSENDINGWITHOUTREPLY_FIELD = "allow_sending_without_reply";
@NonNull
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
@NonNull
private InputFile sticker; ///< Sticker file to send. file_id as String to resend a sticker that is already on the Telegram servers or URL to upload it
private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message
private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
public SendSticker() {
super();
}
public String getChatId() {
return chatId;
}
public SendSticker setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public SendSticker setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
public InputFile getSticker() {
return sticker;
}
public SendSticker setSticker(String sticker) {
this.sticker = new InputFile(sticker);
return this;
}
public Integer getReplyToMessageId() {
return replyToMessageId;
}
public SendSticker setReplyToMessageId(Integer replyToMessageId) {
this.replyToMessageId = replyToMessageId;
return this;
}
public ReplyKeyboard getReplyMarkup() {
return replyMarkup;
}
public SendSticker setReplyMarkup(ReplyKeyboard replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
public SendSticker setSticker(InputFile sticker) {
Objects.requireNonNull(sticker, "sticker cannot be null!");
this.sticker = sticker;
return this;
}
public SendSticker setSticker(File file) {
Objects.requireNonNull(file, "file cannot be null!");
this.sticker = new InputFile(file, file.getName());
return this;
}
public SendSticker setSticker(String stickerName, InputStream inputStream) {
Objects.requireNonNull(stickerName, "stickerName cannot be null!");
Objects.requireNonNull(inputStream, "inputStream cannot be null!");
this.sticker = new InputFile(inputStream, stickerName);
return this;
}
private Boolean allowSendingWithoutReply; ///< Optional Pass True, if the message should be sent even if the specified replied-to message is not found
public Boolean getDisableNotification() {
return disableNotification;
}
public SendSticker enableNotification() {
public void enableNotification() {
this.disableNotification = false;
return this;
}
public SendSticker disableNotification() {
public void disableNotification() {
this.disableNotification = true;
return this;
}
@Override
@ -143,15 +95,4 @@ public class SendSticker extends PartialBotApiMethod<Message> {
replyMarkup.validate();
}
}
@Override
public String toString() {
return "SendSticker{" +
"chatId='" + chatId + '\'' +
", sticker=" + sticker +
", disableNotification=" + disableNotification +
", replyToMessageId=" + replyToMessageId +
", replyMarkup=" + replyMarkup +
'}';
}
}

View File

@ -2,16 +2,23 @@ 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;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.Message;
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.Objects;
/**
* @author Ruben Bermudez
@ -19,6 +26,14 @@ import java.util.Objects;
* Use this method to send information about a venue. On success, the sent Message is
* returned.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SendVenue extends BotApiMethod<Message> {
public static final String PATH = "sendVenue";
@ -32,19 +47,27 @@ public class SendVenue extends BotApiMethod<Message> {
private static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
private static final String REPLYMARKUP_FIELD = "reply_markup";
private static final String FOURSQUARETYPE_FIELD = "foursquare_type";
private static final String ALLOWSENDINGWITHOUTREPLY_FIELD = "allow_sending_without_reply";
private static final String GOOGLEPLACEID_FIELD = "google_place_id";
private static final String GOOGLEPLACETYPE_FIELD = "google_place_type";
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
@JsonProperty(LATITUDE_FIELD)
private Float latitude; ///< Latitude of venue location
@NonNull
private Double latitude; ///< Latitude of venue location
@JsonProperty(LONGITUDE_FIELD)
private Float longitude; ///< Longitude of venue location
@NonNull
private Double longitude; ///< Longitude of venue location
@JsonProperty(TITLE_FIELD)
@NonNull
private String title; ///< Title of the venue
@JsonProperty(ADDRESS_FIELD)
@NonNull
private String address; ///< Address of the venue
@JsonProperty(DISABLENOTIFICATION_FIELD)
private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
@JsonProperty(ADDRESS_FIELD)
private String address; ///< Address of the venue
@JsonProperty(FOURSQUAREID_FIELD)
private String foursquareId; ///< Optional. Foursquare identifier of the venue
@JsonProperty(REPLYTOMESSAGEID_FIELD)
@ -53,110 +76,19 @@ public class SendVenue extends BotApiMethod<Message> {
private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
@JsonProperty(FOURSQUARETYPE_FIELD)
private String foursquareType; ///< Optional. Foursquare type of the venue, if known.
@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
@JsonProperty(GOOGLEPLACEID_FIELD)
private String googlePlaceId; ///< Optional. Google Places identifier of the venue
@JsonProperty(GOOGLEPLACETYPE_FIELD)
private String googlePlaceType; ///< Optional. Google Places type of the venue. (See supported types.)
public SendVenue() {
super();
}
public String getChatId() {
return chatId;
}
public SendVenue setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public SendVenue setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
public Float getLatitude() {
return latitude;
}
public SendVenue setLatitude(Float latitude) {
this.latitude = latitude;
return this;
}
public Float getLongitude() {
return longitude;
}
public SendVenue setLongitude(Float longitude) {
this.longitude = longitude;
return this;
}
public Integer getReplyToMessageId() {
return replyToMessageId;
}
public SendVenue setReplyToMessageId(Integer replyToMessageId) {
this.replyToMessageId = replyToMessageId;
return this;
}
public ReplyKeyboard getReplyMarkup() {
return replyMarkup;
}
public SendVenue setReplyMarkup(ReplyKeyboard replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
public Boolean getDisableNotification() {
return disableNotification;
}
public SendVenue enableNotification() {
public void enableNotification() {
this.disableNotification = false;
return this;
}
public SendVenue disableNotification() {
public void disableNotification() {
this.disableNotification = true;
return this;
}
public String getTitle() {
return title;
}
public SendVenue setTitle(String title) {
this.title = title;
return this;
}
public String getAddress() {
return address;
}
public SendVenue setAddress(String address) {
this.address = address;
return this;
}
public String getFoursquareId() {
return foursquareId;
}
public SendVenue setFoursquareId(String foursquareId) {
this.foursquareId = foursquareId;
return this;
}
public String getFoursquareType() {
return foursquareType;
}
public SendVenue setFoursquareType(String foursquareType) {
this.foursquareType = foursquareType;
return this;
}
@Override
@ -200,20 +132,4 @@ public class SendVenue extends BotApiMethod<Message> {
replyMarkup.validate();
}
}
@Override
public String toString() {
return "SendVenue{" +
"chatId='" + chatId + '\'' +
", latitude=" + latitude +
", longitude=" + longitude +
", title='" + title + '\'' +
", disableNotification=" + disableNotification +
", address='" + address + '\'' +
", foursquareId='" + foursquareId + '\'' +
", replyToMessageId=" + replyToMessageId +
", replyMarkup=" + replyMarkup +
", foursquareType='" + foursquareType + '\'' +
'}';
}
}

View File

@ -1,18 +1,27 @@
package org.telegram.telegrambots.meta.api.methods.send;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.Singular;
import lombok.ToString;
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.ApiResponse;
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.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;
import java.util.List;
/**
* @author Ruben Bermudez
@ -20,6 +29,14 @@ import java.util.Objects;
* Use this method to send video files, Telegram clients support mp4 videos (other formats
* may be sent as Document). On success, the sent Message is returned.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SendVideo extends PartialBotApiMethod<Message> {
public static final String PATH = "sendvideo";
@ -35,8 +52,12 @@ public class SendVideo extends PartialBotApiMethod<Message> {
public static final String REPLYMARKUP_FIELD = "reply_markup";
public static final String PARSEMODE_FIELD = "parse_mode";
public static final String THUMB_FIELD = "thumb";
public static final String CAPTION_ENTITIES_FIELD = "caption_entities";
public static final String ALLOWSENDINGWITHOUTREPLY_FIELD = "allow_sending_without_reply";
@NonNull
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
@NonNull
private InputFile video; ///< Video to send. file_id as String to resend a video that is already on the Telegram servers or URL to upload it
private Integer duration; ///< Optional. Duration of sent video in seconds
private String caption; ///< Optional. Video caption (may also be used when resending videos by file_id).
@ -46,8 +67,9 @@ public class SendVideo extends PartialBotApiMethod<Message> {
private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message
private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
private String parseMode; ///< Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
/**
* Optional.
* Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size.
* A thumbnails width and height should not exceed 320.
* Ignored if the file is not uploaded using multipart/form-data.
@ -55,147 +77,16 @@ public class SendVideo extends PartialBotApiMethod<Message> {
* if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
*/
private InputFile thumb;
@Singular
private List<MessageEntity> captionEntities; ///< Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode
private Boolean allowSendingWithoutReply; ///< Optional Pass True, if the message should be sent even if the specified replied-to message is not found
public SendVideo() {
super();
}
public String getChatId() {
return chatId;
}
public SendVideo setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public InputFile getVideo() {
return video;
}
public SendVideo setVideo(String video) {
this.video = new InputFile(video);
return this;
}
public SendVideo setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
public Integer getDuration() {
return duration;
}
public SendVideo setDuration(Integer duration) {
this.duration = duration;
return this;
}
public String getCaption() {
return caption;
}
public SendVideo setCaption(String caption) {
this.caption = caption;
return this;
}
public Integer getReplyToMessageId() {
return replyToMessageId;
}
public SendVideo setReplyToMessageId(Integer replyToMessageId) {
this.replyToMessageId = replyToMessageId;
return this;
}
public ReplyKeyboard getReplyMarkup() {
return replyMarkup;
}
public SendVideo setReplyMarkup(ReplyKeyboard replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
public Boolean getDisableNotification() {
return disableNotification;
}
public SendVideo enableNotification() {
public void enableNotification() {
this.disableNotification = false;
return this;
}
public SendVideo disableNotification() {
public void disableNotification() {
this.disableNotification = true;
return this;
}
public Integer getWidth() {
return width;
}
public SendVideo setWidth(Integer width) {
this.width = width;
return this;
}
public Integer getHeight() {
return height;
}
public SendVideo setHeight(Integer height) {
this.height = height;
return this;
}
public SendVideo setVideo(InputFile video) {
Objects.requireNonNull(video, "video cannot be null!");
this.video = video;
return this;
}
public SendVideo setVideo(File file) {
Objects.requireNonNull(file, "file cannot be null!");
this.video = new InputFile(file, file.getName());
return this;
}
public SendVideo setVideo(String videoName, InputStream inputStream) {
Objects.requireNonNull(videoName, "videoName cannot be null!");
Objects.requireNonNull(inputStream, "inputStream cannot be null!");
this.video = new InputFile(inputStream, videoName);
return this;
}
public Boolean getSupportsStreaming() {
return supportsStreaming;
}
public SendVideo setSupportsStreaming(Boolean supportsStreaming) {
this.supportsStreaming = supportsStreaming;
return this;
}
public String getParseMode() {
return parseMode;
}
public SendVideo setParseMode(String parseMode) {
this.parseMode = parseMode;
return this;
}
public InputFile getThumb() {
return thumb;
}
public SendVideo setThumb(InputFile thumb) {
this.thumb = thumb;
return this;
}
@Override
@ -223,6 +114,10 @@ public class SendVideo extends PartialBotApiMethod<Message> {
throw new TelegramApiValidationException("Video 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);
}
video.validate();
if (thumb != null) {
@ -232,22 +127,4 @@ public class SendVideo extends PartialBotApiMethod<Message> {
replyMarkup.validate();
}
}
@Override
public String toString() {
return "SendVideo{" +
"chatId='" + chatId + '\'' +
", video=" + video +
", duration=" + duration +
", caption='" + caption + '\'' +
", width=" + width +
", height=" + height +
", supportsStreaming=" + supportsStreaming +
", disableNotification=" + disableNotification +
", replyToMessageId=" + replyToMessageId +
", replyMarkup=" + replyMarkup +
", parseMode='" + parseMode + '\'' +
", thumb=" + thumb +
'}';
}
}

View File

@ -1,20 +1,24 @@
package org.telegram.telegrambots.meta.api.methods.send;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.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.ApiResponse;
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.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
@ -23,6 +27,14 @@ import static com.google.common.base.Preconditions.checkNotNull;
* Use this method to send video messages. On success, the sent Message is returned.
*/
@SuppressWarnings({"UnusedReturnValue", "WeakerAccess"})
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SendVideoNote extends PartialBotApiMethod<Message> {
public static final String PATH = "sendvideonote";
@ -34,8 +46,11 @@ public class SendVideoNote extends PartialBotApiMethod<Message> {
public static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
public static final String REPLYMARKUP_FIELD = "reply_markup";
public static final String THUMB_FIELD = "thumb";
public static final String ALLOWSENDINGWITHOUTREPLY_FIELD = "allow_sending_without_reply";
@NonNull
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
@NonNull
private InputFile videoNote; ///< Videonote to send. file_id as String to resend a video that is already on the Telegram servers.
private Integer duration; ///< Optional. Duration of sent video in seconds
private Integer length; ///< Optional. Video width and height
@ -50,174 +65,14 @@ public class SendVideoNote extends PartialBotApiMethod<Message> {
* if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
*/
private InputFile thumb;
private Boolean allowSendingWithoutReply; ///< Optional Pass True, if the message should be sent even if the specified replied-to message is not found
public SendVideoNote() {
super();
}
/**
* Creates a new video note with a video already present in telegram servers
* @param chatId Chat Id to send the video note
* @param videoNote Video note file_id to send
*/
public SendVideoNote(String chatId, String videoNote) {
this.chatId = checkNotNull(chatId);
this.setVideoNote(checkNotNull(videoNote));
}
/**
* Creates a new video note with a video already present in telegram servers
* @param chatId Chat Id to send the video note
* @param videoNote Video note file_id to send
*/
public SendVideoNote(Long chatId, String videoNote) {
this.chatId = checkNotNull(chatId).toString();
this.setVideoNote(checkNotNull(videoNote));
}
/**
* Creates a new video note with a new video note
* @param chatId Chat Id to send the video note
* @param videoNote Video note file to upload
*/
public SendVideoNote(String chatId, File videoNote) {
this.chatId = checkNotNull(chatId);
this.setVideoNote(videoNote);
}
/**
* Creates a new video note with a video already present in telegram servers
* @param chatId Chat Id to send the video note
* @param videoNote Video note file to upload
*/
public SendVideoNote(Integer chatId, File videoNote) {
this.chatId = checkNotNull(chatId).toString();
this.setVideoNote(videoNote);
}
/**
* Creates a new video note with a new video note
* @param chatId Chat Id to send the video note
* @param videoNoteName Name of the video note file
* @param videoNote Video note file to upload
*/
public SendVideoNote(String chatId, String videoNoteName, InputStream videoNote) {
this.chatId = checkNotNull(chatId);
this.setVideoNote(videoNoteName, videoNote);
}
/**
* Creates a new video note with a video already present in telegram servers
* @param chatId Chat Id to send the video note
* @param videoNoteName Name of the video note file
* @param videoNote Video note file to upload
*/
public SendVideoNote(Integer chatId, String videoNoteName, InputStream videoNote) {
this.chatId = checkNotNull(chatId).toString();
this.setVideoNote(videoNoteName, videoNote);
}
public String getChatId() {
return chatId;
}
public SendVideoNote setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public InputFile getVideoNote() {
return videoNote;
}
public SendVideoNote setVideoNote(String videoNote) {
this.videoNote = new InputFile(videoNote);
return this;
}
public Integer getLength() {
return length;
}
public SendVideoNote setLength(Integer length) {
this.length = length;
return this;
}
public SendVideoNote setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
public Integer getDuration() {
return duration;
}
public SendVideoNote setDuration(Integer duration) {
this.duration = duration;
return this;
}
public Integer getReplyToMessageId() {
return replyToMessageId;
}
public SendVideoNote setReplyToMessageId(Integer replyToMessageId) {
this.replyToMessageId = replyToMessageId;
return this;
}
public ReplyKeyboard getReplyMarkup() {
return replyMarkup;
}
public SendVideoNote setReplyMarkup(ReplyKeyboard replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
public Boolean getDisableNotification() {
return disableNotification;
}
public SendVideoNote enableNotification() {
public void enableNotification() {
this.disableNotification = false;
return this;
}
public SendVideoNote disableNotification() {
public void disableNotification() {
this.disableNotification = true;
return this;
}
public SendVideoNote setVideoNote(InputFile videoNote) {
Objects.requireNonNull(videoNote, "videoNote cannot be null!");
this.videoNote = videoNote;
return this;
}
public SendVideoNote setVideoNote(File file) {
Objects.requireNonNull(file, "file cannot be null!");
this.videoNote = new InputFile(file, file.getName());
return this;
}
public SendVideoNote setVideoNote(String videoName, InputStream inputStream) {
Objects.requireNonNull(videoName, "videoName cannot be null!");
Objects.requireNonNull(inputStream, "inputStream cannot be null!");
this.videoNote = new InputFile(inputStream, videoName);
return this;
}
public InputFile getThumb() {
return thumb;
}
public SendVideoNote setThumb(InputFile thumb) {
this.thumb = thumb;
return this;
}
@Override
@ -254,18 +109,4 @@ public class SendVideoNote extends PartialBotApiMethod<Message> {
replyMarkup.validate();
}
}
@Override
public String toString() {
return "SendVideoNote{" +
"chatId='" + chatId + '\'' +
", videoNote=" + videoNote +
", duration=" + duration +
", length=" + length +
", disableNotification=" + disableNotification +
", replyToMessageId=" + replyToMessageId +
", replyMarkup=" + replyMarkup +
", thumb=" + thumb +
'}';
}
}

View File

@ -1,18 +1,27 @@
package org.telegram.telegrambots.meta.api.methods.send;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.Singular;
import lombok.ToString;
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.ApiResponse;
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.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;
import java.util.List;
/**
* @author Ruben Bermudez
@ -21,6 +30,14 @@ import java.util.Objects;
* playable voice message. For this to work, your audio must be in an .ogg file encoded with OPUS
* (other formats may be sent as Audio or Document).
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SendVoice extends PartialBotApiMethod<Message> {
public static final String PATH = "sendvoice";
@ -32,121 +49,29 @@ public class SendVoice extends PartialBotApiMethod<Message> {
public static final String DURATION_FIELD = "duration";
public static final String CAPTION_FIELD = "caption";
public static final String PARSEMODE_FIELD = "parse_mode";
public static final String CAPTION_ENTITIES_FIELD = "caption_entities";
public static final String ALLOWSENDINGWITHOUTREPLY_FIELD = "allow_sending_without_reply";
@NonNull
private String chatId; ///< Unique identifier for the chat sent message to (Or username for channels)
@NonNull
private InputFile voice; ///< Audio file to send. You can either pass a file_id as String to resend an audio that is already on the Telegram servers, or upload a new audio file using multipart/form-data.
private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message
private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
private Integer duration; ///< Optional. Duration of sent audio in seconds
private String caption; ///< Optional. Voice caption (may also be used when resending videos by file_id).
private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
private String parseMode; ///< Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
@Singular
private List<MessageEntity> captionEntities; ///< Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode
private Boolean allowSendingWithoutReply; ///< Optional Pass True, if the message should be sent even if the specified replied-to message is not found
public SendVoice() {
super();
}
public Boolean getDisableNotification() {
return disableNotification;
}
public SendVoice enableNotification() {
public void enableNotification() {
this.disableNotification = false;
return this;
}
public SendVoice disableNotification() {
public void disableNotification() {
this.disableNotification = true;
return this;
}
public String getChatId() {
return chatId;
}
public SendVoice setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public SendVoice setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
public InputFile getVoice() {
return voice;
}
public SendVoice setVoice(String voice) {
Objects.requireNonNull(voice, "voice cannot be null!");
this.voice = new InputFile(voice);
return this;
}
public SendVoice setVoice(File voice) {
Objects.requireNonNull(voice, "voice cannot be null!");
this.voice = new InputFile(voice, voice.getName());
return this;
}
public SendVoice setVoice(InputFile voice) {
Objects.requireNonNull(voice, "voice cannot be null!");
this.voice = voice;
return this;
}
public SendVoice setVoice(String voiceName, InputStream inputStream) {
Objects.requireNonNull(voiceName, "voiceName cannot be null!");
Objects.requireNonNull(inputStream, "inputStream cannot be null!");
this.voice = new InputFile(inputStream, voiceName);
return this;
}
public Integer getReplyToMessageId() {
return replyToMessageId;
}
public SendVoice setReplyToMessageId(Integer replyToMessageId) {
this.replyToMessageId = replyToMessageId;
return this;
}
public ReplyKeyboard getReplyMarkup() {
return replyMarkup;
}
public SendVoice setReplyMarkup(ReplyKeyboard replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
public Integer getDuration() {
return duration;
}
public SendVoice setDuration(Integer duration) {
this.duration = duration;
return this;
}
public String getCaption() {
return caption;
}
public SendVoice setCaption(String caption) {
this.caption = caption;
return this;
}
public String getParseMode() {
return parseMode;
}
public SendVoice setParseMode(String parseMode) {
this.parseMode = parseMode;
return this;
}
@Override
@ -173,25 +98,13 @@ public class SendVoice extends PartialBotApiMethod<Message> {
if (voice == null) {
throw new TelegramApiValidationException("Voice 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);
}
voice.validate();
if (replyMarkup != null) {
replyMarkup.validate();
}
}
@Override
public String toString() {
return "SendVoice{" +
"chatId='" + chatId + '\'' +
", voice=" + voice +
", disableNotification=" + disableNotification +
", replyToMessageId=" + replyToMessageId +
", replyMarkup=" + replyMarkup +
", duration=" + duration +
", caption='" + caption + '\'' +
", parseMode='" + parseMode + '\'' +
'}';
}
}

View File

@ -1,6 +1,15 @@
package org.telegram.telegrambots.meta.api.methods.stickers;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.InputFile;
@ -8,12 +17,7 @@ import org.telegram.telegrambots.meta.api.objects.stickers.MaskPosition;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
@ -25,6 +29,14 @@ import static com.google.common.base.Preconditions.checkNotNull;
* Static sticker sets can have up to 120 stickers.
* Returns True on success.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class AddStickerToSet extends PartialBotApiMethod<Boolean> {
public static final String PATH = "addStickerToSet";
@ -35,11 +47,15 @@ public class AddStickerToSet extends PartialBotApiMethod<Boolean> {
public static final String EMOJIS_FIELD = "emojis";
public static final String MASKPOSITION_FIELD = "mask_position";
@NonNull
private Integer userId; ///< User identifier of sticker set owner
@NonNull
private String name; ///< Sticker set name
@NonNull
private String emojis; ///< One or more emoji corresponding to the sticker
private MaskPosition maskPosition; ///< Position where the mask should be placed on faces
private MaskPosition maskPosition; ///< Optional. Position where the mask should be placed on faces
/**
* Optional.
* Png image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px,
* and either width or height must be exactly 512px. Pass a file_id as a String to send a file
* that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram
@ -47,93 +63,12 @@ public class AddStickerToSet extends PartialBotApiMethod<Boolean> {
*/
private InputFile pngSticker;
/**
* Optional.
* TGS animation with the sticker, uploaded using multipart/form-data.
* See https://core.telegram.org/animated_stickers#technical-requirements for technical requirements
*/
private InputFile tgsSticker;
public AddStickerToSet() {
super();
}
public AddStickerToSet(Integer userId, String name, String emojis) {
this.userId = checkNotNull(userId);
this.name = checkNotNull(name);
this.emojis = checkNotNull(emojis);
}
public Integer getUserId() {
return userId;
}
public AddStickerToSet setUserId(Integer userId) {
this.userId = userId;
return this;
}
public InputFile getPngSticker() {
return pngSticker;
}
public AddStickerToSet setPngSticker(String pngSticker) {
this.pngSticker = new InputFile(pngSticker);
return this;
}
public AddStickerToSet setPngSticker(File pngSticker) {
Objects.requireNonNull(pngSticker, "pngSticker cannot be null!");
this.pngSticker = new InputFile(pngSticker, pngSticker.getName());
return this;
}
public AddStickerToSet setPngSticker(String pngStickerName, InputStream pngSticker) {
Objects.requireNonNull(pngStickerName, "pngStickerName cannot be null!");
Objects.requireNonNull(pngSticker, "pngSticker cannot be null!");
this.pngSticker = new InputFile(pngSticker, pngStickerName);
return this;
}
public AddStickerToSet setTgsSticker(File tgsSticker) {
this.tgsSticker = new InputFile(checkNotNull(tgsSticker), tgsSticker.getName());
return this;
}
public AddStickerToSet setTgsSticker(String tgsStickerName, InputStream tgsSticker) {
this.tgsSticker = new InputFile(checkNotNull(tgsSticker), checkNotNull(tgsStickerName));
return this;
}
public InputFile getTgsSticker() {
return tgsSticker;
}
public String getName() {
return name;
}
public AddStickerToSet setName(String name) {
this.name = name;
return this;
}
public String getEmojis() {
return emojis;
}
public AddStickerToSet setEmojis(String emojis) {
this.emojis = emojis;
return this;
}
public MaskPosition getMaskPosition() {
return maskPosition;
}
public AddStickerToSet setMaskPosition(MaskPosition maskPosition) {
this.maskPosition = maskPosition;
return this;
}
@Override
public Boolean deserializeResponse(String answer) throws TelegramApiRequestException {
try {
@ -180,16 +115,4 @@ public class AddStickerToSet extends PartialBotApiMethod<Boolean> {
maskPosition.validate();
}
}
@Override
public String toString() {
return "AddStickerToSet{" +
"userId=" + userId +
", name='" + name + '\'' +
", emojis='" + emojis + '\'' +
", maskPosition=" + maskPosition +
", pngSticker=" + pngSticker +
", tgsSticker=" + tgsSticker +
'}';
}
}

View File

@ -1,6 +1,15 @@
package org.telegram.telegrambots.meta.api.methods.stickers;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.InputFile;
@ -8,12 +17,7 @@ import org.telegram.telegrambots.meta.api.objects.stickers.MaskPosition;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
@ -22,6 +26,14 @@ import static com.google.common.base.Preconditions.checkNotNull;
* You must use exactly one of the fields png_sticker or tgs_sticker.
* Returns True on success.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class CreateNewStickerSet extends PartialBotApiMethod<Boolean> {
public static final String PATH = "createNewStickerSet";
@ -34,6 +46,7 @@ public class CreateNewStickerSet extends PartialBotApiMethod<Boolean> {
public static final String CONTAINSMASKS_FIELD = "contains_masks";
public static final String MASKPOSITION_FIELD = "mask_position";
@NonNull
private Integer userId; ///< User identifier of created sticker set owner
/**
* Name of sticker set, to be used in t.me/addstickers/<name> URLs.
@ -41,12 +54,16 @@ public class CreateNewStickerSet extends PartialBotApiMethod<Boolean> {
* Must begin with a letter, can't contain consecutive underscores and must end in _by_<bot username>.
* <bot_username> is case insensitive. 7-64 characters.
*/
@NonNull
private String name; ///< Sticker set title, 1-64 characters
@NonNull
private String title; ///< User identifier of created sticker set owner
@NonNull
private String emojis; ///< One or more emoji corresponding to the sticker
private Boolean containsMasks; ///< Pass True, if a set of mask stickers should be created
private MaskPosition maskPosition; ///< Position where the mask should be placed on faces
private Boolean containsMasks; ///< Optional. Pass True, if a set of mask stickers should be created
private MaskPosition maskPosition; ///< Optional. Position where the mask should be placed on faces
/**
* Optional.
* Png image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px,
* and either width or height must be exactly 512px.
* Pass a file_id as a String to send a file that already exists on the Telegram servers,
@ -56,117 +73,12 @@ public class CreateNewStickerSet extends PartialBotApiMethod<Boolean> {
private InputFile pngSticker;
/**
* @Optional
* TGS animation with the sticker, uploaded using multipart/form-data.
* See https://core.telegram.org/animated_stickers#technical-requirements for technical requirements
*/
private InputFile tgsSticker;
public CreateNewStickerSet() {
super();
}
public CreateNewStickerSet(Integer userId, String name, String title, String emojis) {
this.userId = checkNotNull(userId);
this.name = checkNotNull(name);
this.title = checkNotNull(title);
this.emojis = checkNotNull(emojis);
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public InputFile getPngSticker() {
return pngSticker;
}
public CreateNewStickerSet setPngSticker(String pngSticker) {
this.pngSticker = new InputFile(pngSticker);
return this;
}
public CreateNewStickerSet setPngStickerFile(InputFile pngStickerFile) {
Objects.requireNonNull(pngStickerFile, "pngStickerFile cannot be null!");
this.pngSticker = pngStickerFile;
return this;
}
public CreateNewStickerSet setPngStickerFile(File pngStickerFile) {
Objects.requireNonNull(pngStickerFile, "pngStickerFile cannot be null!");
this.pngSticker = new InputFile(pngStickerFile, pngStickerFile.getName());
return this;
}
public CreateNewStickerSet setPngStickerStream(String pngStickerName, InputStream pngStickerStream) {
Objects.requireNonNull(pngStickerName, "pngStickerName cannot be null!");
Objects.requireNonNull(pngStickerStream, "pngStickerStream cannot be null!");
this.pngSticker = new InputFile(pngStickerStream, pngStickerName);
return this;
}
public CreateNewStickerSet setTgsSticker(InputFile tgsSticker) {
this.tgsSticker = checkNotNull(tgsSticker);
return this;
}
public CreateNewStickerSet setTgsSticker(File tgsStickerFile) {
this.tgsSticker = new InputFile(checkNotNull(tgsStickerFile), tgsStickerFile.getName());;
return this;
}
public CreateNewStickerSet setTgsSticker(String tgsStickerName, InputStream tgsStickerStream) {
this.pngSticker = new InputFile(checkNotNull(tgsStickerStream), checkNotNull(tgsStickerName));
return this;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getEmojis() {
return emojis;
}
public void setEmojis(String emojis) {
this.emojis = emojis;
}
public Boolean getContainsMasks() {
return containsMasks;
}
public void setContainsMasks(Boolean containsMasks) {
this.containsMasks = containsMasks;
}
public MaskPosition getMaskPosition() {
return maskPosition;
}
public void setMaskPosition(MaskPosition maskPosition) {
this.maskPosition = maskPosition;
}
public InputFile getTgsSticker() {
return tgsSticker;
}
@Override
public Boolean deserializeResponse(String answer) throws TelegramApiRequestException {
try {
@ -216,18 +128,4 @@ public class CreateNewStickerSet extends PartialBotApiMethod<Boolean> {
maskPosition.validate();
}
}
@Override
public String toString() {
return "CreateNewStickerSet{" +
"userId=" + userId +
", name='" + name + '\'' +
", title='" + title + '\'' +
", emojis='" + emojis + '\'' +
", containsMasks=" + containsMasks +
", maskPosition=" + maskPosition +
", pngSticker=" + pngSticker +
", tgsSticker=" + tgsSticker +
'}';
}
}

View File

@ -2,6 +2,14 @@ package org.telegram.telegrambots.meta.api.methods.stickers;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.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;
@ -9,30 +17,27 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.IOException;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 1.0
* Use this method to delete a sticker from a set created by the bot. Returns True on success.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class DeleteStickerFromSet extends BotApiMethod<Boolean> {
private static final String PATH = "deleteStickerFromSet";
private static final String STICKER_FIELD = "sticker";
@JsonProperty(STICKER_FIELD)
@NonNull
private String sticker; ///< File identifier of the sticker
public DeleteStickerFromSet() {
super();
}
public DeleteStickerFromSet(String sticker) {
super();
this.sticker = checkNotNull(sticker);
}
@Override
public String getMethod() {
return PATH;
@ -59,20 +64,4 @@ public class DeleteStickerFromSet extends BotApiMethod<Boolean> {
throw new TelegramApiValidationException("sticker can't be null", this);
}
}
public String getSticker() {
return sticker;
}
public DeleteStickerFromSet setSticker(String sticker) {
this.sticker = sticker;
return this;
}
@Override
public String toString() {
return "DeleteStickerFromSet{" +
"sticker='" + sticker + '\'' +
'}';
}
}

View File

@ -2,6 +2,14 @@ package org.telegram.telegrambots.meta.api.methods.stickers;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.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.stickers.StickerSet;
@ -10,30 +18,27 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.IOException;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 1.0
* Use this method to get a sticker set. On success, a StickerSet object is returned.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class GetStickerSet extends BotApiMethod<StickerSet> {
private static final String PATH = "getStickerSet";
private static final String NAME_FIELD = "name";
@JsonProperty(NAME_FIELD)
@NonNull
private String name; ///< Name of the sticker set
public GetStickerSet(String name) {
super();
this.name = checkNotNull(name);
}
public GetStickerSet() {
super();
}
@Override
public String getMethod() {
return PATH;
@ -60,20 +65,4 @@ public class GetStickerSet extends BotApiMethod<StickerSet> {
throw new TelegramApiValidationException("Name can't be null", this);
}
}
public String getName() {
return name;
}
public GetStickerSet setName(String name) {
this.name = name;
return this;
}
@Override
public String toString() {
return "GetStickerSet{" +
"name='" + name + '\'' +
'}';
}
}

View File

@ -2,6 +2,14 @@ package org.telegram.telegrambots.meta.api.methods.stickers;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.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;
@ -9,13 +17,18 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.IOException;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 1.0
* Use this method to move a sticker in a set created by the bot to a specific position. Returns True on success.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SetStickerPositionInSet extends BotApiMethod<Boolean> {
private static final String PATH = "setStickerPositionInSet";
@ -23,19 +36,12 @@ public class SetStickerPositionInSet extends BotApiMethod<Boolean> {
private static final String POSITION_FIELD = "position";
@JsonProperty(STICKER_FIELD)
@NonNull
private String sticker; ///< File identifier of the sticker
@JsonProperty(POSITION_FIELD)
@NonNull
private Integer position; ///< New sticker position in the set, zero-based
public SetStickerPositionInSet(String sticker, Integer position) {
this.sticker = checkNotNull(sticker);
this.position = checkNotNull(position);
}
public SetStickerPositionInSet() {
super();
}
@Override
public String getMethod() {
return PATH;
@ -65,30 +71,4 @@ public class SetStickerPositionInSet extends BotApiMethod<Boolean> {
throw new TelegramApiValidationException("position can't be null", this);
}
}
public String getSticker() {
return sticker;
}
public SetStickerPositionInSet setSticker(String sticker) {
this.sticker = checkNotNull(sticker);
return this;
}
public Integer getPosition() {
return position;
}
public SetStickerPositionInSet setPosition(Integer position) {
this.position = checkNotNull(position);
return this;
}
@Override
public String toString() {
return "SetStickerPositionInSet{" +
"sticker='" + sticker + '\'' +
", position=" + position +
'}';
}
}

View File

@ -1,17 +1,21 @@
package org.telegram.telegrambots.meta.api.methods.stickers;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.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.InputFile;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
@ -19,6 +23,13 @@ import static com.google.common.base.Preconditions.checkNotNull;
* Use this method to set the thumbnail of a sticker set. Animated thumbnails can be set for animated sticker sets only.
* Returns True on success.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SetStickerSetThumb extends BotApiMethod<Boolean> {
private static final String PATH = "setStickerSetThumb";
@ -26,7 +37,9 @@ public class SetStickerSetThumb extends BotApiMethod<Boolean> {
public static final String USERID_FIELD = "user_id";
public static final String THUMB_FIELD = "thumb";
@NonNull
private String name; ///< Sticker set name
@NonNull
private Integer userId; ///< User identifier of the sticker set owner
/**
* A PNG image with the thumbnail, must be up to 128 kilobytes in size and have width and height exactly 100px,
@ -36,58 +49,9 @@ public class SetStickerSetThumb extends BotApiMethod<Boolean> {
* String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data.
* Animated sticker set thumbnail can't be uploaded via HTTP URL.
*/
@NonNull
private InputFile thumb;
public SetStickerSetThumb() {
super();
}
public SetStickerSetThumb(String name, Integer userId, InputFile thumb) {
this.name = name;
this.userId = userId;
this.thumb = thumb;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public InputFile getThumb() {
return thumb;
}
public SetStickerSetThumb setThumb(String thumb) {
this.thumb = new InputFile(thumb);
return this;
}
public SetStickerSetThumb setThumb(InputFile thumb) {
this.thumb = thumb;
return this;
}
public SetStickerSetThumb setThumb(File thumbFile) {
this.thumb = new InputFile(checkNotNull(thumbFile), thumbFile.getName());;
return this;
}
public SetStickerSetThumb setThumb(String thumbName, InputStream thumbStream) {
this.thumb = new InputFile(checkNotNull(thumbStream), checkNotNull(thumbName));
return this;
}
@Override
public String getMethod() {
return PATH;
@ -121,13 +85,4 @@ public class SetStickerSetThumb extends BotApiMethod<Boolean> {
}
thumb.validate();
}
@Override
public String toString() {
return "SetStickerSetThumb{" +
"name='" + name + '\'' +
", userId=" + userId +
", thumb=" + thumb +
'}';
}
}

View File

@ -1,17 +1,22 @@
package org.telegram.telegrambots.meta.api.methods.stickers;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.File;
import org.telegram.telegrambots.meta.api.objects.InputFile;
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.io.InputStream;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
@ -19,28 +24,28 @@ import static com.google.common.base.Preconditions.checkNotNull;
* Use this method to upload a .png file with a sticker for later use in createNewStickerSet and addStickerToSet
* methods (can be used multiple times). Returns the uploaded File on success.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class UploadStickerFile extends PartialBotApiMethod<File> {
public static final String PATH = "uploadStickerFile";
public static final String USERID_FIELD = "user_id";
public static final String PNGSTICKER_FIELD = "png_sticker";
@NonNull
private Integer userId; ///< User identifier of sticker file owner
/**
* Png image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px,
* and either width or height must be exactly 512px. More info on Sending Files »
*/
@NonNull
private InputFile pngSticker; ///< New sticker file
public UploadStickerFile() {
super();
}
public UploadStickerFile(Integer userId) {
super();
this.userId = checkNotNull(userId);
}
@Override
public File deserializeResponse(String answer) throws TelegramApiRequestException {
try {
@ -68,35 +73,4 @@ public class UploadStickerFile extends PartialBotApiMethod<File> {
pngSticker.validate();
}
public Integer getUserId() {
return userId;
}
public UploadStickerFile setUserId(Integer userId) {
this.userId = userId;
return this;
}
public InputFile getPngSticker() {
return pngSticker;
}
public UploadStickerFile setPngSticker(java.io.File pngSticker) {
this.pngSticker = new InputFile(pngSticker, pngSticker.getName());
return this;
}
public UploadStickerFile setPngSticker(String pngStickerName, InputStream pngStickerStream) {
this.pngSticker = new InputFile(pngStickerStream, pngStickerName);
return this;
}
@Override
public String toString() {
return "UploadStickerFile{" +
"userId=" + userId +
", pngSticker=" + pngSticker +
'}';
}
}

View File

@ -0,0 +1,59 @@
package org.telegram.telegrambots.meta.api.methods.updates;
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.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 2.4
* Use this method to close the bot instance before moving it from one local server to another.
* You need to delete the webhook before calling this method to ensure that the bot isn't launched again after server restart.
* The method will return error 429 in the first 10 minutes after the bot is launched.
* Returns True on success.
* Requires no parameters.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@AllArgsConstructor
@Builder
public class Close extends BotApiMethod<Boolean> {
public static final String PATH = "close";
@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 closing", result);
}
} catch (IOException e2) {
throw new TelegramApiRequestException("Unable to deserialize response", e2);
}
}
@Override
public void validate() throws TelegramApiValidationException {
}
}

View File

@ -1,7 +1,14 @@
package org.telegram.telegrambots.meta.api.methods.updates;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.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;
@ -15,12 +22,20 @@ import java.io.IOException;
* Use this method to receive incoming updates using long polling (wiki). An Array of Update
* objects is returned.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class DeleteWebhook extends BotApiMethod<Boolean>{
public static final String PATH = "deleteWebhook";
public DeleteWebhook() {
super();
}
private static final String DROPPENDINGUPDATES_FIELD = "drop_pending_updates";
@JsonProperty(DROPPENDINGUPDATES_FIELD)
private Boolean dropPendingUpdates; ///< Optional. Pass True to drop all pending updates
@Override
public String getMethod() {
@ -46,9 +61,4 @@ public class DeleteWebhook extends BotApiMethod<Boolean>{
@Override
public void validate() throws TelegramApiValidationException {
}
@Override
public String toString() {
return "DeleteWebhook{}";
}
}

Some files were not shown because too many files have changed in this diff Show More