dfkndsfjkdsjjdssdf
This commit is contained in:
19
core/build.gradle
Normal file
19
core/build.gradle
Normal file
@@ -0,0 +1,19 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
}
|
||||
|
||||
group = 'com.github.hdvtdev'
|
||||
version = '1.0.0'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.fasterxml.jackson.core:jackson-databind:2.18.3'
|
||||
}
|
||||
|
||||
jar {
|
||||
from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
}
|
||||
55
core/src/main/java/hdvtdev/telegram/Main.java
Normal file
55
core/src/main/java/hdvtdev/telegram/Main.java
Normal file
@@ -0,0 +1,55 @@
|
||||
package hdvtdev.telegram;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import hdvtdev.telegram.annotations.handlers.TextMessageHandler;
|
||||
import hdvtdev.telegram.core.OkHttpTelegramBot;
|
||||
import hdvtdev.telegram.core.TelegramBot;
|
||||
import hdvtdev.telegram.core.UpdateConsumer;
|
||||
import hdvtdev.telegram.exceptions.TelegramApiException;
|
||||
import hdvtdev.telegram.methods.*;
|
||||
import hdvtdev.telegram.objects.*;
|
||||
import hdvtdev.telegram.util.ClassFinder;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class Main {
|
||||
|
||||
private static String apiKey;
|
||||
|
||||
private static long idd = 2027845508;
|
||||
|
||||
public static TelegramBot bot;
|
||||
|
||||
@TextMessageHandler("пинг")
|
||||
private static void ping(Message message) {
|
||||
bot.execute(new SendMessage(message.chatId(), String.valueOf(bot.getPing())));
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
bot = new OkHttpTelegramBot.Builder(args[0]).enableHandlers(true).build();
|
||||
bot.enableDefaultUpdateConsumer();
|
||||
|
||||
apiKey = args[2];
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static class Upd implements UpdateConsumer, ClassFinder.ErrorHandler {
|
||||
|
||||
@Override
|
||||
public void onError(Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void getUpdates(List<Update> updates) {
|
||||
updates.forEach(System.out::println);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package hdvtdev.telegram.annotations.handlers;
|
||||
|
||||
import hdvtdev.telegram.objects.CallbackQuery;
|
||||
import hdvtdev.telegram.objects.Update;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Marks a static method as a handler for {@link CallbackQuery} updates with specific data values.
|
||||
* <p>
|
||||
* If {@code value} is set to "*", the method will handle all {@link CallbackQuery} data,
|
||||
* and other {@code @CallbackQueryHandler} methods will be ignored.
|
||||
* <p>
|
||||
* The annotated method must be {@code static} and may accept:
|
||||
* <ul>
|
||||
* <li>{@link Void} {@code (no params)}</li>
|
||||
* <li>{@link Update}</li>
|
||||
* <li>{@link CallbackQuery}</li>
|
||||
* </ul>
|
||||
* Only one parameter is allowed.
|
||||
* <p>
|
||||
* You do not need to call {@link CallbackQuery#hasData()} or {@link Update#hasCallbackQuery()},
|
||||
* as these checks are performed automatically before invocation.
|
||||
*
|
||||
* <h3>Usage example:</h3>
|
||||
* <pre><code>
|
||||
* {@code @CallbackQueryHandler({"stop",} "shutdown"})
|
||||
* private static void stop(CallbackQuery callbackQuery) {
|
||||
* long id = callbackQuery.message.chatId;
|
||||
* if (DatabaseManager.isAdmin(id)) {
|
||||
* bot.awaitExecute(new SendMessage(id, "Shutting down..."));
|
||||
* System.exit(0);
|
||||
* }
|
||||
* }
|
||||
* </code></pre>
|
||||
* <h5>Last documentation update: 2025-04-05</h5>
|
||||
* @see Update
|
||||
* @see CallbackQuery
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface CallbackQueryHandler {
|
||||
/**
|
||||
* Values to match against {@link CallbackQuery#data()}.
|
||||
* If set to "*", this method will handle all {@link CallbackQuery} updates,
|
||||
* overriding any other {@code @CallbackQueryHandler} annotations.
|
||||
*
|
||||
* @return array of matching strings
|
||||
*/
|
||||
@NotNull String[] value() default "*";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package hdvtdev.telegram.annotations.handlers;
|
||||
|
||||
import hdvtdev.telegram.objects.Message;
|
||||
import hdvtdev.telegram.objects.Update;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Marks a static method as a handler for {@link Message} updates with specific data values.
|
||||
* <p>
|
||||
* If {@code value} is set to "*", the method will handle all {@link Message} text,
|
||||
* and other {@code @TextMessageHandler} methods will be ignored.
|
||||
* <p>
|
||||
* The annotated method must be {@code static} and may accept:
|
||||
* <ul>
|
||||
* <li>{@link Void} {@code (no params)}</li>
|
||||
* <li>{@link Update}</li>
|
||||
* <li>{@link Message}</li>
|
||||
* </ul>
|
||||
* Only one parameter is allowed.
|
||||
* <p>
|
||||
* You do not need to call {@link Message#hasText()} or {@link Update#hasMessage()},
|
||||
* as these checks are performed automatically before invocation.
|
||||
*
|
||||
* <h3>Usage example:</h3>
|
||||
* <pre><code>
|
||||
* {@code @TextMessageHandler}({"rock", "paper", "scissors"})
|
||||
* private static void cheaterRockPaperScissors(Message message) {
|
||||
* bot.execute(new SendMessage(message.chatId(), switch(message.text()) {
|
||||
* case "rock" -> "paper";
|
||||
* case "paper" -> "scissors";
|
||||
* default -> "rock";
|
||||
* }));
|
||||
*
|
||||
* {@code @TextMessageHandler}("/ping")
|
||||
* private static void ping(Message message) {
|
||||
* bot.execute(new SendMessage(message.chatId(), String.valueOf(bot.getPing())));
|
||||
* }
|
||||
* </code></pre>
|
||||
* <h5>Last documentation update: 2025-04-05</h5>
|
||||
* @see Update
|
||||
* @see Message
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface TextMessageHandler {
|
||||
/**
|
||||
* Values to match against {@link Message#text()}.
|
||||
* If set to "*", this method will handle all {@link Message} updates,
|
||||
* overriding any other {@code @TextMessageHandler} annotations.
|
||||
*
|
||||
* @return array of matching strings
|
||||
*/
|
||||
@NotNull String[] value() default "*";
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package hdvtdev.telegram.annotations.util;
|
||||
|
||||
import hdvtdev.telegram.methods.TelegramApiMethod;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* This annotation is used to indicate {@link TelegramApiMethod} that should be serialized into JSON.
|
||||
* <h5>Last documentation update: 2025-04-05</h5>
|
||||
* @see com.fasterxml.jackson.databind.ObjectMapper
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface Jsonable {
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package hdvtdev.telegram.annotations.util;
|
||||
|
||||
import hdvtdev.telegram.methods.TelegramApiMethod;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* This annotation is used to indicate {@link TelegramApiMethod} that is not tested, usually used if the method was created recently.
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Target({ElementType.METHOD, ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface NotTested {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public record InvokeMethod(Method method, Class<?> parameterType) {
|
||||
|
||||
}
|
||||
52
core/src/main/java/hdvtdev/telegram/core/Main.java
Normal file
52
core/src/main/java/hdvtdev/telegram/core/Main.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.annotations.handlers.TextMessageHandler;
|
||||
import hdvtdev.telegram.longpolling
|
||||
import hdvtdev.telegram.core.TelegramBot;
|
||||
import hdvtdev.telegram.core.UpdateConsumer;
|
||||
import hdvtdev.telegram.methods.*;
|
||||
import hdvtdev.telegram.objects.*;
|
||||
import hdvtdev.telegram.util.ClassFinder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class Main {
|
||||
|
||||
private static String apiKey;
|
||||
|
||||
private static long idd = 2027845508;
|
||||
|
||||
public static TelegramBot bot;
|
||||
|
||||
@TextMessageHandler("пинг")
|
||||
private static void ping(Message message) {
|
||||
bot.execute(new SendMessage(message.chatId(), String.valueOf(bot.getPing())));
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
bot = new OkHttpTelegramBot.Builder(args[0]).enableHandlers(true).build();
|
||||
bot.enableDefaultUpdateConsumer();
|
||||
|
||||
apiKey = args[2];
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static class Upd implements UpdateConsumer, ClassFinder.ErrorHandler {
|
||||
|
||||
@Override
|
||||
public void onError(Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void getUpdates(List<Update> updates) {
|
||||
updates.forEach(System.out::println);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
45
core/src/main/java/hdvtdev/telegram/core/TelegramBot.java
Normal file
45
core/src/main/java/hdvtdev/telegram/core/TelegramBot.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package hdvtdev.telegram.core.bot;
|
||||
|
||||
import hdvtdev.telegram.exceptions.TelegramApiException;
|
||||
import hdvtdev.telegram.exceptions.TelegramApiNetworkException;
|
||||
import hdvtdev.telegram.exceptions.TelegramMethodParsingException;
|
||||
import hdvtdev.telegram.methods.TelegramApiMethod;
|
||||
import hdvtdev.telegram.objects.TelegramFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Path;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public interface TelegramBot {
|
||||
|
||||
<T> T awaitExecute(TelegramApiMethod<T> telegramApiMethod) throws TelegramApiException, TelegramApiNetworkException, TelegramMethodParsingException;
|
||||
|
||||
File awaitDownloadFile(TelegramFile telegramFile, Path targetDirectory);
|
||||
|
||||
default CompletableFuture<File> downloadFile(TelegramFile telegramFile, Path targetDirectory) throws TelegramApiException, TelegramApiNetworkException {
|
||||
return CompletableFuture.supplyAsync(() -> awaitDownloadFile(telegramFile, targetDirectory));
|
||||
}
|
||||
|
||||
default <T> CompletableFuture<T> execute(TelegramApiMethod<T> telegramApiMethod) throws TelegramApiException, TelegramApiNetworkException, TelegramMethodParsingException {
|
||||
return CompletableFuture.supplyAsync(() -> awaitExecute(telegramApiMethod));
|
||||
}
|
||||
|
||||
default int getPing() throws TelegramApiNetworkException {
|
||||
URI uri = URI.create("https://api.telegram.org");
|
||||
long startTime = System.currentTimeMillis();
|
||||
try {
|
||||
HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setConnectTimeout(15000);
|
||||
connection.connect();
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiNetworkException(e);
|
||||
}
|
||||
|
||||
return (int) (System.currentTimeMillis() - startTime);
|
||||
}
|
||||
|
||||
}
|
||||
11
core/src/main/java/hdvtdev/telegram/core/UpdateConsumer.java
Normal file
11
core/src/main/java/hdvtdev/telegram/core/UpdateConsumer.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package hdvtdev.telegram.core.bot;
|
||||
|
||||
import hdvtdev.telegram.core.objects.Update;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface UpdateConsumer {
|
||||
|
||||
void getUpdates(List<Update> updates);
|
||||
|
||||
}
|
||||
4
core/src/main/java/hdvtdev/telegram/core/UserState.java
Normal file
4
core/src/main/java/hdvtdev/telegram/core/UserState.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package hdvtdev.telegram.core.bot;
|
||||
|
||||
public interface UserState {
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package hdvtdev.telegram.core.annotaions;
|
||||
|
||||
import hdvtdev.telegram.core.methods.TelegramApiMethod;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* This annotation is used to indicate {@link TelegramApiMethod} that should be serialized into JSON.
|
||||
* <h5>Last documentation update: 2025-04-05</h5>
|
||||
* @see com.fasterxml.jackson.databind.ObjectMapper
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface Jsonable {
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package hdvtdev.telegram.exceptions;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class TelegramApiException extends IllegalArgumentException {
|
||||
|
||||
public TelegramApiException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public TelegramApiException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public TelegramApiException(ErrorResponse errorResponse) {
|
||||
super(errorResponse.description);
|
||||
}
|
||||
|
||||
public TelegramApiException(Throwable throwable) {
|
||||
super(throwable);
|
||||
}
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record ErrorResponse(boolean ok, @JsonProperty("error_code") int errorCode, String description) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package hdvtdev.telegram.exceptions;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class TelegramApiNetworkException extends RuntimeException {
|
||||
public TelegramApiNetworkException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public TelegramApiNetworkException(IOException e) {
|
||||
super(e);
|
||||
}
|
||||
|
||||
public TelegramApiNetworkException(String s, IOException e) {
|
||||
super(s, e);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package hdvtdev.telegram.exceptions;
|
||||
|
||||
public class TelegramMethodParsingException extends RuntimeException {
|
||||
public TelegramMethodParsingException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public TelegramMethodParsingException(Throwable throwable) {
|
||||
super(throwable);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
import hdvtdev.telegram.objects.Game;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
/**
|
||||
* Use this method to send answers to callback queries sent from inline keyboards.
|
||||
* The answer will be displayed to the user as a notification at the top of the chat screen or as an alert.
|
||||
* Alternatively, the user can be redirected to the specified {@link Game} URL.
|
||||
* For this option to work, you must first create a game for your bot via @BotFather and accept the terms. Otherwise, you may use links like t.me/your_bot?start=XXXX that open your bot with a parameter.
|
||||
* @apiNote On success, {@code Boolean == true} is returned.
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
@NotTested
|
||||
public class AnswerCallbackQuery implements TelegramApiMethod<Boolean> {
|
||||
|
||||
/**
|
||||
* Unique identifier for the query to be answered
|
||||
*/
|
||||
private final String callbackQueryId;
|
||||
/**
|
||||
* Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters
|
||||
*/
|
||||
private String text;
|
||||
/**
|
||||
* If True, an alert will be shown by the client instead of a notification at the top of the chat screen. Defaults to false.
|
||||
*/
|
||||
private Boolean showAlert;
|
||||
/**
|
||||
* URL that will be opened by the user's client.
|
||||
* If you have created a {@link Game} and accepted the conditions via @BotFather, specify the URL that opens your game.
|
||||
* Otherwise, you may use links like t.me/your_bot?start=XXXX that open your bot with a parameter.
|
||||
* @apiNote this will only work if the query comes from a callback_game button.
|
||||
*/
|
||||
private String url;
|
||||
/**
|
||||
* The maximum amount of time in seconds that the result of the callback query may be cached client-side.
|
||||
* Telegram apps will support caching starting in version 3.14. Defaults to 0.
|
||||
*/
|
||||
private Integer cacheTime;
|
||||
|
||||
public AnswerCallbackQuery(String callbackQueryId) {
|
||||
this.callbackQueryId = callbackQueryId;
|
||||
}
|
||||
|
||||
private AnswerCallbackQuery(Builder builder) {
|
||||
callbackQueryId = builder.callbackQueryId;
|
||||
text = builder.text;
|
||||
showAlert = builder.showAlert;
|
||||
url = builder.url;
|
||||
cacheTime = builder.cacheTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
FormBody.Builder builder = new FormBody.Builder().add("callback_query_id", this.callbackQueryId);
|
||||
if (text != null) builder.add("text", this.text);
|
||||
if (showAlert != null) builder.add("show_alert", String.valueOf(this.showAlert));
|
||||
if (url != null) builder.add("url", this.url);
|
||||
if (cacheTime != null) builder.add("cache_time", String.valueOf(this.cacheTime));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "answerCallbackQuery";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Boolean> getResponseClass() {
|
||||
return Boolean.class;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private final String callbackQueryId;
|
||||
private String text;
|
||||
private Boolean showAlert;
|
||||
private String url;
|
||||
private Integer cacheTime;
|
||||
|
||||
public Builder(String callbackQueryId) {
|
||||
this.callbackQueryId = callbackQueryId;
|
||||
}
|
||||
|
||||
public Builder text(String text) {
|
||||
this.text = text;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder showAlert(Boolean showAlert) {
|
||||
this.showAlert = showAlert;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder url(String url) {
|
||||
this.url = url;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder cacheTime(Integer cacheTime) {
|
||||
this.cacheTime = cacheTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AnswerCallbackQuery build() {
|
||||
return new AnswerCallbackQuery(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
import hdvtdev.telegram.objects.ChatAdministratorRights;
|
||||
import hdvtdev.telegram.objects.Chat;
|
||||
import hdvtdev.telegram.objects.User;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Use this method to approve a chat join request.
|
||||
* The bot must be an <u>administrator</u> in the chat for this to work and must have the {@link ChatAdministratorRights#canInviteUsers()} administrator right.
|
||||
* Returns True on success.
|
||||
* @param chatId Unique username of the target channel in the format @channelusername
|
||||
* @param userId Unique identifier of the target user
|
||||
* @see ChatAdministratorRights
|
||||
* @see Chat
|
||||
* @see Chat#id()
|
||||
* @since 0.1.0
|
||||
*/
|
||||
@NotTested
|
||||
public record ApproveChatJoinRequest(@NotNull String chatId, long userId) implements TelegramApiMethod<Boolean> {
|
||||
|
||||
/**
|
||||
* @param chatId Unique identifier for the target chat
|
||||
* @param userId Unique identifier of the target user
|
||||
* @see User#id()
|
||||
* @see Chat#id()
|
||||
*/
|
||||
public ApproveChatJoinRequest(long chatId, long userId) {
|
||||
this(String.valueOf(chatId), userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return new FormBody.Builder().add("chat_id", chatId).add("user_id", String.valueOf(userId)).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "approveChatJoinRequest";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Boolean> getResponseClass() {
|
||||
return Boolean.class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
import hdvtdev.telegram.objects.ChatAdministratorRights;
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
/**
|
||||
* Use this method to ban a user in a group, a supergroup or a channel.
|
||||
* In the case of supergroups and channels, the user will not be able to return
|
||||
* to the chat on their own using invite links, etc., unless unbanned first.
|
||||
* The bot must be an administrator in the chat for this to work and must have
|
||||
* the appropriate administrator rights: {@link ChatAdministratorRights#canRestrictMembers()}. Returns True on success.
|
||||
* @see ChatAdministratorRights
|
||||
* @since 0.1.1
|
||||
*/
|
||||
@NotTested
|
||||
public final class BanChatMember implements TelegramApiMethod<Boolean> {
|
||||
|
||||
/**
|
||||
* Unique identifier for the target group or username of the target supergroup or channel (in the format @channelusername)
|
||||
*/
|
||||
private final String chatId;
|
||||
/**
|
||||
* Unique identifier of the target user
|
||||
*/
|
||||
private final long userId;
|
||||
/**
|
||||
* 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.
|
||||
* Applied for supergroups and channels only.
|
||||
*/
|
||||
private Long untilDate;
|
||||
/**
|
||||
* Pass true to delete all messages from the chat for the user that is being removed.
|
||||
* If false, the user will be able to see messages in the group that were sent before the user was removed.
|
||||
* Always True for supergroups and channels.
|
||||
*/
|
||||
private Boolean revokeMessages;
|
||||
|
||||
public BanChatMember(String chatId, long userId) {
|
||||
this.chatId = chatId;
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public BanChatMember(long chatId, long userId) {
|
||||
this.chatId = String.valueOf(chatId);
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
private BanChatMember(Builder builder) {
|
||||
chatId = builder.chatId;
|
||||
userId = builder.userId;
|
||||
setUntilDate(builder.untilDate);
|
||||
setRevokeMessages(builder.revokeMessages);
|
||||
}
|
||||
|
||||
public void setUntilDate(Long untilDate) {
|
||||
this.untilDate = untilDate;
|
||||
}
|
||||
|
||||
public void setRevokeMessages(Boolean revokeMessages) {
|
||||
this.revokeMessages = revokeMessages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
FormBody.Builder builder = new FormBody.Builder().add("chat_id", this.chatId).add("user_id", String.valueOf(userId));
|
||||
if (untilDate != null) builder.add("until_date", String.valueOf(untilDate));
|
||||
if (revokeMessages != null) builder.add("revoke_messages", String.valueOf(revokeMessages));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "banChatMember";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Boolean> getResponseClass() {
|
||||
return Boolean.class;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private final String chatId;
|
||||
private final long userId;
|
||||
private Long untilDate;
|
||||
private Boolean revokeMessages;
|
||||
|
||||
public Builder(String chatId, long userId) {
|
||||
this.chatId = chatId;
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public Builder untilDate(Long untilDate) {
|
||||
this.untilDate = untilDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder revokeMessages(Boolean revokeMessages) {
|
||||
this.revokeMessages = revokeMessages;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BanChatMember build() {
|
||||
return new BanChatMember(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Use this method to ban a channel chat in a supergroup or a channel.
|
||||
* Until the chat is unbanned, the owner of the banned chat won't be able to send messages on behalf of
|
||||
* their channels. The bot must be an administrator in the supergroup or channel for this to
|
||||
* work and must have the appropriate administrator rights. Returns True on success.
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@NotTested
|
||||
public record BanChatSenderChat(@NotNull String chatId, long userId) implements TelegramApiMethod<Boolean> {
|
||||
|
||||
public BanChatSenderChat(long chatId, long userId) {
|
||||
this(String.valueOf(chatId), userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return new FormBody.Builder().add("chat_id", chatId).add("user_id", String.valueOf(userId)).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "banChatSenderChat";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Boolean> getResponseClass() {
|
||||
return Boolean.class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
import hdvtdev.telegram.objects.ChatAdministratorRights;
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
/**
|
||||
* Use this method to close an open topic in a forum supergroup chat.
|
||||
* The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights,
|
||||
* unless it is the creator of the topic. Returns {@code true} on success.
|
||||
* @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
|
||||
* @param messageThreadId Unique identifier for the target message thread of the forum topic
|
||||
* @see ChatAdministratorRights#canManageTopics()
|
||||
*/
|
||||
@NotTested
|
||||
public record CloseForumTopic(String chatId, long messageThreadId) implements TelegramApiMethod<Boolean> {
|
||||
|
||||
public CloseForumTopic(long chatId, long messageThreadId) {
|
||||
this(String.valueOf(chatId), messageThreadId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return new FormBody.Builder().add("chat_id", chatId).add("message_thread_id", String.valueOf(messageThreadId)).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "closeForumTopic";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Boolean> getResponseClass() {
|
||||
return Boolean.class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
import hdvtdev.telegram.objects.ChatAdministratorRights;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
/**
|
||||
* Use this method to close an open 'General' topic in a forum supergroup chat.
|
||||
* The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights.
|
||||
* Returns {@code true} on success.
|
||||
* @see ChatAdministratorRights#canManageTopics()
|
||||
* @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
|
||||
*/
|
||||
@NotTested
|
||||
public record CloseGeneralForumTopic(String chatId) implements TelegramApiMethod<Boolean> {
|
||||
|
||||
public CloseGeneralForumTopic(long chatId) {
|
||||
this(String.valueOf(chatId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return new FormBody.Builder().add("chat_id", chatId).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "closeGeneralForumTopic";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Boolean> getResponseClass() {
|
||||
return Boolean.class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
import hdvtdev.telegram.objects.MessageEntity;
|
||||
import hdvtdev.telegram.objects.Poll;
|
||||
import hdvtdev.telegram.objects.ReplyMarkup;
|
||||
import hdvtdev.telegram.objects.ReplyParameters;
|
||||
import hdvtdev.telegram.util.ParseMode;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Use this method to copy messages of any kind.
|
||||
* Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied.
|
||||
* A quiz {@link Poll} can be copied only if the value of the field correct_option_id is known to the bot.
|
||||
* The method is analogous to the method {@link ForwardMessage}, but the copied message doesn't have a link to the original message.
|
||||
* Returns the messageId as {@link Long} of the sent message on success.
|
||||
* @see Poll#correctOptionId()
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@NotTested
|
||||
@Jsonable
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public final class CopyMessage implements TelegramApiMethod<Long> {
|
||||
|
||||
@JsonProperty("chat_id")
|
||||
private final String chatId;
|
||||
@JsonProperty("message_thread_id")
|
||||
private Long messageThreadId;
|
||||
@JsonProperty("from_chat_id")
|
||||
private final String fromChatId;
|
||||
@JsonProperty("message_id")
|
||||
private final long messageId;
|
||||
@JsonProperty("video_start_timestamp")
|
||||
private long videoStartTimestamp;
|
||||
@JsonProperty("caption")
|
||||
private String caption;
|
||||
@JsonProperty("parse_mode")
|
||||
private ParseMode parseMode;
|
||||
@JsonProperty("caption_entities")
|
||||
private List<MessageEntity> captionEntities;
|
||||
@JsonProperty("show_caption_above_media")
|
||||
private Boolean showCaptionAboveMedia;
|
||||
@JsonProperty("disable_notification")
|
||||
private Boolean disableNotification;
|
||||
@JsonProperty("protect_content")
|
||||
private Boolean protectContent;
|
||||
@JsonProperty("allow_paid_broadcast")
|
||||
private Boolean allowPaidBroadcast;
|
||||
@JsonProperty("reply_parameters")
|
||||
private ReplyParameters replyParameters;
|
||||
@JsonProperty("reply_markup")
|
||||
private ReplyMarkup replyMarkup;
|
||||
|
||||
public CopyMessage(String chatId, String fromChatId, long messageId) {
|
||||
this.chatId = chatId;
|
||||
this.fromChatId = fromChatId;
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
public CopyMessage(long chatId, String fromChatId, long messageId) {
|
||||
this(String.valueOf(chatId), fromChatId, messageId);
|
||||
}
|
||||
|
||||
public CopyMessage(long chatId, long fromChatId, long messageId) {
|
||||
this(String.valueOf(chatId), String.valueOf(fromChatId), messageId);
|
||||
}
|
||||
|
||||
public CopyMessage(String chatId, long fromChatId, long messageId) {
|
||||
this(chatId, String.valueOf(fromChatId), messageId);
|
||||
}
|
||||
|
||||
private CopyMessage(Builder builder) {
|
||||
chatId = builder.chatId;
|
||||
setMessageThreadId(builder.messageThreadId);
|
||||
fromChatId = builder.fromChatId;
|
||||
messageId = builder.messageId;
|
||||
setVideoStartTimestamp(builder.videoStartTimestamp);
|
||||
setCaption(builder.caption);
|
||||
setParseMode(builder.parseMode);
|
||||
setCaptionEntities(builder.captionEntities);
|
||||
setShowCaptionAboveMedia(builder.showCaptionAboveMedia);
|
||||
setDisableNotification(builder.disableNotification);
|
||||
setProtectContent(builder.protectContent);
|
||||
setAllowPaidBroadcast(builder.allowPaidBroadcast);
|
||||
setReplyParameters(builder.replyParameters);
|
||||
setReplyMarkup(builder.replyMarkup);
|
||||
}
|
||||
|
||||
public void setMessageThreadId(Long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
}
|
||||
|
||||
public void setVideoStartTimestamp(long videoStartTimestamp) {
|
||||
this.videoStartTimestamp = videoStartTimestamp;
|
||||
}
|
||||
|
||||
public void setCaption(String caption) {
|
||||
this.caption = caption;
|
||||
}
|
||||
|
||||
public void setParseMode(ParseMode parseMode) {
|
||||
this.parseMode = parseMode;
|
||||
}
|
||||
|
||||
public void setCaptionEntities(List<MessageEntity> captionEntities) {
|
||||
this.captionEntities = captionEntities;
|
||||
}
|
||||
|
||||
public void setShowCaptionAboveMedia(Boolean showCaptionAboveMedia) {
|
||||
this.showCaptionAboveMedia = showCaptionAboveMedia;
|
||||
}
|
||||
|
||||
public void setDisableNotification(Boolean disableNotification) {
|
||||
this.disableNotification = disableNotification;
|
||||
}
|
||||
|
||||
public void setProtectContent(Boolean protectContent) {
|
||||
this.protectContent = protectContent;
|
||||
}
|
||||
|
||||
public void setAllowPaidBroadcast(Boolean allowPaidBroadcast) {
|
||||
this.allowPaidBroadcast = allowPaidBroadcast;
|
||||
}
|
||||
|
||||
public void setReplyParameters(ReplyParameters replyParameters) {
|
||||
this.replyParameters = replyParameters;
|
||||
}
|
||||
|
||||
public void setReplyMarkup(ReplyMarkup replyMarkup) {
|
||||
this.replyMarkup = replyMarkup;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "copyMessage";
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Class<Long> getResponseClass() {
|
||||
return Long.class;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private final String chatId;
|
||||
private Long messageThreadId;
|
||||
private final String fromChatId;
|
||||
private final long messageId;
|
||||
private long videoStartTimestamp;
|
||||
private String caption;
|
||||
private ParseMode parseMode;
|
||||
private List<MessageEntity> captionEntities;
|
||||
private Boolean showCaptionAboveMedia;
|
||||
private Boolean disableNotification;
|
||||
private Boolean protectContent;
|
||||
private Boolean allowPaidBroadcast;
|
||||
private ReplyParameters replyParameters;
|
||||
private ReplyMarkup replyMarkup;
|
||||
|
||||
public Builder(String chatId, String fromChatId, long messageId) {
|
||||
this.chatId = chatId;
|
||||
this.fromChatId = fromChatId;
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
public Builder(long chatId, String fromChatId, long messageId) {
|
||||
this(String.valueOf(chatId), fromChatId, messageId);
|
||||
}
|
||||
|
||||
public Builder messageThreadId(Long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder videoStartTimestamp(long videoStartTimestamp) {
|
||||
this.videoStartTimestamp = videoStartTimestamp;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder caption(String caption) {
|
||||
this.caption = caption;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder parseMode(ParseMode parseMode) {
|
||||
this.parseMode = parseMode;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder captionEntities(List<MessageEntity> captionEntities) {
|
||||
this.captionEntities = captionEntities;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder showCaptionAboveMedia(Boolean showCaptionAboveMedia) {
|
||||
this.showCaptionAboveMedia = showCaptionAboveMedia;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder disableNotification(Boolean disableNotification) {
|
||||
this.disableNotification = disableNotification;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder protectContent(Boolean protectContent) {
|
||||
this.protectContent = protectContent;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder allowPaidBroadcast(Boolean allowPaidBroadcast) {
|
||||
this.allowPaidBroadcast = allowPaidBroadcast;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder replyParameters(ReplyParameters replyParameters) {
|
||||
this.replyParameters = replyParameters;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder replyMarkup(ReplyMarkup replyMarkup) {
|
||||
this.replyMarkup = replyMarkup;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CopyMessage build() {
|
||||
return new CopyMessage(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.objects.Poll;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Use this method to copy messages of any kind.
|
||||
* If some of the specified messages can't be found or copied, they are skipped.
|
||||
* Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied.
|
||||
* A quiz {@link Poll} can be copied only if the value of the field correct_option_id is known to the bot.
|
||||
* The method is analogous to the method {@link ForwardMessages}, but the copied messages don't have a link to the original message.
|
||||
* Album grouping is kept for copied messages.
|
||||
* On success, an array of MessageId as {@link Long}{@code []} of the sent messages is returned.
|
||||
* @see Poll#correctOptionId()
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Jsonable
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public final class CopyMessages implements TelegramApiMethod<Long[]> {
|
||||
|
||||
@JsonProperty("chat_id")
|
||||
private final String chatId;
|
||||
@JsonProperty("message_thread_id")
|
||||
private Long messageThreadId;
|
||||
@JsonProperty("from_chat_id")
|
||||
private final String fromChatId;
|
||||
@JsonProperty("message_id")
|
||||
private final List<Long> messageIds;
|
||||
@JsonProperty("disable_notification")
|
||||
private Boolean disableNotification;
|
||||
@JsonProperty("protect_content")
|
||||
private Boolean protectContent;
|
||||
@JsonProperty("remove_caption")
|
||||
private Boolean removeCaption;
|
||||
|
||||
/**
|
||||
* @param chatId Username of the target channel (in the format @channelusername)
|
||||
* @param fromChatId Channel username in the format @channelusername for the chat where the original messages were sent
|
||||
* @param messageIds List of 1-100 identifiers of messages in the chat to copy.
|
||||
*/
|
||||
public CopyMessages(String chatId, String fromChatId, List<Long> messageIds) {
|
||||
this.chatId = chatId;
|
||||
this.fromChatId = fromChatId;
|
||||
ArrayList<Long> sortedMessageIds = new ArrayList<>(messageIds.subList(0, Math.min(messageIds.size(), 100)));
|
||||
sortedMessageIds.sort(null);
|
||||
this.messageIds = sortedMessageIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param chatId Unique identifier for the target chat
|
||||
* @param fromChatId Channel username in the format @channelusername for the chat where the original messages were sent
|
||||
* @param messageIds List of 1-100 identifiers of messages in the chat to copy.
|
||||
*/
|
||||
public CopyMessages(long chatId, String fromChatId, List<Long> messageIds) {
|
||||
this(String.valueOf(chatId), fromChatId, messageIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param chatId Unique identifier for the target chat
|
||||
* @param fromChatId Unique identifier for the chat where the original messages were sent
|
||||
* @param messageIds List of 1-100 identifiers of messages in the chat to copy.
|
||||
*/
|
||||
public CopyMessages(long chatId, long fromChatId, List<Long> messageIds) {
|
||||
this(String.valueOf(chatId), String.valueOf(fromChatId), messageIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param chatId Channel username in the format @channelusername for the chat where the original messages were sent
|
||||
* @param fromChatId Unique identifier for the target chat
|
||||
* @param messageIds List of 1-100 identifiers of messages in the chat to copy.
|
||||
*/
|
||||
public CopyMessages(String chatId, long fromChatId, List<Long> messageIds) {
|
||||
this(chatId, String.valueOf(fromChatId), messageIds);
|
||||
}
|
||||
|
||||
private CopyMessages(Builder builder) {
|
||||
chatId = builder.chatId;
|
||||
setMessageThreadId(builder.messageThreadId);
|
||||
fromChatId = builder.fromChatId;
|
||||
messageIds = builder.messageIds;
|
||||
setDisableNotification(builder.disableNotification);
|
||||
setProtectContent(builder.protectContent);
|
||||
setRemoveCaption(builder.removeCaption);
|
||||
}
|
||||
|
||||
public void setMessageThreadId(Long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
}
|
||||
|
||||
public void setDisableNotification(Boolean disableNotification) {
|
||||
this.disableNotification = disableNotification;
|
||||
}
|
||||
|
||||
public void setProtectContent(Boolean protectContent) {
|
||||
this.protectContent = protectContent;
|
||||
}
|
||||
|
||||
public void setRemoveCaption(Boolean removeCaption) {
|
||||
this.removeCaption = removeCaption;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "copyMessages";
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Class<Long[]> getResponseClass() {
|
||||
return Long[].class;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private final String chatId;
|
||||
private Long messageThreadId;
|
||||
private final String fromChatId;
|
||||
private final List<Long> messageIds;
|
||||
private Boolean disableNotification;
|
||||
private Boolean protectContent;
|
||||
private Boolean removeCaption;
|
||||
|
||||
public Builder(String chatId, String fromChatId, List<Long> messageIds) {
|
||||
this.chatId = chatId;
|
||||
this.fromChatId = fromChatId;
|
||||
ArrayList<Long> sortedMessageIds = new ArrayList<>(messageIds.subList(0, Math.min(messageIds.size(), 100)));
|
||||
sortedMessageIds.sort(null);
|
||||
this.messageIds = sortedMessageIds;
|
||||
}
|
||||
public Builder(long chatId, String fromChatId, List<Long> messageIds) {
|
||||
this(String.valueOf(chatId), fromChatId, messageIds);
|
||||
}
|
||||
|
||||
public Builder(long chatId, long fromChatId, List<Long> messageIds) {
|
||||
this(String.valueOf(chatId), String.valueOf(fromChatId), messageIds);
|
||||
}
|
||||
|
||||
public Builder(String chatId, long fromChatId, List<Long> messageIds) {
|
||||
this(chatId, String.valueOf(fromChatId), messageIds);
|
||||
}
|
||||
|
||||
public Builder messageThreadId(Long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder disableNotification(Boolean disableNotification) {
|
||||
this.disableNotification = disableNotification;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder protectContent(Boolean protectContent) {
|
||||
this.protectContent = protectContent;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder removeCaption(Boolean removeCaption) {
|
||||
this.removeCaption = removeCaption;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CopyMessages build() {
|
||||
return new CopyMessages(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.objects.ChatAdministratorRights;
|
||||
import hdvtdev.telegram.objects.ChatInviteLink;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
/**
|
||||
* Use this method to create an additional invite link for a chat.
|
||||
* The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
|
||||
* The link can be revoked using the method {@link RevokeChatInviteLink}. Returns the new invite link as {@link ChatInviteLink} object.
|
||||
* @see ChatAdministratorRights#canInviteUsers()
|
||||
*/
|
||||
public final class CreateChatInviteLink implements TelegramApiMethod<ChatInviteLink> {
|
||||
|
||||
private final String chatId;
|
||||
private String name;
|
||||
private Long expireDate;
|
||||
private Integer memberLimit;
|
||||
private Boolean createsJoinRequest;
|
||||
|
||||
public CreateChatInviteLink(String chatId) {
|
||||
this.chatId = chatId;
|
||||
}
|
||||
|
||||
public CreateChatInviteLink(long chatId) {
|
||||
this(String.valueOf(chatId));
|
||||
}
|
||||
|
||||
private CreateChatInviteLink(Builder builder) {
|
||||
chatId = builder.chatId;
|
||||
setName(builder.name);
|
||||
setExpireDate(builder.expireDate);
|
||||
setMemberLimit(builder.memberLimit);
|
||||
setCreatesJoinRequest(builder.createsJoinRequest);
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setExpireDate(Long expireDate) {
|
||||
this.expireDate = expireDate;
|
||||
}
|
||||
|
||||
public void setMemberLimit(Integer memberLimit) {
|
||||
this.memberLimit = memberLimit;
|
||||
}
|
||||
|
||||
public void setCreatesJoinRequest(Boolean createsJoinRequest) {
|
||||
this.createsJoinRequest = createsJoinRequest;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
FormBody.Builder builder = new FormBody.Builder().add("chat_id", chatId);
|
||||
if (expireDate != null) builder.add("expire_date", String.valueOf(expireDate));
|
||||
if (memberLimit != null) builder.add("member_limit", String.valueOf(memberLimit));
|
||||
if (createsJoinRequest != null) builder.add("creates_join_request", String.valueOf(createsJoinRequest));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "createChatInviteLink";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<ChatInviteLink> getResponseClass() {
|
||||
return ChatInviteLink.class;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private final String chatId;
|
||||
private String name;
|
||||
private Long expireDate;
|
||||
private Integer memberLimit;
|
||||
private Boolean createsJoinRequest;
|
||||
|
||||
public Builder(String chatId) {
|
||||
this.chatId = chatId;
|
||||
}
|
||||
|
||||
public Builder(long chatId) {
|
||||
this(String.valueOf(chatId));
|
||||
}
|
||||
|
||||
public Builder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder expireDate(Long expireDate) {
|
||||
this.expireDate = expireDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder memberLimit(Integer memberLimit) {
|
||||
this.memberLimit = memberLimit;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder createsJoinRequest(Boolean createsJoinRequest) {
|
||||
this.createsJoinRequest = createsJoinRequest;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CreateChatInviteLink build() {
|
||||
return new CreateChatInviteLink(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.objects.Message;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
/**
|
||||
* Use this method to forward messages of any kind.
|
||||
* Service messages and messages with protected content can't be forwarded.
|
||||
* On success, the sent {@link Message} is returned.
|
||||
*/
|
||||
@Jsonable
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public final class ForwardMessage implements TelegramApiMethod<Message> {
|
||||
|
||||
@JsonProperty("chat_id")
|
||||
private final String chatId;
|
||||
@JsonProperty("message_thread_id")
|
||||
private Long messageThreadId;
|
||||
@JsonProperty("from_chat_id")
|
||||
private final String fromChatId;
|
||||
@JsonProperty("message_id")
|
||||
private final long messageId;
|
||||
@JsonProperty("disable_notification")
|
||||
private Boolean disableNotification;
|
||||
@JsonProperty("protect_content")
|
||||
private Boolean protectContent;
|
||||
@JsonProperty("video_start_timestamp")
|
||||
private long videoStartTimestamp;
|
||||
|
||||
public ForwardMessage(String chatId, String fromChatId, long messageId) {
|
||||
this.chatId = chatId;
|
||||
this.fromChatId = fromChatId;
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
public ForwardMessage(long chatId, String fromChatId, long messageId) {
|
||||
this(String.valueOf(chatId), fromChatId, messageId);
|
||||
}
|
||||
|
||||
public ForwardMessage(long chatId, long fromChatId, long messageId) {
|
||||
this(String.valueOf(chatId), String.valueOf(fromChatId), messageId);
|
||||
}
|
||||
|
||||
private ForwardMessage(Builder builder) {
|
||||
chatId = builder.chatId;
|
||||
setMessageThreadId(builder.messageThreadId);
|
||||
fromChatId = builder.fromChatId;
|
||||
messageId = builder.messageId;
|
||||
setDisableNotification(builder.disableNotification);
|
||||
setProtectContent(builder.protectContent);
|
||||
setVideoStartTimestamp(builder.videoStartTimestamp);
|
||||
}
|
||||
|
||||
public void setMessageThreadId(Long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
}
|
||||
|
||||
public void setDisableNotification(Boolean disableNotification) {
|
||||
this.disableNotification = disableNotification;
|
||||
}
|
||||
|
||||
public void setProtectContent(Boolean protectContent) {
|
||||
this.protectContent = protectContent;
|
||||
}
|
||||
|
||||
public void setVideoStartTimestamp(long videoStartTimestamp) {
|
||||
this.videoStartTimestamp = videoStartTimestamp;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "forwardMessage";
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Class<Message> getResponseClass() {
|
||||
return Message.class;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private final String chatId;
|
||||
private Long messageThreadId;
|
||||
private final String fromChatId;
|
||||
private final long messageId;
|
||||
private Boolean disableNotification;
|
||||
private Boolean protectContent;
|
||||
private long videoStartTimestamp;
|
||||
|
||||
public Builder(String chatId, String fromChatId, long messageId) {
|
||||
this.chatId = chatId;
|
||||
this.fromChatId = fromChatId;
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
public Builder messageThreadId(Long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder disableNotification(Boolean disableNotification) {
|
||||
this.disableNotification = disableNotification;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder protectContent(Boolean protectContent) {
|
||||
this.protectContent = protectContent;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder videoStartTimestamp(long videoStartTimestamp) {
|
||||
this.videoStartTimestamp = videoStartTimestamp;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ForwardMessage build() {
|
||||
return new ForwardMessage(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import hdvtdev.telegram.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
import hdvtdev.telegram.objects.Message;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Use this method to forward multiple messages of any kind. If some of the specified messages can't be found or forwarded, they are skipped.
|
||||
* Service messages and messages with protected content can't be forwarded. Album grouping is kept for forwarded messages.
|
||||
* On success, an array of MessageId as {@link Long} of the sent messages is returned.
|
||||
* @see Message#hasProtectedContent()
|
||||
*/
|
||||
@Jsonable
|
||||
@NotTested
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public final class ForwardMessages implements TelegramApiMethod<Long[]> {
|
||||
|
||||
@JsonProperty("chat_id")
|
||||
private final String chatId;
|
||||
@JsonProperty("message_thread_id")
|
||||
private Long messageThreadId;
|
||||
@JsonProperty("from_chat_id")
|
||||
private final String fromChatId;
|
||||
@JsonProperty("message_id")
|
||||
private final List<Long> messageIds;
|
||||
@JsonProperty("disable_notification")
|
||||
private Boolean disableNotification;
|
||||
@JsonProperty("protect_content")
|
||||
private Boolean protectContent;
|
||||
|
||||
public ForwardMessages(String chatId, String fromChatId, List<Long> messageIds) {
|
||||
ArrayList<Long> sortedMessageIds = new ArrayList<>(messageIds.size() > 100 ? messageIds.subList(0, 100) : messageIds);
|
||||
sortedMessageIds.sort(null);
|
||||
this.chatId = chatId;
|
||||
this.fromChatId = fromChatId;
|
||||
this.messageIds = sortedMessageIds;
|
||||
}
|
||||
|
||||
public ForwardMessages(long chatId, String fromChatId, List<Long> messageIds) {
|
||||
this(String.valueOf(chatId), fromChatId, messageIds);
|
||||
}
|
||||
|
||||
public ForwardMessages(String chatId, long fromChatId, List<Long> messageIds) {
|
||||
this(chatId, String.valueOf(fromChatId), messageIds);
|
||||
}
|
||||
|
||||
public ForwardMessages(long chatId, long fromChatId, List<Long> messageIds) {
|
||||
this(String.valueOf(chatId), String.valueOf(fromChatId), messageIds);
|
||||
}
|
||||
|
||||
private ForwardMessages(Builder builder) {
|
||||
chatId = builder.chatId;
|
||||
messageThreadId = builder.messageThreadId;
|
||||
fromChatId = builder.fromChatId;
|
||||
messageIds = builder.messageIds;
|
||||
disableNotification = builder.disableNotification;
|
||||
protectContent = builder.protectContent;
|
||||
}
|
||||
|
||||
public void setMessageThreadId(long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
}
|
||||
|
||||
public void setDisableNotification(boolean disableNotification) {
|
||||
this.disableNotification = disableNotification;
|
||||
}
|
||||
|
||||
public void setProtectContent(boolean protectContent) {
|
||||
this.protectContent = protectContent;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "forwardMessages";
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Class<Long[]> getResponseClass() {
|
||||
return Long[].class;
|
||||
}
|
||||
|
||||
|
||||
public static final class Builder {
|
||||
private final String chatId;
|
||||
private Long messageThreadId;
|
||||
private final String fromChatId;
|
||||
private final List<Long> messageIds;
|
||||
private Boolean disableNotification;
|
||||
private Boolean protectContent;
|
||||
|
||||
public Builder(String chatId, String fromChatId, List<Long> messageIds) {
|
||||
ArrayList<Long> sortedMessageIds = new ArrayList<>(messageIds.size() > 100 ? messageIds.subList(0, 100) : messageIds);
|
||||
sortedMessageIds.sort(null);
|
||||
this.chatId = chatId;
|
||||
this.fromChatId = fromChatId;
|
||||
this.messageIds = sortedMessageIds;
|
||||
}
|
||||
|
||||
public Builder(long chatId, String fromChatId, List<Long> messageIds) {
|
||||
this(String.valueOf(chatId), fromChatId, messageIds);
|
||||
}
|
||||
|
||||
public Builder(String chatId, long fromChatId, List<Long> messageIds) {
|
||||
this(chatId, String.valueOf(fromChatId), messageIds);
|
||||
}
|
||||
|
||||
public Builder(long chatId, long fromChatId, List<Long> messageIds) {
|
||||
this(String.valueOf(chatId), String.valueOf(fromChatId), messageIds);
|
||||
}
|
||||
|
||||
public Builder messageThreadId(long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder disableNotification(boolean disableNotification) {
|
||||
this.disableNotification = disableNotification;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder protectContent(boolean protectContent) {
|
||||
this.protectContent = protectContent;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ForwardMessages build() {
|
||||
return new ForwardMessages(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
import hdvtdev.telegram.objects.ChatMember;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Use this method to get a list of administrators in a chat, which aren't bots. Returns an Array of {@link ChatMember} objects.
|
||||
* @param chatId
|
||||
*/
|
||||
@NotTested
|
||||
public record GetChatAdministrators(@NotNull String chatId) implements TelegramApiMethod<ChatMember[]> {
|
||||
|
||||
public GetChatAdministrators(long chatId) {
|
||||
this(String.valueOf(chatId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return new FormBody.Builder().add("chat_id", chatId).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "getChatAdministrators";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<ChatMember[]> getResponseClass() {
|
||||
return ChatMember[].class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.objects.ChatMember;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record GetChatMember(@NotNull String chatId, long userId) implements TelegramApiMethod<ChatMember> {
|
||||
|
||||
public GetChatMember(long chatId, long userId) {
|
||||
this(String.valueOf(chatId), userId);
|
||||
}
|
||||
|
||||
public GetChatMember(String chatId, String userId) {
|
||||
this(chatId, Long.parseLong(userId));
|
||||
}
|
||||
|
||||
public GetChatMember(long chatId, String userId) {
|
||||
this(String.valueOf(chatId), userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return new FormBody.Builder().add("chat_id", chatId).add("user_id", String.valueOf(userId)).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "getChatMember";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<ChatMember> getResponseClass() {
|
||||
return ChatMember.class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.objects.TelegramFile;
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
public record GetFile(String fileId) implements TelegramApiMethod<TelegramFile> {
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return new FormBody.Builder().add("file_id", fileId).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "getFile";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<TelegramFile> getResponseClass() {
|
||||
return TelegramFile.class;
|
||||
}
|
||||
}
|
||||
22
core/src/main/java/hdvtdev/telegram/core/methods/GetMe.java
Normal file
22
core/src/main/java/hdvtdev/telegram/core/methods/GetMe.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.objects.User;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
public final class GetMe implements TelegramApiMethod<User.Bot> {
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "getMe";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<User.Bot> getResponseClass() {
|
||||
return User.Bot.class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.objects.bot.BotCommand;
|
||||
import hdvtdev.telegram.objects.bot.BotCommandScope;
|
||||
import hdvtdev.telegram.objects.bot.BotCommandScopeDefault;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
/**
|
||||
* Use this method to get the current list of the bot's commands for the given scope and user language.
|
||||
* Returns an Array of {@link BotCommand} objects. If commands aren't set, an empty list is returned.
|
||||
* @param scope Scope of users. Defaults to {@link BotCommandScopeDefault}.
|
||||
* @param languageCode A two-letter ISO 639-1 language code or an empty string
|
||||
* @see BotCommandScope
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Jsonable
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public record GetMyCommands(
|
||||
@JsonProperty("scope") BotCommandScope scope,
|
||||
@JsonProperty("language_code") String languageCode
|
||||
) implements TelegramApiMethod<BotCommand[]> {
|
||||
|
||||
public GetMyCommands() {
|
||||
this(null, null);
|
||||
}
|
||||
|
||||
public GetMyCommands(String languageCode) {
|
||||
this(null, languageCode);
|
||||
}
|
||||
|
||||
public GetMyCommands(BotCommandScope scope) {
|
||||
this(scope, null);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "getMyCommands";
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Class<BotCommand[]> getResponseClass() {
|
||||
return BotCommand[].class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record GetMyDescription(String languageCode) implements TelegramApiMethod<GetMyDescription.BotDescription> {
|
||||
|
||||
public GetMyDescription() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return languageCode == null ? null : new FormBody.Builder().add("language_code", languageCode).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "getMyDescription";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<BotDescription> getResponseClass() {
|
||||
return BotDescription.class;
|
||||
}
|
||||
|
||||
public record BotDescription(String description) {
|
||||
@NotNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return description.isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record GetMyName(String languageCode) implements TelegramApiMethod<GetMyName.BotName> {
|
||||
|
||||
public GetMyName() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return this.languageCode == null ? null : new FormBody.Builder().add("language_code", this.languageCode).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "getMyName";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<BotName> getResponseClass() {
|
||||
return BotName.class;
|
||||
}
|
||||
|
||||
public record BotName(String name) {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
|
||||
import hdvtdev.telegram.objects.Update;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public record GetUpdates(
|
||||
Long offset,
|
||||
Integer limit,
|
||||
Integer timeout
|
||||
) implements TelegramApiMethod<Update[]> {
|
||||
|
||||
public GetUpdates() {
|
||||
this(null, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
ArrayList<String> params = new ArrayList<>(3);
|
||||
if (offset != null) params.add("offset=" + offset);
|
||||
if (limit != null) params.add("limit=" + limit);
|
||||
if (timeout != null) params.add("timeout=" + timeout);
|
||||
|
||||
if (params.isEmpty()) {
|
||||
return "getUpdates";
|
||||
} else {
|
||||
return "getUpdates?" + String.join("&", params);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Update[]> getResponseClass() {
|
||||
return Update[].class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.objects.ChatInviteLink;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Use this method to revoke an invite link created by the bot. If the primary link is revoked, a new link is automatically generated.
|
||||
* The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
|
||||
* Returns the revoked invite link as {@link ChatInviteLink} object.
|
||||
* @param chatId Unique identifier of the target chat or username of the target channel (in the format @channelusername)
|
||||
* @param link The invite link to revoke
|
||||
*/
|
||||
public record RevokeChatInviteLink(@NotNull String chatId, @NotNull String link) implements TelegramApiMethod<ChatInviteLink> {
|
||||
|
||||
public RevokeChatInviteLink(long chatId, @NotNull String link) {
|
||||
this(String.valueOf(chatId), link);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return new FormBody.Builder().add("chat_id", chatId).add("link", link).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "revokeChatInviteLink";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<ChatInviteLink> getResponseClass() {
|
||||
return ChatInviteLink.class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public final class SendChatAction implements TelegramApiMethod<Boolean> {
|
||||
|
||||
private String businessConnectionId;
|
||||
private final String chatId;
|
||||
private Long messageThreadId;
|
||||
private final ChatAction chatAction;
|
||||
|
||||
public SendChatAction(@Nullable String businessConnectionId, @NotNull String chatId, @Nullable Long messageThreadId, @NotNull ChatAction chatAction) {
|
||||
this.businessConnectionId = businessConnectionId;
|
||||
this.chatId = chatId;
|
||||
this.messageThreadId = messageThreadId;
|
||||
this.chatAction = chatAction;
|
||||
}
|
||||
|
||||
public SendChatAction(String chatId, ChatAction chatAction) {
|
||||
this(null, chatId, null, chatAction);
|
||||
}
|
||||
|
||||
public SendChatAction(long chatId, ChatAction chatAction) {
|
||||
this(String.valueOf(chatId), chatAction);
|
||||
}
|
||||
|
||||
private SendChatAction(Builder builder) {
|
||||
this(builder.businessConnectionId, builder.chatId, builder.messageThreadId, builder.chatAction);
|
||||
}
|
||||
|
||||
public void setBusinessConnectionId(String businessConnectionId) {
|
||||
this.businessConnectionId = businessConnectionId;
|
||||
}
|
||||
|
||||
public void setMessageThreadId(Long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
|
||||
FormBody.Builder builder = new FormBody.Builder().add("chat_id", chatId).add("action", chatAction.equals(ChatAction.UPLOAD_FILE) ? ChatAction.UPLOAD_DOCUMENT.name() : chatAction.name());
|
||||
|
||||
if (businessConnectionId != null) builder.add("business_connection_id", businessConnectionId);
|
||||
if (messageThreadId != null) builder.add("message_thread_id", String.valueOf(messageThreadId));
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "sendChatAction";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Boolean> getResponseClass() {
|
||||
return Boolean.class;
|
||||
}
|
||||
|
||||
public enum ChatAction {
|
||||
TYPING,
|
||||
UPLOAD_PHOTO,
|
||||
RECORD_VIDEO,
|
||||
UPLOAD_VIDEO,
|
||||
RECORD_VOICE,
|
||||
UPLOAD_VOICE,
|
||||
UPLOAD_DOCUMENT,
|
||||
UPLOAD_FILE,
|
||||
CHOOSE_STICKER,
|
||||
FIND_LOCATION,
|
||||
RECORD_VIDEO_NOTE,
|
||||
UPLOAD_VIDEO_NOTE
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private String businessConnectionId;
|
||||
private final String chatId;
|
||||
private Long messageThreadId;
|
||||
private final ChatAction chatAction;
|
||||
|
||||
public Builder(String chatId, ChatAction chatAction) {
|
||||
this.chatId = chatId;
|
||||
this.chatAction = chatAction;
|
||||
}
|
||||
|
||||
public Builder businessConnectionId(String businessConnectionId) {
|
||||
this.businessConnectionId = businessConnectionId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder messageThreadId(Long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SendChatAction build() {
|
||||
return new SendChatAction(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
133
core/src/main/java/hdvtdev/telegram/core/methods/SendDice.java
Normal file
133
core/src/main/java/hdvtdev/telegram/core/methods/SendDice.java
Normal file
@@ -0,0 +1,133 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.objects.Message;
|
||||
import hdvtdev.telegram.objects.ReplyMarkup;
|
||||
import hdvtdev.telegram.objects.ReplyParameters;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
@Jsonable
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public final class SendDice implements TelegramApiMethod<Message> {
|
||||
|
||||
@JsonProperty("chat_id")
|
||||
private final String chatId;
|
||||
@JsonProperty("business_connection_id")
|
||||
private String businessConnectionId;
|
||||
@JsonProperty("message_thread_id")
|
||||
private Long messageThreadId;
|
||||
@JsonProperty("emoji")
|
||||
private String emoji;
|
||||
@JsonProperty("disable_notification")
|
||||
private Boolean disableNotification;
|
||||
@JsonProperty("protect_content")
|
||||
private Boolean protectContent;
|
||||
@JsonProperty("allow_paid_broadcast")
|
||||
private Boolean allowPaidBroadcast;
|
||||
@JsonProperty("message_effect_id")
|
||||
private String messageEffectId;
|
||||
@JsonProperty("reply_parameters")
|
||||
private ReplyParameters replyParameters;
|
||||
@JsonProperty("reply_markup")
|
||||
private ReplyMarkup replyMarkup;
|
||||
|
||||
public SendDice(String chatId) {
|
||||
this.chatId = chatId;
|
||||
}
|
||||
|
||||
public SendDice(long chatId) {
|
||||
this(String.valueOf(chatId));
|
||||
}
|
||||
|
||||
public SendDice(String chatId, Emoji emoji) {
|
||||
this.emoji = emoji.getEmoji();
|
||||
this.chatId = chatId;
|
||||
}
|
||||
|
||||
public SendDice(long chatId, Emoji emoji) {
|
||||
this(String.valueOf(chatId), emoji);
|
||||
}
|
||||
|
||||
|
||||
public void setBusinessConnectionId(String businessConnectionId) {
|
||||
this.businessConnectionId = businessConnectionId;
|
||||
}
|
||||
|
||||
public void setMessageThreadId(Long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
}
|
||||
|
||||
public void setEmoji(Emoji emoji) {
|
||||
this.emoji = emoji.getEmoji();
|
||||
}
|
||||
|
||||
public void setDisableNotification(Boolean disableNotification) {
|
||||
this.disableNotification = disableNotification;
|
||||
}
|
||||
|
||||
public void setProtectContent(Boolean protectContent) {
|
||||
this.protectContent = protectContent;
|
||||
}
|
||||
|
||||
public void setAllowPaidBroadcast(Boolean allowPaidBroadcast) {
|
||||
this.allowPaidBroadcast = allowPaidBroadcast;
|
||||
}
|
||||
|
||||
public void setMessageEffectId(String messageEffectId) {
|
||||
this.messageEffectId = messageEffectId;
|
||||
}
|
||||
|
||||
public void setReplyParameters(ReplyParameters replyParameters) {
|
||||
this.replyParameters = replyParameters;
|
||||
}
|
||||
|
||||
public void setReplyMarkup(ReplyMarkup replyMarkup) {
|
||||
this.replyMarkup = replyMarkup;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "sendDice";
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Class<Message> getResponseClass() {
|
||||
return Message.class;
|
||||
}
|
||||
|
||||
public enum Emoji {
|
||||
DICE("🎲"),
|
||||
DART("🎯"),
|
||||
BASKETBALL("🏀"),
|
||||
FOOTBALL("⚽"),
|
||||
BOWLING("🎳"),
|
||||
SLOT_MACHINE("🎰");
|
||||
|
||||
private final String emoji;
|
||||
|
||||
Emoji(String emoji) {
|
||||
this.emoji = emoji;
|
||||
}
|
||||
|
||||
public String getEmoji() {
|
||||
return emoji;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.objects.*;
|
||||
import hdvtdev.telegram.util.ParseMode;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
@Jsonable
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public final class SendMessage implements TelegramApiMethod<Message> {
|
||||
|
||||
@JsonProperty("chat_id")
|
||||
private final String chatId;
|
||||
@JsonProperty("text")
|
||||
private final String text;
|
||||
@JsonProperty("business_connection_id")
|
||||
private String businessConnectionId;
|
||||
@JsonProperty("message_thread_id")
|
||||
private Long messageThreadId;
|
||||
@JsonProperty("parse_mode")
|
||||
private ParseMode parseMode;
|
||||
@JsonProperty("entities")
|
||||
private MessageEntity[] entities;
|
||||
@JsonProperty("link_preview_options")
|
||||
private LinkPreviewOptions linkPreviewOptions;
|
||||
@JsonProperty("disable_notification")
|
||||
private Boolean disableNotification;
|
||||
@JsonProperty("protect_content")
|
||||
private Boolean protectContent;
|
||||
@JsonProperty("allow_paid_broadcast")
|
||||
private Boolean allowPaidBroadcast;
|
||||
@JsonProperty("message_effect_id")
|
||||
private String messageEffectId;
|
||||
@JsonProperty("reply_parameters")
|
||||
private ReplyParameters replyParameters;
|
||||
@JsonProperty("reply_markup")
|
||||
private ReplyMarkup replyMarkup;
|
||||
|
||||
private SendMessage(Builder builder) {
|
||||
chatId = builder.chatId;
|
||||
text = builder.text;
|
||||
setBusinessConnectionId(builder.businessConnectionId);
|
||||
setMessageThreadId(builder.messageThreadId);
|
||||
setParseMode(builder.parseMode);
|
||||
setEntities(builder.entities);
|
||||
setLinkPreviewOptions(builder.linkPreviewOptions);
|
||||
setDisableNotification(builder.disableNotification);
|
||||
setProtectContent(builder.protectContent);
|
||||
setAllowPaidBroadcast(builder.allowPaidBroadcast);
|
||||
setMessageEffectId(builder.messageEffectId);
|
||||
setReplyParameters(builder.replyParameters);
|
||||
setReplyMarkup(builder.replyMarkup);
|
||||
}
|
||||
|
||||
public void setLinkPreviewOptions(LinkPreviewOptions linkPreviewOptions) {
|
||||
this.linkPreviewOptions = linkPreviewOptions;
|
||||
}
|
||||
|
||||
public void setBusinessConnectionId(String businessConnectionId) {
|
||||
this.businessConnectionId = businessConnectionId;
|
||||
}
|
||||
|
||||
public void setMessageThreadId(Long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
}
|
||||
|
||||
public void setParseMode(ParseMode parseMode) {
|
||||
this.parseMode = parseMode;
|
||||
}
|
||||
|
||||
public void setEntities(MessageEntity[] entities) {
|
||||
this.entities = entities;
|
||||
}
|
||||
|
||||
public void setDisableNotification(Boolean disableNotification) {
|
||||
this.disableNotification = disableNotification;
|
||||
}
|
||||
|
||||
public void setProtectContent(Boolean protectContent) {
|
||||
this.protectContent = protectContent;
|
||||
}
|
||||
|
||||
public void setAllowPaidBroadcast(Boolean allowPaidBroadcast) {
|
||||
this.allowPaidBroadcast = allowPaidBroadcast;
|
||||
}
|
||||
|
||||
public void setMessageEffectId(String messageEffectId) {
|
||||
this.messageEffectId = messageEffectId;
|
||||
}
|
||||
|
||||
public void setReplyParameters(ReplyParameters replyParameters) {
|
||||
this.replyParameters = replyParameters;
|
||||
}
|
||||
|
||||
public void setReplyToMessage(long messageId) {
|
||||
this.replyParameters = new ReplyParameters(messageId, chatId);
|
||||
}
|
||||
|
||||
public void setReplyMarkup(ReplyMarkup replyMarkup) {
|
||||
this.replyMarkup = replyMarkup;
|
||||
}
|
||||
|
||||
public SendMessage(String chatId, String text) {
|
||||
if (chatId.isEmpty() || text.isEmpty())
|
||||
throw new IllegalArgumentException("chatId or/and message (text) cannot be empty.");
|
||||
this.chatId = chatId;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public SendMessage(long chatIdAsLong, String text) {
|
||||
this(String.valueOf(chatIdAsLong), text);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "sendMessage";
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Class<Message> getResponseClass() {
|
||||
return Message.class;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private final String chatId;
|
||||
private final String text;
|
||||
private String businessConnectionId;
|
||||
private Long messageThreadId;
|
||||
private ParseMode parseMode;
|
||||
private MessageEntity[] entities;
|
||||
private LinkPreviewOptions linkPreviewOptions;
|
||||
private Boolean disableNotification;
|
||||
private Boolean protectContent;
|
||||
private Boolean allowPaidBroadcast;
|
||||
private String messageEffectId;
|
||||
private ReplyParameters replyParameters;
|
||||
private ReplyMarkup replyMarkup;
|
||||
|
||||
public Builder(long chatId, String text) {
|
||||
this(String.valueOf(chatId), text);
|
||||
}
|
||||
|
||||
public Builder(String chatId, String text) {
|
||||
this.chatId = chatId;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public Builder businessConnectionId(String val) {
|
||||
businessConnectionId = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder messageThreadId(Long val) {
|
||||
messageThreadId = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder parseMode(ParseMode val) {
|
||||
parseMode = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder entities(MessageEntity[] val) {
|
||||
entities = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder linkPreviewOptions(LinkPreviewOptions val) {
|
||||
linkPreviewOptions = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder disableNotification() {
|
||||
disableNotification = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder protectContent() {
|
||||
protectContent = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder allowPaidBroadcast() {
|
||||
allowPaidBroadcast = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder messageEffectId(String val) {
|
||||
messageEffectId = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder replyParameters(ReplyParameters val) {
|
||||
replyParameters = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder replyToMessage(long val) {
|
||||
replyParameters = new ReplyParameters(val, this.chatId);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder replyMarkup(ReplyMarkup val) {
|
||||
replyMarkup = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SendMessage build() {
|
||||
return new SendMessage(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.objects.ReactionType;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Jsonable
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class SetMessageReaction implements TelegramApiMethod<Boolean> {
|
||||
|
||||
@JsonProperty("chat_id")
|
||||
private final String chatId;
|
||||
@JsonProperty("message_id")
|
||||
private final long messageId;
|
||||
@JsonProperty("reaction")
|
||||
private List<ReactionType> reactions;
|
||||
@JsonProperty("is_big")
|
||||
private Boolean isBig;
|
||||
|
||||
public SetMessageReaction(String chatId, long messageId) {
|
||||
this.chatId = chatId;
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
public SetMessageReaction(long chatId, long messageId) {
|
||||
this.chatId = String.valueOf(chatId);
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
private SetMessageReaction(Builder builder) {
|
||||
chatId = builder.chatId;
|
||||
messageId = builder.messageId;
|
||||
setReactions(builder.reactions);
|
||||
isBig = builder.isBig;
|
||||
}
|
||||
|
||||
public void setReactions(List<ReactionType> reactions) {
|
||||
this.reactions = reactions;
|
||||
}
|
||||
|
||||
public void setBig(Boolean big) {
|
||||
isBig = big;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "setMessageReaction";
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Class<Boolean> getResponseClass() {
|
||||
return Boolean.class;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private final String chatId;
|
||||
private final long messageId;
|
||||
private List<ReactionType> reactions;
|
||||
private Boolean isBig;
|
||||
|
||||
public Builder(String chatId, long messageId) {
|
||||
this.chatId = chatId;
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
public Builder(long chatId, long messageId) {
|
||||
this.chatId = String.valueOf(chatId);
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
public Builder reactions(List<ReactionType> reactions) {
|
||||
this.reactions = reactions;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder isBig(Boolean isBig) {
|
||||
this.isBig = isBig;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SetMessageReaction build() {
|
||||
return new SetMessageReaction(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.objects.bot.BotCommand;
|
||||
import hdvtdev.telegram.objects.bot.BotCommandScope;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Jsonable
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public final class SetMyCommands implements TelegramApiMethod<Boolean> {
|
||||
|
||||
@JsonProperty("commands")
|
||||
private final List<BotCommand> commands;
|
||||
@JsonProperty("scope")
|
||||
private Object scope;
|
||||
@JsonProperty("language_code")
|
||||
private String languageCode;
|
||||
|
||||
public SetMyCommands(List<BotCommand> commands, Object scope, String languageCode) {
|
||||
this.commands = commands;
|
||||
this.scope = scope;
|
||||
this.languageCode = languageCode;
|
||||
}
|
||||
|
||||
public SetMyCommands(BotCommand... commands) {
|
||||
this.commands = List.of(commands);
|
||||
}
|
||||
|
||||
public SetMyCommands(List<BotCommand> commands) {
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
private SetMyCommands(Builder builder) {
|
||||
commands = builder.commands;
|
||||
setScope(builder.scope);
|
||||
setLanguageCode(builder.languageCode);
|
||||
}
|
||||
|
||||
public void setScope(Object scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
public void setLanguageCode(String languageCode) {
|
||||
this.languageCode = languageCode;
|
||||
}
|
||||
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "setMyCommands";
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Class<Boolean> getResponseClass() {
|
||||
return Boolean.class;
|
||||
}
|
||||
|
||||
|
||||
public static final class Builder {
|
||||
private final List<BotCommand> commands;
|
||||
private Object scope;
|
||||
private String languageCode;
|
||||
|
||||
public Builder(List<BotCommand> commands) {
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
public Builder(BotCommand... commands) {
|
||||
this.commands = List.of(commands);
|
||||
}
|
||||
|
||||
public Builder scope(BotCommandScope scope) {
|
||||
this.scope = scope;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder languageCode(String languageCode) {
|
||||
this.languageCode = languageCode;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SetMyCommands build() {
|
||||
return new SetMyCommands(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
/**
|
||||
* Use this method to change the bot's description, which is shown in the chat with the bot if the chat is empty.
|
||||
* Returns {@code true} on success.
|
||||
* @param description New bot description; 0-512 characters. Pass an empty string to remove the dedicated description for the given language.
|
||||
* @param languageCode A two-letter ISO 639-1 language code. If empty, the description will be applied to all users for whose language there is no dedicated description.
|
||||
*/
|
||||
public record SetMyDescription(String description, String languageCode) implements TelegramApiMethod<Boolean> {
|
||||
|
||||
public SetMyDescription() {
|
||||
this(null, null);
|
||||
}
|
||||
|
||||
public SetMyDescription(String description) {
|
||||
this(description, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
if (description == null) {
|
||||
return null;
|
||||
}
|
||||
FormBody.Builder builder = new FormBody.Builder().add("description", description);
|
||||
if (languageCode != null) builder.add("language_code", languageCode);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "setMyDescription";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Boolean> getResponseClass() {
|
||||
return Boolean.class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
public record SetMyName(String name, String languageCode) implements TelegramApiMethod<Boolean> {
|
||||
|
||||
public SetMyName(String name) {
|
||||
this(name, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
FormBody.Builder builder = new FormBody.Builder().add("name", this.name);
|
||||
if (languageCode != null) builder.add("language_code", this.languageCode);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "setMyName";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Boolean> getResponseClass() {
|
||||
return Boolean.class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
public interface TelegramApiMethod<T> {
|
||||
|
||||
RequestBody getBody();
|
||||
|
||||
String getMethodName();
|
||||
|
||||
Class<T> getResponseClass();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package hdvtdev.telegram.core.bot;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public final class TelegramApiMethodBody {
|
||||
|
||||
private final ArrayList<Element> elements;
|
||||
|
||||
public TelegramApiMethodBody(int size) {
|
||||
elements = new ArrayList<>(size);
|
||||
}
|
||||
|
||||
public TelegramApiMethodBody() {
|
||||
elements = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void add(String name, String value) {
|
||||
if (value != null) this.elements.add(new Element(name, value));
|
||||
}
|
||||
|
||||
public void forEach(Consumer<? super Element> action) {
|
||||
this.elements.forEach(action);
|
||||
}
|
||||
|
||||
public record Element(String name, String value) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package hdvtdev.telegram.core;
|
||||
|
||||
public enum ParseMode {
|
||||
MARKDOWN,
|
||||
MARKDOWNV2,
|
||||
HTML
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package hdvtdev.telegram.core;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
public class Util {
|
||||
|
||||
public static void pretty(Path filePath) {
|
||||
try {
|
||||
if (filePath.toString().contains("InlineKeyboard")) return;
|
||||
List<String> lines = Files.readAllLines(filePath);
|
||||
HashSet<String> linesSet = new HashSet<>(lines);
|
||||
ArrayList<String> res = new ArrayList<>(lines.size());
|
||||
|
||||
if (!linesSet.contains("import com.fasterxml.jackson.annotation.JsonProperty;"))
|
||||
lines.add(2, "import com.fasterxml.jackson.annotation.JsonProperty;");
|
||||
boolean inRecord = false;
|
||||
for (String line : lines) {
|
||||
if (line.contains("@JsonProperty\\(.*?\\)")) {
|
||||
res.add(line);
|
||||
continue;
|
||||
}
|
||||
if (!line.contains("@") && !line.contains("class") && !line.contains("=")) {
|
||||
if (line.contains("record")) {
|
||||
String bufferLine = line;
|
||||
if (bufferLine.replaceAll("[{}]", "").trim().endsWith(")")) {
|
||||
if (bufferLine.contains("()")) {
|
||||
res.add(line);
|
||||
continue;
|
||||
}
|
||||
bufferLine = bufferLine.split("\\(", 2)[1];
|
||||
bufferLine = bufferLine.split("\\)", 2)[0];
|
||||
|
||||
if (bufferLine.contains(",")) {
|
||||
for (String element : bufferLine.split(",")) {
|
||||
element = element.strip();
|
||||
String ann = String.format("@JsonProperty(\"%s\") %s", element.split(" ", 2)[1], element);
|
||||
line = line.replace(element, ann);
|
||||
}
|
||||
} else {
|
||||
String element = bufferLine.strip();
|
||||
if (element.isEmpty()) continue;
|
||||
String ann = String.format("@JsonProperty(\"%s\") %s", element.split(" ", 2)[1], element);
|
||||
line = line.replace(element, ann);
|
||||
}
|
||||
} else {
|
||||
inRecord = true;
|
||||
res.add(line);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (inRecord) {
|
||||
if (line.contains("{") && line.contains(")")) {
|
||||
inRecord = false;
|
||||
} else {
|
||||
if (line.isEmpty() || line.contains("}")) {
|
||||
res.add(line);
|
||||
continue;
|
||||
}
|
||||
String element = line.strip();
|
||||
if (element.isEmpty()) continue;
|
||||
String ann = String.format("@JsonProperty(\"%s\") %s", element.split(" ", 2)[1].replace(",", ""), element);
|
||||
line = line.replace(element, ann);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
res.add(line);
|
||||
}
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(filePath.toFile()));
|
||||
for (String s : res) {
|
||||
writer.write(s);
|
||||
writer.newLine();
|
||||
}
|
||||
writer.flush();
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void date() {
|
||||
LocalDate today = LocalDate.now();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE; // формат ГГГГ-ММ-ДД
|
||||
|
||||
String formattedDate = today.format(formatter);
|
||||
System.out.println(formattedDate);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
import hdvtdev.telegram.objects.Game;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
/**
|
||||
* Use this method to send answers to callback queries sent from inline keyboards.
|
||||
* The answer will be displayed to the user as a notification at the top of the chat screen or as an alert.
|
||||
* Alternatively, the user can be redirected to the specified {@link Game} URL.
|
||||
* For this option to work, you must first create a game for your bot via @BotFather and accept the terms. Otherwise, you may use links like t.me/your_bot?start=XXXX that open your bot with a parameter.
|
||||
* @apiNote On success, {@code Boolean == true} is returned.
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
@NotTested
|
||||
public class AnswerCallbackQuery implements TelegramApiMethod<Boolean> {
|
||||
|
||||
/**
|
||||
* Unique identifier for the query to be answered
|
||||
*/
|
||||
private final String callbackQueryId;
|
||||
/**
|
||||
* Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters
|
||||
*/
|
||||
private String text;
|
||||
/**
|
||||
* If True, an alert will be shown by the client instead of a notification at the top of the chat screen. Defaults to false.
|
||||
*/
|
||||
private Boolean showAlert;
|
||||
/**
|
||||
* URL that will be opened by the user's client.
|
||||
* If you have created a {@link Game} and accepted the conditions via @BotFather, specify the URL that opens your game.
|
||||
* Otherwise, you may use links like t.me/your_bot?start=XXXX that open your bot with a parameter.
|
||||
* @apiNote this will only work if the query comes from a callback_game button.
|
||||
*/
|
||||
private String url;
|
||||
/**
|
||||
* The maximum amount of time in seconds that the result of the callback query may be cached client-side.
|
||||
* Telegram apps will support caching starting in version 3.14. Defaults to 0.
|
||||
*/
|
||||
private Integer cacheTime;
|
||||
|
||||
public AnswerCallbackQuery(String callbackQueryId) {
|
||||
this.callbackQueryId = callbackQueryId;
|
||||
}
|
||||
|
||||
private AnswerCallbackQuery(Builder builder) {
|
||||
callbackQueryId = builder.callbackQueryId;
|
||||
text = builder.text;
|
||||
showAlert = builder.showAlert;
|
||||
url = builder.url;
|
||||
cacheTime = builder.cacheTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
FormBody.Builder builder = new FormBody.Builder().add("callback_query_id", this.callbackQueryId);
|
||||
if (text != null) builder.add("text", this.text);
|
||||
if (showAlert != null) builder.add("show_alert", String.valueOf(this.showAlert));
|
||||
if (url != null) builder.add("url", this.url);
|
||||
if (cacheTime != null) builder.add("cache_time", String.valueOf(this.cacheTime));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "answerCallbackQuery";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Boolean> getResponseClass() {
|
||||
return Boolean.class;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private final String callbackQueryId;
|
||||
private String text;
|
||||
private Boolean showAlert;
|
||||
private String url;
|
||||
private Integer cacheTime;
|
||||
|
||||
public Builder(String callbackQueryId) {
|
||||
this.callbackQueryId = callbackQueryId;
|
||||
}
|
||||
|
||||
public Builder text(String text) {
|
||||
this.text = text;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder showAlert(Boolean showAlert) {
|
||||
this.showAlert = showAlert;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder url(String url) {
|
||||
this.url = url;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder cacheTime(Integer cacheTime) {
|
||||
this.cacheTime = cacheTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AnswerCallbackQuery build() {
|
||||
return new AnswerCallbackQuery(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
import hdvtdev.telegram.objects.ChatAdministratorRights;
|
||||
import hdvtdev.telegram.objects.Chat;
|
||||
import hdvtdev.telegram.objects.User;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Use this method to approve a chat join request.
|
||||
* The bot must be an <u>administrator</u> in the chat for this to work and must have the {@link ChatAdministratorRights#canInviteUsers()} administrator right.
|
||||
* Returns True on success.
|
||||
* @param chatId Unique username of the target channel in the format @channelusername
|
||||
* @param userId Unique identifier of the target user
|
||||
* @see ChatAdministratorRights
|
||||
* @see Chat
|
||||
* @see Chat#id()
|
||||
* @since 0.1.0
|
||||
*/
|
||||
@NotTested
|
||||
public record ApproveChatJoinRequest(@NotNull String chatId, long userId) implements TelegramApiMethod<Boolean> {
|
||||
|
||||
/**
|
||||
* @param chatId Unique identifier for the target chat
|
||||
* @param userId Unique identifier of the target user
|
||||
* @see User#id()
|
||||
* @see Chat#id()
|
||||
*/
|
||||
public ApproveChatJoinRequest(long chatId, long userId) {
|
||||
this(String.valueOf(chatId), userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return new FormBody.Builder().add("chat_id", chatId).add("user_id", String.valueOf(userId)).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "approveChatJoinRequest";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Boolean> getResponseClass() {
|
||||
return Boolean.class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
import hdvtdev.telegram.objects.ChatAdministratorRights;
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
/**
|
||||
* Use this method to ban a user in a group, a supergroup or a channel.
|
||||
* In the case of supergroups and channels, the user will not be able to return
|
||||
* to the chat on their own using invite links, etc., unless unbanned first.
|
||||
* The bot must be an administrator in the chat for this to work and must have
|
||||
* the appropriate administrator rights: {@link ChatAdministratorRights#canRestrictMembers()}. Returns True on success.
|
||||
* @see ChatAdministratorRights
|
||||
* @since 0.1.1
|
||||
*/
|
||||
@NotTested
|
||||
public final class BanChatMember implements TelegramApiMethod<Boolean> {
|
||||
|
||||
/**
|
||||
* Unique identifier for the target group or username of the target supergroup or channel (in the format @channelusername)
|
||||
*/
|
||||
private final String chatId;
|
||||
/**
|
||||
* Unique identifier of the target user
|
||||
*/
|
||||
private final long userId;
|
||||
/**
|
||||
* 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.
|
||||
* Applied for supergroups and channels only.
|
||||
*/
|
||||
private Long untilDate;
|
||||
/**
|
||||
* Pass true to delete all messages from the chat for the user that is being removed.
|
||||
* If false, the user will be able to see messages in the group that were sent before the user was removed.
|
||||
* Always True for supergroups and channels.
|
||||
*/
|
||||
private Boolean revokeMessages;
|
||||
|
||||
public BanChatMember(String chatId, long userId) {
|
||||
this.chatId = chatId;
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public BanChatMember(long chatId, long userId) {
|
||||
this.chatId = String.valueOf(chatId);
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
private BanChatMember(Builder builder) {
|
||||
chatId = builder.chatId;
|
||||
userId = builder.userId;
|
||||
setUntilDate(builder.untilDate);
|
||||
setRevokeMessages(builder.revokeMessages);
|
||||
}
|
||||
|
||||
public void setUntilDate(Long untilDate) {
|
||||
this.untilDate = untilDate;
|
||||
}
|
||||
|
||||
public void setRevokeMessages(Boolean revokeMessages) {
|
||||
this.revokeMessages = revokeMessages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
FormBody.Builder builder = new FormBody.Builder().add("chat_id", this.chatId).add("user_id", String.valueOf(userId));
|
||||
if (untilDate != null) builder.add("until_date", String.valueOf(untilDate));
|
||||
if (revokeMessages != null) builder.add("revoke_messages", String.valueOf(revokeMessages));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "banChatMember";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Boolean> getResponseClass() {
|
||||
return Boolean.class;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private final String chatId;
|
||||
private final long userId;
|
||||
private Long untilDate;
|
||||
private Boolean revokeMessages;
|
||||
|
||||
public Builder(String chatId, long userId) {
|
||||
this.chatId = chatId;
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public Builder untilDate(Long untilDate) {
|
||||
this.untilDate = untilDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder revokeMessages(Boolean revokeMessages) {
|
||||
this.revokeMessages = revokeMessages;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BanChatMember build() {
|
||||
return new BanChatMember(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Use this method to ban a channel chat in a supergroup or a channel.
|
||||
* Until the chat is unbanned, the owner of the banned chat won't be able to send messages on behalf of
|
||||
* their channels. The bot must be an administrator in the supergroup or channel for this to
|
||||
* work and must have the appropriate administrator rights. Returns True on success.
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@NotTested
|
||||
public record BanChatSenderChat(@NotNull String chatId, long userId) implements TelegramApiMethod<Boolean> {
|
||||
|
||||
public BanChatSenderChat(long chatId, long userId) {
|
||||
this(String.valueOf(chatId), userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return new FormBody.Builder().add("chat_id", chatId).add("user_id", String.valueOf(userId)).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "banChatSenderChat";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Boolean> getResponseClass() {
|
||||
return Boolean.class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record ChosenInlineResult(
|
||||
@JsonProperty("result_id") String resultId,
|
||||
@JsonProperty("from") User from,
|
||||
@JsonProperty("location") Location location,
|
||||
@JsonProperty("inline_message_id") String inlineMessageId,
|
||||
@JsonProperty("query") String query
|
||||
) {
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
import hdvtdev.telegram.objects.ChatAdministratorRights;
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
/**
|
||||
* Use this method to close an open topic in a forum supergroup chat.
|
||||
* The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights,
|
||||
* unless it is the creator of the topic. Returns {@code true} on success.
|
||||
* @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
|
||||
* @param messageThreadId Unique identifier for the target message thread of the forum topic
|
||||
* @see ChatAdministratorRights#canManageTopics()
|
||||
*/
|
||||
@NotTested
|
||||
public record CloseForumTopic(String chatId, long messageThreadId) implements TelegramApiMethod<Boolean> {
|
||||
|
||||
public CloseForumTopic(long chatId, long messageThreadId) {
|
||||
this(String.valueOf(chatId), messageThreadId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return new FormBody.Builder().add("chat_id", chatId).add("message_thread_id", String.valueOf(messageThreadId)).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "closeForumTopic";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Boolean> getResponseClass() {
|
||||
return Boolean.class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
import hdvtdev.telegram.objects.ChatAdministratorRights;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
/**
|
||||
* Use this method to close an open 'General' topic in a forum supergroup chat.
|
||||
* The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights.
|
||||
* Returns {@code true} on success.
|
||||
* @see ChatAdministratorRights#canManageTopics()
|
||||
* @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
|
||||
*/
|
||||
@NotTested
|
||||
public record CloseGeneralForumTopic(String chatId) implements TelegramApiMethod<Boolean> {
|
||||
|
||||
public CloseGeneralForumTopic(long chatId) {
|
||||
this(String.valueOf(chatId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return new FormBody.Builder().add("chat_id", chatId).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "closeGeneralForumTopic";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Boolean> getResponseClass() {
|
||||
return Boolean.class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record Contact(
|
||||
@JsonProperty("phone_number") String phoneNumber,
|
||||
@JsonProperty("first_name") String firstName,
|
||||
@JsonProperty("last_name") String lastName,
|
||||
@JsonProperty("user_id") long userId,
|
||||
@JsonProperty("vcard") String vcard
|
||||
) {
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
import hdvtdev.telegram.objects.MessageEntity;
|
||||
import hdvtdev.telegram.objects.Poll;
|
||||
import hdvtdev.telegram.objects.ReplyMarkup;
|
||||
import hdvtdev.telegram.objects.ReplyParameters;
|
||||
import hdvtdev.telegram.util.ParseMode;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Use this method to copy messages of any kind.
|
||||
* Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied.
|
||||
* A quiz {@link Poll} can be copied only if the value of the field correct_option_id is known to the bot.
|
||||
* The method is analogous to the method {@link ForwardMessage}, but the copied message doesn't have a link to the original message.
|
||||
* Returns the messageId as {@link Long} of the sent message on success.
|
||||
* @see Poll#correctOptionId()
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@NotTested
|
||||
@Jsonable
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public final class CopyMessage implements TelegramApiMethod<Long> {
|
||||
|
||||
@JsonProperty("chat_id")
|
||||
private final String chatId;
|
||||
@JsonProperty("message_thread_id")
|
||||
private Long messageThreadId;
|
||||
@JsonProperty("from_chat_id")
|
||||
private final String fromChatId;
|
||||
@JsonProperty("message_id")
|
||||
private final long messageId;
|
||||
@JsonProperty("video_start_timestamp")
|
||||
private long videoStartTimestamp;
|
||||
@JsonProperty("caption")
|
||||
private String caption;
|
||||
@JsonProperty("parse_mode")
|
||||
private ParseMode parseMode;
|
||||
@JsonProperty("caption_entities")
|
||||
private List<MessageEntity> captionEntities;
|
||||
@JsonProperty("show_caption_above_media")
|
||||
private Boolean showCaptionAboveMedia;
|
||||
@JsonProperty("disable_notification")
|
||||
private Boolean disableNotification;
|
||||
@JsonProperty("protect_content")
|
||||
private Boolean protectContent;
|
||||
@JsonProperty("allow_paid_broadcast")
|
||||
private Boolean allowPaidBroadcast;
|
||||
@JsonProperty("reply_parameters")
|
||||
private ReplyParameters replyParameters;
|
||||
@JsonProperty("reply_markup")
|
||||
private ReplyMarkup replyMarkup;
|
||||
|
||||
public CopyMessage(String chatId, String fromChatId, long messageId) {
|
||||
this.chatId = chatId;
|
||||
this.fromChatId = fromChatId;
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
public CopyMessage(long chatId, String fromChatId, long messageId) {
|
||||
this(String.valueOf(chatId), fromChatId, messageId);
|
||||
}
|
||||
|
||||
public CopyMessage(long chatId, long fromChatId, long messageId) {
|
||||
this(String.valueOf(chatId), String.valueOf(fromChatId), messageId);
|
||||
}
|
||||
|
||||
public CopyMessage(String chatId, long fromChatId, long messageId) {
|
||||
this(chatId, String.valueOf(fromChatId), messageId);
|
||||
}
|
||||
|
||||
private CopyMessage(Builder builder) {
|
||||
chatId = builder.chatId;
|
||||
setMessageThreadId(builder.messageThreadId);
|
||||
fromChatId = builder.fromChatId;
|
||||
messageId = builder.messageId;
|
||||
setVideoStartTimestamp(builder.videoStartTimestamp);
|
||||
setCaption(builder.caption);
|
||||
setParseMode(builder.parseMode);
|
||||
setCaptionEntities(builder.captionEntities);
|
||||
setShowCaptionAboveMedia(builder.showCaptionAboveMedia);
|
||||
setDisableNotification(builder.disableNotification);
|
||||
setProtectContent(builder.protectContent);
|
||||
setAllowPaidBroadcast(builder.allowPaidBroadcast);
|
||||
setReplyParameters(builder.replyParameters);
|
||||
setReplyMarkup(builder.replyMarkup);
|
||||
}
|
||||
|
||||
public void setMessageThreadId(Long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
}
|
||||
|
||||
public void setVideoStartTimestamp(long videoStartTimestamp) {
|
||||
this.videoStartTimestamp = videoStartTimestamp;
|
||||
}
|
||||
|
||||
public void setCaption(String caption) {
|
||||
this.caption = caption;
|
||||
}
|
||||
|
||||
public void setParseMode(ParseMode parseMode) {
|
||||
this.parseMode = parseMode;
|
||||
}
|
||||
|
||||
public void setCaptionEntities(List<MessageEntity> captionEntities) {
|
||||
this.captionEntities = captionEntities;
|
||||
}
|
||||
|
||||
public void setShowCaptionAboveMedia(Boolean showCaptionAboveMedia) {
|
||||
this.showCaptionAboveMedia = showCaptionAboveMedia;
|
||||
}
|
||||
|
||||
public void setDisableNotification(Boolean disableNotification) {
|
||||
this.disableNotification = disableNotification;
|
||||
}
|
||||
|
||||
public void setProtectContent(Boolean protectContent) {
|
||||
this.protectContent = protectContent;
|
||||
}
|
||||
|
||||
public void setAllowPaidBroadcast(Boolean allowPaidBroadcast) {
|
||||
this.allowPaidBroadcast = allowPaidBroadcast;
|
||||
}
|
||||
|
||||
public void setReplyParameters(ReplyParameters replyParameters) {
|
||||
this.replyParameters = replyParameters;
|
||||
}
|
||||
|
||||
public void setReplyMarkup(ReplyMarkup replyMarkup) {
|
||||
this.replyMarkup = replyMarkup;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "copyMessage";
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Class<Long> getResponseClass() {
|
||||
return Long.class;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private final String chatId;
|
||||
private Long messageThreadId;
|
||||
private final String fromChatId;
|
||||
private final long messageId;
|
||||
private long videoStartTimestamp;
|
||||
private String caption;
|
||||
private ParseMode parseMode;
|
||||
private List<MessageEntity> captionEntities;
|
||||
private Boolean showCaptionAboveMedia;
|
||||
private Boolean disableNotification;
|
||||
private Boolean protectContent;
|
||||
private Boolean allowPaidBroadcast;
|
||||
private ReplyParameters replyParameters;
|
||||
private ReplyMarkup replyMarkup;
|
||||
|
||||
public Builder(String chatId, String fromChatId, long messageId) {
|
||||
this.chatId = chatId;
|
||||
this.fromChatId = fromChatId;
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
public Builder(long chatId, String fromChatId, long messageId) {
|
||||
this(String.valueOf(chatId), fromChatId, messageId);
|
||||
}
|
||||
|
||||
public Builder messageThreadId(Long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder videoStartTimestamp(long videoStartTimestamp) {
|
||||
this.videoStartTimestamp = videoStartTimestamp;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder caption(String caption) {
|
||||
this.caption = caption;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder parseMode(ParseMode parseMode) {
|
||||
this.parseMode = parseMode;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder captionEntities(List<MessageEntity> captionEntities) {
|
||||
this.captionEntities = captionEntities;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder showCaptionAboveMedia(Boolean showCaptionAboveMedia) {
|
||||
this.showCaptionAboveMedia = showCaptionAboveMedia;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder disableNotification(Boolean disableNotification) {
|
||||
this.disableNotification = disableNotification;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder protectContent(Boolean protectContent) {
|
||||
this.protectContent = protectContent;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder allowPaidBroadcast(Boolean allowPaidBroadcast) {
|
||||
this.allowPaidBroadcast = allowPaidBroadcast;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder replyParameters(ReplyParameters replyParameters) {
|
||||
this.replyParameters = replyParameters;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder replyMarkup(ReplyMarkup replyMarkup) {
|
||||
this.replyMarkup = replyMarkup;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CopyMessage build() {
|
||||
return new CopyMessage(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.objects.Poll;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Use this method to copy messages of any kind.
|
||||
* If some of the specified messages can't be found or copied, they are skipped.
|
||||
* Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied.
|
||||
* A quiz {@link Poll} can be copied only if the value of the field correct_option_id is known to the bot.
|
||||
* The method is analogous to the method {@link ForwardMessages}, but the copied messages don't have a link to the original message.
|
||||
* Album grouping is kept for copied messages.
|
||||
* On success, an array of MessageId as {@link Long}{@code []} of the sent messages is returned.
|
||||
* @see Poll#correctOptionId()
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Jsonable
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public final class CopyMessages implements TelegramApiMethod<Long[]> {
|
||||
|
||||
@JsonProperty("chat_id")
|
||||
private final String chatId;
|
||||
@JsonProperty("message_thread_id")
|
||||
private Long messageThreadId;
|
||||
@JsonProperty("from_chat_id")
|
||||
private final String fromChatId;
|
||||
@JsonProperty("message_id")
|
||||
private final List<Long> messageIds;
|
||||
@JsonProperty("disable_notification")
|
||||
private Boolean disableNotification;
|
||||
@JsonProperty("protect_content")
|
||||
private Boolean protectContent;
|
||||
@JsonProperty("remove_caption")
|
||||
private Boolean removeCaption;
|
||||
|
||||
/**
|
||||
* @param chatId Username of the target channel (in the format @channelusername)
|
||||
* @param fromChatId Channel username in the format @channelusername for the chat where the original messages were sent
|
||||
* @param messageIds List of 1-100 identifiers of messages in the chat to copy.
|
||||
*/
|
||||
public CopyMessages(String chatId, String fromChatId, List<Long> messageIds) {
|
||||
this.chatId = chatId;
|
||||
this.fromChatId = fromChatId;
|
||||
ArrayList<Long> sortedMessageIds = new ArrayList<>(messageIds.subList(0, Math.min(messageIds.size(), 100)));
|
||||
sortedMessageIds.sort(null);
|
||||
this.messageIds = sortedMessageIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param chatId Unique identifier for the target chat
|
||||
* @param fromChatId Channel username in the format @channelusername for the chat where the original messages were sent
|
||||
* @param messageIds List of 1-100 identifiers of messages in the chat to copy.
|
||||
*/
|
||||
public CopyMessages(long chatId, String fromChatId, List<Long> messageIds) {
|
||||
this(String.valueOf(chatId), fromChatId, messageIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param chatId Unique identifier for the target chat
|
||||
* @param fromChatId Unique identifier for the chat where the original messages were sent
|
||||
* @param messageIds List of 1-100 identifiers of messages in the chat to copy.
|
||||
*/
|
||||
public CopyMessages(long chatId, long fromChatId, List<Long> messageIds) {
|
||||
this(String.valueOf(chatId), String.valueOf(fromChatId), messageIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param chatId Channel username in the format @channelusername for the chat where the original messages were sent
|
||||
* @param fromChatId Unique identifier for the target chat
|
||||
* @param messageIds List of 1-100 identifiers of messages in the chat to copy.
|
||||
*/
|
||||
public CopyMessages(String chatId, long fromChatId, List<Long> messageIds) {
|
||||
this(chatId, String.valueOf(fromChatId), messageIds);
|
||||
}
|
||||
|
||||
private CopyMessages(Builder builder) {
|
||||
chatId = builder.chatId;
|
||||
setMessageThreadId(builder.messageThreadId);
|
||||
fromChatId = builder.fromChatId;
|
||||
messageIds = builder.messageIds;
|
||||
setDisableNotification(builder.disableNotification);
|
||||
setProtectContent(builder.protectContent);
|
||||
setRemoveCaption(builder.removeCaption);
|
||||
}
|
||||
|
||||
public void setMessageThreadId(Long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
}
|
||||
|
||||
public void setDisableNotification(Boolean disableNotification) {
|
||||
this.disableNotification = disableNotification;
|
||||
}
|
||||
|
||||
public void setProtectContent(Boolean protectContent) {
|
||||
this.protectContent = protectContent;
|
||||
}
|
||||
|
||||
public void setRemoveCaption(Boolean removeCaption) {
|
||||
this.removeCaption = removeCaption;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "copyMessages";
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Class<Long[]> getResponseClass() {
|
||||
return Long[].class;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private final String chatId;
|
||||
private Long messageThreadId;
|
||||
private final String fromChatId;
|
||||
private final List<Long> messageIds;
|
||||
private Boolean disableNotification;
|
||||
private Boolean protectContent;
|
||||
private Boolean removeCaption;
|
||||
|
||||
public Builder(String chatId, String fromChatId, List<Long> messageIds) {
|
||||
this.chatId = chatId;
|
||||
this.fromChatId = fromChatId;
|
||||
ArrayList<Long> sortedMessageIds = new ArrayList<>(messageIds.subList(0, Math.min(messageIds.size(), 100)));
|
||||
sortedMessageIds.sort(null);
|
||||
this.messageIds = sortedMessageIds;
|
||||
}
|
||||
public Builder(long chatId, String fromChatId, List<Long> messageIds) {
|
||||
this(String.valueOf(chatId), fromChatId, messageIds);
|
||||
}
|
||||
|
||||
public Builder(long chatId, long fromChatId, List<Long> messageIds) {
|
||||
this(String.valueOf(chatId), String.valueOf(fromChatId), messageIds);
|
||||
}
|
||||
|
||||
public Builder(String chatId, long fromChatId, List<Long> messageIds) {
|
||||
this(chatId, String.valueOf(fromChatId), messageIds);
|
||||
}
|
||||
|
||||
public Builder messageThreadId(Long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder disableNotification(Boolean disableNotification) {
|
||||
this.disableNotification = disableNotification;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder protectContent(Boolean protectContent) {
|
||||
this.protectContent = protectContent;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder removeCaption(Boolean removeCaption) {
|
||||
this.removeCaption = removeCaption;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CopyMessages build() {
|
||||
return new CopyMessages(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.objects.ChatAdministratorRights;
|
||||
import hdvtdev.telegram.objects.ChatInviteLink;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
/**
|
||||
* Use this method to create an additional invite link for a chat.
|
||||
* The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
|
||||
* The link can be revoked using the method {@link RevokeChatInviteLink}. Returns the new invite link as {@link ChatInviteLink} object.
|
||||
* @see ChatAdministratorRights#canInviteUsers()
|
||||
*/
|
||||
public final class CreateChatInviteLink implements TelegramApiMethod<ChatInviteLink> {
|
||||
|
||||
private final String chatId;
|
||||
private String name;
|
||||
private Long expireDate;
|
||||
private Integer memberLimit;
|
||||
private Boolean createsJoinRequest;
|
||||
|
||||
public CreateChatInviteLink(String chatId) {
|
||||
this.chatId = chatId;
|
||||
}
|
||||
|
||||
public CreateChatInviteLink(long chatId) {
|
||||
this(String.valueOf(chatId));
|
||||
}
|
||||
|
||||
private CreateChatInviteLink(Builder builder) {
|
||||
chatId = builder.chatId;
|
||||
setName(builder.name);
|
||||
setExpireDate(builder.expireDate);
|
||||
setMemberLimit(builder.memberLimit);
|
||||
setCreatesJoinRequest(builder.createsJoinRequest);
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setExpireDate(Long expireDate) {
|
||||
this.expireDate = expireDate;
|
||||
}
|
||||
|
||||
public void setMemberLimit(Integer memberLimit) {
|
||||
this.memberLimit = memberLimit;
|
||||
}
|
||||
|
||||
public void setCreatesJoinRequest(Boolean createsJoinRequest) {
|
||||
this.createsJoinRequest = createsJoinRequest;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
FormBody.Builder builder = new FormBody.Builder().add("chat_id", chatId);
|
||||
if (expireDate != null) builder.add("expire_date", String.valueOf(expireDate));
|
||||
if (memberLimit != null) builder.add("member_limit", String.valueOf(memberLimit));
|
||||
if (createsJoinRequest != null) builder.add("creates_join_request", String.valueOf(createsJoinRequest));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "createChatInviteLink";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<ChatInviteLink> getResponseClass() {
|
||||
return ChatInviteLink.class;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private final String chatId;
|
||||
private String name;
|
||||
private Long expireDate;
|
||||
private Integer memberLimit;
|
||||
private Boolean createsJoinRequest;
|
||||
|
||||
public Builder(String chatId) {
|
||||
this.chatId = chatId;
|
||||
}
|
||||
|
||||
public Builder(long chatId) {
|
||||
this(String.valueOf(chatId));
|
||||
}
|
||||
|
||||
public Builder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder expireDate(Long expireDate) {
|
||||
this.expireDate = expireDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder memberLimit(Integer memberLimit) {
|
||||
this.memberLimit = memberLimit;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder createsJoinRequest(Boolean createsJoinRequest) {
|
||||
this.createsJoinRequest = createsJoinRequest;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CreateChatInviteLink build() {
|
||||
return new CreateChatInviteLink(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
13
core/src/main/java/hdvtdev/telegram/core/objects/Dice.java
Normal file
13
core/src/main/java/hdvtdev/telegram/core/objects/Dice.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record Dice(
|
||||
@JsonProperty("emoji") String emoji,
|
||||
@JsonProperty("value") int value
|
||||
) {
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.objects.Message;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
/**
|
||||
* Use this method to forward messages of any kind.
|
||||
* Service messages and messages with protected content can't be forwarded.
|
||||
* On success, the sent {@link Message} is returned.
|
||||
*/
|
||||
@Jsonable
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public final class ForwardMessage implements TelegramApiMethod<Message> {
|
||||
|
||||
@JsonProperty("chat_id")
|
||||
private final String chatId;
|
||||
@JsonProperty("message_thread_id")
|
||||
private Long messageThreadId;
|
||||
@JsonProperty("from_chat_id")
|
||||
private final String fromChatId;
|
||||
@JsonProperty("message_id")
|
||||
private final long messageId;
|
||||
@JsonProperty("disable_notification")
|
||||
private Boolean disableNotification;
|
||||
@JsonProperty("protect_content")
|
||||
private Boolean protectContent;
|
||||
@JsonProperty("video_start_timestamp")
|
||||
private long videoStartTimestamp;
|
||||
|
||||
public ForwardMessage(String chatId, String fromChatId, long messageId) {
|
||||
this.chatId = chatId;
|
||||
this.fromChatId = fromChatId;
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
public ForwardMessage(long chatId, String fromChatId, long messageId) {
|
||||
this(String.valueOf(chatId), fromChatId, messageId);
|
||||
}
|
||||
|
||||
public ForwardMessage(long chatId, long fromChatId, long messageId) {
|
||||
this(String.valueOf(chatId), String.valueOf(fromChatId), messageId);
|
||||
}
|
||||
|
||||
private ForwardMessage(Builder builder) {
|
||||
chatId = builder.chatId;
|
||||
setMessageThreadId(builder.messageThreadId);
|
||||
fromChatId = builder.fromChatId;
|
||||
messageId = builder.messageId;
|
||||
setDisableNotification(builder.disableNotification);
|
||||
setProtectContent(builder.protectContent);
|
||||
setVideoStartTimestamp(builder.videoStartTimestamp);
|
||||
}
|
||||
|
||||
public void setMessageThreadId(Long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
}
|
||||
|
||||
public void setDisableNotification(Boolean disableNotification) {
|
||||
this.disableNotification = disableNotification;
|
||||
}
|
||||
|
||||
public void setProtectContent(Boolean protectContent) {
|
||||
this.protectContent = protectContent;
|
||||
}
|
||||
|
||||
public void setVideoStartTimestamp(long videoStartTimestamp) {
|
||||
this.videoStartTimestamp = videoStartTimestamp;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "forwardMessage";
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Class<Message> getResponseClass() {
|
||||
return Message.class;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private final String chatId;
|
||||
private Long messageThreadId;
|
||||
private final String fromChatId;
|
||||
private final long messageId;
|
||||
private Boolean disableNotification;
|
||||
private Boolean protectContent;
|
||||
private long videoStartTimestamp;
|
||||
|
||||
public Builder(String chatId, String fromChatId, long messageId) {
|
||||
this.chatId = chatId;
|
||||
this.fromChatId = fromChatId;
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
public Builder messageThreadId(Long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder disableNotification(Boolean disableNotification) {
|
||||
this.disableNotification = disableNotification;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder protectContent(Boolean protectContent) {
|
||||
this.protectContent = protectContent;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder videoStartTimestamp(long videoStartTimestamp) {
|
||||
this.videoStartTimestamp = videoStartTimestamp;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ForwardMessage build() {
|
||||
return new ForwardMessage(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import hdvtdev.telegram.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
import hdvtdev.telegram.objects.Message;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Use this method to forward multiple messages of any kind. If some of the specified messages can't be found or forwarded, they are skipped.
|
||||
* Service messages and messages with protected content can't be forwarded. Album grouping is kept for forwarded messages.
|
||||
* On success, an array of MessageId as {@link Long} of the sent messages is returned.
|
||||
* @see Message#hasProtectedContent()
|
||||
*/
|
||||
@Jsonable
|
||||
@NotTested
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public final class ForwardMessages implements TelegramApiMethod<Long[]> {
|
||||
|
||||
@JsonProperty("chat_id")
|
||||
private final String chatId;
|
||||
@JsonProperty("message_thread_id")
|
||||
private Long messageThreadId;
|
||||
@JsonProperty("from_chat_id")
|
||||
private final String fromChatId;
|
||||
@JsonProperty("message_id")
|
||||
private final List<Long> messageIds;
|
||||
@JsonProperty("disable_notification")
|
||||
private Boolean disableNotification;
|
||||
@JsonProperty("protect_content")
|
||||
private Boolean protectContent;
|
||||
|
||||
public ForwardMessages(String chatId, String fromChatId, List<Long> messageIds) {
|
||||
ArrayList<Long> sortedMessageIds = new ArrayList<>(messageIds.size() > 100 ? messageIds.subList(0, 100) : messageIds);
|
||||
sortedMessageIds.sort(null);
|
||||
this.chatId = chatId;
|
||||
this.fromChatId = fromChatId;
|
||||
this.messageIds = sortedMessageIds;
|
||||
}
|
||||
|
||||
public ForwardMessages(long chatId, String fromChatId, List<Long> messageIds) {
|
||||
this(String.valueOf(chatId), fromChatId, messageIds);
|
||||
}
|
||||
|
||||
public ForwardMessages(String chatId, long fromChatId, List<Long> messageIds) {
|
||||
this(chatId, String.valueOf(fromChatId), messageIds);
|
||||
}
|
||||
|
||||
public ForwardMessages(long chatId, long fromChatId, List<Long> messageIds) {
|
||||
this(String.valueOf(chatId), String.valueOf(fromChatId), messageIds);
|
||||
}
|
||||
|
||||
private ForwardMessages(Builder builder) {
|
||||
chatId = builder.chatId;
|
||||
messageThreadId = builder.messageThreadId;
|
||||
fromChatId = builder.fromChatId;
|
||||
messageIds = builder.messageIds;
|
||||
disableNotification = builder.disableNotification;
|
||||
protectContent = builder.protectContent;
|
||||
}
|
||||
|
||||
public void setMessageThreadId(long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
}
|
||||
|
||||
public void setDisableNotification(boolean disableNotification) {
|
||||
this.disableNotification = disableNotification;
|
||||
}
|
||||
|
||||
public void setProtectContent(boolean protectContent) {
|
||||
this.protectContent = protectContent;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "forwardMessages";
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Class<Long[]> getResponseClass() {
|
||||
return Long[].class;
|
||||
}
|
||||
|
||||
|
||||
public static final class Builder {
|
||||
private final String chatId;
|
||||
private Long messageThreadId;
|
||||
private final String fromChatId;
|
||||
private final List<Long> messageIds;
|
||||
private Boolean disableNotification;
|
||||
private Boolean protectContent;
|
||||
|
||||
public Builder(String chatId, String fromChatId, List<Long> messageIds) {
|
||||
ArrayList<Long> sortedMessageIds = new ArrayList<>(messageIds.size() > 100 ? messageIds.subList(0, 100) : messageIds);
|
||||
sortedMessageIds.sort(null);
|
||||
this.chatId = chatId;
|
||||
this.fromChatId = fromChatId;
|
||||
this.messageIds = sortedMessageIds;
|
||||
}
|
||||
|
||||
public Builder(long chatId, String fromChatId, List<Long> messageIds) {
|
||||
this(String.valueOf(chatId), fromChatId, messageIds);
|
||||
}
|
||||
|
||||
public Builder(String chatId, long fromChatId, List<Long> messageIds) {
|
||||
this(chatId, String.valueOf(fromChatId), messageIds);
|
||||
}
|
||||
|
||||
public Builder(long chatId, long fromChatId, List<Long> messageIds) {
|
||||
this(String.valueOf(chatId), String.valueOf(fromChatId), messageIds);
|
||||
}
|
||||
|
||||
public Builder messageThreadId(long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder disableNotification(boolean disableNotification) {
|
||||
this.disableNotification = disableNotification;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder protectContent(boolean protectContent) {
|
||||
this.protectContent = protectContent;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ForwardMessages build() {
|
||||
return new ForwardMessages(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
17
core/src/main/java/hdvtdev/telegram/core/objects/Game.java
Normal file
17
core/src/main/java/hdvtdev/telegram/core/objects/Game.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record Game(
|
||||
@JsonProperty("title") String title,
|
||||
@JsonProperty("description") String description,
|
||||
@JsonProperty("photo") PhotoSize[] photo,
|
||||
@JsonProperty("text") String text,
|
||||
@JsonProperty("text_entities") MessageEntity[] textEntities,
|
||||
@JsonProperty("animation") Animation animation
|
||||
) {
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
import hdvtdev.telegram.objects.ChatMember;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Use this method to get a list of administrators in a chat, which aren't bots. Returns an Array of {@link ChatMember} objects.
|
||||
* @param chatId
|
||||
*/
|
||||
@NotTested
|
||||
public record GetChatAdministrators(@NotNull String chatId) implements TelegramApiMethod<ChatMember[]> {
|
||||
|
||||
public GetChatAdministrators(long chatId) {
|
||||
this(String.valueOf(chatId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return new FormBody.Builder().add("chat_id", chatId).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "getChatAdministrators";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<ChatMember[]> getResponseClass() {
|
||||
return ChatMember[].class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.objects.ChatMember;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record GetChatMember(@NotNull String chatId, long userId) implements TelegramApiMethod<ChatMember> {
|
||||
|
||||
public GetChatMember(long chatId, long userId) {
|
||||
this(String.valueOf(chatId), userId);
|
||||
}
|
||||
|
||||
public GetChatMember(String chatId, String userId) {
|
||||
this(chatId, Long.parseLong(userId));
|
||||
}
|
||||
|
||||
public GetChatMember(long chatId, String userId) {
|
||||
this(String.valueOf(chatId), userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return new FormBody.Builder().add("chat_id", chatId).add("user_id", String.valueOf(userId)).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "getChatMember";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<ChatMember> getResponseClass() {
|
||||
return ChatMember.class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.objects.TelegramFile;
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
public record GetFile(String fileId) implements TelegramApiMethod<TelegramFile> {
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return new FormBody.Builder().add("file_id", fileId).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "getFile";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<TelegramFile> getResponseClass() {
|
||||
return TelegramFile.class;
|
||||
}
|
||||
}
|
||||
22
core/src/main/java/hdvtdev/telegram/core/objects/GetMe.java
Normal file
22
core/src/main/java/hdvtdev/telegram/core/objects/GetMe.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.objects.User;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
public final class GetMe implements TelegramApiMethod<User.Bot> {
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "getMe";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<User.Bot> getResponseClass() {
|
||||
return User.Bot.class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.objects.bot.BotCommand;
|
||||
import hdvtdev.telegram.objects.bot.BotCommandScope;
|
||||
import hdvtdev.telegram.objects.bot.BotCommandScopeDefault;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
/**
|
||||
* Use this method to get the current list of the bot's commands for the given scope and user language.
|
||||
* Returns an Array of {@link BotCommand} objects. If commands aren't set, an empty list is returned.
|
||||
* @param scope Scope of users. Defaults to {@link BotCommandScopeDefault}.
|
||||
* @param languageCode A two-letter ISO 639-1 language code or an empty string
|
||||
* @see BotCommandScope
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Jsonable
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public record GetMyCommands(
|
||||
@JsonProperty("scope") BotCommandScope scope,
|
||||
@JsonProperty("language_code") String languageCode
|
||||
) implements TelegramApiMethod<BotCommand[]> {
|
||||
|
||||
public GetMyCommands() {
|
||||
this(null, null);
|
||||
}
|
||||
|
||||
public GetMyCommands(String languageCode) {
|
||||
this(null, languageCode);
|
||||
}
|
||||
|
||||
public GetMyCommands(BotCommandScope scope) {
|
||||
this(scope, null);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "getMyCommands";
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Class<BotCommand[]> getResponseClass() {
|
||||
return BotCommand[].class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record GetMyDescription(String languageCode) implements TelegramApiMethod<GetMyDescription.BotDescription> {
|
||||
|
||||
public GetMyDescription() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return languageCode == null ? null : new FormBody.Builder().add("language_code", languageCode).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "getMyDescription";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<BotDescription> getResponseClass() {
|
||||
return BotDescription.class;
|
||||
}
|
||||
|
||||
public record BotDescription(String description) {
|
||||
@NotNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return description.isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record GetMyName(String languageCode) implements TelegramApiMethod<GetMyName.BotName> {
|
||||
|
||||
public GetMyName() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return this.languageCode == null ? null : new FormBody.Builder().add("language_code", this.languageCode).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "getMyName";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<BotName> getResponseClass() {
|
||||
return BotName.class;
|
||||
}
|
||||
|
||||
public record BotName(String name) {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
|
||||
import hdvtdev.telegram.objects.Update;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public record GetUpdates(
|
||||
Long offset,
|
||||
Integer limit,
|
||||
Integer timeout
|
||||
) implements TelegramApiMethod<Update[]> {
|
||||
|
||||
public GetUpdates() {
|
||||
this(null, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
ArrayList<String> params = new ArrayList<>(3);
|
||||
if (offset != null) params.add("offset=" + offset);
|
||||
if (limit != null) params.add("limit=" + limit);
|
||||
if (timeout != null) params.add("timeout=" + timeout);
|
||||
|
||||
if (params.isEmpty()) {
|
||||
return "getUpdates";
|
||||
} else {
|
||||
return "getUpdates?" + String.join("&", params);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Update[]> getResponseClass() {
|
||||
return Update[].class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record InlineQuery(
|
||||
@JsonProperty("id") String id,
|
||||
@JsonProperty("from") User from,
|
||||
@JsonProperty("query") String query,
|
||||
@JsonProperty("offset") String offset,
|
||||
@JsonProperty("chat_type") String chatType,
|
||||
@JsonProperty("location") Location location
|
||||
) {
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record Location(
|
||||
@JsonProperty("latitude") float latitude,
|
||||
@JsonProperty("longitude") float longitude,
|
||||
@JsonProperty("horizontal_accuracy") float horizontalAccuracy,
|
||||
@JsonProperty("live_period") int livePeriod,
|
||||
@JsonProperty("heading") int heading,
|
||||
@JsonProperty("proximity_alert_radius") int proximityAlertRadius
|
||||
) {
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record LoginUrl(
|
||||
@JsonProperty("url") String url,
|
||||
@JsonProperty("forward_text") String forwardText,
|
||||
@JsonProperty("bot_username") String botUsername,
|
||||
@JsonProperty("request_write_access") boolean requestWriteAccess
|
||||
) {
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record MaskPosition(
|
||||
@JsonProperty("point") String point,
|
||||
@JsonProperty("x_shift") float xShift,
|
||||
@JsonProperty("y_shift") float yShift,
|
||||
@JsonProperty("scale") float scale
|
||||
) {
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record ProximityAlertTriggered(
|
||||
@JsonProperty("traveler") User traveler,
|
||||
@JsonProperty("watcher") User watcher,
|
||||
@JsonProperty("distance") int distance
|
||||
) {
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record ReplyParameters(
|
||||
@JsonProperty("message_id") long messageId,
|
||||
@JsonProperty("chat_id") String chatId,
|
||||
@JsonProperty("allow_sending_without_reply") boolean allowSendingWithoutReply,
|
||||
@JsonProperty("quote") String quote,
|
||||
@JsonProperty("quote_parse_mode") String quoteParseMode,
|
||||
@JsonProperty("quote_entities") MessageEntity[] quoteEntities,
|
||||
@JsonProperty("quote_position") Integer quotePosition
|
||||
) {
|
||||
|
||||
public ReplyParameters(long messageId, String chatId) {
|
||||
this(messageId, chatId, false, null, null, null, null);
|
||||
}
|
||||
|
||||
public ReplyParameters(long messageId, long chatId) {
|
||||
this(messageId, String.valueOf(chatId));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.objects.ChatInviteLink;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Use this method to revoke an invite link created by the bot. If the primary link is revoked, a new link is automatically generated.
|
||||
* The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
|
||||
* Returns the revoked invite link as {@link ChatInviteLink} object.
|
||||
* @param chatId Unique identifier of the target chat or username of the target channel (in the format @channelusername)
|
||||
* @param link The invite link to revoke
|
||||
*/
|
||||
public record RevokeChatInviteLink(@NotNull String chatId, @NotNull String link) implements TelegramApiMethod<ChatInviteLink> {
|
||||
|
||||
public RevokeChatInviteLink(long chatId, @NotNull String link) {
|
||||
this(String.valueOf(chatId), link);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return new FormBody.Builder().add("chat_id", chatId).add("link", link).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "revokeChatInviteLink";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<ChatInviteLink> getResponseClass() {
|
||||
return ChatInviteLink.class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public final class SendChatAction implements TelegramApiMethod<Boolean> {
|
||||
|
||||
private String businessConnectionId;
|
||||
private final String chatId;
|
||||
private Long messageThreadId;
|
||||
private final ChatAction chatAction;
|
||||
|
||||
public SendChatAction(@Nullable String businessConnectionId, @NotNull String chatId, @Nullable Long messageThreadId, @NotNull ChatAction chatAction) {
|
||||
this.businessConnectionId = businessConnectionId;
|
||||
this.chatId = chatId;
|
||||
this.messageThreadId = messageThreadId;
|
||||
this.chatAction = chatAction;
|
||||
}
|
||||
|
||||
public SendChatAction(String chatId, ChatAction chatAction) {
|
||||
this(null, chatId, null, chatAction);
|
||||
}
|
||||
|
||||
public SendChatAction(long chatId, ChatAction chatAction) {
|
||||
this(String.valueOf(chatId), chatAction);
|
||||
}
|
||||
|
||||
private SendChatAction(Builder builder) {
|
||||
this(builder.businessConnectionId, builder.chatId, builder.messageThreadId, builder.chatAction);
|
||||
}
|
||||
|
||||
public void setBusinessConnectionId(String businessConnectionId) {
|
||||
this.businessConnectionId = businessConnectionId;
|
||||
}
|
||||
|
||||
public void setMessageThreadId(Long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
|
||||
FormBody.Builder builder = new FormBody.Builder().add("chat_id", chatId).add("action", chatAction.equals(ChatAction.UPLOAD_FILE) ? ChatAction.UPLOAD_DOCUMENT.name() : chatAction.name());
|
||||
|
||||
if (businessConnectionId != null) builder.add("business_connection_id", businessConnectionId);
|
||||
if (messageThreadId != null) builder.add("message_thread_id", String.valueOf(messageThreadId));
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "sendChatAction";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Boolean> getResponseClass() {
|
||||
return Boolean.class;
|
||||
}
|
||||
|
||||
public enum ChatAction {
|
||||
TYPING,
|
||||
UPLOAD_PHOTO,
|
||||
RECORD_VIDEO,
|
||||
UPLOAD_VIDEO,
|
||||
RECORD_VOICE,
|
||||
UPLOAD_VOICE,
|
||||
UPLOAD_DOCUMENT,
|
||||
UPLOAD_FILE,
|
||||
CHOOSE_STICKER,
|
||||
FIND_LOCATION,
|
||||
RECORD_VIDEO_NOTE,
|
||||
UPLOAD_VIDEO_NOTE
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private String businessConnectionId;
|
||||
private final String chatId;
|
||||
private Long messageThreadId;
|
||||
private final ChatAction chatAction;
|
||||
|
||||
public Builder(String chatId, ChatAction chatAction) {
|
||||
this.chatId = chatId;
|
||||
this.chatAction = chatAction;
|
||||
}
|
||||
|
||||
public Builder businessConnectionId(String businessConnectionId) {
|
||||
this.businessConnectionId = businessConnectionId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder messageThreadId(Long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SendChatAction build() {
|
||||
return new SendChatAction(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
133
core/src/main/java/hdvtdev/telegram/core/objects/SendDice.java
Normal file
133
core/src/main/java/hdvtdev/telegram/core/objects/SendDice.java
Normal file
@@ -0,0 +1,133 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.objects.Message;
|
||||
import hdvtdev.telegram.objects.ReplyMarkup;
|
||||
import hdvtdev.telegram.objects.ReplyParameters;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
@Jsonable
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public final class SendDice implements TelegramApiMethod<Message> {
|
||||
|
||||
@JsonProperty("chat_id")
|
||||
private final String chatId;
|
||||
@JsonProperty("business_connection_id")
|
||||
private String businessConnectionId;
|
||||
@JsonProperty("message_thread_id")
|
||||
private Long messageThreadId;
|
||||
@JsonProperty("emoji")
|
||||
private String emoji;
|
||||
@JsonProperty("disable_notification")
|
||||
private Boolean disableNotification;
|
||||
@JsonProperty("protect_content")
|
||||
private Boolean protectContent;
|
||||
@JsonProperty("allow_paid_broadcast")
|
||||
private Boolean allowPaidBroadcast;
|
||||
@JsonProperty("message_effect_id")
|
||||
private String messageEffectId;
|
||||
@JsonProperty("reply_parameters")
|
||||
private ReplyParameters replyParameters;
|
||||
@JsonProperty("reply_markup")
|
||||
private ReplyMarkup replyMarkup;
|
||||
|
||||
public SendDice(String chatId) {
|
||||
this.chatId = chatId;
|
||||
}
|
||||
|
||||
public SendDice(long chatId) {
|
||||
this(String.valueOf(chatId));
|
||||
}
|
||||
|
||||
public SendDice(String chatId, Emoji emoji) {
|
||||
this.emoji = emoji.getEmoji();
|
||||
this.chatId = chatId;
|
||||
}
|
||||
|
||||
public SendDice(long chatId, Emoji emoji) {
|
||||
this(String.valueOf(chatId), emoji);
|
||||
}
|
||||
|
||||
|
||||
public void setBusinessConnectionId(String businessConnectionId) {
|
||||
this.businessConnectionId = businessConnectionId;
|
||||
}
|
||||
|
||||
public void setMessageThreadId(Long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
}
|
||||
|
||||
public void setEmoji(Emoji emoji) {
|
||||
this.emoji = emoji.getEmoji();
|
||||
}
|
||||
|
||||
public void setDisableNotification(Boolean disableNotification) {
|
||||
this.disableNotification = disableNotification;
|
||||
}
|
||||
|
||||
public void setProtectContent(Boolean protectContent) {
|
||||
this.protectContent = protectContent;
|
||||
}
|
||||
|
||||
public void setAllowPaidBroadcast(Boolean allowPaidBroadcast) {
|
||||
this.allowPaidBroadcast = allowPaidBroadcast;
|
||||
}
|
||||
|
||||
public void setMessageEffectId(String messageEffectId) {
|
||||
this.messageEffectId = messageEffectId;
|
||||
}
|
||||
|
||||
public void setReplyParameters(ReplyParameters replyParameters) {
|
||||
this.replyParameters = replyParameters;
|
||||
}
|
||||
|
||||
public void setReplyMarkup(ReplyMarkup replyMarkup) {
|
||||
this.replyMarkup = replyMarkup;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "sendDice";
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Class<Message> getResponseClass() {
|
||||
return Message.class;
|
||||
}
|
||||
|
||||
public enum Emoji {
|
||||
DICE("🎲"),
|
||||
DART("🎯"),
|
||||
BASKETBALL("🏀"),
|
||||
FOOTBALL("⚽"),
|
||||
BOWLING("🎳"),
|
||||
SLOT_MACHINE("🎰");
|
||||
|
||||
private final String emoji;
|
||||
|
||||
Emoji(String emoji) {
|
||||
this.emoji = emoji;
|
||||
}
|
||||
|
||||
public String getEmoji() {
|
||||
return emoji;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.objects.*;
|
||||
import hdvtdev.telegram.util.ParseMode;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
@Jsonable
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public final class SendMessage implements TelegramApiMethod<Message> {
|
||||
|
||||
@JsonProperty("chat_id")
|
||||
private final String chatId;
|
||||
@JsonProperty("text")
|
||||
private final String text;
|
||||
@JsonProperty("business_connection_id")
|
||||
private String businessConnectionId;
|
||||
@JsonProperty("message_thread_id")
|
||||
private Long messageThreadId;
|
||||
@JsonProperty("parse_mode")
|
||||
private ParseMode parseMode;
|
||||
@JsonProperty("entities")
|
||||
private MessageEntity[] entities;
|
||||
@JsonProperty("link_preview_options")
|
||||
private LinkPreviewOptions linkPreviewOptions;
|
||||
@JsonProperty("disable_notification")
|
||||
private Boolean disableNotification;
|
||||
@JsonProperty("protect_content")
|
||||
private Boolean protectContent;
|
||||
@JsonProperty("allow_paid_broadcast")
|
||||
private Boolean allowPaidBroadcast;
|
||||
@JsonProperty("message_effect_id")
|
||||
private String messageEffectId;
|
||||
@JsonProperty("reply_parameters")
|
||||
private ReplyParameters replyParameters;
|
||||
@JsonProperty("reply_markup")
|
||||
private ReplyMarkup replyMarkup;
|
||||
|
||||
private SendMessage(Builder builder) {
|
||||
chatId = builder.chatId;
|
||||
text = builder.text;
|
||||
setBusinessConnectionId(builder.businessConnectionId);
|
||||
setMessageThreadId(builder.messageThreadId);
|
||||
setParseMode(builder.parseMode);
|
||||
setEntities(builder.entities);
|
||||
setLinkPreviewOptions(builder.linkPreviewOptions);
|
||||
setDisableNotification(builder.disableNotification);
|
||||
setProtectContent(builder.protectContent);
|
||||
setAllowPaidBroadcast(builder.allowPaidBroadcast);
|
||||
setMessageEffectId(builder.messageEffectId);
|
||||
setReplyParameters(builder.replyParameters);
|
||||
setReplyMarkup(builder.replyMarkup);
|
||||
}
|
||||
|
||||
public void setLinkPreviewOptions(LinkPreviewOptions linkPreviewOptions) {
|
||||
this.linkPreviewOptions = linkPreviewOptions;
|
||||
}
|
||||
|
||||
public void setBusinessConnectionId(String businessConnectionId) {
|
||||
this.businessConnectionId = businessConnectionId;
|
||||
}
|
||||
|
||||
public void setMessageThreadId(Long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
}
|
||||
|
||||
public void setParseMode(ParseMode parseMode) {
|
||||
this.parseMode = parseMode;
|
||||
}
|
||||
|
||||
public void setEntities(MessageEntity[] entities) {
|
||||
this.entities = entities;
|
||||
}
|
||||
|
||||
public void setDisableNotification(Boolean disableNotification) {
|
||||
this.disableNotification = disableNotification;
|
||||
}
|
||||
|
||||
public void setProtectContent(Boolean protectContent) {
|
||||
this.protectContent = protectContent;
|
||||
}
|
||||
|
||||
public void setAllowPaidBroadcast(Boolean allowPaidBroadcast) {
|
||||
this.allowPaidBroadcast = allowPaidBroadcast;
|
||||
}
|
||||
|
||||
public void setMessageEffectId(String messageEffectId) {
|
||||
this.messageEffectId = messageEffectId;
|
||||
}
|
||||
|
||||
public void setReplyParameters(ReplyParameters replyParameters) {
|
||||
this.replyParameters = replyParameters;
|
||||
}
|
||||
|
||||
public void setReplyToMessage(long messageId) {
|
||||
this.replyParameters = new ReplyParameters(messageId, chatId);
|
||||
}
|
||||
|
||||
public void setReplyMarkup(ReplyMarkup replyMarkup) {
|
||||
this.replyMarkup = replyMarkup;
|
||||
}
|
||||
|
||||
public SendMessage(String chatId, String text) {
|
||||
if (chatId.isEmpty() || text.isEmpty())
|
||||
throw new IllegalArgumentException("chatId or/and message (text) cannot be empty.");
|
||||
this.chatId = chatId;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public SendMessage(long chatIdAsLong, String text) {
|
||||
this(String.valueOf(chatIdAsLong), text);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "sendMessage";
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Class<Message> getResponseClass() {
|
||||
return Message.class;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private final String chatId;
|
||||
private final String text;
|
||||
private String businessConnectionId;
|
||||
private Long messageThreadId;
|
||||
private ParseMode parseMode;
|
||||
private MessageEntity[] entities;
|
||||
private LinkPreviewOptions linkPreviewOptions;
|
||||
private Boolean disableNotification;
|
||||
private Boolean protectContent;
|
||||
private Boolean allowPaidBroadcast;
|
||||
private String messageEffectId;
|
||||
private ReplyParameters replyParameters;
|
||||
private ReplyMarkup replyMarkup;
|
||||
|
||||
public Builder(long chatId, String text) {
|
||||
this(String.valueOf(chatId), text);
|
||||
}
|
||||
|
||||
public Builder(String chatId, String text) {
|
||||
this.chatId = chatId;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public Builder businessConnectionId(String val) {
|
||||
businessConnectionId = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder messageThreadId(Long val) {
|
||||
messageThreadId = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder parseMode(ParseMode val) {
|
||||
parseMode = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder entities(MessageEntity[] val) {
|
||||
entities = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder linkPreviewOptions(LinkPreviewOptions val) {
|
||||
linkPreviewOptions = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder disableNotification() {
|
||||
disableNotification = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder protectContent() {
|
||||
protectContent = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder allowPaidBroadcast() {
|
||||
allowPaidBroadcast = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder messageEffectId(String val) {
|
||||
messageEffectId = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder replyParameters(ReplyParameters val) {
|
||||
replyParameters = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder replyToMessage(long val) {
|
||||
replyParameters = new ReplyParameters(val, this.chatId);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder replyMarkup(ReplyMarkup val) {
|
||||
replyMarkup = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SendMessage build() {
|
||||
return new SendMessage(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.objects.ReactionType;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Jsonable
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class SetMessageReaction implements TelegramApiMethod<Boolean> {
|
||||
|
||||
@JsonProperty("chat_id")
|
||||
private final String chatId;
|
||||
@JsonProperty("message_id")
|
||||
private final long messageId;
|
||||
@JsonProperty("reaction")
|
||||
private List<ReactionType> reactions;
|
||||
@JsonProperty("is_big")
|
||||
private Boolean isBig;
|
||||
|
||||
public SetMessageReaction(String chatId, long messageId) {
|
||||
this.chatId = chatId;
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
public SetMessageReaction(long chatId, long messageId) {
|
||||
this.chatId = String.valueOf(chatId);
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
private SetMessageReaction(Builder builder) {
|
||||
chatId = builder.chatId;
|
||||
messageId = builder.messageId;
|
||||
setReactions(builder.reactions);
|
||||
isBig = builder.isBig;
|
||||
}
|
||||
|
||||
public void setReactions(List<ReactionType> reactions) {
|
||||
this.reactions = reactions;
|
||||
}
|
||||
|
||||
public void setBig(Boolean big) {
|
||||
isBig = big;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "setMessageReaction";
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Class<Boolean> getResponseClass() {
|
||||
return Boolean.class;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private final String chatId;
|
||||
private final long messageId;
|
||||
private List<ReactionType> reactions;
|
||||
private Boolean isBig;
|
||||
|
||||
public Builder(String chatId, long messageId) {
|
||||
this.chatId = chatId;
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
public Builder(long chatId, long messageId) {
|
||||
this.chatId = String.valueOf(chatId);
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
public Builder reactions(List<ReactionType> reactions) {
|
||||
this.reactions = reactions;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder isBig(Boolean isBig) {
|
||||
this.isBig = isBig;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SetMessageReaction build() {
|
||||
return new SetMessageReaction(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.objects.bot.BotCommand;
|
||||
import hdvtdev.telegram.objects.bot.BotCommandScope;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Jsonable
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public final class SetMyCommands implements TelegramApiMethod<Boolean> {
|
||||
|
||||
@JsonProperty("commands")
|
||||
private final List<BotCommand> commands;
|
||||
@JsonProperty("scope")
|
||||
private Object scope;
|
||||
@JsonProperty("language_code")
|
||||
private String languageCode;
|
||||
|
||||
public SetMyCommands(List<BotCommand> commands, Object scope, String languageCode) {
|
||||
this.commands = commands;
|
||||
this.scope = scope;
|
||||
this.languageCode = languageCode;
|
||||
}
|
||||
|
||||
public SetMyCommands(BotCommand... commands) {
|
||||
this.commands = List.of(commands);
|
||||
}
|
||||
|
||||
public SetMyCommands(List<BotCommand> commands) {
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
private SetMyCommands(Builder builder) {
|
||||
commands = builder.commands;
|
||||
setScope(builder.scope);
|
||||
setLanguageCode(builder.languageCode);
|
||||
}
|
||||
|
||||
public void setScope(Object scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
public void setLanguageCode(String languageCode) {
|
||||
this.languageCode = languageCode;
|
||||
}
|
||||
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "setMyCommands";
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Class<Boolean> getResponseClass() {
|
||||
return Boolean.class;
|
||||
}
|
||||
|
||||
|
||||
public static final class Builder {
|
||||
private final List<BotCommand> commands;
|
||||
private Object scope;
|
||||
private String languageCode;
|
||||
|
||||
public Builder(List<BotCommand> commands) {
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
public Builder(BotCommand... commands) {
|
||||
this.commands = List.of(commands);
|
||||
}
|
||||
|
||||
public Builder scope(BotCommandScope scope) {
|
||||
this.scope = scope;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder languageCode(String languageCode) {
|
||||
this.languageCode = languageCode;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SetMyCommands build() {
|
||||
return new SetMyCommands(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
/**
|
||||
* Use this method to change the bot's description, which is shown in the chat with the bot if the chat is empty.
|
||||
* Returns {@code true} on success.
|
||||
* @param description New bot description; 0-512 characters. Pass an empty string to remove the dedicated description for the given language.
|
||||
* @param languageCode A two-letter ISO 639-1 language code. If empty, the description will be applied to all users for whose language there is no dedicated description.
|
||||
*/
|
||||
public record SetMyDescription(String description, String languageCode) implements TelegramApiMethod<Boolean> {
|
||||
|
||||
public SetMyDescription() {
|
||||
this(null, null);
|
||||
}
|
||||
|
||||
public SetMyDescription(String description) {
|
||||
this(description, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
if (description == null) {
|
||||
return null;
|
||||
}
|
||||
FormBody.Builder builder = new FormBody.Builder().add("description", description);
|
||||
if (languageCode != null) builder.add("language_code", languageCode);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "setMyDescription";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Boolean> getResponseClass() {
|
||||
return Boolean.class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
public record SetMyName(String name, String languageCode) implements TelegramApiMethod<Boolean> {
|
||||
|
||||
public SetMyName(String name) {
|
||||
this(name, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
FormBody.Builder builder = new FormBody.Builder().add("name", this.name);
|
||||
if (languageCode != null) builder.add("language_code", this.languageCode);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "setMyName";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Boolean> getResponseClass() {
|
||||
return Boolean.class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record SharedUser(
|
||||
@JsonProperty("user_id") long userId,
|
||||
@JsonProperty("first_name") String firstName,
|
||||
@JsonProperty("last_name") String lastName,
|
||||
@JsonProperty("username") String username,
|
||||
@JsonProperty("photo") PhotoSize[] photo
|
||||
) {
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
public interface TelegramApiMethod<T> {
|
||||
|
||||
RequestBody getBody();
|
||||
|
||||
String getMethodName();
|
||||
|
||||
Class<T> getResponseClass();
|
||||
|
||||
}
|
||||
139
core/src/main/java/hdvtdev/telegram/core/objects/Update.java
Normal file
139
core/src/main/java/hdvtdev/telegram/core/objects/Update.java
Normal file
@@ -0,0 +1,139 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record Update(
|
||||
@JsonProperty("update_id") long updateId,
|
||||
@JsonProperty("message") Message message,
|
||||
@JsonProperty("edited_message") Message editedMessage,
|
||||
@JsonProperty("channel_post") Message channelPost,
|
||||
@JsonProperty("edited_channel_post") Message editedChannelPost,
|
||||
@JsonProperty("business_connection") BusinessConnection businessConnection,
|
||||
@JsonProperty("business_message") Message businessMessage,
|
||||
@JsonProperty("edited_business_message") Message editedBusinessMessage,
|
||||
@JsonProperty("deleted_business_messages") BusinessMessagesDeleted businessMessagesDeleted,
|
||||
@JsonProperty("message_reaction") MessageReactionUpdated messageReaction,
|
||||
@JsonProperty("message_reaction_count") MessageReactionCountUpdated messageReactionCount,
|
||||
@JsonProperty("inline_query") InlineQuery inlineQuery,
|
||||
@JsonProperty("chosen_inline_result") ChosenInlineResult chosenInlineResult,
|
||||
@JsonProperty("callback_query") CallbackQuery callbackQuery,
|
||||
@JsonProperty("shipping_query") ShippingQuery shippingQuery,
|
||||
@JsonProperty("pre_checkout_query") PreCheckoutQuery preCheckoutQuery,
|
||||
@JsonProperty("purchased_paid_media") PaidMediaPurchased paidMediaPurchased,
|
||||
@JsonProperty("poll") Poll poll,
|
||||
@JsonProperty("poll_answer") PollAnswer pollAnswer,
|
||||
@JsonProperty("my_chat_member") ChatMemberUpdated myChatMember,
|
||||
@JsonProperty("chat_member") ChatMemberUpdated chatMember,
|
||||
@JsonProperty("chat_join_request") ChatJoinRequest chatJoinRequest,
|
||||
@JsonProperty("chat_boost") ChatBoostUpdated chatBoost,
|
||||
@JsonProperty("removed_chat_boost") ChatBoostRemoved chatBoostRemoved
|
||||
) {
|
||||
|
||||
public boolean hasMessage() {
|
||||
return this.message != null;
|
||||
}
|
||||
|
||||
public boolean hasEditedMessage() {
|
||||
return this.editedMessage != null;
|
||||
}
|
||||
|
||||
public boolean hasChannelPost() {
|
||||
return this.channelPost != null;
|
||||
}
|
||||
|
||||
public boolean hasEditedChannelPost() {
|
||||
return this.editedChannelPost != null;
|
||||
}
|
||||
|
||||
public boolean hasBusinessConnection() {
|
||||
return this.businessConnection != null;
|
||||
}
|
||||
|
||||
public boolean hasBusinessMessage() {
|
||||
return this.businessMessage != null;
|
||||
}
|
||||
|
||||
public boolean hasEditedBusinessMessage() {
|
||||
return this.editedBusinessMessage != null;
|
||||
}
|
||||
|
||||
public boolean hasDeletedBusinessMessages() {
|
||||
return this.businessMessagesDeleted != null;
|
||||
}
|
||||
|
||||
public boolean hasMessageReaction() {
|
||||
return this.messageReaction != null;
|
||||
}
|
||||
|
||||
public boolean hasMessageReactionCount() {
|
||||
return this.messageReactionCount != null;
|
||||
}
|
||||
|
||||
public boolean hasInlineQuery() {
|
||||
return this.inlineQuery != null;
|
||||
}
|
||||
|
||||
public boolean hasChosenInlineResult() {
|
||||
return this.chosenInlineResult != null;
|
||||
}
|
||||
|
||||
public boolean hasCallbackQuery() {
|
||||
return this.callbackQuery != null;
|
||||
}
|
||||
|
||||
public boolean hasShippingQuery() {
|
||||
return this.shippingQuery != null;
|
||||
}
|
||||
|
||||
public boolean hasPreCheckoutQuery() {
|
||||
return this.preCheckoutQuery != null;
|
||||
}
|
||||
|
||||
public boolean hasPurchasedPaidMedia() {
|
||||
return this.paidMediaPurchased != null;
|
||||
}
|
||||
|
||||
public boolean hasPoll() {
|
||||
return this.poll != null;
|
||||
}
|
||||
|
||||
public boolean hasPollAnswer() {
|
||||
return this.pollAnswer != null;
|
||||
}
|
||||
|
||||
public boolean hasMyChatMember() {
|
||||
return this.myChatMember != null;
|
||||
}
|
||||
|
||||
public boolean hasChatMember() {
|
||||
return this.chatMember != null;
|
||||
}
|
||||
|
||||
public boolean hasChatJoinRequest() {
|
||||
return this.chatJoinRequest != null;
|
||||
}
|
||||
|
||||
public boolean hasChatBoost() {
|
||||
return this.chatBoost != null;
|
||||
}
|
||||
|
||||
public boolean hasRemovedChatBoost() {
|
||||
return this.chatBoostRemoved != null;
|
||||
}
|
||||
|
||||
public Optional<String> getAnyText() {
|
||||
if (hasMessage()) {
|
||||
if (message.hasText()) return Optional.of(message.text());
|
||||
if (message.hasCaption()) return Optional.of(message.caption());
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
62
core/src/main/java/hdvtdev/telegram/core/objects/User.java
Normal file
62
core/src/main/java/hdvtdev/telegram/core/objects/User.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record User(
|
||||
@JsonProperty("id") long id,
|
||||
@JsonProperty("is_bot") boolean isBot,
|
||||
@JsonProperty("first_name") String firstName,
|
||||
@JsonProperty("last_name") String lastName,
|
||||
@JsonProperty("username") String username,
|
||||
@JsonProperty("language_code") String languageCode,
|
||||
@JsonProperty("is_premium") boolean isPremium,
|
||||
@JsonProperty("added_to_attachment_menu") boolean addedToAttachmentMenu
|
||||
) {
|
||||
|
||||
public boolean hasLastName() {
|
||||
return this.lastName != null;
|
||||
}
|
||||
|
||||
public boolean hasUsername() {
|
||||
return this.username != null;
|
||||
}
|
||||
|
||||
public boolean hasLanguageCode() {
|
||||
return this.languageCode != null;
|
||||
}
|
||||
|
||||
public record Bot(
|
||||
@JsonProperty("id") long id,
|
||||
@JsonProperty("is_bot") Boolean isBot,
|
||||
@JsonProperty("first_name") String firstName,
|
||||
@JsonProperty("last_name") String lastName,
|
||||
@JsonProperty("username") String username,
|
||||
@JsonProperty("language_code") String languageCode,
|
||||
@JsonProperty("is_premium") boolean isPremium,
|
||||
@JsonProperty("added_to_attachment_menu") boolean addedToAttachmentMenu,
|
||||
@JsonProperty("can_join_groups") boolean canJoinGroups,
|
||||
@JsonProperty("can_read_all_group_messages") boolean canReadAllGroupMessages,
|
||||
@JsonProperty("supports_inline_queries") boolean supportsInlineQueries,
|
||||
@JsonProperty("can_connect_to_business") boolean canConnectToBusiness,
|
||||
@JsonProperty("has_main_web_app") boolean hasMainWebApp
|
||||
) {
|
||||
|
||||
public boolean hasLastName() {
|
||||
return this.lastName != null;
|
||||
}
|
||||
|
||||
public boolean hasUsername() {
|
||||
return this.username != null;
|
||||
}
|
||||
|
||||
public boolean hasLanguageCode() {
|
||||
return this.languageCode != null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record UsersShared(
|
||||
@JsonProperty("request_id") int requestId,
|
||||
@JsonProperty("users") SharedUser[] users
|
||||
) {
|
||||
}
|
||||
18
core/src/main/java/hdvtdev/telegram/core/objects/Venue.java
Normal file
18
core/src/main/java/hdvtdev/telegram/core/objects/Venue.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record Venue(
|
||||
@JsonProperty("location") Location location,
|
||||
@JsonProperty("title") String title,
|
||||
@JsonProperty("address") String address,
|
||||
@JsonProperty("foursquare_id") String foursquareId,
|
||||
@JsonProperty("foursquare_type") String foursquareType,
|
||||
@JsonProperty("google_place_id") String googlePlaceId,
|
||||
@JsonProperty("google_place_type") String googlePlaceType
|
||||
) {
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record WebAppData(String data, @JsonProperty("button_text") String buttonText) {
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record WebAppInfo(@JsonProperty("url") String url) {
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record WriteAccessAllowed(
|
||||
@JsonProperty("from_request") boolean fromRequest,
|
||||
@JsonProperty("web_app_name") String webAppName,
|
||||
@JsonProperty("from_attachment_menu") boolean fromAttachmentMenu
|
||||
) {
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
|
||||
@JsonTypeInfo(
|
||||
use = JsonTypeInfo.Id.NAME,
|
||||
include = JsonTypeInfo.As.EXISTING_PROPERTY,
|
||||
property = "type"
|
||||
)
|
||||
@JsonSubTypes({
|
||||
@JsonSubTypes.Type(value = BackgroundFillSolid.class, name = "solid"),
|
||||
@JsonSubTypes.Type(value = BackgroundFillGradient.class, name = "gradient"),
|
||||
@JsonSubTypes.Type(value = BackgroundFillFreeformGradient.class, name = "freeform_gradient")
|
||||
})
|
||||
public interface BackgroundFill {
|
||||
String type();
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package hdvtdev.telegram.core.objects.background;
|
||||
|
||||
public class BackgroundFillDeserializer {
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record BackgroundFillFreeformGradient(
|
||||
@JsonProperty("type") String type,
|
||||
@JsonProperty("colors") int[] colors
|
||||
) implements BackgroundFill {
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record BackgroundFillGradient(
|
||||
@JsonProperty("type") String type,
|
||||
@JsonProperty("top_color") int topColor,
|
||||
@JsonProperty("bottom_color") int bottomColor,
|
||||
@JsonProperty("rotation_angle") int rotationAngle
|
||||
) implements BackgroundFill {
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record BackgroundFillSolid(
|
||||
@JsonProperty("type") String type,
|
||||
@JsonProperty("color") int color
|
||||
) implements BackgroundFill {
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
|
||||
@JsonTypeInfo(
|
||||
use = JsonTypeInfo.Id.NAME,
|
||||
include = JsonTypeInfo.As.EXISTING_PROPERTY,
|
||||
property = "type"
|
||||
)
|
||||
@JsonSubTypes({
|
||||
@JsonSubTypes.Type(value = BackgroundTypeFill.class, name = "fill"),
|
||||
@JsonSubTypes.Type(value = BackgroundTypeWallpaper.class, name = "wallpaper"),
|
||||
@JsonSubTypes.Type(value = BackgroundTypePattern.class, name = "pattern"),
|
||||
@JsonSubTypes.Type(value = BackgroundTypeChatTheme.class, name = "chat_theme")
|
||||
})
|
||||
public interface BackgroundType {
|
||||
String type();
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record BackgroundTypeChatTheme(
|
||||
@JsonProperty("type") String type,
|
||||
@JsonProperty("theme_name") String themeName
|
||||
) implements BackgroundType {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package hdvtdev.telegram.core.objects.background;
|
||||
|
||||
public class BackgroundTypeDeserializer {
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user