diff --git a/TODO/ClassFinder.java b/TODO/ClassFinder.java new file mode 100644 index 0000000..c29b0ae --- /dev/null +++ b/TODO/ClassFinder.java @@ -0,0 +1,136 @@ +package hdvtdev.telegram.core.objects; + +import hdvtdev.telegram.annotations.handlers.CallbackQueryHandler; +import hdvtdev.telegram.annotations.handlers.TextMessageHandler; +import hdvtdev.telegram.objects.CallbackQuery; +import hdvtdev.telegram.objects.Message; +import hdvtdev.telegram.objects.Update; + +import java.io.File; +import java.io.IOException; +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; +import java.security.CodeSource; +import java.util.*; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; + +public abstract class ClassFinder { + + private static final Set> annotationsToSearch = Set.of(TextMessageHandler.class, CallbackQueryHandler.class); + private static final Set> methodsArgumentType = Set.of(Message.class, Update.class, CallbackQuery.class); + + private static ErrorHandler errorHandler; + + public static Map, Map> getClasses() { + + Map, Map> allMethods = new HashMap<>(); + annotationsToSearch.forEach(annotation -> allMethods.put(annotation, new HashMap<>())); + + CodeSource codeSource = ClassFinder.class.getProtectionDomain().getCodeSource(); + if (codeSource != null) { + try { + String path = codeSource.getLocation().toURI().getPath(); + File file = new File(URLDecoder.decode(path, StandardCharsets.UTF_8)); + + if (file.isFile() && file.getName().endsWith(".jar")) { + processJar(file, allMethods); + } else if (file.isDirectory()) { + processDirectory(file, "", allMethods); + } + } catch (Exception e) { + return Map.of(); + } + } + + return Collections.unmodifiableMap(allMethods); + } + + private static void processDirectory(File directory, String packageName, Map, Map> methods) { + File[] files = directory.listFiles(); + if (files == null) return; + + for (File file : files) { + if (file.isDirectory()) { + processDirectory(file, packageName + file.getName() + ".", methods); + } else if (file.getName().endsWith(".class")) { + + String className = packageName + file.getName().replace(".class", ""); + loadClass(className, methods); + } + } + } + + private static void processJar(File jarFile, Map, Map> methods) { + try (JarFile jar = new JarFile(jarFile)) { + Enumeration entries = jar.entries(); + while (entries.hasMoreElements()) { + JarEntry entry = entries.nextElement(); + if (entry.getName().endsWith(".class")) { + String className = entry.getName() + .replace("/", ".") + .replace(".class", ""); + + loadClass(className, methods); + } + } + } catch (IOException ignored) { + } + } + + public static Map, Map> localScan(Class cls) { + Map, Map> allMethods = new HashMap<>(); + annotationsToSearch.forEach(annotation -> allMethods.put(annotation, new HashMap<>())); + loadClass(cls.getName(), allMethods); + return allMethods; + } + + + private static void loadClass(String className, Map, Map> methods) { + try { + Class c = Class.forName(className); + + for (Method method : c.getDeclaredMethods()) { + + Class[] parameters = method.getParameterTypes(); + + if (parameters.length != 0 && !methodsArgumentType.contains(parameters[0])) { + continue; + } + + if (method.isAnnotationPresent(CallbackQueryHandler.class)) { + if (Modifier.isStatic(method.getModifiers())) { + for (String value : method.getAnnotation(CallbackQueryHandler.class).value()) { + methods.get(CallbackQueryHandler.class).put(value, new InvokeMethod(method, parameters[0])); + } + } else + System.err.println(method + " is annotated with @CallbackQueryHandler, but it is not static. For the annotation to work, the method must be static."); + } + + if (method.isAnnotationPresent(TextMessageHandler.class)) { + if (Modifier.isStatic(method.getModifiers())) { + for (String value : method.getAnnotation(TextMessageHandler.class).value()) { + methods.get(TextMessageHandler.class).put(value, new InvokeMethod(method, parameters[0])); + } + } else + System.err.println(method + " is annotated with @TextMessageHandler, but it is not static. For the annotation to work, the method must be static."); + } + + } + } catch (NoClassDefFoundError | UnsupportedClassVersionError | ClassNotFoundException e) { + if (errorHandler != null) errorHandler.onError(e); + } + } + + public void setErrorHandler(ErrorHandler errorHandler) { + ClassFinder.errorHandler = errorHandler; + } + + public interface ErrorHandler { + void onError(Throwable throwable); + } + +} diff --git a/core/build.gradle b/core/build.gradle new file mode 100644 index 0000000..e472613 --- /dev/null +++ b/core/build.gradle @@ -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 +} diff --git a/core/src/main/java/hdvtdev/telegram/Main.java b/core/src/main/java/hdvtdev/telegram/Main.java new file mode 100644 index 0000000..a7be11d --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/Main.java @@ -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 updates) { + updates.forEach(System.out::println); + } + } + + +} diff --git a/core/src/main/java/hdvtdev/telegram/annotations/handlers/CallbackQueryHandler.java b/core/src/main/java/hdvtdev/telegram/annotations/handlers/CallbackQueryHandler.java new file mode 100644 index 0000000..68e13e4 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/annotations/handlers/CallbackQueryHandler.java @@ -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. + *

+ * If {@code value} is set to "*", the method will handle all {@link CallbackQuery} data, + * and other {@code @CallbackQueryHandler} methods will be ignored. + *

+ * The annotated method must be {@code static} and may accept: + *

    + *
  • {@link Void} {@code (no params)}
  • + *
  • {@link Update}
  • + *
  • {@link CallbackQuery}
  • + *
+ * Only one parameter is allowed. + *

+ * You do not need to call {@link CallbackQuery#hasData()} or {@link Update#hasCallbackQuery()}, + * as these checks are performed automatically before invocation. + * + *

Usage example:

+ *

+ * {@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);
+ *     }
+ * }
+ * 
+ *
Last documentation update: 2025-04-05
+ * @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 "*"; +} + diff --git a/core/src/main/java/hdvtdev/telegram/annotations/handlers/TextMessageHandler.java b/core/src/main/java/hdvtdev/telegram/annotations/handlers/TextMessageHandler.java new file mode 100644 index 0000000..89837b8 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/annotations/handlers/TextMessageHandler.java @@ -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. + *

+ * If {@code value} is set to "*", the method will handle all {@link Message} text, + * and other {@code @TextMessageHandler} methods will be ignored. + *

+ * The annotated method must be {@code static} and may accept: + *

    + *
  • {@link Void} {@code (no params)}
  • + *
  • {@link Update}
  • + *
  • {@link Message}
  • + *
+ * Only one parameter is allowed. + *

+ * You do not need to call {@link Message#hasText()} or {@link Update#hasMessage()}, + * as these checks are performed automatically before invocation. + * + *

Usage example:

+ *

+ * {@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())));
+ * }
+ * 
+ *
Last documentation update: 2025-04-05
+ * @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 "*"; +} diff --git a/core/src/main/java/hdvtdev/telegram/annotations/util/Jsonable.java b/core/src/main/java/hdvtdev/telegram/annotations/util/Jsonable.java new file mode 100644 index 0000000..d4bf8fa --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/annotations/util/Jsonable.java @@ -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. + *
Last documentation update: 2025-04-05
+ * @see com.fasterxml.jackson.databind.ObjectMapper + * @since 1.0.0 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface Jsonable { +} diff --git a/core/src/main/java/hdvtdev/telegram/annotations/util/NotTested.java b/core/src/main/java/hdvtdev/telegram/annotations/util/NotTested.java new file mode 100644 index 0000000..4f75c06 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/annotations/util/NotTested.java @@ -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 { + +} diff --git a/core/src/main/java/hdvtdev/telegram/core/InvokeMethod.java b/core/src/main/java/hdvtdev/telegram/core/InvokeMethod.java new file mode 100644 index 0000000..0f70fa3 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/InvokeMethod.java @@ -0,0 +1,7 @@ +package hdvtdev.telegram.core.objects; + +import java.lang.reflect.Method; + +public record InvokeMethod(Method method, Class parameterType) { + +} diff --git a/core/src/main/java/hdvtdev/telegram/core/Main.java b/core/src/main/java/hdvtdev/telegram/core/Main.java new file mode 100644 index 0000000..d3da0f0 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/Main.java @@ -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 updates) { + updates.forEach(System.out::println); + } + } + + +} diff --git a/core/src/main/java/hdvtdev/telegram/core/TelegramBot.java b/core/src/main/java/hdvtdev/telegram/core/TelegramBot.java new file mode 100644 index 0000000..a32029e --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/TelegramBot.java @@ -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 awaitExecute(TelegramApiMethod telegramApiMethod) throws TelegramApiException, TelegramApiNetworkException, TelegramMethodParsingException; + + File awaitDownloadFile(TelegramFile telegramFile, Path targetDirectory); + + default CompletableFuture downloadFile(TelegramFile telegramFile, Path targetDirectory) throws TelegramApiException, TelegramApiNetworkException { + return CompletableFuture.supplyAsync(() -> awaitDownloadFile(telegramFile, targetDirectory)); + } + + default CompletableFuture execute(TelegramApiMethod 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); + } + +} diff --git a/core/src/main/java/hdvtdev/telegram/core/UpdateConsumer.java b/core/src/main/java/hdvtdev/telegram/core/UpdateConsumer.java new file mode 100644 index 0000000..2348807 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/UpdateConsumer.java @@ -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 updates); + +} diff --git a/core/src/main/java/hdvtdev/telegram/core/UserState.java b/core/src/main/java/hdvtdev/telegram/core/UserState.java new file mode 100644 index 0000000..3008cd7 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/UserState.java @@ -0,0 +1,4 @@ +package hdvtdev.telegram.core.bot; + +public interface UserState { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/annotaions/Jsonable.java b/core/src/main/java/hdvtdev/telegram/core/annotaions/Jsonable.java new file mode 100644 index 0000000..835b973 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/annotaions/Jsonable.java @@ -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. + *
Last documentation update: 2025-04-05
+ * @see com.fasterxml.jackson.databind.ObjectMapper + * @since 1.0.0 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface Jsonable { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/exceptions/TelegramApiException.java b/core/src/main/java/hdvtdev/telegram/core/exceptions/TelegramApiException.java new file mode 100644 index 0000000..4808610 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/exceptions/TelegramApiException.java @@ -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) { + + } + +} diff --git a/core/src/main/java/hdvtdev/telegram/core/exceptions/TelegramApiNetworkException.java b/core/src/main/java/hdvtdev/telegram/core/exceptions/TelegramApiNetworkException.java new file mode 100644 index 0000000..8ee9c6a --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/exceptions/TelegramApiNetworkException.java @@ -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); + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/exceptions/TelegramMethodParsingException.java b/core/src/main/java/hdvtdev/telegram/core/exceptions/TelegramMethodParsingException.java new file mode 100644 index 0000000..cad5c01 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/exceptions/TelegramMethodParsingException.java @@ -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); + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/methods/AnswerCallbackQuery.java b/core/src/main/java/hdvtdev/telegram/core/methods/AnswerCallbackQuery.java new file mode 100644 index 0000000..13b9a17 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/AnswerCallbackQuery.java @@ -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 { + + /** + * 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 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); + } + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/methods/ApproveChatJoinRequest.java b/core/src/main/java/hdvtdev/telegram/core/methods/ApproveChatJoinRequest.java new file mode 100644 index 0000000..7338266 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/ApproveChatJoinRequest.java @@ -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 administrator 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 { + + /** + * @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 getResponseClass() { + return Boolean.class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/methods/BanChatMember.java b/core/src/main/java/hdvtdev/telegram/core/methods/BanChatMember.java new file mode 100644 index 0000000..17622c3 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/BanChatMember.java @@ -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 { + + /** + * 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 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); + } + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/methods/BanChatSenderChat.java b/core/src/main/java/hdvtdev/telegram/core/methods/BanChatSenderChat.java new file mode 100644 index 0000000..323e677 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/BanChatSenderChat.java @@ -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 { + + 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 getResponseClass() { + return Boolean.class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/methods/CloseForumTopic.java b/core/src/main/java/hdvtdev/telegram/core/methods/CloseForumTopic.java new file mode 100644 index 0000000..debe5e5 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/CloseForumTopic.java @@ -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 { + + 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 getResponseClass() { + return Boolean.class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/methods/CloseGeneralForumTopic.java b/core/src/main/java/hdvtdev/telegram/core/methods/CloseGeneralForumTopic.java new file mode 100644 index 0000000..2d2ed8e --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/CloseGeneralForumTopic.java @@ -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 { + + 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 getResponseClass() { + return Boolean.class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/methods/CopyMessage.java b/core/src/main/java/hdvtdev/telegram/core/methods/CopyMessage.java new file mode 100644 index 0000000..a910879 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/CopyMessage.java @@ -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 { + + @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 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 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 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 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 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); + } + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/methods/CopyMessages.java b/core/src/main/java/hdvtdev/telegram/core/methods/CopyMessages.java new file mode 100644 index 0000000..b5bc081 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/CopyMessages.java @@ -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 { + + @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 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 messageIds) { + this.chatId = chatId; + this.fromChatId = fromChatId; + ArrayList 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 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 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 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 getResponseClass() { + return Long[].class; + } + + public static final class Builder { + private final String chatId; + private Long messageThreadId; + private final String fromChatId; + private final List messageIds; + private Boolean disableNotification; + private Boolean protectContent; + private Boolean removeCaption; + + public Builder(String chatId, String fromChatId, List messageIds) { + this.chatId = chatId; + this.fromChatId = fromChatId; + ArrayList sortedMessageIds = new ArrayList<>(messageIds.subList(0, Math.min(messageIds.size(), 100))); + sortedMessageIds.sort(null); + this.messageIds = sortedMessageIds; + } + public Builder(long chatId, String fromChatId, List messageIds) { + this(String.valueOf(chatId), fromChatId, messageIds); + } + + public Builder(long chatId, long fromChatId, List messageIds) { + this(String.valueOf(chatId), String.valueOf(fromChatId), messageIds); + } + + public Builder(String chatId, long fromChatId, List 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); + } + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/methods/CreateChatInviteLink.java b/core/src/main/java/hdvtdev/telegram/core/methods/CreateChatInviteLink.java new file mode 100644 index 0000000..45bcd68 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/CreateChatInviteLink.java @@ -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 { + + 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 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); + } + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/methods/ForwardMessage.java b/core/src/main/java/hdvtdev/telegram/core/methods/ForwardMessage.java new file mode 100644 index 0000000..f6bb9d1 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/ForwardMessage.java @@ -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 { + + @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 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); + } + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/methods/ForwardMessages.java b/core/src/main/java/hdvtdev/telegram/core/methods/ForwardMessages.java new file mode 100644 index 0000000..7ff9110 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/ForwardMessages.java @@ -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 { + + @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 messageIds; + @JsonProperty("disable_notification") + private Boolean disableNotification; + @JsonProperty("protect_content") + private Boolean protectContent; + + public ForwardMessages(String chatId, String fromChatId, List messageIds) { + ArrayList 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 messageIds) { + this(String.valueOf(chatId), fromChatId, messageIds); + } + + public ForwardMessages(String chatId, long fromChatId, List messageIds) { + this(chatId, String.valueOf(fromChatId), messageIds); + } + + public ForwardMessages(long chatId, long fromChatId, List 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 getResponseClass() { + return Long[].class; + } + + + public static final class Builder { + private final String chatId; + private Long messageThreadId; + private final String fromChatId; + private final List messageIds; + private Boolean disableNotification; + private Boolean protectContent; + + public Builder(String chatId, String fromChatId, List messageIds) { + ArrayList 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 messageIds) { + this(String.valueOf(chatId), fromChatId, messageIds); + } + + public Builder(String chatId, long fromChatId, List messageIds) { + this(chatId, String.valueOf(fromChatId), messageIds); + } + + public Builder(long chatId, long fromChatId, List 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); + } + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/methods/GetChatAdministrators.java b/core/src/main/java/hdvtdev/telegram/core/methods/GetChatAdministrators.java new file mode 100644 index 0000000..8a0ad7a --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/GetChatAdministrators.java @@ -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 { + + 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 getResponseClass() { + return ChatMember[].class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/methods/GetChatMember.java b/core/src/main/java/hdvtdev/telegram/core/methods/GetChatMember.java new file mode 100644 index 0000000..1c0065c --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/GetChatMember.java @@ -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 { + + 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 getResponseClass() { + return ChatMember.class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/methods/GetFile.java b/core/src/main/java/hdvtdev/telegram/core/methods/GetFile.java new file mode 100644 index 0000000..96bfbd5 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/GetFile.java @@ -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 { + + @Override + public RequestBody getBody() { + return new FormBody.Builder().add("file_id", fileId).build(); + } + + @Override + public String getMethodName() { + return "getFile"; + } + + @Override + public Class getResponseClass() { + return TelegramFile.class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/methods/GetMe.java b/core/src/main/java/hdvtdev/telegram/core/methods/GetMe.java new file mode 100644 index 0000000..cfe2819 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/GetMe.java @@ -0,0 +1,22 @@ +package hdvtdev.telegram.core.objects; + +import hdvtdev.telegram.objects.User; +import okhttp3.RequestBody; + +public final class GetMe implements TelegramApiMethod { + + @Override + public RequestBody getBody() { + return null; + } + + @Override + public String getMethodName() { + return "getMe"; + } + + @Override + public Class getResponseClass() { + return User.Bot.class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/methods/GetMyCommands.java b/core/src/main/java/hdvtdev/telegram/core/methods/GetMyCommands.java new file mode 100644 index 0000000..aebee4d --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/GetMyCommands.java @@ -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 { + + 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 getResponseClass() { + return BotCommand[].class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/methods/GetMyDescription.java b/core/src/main/java/hdvtdev/telegram/core/methods/GetMyDescription.java new file mode 100644 index 0000000..a351910 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/GetMyDescription.java @@ -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 { + + 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 getResponseClass() { + return BotDescription.class; + } + + public record BotDescription(String description) { + @NotNull + @Override + public String toString() { + return description; + } + + public boolean isEmpty() { + return description.isEmpty(); + } + + } + +} diff --git a/core/src/main/java/hdvtdev/telegram/core/methods/GetMyName.java b/core/src/main/java/hdvtdev/telegram/core/methods/GetMyName.java new file mode 100644 index 0000000..af83b33 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/GetMyName.java @@ -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 { + + 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 getResponseClass() { + return BotName.class; + } + + public record BotName(String name) { + + @NotNull + @Override + public String toString() { + return this.name; + } + + } + +} diff --git a/core/src/main/java/hdvtdev/telegram/core/methods/GetUpdates.java b/core/src/main/java/hdvtdev/telegram/core/methods/GetUpdates.java new file mode 100644 index 0000000..2f12900 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/GetUpdates.java @@ -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 { + + public GetUpdates() { + this(null, null, null); + } + + @Override + public RequestBody getBody() { + return null; + } + + @Override + public String getMethodName() { + ArrayList 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 getResponseClass() { + return Update[].class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/methods/RevokeChatInviteLink.java b/core/src/main/java/hdvtdev/telegram/core/methods/RevokeChatInviteLink.java new file mode 100644 index 0000000..f3324f2 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/RevokeChatInviteLink.java @@ -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 { + + 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 getResponseClass() { + return ChatInviteLink.class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/methods/SendChatAction.java b/core/src/main/java/hdvtdev/telegram/core/methods/SendChatAction.java new file mode 100644 index 0000000..9f59abd --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/SendChatAction.java @@ -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 { + + 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 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); + } + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/methods/SendDice.java b/core/src/main/java/hdvtdev/telegram/core/methods/SendDice.java new file mode 100644 index 0000000..3bb16dc --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/SendDice.java @@ -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 { + + @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 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; + } + + } + + + +} diff --git a/core/src/main/java/hdvtdev/telegram/core/methods/SendMessage.java b/core/src/main/java/hdvtdev/telegram/core/methods/SendMessage.java new file mode 100644 index 0000000..6187da7 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/SendMessage.java @@ -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 { + + @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 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); + } + } +} + diff --git a/core/src/main/java/hdvtdev/telegram/core/methods/SetMessageReaction.java b/core/src/main/java/hdvtdev/telegram/core/methods/SetMessageReaction.java new file mode 100644 index 0000000..3aecda3 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/SetMessageReaction.java @@ -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 { + + @JsonProperty("chat_id") + private final String chatId; + @JsonProperty("message_id") + private final long messageId; + @JsonProperty("reaction") + private List 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 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 getResponseClass() { + return Boolean.class; + } + + public static final class Builder { + private final String chatId; + private final long messageId; + private List 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 reactions) { + this.reactions = reactions; + return this; + } + + public Builder isBig(Boolean isBig) { + this.isBig = isBig; + return this; + } + + public SetMessageReaction build() { + return new SetMessageReaction(this); + } + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/methods/SetMyCommands.java b/core/src/main/java/hdvtdev/telegram/core/methods/SetMyCommands.java new file mode 100644 index 0000000..8dac79a --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/SetMyCommands.java @@ -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 { + + @JsonProperty("commands") + private final List commands; + @JsonProperty("scope") + private Object scope; + @JsonProperty("language_code") + private String languageCode; + + public SetMyCommands(List 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 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 getResponseClass() { + return Boolean.class; + } + + + public static final class Builder { + private final List commands; + private Object scope; + private String languageCode; + + public Builder(List 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); + } + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/methods/SetMyDescription.java b/core/src/main/java/hdvtdev/telegram/core/methods/SetMyDescription.java new file mode 100644 index 0000000..2dc5c26 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/SetMyDescription.java @@ -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 { + + 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 getResponseClass() { + return Boolean.class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/methods/SetMyName.java b/core/src/main/java/hdvtdev/telegram/core/methods/SetMyName.java new file mode 100644 index 0000000..fb7eff3 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/SetMyName.java @@ -0,0 +1,28 @@ +package hdvtdev.telegram.core.objects; + +import okhttp3.FormBody; +import okhttp3.RequestBody; + +public record SetMyName(String name, String languageCode) implements TelegramApiMethod { + + 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 getResponseClass() { + return Boolean.class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/methods/TelegramApiMethod.java b/core/src/main/java/hdvtdev/telegram/core/methods/TelegramApiMethod.java new file mode 100644 index 0000000..1035ba3 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/TelegramApiMethod.java @@ -0,0 +1,13 @@ +package hdvtdev.telegram.core.objects; + +import okhttp3.RequestBody; + +public interface TelegramApiMethod { + + RequestBody getBody(); + + String getMethodName(); + + Class getResponseClass(); + +} diff --git a/core/src/main/java/hdvtdev/telegram/core/methods/TelegramApiMethodBody.java b/core/src/main/java/hdvtdev/telegram/core/methods/TelegramApiMethodBody.java new file mode 100644 index 0000000..3f65f96 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/TelegramApiMethodBody.java @@ -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 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 action) { + this.elements.forEach(action); + } + + public record Element(String name, String value) { + + } + +} + diff --git a/core/src/main/java/hdvtdev/telegram/core/methods/util/ParseMode.java b/core/src/main/java/hdvtdev/telegram/core/methods/util/ParseMode.java new file mode 100644 index 0000000..5ceaa73 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/util/ParseMode.java @@ -0,0 +1,7 @@ +package hdvtdev.telegram.core; + +public enum ParseMode { + MARKDOWN, + MARKDOWNV2, + HTML +} \ No newline at end of file diff --git a/core/src/main/java/hdvtdev/telegram/core/methods/util/Util.java b/core/src/main/java/hdvtdev/telegram/core/methods/util/Util.java new file mode 100644 index 0000000..d955f77 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/util/Util.java @@ -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 lines = Files.readAllLines(filePath); + HashSet linesSet = new HashSet<>(lines); + ArrayList 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); + } + +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/AnswerCallbackQuery.java b/core/src/main/java/hdvtdev/telegram/core/objects/AnswerCallbackQuery.java new file mode 100644 index 0000000..13b9a17 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/AnswerCallbackQuery.java @@ -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 { + + /** + * 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 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); + } + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/ApproveChatJoinRequest.java b/core/src/main/java/hdvtdev/telegram/core/objects/ApproveChatJoinRequest.java new file mode 100644 index 0000000..7338266 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/ApproveChatJoinRequest.java @@ -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 administrator 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 { + + /** + * @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 getResponseClass() { + return Boolean.class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/BanChatMember.java b/core/src/main/java/hdvtdev/telegram/core/objects/BanChatMember.java new file mode 100644 index 0000000..17622c3 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/BanChatMember.java @@ -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 { + + /** + * 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 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); + } + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/BanChatSenderChat.java b/core/src/main/java/hdvtdev/telegram/core/objects/BanChatSenderChat.java new file mode 100644 index 0000000..323e677 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/BanChatSenderChat.java @@ -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 { + + 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 getResponseClass() { + return Boolean.class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/ChosenInlineResult.java b/core/src/main/java/hdvtdev/telegram/core/objects/ChosenInlineResult.java new file mode 100644 index 0000000..97dfb43 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/ChosenInlineResult.java @@ -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 +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/CloseForumTopic.java b/core/src/main/java/hdvtdev/telegram/core/objects/CloseForumTopic.java new file mode 100644 index 0000000..debe5e5 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/CloseForumTopic.java @@ -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 { + + 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 getResponseClass() { + return Boolean.class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/CloseGeneralForumTopic.java b/core/src/main/java/hdvtdev/telegram/core/objects/CloseGeneralForumTopic.java new file mode 100644 index 0000000..2d2ed8e --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/CloseGeneralForumTopic.java @@ -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 { + + 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 getResponseClass() { + return Boolean.class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/Contact.java b/core/src/main/java/hdvtdev/telegram/core/objects/Contact.java new file mode 100644 index 0000000..36539bb --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/Contact.java @@ -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 +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/CopyMessage.java b/core/src/main/java/hdvtdev/telegram/core/objects/CopyMessage.java new file mode 100644 index 0000000..a910879 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/CopyMessage.java @@ -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 { + + @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 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 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 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 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 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); + } + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/CopyMessages.java b/core/src/main/java/hdvtdev/telegram/core/objects/CopyMessages.java new file mode 100644 index 0000000..b5bc081 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/CopyMessages.java @@ -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 { + + @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 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 messageIds) { + this.chatId = chatId; + this.fromChatId = fromChatId; + ArrayList 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 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 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 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 getResponseClass() { + return Long[].class; + } + + public static final class Builder { + private final String chatId; + private Long messageThreadId; + private final String fromChatId; + private final List messageIds; + private Boolean disableNotification; + private Boolean protectContent; + private Boolean removeCaption; + + public Builder(String chatId, String fromChatId, List messageIds) { + this.chatId = chatId; + this.fromChatId = fromChatId; + ArrayList sortedMessageIds = new ArrayList<>(messageIds.subList(0, Math.min(messageIds.size(), 100))); + sortedMessageIds.sort(null); + this.messageIds = sortedMessageIds; + } + public Builder(long chatId, String fromChatId, List messageIds) { + this(String.valueOf(chatId), fromChatId, messageIds); + } + + public Builder(long chatId, long fromChatId, List messageIds) { + this(String.valueOf(chatId), String.valueOf(fromChatId), messageIds); + } + + public Builder(String chatId, long fromChatId, List 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); + } + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/CreateChatInviteLink.java b/core/src/main/java/hdvtdev/telegram/core/objects/CreateChatInviteLink.java new file mode 100644 index 0000000..45bcd68 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/CreateChatInviteLink.java @@ -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 { + + 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 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); + } + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/Dice.java b/core/src/main/java/hdvtdev/telegram/core/objects/Dice.java new file mode 100644 index 0000000..4f3b25e --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/Dice.java @@ -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 +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/ForwardMessage.java b/core/src/main/java/hdvtdev/telegram/core/objects/ForwardMessage.java new file mode 100644 index 0000000..f6bb9d1 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/ForwardMessage.java @@ -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 { + + @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 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); + } + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/ForwardMessages.java b/core/src/main/java/hdvtdev/telegram/core/objects/ForwardMessages.java new file mode 100644 index 0000000..7ff9110 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/ForwardMessages.java @@ -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 { + + @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 messageIds; + @JsonProperty("disable_notification") + private Boolean disableNotification; + @JsonProperty("protect_content") + private Boolean protectContent; + + public ForwardMessages(String chatId, String fromChatId, List messageIds) { + ArrayList 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 messageIds) { + this(String.valueOf(chatId), fromChatId, messageIds); + } + + public ForwardMessages(String chatId, long fromChatId, List messageIds) { + this(chatId, String.valueOf(fromChatId), messageIds); + } + + public ForwardMessages(long chatId, long fromChatId, List 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 getResponseClass() { + return Long[].class; + } + + + public static final class Builder { + private final String chatId; + private Long messageThreadId; + private final String fromChatId; + private final List messageIds; + private Boolean disableNotification; + private Boolean protectContent; + + public Builder(String chatId, String fromChatId, List messageIds) { + ArrayList 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 messageIds) { + this(String.valueOf(chatId), fromChatId, messageIds); + } + + public Builder(String chatId, long fromChatId, List messageIds) { + this(chatId, String.valueOf(fromChatId), messageIds); + } + + public Builder(long chatId, long fromChatId, List 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); + } + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/Game.java b/core/src/main/java/hdvtdev/telegram/core/objects/Game.java new file mode 100644 index 0000000..6019a26 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/Game.java @@ -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 +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/GetChatAdministrators.java b/core/src/main/java/hdvtdev/telegram/core/objects/GetChatAdministrators.java new file mode 100644 index 0000000..8a0ad7a --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/GetChatAdministrators.java @@ -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 { + + 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 getResponseClass() { + return ChatMember[].class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/GetChatMember.java b/core/src/main/java/hdvtdev/telegram/core/objects/GetChatMember.java new file mode 100644 index 0000000..1c0065c --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/GetChatMember.java @@ -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 { + + 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 getResponseClass() { + return ChatMember.class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/GetFile.java b/core/src/main/java/hdvtdev/telegram/core/objects/GetFile.java new file mode 100644 index 0000000..96bfbd5 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/GetFile.java @@ -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 { + + @Override + public RequestBody getBody() { + return new FormBody.Builder().add("file_id", fileId).build(); + } + + @Override + public String getMethodName() { + return "getFile"; + } + + @Override + public Class getResponseClass() { + return TelegramFile.class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/GetMe.java b/core/src/main/java/hdvtdev/telegram/core/objects/GetMe.java new file mode 100644 index 0000000..cfe2819 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/GetMe.java @@ -0,0 +1,22 @@ +package hdvtdev.telegram.core.objects; + +import hdvtdev.telegram.objects.User; +import okhttp3.RequestBody; + +public final class GetMe implements TelegramApiMethod { + + @Override + public RequestBody getBody() { + return null; + } + + @Override + public String getMethodName() { + return "getMe"; + } + + @Override + public Class getResponseClass() { + return User.Bot.class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/GetMyCommands.java b/core/src/main/java/hdvtdev/telegram/core/objects/GetMyCommands.java new file mode 100644 index 0000000..aebee4d --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/GetMyCommands.java @@ -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 { + + 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 getResponseClass() { + return BotCommand[].class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/GetMyDescription.java b/core/src/main/java/hdvtdev/telegram/core/objects/GetMyDescription.java new file mode 100644 index 0000000..a351910 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/GetMyDescription.java @@ -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 { + + 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 getResponseClass() { + return BotDescription.class; + } + + public record BotDescription(String description) { + @NotNull + @Override + public String toString() { + return description; + } + + public boolean isEmpty() { + return description.isEmpty(); + } + + } + +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/GetMyName.java b/core/src/main/java/hdvtdev/telegram/core/objects/GetMyName.java new file mode 100644 index 0000000..af83b33 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/GetMyName.java @@ -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 { + + 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 getResponseClass() { + return BotName.class; + } + + public record BotName(String name) { + + @NotNull + @Override + public String toString() { + return this.name; + } + + } + +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/GetUpdates.java b/core/src/main/java/hdvtdev/telegram/core/objects/GetUpdates.java new file mode 100644 index 0000000..2f12900 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/GetUpdates.java @@ -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 { + + public GetUpdates() { + this(null, null, null); + } + + @Override + public RequestBody getBody() { + return null; + } + + @Override + public String getMethodName() { + ArrayList 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 getResponseClass() { + return Update[].class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/InlineQuery.java b/core/src/main/java/hdvtdev/telegram/core/objects/InlineQuery.java new file mode 100644 index 0000000..566c0f9 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/InlineQuery.java @@ -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 +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/Location.java b/core/src/main/java/hdvtdev/telegram/core/objects/Location.java new file mode 100644 index 0000000..29dbf94 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/Location.java @@ -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 +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/LoginUrl.java b/core/src/main/java/hdvtdev/telegram/core/objects/LoginUrl.java new file mode 100644 index 0000000..67b9344 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/LoginUrl.java @@ -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 +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/MaskPosition.java b/core/src/main/java/hdvtdev/telegram/core/objects/MaskPosition.java new file mode 100644 index 0000000..e9de212 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/MaskPosition.java @@ -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 +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/ProximityAlertTriggered.java b/core/src/main/java/hdvtdev/telegram/core/objects/ProximityAlertTriggered.java new file mode 100644 index 0000000..b111773 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/ProximityAlertTriggered.java @@ -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 +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/ReplyParameters.java b/core/src/main/java/hdvtdev/telegram/core/objects/ReplyParameters.java new file mode 100644 index 0000000..c14a787 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/ReplyParameters.java @@ -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)); + } + + +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/RevokeChatInviteLink.java b/core/src/main/java/hdvtdev/telegram/core/objects/RevokeChatInviteLink.java new file mode 100644 index 0000000..f3324f2 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/RevokeChatInviteLink.java @@ -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 { + + 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 getResponseClass() { + return ChatInviteLink.class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/SendChatAction.java b/core/src/main/java/hdvtdev/telegram/core/objects/SendChatAction.java new file mode 100644 index 0000000..9f59abd --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/SendChatAction.java @@ -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 { + + 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 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); + } + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/SendDice.java b/core/src/main/java/hdvtdev/telegram/core/objects/SendDice.java new file mode 100644 index 0000000..3bb16dc --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/SendDice.java @@ -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 { + + @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 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; + } + + } + + + +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/SendMessage.java b/core/src/main/java/hdvtdev/telegram/core/objects/SendMessage.java new file mode 100644 index 0000000..6187da7 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/SendMessage.java @@ -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 { + + @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 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); + } + } +} + diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/SetMessageReaction.java b/core/src/main/java/hdvtdev/telegram/core/objects/SetMessageReaction.java new file mode 100644 index 0000000..3aecda3 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/SetMessageReaction.java @@ -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 { + + @JsonProperty("chat_id") + private final String chatId; + @JsonProperty("message_id") + private final long messageId; + @JsonProperty("reaction") + private List 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 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 getResponseClass() { + return Boolean.class; + } + + public static final class Builder { + private final String chatId; + private final long messageId; + private List 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 reactions) { + this.reactions = reactions; + return this; + } + + public Builder isBig(Boolean isBig) { + this.isBig = isBig; + return this; + } + + public SetMessageReaction build() { + return new SetMessageReaction(this); + } + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/SetMyCommands.java b/core/src/main/java/hdvtdev/telegram/core/objects/SetMyCommands.java new file mode 100644 index 0000000..8dac79a --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/SetMyCommands.java @@ -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 { + + @JsonProperty("commands") + private final List commands; + @JsonProperty("scope") + private Object scope; + @JsonProperty("language_code") + private String languageCode; + + public SetMyCommands(List 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 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 getResponseClass() { + return Boolean.class; + } + + + public static final class Builder { + private final List commands; + private Object scope; + private String languageCode; + + public Builder(List 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); + } + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/SetMyDescription.java b/core/src/main/java/hdvtdev/telegram/core/objects/SetMyDescription.java new file mode 100644 index 0000000..2dc5c26 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/SetMyDescription.java @@ -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 { + + 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 getResponseClass() { + return Boolean.class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/SetMyName.java b/core/src/main/java/hdvtdev/telegram/core/objects/SetMyName.java new file mode 100644 index 0000000..fb7eff3 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/SetMyName.java @@ -0,0 +1,28 @@ +package hdvtdev.telegram.core.objects; + +import okhttp3.FormBody; +import okhttp3.RequestBody; + +public record SetMyName(String name, String languageCode) implements TelegramApiMethod { + + 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 getResponseClass() { + return Boolean.class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/SharedUser.java b/core/src/main/java/hdvtdev/telegram/core/objects/SharedUser.java new file mode 100644 index 0000000..59f7864 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/SharedUser.java @@ -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 +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/TelegramApiMethod.java b/core/src/main/java/hdvtdev/telegram/core/objects/TelegramApiMethod.java new file mode 100644 index 0000000..1035ba3 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/TelegramApiMethod.java @@ -0,0 +1,13 @@ +package hdvtdev.telegram.core.objects; + +import okhttp3.RequestBody; + +public interface TelegramApiMethod { + + RequestBody getBody(); + + String getMethodName(); + + Class getResponseClass(); + +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/Update.java b/core/src/main/java/hdvtdev/telegram/core/objects/Update.java new file mode 100644 index 0000000..450da73 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/Update.java @@ -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 getAnyText() { + if (hasMessage()) { + if (message.hasText()) return Optional.of(message.text()); + if (message.hasCaption()) return Optional.of(message.caption()); + } + return Optional.empty(); + } + +} + diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/User.java b/core/src/main/java/hdvtdev/telegram/core/objects/User.java new file mode 100644 index 0000000..3f0f29d --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/User.java @@ -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; + } + + + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/UsersShared.java b/core/src/main/java/hdvtdev/telegram/core/objects/UsersShared.java new file mode 100644 index 0000000..5d9231d --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/UsersShared.java @@ -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 +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/Venue.java b/core/src/main/java/hdvtdev/telegram/core/objects/Venue.java new file mode 100644 index 0000000..7a1d746 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/Venue.java @@ -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 +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/WebAppData.java b/core/src/main/java/hdvtdev/telegram/core/objects/WebAppData.java new file mode 100644 index 0000000..4ca6087 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/WebAppData.java @@ -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) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/WebAppInfo.java b/core/src/main/java/hdvtdev/telegram/core/objects/WebAppInfo.java new file mode 100644 index 0000000..61ef90a --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/WebAppInfo.java @@ -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) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/WriteAccessAllowed.java b/core/src/main/java/hdvtdev/telegram/core/objects/WriteAccessAllowed.java new file mode 100644 index 0000000..4513ab0 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/WriteAccessAllowed.java @@ -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 +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundFill.java b/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundFill.java new file mode 100644 index 0000000..dd020c9 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundFill.java @@ -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(); +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundFillDeserializer.java b/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundFillDeserializer.java new file mode 100644 index 0000000..5dd0c4f --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundFillDeserializer.java @@ -0,0 +1,4 @@ +package hdvtdev.telegram.core.objects.background; + +public class BackgroundFillDeserializer { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundFillFreeformGradient.java b/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundFillFreeformGradient.java new file mode 100644 index 0000000..c6ada4e --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundFillFreeformGradient.java @@ -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 { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundFillGradient.java b/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundFillGradient.java new file mode 100644 index 0000000..bf70298 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundFillGradient.java @@ -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 { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundFillSolid.java b/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundFillSolid.java new file mode 100644 index 0000000..3ef193e --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundFillSolid.java @@ -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 { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundType.java b/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundType.java new file mode 100644 index 0000000..3073a05 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundType.java @@ -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(); +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundTypeChatTheme.java b/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundTypeChatTheme.java new file mode 100644 index 0000000..f6b9110 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundTypeChatTheme.java @@ -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 { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundTypeDeserializer.java b/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundTypeDeserializer.java new file mode 100644 index 0000000..ed96f2b --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundTypeDeserializer.java @@ -0,0 +1,4 @@ +package hdvtdev.telegram.core.objects.background; + +public class BackgroundTypeDeserializer { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundTypeFill.java b/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundTypeFill.java new file mode 100644 index 0000000..c327930 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundTypeFill.java @@ -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 BackgroundTypeFill( + @JsonProperty("type") String type, + @JsonProperty("fill") BackgroundFill fill, + @JsonProperty("dark_theme_dimming") int darkThemeDimming +) implements BackgroundType { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundTypePattern.java b/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundTypePattern.java new file mode 100644 index 0000000..1d8cca6 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundTypePattern.java @@ -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 BackgroundTypePattern( + @JsonProperty("type") String type, + @JsonProperty("document") Document document, + @JsonProperty("fill") BackgroundFill fill, + @JsonProperty("is_inverted") boolean isInverted, + @JsonProperty("is_moving") boolean isMoving +) implements BackgroundType { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundTypeWallpaper.java b/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundTypeWallpaper.java new file mode 100644 index 0000000..79d88ee --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundTypeWallpaper.java @@ -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 BackgroundTypeWallpaper( + @JsonProperty("type") String type, + @JsonProperty("document") Document document, + @JsonProperty("dark_theme_dimming") int darkThemeDimming, + @JsonProperty("is_blurred") boolean isBlurred, + @JsonProperty("is_moving") boolean isMoving +) implements BackgroundType { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/business/BusinessConnection.java b/core/src/main/java/hdvtdev/telegram/core/objects/business/BusinessConnection.java new file mode 100644 index 0000000..af94133 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/business/BusinessConnection.java @@ -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 BusinessConnection( + @JsonProperty("id") String id, + @JsonProperty("user") User user, + @JsonProperty("user_chat_id") long userChatId, + @JsonProperty("date") long date, + @JsonProperty("can_reply") boolean canReply, + @JsonProperty("is_enabled") boolean isEnabled +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/business/BusinessMessagesDeleted.java b/core/src/main/java/hdvtdev/telegram/core/objects/business/BusinessMessagesDeleted.java new file mode 100644 index 0000000..3f544b9 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/business/BusinessMessagesDeleted.java @@ -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; +import hdvtdev.telegram.core.objects.chat.Chat; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record BusinessMessagesDeleted( + @JsonProperty("business_connection_id") String businessConnectionId, + @JsonProperty("chat") Chat chat, + @JsonProperty("message_ids") long[] messageIds +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/callback/CallbackGame.java b/core/src/main/java/hdvtdev/telegram/core/objects/callback/CallbackGame.java new file mode 100644 index 0000000..7cce5fd --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/callback/CallbackGame.java @@ -0,0 +1,9 @@ +package hdvtdev.telegram.core.objects; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record CallbackGame() { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/callback/CallbackQuery.java b/core/src/main/java/hdvtdev/telegram/core/objects/callback/CallbackQuery.java new file mode 100644 index 0000000..2856d32 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/callback/CallbackQuery.java @@ -0,0 +1,40 @@ +package hdvtdev.telegram.core.objects; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.message.MaybeInaccessibleMessage; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record CallbackQuery( + @JsonProperty("id") String id, + @JsonProperty("from") User from, + @JsonProperty("message") MaybeInaccessibleMessage message, + @JsonProperty("inline_message_id") String inlineMessageId, + @JsonProperty("chat_instance") String chatInstance, + @JsonProperty("data") String data, + @JsonProperty("game_short_name") String gameShortName +) { + + public boolean hasMessage() { + return this.message != null; + } + + public boolean hasInlineMessageId() { + return this.inlineMessageId != null; + } + + public boolean hasChatInstance() { + return this.chatInstance != null; + } + + public boolean hasData() { + return this.data != null; + } + + public boolean hasGameShortName() { + return this.gameShortName != null; + } + +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/chat/Chat.java b/core/src/main/java/hdvtdev/telegram/core/objects/chat/Chat.java new file mode 100644 index 0000000..15e8385 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chat/Chat.java @@ -0,0 +1,35 @@ +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 Chat( + @JsonProperty("id") long id, + @JsonProperty("type") String type, + @JsonProperty("title") String title, + @JsonProperty("username") String username, + @JsonProperty("first_name") String firstName, + @JsonProperty("last_name") String lastName, + @JsonProperty("is_forum") boolean isForum +) { + + public boolean hasTitle() { + return this.title != null; + } + + public boolean hasUsername() { + return this.username != null; + } + + public boolean hasFirstName() { + return this.firstName != null; + } + + public boolean hasLastName() { + return this.lastName != null; + } + +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatAdministratorRights.java b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatAdministratorRights.java new file mode 100644 index 0000000..4d5310c --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatAdministratorRights.java @@ -0,0 +1,26 @@ +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 ChatAdministratorRights( + @JsonProperty("is_anonymous") boolean isAnonymous, + @JsonProperty("can_manage_chat") boolean canManageChat, + @JsonProperty("can_delete_messages") boolean canDeleteMessages, + @JsonProperty("can_manage_video_chats") boolean canManageVideoChats, + @JsonProperty("can_restrict_members") boolean canRestrictMembers, + @JsonProperty("can_promote_members") boolean canPromoteMembers, + @JsonProperty("can_change_info") boolean canChangeInfo, + @JsonProperty("can_invite_users") boolean canInviteUsers, + @JsonProperty("can_post_stories") boolean canPostStories, + @JsonProperty("can_edit_stories") boolean canEditStories, + @JsonProperty("can_delete_stories") boolean canDeleteStories, + @JsonProperty("can_post_messages") boolean canPostMessages, + @JsonProperty("can_edit_messages") boolean canEditMessages, + @JsonProperty("can_pin_messages") boolean canPinMessages, + @JsonProperty("can_manage_topics") boolean canManageTopics +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatBackground.java b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatBackground.java new file mode 100644 index 0000000..debb727 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatBackground.java @@ -0,0 +1,11 @@ +package hdvtdev.telegram.core.objects; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.background.BackgroundType; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record ChatBackground(@JsonProperty("type") BackgroundType type) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatInviteLink.java b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatInviteLink.java new file mode 100644 index 0000000..677f38b --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatInviteLink.java @@ -0,0 +1,29 @@ +package hdvtdev.telegram.core.objects; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import org.jetbrains.annotations.NotNull; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record ChatInviteLink( + @JsonProperty("invite_link") String inviteLink, + @JsonProperty("creator") User creator, + @JsonProperty("creates_join_request") boolean createsJoinRequest, + @JsonProperty("is_primary") boolean isPrimary, + @JsonProperty("is_revoked") boolean isRevoked, + @JsonProperty("name") String name, + @JsonProperty("expire_date") long expireDate, + @JsonProperty("member_limit") int memberLimit, + @JsonProperty("pending_join_request_count") int pendingJoinRequestCount, + @JsonProperty("subscription_period") int subscriptionPeriod, + @JsonProperty("subscription_price") int subscriptionPrice +) { + @NotNull + @Override + public String toString() { + return this.inviteLink; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatJoinRequest.java b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatJoinRequest.java new file mode 100644 index 0000000..8ff0772 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatJoinRequest.java @@ -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 ChatJoinRequest( + @JsonProperty("chat") Chat chat, + @JsonProperty("from") User from, + @JsonProperty("user_chat_id") long userChatId, + @JsonProperty("date") long date, + @JsonProperty("bio") String bio, + @JsonProperty("invite_link") ChatInviteLink chatInviteLink +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatMember.java b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatMember.java new file mode 100644 index 0000000..fe32e82 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatMember.java @@ -0,0 +1,28 @@ +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 = "status" +) +@JsonSubTypes({ + @JsonSubTypes.Type(value = ChatMemberAdministrator.class, name = "administrator"), + @JsonSubTypes.Type(value = ChatMemberBanned.class, name = "kicked"), + @JsonSubTypes.Type(value = ChatMemberLeft.class, name = "left"), + @JsonSubTypes.Type(value = ChatMemberMember.class, name = "member"), + @JsonSubTypes.Type(value = ChatMemberOwner.class, name = "creator"), + @JsonSubTypes.Type(value = ChatMemberRestricted.class, name = "restricted"), +}) +public interface ChatMember { + User user(); + String status(); + + default ChatMemberAdministrator getAsChatMemberAdministrator() { + return (ChatMemberAdministrator) this; + } + +} + diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatMemberAdministrator.java b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatMemberAdministrator.java new file mode 100644 index 0000000..e3b69d3 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatMemberAdministrator.java @@ -0,0 +1,30 @@ +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 ChatMemberAdministrator( + @JsonProperty("status") String status, + @JsonProperty("user") User user, + @JsonProperty("can_be_edited") boolean canBeEdited, + @JsonProperty("is_anonymous") boolean isAnonymous, + @JsonProperty("can_manage_chat") boolean canManageChat, + @JsonProperty("can_delete_messages") boolean canDeleteMessages, + @JsonProperty("can_manage_video_chats") boolean canManageVideoChat, + @JsonProperty("can_restrict_members") boolean canRestrictMembers, + @JsonProperty("can_promote_members") boolean canPromoteMembers, + @JsonProperty("can_change_info") boolean canChangeInfo, + @JsonProperty("can_invite_users") boolean canInviteUsers, + @JsonProperty("can_post_stories") boolean canPostStories, + @JsonProperty("can_edit_stories") boolean canEditStories, + @JsonProperty("can_delete_stories") boolean canDeleteStories, + @JsonProperty("can_post_messages") boolean canPostMessages, + @JsonProperty("can_edit_messages") boolean canEditMessages, + @JsonProperty("can_pin_messages") boolean canPinMessages, + @JsonProperty("can_manage_topics") boolean canManageTopics, + @JsonProperty("custom_title") boolean hasCustomTitle +) implements ChatMember { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatMemberBanned.java b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatMemberBanned.java new file mode 100644 index 0000000..6c620b1 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatMemberBanned.java @@ -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 ChatMemberBanned( + @JsonProperty("status") String status, + @JsonProperty("user") User user, + @JsonProperty("until_date") long untilDate +) implements ChatMember { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatMemberLeft.java b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatMemberLeft.java new file mode 100644 index 0000000..c2c6173 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatMemberLeft.java @@ -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 ChatMemberLeft( + @JsonProperty("status") String status, + @JsonProperty("user") User user +) implements ChatMember { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatMemberMember.java b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatMemberMember.java new file mode 100644 index 0000000..d1c72b1 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatMemberMember.java @@ -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 ChatMemberMember( + @JsonProperty("status") String status, + @JsonProperty("user") User user, + @JsonProperty("until_date") long untilDate +) implements ChatMember { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatMemberOwner.java b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatMemberOwner.java new file mode 100644 index 0000000..15a79c9 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatMemberOwner.java @@ -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 ChatMemberOwner( + @JsonProperty("status") String status, + @JsonProperty("user") User user, + @JsonProperty("is_anonymous") boolean isAnonymous, + @JsonProperty("custom_title") String customTitle +) implements ChatMember { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatMemberRestricted.java b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatMemberRestricted.java new file mode 100644 index 0000000..cfc94d3 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatMemberRestricted.java @@ -0,0 +1,29 @@ +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 ChatMemberRestricted( + @JsonProperty("status") String status, + @JsonProperty("user") User user, + @JsonProperty("is_member") boolean isMember, + @JsonProperty("can_send_messages") boolean canSendMessage, + @JsonProperty("can_send_audios") boolean canSendAudios, + @JsonProperty("can_send_documents") boolean canSendDocuments, + @JsonProperty("can_send_photos") boolean canSendPhotos, + @JsonProperty("can_send_videos") boolean canSendVideos, + @JsonProperty("can_send_video_notes") boolean canSendVideoNotes, + @JsonProperty("can_send_voice_notes") boolean canSendVoiceNotes, + @JsonProperty("can_send_polls") boolean canSendPolls, + @JsonProperty("can_send_other_messages") boolean canSendOtherMessages, + @JsonProperty("can_add_web_page_previews") boolean canAddWebPagePreviews, + @JsonProperty("can_change_info") boolean canChangeInfo, + @JsonProperty("can_invite_users") boolean canInviteUsers, + @JsonProperty("can_pin_messages") boolean canPinMessages, + @JsonProperty("can_manage_topics") boolean canManageTopics, + @JsonProperty("until_date") long untilDate +) implements ChatMember { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatMemberUpdated.java b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatMemberUpdated.java new file mode 100644 index 0000000..ebd92be --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatMemberUpdated.java @@ -0,0 +1,19 @@ +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 ChatMemberUpdated( + @JsonProperty("chat") Chat chat, + @JsonProperty("from") User from, + @JsonProperty("date") long date, + @JsonProperty("old_chat_member") ChatMember oldChatMember, + @JsonProperty("new_chat_member") ChatMember newChatMember, + @JsonProperty("invite_link") ChatInviteLink chatInviteLink, + @JsonProperty("via_join_request") boolean viaJoinRequest, + @JsonProperty("via_chat_folder_invite_link") boolean viaChatFolderInviteLink +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatShared.java b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatShared.java new file mode 100644 index 0000000..5c0c9a0 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatShared.java @@ -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 ChatShared( + @JsonProperty("request_id") int requestId, + @JsonProperty("chat_id") long chatId, + @JsonProperty("title") String title, + @JsonProperty("username") String username, + @JsonProperty("photo") PhotoSize[] photo +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/chatboost/ChatBoost.java b/core/src/main/java/hdvtdev/telegram/core/objects/chatboost/ChatBoost.java new file mode 100644 index 0000000..c7a0bfb --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chatboost/ChatBoost.java @@ -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 ChatBoost( + @JsonProperty("boost_id") String boostId, + @JsonProperty("add_date") long addDate, + @JsonProperty("expiration_date") long expirationDate, + @JsonProperty("source") ChatBoostSource source +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/chatboost/ChatBoostAdded.java b/core/src/main/java/hdvtdev/telegram/core/objects/chatboost/ChatBoostAdded.java new file mode 100644 index 0000000..917b417 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chatboost/ChatBoostAdded.java @@ -0,0 +1,12 @@ +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 ChatBoostAdded( + @JsonProperty("boost_count") int boostCount +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/chatboost/ChatBoostRemoved.java b/core/src/main/java/hdvtdev/telegram/core/objects/chatboost/ChatBoostRemoved.java new file mode 100644 index 0000000..8f8cd8a --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chatboost/ChatBoostRemoved.java @@ -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 ChatBoostRemoved( + @JsonProperty("chat") Chat chat, + @JsonProperty("boost_id") String boostId, + @JsonProperty("remove_date") long removeDate, + @JsonProperty("source") ChatBoostSource source +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/chatboost/ChatBoostSource.java b/core/src/main/java/hdvtdev/telegram/core/objects/chatboost/ChatBoostSource.java new file mode 100644 index 0000000..3352393 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chatboost/ChatBoostSource.java @@ -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 = "source" +) +@JsonSubTypes({ + @JsonSubTypes.Type(value = ChatBoostSourcePremium.class, name = "premium"), + @JsonSubTypes.Type(value = ChatBoostSourceGiveaway.class, name = "giveaway"), + @JsonSubTypes.Type(value = ChatBoostSourceGiftCode.class, name = "gift_code") +}) +public interface ChatBoostSource { + String source(); +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/chatboost/ChatBoostSourceGiftCode.java b/core/src/main/java/hdvtdev/telegram/core/objects/chatboost/ChatBoostSourceGiftCode.java new file mode 100644 index 0000000..2c4addb --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chatboost/ChatBoostSourceGiftCode.java @@ -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 ChatBoostSourceGiftCode( + @JsonProperty("source") String source, + @JsonProperty("user") User user +) implements ChatBoostSource { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/chatboost/ChatBoostSourceGiveaway.java b/core/src/main/java/hdvtdev/telegram/core/objects/chatboost/ChatBoostSourceGiveaway.java new file mode 100644 index 0000000..69d90c6 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chatboost/ChatBoostSourceGiveaway.java @@ -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 ChatBoostSourceGiveaway( + @JsonProperty("source") String source, + @JsonProperty("giveaway_message_id") long giveawayMessageId, + @JsonProperty("user") User user, + @JsonProperty("prize_star_count") int prizeStarCount, + @JsonProperty("is_unclaimed") boolean isUnclaimed +) implements ChatBoostSource { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/chatboost/ChatBoostSourcePremium.java b/core/src/main/java/hdvtdev/telegram/core/objects/chatboost/ChatBoostSourcePremium.java new file mode 100644 index 0000000..a97339a --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chatboost/ChatBoostSourcePremium.java @@ -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 ChatBoostSourcePremium( + @JsonProperty("source") String source, + @JsonProperty("user") User user +) implements ChatBoostSource { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/chatboost/ChatBoostUpdated.java b/core/src/main/java/hdvtdev/telegram/core/objects/chatboost/ChatBoostUpdated.java new file mode 100644 index 0000000..fe965d6 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chatboost/ChatBoostUpdated.java @@ -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 ChatBoostUpdated( + @JsonProperty("chat") Chat chat, + @JsonProperty("boost") ChatBoost boost +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommand.java b/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommand.java new file mode 100644 index 0000000..a6b0845 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommand.java @@ -0,0 +1,13 @@ +package hdvtdev.telegram.core.objects.bot; + +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 BotCommand( + @JsonProperty("command") String name, + @JsonProperty("description") String description +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommandScope.java b/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommandScope.java new file mode 100644 index 0000000..8413da0 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommandScope.java @@ -0,0 +1,22 @@ +package hdvtdev.telegram.core.objects.bot; + +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 = BotCommandScopeDefault.class, name = "default"), + @JsonSubTypes.Type(value = BotCommandScopeAllPrivateChats.class, name = "all_private_chats"), + @JsonSubTypes.Type(value = BotCommandScopeAllGroupChats.class, name = "all_group_chats"), + @JsonSubTypes.Type(value = BotCommandScopeAllChatAdministrators.class, name = "all_chat_administrators"), + @JsonSubTypes.Type(value = BotCommandScopeChat.class, name = "chat"), + @JsonSubTypes.Type(value = BotCommandScopeChatAdministrators.class, name = "chat_administrators"), + @JsonSubTypes.Type(value = BotCommandScopeChatMember.class, name = "chat_member") +}) +public interface BotCommandScope { + String type(); +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommandScopeAllChatAdministrators.java b/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommandScopeAllChatAdministrators.java new file mode 100644 index 0000000..99df70b --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommandScopeAllChatAdministrators.java @@ -0,0 +1,10 @@ +package hdvtdev.telegram.core.objects.bot; + +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 BotCommandScopeAllChatAdministrators(@JsonProperty("type") String type) implements BotCommandScope { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommandScopeAllGroupChats.java b/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommandScopeAllGroupChats.java new file mode 100644 index 0000000..52febd0 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommandScopeAllGroupChats.java @@ -0,0 +1,10 @@ +package hdvtdev.telegram.core.objects.bot; + +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 BotCommandScopeAllGroupChats(@JsonProperty("type") String type) implements BotCommandScope { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommandScopeAllPrivateChats.java b/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommandScopeAllPrivateChats.java new file mode 100644 index 0000000..4bc5332 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommandScopeAllPrivateChats.java @@ -0,0 +1,10 @@ +package hdvtdev.telegram.core.objects.bot; + +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 BotCommandScopeAllPrivateChats(@JsonProperty("type") String type) implements BotCommandScope { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommandScopeChat.java b/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommandScopeChat.java new file mode 100644 index 0000000..0defde5 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommandScopeChat.java @@ -0,0 +1,14 @@ +package hdvtdev.telegram.core.objects.bot; + +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 BotCommandScopeChat(@JsonProperty("type") String type, + @JsonProperty("chat_id") String chatId) implements BotCommandScope { + public BotCommandScopeChat(@JsonProperty("type") String type, @JsonProperty("chat_id") long chatId) { + this(type, String.valueOf(chatId)); + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommandScopeChatAdministrators.java b/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommandScopeChatAdministrators.java new file mode 100644 index 0000000..9820090 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommandScopeChatAdministrators.java @@ -0,0 +1,14 @@ +package hdvtdev.telegram.core.objects.bot; + +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 BotCommandScopeChatAdministrators(@JsonProperty("type") String type, + @JsonProperty("chat_id") String chatId) implements BotCommandScope { + public BotCommandScopeChatAdministrators(@JsonProperty("type") String type, @JsonProperty("chat_id") long chatId) { + this(type, String.valueOf(chatId)); + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommandScopeChatMember.java b/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommandScopeChatMember.java new file mode 100644 index 0000000..7b2fbdc --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommandScopeChatMember.java @@ -0,0 +1,27 @@ +package hdvtdev.telegram.core.objects.bot; + +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 BotCommandScopeChatMember( + @JsonProperty("type") String type, + @JsonProperty("chat_id") String chatId, + @JsonProperty("user_id") long userId +) implements BotCommandScope { + + public BotCommandScopeChatMember(@JsonProperty("type") String type, @JsonProperty("chat_id") long chatId, @JsonProperty("user_id") long userId) { + this(type, String.valueOf(chatId), userId); + } + + public BotCommandScopeChatMember(@JsonProperty("type") String type, @JsonProperty("chat_id") long chatId, @JsonProperty("user_id") String userId) { + this(type, String.valueOf(chatId), Long.parseLong(userId)); + } + + public BotCommandScopeChatMember(@JsonProperty("type") String type, @JsonProperty("chat_id") String chatId, @JsonProperty("user_id") String userId) { + this(type, chatId, Long.parseLong(userId)); + } + +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommandScopeDefault.java b/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommandScopeDefault.java new file mode 100644 index 0000000..9e8f73d --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommandScopeDefault.java @@ -0,0 +1,10 @@ +package hdvtdev.telegram.core.objects.bot; + +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 BotCommandScopeDefault(@JsonProperty("type") String type) implements BotCommandScope { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/forum/ForumTopicClosed.java b/core/src/main/java/hdvtdev/telegram/core/objects/forum/ForumTopicClosed.java new file mode 100644 index 0000000..c1363d9 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/forum/ForumTopicClosed.java @@ -0,0 +1,9 @@ +package hdvtdev.telegram.core.objects; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record ForumTopicClosed() { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/forum/ForumTopicCreated.java b/core/src/main/java/hdvtdev/telegram/core/objects/forum/ForumTopicCreated.java new file mode 100644 index 0000000..251cff6 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/forum/ForumTopicCreated.java @@ -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 ForumTopicCreated( + @JsonProperty("name") String name, + @JsonProperty("icon_color") int iconColor, + @JsonProperty("icon_custom_emoji_id") String iconCustomEmojiId +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/forum/ForumTopicEdited.java b/core/src/main/java/hdvtdev/telegram/core/objects/forum/ForumTopicEdited.java new file mode 100644 index 0000000..fb5d498 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/forum/ForumTopicEdited.java @@ -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 ForumTopicEdited( + @JsonProperty("name") String name, + @JsonProperty("icon_custom_emoji_id") String iconCustomEmojiId +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/forum/ForumTopicReopened.java b/core/src/main/java/hdvtdev/telegram/core/objects/forum/ForumTopicReopened.java new file mode 100644 index 0000000..9d025e1 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/forum/ForumTopicReopened.java @@ -0,0 +1,9 @@ +package hdvtdev.telegram.core.objects; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record ForumTopicReopened() { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/forum/GeneralForumTopicHidden.java b/core/src/main/java/hdvtdev/telegram/core/objects/forum/GeneralForumTopicHidden.java new file mode 100644 index 0000000..78bae5d --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/forum/GeneralForumTopicHidden.java @@ -0,0 +1,9 @@ +package hdvtdev.telegram.core.objects; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record GeneralForumTopicHidden() { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/forum/GeneralForumTopicUnhidden.java b/core/src/main/java/hdvtdev/telegram/core/objects/forum/GeneralForumTopicUnhidden.java new file mode 100644 index 0000000..1469725 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/forum/GeneralForumTopicUnhidden.java @@ -0,0 +1,9 @@ +package hdvtdev.telegram.core.objects; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record GeneralForumTopicUnhidden() { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/giveaway/Giveaway.java b/core/src/main/java/hdvtdev/telegram/core/objects/giveaway/Giveaway.java new file mode 100644 index 0000000..955e52c --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/giveaway/Giveaway.java @@ -0,0 +1,21 @@ +package hdvtdev.telegram.core.objects; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.chat.Chat; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record Giveaway( + @JsonProperty("chats") Chat[] chats, + @JsonProperty("winners_selection_date") long winnersSelectionDate, + @JsonProperty("winner_count") int winnerCount, + @JsonProperty("only_new_members") boolean onlyNewMembers, + @JsonProperty("has_public_winners") boolean hasPublicWinners, + @JsonProperty("prize_description") String prizeDescription, + @JsonProperty("country_codes") String[] countryCodes, + @JsonProperty("prize_star_count") int prizeStarCount, + @JsonProperty("premium_subscription_month_count") int premiumSubscriptionMonthCount +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/giveaway/GiveawayCompleted.java b/core/src/main/java/hdvtdev/telegram/core/objects/giveaway/GiveawayCompleted.java new file mode 100644 index 0000000..22bee08 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/giveaway/GiveawayCompleted.java @@ -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; +import hdvtdev.telegram.core.objects.message.Message; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record GiveawayCompleted( + @JsonProperty("winner_count") int winnerCount, + @JsonProperty("unclaimed_prize_count") int unclaimedPrizeCount, + @JsonProperty("giveaway_message") Message giveawayMessage, + @JsonProperty("is_star_giveaway") boolean isStarGiveaway +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/giveaway/GiveawayCreated.java b/core/src/main/java/hdvtdev/telegram/core/objects/giveaway/GiveawayCreated.java new file mode 100644 index 0000000..30312b9 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/giveaway/GiveawayCreated.java @@ -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 GiveawayCreated(@JsonProperty("prize_star_count") int prizeStarCount) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/giveaway/GiveawayWinners.java b/core/src/main/java/hdvtdev/telegram/core/objects/giveaway/GiveawayWinners.java new file mode 100644 index 0000000..c356fb4 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/giveaway/GiveawayWinners.java @@ -0,0 +1,24 @@ +package hdvtdev.telegram.core.objects; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.chat.Chat; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record GiveawayWinners( + @JsonProperty("chat") Chat chat, + @JsonProperty("giveaway_message_id") long giveawayMessageId, + @JsonProperty("winners_selection_date") long winnersSelectionDate, + @JsonProperty("winners_count") int winnersCount, + @JsonProperty("winners") User[] winners, + @JsonProperty("additional_chat_count") int additionalChatCount, + @JsonProperty("prize_star_count") int prizeStarCount, + @JsonProperty("premium_subscription_month_count") int premiumSubscriptionMonthCount, + @JsonProperty("unclaimed_prize_count") int unclaimedPrizeCount, + @JsonProperty("only_new_members") boolean onlyNewMembers, + @JsonProperty("was_refunded") boolean wasRefunded, + @JsonProperty("prize_description") String prizeDescription +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/markup/CopyTextButton.java b/core/src/main/java/hdvtdev/telegram/core/objects/markup/CopyTextButton.java new file mode 100644 index 0000000..d770957 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/markup/CopyTextButton.java @@ -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 CopyTextButton(@JsonProperty("text") String text) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/markup/ForceReply.java b/core/src/main/java/hdvtdev/telegram/core/objects/markup/ForceReply.java new file mode 100644 index 0000000..52edddc --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/markup/ForceReply.java @@ -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; +import hdvtdev.telegram.core.objects.markup.ReplyMarkup; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record ForceReply( + @JsonProperty("force_reply") boolean forceReply, + @JsonProperty("input_field_placeholder") String inputFieldPlaceholder, + @JsonProperty("selective") boolean selective +) implements ReplyMarkup { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/markup/InlineKeyboardButton.java b/core/src/main/java/hdvtdev/telegram/core/objects/markup/InlineKeyboardButton.java new file mode 100644 index 0000000..a4e7586 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/markup/InlineKeyboardButton.java @@ -0,0 +1,250 @@ +package hdvtdev.telegram.core.objects; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public final class InlineKeyboardButton { + + @JsonProperty("text") + private final String text; + @JsonProperty("url") + private String url; + @JsonProperty("callback_data") + private String callbackData; + @JsonProperty("web_app") + private WebAppInfo webApp; + @JsonProperty("login_url") + private LoginUrl loginUrl; + @JsonProperty("switch_inline_query") + private String switchInlineQuery; + @JsonProperty("switch_inline_query_current_chat") + private String switchInlineQueryCurrentChat; + @JsonProperty("switch_inline_query_chosen_chat") + private SwitchInlineQueryChosenChat switchInlineQueryChosenChat; + @JsonProperty("copy_text") + private CopyTextButton copyTextButton; + @JsonProperty("callback_game") + private CallbackGame callbackGame; + @JsonProperty("pay") + private Boolean pay; + + @JsonCreator + public InlineKeyboardButton( + @JsonProperty("text") String text, + @JsonProperty("url") String url, + @JsonProperty("callback_data") String callbackData, + @JsonProperty("web_app") WebAppInfo webApp, + @JsonProperty("login_url") LoginUrl loginUrl, + @JsonProperty("switch_inline_query") String switchInlineQuery, + @JsonProperty("switch_inline_query_current_chat") String switchInlineQueryCurrentChat, + @JsonProperty("switch_inline_query_chosen_chat") SwitchInlineQueryChosenChat switchInlineQueryChosenChat, + @JsonProperty("copy_text") CopyTextButton copyTextButton, + @JsonProperty("callback_game") CallbackGame callbackGame, + @JsonProperty("pay") Boolean pay + ) { + this.text = text; + this.url = url; + this.callbackData = callbackData; + this.webApp = webApp; + this.loginUrl = loginUrl; + this.switchInlineQuery = switchInlineQuery; + this.switchInlineQueryCurrentChat = switchInlineQueryCurrentChat; + this.switchInlineQueryChosenChat = switchInlineQueryChosenChat; + this.copyTextButton = copyTextButton; + this.callbackGame = callbackGame; + this.pay = pay; + } + + private InlineKeyboardButton(Builder builder) { + this.text = builder.text; + setUrl(builder.url); + setCallbackData(builder.callbackData); + setWebApp(builder.webApp); + setLoginUrl(builder.loginUrl); + setSwitchInlineQuery(builder.switchInlineQuery); + setSwitchInlineQueryCurrentChat(builder.switchInlineQueryCurrentChat); + setSwitchInlineQueryChosenChat(builder.switchInlineQueryChosenChat); + setCopyTextButton(builder.copyTextButton); + setCallbackGame(builder.callbackGame); + setPay(builder.pay); + } + + public InlineKeyboardButton(String text) { + this.text = text; + } + + public InlineKeyboardButton(String text, String data) { + this.text = text; + this.callbackData = data; + } + + @JsonIgnore + public String getText() { + return text; + } + + @JsonIgnore + public String getUrl() { + return url; + } + + @JsonIgnore + public String getCallbackData() { + return callbackData; + } + + @JsonIgnore + public WebAppInfo getWebApp() { + return webApp; + } + + @JsonIgnore + public LoginUrl getLoginUrl() { + return loginUrl; + } + + @JsonIgnore + public String getSwitchInlineQuery() { + return switchInlineQuery; + } + + @JsonIgnore + public String getSwitchInlineQueryCurrentChat() { + return switchInlineQueryCurrentChat; + } + + @JsonIgnore + public SwitchInlineQueryChosenChat getSwitchInlineQueryChosenChat() { + return switchInlineQueryChosenChat; + } + + @JsonIgnore + public CopyTextButton getCopyTextButton() { + return copyTextButton; + } + + @JsonIgnore + public CallbackGame getCallbackGame() { + return callbackGame; + } + + @JsonIgnore + public Boolean getPay() { + return pay; + } + + public void setUrl(String url) { + this.url = url; + } + + public void setCallbackData(String callbackData) { + this.callbackData = callbackData; + } + + public void setWebApp(WebAppInfo webApp) { + this.webApp = webApp; + } + + public void setLoginUrl(LoginUrl loginUrl) { + this.loginUrl = loginUrl; + } + + public void setSwitchInlineQuery(String switchInlineQuery) { + this.switchInlineQuery = switchInlineQuery; + } + + public void setSwitchInlineQueryCurrentChat(String switchInlineQueryCurrentChat) { + this.switchInlineQueryCurrentChat = switchInlineQueryCurrentChat; + } + + public void setSwitchInlineQueryChosenChat(SwitchInlineQueryChosenChat switchInlineQueryChosenChat) { + this.switchInlineQueryChosenChat = switchInlineQueryChosenChat; + } + + public void setCopyTextButton(CopyTextButton copyTextButton) { + this.copyTextButton = copyTextButton; + } + + public void setCallbackGame(CallbackGame callbackGame) { + this.callbackGame = callbackGame; + } + + public void setPay(Boolean pay) { + this.pay = pay; + } + + public static final class Builder { + private final String text; + private String url; + private String callbackData; + private WebAppInfo webApp; + private LoginUrl loginUrl; + private String switchInlineQuery; + private String switchInlineQueryCurrentChat; + private SwitchInlineQueryChosenChat switchInlineQueryChosenChat; + private CopyTextButton copyTextButton; + private CallbackGame callbackGame; + private Boolean pay; + + public Builder(String text) { + this.text = text; + } + + public Builder pay(boolean pay) { + this.pay = pay; + return this; + } + + public Builder url(String url) { + this.url = url; + return this; + } + + public Builder callbackData(String callbackData) { + this.callbackData = callbackData; + return this; + } + + public Builder webApp(WebAppInfo webApp) { + this.webApp = webApp; + return this; + } + + public Builder loginUrl(LoginUrl loginUrl) { + this.loginUrl = loginUrl; + return this; + } + + public Builder switchInlineQuery(String switchInlineQuery) { + this.switchInlineQuery = switchInlineQuery; + return this; + } + + public Builder switchInlineQueryCurrentChat(String switchInlineQueryCurrentChat) { + this.switchInlineQueryCurrentChat = switchInlineQueryCurrentChat; + return this; + } + + public Builder switchInlineQueryChosenChat(SwitchInlineQueryChosenChat switchInlineQueryChosenChat) { + this.switchInlineQueryChosenChat = switchInlineQueryChosenChat; + return this; + } + + public Builder copyTextButton(CopyTextButton copyTextButton) { + this.copyTextButton = copyTextButton; + return this; + } + + public Builder callbackGame(CallbackGame callbackGame) { + this.callbackGame = callbackGame; + return this; + } + + public InlineKeyboardButton build() { + return new InlineKeyboardButton(this); + } + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/markup/InlineKeyboardMarkup.java b/core/src/main/java/hdvtdev/telegram/core/objects/markup/InlineKeyboardMarkup.java new file mode 100644 index 0000000..9eae0f4 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/markup/InlineKeyboardMarkup.java @@ -0,0 +1,35 @@ +package hdvtdev.telegram.core.objects; + +import com.fasterxml.jackson.annotation.*; + +import java.util.List; + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public record InlineKeyboardMarkup( + @JsonProperty("inline_keyboard") InlineKeyboardRow... keyboard) implements ReplyMarkup { + + @JsonCreator + public InlineKeyboardMarkup(@JsonProperty("inline_keyboard") InlineKeyboardButton[][] keyboardButtons) { + this(convertToInlineKeyboardRow(keyboardButtons)); + } + + public InlineKeyboardMarkup(List inlineKeyboardRows) { + this(inlineKeyboardRows.toArray(new InlineKeyboardRow[0])); + } + + @JsonIgnore + private static InlineKeyboardRow[] convertToInlineKeyboardRow(InlineKeyboardButton[][] keyboardButtons) { + InlineKeyboardRow[] rows = new InlineKeyboardRow[keyboardButtons.length]; + for (int i = 0; i < keyboardButtons.length; i++) { + rows[i] = new InlineKeyboardRow(keyboardButtons[i]); + } + return rows; + } + + @JsonIgnore + public static InlineKeyboardMarkup ofSingleButton(InlineKeyboardButton button) { + return new InlineKeyboardMarkup(new InlineKeyboardRow(button)); + } + +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/markup/InlineKeyboardRow.java b/core/src/main/java/hdvtdev/telegram/core/objects/markup/InlineKeyboardRow.java new file mode 100644 index 0000000..f951109 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/markup/InlineKeyboardRow.java @@ -0,0 +1,69 @@ +package hdvtdev.telegram.core.objects; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonValue; +import org.jetbrains.annotations.NotNull; + +import java.util.AbstractList; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + + +public final class InlineKeyboardRow extends AbstractList { + + @JsonIgnore + private final ArrayList buttonsList = new ArrayList<>(); + + public InlineKeyboardRow() { + + } + + public InlineKeyboardButton remove(int i) { + return this.buttonsList.remove(i); + } + + @JsonIgnore + @Override + public void clear() { + this.buttonsList.clear(); + } + + @JsonIgnore + @Override + public int size() { + return this.buttonsList.size(); + } + + @JsonIgnore + @Override + public boolean addAll(@NotNull Collection buttons) { + return this.buttonsList.addAll(buttons); + } + + public void addAll(InlineKeyboardButton... buttons) { + this.buttonsList.addAll(List.of(buttons)); + } + + public InlineKeyboardRow(InlineKeyboardButton... buttons) { + this.buttonsList.addAll(List.of(buttons)); + } + + @JsonIgnore + @Override + public boolean add(InlineKeyboardButton button) { + return this.buttonsList.add(button); + } + + @JsonIgnore + @Override + public InlineKeyboardButton get(int i) { + return this.buttonsList.get(i); + } + + @JsonValue + public List buttons() { + return buttonsList; + } + +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/markup/KeyboardButton.java b/core/src/main/java/hdvtdev/telegram/core/objects/markup/KeyboardButton.java new file mode 100644 index 0000000..f653db7 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/markup/KeyboardButton.java @@ -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 KeyboardButton( + @JsonProperty("text") String text, + @JsonProperty("request_users") KeyboardButtonRequestUsers requestUsers, + @JsonProperty("request_chat") KeyboardButtonRequestChat requestChat, + @JsonProperty("request_contact") boolean requestContact, + @JsonProperty("request_location") boolean requestLocation, + @JsonProperty("request_poll") KeyboardButtonPollType requestPoll, + @JsonProperty("web_app") WebAppInfo webApp +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/markup/KeyboardButtonPollType.java b/core/src/main/java/hdvtdev/telegram/core/objects/markup/KeyboardButtonPollType.java new file mode 100644 index 0000000..74be5d4 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/markup/KeyboardButtonPollType.java @@ -0,0 +1,12 @@ +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 KeyboardButtonPollType( + @JsonProperty("type") String type +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/markup/KeyboardButtonRequestChat.java b/core/src/main/java/hdvtdev/telegram/core/objects/markup/KeyboardButtonRequestChat.java new file mode 100644 index 0000000..90c805f --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/markup/KeyboardButtonRequestChat.java @@ -0,0 +1,23 @@ +package hdvtdev.telegram.core.objects; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.chat.ChatAdministratorRights; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record KeyboardButtonRequestChat( + @JsonProperty("request_id") Integer requestId, + @JsonProperty("chat_is_channel") boolean chatIsChannel, + @JsonProperty("chat_is_forum") boolean chatIsForum, + @JsonProperty("chat_has_username") boolean chatHasUsername, + @JsonProperty("chat_is_created") boolean chatIsCreated, + @JsonProperty("user_administrator_rights") ChatAdministratorRights userAdministratorRights, + @JsonProperty("bot_administrator_rights") ChatAdministratorRights botAdministratorRights, + @JsonProperty("bot_is_member") boolean botIsMember, + @JsonProperty("request_title") boolean requestTitle, + @JsonProperty("request_username") boolean requestUsername, + @JsonProperty("request_photo") boolean requestPhoto +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/markup/KeyboardButtonRequestUsers.java b/core/src/main/java/hdvtdev/telegram/core/objects/markup/KeyboardButtonRequestUsers.java new file mode 100644 index 0000000..022c06b --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/markup/KeyboardButtonRequestUsers.java @@ -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 KeyboardButtonRequestUsers( + @JsonProperty("request_id") Integer requestId, + @JsonProperty("user_is_bot") boolean userIsBot, + @JsonProperty("user_is_premium") boolean userIsPremium, + @JsonProperty("max_quantity") Integer maxQuantity, + @JsonProperty("request_name") Boolean requestName, + @JsonProperty("request_username") Boolean requestUsername, + @JsonProperty("request_photo") Boolean requestPhoto +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/markup/ReplyKeyboardMarkup.java b/core/src/main/java/hdvtdev/telegram/core/objects/markup/ReplyKeyboardMarkup.java new file mode 100644 index 0000000..af1be9e --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/markup/ReplyKeyboardMarkup.java @@ -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 ReplyKeyboardMarkup( + @JsonProperty("keyboard") KeyboardButton[][] keyboard, + @JsonProperty("is_persistent") boolean isPersistent, + @JsonProperty("resize_keyboard") boolean resizeKeyboard, + @JsonProperty("one_time_keyboard") boolean oneTimeKeyboard, + @JsonProperty("input_field_placeholder") String inputFieldPlaceholder, + @JsonProperty("selective") boolean selective +) implements ReplyMarkup { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/markup/ReplyKeyboardRemove.java b/core/src/main/java/hdvtdev/telegram/core/objects/markup/ReplyKeyboardRemove.java new file mode 100644 index 0000000..e320039 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/markup/ReplyKeyboardRemove.java @@ -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 ReplyKeyboardRemove( + @JsonProperty("remove_keyboard") boolean removeKeyboard, + @JsonProperty("selective") boolean selective +) implements ReplyMarkup { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/markup/ReplyMarkup.java b/core/src/main/java/hdvtdev/telegram/core/objects/markup/ReplyMarkup.java new file mode 100644 index 0000000..9325e99 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/markup/ReplyMarkup.java @@ -0,0 +1,16 @@ +package hdvtdev.telegram.core.objects; + +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; + +@JsonTypeInfo( + use = JsonTypeInfo.Id.DEDUCTION, + defaultImpl = Void.class +) +@JsonSubTypes({ + @JsonSubTypes.Type(value = ReplyKeyboardMarkup.class), + @JsonSubTypes.Type(value = InlineKeyboardMarkup.class), + @JsonSubTypes.Type(value = ReplyKeyboardRemove.class) +}) +public interface ReplyMarkup { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/markup/SwitchInlineQueryChosenChat.java b/core/src/main/java/hdvtdev/telegram/core/objects/markup/SwitchInlineQueryChosenChat.java new file mode 100644 index 0000000..65044dd --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/markup/SwitchInlineQueryChosenChat.java @@ -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 SwitchInlineQueryChosenChat( + @JsonProperty("query") String query, + @JsonProperty("allow_user_chats") boolean allowUserChats, + @JsonProperty("allow_bot_chats") boolean allowBotChats, + @JsonProperty("allow_group_chats") boolean allowGroupChats, + @JsonProperty("allow_channel_chats") boolean allowChannelChats +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/media/Animation.java b/core/src/main/java/hdvtdev/telegram/core/objects/media/Animation.java new file mode 100644 index 0000000..693eaf1 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/Animation.java @@ -0,0 +1,37 @@ +package hdvtdev.telegram.core.objects; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public record Animation( + @JsonProperty("file_id") String fileId, + @JsonProperty("file_unique_id") String fileUniqueId, + @JsonProperty("width") int width, + @JsonProperty("height") int height, + @JsonProperty("duration") int duration, + @JsonProperty("thumbnail") PhotoSize thumbnail, + @JsonProperty("file_name") String fileName, + @JsonProperty("mime_type") String mimeType, + @JsonProperty("file_size") Long fileSize +) { + + public boolean hasThumbnail() { + return this.thumbnail != null; + } + + public boolean hasFileName() { + return this.fileName != null; + } + + public boolean hasMimeType() { + return this.mimeType != null; + } + + public boolean hasFileSize() { + return this.fileSize != null; + } + +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/media/Audio.java b/core/src/main/java/hdvtdev/telegram/core/objects/media/Audio.java new file mode 100644 index 0000000..0d27c8c --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/Audio.java @@ -0,0 +1,37 @@ +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 Audio( + @JsonProperty("file_id") String fileId, + @JsonProperty("file_unique_id") String fileUniqueId, + @JsonProperty("duration") int duration, + @JsonProperty("performer") String performer, + @JsonProperty("title") String title, + @JsonProperty("file_name") String fileName, + @JsonProperty("mime_type") String mimeType, + @JsonProperty("file_size") Long fileSize, + @JsonProperty("thumbnail") PhotoSize thumbnail +) { + + public boolean hasThumbnail() { + return this.thumbnail != null; + } + + public boolean hasFileName() { + return this.fileName != null; + } + + public boolean hasMimeType() { + return this.mimeType != null; + } + + public boolean hasFileSize() { + return this.fileSize != null; + } + +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/media/Document.java b/core/src/main/java/hdvtdev/telegram/core/objects/media/Document.java new file mode 100644 index 0000000..230e080 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/Document.java @@ -0,0 +1,21 @@ +package hdvtdev.telegram.core.objects; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.methods.GetFile; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record Document( + @JsonProperty("file_id") String fileId, + @JsonProperty("file_unique_id") String fileUniqueId, + @JsonProperty("thumbnail") PhotoSize thumbnail, + @JsonProperty("file_name") String fileName, + @JsonProperty("mime_type") String mimeType, + @JsonProperty("file_size") long fileSize +) { + public GetFile getFile() { + return new GetFile(this.fileId); + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/media/PhotoSize.java b/core/src/main/java/hdvtdev/telegram/core/objects/media/PhotoSize.java new file mode 100644 index 0000000..1337781 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/PhotoSize.java @@ -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 PhotoSize( + @JsonProperty("file_id") String fileId, + @JsonProperty("file_unique_id") String fileUniqueId, + @JsonProperty("width") int width, + @JsonProperty("height") int height, + @JsonProperty("file_size") long file_size +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/media/Sticker.java b/core/src/main/java/hdvtdev/telegram/core/objects/media/Sticker.java new file mode 100644 index 0000000..ae66739 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/Sticker.java @@ -0,0 +1,26 @@ +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 Sticker( + @JsonProperty("file_id") String fileId, + @JsonProperty("file_unique_id") String fileUniqueId, + @JsonProperty("type") String type, + @JsonProperty("width") int width, + @JsonProperty("height") int height, + @JsonProperty("is_animated") boolean isAnimated, + @JsonProperty("is_video") boolean isVideo, + @JsonProperty("thumbnail") PhotoSize thumbnail, + @JsonProperty("emoji") String emoji, + @JsonProperty("set_name") String setName, + @JsonProperty("premium_animation") TelegramFile premiumAnimation, + @JsonProperty("mask_position") MaskPosition maskPosition, + @JsonProperty("custom_emoji_id") String customEmojiId, + @JsonProperty("needs_repairing") boolean needsRepairing, + @JsonProperty("file_size") long fileSize +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/media/Story.java b/core/src/main/java/hdvtdev/telegram/core/objects/media/Story.java new file mode 100644 index 0000000..fd95027 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/Story.java @@ -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; +import hdvtdev.telegram.core.objects.chat.Chat; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record Story( + @JsonProperty("chat") Chat chat, + @JsonProperty("id") long id +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/media/TelegramFile.java b/core/src/main/java/hdvtdev/telegram/core/objects/media/TelegramFile.java new file mode 100644 index 0000000..60426f1 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/TelegramFile.java @@ -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; +import com.fasterxml.jackson.annotation.JsonRootName; + +@JsonRootName("file") +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record TelegramFile( + @JsonProperty("file_id") String fileId, + @JsonProperty("file_unique_id") String fileUniqueId, + @JsonProperty("file_size") long fileSize, + @JsonProperty("file_path") String filePath //link to file +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/media/Voice.java b/core/src/main/java/hdvtdev/telegram/core/objects/media/Voice.java new file mode 100644 index 0000000..6fc5d3c --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/Voice.java @@ -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 Voice( + @JsonProperty("file_id") String fileId, + @JsonProperty("file_unique_id") String fileUniqueId, + @JsonProperty("duration") int duration, + @JsonProperty("mime_type") String mimeType, + @JsonProperty("file_size") long fileSize +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/media/paidmedia/PaidMedia.java b/core/src/main/java/hdvtdev/telegram/core/objects/media/paidmedia/PaidMedia.java new file mode 100644 index 0000000..405cf76 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/paidmedia/PaidMedia.java @@ -0,0 +1,17 @@ +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 = PaidMediaPreview.class, name = "preview"), + @JsonSubTypes.Type(value = PaidMediaPhoto.class, name = "photo"), + @JsonSubTypes.Type(value = PaidMediaVideo.class, name = "video") +}) +public interface PaidMedia { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/media/paidmedia/PaidMediaInfo.java b/core/src/main/java/hdvtdev/telegram/core/objects/media/paidmedia/PaidMediaInfo.java new file mode 100644 index 0000000..34a488a --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/paidmedia/PaidMediaInfo.java @@ -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 PaidMediaInfo( + @JsonProperty("star_count") int startCount, + @JsonProperty("paid_media") PaidMedia[] paidMedia +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/media/paidmedia/PaidMediaPhoto.java b/core/src/main/java/hdvtdev/telegram/core/objects/media/paidmedia/PaidMediaPhoto.java new file mode 100644 index 0000000..a952f23 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/paidmedia/PaidMediaPhoto.java @@ -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 PaidMediaPhoto( + @JsonProperty("type") String type, + @JsonProperty("photo") PhotoSize[] photo +) implements PaidMedia { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/media/paidmedia/PaidMediaPreview.java b/core/src/main/java/hdvtdev/telegram/core/objects/media/paidmedia/PaidMediaPreview.java new file mode 100644 index 0000000..f4464e7 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/paidmedia/PaidMediaPreview.java @@ -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 PaidMediaPreview( + @JsonProperty("type") String type, + @JsonProperty("width") int width, + @JsonProperty("height") int height, + @JsonProperty("duration") int duration +) implements PaidMedia { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/media/paidmedia/PaidMediaPurchased.java b/core/src/main/java/hdvtdev/telegram/core/objects/media/paidmedia/PaidMediaPurchased.java new file mode 100644 index 0000000..841da3b --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/paidmedia/PaidMediaPurchased.java @@ -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 PaidMediaPurchased( + @JsonProperty("from") User from, + @JsonProperty("paid_media_payload") String paidMediaPayload +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/media/paidmedia/PaidMediaVideo.java b/core/src/main/java/hdvtdev/telegram/core/objects/media/paidmedia/PaidMediaVideo.java new file mode 100644 index 0000000..b32b07e --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/paidmedia/PaidMediaVideo.java @@ -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 PaidMediaVideo( + @JsonProperty("type") String type, + @JsonProperty("video") Video video +) implements PaidMedia { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/media/video/Video.java b/core/src/main/java/hdvtdev/telegram/core/objects/media/video/Video.java new file mode 100644 index 0000000..4cddbd3 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/video/Video.java @@ -0,0 +1,22 @@ +package hdvtdev.telegram.core.objects.media; + +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 Video( + @JsonProperty("file_id") String fileId, + @JsonProperty("file_unique_id") String fileUniqueId, + @JsonProperty("width") int width, + @JsonProperty("height") int height, + @JsonProperty("duration") int duration, + @JsonProperty("thumbnail") PhotoSize thumbnail, + @JsonProperty("cover") PhotoSize[] cover, + @JsonProperty("start_timestamp") int startTimestamp, + @JsonProperty("file_name") String fileName, + @JsonProperty("mime_type") String mimeType, + @JsonProperty("file_size") long fileSize +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/media/video/VideoChatEnded.java b/core/src/main/java/hdvtdev/telegram/core/objects/media/video/VideoChatEnded.java new file mode 100644 index 0000000..47c6741 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/video/VideoChatEnded.java @@ -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 VideoChatEnded(@JsonProperty("duration") long duration) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/media/video/VideoChatParticipantsInvited.java b/core/src/main/java/hdvtdev/telegram/core/objects/media/video/VideoChatParticipantsInvited.java new file mode 100644 index 0000000..4c43c69 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/video/VideoChatParticipantsInvited.java @@ -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 VideoChatParticipantsInvited(@JsonProperty("users") User[] users) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/media/video/VideoChatScheduled.java b/core/src/main/java/hdvtdev/telegram/core/objects/media/video/VideoChatScheduled.java new file mode 100644 index 0000000..dff9e28 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/video/VideoChatScheduled.java @@ -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 VideoChatScheduled(@JsonProperty("start_date") long startDate) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/media/video/VideoChatStarted.java b/core/src/main/java/hdvtdev/telegram/core/objects/media/video/VideoChatStarted.java new file mode 100644 index 0000000..82bc832 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/video/VideoChatStarted.java @@ -0,0 +1,9 @@ +package hdvtdev.telegram.core.objects; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record VideoChatStarted() { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/media/video/VideoNote.java b/core/src/main/java/hdvtdev/telegram/core/objects/media/video/VideoNote.java new file mode 100644 index 0000000..d2f1c3f --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/video/VideoNote.java @@ -0,0 +1,17 @@ +package hdvtdev.telegram.core.objects.media; + +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 VideoNote( + @JsonProperty("file_id") String fileId, + @JsonProperty("file_unique_id") String fileUniqueId, + @JsonProperty("length") long length, + @JsonProperty("duration") int duration, + @JsonProperty("thumbnail") PhotoSize thumbnail, + @JsonProperty("file_size") long fileSize +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/message/ExternalReplyInfo.java b/core/src/main/java/hdvtdev/telegram/core/objects/message/ExternalReplyInfo.java new file mode 100644 index 0000000..9cecc55 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/message/ExternalReplyInfo.java @@ -0,0 +1,46 @@ +package hdvtdev.telegram.core.objects; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.chat.Chat; +import hdvtdev.telegram.core.objects.giveaway.Giveaway; +import hdvtdev.telegram.core.objects.giveaway.GiveawayWinners; +import hdvtdev.telegram.core.objects.media.*; +import hdvtdev.telegram.core.objects.media.paidmedia.PaidMediaInfo; +import hdvtdev.telegram.core.objects.media.video.Video; +import hdvtdev.telegram.core.objects.media.video.VideoNote; +import hdvtdev.telegram.core.objects.message.LinkPreviewOptions; +import hdvtdev.telegram.core.objects.message.MessageOrigin; +import hdvtdev.telegram.core.objects.payment.Invoice; +import hdvtdev.telegram.core.objects.poll.Poll; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record ExternalReplyInfo( + @JsonProperty("origin") MessageOrigin origin, + @JsonProperty("chat") Chat chat, + @JsonProperty("message_id") long messageId, + @JsonProperty("link_preview_options") LinkPreviewOptions linkPreviewOptions, + @JsonProperty("animation") Animation animation, + @JsonProperty("audio") Audio audio, + @JsonProperty("document") Document document, + @JsonProperty("paid_media") PaidMediaInfo paidMediaInfo, + @JsonProperty("photo") PhotoSize[] photo, + @JsonProperty("sticker") Sticker sticker, + @JsonProperty("story") Story story, + @JsonProperty("video") Video video, + @JsonProperty("video_note") VideoNote videoNote, + @JsonProperty("voice") Voice voice, + @JsonProperty("has_media_spoiler") boolean hasMediaSpoiler, + @JsonProperty("contact") Contact contact, + @JsonProperty("dice") Dice dice, + @JsonProperty("game") Game game, + @JsonProperty("giveaway") Giveaway giveaway, + @JsonProperty("giveaway_winners") GiveawayWinners giveawayWinners, + @JsonProperty("invoice") Invoice invoice, + @JsonProperty("location") Location location, + @JsonProperty("poll") Poll poll, + @JsonProperty("venue") Venue venue +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/message/InaccessibleMessage.java b/core/src/main/java/hdvtdev/telegram/core/objects/message/InaccessibleMessage.java new file mode 100644 index 0000000..5c106ae --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/message/InaccessibleMessage.java @@ -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 InaccessibleMessage(Chat chat, @JsonProperty("message_id") int messageId, + long date) implements MaybeInaccessibleMessage { + @Override + public long chatId() { + return chat.id(); + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/message/LinkPreviewOptions.java b/core/src/main/java/hdvtdev/telegram/core/objects/message/LinkPreviewOptions.java new file mode 100644 index 0000000..f1af977 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/message/LinkPreviewOptions.java @@ -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 LinkPreviewOptions( + @JsonProperty("is_disabled") boolean isDisabled, + @JsonProperty("url") String url, + @JsonProperty("prefer_small_media") boolean preferSmallMedia, + @JsonProperty("prefer_large_media") boolean preferLargeMedia, + @JsonProperty("show_above_text") boolean showAboveText + +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/message/MaybeInaccessibleMessage.java b/core/src/main/java/hdvtdev/telegram/core/objects/message/MaybeInaccessibleMessage.java new file mode 100644 index 0000000..701308c --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/message/MaybeInaccessibleMessage.java @@ -0,0 +1,15 @@ +package hdvtdev.telegram.core.objects; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +@JsonDeserialize(using = MaybeInaccessibleMessageDeserializer.class) +public interface MaybeInaccessibleMessage { + long chatId(); + + Chat chat(); + + int messageId(); + + long date(); + +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/message/MaybeInaccessibleMessageDeserializer.java b/core/src/main/java/hdvtdev/telegram/core/objects/message/MaybeInaccessibleMessageDeserializer.java new file mode 100644 index 0000000..70c96e6 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/message/MaybeInaccessibleMessageDeserializer.java @@ -0,0 +1,16 @@ +package hdvtdev.telegram.core.objects; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; + +import java.io.IOException; + +public class MaybeInaccessibleMessageDeserializer extends JsonDeserializer { + + @Override + public MaybeInaccessibleMessage deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { + Message msg = p.getCodec().readValue(p, Message.class); + return msg.date() == 0 ? new InaccessibleMessage(msg.chat(), msg.messageId(), 0) : msg; + } +} \ No newline at end of file diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/message/Message.java b/core/src/main/java/hdvtdev/telegram/core/objects/message/Message.java new file mode 100644 index 0000000..74fdf14 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/message/Message.java @@ -0,0 +1,275 @@ +package hdvtdev.telegram.core.objects; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.chatboost.ChatBoostAdded; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record Message( + @JsonProperty("message_id") int messageId, + @JsonProperty("message_thread_id") Long messageThreadId, + @JsonProperty("from") User user, + @JsonProperty("sender_chat") Chat senderChat, + @JsonProperty("sender_boost_count") Integer senderBoostCount, + @JsonProperty("sender_business_bot") User senderBusinessBot, + @JsonProperty("date") long date, + @JsonProperty("business_connection_id") String businessConnectionId, + @JsonProperty("chat") Chat chat, + @JsonProperty("forward_origin") MessageOrigin forwardOrigin, + @JsonProperty("is_topic_message") boolean isTopicMessage, + @JsonProperty("is_automatic_forward") boolean isAutomaticForward, + @JsonProperty("reply_to_message") Message replyToMessage, + @JsonProperty("external_reply") ExternalReplyInfo externalReply, + @JsonProperty("quote") TextQuote quote, + @JsonProperty("reply_to_story") Story replyToStory, + @JsonProperty("via_bot") User viaBot, + @JsonProperty("edit_date") long editDate, + @JsonProperty("has_protected_content") boolean hasProtectedContent, + @JsonProperty("is_from_offline") boolean isFromOnline, + @JsonProperty("media_group_id") String mediaGroupId, + @JsonProperty("author_signature") String authorSignature, + @JsonProperty("text") String text, + @JsonProperty("entities") MessageEntity[] entities, + @JsonProperty("link_preview_options") LinkPreviewOptions linkPreviewOptions, + @JsonProperty("effect_id") String effectId, + @JsonProperty("animation") Animation animation, + @JsonProperty("audio") Audio audio, + @JsonProperty("document") Document document, + @JsonProperty("paid_media") PaidMediaInfo paidMediaInfo, + @JsonProperty("photo") PhotoSize[] photo, + @JsonProperty("sticker") Sticker sticker, + @JsonProperty("story") Story story, + @JsonProperty("video") Video video, + @JsonProperty("video_note") VideoNote videoNote, + @JsonProperty("voice") Voice voice, + @JsonProperty("caption") String caption, + @JsonProperty("caption_entities") MessageEntity[] captionEntities, + @JsonProperty("show_caption_above_media") boolean showCaptionAboveMedia, + @JsonProperty("has_media_spoiler") boolean hasMediaSpoiler, + @JsonProperty("contact") Contact contact, + @JsonProperty("dice") Dice dice, + @JsonProperty("game") Game game, + @JsonProperty("poll") Poll poll, + @JsonProperty("venue") Venue venue, + @JsonProperty("location") Location location, + @JsonProperty("new_chat_members") User[] newChatMembers, + @JsonProperty("left_chat_member") User leftChatMember, + @JsonProperty("new_chat_title") String newChatTitle, + @JsonProperty("new_chat_photo") PhotoSize[] newChatPhoto, + @JsonProperty("delete_chat_photo") boolean deleteChatPhoto, + @JsonProperty("group_chat_created") boolean groupChatCreated, + @JsonProperty("supergroup_chat_created") boolean supergroupChatCreated, + @JsonProperty("channel_chat_created") boolean channelChatCreated, + @JsonProperty("message_auto_delete_timer_changed") MessageAutoDeleteTimerChanged messageAutoDeleteTimerChanged, + @JsonProperty("migrate_to_chat_id") Long migrateToChatId, + @JsonProperty("migrate_from_chat_id") Long migrateFromChatId, + @JsonProperty("pinned_message") MaybeInaccessibleMessage pinnedMessage, + @JsonProperty("invoice") Invoice invoice, + @JsonProperty("successful_payment") SuccessfulPayment successfulPayment, + @JsonProperty("refunded_payment") RefundedPayment refundedPayment, + @JsonProperty("users_shared") UsersShared usersShared, + @JsonProperty("chat_shared") ChatShared chatShared, + @JsonProperty("connected_website") String connectedWebsite, + @JsonProperty("write_access_allowed") WriteAccessAllowed writeAccessAllowed, + @JsonProperty("passport_data") PassportData passportData, + @JsonProperty("proximity_alert_triggered") ProximityAlertTriggered proximityAlertTriggered, + @JsonProperty("boost_added") ChatBoostAdded chatBoostAdded, + @JsonProperty("chat_background_set") ChatBackground chatBackground, + @JsonProperty("forum_topic_created") ForumTopicCreated forumTopicCreated, + @JsonProperty("forum_topic_edited") ForumTopicEdited forumTopicEdited, + @JsonProperty("forum_topic_closed") ForumTopicClosed forumTopicClosed, + @JsonProperty("forum_topic_reopened") ForumTopicReopened forumTopicReopened, + @JsonProperty("general_forum_topic_hidden") GeneralForumTopicHidden generalForumTopicHidden, + @JsonProperty("general_forum_topic_unhidden") GeneralForumTopicUnhidden generalForumTopicUnhidden, + @JsonProperty("giveaway_created") GiveawayCreated giveawayCreated, + @JsonProperty("giveaway") Giveaway giveaway, + @JsonProperty("giveaway_winners") GiveawayWinners giveawayWinners, + @JsonProperty("giveaway_completed") GiveawayCompleted giveawayCompleted, + @JsonProperty("video_chat_scheduled") VideoChatScheduled videoChatScheduled, + @JsonProperty("video_chat_started") VideoChatStarted videoChatStarted, + @JsonProperty("video_chat_ended") VideoChatEnded videoChatEnded, + @JsonProperty("video_chat_participants_invited") VideoChatParticipantsInvited videoChatParticipantsInvited, + @JsonProperty("web_app_data") WebAppData webAppData, + @JsonProperty("reply_markup") InlineKeyboardMarkup inlineKeyboardMarkup + +) implements MaybeInaccessibleMessage { + + public boolean hasMessageThreadId() { + return messageThreadId != null; + } + + public boolean hasSenderChat() { + return senderChat != null; + } + + public boolean hasSenderBoostCount() { + return senderBoostCount != null; + } + + public boolean hasSenderBusinessBot() { + return senderBusinessBot != null; + } + + public boolean hasBusinessConnectionId() { + return businessConnectionId != null; + } + + public boolean hasForwardOrigin() { + return forwardOrigin != null; + } + + public boolean hasReplyToMessage() { + return replyToMessage != null; + } + + public boolean hasExternalReply() { + return externalReply != null; + } + + public boolean hasQuote() { + return quote != null; + } + + public boolean hasReplyToStory() { + return replyToStory != null; + } + + public boolean hasViaBot() { + return viaBot != null; + } + + public boolean hasEditDate() { + return editDate != 0; + } + + public boolean hasMediaGroupId() { + return mediaGroupId != null; + } + + public boolean hasAuthorSignature() { + return authorSignature != null; + } + + public boolean hasText() { + return text != null; + } + + public boolean hasEntities() { + return entities != null; + } + + public boolean hasLinkPreviewOptions() { + return linkPreviewOptions != null; + } + + public boolean hasEffectId() { + return effectId != null; + } + + public boolean hasAnimation() { + return animation != null; + } + + public boolean hasAudio() { + return audio != null; + } + + public boolean hasDocument() { + return document != null; + } + + public boolean hasPaidMediaInfo() { + return paidMediaInfo != null; + } + + public boolean hasPhoto() { + return photo != null; + } + + public boolean hasSticker() { + return sticker != null; + } + + public boolean hasStory() { + return story != null; + } + + public boolean hasVideo() { + return video != null; + } + + public boolean hasVideoNote() { + return videoNote != null; + } + + public boolean hasVoice() { + return voice != null; + } + + public boolean hasCaption() { + return caption != null; + } + + public boolean hasCaptionEntities() { + return captionEntities != null; + } + + public boolean hasContact() { + return contact != null; + } + + public boolean hasDice() { + return dice != null; + } + + public boolean hasGame() { + return game != null; + } + + public boolean hasPoll() { + return poll != null; + } + + public boolean hasVenue() { + return venue != null; + } + + public boolean hasLocation() { + return location != null; + } + + public boolean hasNewChatMembers() { + return newChatMembers != null; + } + + public boolean hasLeftChatMember() { + return leftChatMember != null; + } + + public boolean hasNewChatTitle() { + return newChatTitle != null; + } + + public boolean hasNewChatPhoto() { + return newChatPhoto != null; + } + + public boolean hasMessageAutoDeleteTimerChanged() { + return messageAutoDeleteTimerChanged != null; + } + + public boolean hasMigrateToChatId() { + return migrateToChatId != null; + } + + public boolean hasMigrateFromChatId() { + return migrateFromChatId != null; + } + + @Override + public long chatId() { + return this.chat.id(); + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageAutoDeleteTimerChanged.java b/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageAutoDeleteTimerChanged.java new file mode 100644 index 0000000..c0908eb --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageAutoDeleteTimerChanged.java @@ -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 MessageAutoDeleteTimerChanged(@JsonProperty("message_auto_delete_time") long messageAutoDeleteTime) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageEntity.java b/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageEntity.java new file mode 100644 index 0000000..abc075f --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageEntity.java @@ -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 MessageEntity( + @JsonProperty("type") String type, + @JsonProperty("offset") int offset, + @JsonProperty("length") int length, + @JsonProperty("url") String url, + @JsonProperty("user") User user, + @JsonProperty("language") String language, + @JsonProperty("custom_emoji_id") String customEmojiId +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageOrigin.java b/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageOrigin.java new file mode 100644 index 0000000..9de39a2 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageOrigin.java @@ -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 = MessageOriginUser.class, name = "user"), + @JsonSubTypes.Type(value = MessageOriginHiddenUser.class, name = "hidden_user"), + @JsonSubTypes.Type(value = MessageOriginChat.class, name = "chat"), + @JsonSubTypes.Type(value = MessageOriginChannel.class, name = "channel") +}) +public interface MessageOrigin { + +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageOriginChannel.java b/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageOriginChannel.java new file mode 100644 index 0000000..aeb5c4d --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageOriginChannel.java @@ -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 MessageOriginChannel( + @JsonProperty("type") String type, + @JsonProperty("date") long date, + @JsonProperty("chat") Chat chat, + @JsonProperty("message_id") long messageId, + @JsonProperty("author_signature") String authorSignature +) implements MessageOrigin { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageOriginChat.java b/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageOriginChat.java new file mode 100644 index 0000000..3873b5c --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageOriginChat.java @@ -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 MessageOriginChat( + @JsonProperty("type") String type, + @JsonProperty("date") long date, + @JsonProperty("sender_chat") Chat senderChat, + @JsonProperty("author_signature") String authorSignature +) implements MessageOrigin { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageOriginHiddenUser.java b/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageOriginHiddenUser.java new file mode 100644 index 0000000..1fa924e --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageOriginHiddenUser.java @@ -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 MessageOriginHiddenUser( + @JsonProperty("type") String type, + @JsonProperty("date") long date, + @JsonProperty("sender_user_name") String senderUserName +) implements MessageOrigin { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageOriginUser.java b/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageOriginUser.java new file mode 100644 index 0000000..3a19e38 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageOriginUser.java @@ -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 MessageOriginUser( + @JsonProperty("type") String type, + @JsonProperty("date") long date, + @JsonProperty("sender_user") User senderUser +) implements MessageOrigin { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageReactionCountUpdated.java b/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageReactionCountUpdated.java new file mode 100644 index 0000000..f389b84 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageReactionCountUpdated.java @@ -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 MessageReactionCountUpdated( + @JsonProperty("chat") Chat chat, + @JsonProperty("message_id") long messageId, + @JsonProperty("date") long date, + @JsonProperty("reactions") ReactionCount[] reactions +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageReactionUpdated.java b/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageReactionUpdated.java new file mode 100644 index 0000000..7135efb --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageReactionUpdated.java @@ -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 MessageReactionUpdated( + @JsonProperty("chat") Chat chat, + @JsonProperty("message_id") long messageId, + @JsonProperty("user") User user, + @JsonProperty("actor_chat") Chat actorChat, + @JsonProperty("date") long date, + @JsonProperty("old_reaction") ReactionType[] oldReaction, + @JsonProperty("new_reaction") ReactionType[] newReaction +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/message/TextQuote.java b/core/src/main/java/hdvtdev/telegram/core/objects/message/TextQuote.java new file mode 100644 index 0000000..0a1a389 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/message/TextQuote.java @@ -0,0 +1,12 @@ +package hdvtdev.telegram.core.objects; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.message.MessageEntity; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record TextQuote(String text, MessageEntity[] entities, int position, + @JsonProperty("is_manual") boolean isManual) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/passport/EncryptedCredentials.java b/core/src/main/java/hdvtdev/telegram/core/objects/passport/EncryptedCredentials.java new file mode 100644 index 0000000..520fdc0 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/passport/EncryptedCredentials.java @@ -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 EncryptedCredentials( + @JsonProperty("data") String data, + @JsonProperty("hash") String hash, + @JsonProperty("secret") String secret +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/passport/EncryptedPassportElement.java b/core/src/main/java/hdvtdev/telegram/core/objects/passport/EncryptedPassportElement.java new file mode 100644 index 0000000..38dcb8a --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/passport/EncryptedPassportElement.java @@ -0,0 +1,21 @@ +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 EncryptedPassportElement( + @JsonProperty("type") String type, + @JsonProperty("data") String data, + @JsonProperty("phone_number") String phoneNumber, + @JsonProperty("email") String email, + @JsonProperty("files") PassportFile[] files, + @JsonProperty("front_side") PassportFile frontSide, + @JsonProperty("reverse_side") PassportFile reverseSide, + @JsonProperty("selfie") PassportFile selfie, + @JsonProperty("translation") PassportFile[] translation, + @JsonProperty("hash") String hash +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/passport/PassportData.java b/core/src/main/java/hdvtdev/telegram/core/objects/passport/PassportData.java new file mode 100644 index 0000000..f34b0bb --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/passport/PassportData.java @@ -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 PassportData( + @JsonProperty("data") EncryptedPassportElement[] data, + @JsonProperty("credentials") EncryptedCredentials credentials +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/passport/PassportFile.java b/core/src/main/java/hdvtdev/telegram/core/objects/passport/PassportFile.java new file mode 100644 index 0000000..9019afa --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/passport/PassportFile.java @@ -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 PassportFile( + @JsonProperty("file_id") String fileId, + @JsonProperty("file_unique_id") String fileUniqueId, + @JsonProperty("file_size") long fileSize, + @JsonProperty("file_date") long fileDate +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/payment/Invoice.java b/core/src/main/java/hdvtdev/telegram/core/objects/payment/Invoice.java new file mode 100644 index 0000000..df557d6 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/payment/Invoice.java @@ -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 Invoice( + @JsonProperty("title") String title, + @JsonProperty("description") String description, + @JsonProperty("start_parameter") String startParameter, + @JsonProperty("currency") String currency, + @JsonProperty("total_amount") int totalAmount +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/payment/OrderInfo.java b/core/src/main/java/hdvtdev/telegram/core/objects/payment/OrderInfo.java new file mode 100644 index 0000000..af6dce5 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/payment/OrderInfo.java @@ -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 OrderInfo( + @JsonProperty("name") String name, + @JsonProperty("phone_number") String phoneNumber, + @JsonProperty("email") String email, + @JsonProperty("shipping_address") ShippingAddress shippingAddress +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/payment/PreCheckoutQuery.java b/core/src/main/java/hdvtdev/telegram/core/objects/payment/PreCheckoutQuery.java new file mode 100644 index 0000000..d0037b5 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/payment/PreCheckoutQuery.java @@ -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 PreCheckoutQuery( + @JsonProperty("id") String id, + @JsonProperty("from") User from, + @JsonProperty("currency") String currency, + @JsonProperty("total_amount") int totalAmount, + @JsonProperty("invoice_payload") String invoicePayload, + @JsonProperty("shipping_option_id") String shippingOptionId, + @JsonProperty("order_info") OrderInfo orderInfo +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/payment/RefundedPayment.java b/core/src/main/java/hdvtdev/telegram/core/objects/payment/RefundedPayment.java new file mode 100644 index 0000000..78ac21a --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/payment/RefundedPayment.java @@ -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 RefundedPayment( + @JsonProperty("currency") String currency, + @JsonProperty("total_amount") int totalAmount, + @JsonProperty("invoice_payload") String invoicePayload, + @JsonProperty("telegram_payment_charge_id") String telegramPaymentChargeId, + @JsonProperty("provider_payment_charge_id") String providerPaymentChargeId +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/payment/ShippingAddress.java b/core/src/main/java/hdvtdev/telegram/core/objects/payment/ShippingAddress.java new file mode 100644 index 0000000..07c8693 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/payment/ShippingAddress.java @@ -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 ShippingAddress( + @JsonProperty("country_code") String countryCode, + @JsonProperty("state") String state, + @JsonProperty("city") String city, + @JsonProperty("street_line1") String firstStreetLine, + @JsonProperty("street_line2") String secondStreetLine, + @JsonProperty("post_code") String postCode +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/payment/ShippingQuery.java b/core/src/main/java/hdvtdev/telegram/core/objects/payment/ShippingQuery.java new file mode 100644 index 0000000..1d4a95d --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/payment/ShippingQuery.java @@ -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 ShippingQuery( + @JsonProperty("id") String id, + @JsonProperty("from") User from, + @JsonProperty("invoice_payload") String invoicePayload, + @JsonProperty("shipping_address") ShippingAddress shippingAddress +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/payment/SuccessfulPayment.java b/core/src/main/java/hdvtdev/telegram/core/objects/payment/SuccessfulPayment.java new file mode 100644 index 0000000..88840ad --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/payment/SuccessfulPayment.java @@ -0,0 +1,21 @@ +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 SuccessfulPayment( + @JsonProperty("currency") String currency, + @JsonProperty("total_amount") int totalAmount, //price + @JsonProperty("invoice_payload") String invoicePayload, + @JsonProperty("subscription_expiration_date") long subscriptionExpirationDate, + @JsonProperty("is_recurring") boolean isRecurring, + @JsonProperty("is_first_recurring") boolean isFirstRecurring, + @JsonProperty("shipping_option_id") String shippingOptionId, + @JsonProperty("order_info") OrderInfo orderInfo, + @JsonProperty("telegram_payment_charge_id") String telegramPaymentChargeId, + @JsonProperty("provider_payment_charge_id") String providerPaymentChargeId +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/poll/Poll.java b/core/src/main/java/hdvtdev/telegram/core/objects/poll/Poll.java new file mode 100644 index 0000000..b25fd4c --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/poll/Poll.java @@ -0,0 +1,26 @@ +package hdvtdev.telegram.core.objects; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.message.MessageEntity; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record Poll( + @JsonProperty("id") String id, + @JsonProperty("question") String question, + @JsonProperty("question_entities") MessageEntity[] questionEntities, + @JsonProperty("options") PollOption[] options, + @JsonProperty("total_voter_count") int totalVoterCount, + @JsonProperty("is_closed") boolean isClosed, + @JsonProperty("is_anonymous") boolean isAnonymous, + @JsonProperty("type") String type, + @JsonProperty("allows_multiple_answers") boolean allowMultipleAnswers, + @JsonProperty("correct_option_id") int correctOptionId, + @JsonProperty("explanation") String explanation, + @JsonProperty("explanation_entities") MessageEntity[] explanationEntities, + @JsonProperty("open_period") long openPeriod, + @JsonProperty("close_date") long closeDate +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/poll/PollAnswer.java b/core/src/main/java/hdvtdev/telegram/core/objects/poll/PollAnswer.java new file mode 100644 index 0000000..05bab19 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/poll/PollAnswer.java @@ -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; +import hdvtdev.telegram.core.objects.chat.Chat; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record PollAnswer( + @JsonProperty("poll_id") String pollId, + @JsonProperty("voter_chat") Chat voterChat, + @JsonProperty("user") User user, + @JsonProperty("option_ids") int[] optionsIds +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/poll/PollOption.java b/core/src/main/java/hdvtdev/telegram/core/objects/poll/PollOption.java new file mode 100644 index 0000000..2e09c91 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/poll/PollOption.java @@ -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; +import hdvtdev.telegram.core.objects.message.MessageEntity; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record PollOption( + @JsonProperty("text") String text, + @JsonProperty("text_entities") MessageEntity[] textEntities, + @JsonProperty("voter_count") int voterCount +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/reaction/ReactionCount.java b/core/src/main/java/hdvtdev/telegram/core/objects/reaction/ReactionCount.java new file mode 100644 index 0000000..3d0ec3c --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/reaction/ReactionCount.java @@ -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 ReactionCount( + @JsonProperty("type") ReactionType type, + @JsonProperty("total_count") int totalCount +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/reaction/ReactionType.java b/core/src/main/java/hdvtdev/telegram/core/objects/reaction/ReactionType.java new file mode 100644 index 0000000..93a2a1d --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/reaction/ReactionType.java @@ -0,0 +1,17 @@ +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 = ReactionTypeEmoji.class, name = "emoji"), + @JsonSubTypes.Type(value = ReactionTypeCustomEmoji.class, name = "custom_emoji"), + @JsonSubTypes.Type(value = ReactionTypePaid.class, name = "paid") +}) +public interface ReactionType { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/reaction/ReactionTypeCustomEmoji.java b/core/src/main/java/hdvtdev/telegram/core/objects/reaction/ReactionTypeCustomEmoji.java new file mode 100644 index 0000000..8c9a561 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/reaction/ReactionTypeCustomEmoji.java @@ -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 ReactionTypeCustomEmoji( + @JsonProperty("type") String type, + @JsonProperty("custom_emoji_id") String customEmojiId +) implements ReactionType { +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/reaction/ReactionTypeEmoji.java b/core/src/main/java/hdvtdev/telegram/core/objects/reaction/ReactionTypeEmoji.java new file mode 100644 index 0000000..8d483bf --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/reaction/ReactionTypeEmoji.java @@ -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 ReactionTypeEmoji( + @JsonProperty("type") String type, + @JsonProperty("emoji") String emoji +) implements ReactionType { + public ReactionTypeEmoji(String emoji) { + this("emoji", emoji); + } +} diff --git a/core/src/main/java/hdvtdev/telegram/core/objects/reaction/ReactionTypePaid.java b/core/src/main/java/hdvtdev/telegram/core/objects/reaction/ReactionTypePaid.java new file mode 100644 index 0000000..645b4f5 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/reaction/ReactionTypePaid.java @@ -0,0 +1,12 @@ +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 ReactionTypePaid( + @JsonProperty("type") String type +) implements ReactionType { +} diff --git a/core/src/main/java/hdvtdev/telegram/exceptions/TelegramApiException.java b/core/src/main/java/hdvtdev/telegram/exceptions/TelegramApiException.java new file mode 100644 index 0000000..4808610 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/exceptions/TelegramApiException.java @@ -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) { + + } + +} diff --git a/core/src/main/java/hdvtdev/telegram/exceptions/TelegramApiNetworkException.java b/core/src/main/java/hdvtdev/telegram/exceptions/TelegramApiNetworkException.java new file mode 100644 index 0000000..8ee9c6a --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/exceptions/TelegramApiNetworkException.java @@ -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); + } +} diff --git a/core/src/main/java/hdvtdev/telegram/exceptions/TelegramMethodParsingException.java b/core/src/main/java/hdvtdev/telegram/exceptions/TelegramMethodParsingException.java new file mode 100644 index 0000000..cad5c01 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/exceptions/TelegramMethodParsingException.java @@ -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); + } +} diff --git a/core/src/main/java/hdvtdev/telegram/methods/AnswerCallbackQuery.java b/core/src/main/java/hdvtdev/telegram/methods/AnswerCallbackQuery.java new file mode 100644 index 0000000..3c983b2 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/methods/AnswerCallbackQuery.java @@ -0,0 +1,113 @@ +package hdvtdev.telegram.methods; + +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 { + + /** + * 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 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); + } + } +} diff --git a/core/src/main/java/hdvtdev/telegram/methods/ApproveChatJoinRequest.java b/core/src/main/java/hdvtdev/telegram/methods/ApproveChatJoinRequest.java new file mode 100644 index 0000000..7438c51 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/methods/ApproveChatJoinRequest.java @@ -0,0 +1,51 @@ +package hdvtdev.telegram.methods; + +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 administrator 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 { + + /** + * @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 getResponseClass() { + return Boolean.class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/methods/BanChatMember.java b/core/src/main/java/hdvtdev/telegram/methods/BanChatMember.java new file mode 100644 index 0000000..a0829fb --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/methods/BanChatMember.java @@ -0,0 +1,110 @@ +package hdvtdev.telegram.methods; + +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 { + + /** + * 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 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); + } + } +} diff --git a/core/src/main/java/hdvtdev/telegram/methods/BanChatSenderChat.java b/core/src/main/java/hdvtdev/telegram/methods/BanChatSenderChat.java new file mode 100644 index 0000000..5bb2d4b --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/methods/BanChatSenderChat.java @@ -0,0 +1,38 @@ +package hdvtdev.telegram.methods; + +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 { + + 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 getResponseClass() { + return Boolean.class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/methods/CloseForumTopic.java b/core/src/main/java/hdvtdev/telegram/methods/CloseForumTopic.java new file mode 100644 index 0000000..36d35b0 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/methods/CloseForumTopic.java @@ -0,0 +1,37 @@ +package hdvtdev.telegram.methods; + +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 { + + 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 getResponseClass() { + return Boolean.class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/methods/CloseGeneralForumTopic.java b/core/src/main/java/hdvtdev/telegram/methods/CloseGeneralForumTopic.java new file mode 100644 index 0000000..17cff82 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/methods/CloseGeneralForumTopic.java @@ -0,0 +1,37 @@ +package hdvtdev.telegram.methods; + +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 { + + 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 getResponseClass() { + return Boolean.class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/methods/CopyMessage.java b/core/src/main/java/hdvtdev/telegram/methods/CopyMessage.java new file mode 100644 index 0000000..46ece7d --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/methods/CopyMessage.java @@ -0,0 +1,244 @@ +package hdvtdev.telegram.methods; + +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 { + + @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 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 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 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 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 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); + } + } +} diff --git a/core/src/main/java/hdvtdev/telegram/methods/CopyMessages.java b/core/src/main/java/hdvtdev/telegram/methods/CopyMessages.java new file mode 100644 index 0000000..ceafa51 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/methods/CopyMessages.java @@ -0,0 +1,181 @@ +package hdvtdev.telegram.methods; + +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 { + + @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 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 messageIds) { + this.chatId = chatId; + this.fromChatId = fromChatId; + ArrayList 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 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 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 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 getResponseClass() { + return Long[].class; + } + + public static final class Builder { + private final String chatId; + private Long messageThreadId; + private final String fromChatId; + private final List messageIds; + private Boolean disableNotification; + private Boolean protectContent; + private Boolean removeCaption; + + public Builder(String chatId, String fromChatId, List messageIds) { + this.chatId = chatId; + this.fromChatId = fromChatId; + ArrayList sortedMessageIds = new ArrayList<>(messageIds.subList(0, Math.min(messageIds.size(), 100))); + sortedMessageIds.sort(null); + this.messageIds = sortedMessageIds; + } + public Builder(long chatId, String fromChatId, List messageIds) { + this(String.valueOf(chatId), fromChatId, messageIds); + } + + public Builder(long chatId, long fromChatId, List messageIds) { + this(String.valueOf(chatId), String.valueOf(fromChatId), messageIds); + } + + public Builder(String chatId, long fromChatId, List 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); + } + } +} diff --git a/core/src/main/java/hdvtdev/telegram/methods/CreateChatInviteLink.java b/core/src/main/java/hdvtdev/telegram/methods/CreateChatInviteLink.java new file mode 100644 index 0000000..8294d9a --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/methods/CreateChatInviteLink.java @@ -0,0 +1,114 @@ +package hdvtdev.telegram.methods; + +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 { + + 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 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); + } + } +} diff --git a/core/src/main/java/hdvtdev/telegram/methods/ForwardMessage.java b/core/src/main/java/hdvtdev/telegram/methods/ForwardMessage.java new file mode 100644 index 0000000..4f43654 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/methods/ForwardMessage.java @@ -0,0 +1,133 @@ +package hdvtdev.telegram.methods; + +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 { + + @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 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); + } + } +} diff --git a/core/src/main/java/hdvtdev/telegram/methods/ForwardMessages.java b/core/src/main/java/hdvtdev/telegram/methods/ForwardMessages.java new file mode 100644 index 0000000..664566f --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/methods/ForwardMessages.java @@ -0,0 +1,147 @@ +package hdvtdev.telegram.methods; + +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 { + + @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 messageIds; + @JsonProperty("disable_notification") + private Boolean disableNotification; + @JsonProperty("protect_content") + private Boolean protectContent; + + public ForwardMessages(String chatId, String fromChatId, List messageIds) { + ArrayList 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 messageIds) { + this(String.valueOf(chatId), fromChatId, messageIds); + } + + public ForwardMessages(String chatId, long fromChatId, List messageIds) { + this(chatId, String.valueOf(fromChatId), messageIds); + } + + public ForwardMessages(long chatId, long fromChatId, List 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 getResponseClass() { + return Long[].class; + } + + + public static final class Builder { + private final String chatId; + private Long messageThreadId; + private final String fromChatId; + private final List messageIds; + private Boolean disableNotification; + private Boolean protectContent; + + public Builder(String chatId, String fromChatId, List messageIds) { + ArrayList 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 messageIds) { + this(String.valueOf(chatId), fromChatId, messageIds); + } + + public Builder(String chatId, long fromChatId, List messageIds) { + this(chatId, String.valueOf(fromChatId), messageIds); + } + + public Builder(long chatId, long fromChatId, List 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); + } + } +} diff --git a/core/src/main/java/hdvtdev/telegram/methods/GetChatAdministrators.java b/core/src/main/java/hdvtdev/telegram/methods/GetChatAdministrators.java new file mode 100644 index 0000000..231c2bc --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/methods/GetChatAdministrators.java @@ -0,0 +1,36 @@ +package hdvtdev.telegram.methods; + +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 { + + 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 getResponseClass() { + return ChatMember[].class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/methods/GetChatMember.java b/core/src/main/java/hdvtdev/telegram/methods/GetChatMember.java new file mode 100644 index 0000000..fee4dd3 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/methods/GetChatMember.java @@ -0,0 +1,38 @@ +package hdvtdev.telegram.methods; + +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 { + + 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 getResponseClass() { + return ChatMember.class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/methods/GetFile.java b/core/src/main/java/hdvtdev/telegram/methods/GetFile.java new file mode 100644 index 0000000..c29f5df --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/methods/GetFile.java @@ -0,0 +1,23 @@ +package hdvtdev.telegram.methods; + +import hdvtdev.telegram.objects.TelegramFile; +import okhttp3.FormBody; +import okhttp3.RequestBody; + +public record GetFile(String fileId) implements TelegramApiMethod { + + @Override + public RequestBody getBody() { + return new FormBody.Builder().add("file_id", fileId).build(); + } + + @Override + public String getMethodName() { + return "getFile"; + } + + @Override + public Class getResponseClass() { + return TelegramFile.class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/methods/GetMe.java b/core/src/main/java/hdvtdev/telegram/methods/GetMe.java new file mode 100644 index 0000000..224bbae --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/methods/GetMe.java @@ -0,0 +1,22 @@ +package hdvtdev.telegram.methods; + +import hdvtdev.telegram.objects.User; +import okhttp3.RequestBody; + +public final class GetMe implements TelegramApiMethod { + + @Override + public RequestBody getBody() { + return null; + } + + @Override + public String getMethodName() { + return "getMe"; + } + + @Override + public Class getResponseClass() { + return User.Bot.class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/methods/GetMyCommands.java b/core/src/main/java/hdvtdev/telegram/methods/GetMyCommands.java new file mode 100644 index 0000000..abd0400 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/methods/GetMyCommands.java @@ -0,0 +1,58 @@ +package hdvtdev.telegram.methods; + +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 { + + 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 getResponseClass() { + return BotCommand[].class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/methods/GetMyDescription.java b/core/src/main/java/hdvtdev/telegram/methods/GetMyDescription.java new file mode 100644 index 0000000..2c74024 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/methods/GetMyDescription.java @@ -0,0 +1,42 @@ +package hdvtdev.telegram.methods; + +import okhttp3.FormBody; +import okhttp3.RequestBody; + +import org.jetbrains.annotations.NotNull; + +public record GetMyDescription(String languageCode) implements TelegramApiMethod { + + 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 getResponseClass() { + return BotDescription.class; + } + + public record BotDescription(String description) { + @NotNull + @Override + public String toString() { + return description; + } + + public boolean isEmpty() { + return description.isEmpty(); + } + + } + +} diff --git a/core/src/main/java/hdvtdev/telegram/methods/GetMyName.java b/core/src/main/java/hdvtdev/telegram/methods/GetMyName.java new file mode 100644 index 0000000..1e76f28 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/methods/GetMyName.java @@ -0,0 +1,38 @@ +package hdvtdev.telegram.methods; + +import okhttp3.FormBody; +import okhttp3.RequestBody; +import org.jetbrains.annotations.NotNull; + +public record GetMyName(String languageCode) implements TelegramApiMethod { + + 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 getResponseClass() { + return BotName.class; + } + + public record BotName(String name) { + + @NotNull + @Override + public String toString() { + return this.name; + } + + } + +} diff --git a/core/src/main/java/hdvtdev/telegram/methods/GetUpdates.java b/core/src/main/java/hdvtdev/telegram/methods/GetUpdates.java new file mode 100644 index 0000000..7dfcf74 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/methods/GetUpdates.java @@ -0,0 +1,42 @@ +package hdvtdev.telegram.methods; + + +import hdvtdev.telegram.objects.Update; +import okhttp3.RequestBody; + +import java.util.ArrayList; + +public record GetUpdates( + Long offset, + Integer limit, + Integer timeout +) implements TelegramApiMethod { + + public GetUpdates() { + this(null, null, null); + } + + @Override + public RequestBody getBody() { + return null; + } + + @Override + public String getMethodName() { + ArrayList 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 getResponseClass() { + return Update[].class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/methods/RevokeChatInviteLink.java b/core/src/main/java/hdvtdev/telegram/methods/RevokeChatInviteLink.java new file mode 100644 index 0000000..e201091 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/methods/RevokeChatInviteLink.java @@ -0,0 +1,37 @@ +package hdvtdev.telegram.methods; + +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 { + + 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 getResponseClass() { + return ChatInviteLink.class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/methods/SendChatAction.java b/core/src/main/java/hdvtdev/telegram/methods/SendChatAction.java new file mode 100644 index 0000000..871c195 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/methods/SendChatAction.java @@ -0,0 +1,104 @@ +package hdvtdev.telegram.methods; + +import okhttp3.FormBody; +import okhttp3.RequestBody; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public final class SendChatAction implements TelegramApiMethod { + + 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 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); + } + } +} diff --git a/core/src/main/java/hdvtdev/telegram/methods/SendDice.java b/core/src/main/java/hdvtdev/telegram/methods/SendDice.java new file mode 100644 index 0000000..e71c879 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/methods/SendDice.java @@ -0,0 +1,133 @@ +package hdvtdev.telegram.methods; + +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 { + + @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 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; + } + + } + + + +} diff --git a/core/src/main/java/hdvtdev/telegram/methods/SendMessage.java b/core/src/main/java/hdvtdev/telegram/methods/SendMessage.java new file mode 100644 index 0000000..8c67974 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/methods/SendMessage.java @@ -0,0 +1,226 @@ +package hdvtdev.telegram.methods; + +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 { + + @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 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); + } + } +} + diff --git a/core/src/main/java/hdvtdev/telegram/methods/SetMessageReaction.java b/core/src/main/java/hdvtdev/telegram/methods/SetMessageReaction.java new file mode 100644 index 0000000..2cf41ea --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/methods/SetMessageReaction.java @@ -0,0 +1,100 @@ +package hdvtdev.telegram.methods; + +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 { + + @JsonProperty("chat_id") + private final String chatId; + @JsonProperty("message_id") + private final long messageId; + @JsonProperty("reaction") + private List 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 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 getResponseClass() { + return Boolean.class; + } + + public static final class Builder { + private final String chatId; + private final long messageId; + private List 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 reactions) { + this.reactions = reactions; + return this; + } + + public Builder isBig(Boolean isBig) { + this.isBig = isBig; + return this; + } + + public SetMessageReaction build() { + return new SetMessageReaction(this); + } + } +} diff --git a/core/src/main/java/hdvtdev/telegram/methods/SetMyCommands.java b/core/src/main/java/hdvtdev/telegram/methods/SetMyCommands.java new file mode 100644 index 0000000..6fa9fbf --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/methods/SetMyCommands.java @@ -0,0 +1,100 @@ +package hdvtdev.telegram.methods; + +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 { + + @JsonProperty("commands") + private final List commands; + @JsonProperty("scope") + private Object scope; + @JsonProperty("language_code") + private String languageCode; + + public SetMyCommands(List 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 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 getResponseClass() { + return Boolean.class; + } + + + public static final class Builder { + private final List commands; + private Object scope; + private String languageCode; + + public Builder(List 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); + } + } +} diff --git a/core/src/main/java/hdvtdev/telegram/methods/SetMyDescription.java b/core/src/main/java/hdvtdev/telegram/methods/SetMyDescription.java new file mode 100644 index 0000000..8757cc7 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/methods/SetMyDescription.java @@ -0,0 +1,41 @@ +package hdvtdev.telegram.methods; + +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 { + + 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 getResponseClass() { + return Boolean.class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/methods/SetMyName.java b/core/src/main/java/hdvtdev/telegram/methods/SetMyName.java new file mode 100644 index 0000000..536002c --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/methods/SetMyName.java @@ -0,0 +1,28 @@ +package hdvtdev.telegram.methods; + +import okhttp3.FormBody; +import okhttp3.RequestBody; + +public record SetMyName(String name, String languageCode) implements TelegramApiMethod { + + 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 getResponseClass() { + return Boolean.class; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/methods/TelegramApiMethod.java b/core/src/main/java/hdvtdev/telegram/methods/TelegramApiMethod.java new file mode 100644 index 0000000..268f6db --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/methods/TelegramApiMethod.java @@ -0,0 +1,13 @@ +package hdvtdev.telegram.methods; + +import okhttp3.RequestBody; + +public interface TelegramApiMethod { + + RequestBody getBody(); + + String getMethodName(); + + Class getResponseClass(); + +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/Animation.java b/core/src/main/java/hdvtdev/telegram/objects/Animation.java new file mode 100644 index 0000000..e5c3785 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/Animation.java @@ -0,0 +1,37 @@ +package hdvtdev.telegram.objects; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public record Animation( + @JsonProperty("file_id") String fileId, + @JsonProperty("file_unique_id") String fileUniqueId, + @JsonProperty("width") int width, + @JsonProperty("height") int height, + @JsonProperty("duration") int duration, + @JsonProperty("thumbnail") PhotoSize thumbnail, + @JsonProperty("file_name") String fileName, + @JsonProperty("mime_type") String mimeType, + @JsonProperty("file_size") Long fileSize +) { + + public boolean hasThumbnail() { + return this.thumbnail != null; + } + + public boolean hasFileName() { + return this.fileName != null; + } + + public boolean hasMimeType() { + return this.mimeType != null; + } + + public boolean hasFileSize() { + return this.fileSize != null; + } + +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/Audio.java b/core/src/main/java/hdvtdev/telegram/objects/Audio.java new file mode 100644 index 0000000..591f8be --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/Audio.java @@ -0,0 +1,37 @@ +package hdvtdev.telegram.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 Audio( + @JsonProperty("file_id") String fileId, + @JsonProperty("file_unique_id") String fileUniqueId, + @JsonProperty("duration") int duration, + @JsonProperty("performer") String performer, + @JsonProperty("title") String title, + @JsonProperty("file_name") String fileName, + @JsonProperty("mime_type") String mimeType, + @JsonProperty("file_size") Long fileSize, + @JsonProperty("thumbnail") PhotoSize thumbnail +) { + + public boolean hasThumbnail() { + return this.thumbnail != null; + } + + public boolean hasFileName() { + return this.fileName != null; + } + + public boolean hasMimeType() { + return this.mimeType != null; + } + + public boolean hasFileSize() { + return this.fileSize != null; + } + +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/BackgroundFill.java b/core/src/main/java/hdvtdev/telegram/objects/BackgroundFill.java new file mode 100644 index 0000000..94fe350 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/BackgroundFill.java @@ -0,0 +1,18 @@ +package hdvtdev.telegram.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(); +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/BackgroundFillFreeformGradient.java b/core/src/main/java/hdvtdev/telegram/objects/BackgroundFillFreeformGradient.java new file mode 100644 index 0000000..6e9c38d --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/BackgroundFillFreeformGradient.java @@ -0,0 +1,13 @@ +package hdvtdev.telegram.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 { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/BackgroundFillGradient.java b/core/src/main/java/hdvtdev/telegram/objects/BackgroundFillGradient.java new file mode 100644 index 0000000..a1573fe --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/BackgroundFillGradient.java @@ -0,0 +1,15 @@ +package hdvtdev.telegram.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 { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/BackgroundFillSolid.java b/core/src/main/java/hdvtdev/telegram/objects/BackgroundFillSolid.java new file mode 100644 index 0000000..c2bfba8 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/BackgroundFillSolid.java @@ -0,0 +1,13 @@ +package hdvtdev.telegram.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 { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/BackgroundType.java b/core/src/main/java/hdvtdev/telegram/objects/BackgroundType.java new file mode 100644 index 0000000..9b3c347 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/BackgroundType.java @@ -0,0 +1,19 @@ +package hdvtdev.telegram.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(); +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/BackgroundTypeChatTheme.java b/core/src/main/java/hdvtdev/telegram/objects/BackgroundTypeChatTheme.java new file mode 100644 index 0000000..1d7323d --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/BackgroundTypeChatTheme.java @@ -0,0 +1,13 @@ +package hdvtdev.telegram.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 { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/BackgroundTypeFill.java b/core/src/main/java/hdvtdev/telegram/objects/BackgroundTypeFill.java new file mode 100644 index 0000000..00efd83 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/BackgroundTypeFill.java @@ -0,0 +1,14 @@ +package hdvtdev.telegram.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 BackgroundTypeFill( + @JsonProperty("type") String type, + @JsonProperty("fill") BackgroundFill fill, + @JsonProperty("dark_theme_dimming") int darkThemeDimming +) implements BackgroundType { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/BackgroundTypePattern.java b/core/src/main/java/hdvtdev/telegram/objects/BackgroundTypePattern.java new file mode 100644 index 0000000..201eef1 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/BackgroundTypePattern.java @@ -0,0 +1,16 @@ +package hdvtdev.telegram.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 BackgroundTypePattern( + @JsonProperty("type") String type, + @JsonProperty("document") Document document, + @JsonProperty("fill") BackgroundFill fill, + @JsonProperty("is_inverted") boolean isInverted, + @JsonProperty("is_moving") boolean isMoving +) implements BackgroundType { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/BackgroundTypeWallpaper.java b/core/src/main/java/hdvtdev/telegram/objects/BackgroundTypeWallpaper.java new file mode 100644 index 0000000..da3a7ef --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/BackgroundTypeWallpaper.java @@ -0,0 +1,16 @@ +package hdvtdev.telegram.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 BackgroundTypeWallpaper( + @JsonProperty("type") String type, + @JsonProperty("document") Document document, + @JsonProperty("dark_theme_dimming") int darkThemeDimming, + @JsonProperty("is_blurred") boolean isBlurred, + @JsonProperty("is_moving") boolean isMoving +) implements BackgroundType { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/BusinessConnection.java b/core/src/main/java/hdvtdev/telegram/objects/BusinessConnection.java new file mode 100644 index 0000000..2917f45 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/BusinessConnection.java @@ -0,0 +1,17 @@ +package hdvtdev.telegram.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 BusinessConnection( + @JsonProperty("id") String id, + @JsonProperty("user") User user, + @JsonProperty("user_chat_id") long userChatId, + @JsonProperty("date") long date, + @JsonProperty("can_reply") boolean canReply, + @JsonProperty("is_enabled") boolean isEnabled +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/BusinessMessagesDeleted.java b/core/src/main/java/hdvtdev/telegram/objects/BusinessMessagesDeleted.java new file mode 100644 index 0000000..06a4536 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/BusinessMessagesDeleted.java @@ -0,0 +1,14 @@ +package hdvtdev.telegram.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 BusinessMessagesDeleted( + @JsonProperty("business_connection_id") String businessConnectionId, + @JsonProperty("chat") Chat chat, + @JsonProperty("message_ids") long[] messageIds +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/CallbackGame.java b/core/src/main/java/hdvtdev/telegram/objects/CallbackGame.java new file mode 100644 index 0000000..4213d42 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/CallbackGame.java @@ -0,0 +1,9 @@ +package hdvtdev.telegram.objects; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record CallbackGame() { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/CallbackQuery.java b/core/src/main/java/hdvtdev/telegram/objects/CallbackQuery.java new file mode 100644 index 0000000..add7ba0 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/CallbackQuery.java @@ -0,0 +1,39 @@ +package hdvtdev.telegram.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 CallbackQuery( + @JsonProperty("id") String id, + @JsonProperty("from") User from, + @JsonProperty("message") MaybeInaccessibleMessage message, + @JsonProperty("inline_message_id") String inlineMessageId, + @JsonProperty("chat_instance") String chatInstance, + @JsonProperty("data") String data, + @JsonProperty("game_short_name") String gameShortName +) { + + public boolean hasMessage() { + return this.message != null; + } + + public boolean hasInlineMessageId() { + return this.inlineMessageId != null; + } + + public boolean hasChatInstance() { + return this.chatInstance != null; + } + + public boolean hasData() { + return this.data != null; + } + + public boolean hasGameShortName() { + return this.gameShortName != null; + } + +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/Chat.java b/core/src/main/java/hdvtdev/telegram/objects/Chat.java new file mode 100644 index 0000000..4d15355 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/Chat.java @@ -0,0 +1,35 @@ +package hdvtdev.telegram.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 Chat( + @JsonProperty("id") long id, + @JsonProperty("type") String type, + @JsonProperty("title") String title, + @JsonProperty("username") String username, + @JsonProperty("first_name") String firstName, + @JsonProperty("last_name") String lastName, + @JsonProperty("is_forum") boolean isForum +) { + + public boolean hasTitle() { + return this.title != null; + } + + public boolean hasUsername() { + return this.username != null; + } + + public boolean hasFirstName() { + return this.firstName != null; + } + + public boolean hasLastName() { + return this.lastName != null; + } + +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ChatAdministratorRights.java b/core/src/main/java/hdvtdev/telegram/objects/ChatAdministratorRights.java new file mode 100644 index 0000000..0653c1a --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ChatAdministratorRights.java @@ -0,0 +1,26 @@ +package hdvtdev.telegram.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 ChatAdministratorRights( + @JsonProperty("is_anonymous") boolean isAnonymous, + @JsonProperty("can_manage_chat") boolean canManageChat, + @JsonProperty("can_delete_messages") boolean canDeleteMessages, + @JsonProperty("can_manage_video_chats") boolean canManageVideoChats, + @JsonProperty("can_restrict_members") boolean canRestrictMembers, + @JsonProperty("can_promote_members") boolean canPromoteMembers, + @JsonProperty("can_change_info") boolean canChangeInfo, + @JsonProperty("can_invite_users") boolean canInviteUsers, + @JsonProperty("can_post_stories") boolean canPostStories, + @JsonProperty("can_edit_stories") boolean canEditStories, + @JsonProperty("can_delete_stories") boolean canDeleteStories, + @JsonProperty("can_post_messages") boolean canPostMessages, + @JsonProperty("can_edit_messages") boolean canEditMessages, + @JsonProperty("can_pin_messages") boolean canPinMessages, + @JsonProperty("can_manage_topics") boolean canManageTopics +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ChatBackground.java b/core/src/main/java/hdvtdev/telegram/objects/ChatBackground.java new file mode 100644 index 0000000..af2af91 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ChatBackground.java @@ -0,0 +1,10 @@ +package hdvtdev.telegram.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 ChatBackground(@JsonProperty("type") BackgroundType type) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ChatBoost.java b/core/src/main/java/hdvtdev/telegram/objects/ChatBoost.java new file mode 100644 index 0000000..2f16be1 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ChatBoost.java @@ -0,0 +1,15 @@ +package hdvtdev.telegram.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 ChatBoost( + @JsonProperty("boost_id") String boostId, + @JsonProperty("add_date") long addDate, + @JsonProperty("expiration_date") long expirationDate, + @JsonProperty("source") ChatBoostSource source +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ChatBoostAdded.java b/core/src/main/java/hdvtdev/telegram/objects/ChatBoostAdded.java new file mode 100644 index 0000000..de0db01 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ChatBoostAdded.java @@ -0,0 +1,12 @@ +package hdvtdev.telegram.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 ChatBoostAdded( + @JsonProperty("boost_count") int boostCount +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ChatBoostRemoved.java b/core/src/main/java/hdvtdev/telegram/objects/ChatBoostRemoved.java new file mode 100644 index 0000000..2c04426 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ChatBoostRemoved.java @@ -0,0 +1,15 @@ +package hdvtdev.telegram.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 ChatBoostRemoved( + @JsonProperty("chat") Chat chat, + @JsonProperty("boost_id") String boostId, + @JsonProperty("remove_date") long removeDate, + @JsonProperty("source") ChatBoostSource source +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ChatBoostSource.java b/core/src/main/java/hdvtdev/telegram/objects/ChatBoostSource.java new file mode 100644 index 0000000..0b46d25 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ChatBoostSource.java @@ -0,0 +1,18 @@ +package hdvtdev.telegram.objects; + +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; + +@JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, + include = JsonTypeInfo.As.EXISTING_PROPERTY, + property = "source" +) +@JsonSubTypes({ + @JsonSubTypes.Type(value = ChatBoostSourcePremium.class, name = "premium"), + @JsonSubTypes.Type(value = ChatBoostSourceGiveaway.class, name = "giveaway"), + @JsonSubTypes.Type(value = ChatBoostSourceGiftCode.class, name = "gift_code") +}) +public interface ChatBoostSource { + String source(); +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ChatBoostSourceGiftCode.java b/core/src/main/java/hdvtdev/telegram/objects/ChatBoostSourceGiftCode.java new file mode 100644 index 0000000..c3e8cd8 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ChatBoostSourceGiftCode.java @@ -0,0 +1,13 @@ +package hdvtdev.telegram.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 ChatBoostSourceGiftCode( + @JsonProperty("source") String source, + @JsonProperty("user") User user +) implements ChatBoostSource { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ChatBoostSourceGiveaway.java b/core/src/main/java/hdvtdev/telegram/objects/ChatBoostSourceGiveaway.java new file mode 100644 index 0000000..d48c42c --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ChatBoostSourceGiveaway.java @@ -0,0 +1,16 @@ +package hdvtdev.telegram.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 ChatBoostSourceGiveaway( + @JsonProperty("source") String source, + @JsonProperty("giveaway_message_id") long giveawayMessageId, + @JsonProperty("user") User user, + @JsonProperty("prize_star_count") int prizeStarCount, + @JsonProperty("is_unclaimed") boolean isUnclaimed +) implements ChatBoostSource { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ChatBoostSourcePremium.java b/core/src/main/java/hdvtdev/telegram/objects/ChatBoostSourcePremium.java new file mode 100644 index 0000000..a096875 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ChatBoostSourcePremium.java @@ -0,0 +1,13 @@ +package hdvtdev.telegram.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 ChatBoostSourcePremium( + @JsonProperty("source") String source, + @JsonProperty("user") User user +) implements ChatBoostSource { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ChatBoostUpdated.java b/core/src/main/java/hdvtdev/telegram/objects/ChatBoostUpdated.java new file mode 100644 index 0000000..05dd19d --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ChatBoostUpdated.java @@ -0,0 +1,13 @@ +package hdvtdev.telegram.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 ChatBoostUpdated( + @JsonProperty("chat") Chat chat, + @JsonProperty("boost") ChatBoost boost +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ChatInviteLink.java b/core/src/main/java/hdvtdev/telegram/objects/ChatInviteLink.java new file mode 100644 index 0000000..c8a57ee --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ChatInviteLink.java @@ -0,0 +1,29 @@ +package hdvtdev.telegram.objects; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import org.jetbrains.annotations.NotNull; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record ChatInviteLink( + @JsonProperty("invite_link") String inviteLink, + @JsonProperty("creator") User creator, + @JsonProperty("creates_join_request") boolean createsJoinRequest, + @JsonProperty("is_primary") boolean isPrimary, + @JsonProperty("is_revoked") boolean isRevoked, + @JsonProperty("name") String name, + @JsonProperty("expire_date") long expireDate, + @JsonProperty("member_limit") int memberLimit, + @JsonProperty("pending_join_request_count") int pendingJoinRequestCount, + @JsonProperty("subscription_period") int subscriptionPeriod, + @JsonProperty("subscription_price") int subscriptionPrice +) { + @NotNull + @Override + public String toString() { + return this.inviteLink; + } +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ChatJoinRequest.java b/core/src/main/java/hdvtdev/telegram/objects/ChatJoinRequest.java new file mode 100644 index 0000000..d5e8a86 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ChatJoinRequest.java @@ -0,0 +1,17 @@ +package hdvtdev.telegram.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 ChatJoinRequest( + @JsonProperty("chat") Chat chat, + @JsonProperty("from") User from, + @JsonProperty("user_chat_id") long userChatId, + @JsonProperty("date") long date, + @JsonProperty("bio") String bio, + @JsonProperty("invite_link") ChatInviteLink chatInviteLink +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ChatMember.java b/core/src/main/java/hdvtdev/telegram/objects/ChatMember.java new file mode 100644 index 0000000..fdce955 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ChatMember.java @@ -0,0 +1,28 @@ +package hdvtdev.telegram.objects; + +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; + +@JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, + include = JsonTypeInfo.As.EXISTING_PROPERTY, + property = "status" +) +@JsonSubTypes({ + @JsonSubTypes.Type(value = ChatMemberAdministrator.class, name = "administrator"), + @JsonSubTypes.Type(value = ChatMemberBanned.class, name = "kicked"), + @JsonSubTypes.Type(value = ChatMemberLeft.class, name = "left"), + @JsonSubTypes.Type(value = ChatMemberMember.class, name = "member"), + @JsonSubTypes.Type(value = ChatMemberOwner.class, name = "creator"), + @JsonSubTypes.Type(value = ChatMemberRestricted.class, name = "restricted"), +}) +public interface ChatMember { + User user(); + String status(); + + default ChatMemberAdministrator getAsChatMemberAdministrator() { + return (ChatMemberAdministrator) this; + } + +} + diff --git a/core/src/main/java/hdvtdev/telegram/objects/ChatMemberAdministrator.java b/core/src/main/java/hdvtdev/telegram/objects/ChatMemberAdministrator.java new file mode 100644 index 0000000..c2ee0ed --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ChatMemberAdministrator.java @@ -0,0 +1,30 @@ +package hdvtdev.telegram.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 ChatMemberAdministrator( + @JsonProperty("status") String status, + @JsonProperty("user") User user, + @JsonProperty("can_be_edited") boolean canBeEdited, + @JsonProperty("is_anonymous") boolean isAnonymous, + @JsonProperty("can_manage_chat") boolean canManageChat, + @JsonProperty("can_delete_messages") boolean canDeleteMessages, + @JsonProperty("can_manage_video_chats") boolean canManageVideoChat, + @JsonProperty("can_restrict_members") boolean canRestrictMembers, + @JsonProperty("can_promote_members") boolean canPromoteMembers, + @JsonProperty("can_change_info") boolean canChangeInfo, + @JsonProperty("can_invite_users") boolean canInviteUsers, + @JsonProperty("can_post_stories") boolean canPostStories, + @JsonProperty("can_edit_stories") boolean canEditStories, + @JsonProperty("can_delete_stories") boolean canDeleteStories, + @JsonProperty("can_post_messages") boolean canPostMessages, + @JsonProperty("can_edit_messages") boolean canEditMessages, + @JsonProperty("can_pin_messages") boolean canPinMessages, + @JsonProperty("can_manage_topics") boolean canManageTopics, + @JsonProperty("custom_title") boolean hasCustomTitle +) implements ChatMember { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ChatMemberBanned.java b/core/src/main/java/hdvtdev/telegram/objects/ChatMemberBanned.java new file mode 100644 index 0000000..e31b1f2 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ChatMemberBanned.java @@ -0,0 +1,14 @@ +package hdvtdev.telegram.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 ChatMemberBanned( + @JsonProperty("status") String status, + @JsonProperty("user") User user, + @JsonProperty("until_date") long untilDate +) implements ChatMember { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ChatMemberLeft.java b/core/src/main/java/hdvtdev/telegram/objects/ChatMemberLeft.java new file mode 100644 index 0000000..a8511e7 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ChatMemberLeft.java @@ -0,0 +1,13 @@ +package hdvtdev.telegram.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 ChatMemberLeft( + @JsonProperty("status") String status, + @JsonProperty("user") User user +) implements ChatMember { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ChatMemberMember.java b/core/src/main/java/hdvtdev/telegram/objects/ChatMemberMember.java new file mode 100644 index 0000000..6462ead --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ChatMemberMember.java @@ -0,0 +1,14 @@ +package hdvtdev.telegram.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 ChatMemberMember( + @JsonProperty("status") String status, + @JsonProperty("user") User user, + @JsonProperty("until_date") long untilDate +) implements ChatMember { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ChatMemberOwner.java b/core/src/main/java/hdvtdev/telegram/objects/ChatMemberOwner.java new file mode 100644 index 0000000..b41346b --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ChatMemberOwner.java @@ -0,0 +1,15 @@ +package hdvtdev.telegram.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 ChatMemberOwner( + @JsonProperty("status") String status, + @JsonProperty("user") User user, + @JsonProperty("is_anonymous") boolean isAnonymous, + @JsonProperty("custom_title") String customTitle +) implements ChatMember { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ChatMemberRestricted.java b/core/src/main/java/hdvtdev/telegram/objects/ChatMemberRestricted.java new file mode 100644 index 0000000..d801758 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ChatMemberRestricted.java @@ -0,0 +1,29 @@ +package hdvtdev.telegram.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 ChatMemberRestricted( + @JsonProperty("status") String status, + @JsonProperty("user") User user, + @JsonProperty("is_member") boolean isMember, + @JsonProperty("can_send_messages") boolean canSendMessage, + @JsonProperty("can_send_audios") boolean canSendAudios, + @JsonProperty("can_send_documents") boolean canSendDocuments, + @JsonProperty("can_send_photos") boolean canSendPhotos, + @JsonProperty("can_send_videos") boolean canSendVideos, + @JsonProperty("can_send_video_notes") boolean canSendVideoNotes, + @JsonProperty("can_send_voice_notes") boolean canSendVoiceNotes, + @JsonProperty("can_send_polls") boolean canSendPolls, + @JsonProperty("can_send_other_messages") boolean canSendOtherMessages, + @JsonProperty("can_add_web_page_previews") boolean canAddWebPagePreviews, + @JsonProperty("can_change_info") boolean canChangeInfo, + @JsonProperty("can_invite_users") boolean canInviteUsers, + @JsonProperty("can_pin_messages") boolean canPinMessages, + @JsonProperty("can_manage_topics") boolean canManageTopics, + @JsonProperty("until_date") long untilDate +) implements ChatMember { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ChatMemberUpdated.java b/core/src/main/java/hdvtdev/telegram/objects/ChatMemberUpdated.java new file mode 100644 index 0000000..0634715 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ChatMemberUpdated.java @@ -0,0 +1,19 @@ +package hdvtdev.telegram.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 ChatMemberUpdated( + @JsonProperty("chat") Chat chat, + @JsonProperty("from") User from, + @JsonProperty("date") long date, + @JsonProperty("old_chat_member") ChatMember oldChatMember, + @JsonProperty("new_chat_member") ChatMember newChatMember, + @JsonProperty("invite_link") ChatInviteLink chatInviteLink, + @JsonProperty("via_join_request") boolean viaJoinRequest, + @JsonProperty("via_chat_folder_invite_link") boolean viaChatFolderInviteLink +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ChatShared.java b/core/src/main/java/hdvtdev/telegram/objects/ChatShared.java new file mode 100644 index 0000000..114346a --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ChatShared.java @@ -0,0 +1,16 @@ +package hdvtdev.telegram.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 ChatShared( + @JsonProperty("request_id") int requestId, + @JsonProperty("chat_id") long chatId, + @JsonProperty("title") String title, + @JsonProperty("username") String username, + @JsonProperty("photo") PhotoSize[] photo +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ChosenInlineResult.java b/core/src/main/java/hdvtdev/telegram/objects/ChosenInlineResult.java new file mode 100644 index 0000000..d57196f --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ChosenInlineResult.java @@ -0,0 +1,16 @@ +package hdvtdev.telegram.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 +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/Contact.java b/core/src/main/java/hdvtdev/telegram/objects/Contact.java new file mode 100644 index 0000000..5e28ed9 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/Contact.java @@ -0,0 +1,16 @@ +package hdvtdev.telegram.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 +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/CopyTextButton.java b/core/src/main/java/hdvtdev/telegram/objects/CopyTextButton.java new file mode 100644 index 0000000..895f845 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/CopyTextButton.java @@ -0,0 +1,10 @@ +package hdvtdev.telegram.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 CopyTextButton(@JsonProperty("text") String text) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/Dice.java b/core/src/main/java/hdvtdev/telegram/objects/Dice.java new file mode 100644 index 0000000..5c3061b --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/Dice.java @@ -0,0 +1,13 @@ +package hdvtdev.telegram.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 +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/Document.java b/core/src/main/java/hdvtdev/telegram/objects/Document.java new file mode 100644 index 0000000..8e3fd8c --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/Document.java @@ -0,0 +1,21 @@ +package hdvtdev.telegram.objects; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.methods.GetFile; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record Document( + @JsonProperty("file_id") String fileId, + @JsonProperty("file_unique_id") String fileUniqueId, + @JsonProperty("thumbnail") PhotoSize thumbnail, + @JsonProperty("file_name") String fileName, + @JsonProperty("mime_type") String mimeType, + @JsonProperty("file_size") long fileSize +) { + public GetFile getFile() { + return new GetFile(this.fileId); + } +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/EncryptedCredentials.java b/core/src/main/java/hdvtdev/telegram/objects/EncryptedCredentials.java new file mode 100644 index 0000000..90a57ae --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/EncryptedCredentials.java @@ -0,0 +1,14 @@ +package hdvtdev.telegram.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 EncryptedCredentials( + @JsonProperty("data") String data, + @JsonProperty("hash") String hash, + @JsonProperty("secret") String secret +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/EncryptedPassportElement.java b/core/src/main/java/hdvtdev/telegram/objects/EncryptedPassportElement.java new file mode 100644 index 0000000..a1dfa54 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/EncryptedPassportElement.java @@ -0,0 +1,21 @@ +package hdvtdev.telegram.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 EncryptedPassportElement( + @JsonProperty("type") String type, + @JsonProperty("data") String data, + @JsonProperty("phone_number") String phoneNumber, + @JsonProperty("email") String email, + @JsonProperty("files") PassportFile[] files, + @JsonProperty("front_side") PassportFile frontSide, + @JsonProperty("reverse_side") PassportFile reverseSide, + @JsonProperty("selfie") PassportFile selfie, + @JsonProperty("translation") PassportFile[] translation, + @JsonProperty("hash") String hash +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ExternalReplyInfo.java b/core/src/main/java/hdvtdev/telegram/objects/ExternalReplyInfo.java new file mode 100644 index 0000000..84f2ce8 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ExternalReplyInfo.java @@ -0,0 +1,35 @@ +package hdvtdev.telegram.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 ExternalReplyInfo( + @JsonProperty("origin") MessageOrigin origin, + @JsonProperty("chat") Chat chat, + @JsonProperty("message_id") long messageId, + @JsonProperty("link_preview_options") LinkPreviewOptions linkPreviewOptions, + @JsonProperty("animation") Animation animation, + @JsonProperty("audio") Audio audio, + @JsonProperty("document") Document document, + @JsonProperty("paid_media") PaidMediaInfo paidMediaInfo, + @JsonProperty("photo") PhotoSize[] photo, + @JsonProperty("sticker") Sticker sticker, + @JsonProperty("story") Story story, + @JsonProperty("video") Video video, + @JsonProperty("video_note") VideoNote videoNote, + @JsonProperty("voice") Voice voice, + @JsonProperty("has_media_spoiler") boolean hasMediaSpoiler, + @JsonProperty("contact") Contact contact, + @JsonProperty("dice") Dice dice, + @JsonProperty("game") Game game, + @JsonProperty("giveaway") Giveaway giveaway, + @JsonProperty("giveaway_winners") GiveawayWinners giveawayWinners, + @JsonProperty("invoice") Invoice invoice, + @JsonProperty("location") Location location, + @JsonProperty("poll") Poll poll, + @JsonProperty("venue") Venue venue +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ForceReply.java b/core/src/main/java/hdvtdev/telegram/objects/ForceReply.java new file mode 100644 index 0000000..61df0cb --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ForceReply.java @@ -0,0 +1,14 @@ +package hdvtdev.telegram.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 ForceReply( + @JsonProperty("force_reply") boolean forceReply, + @JsonProperty("input_field_placeholder") String inputFieldPlaceholder, + @JsonProperty("selective") boolean selective +) implements ReplyMarkup { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ForumTopicClosed.java b/core/src/main/java/hdvtdev/telegram/objects/ForumTopicClosed.java new file mode 100644 index 0000000..619afff --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ForumTopicClosed.java @@ -0,0 +1,9 @@ +package hdvtdev.telegram.objects; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record ForumTopicClosed() { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ForumTopicCreated.java b/core/src/main/java/hdvtdev/telegram/objects/ForumTopicCreated.java new file mode 100644 index 0000000..166e12f --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ForumTopicCreated.java @@ -0,0 +1,14 @@ +package hdvtdev.telegram.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 ForumTopicCreated( + @JsonProperty("name") String name, + @JsonProperty("icon_color") int iconColor, + @JsonProperty("icon_custom_emoji_id") String iconCustomEmojiId +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ForumTopicEdited.java b/core/src/main/java/hdvtdev/telegram/objects/ForumTopicEdited.java new file mode 100644 index 0000000..85e3c3f --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ForumTopicEdited.java @@ -0,0 +1,13 @@ +package hdvtdev.telegram.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 ForumTopicEdited( + @JsonProperty("name") String name, + @JsonProperty("icon_custom_emoji_id") String iconCustomEmojiId +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ForumTopicReopened.java b/core/src/main/java/hdvtdev/telegram/objects/ForumTopicReopened.java new file mode 100644 index 0000000..1beab80 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ForumTopicReopened.java @@ -0,0 +1,9 @@ +package hdvtdev.telegram.objects; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record ForumTopicReopened() { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/Game.java b/core/src/main/java/hdvtdev/telegram/objects/Game.java new file mode 100644 index 0000000..ec4a513 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/Game.java @@ -0,0 +1,17 @@ +package hdvtdev.telegram.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 +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/GeneralForumTopicHidden.java b/core/src/main/java/hdvtdev/telegram/objects/GeneralForumTopicHidden.java new file mode 100644 index 0000000..cc154a1 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/GeneralForumTopicHidden.java @@ -0,0 +1,9 @@ +package hdvtdev.telegram.objects; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record GeneralForumTopicHidden() { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/GeneralForumTopicUnhidden.java b/core/src/main/java/hdvtdev/telegram/objects/GeneralForumTopicUnhidden.java new file mode 100644 index 0000000..81616f9 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/GeneralForumTopicUnhidden.java @@ -0,0 +1,9 @@ +package hdvtdev.telegram.objects; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record GeneralForumTopicUnhidden() { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/Giveaway.java b/core/src/main/java/hdvtdev/telegram/objects/Giveaway.java new file mode 100644 index 0000000..9f7a292 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/Giveaway.java @@ -0,0 +1,20 @@ +package hdvtdev.telegram.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 Giveaway( + @JsonProperty("chats") Chat[] chats, + @JsonProperty("winners_selection_date") long winnersSelectionDate, + @JsonProperty("winner_count") int winnerCount, + @JsonProperty("only_new_members") boolean onlyNewMembers, + @JsonProperty("has_public_winners") boolean hasPublicWinners, + @JsonProperty("prize_description") String prizeDescription, + @JsonProperty("country_codes") String[] countryCodes, + @JsonProperty("prize_star_count") int prizeStarCount, + @JsonProperty("premium_subscription_month_count") int premiumSubscriptionMonthCount +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/GiveawayCompleted.java b/core/src/main/java/hdvtdev/telegram/objects/GiveawayCompleted.java new file mode 100644 index 0000000..b293899 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/GiveawayCompleted.java @@ -0,0 +1,15 @@ +package hdvtdev.telegram.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 GiveawayCompleted( + @JsonProperty("winner_count") int winnerCount, + @JsonProperty("unclaimed_prize_count") int unclaimedPrizeCount, + @JsonProperty("giveaway_message") Message giveawayMessage, + @JsonProperty("is_star_giveaway") boolean isStarGiveaway +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/GiveawayCreated.java b/core/src/main/java/hdvtdev/telegram/objects/GiveawayCreated.java new file mode 100644 index 0000000..e69d7c4 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/GiveawayCreated.java @@ -0,0 +1,10 @@ +package hdvtdev.telegram.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 GiveawayCreated(@JsonProperty("prize_star_count") int prizeStarCount) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/GiveawayWinners.java b/core/src/main/java/hdvtdev/telegram/objects/GiveawayWinners.java new file mode 100644 index 0000000..028819e --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/GiveawayWinners.java @@ -0,0 +1,23 @@ +package hdvtdev.telegram.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 GiveawayWinners( + @JsonProperty("chat") Chat chat, + @JsonProperty("giveaway_message_id") long giveawayMessageId, + @JsonProperty("winners_selection_date") long winnersSelectionDate, + @JsonProperty("winners_count") int winnersCount, + @JsonProperty("winners") User[] winners, + @JsonProperty("additional_chat_count") int additionalChatCount, + @JsonProperty("prize_star_count") int prizeStarCount, + @JsonProperty("premium_subscription_month_count") int premiumSubscriptionMonthCount, + @JsonProperty("unclaimed_prize_count") int unclaimedPrizeCount, + @JsonProperty("only_new_members") boolean onlyNewMembers, + @JsonProperty("was_refunded") boolean wasRefunded, + @JsonProperty("prize_description") String prizeDescription +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/InaccessibleMessage.java b/core/src/main/java/hdvtdev/telegram/objects/InaccessibleMessage.java new file mode 100644 index 0000000..ec66ce7 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/InaccessibleMessage.java @@ -0,0 +1,15 @@ +package hdvtdev.telegram.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 InaccessibleMessage(Chat chat, @JsonProperty("message_id") int messageId, + long date) implements MaybeInaccessibleMessage { + @Override + public long chatId() { + return chat.id(); + } +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/InlineKeyboardButton.java b/core/src/main/java/hdvtdev/telegram/objects/InlineKeyboardButton.java new file mode 100644 index 0000000..0b71217 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/InlineKeyboardButton.java @@ -0,0 +1,250 @@ +package hdvtdev.telegram.objects; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public final class InlineKeyboardButton { + + @JsonProperty("text") + private final String text; + @JsonProperty("url") + private String url; + @JsonProperty("callback_data") + private String callbackData; + @JsonProperty("web_app") + private WebAppInfo webApp; + @JsonProperty("login_url") + private LoginUrl loginUrl; + @JsonProperty("switch_inline_query") + private String switchInlineQuery; + @JsonProperty("switch_inline_query_current_chat") + private String switchInlineQueryCurrentChat; + @JsonProperty("switch_inline_query_chosen_chat") + private SwitchInlineQueryChosenChat switchInlineQueryChosenChat; + @JsonProperty("copy_text") + private CopyTextButton copyTextButton; + @JsonProperty("callback_game") + private CallbackGame callbackGame; + @JsonProperty("pay") + private Boolean pay; + + @JsonCreator + public InlineKeyboardButton( + @JsonProperty("text") String text, + @JsonProperty("url") String url, + @JsonProperty("callback_data") String callbackData, + @JsonProperty("web_app") WebAppInfo webApp, + @JsonProperty("login_url") LoginUrl loginUrl, + @JsonProperty("switch_inline_query") String switchInlineQuery, + @JsonProperty("switch_inline_query_current_chat") String switchInlineQueryCurrentChat, + @JsonProperty("switch_inline_query_chosen_chat") SwitchInlineQueryChosenChat switchInlineQueryChosenChat, + @JsonProperty("copy_text") CopyTextButton copyTextButton, + @JsonProperty("callback_game") CallbackGame callbackGame, + @JsonProperty("pay") Boolean pay + ) { + this.text = text; + this.url = url; + this.callbackData = callbackData; + this.webApp = webApp; + this.loginUrl = loginUrl; + this.switchInlineQuery = switchInlineQuery; + this.switchInlineQueryCurrentChat = switchInlineQueryCurrentChat; + this.switchInlineQueryChosenChat = switchInlineQueryChosenChat; + this.copyTextButton = copyTextButton; + this.callbackGame = callbackGame; + this.pay = pay; + } + + private InlineKeyboardButton(Builder builder) { + this.text = builder.text; + setUrl(builder.url); + setCallbackData(builder.callbackData); + setWebApp(builder.webApp); + setLoginUrl(builder.loginUrl); + setSwitchInlineQuery(builder.switchInlineQuery); + setSwitchInlineQueryCurrentChat(builder.switchInlineQueryCurrentChat); + setSwitchInlineQueryChosenChat(builder.switchInlineQueryChosenChat); + setCopyTextButton(builder.copyTextButton); + setCallbackGame(builder.callbackGame); + setPay(builder.pay); + } + + public InlineKeyboardButton(String text) { + this.text = text; + } + + public InlineKeyboardButton(String text, String data) { + this.text = text; + this.callbackData = data; + } + + @JsonIgnore + public String getText() { + return text; + } + + @JsonIgnore + public String getUrl() { + return url; + } + + @JsonIgnore + public String getCallbackData() { + return callbackData; + } + + @JsonIgnore + public WebAppInfo getWebApp() { + return webApp; + } + + @JsonIgnore + public LoginUrl getLoginUrl() { + return loginUrl; + } + + @JsonIgnore + public String getSwitchInlineQuery() { + return switchInlineQuery; + } + + @JsonIgnore + public String getSwitchInlineQueryCurrentChat() { + return switchInlineQueryCurrentChat; + } + + @JsonIgnore + public SwitchInlineQueryChosenChat getSwitchInlineQueryChosenChat() { + return switchInlineQueryChosenChat; + } + + @JsonIgnore + public CopyTextButton getCopyTextButton() { + return copyTextButton; + } + + @JsonIgnore + public CallbackGame getCallbackGame() { + return callbackGame; + } + + @JsonIgnore + public Boolean getPay() { + return pay; + } + + public void setUrl(String url) { + this.url = url; + } + + public void setCallbackData(String callbackData) { + this.callbackData = callbackData; + } + + public void setWebApp(WebAppInfo webApp) { + this.webApp = webApp; + } + + public void setLoginUrl(LoginUrl loginUrl) { + this.loginUrl = loginUrl; + } + + public void setSwitchInlineQuery(String switchInlineQuery) { + this.switchInlineQuery = switchInlineQuery; + } + + public void setSwitchInlineQueryCurrentChat(String switchInlineQueryCurrentChat) { + this.switchInlineQueryCurrentChat = switchInlineQueryCurrentChat; + } + + public void setSwitchInlineQueryChosenChat(SwitchInlineQueryChosenChat switchInlineQueryChosenChat) { + this.switchInlineQueryChosenChat = switchInlineQueryChosenChat; + } + + public void setCopyTextButton(CopyTextButton copyTextButton) { + this.copyTextButton = copyTextButton; + } + + public void setCallbackGame(CallbackGame callbackGame) { + this.callbackGame = callbackGame; + } + + public void setPay(Boolean pay) { + this.pay = pay; + } + + public static final class Builder { + private final String text; + private String url; + private String callbackData; + private WebAppInfo webApp; + private LoginUrl loginUrl; + private String switchInlineQuery; + private String switchInlineQueryCurrentChat; + private SwitchInlineQueryChosenChat switchInlineQueryChosenChat; + private CopyTextButton copyTextButton; + private CallbackGame callbackGame; + private Boolean pay; + + public Builder(String text) { + this.text = text; + } + + public Builder pay(boolean pay) { + this.pay = pay; + return this; + } + + public Builder url(String url) { + this.url = url; + return this; + } + + public Builder callbackData(String callbackData) { + this.callbackData = callbackData; + return this; + } + + public Builder webApp(WebAppInfo webApp) { + this.webApp = webApp; + return this; + } + + public Builder loginUrl(LoginUrl loginUrl) { + this.loginUrl = loginUrl; + return this; + } + + public Builder switchInlineQuery(String switchInlineQuery) { + this.switchInlineQuery = switchInlineQuery; + return this; + } + + public Builder switchInlineQueryCurrentChat(String switchInlineQueryCurrentChat) { + this.switchInlineQueryCurrentChat = switchInlineQueryCurrentChat; + return this; + } + + public Builder switchInlineQueryChosenChat(SwitchInlineQueryChosenChat switchInlineQueryChosenChat) { + this.switchInlineQueryChosenChat = switchInlineQueryChosenChat; + return this; + } + + public Builder copyTextButton(CopyTextButton copyTextButton) { + this.copyTextButton = copyTextButton; + return this; + } + + public Builder callbackGame(CallbackGame callbackGame) { + this.callbackGame = callbackGame; + return this; + } + + public InlineKeyboardButton build() { + return new InlineKeyboardButton(this); + } + } +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/InlineKeyboardMarkup.java b/core/src/main/java/hdvtdev/telegram/objects/InlineKeyboardMarkup.java new file mode 100644 index 0000000..34ff270 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/InlineKeyboardMarkup.java @@ -0,0 +1,35 @@ +package hdvtdev.telegram.objects; + +import com.fasterxml.jackson.annotation.*; + +import java.util.List; + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public record InlineKeyboardMarkup( + @JsonProperty("inline_keyboard") InlineKeyboardRow... keyboard) implements ReplyMarkup { + + @JsonCreator + public InlineKeyboardMarkup(@JsonProperty("inline_keyboard") InlineKeyboardButton[][] keyboardButtons) { + this(convertToInlineKeyboardRow(keyboardButtons)); + } + + public InlineKeyboardMarkup(List inlineKeyboardRows) { + this(inlineKeyboardRows.toArray(new InlineKeyboardRow[0])); + } + + @JsonIgnore + private static InlineKeyboardRow[] convertToInlineKeyboardRow(InlineKeyboardButton[][] keyboardButtons) { + InlineKeyboardRow[] rows = new InlineKeyboardRow[keyboardButtons.length]; + for (int i = 0; i < keyboardButtons.length; i++) { + rows[i] = new InlineKeyboardRow(keyboardButtons[i]); + } + return rows; + } + + @JsonIgnore + public static InlineKeyboardMarkup ofSingleButton(InlineKeyboardButton button) { + return new InlineKeyboardMarkup(new InlineKeyboardRow(button)); + } + +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/InlineKeyboardRow.java b/core/src/main/java/hdvtdev/telegram/objects/InlineKeyboardRow.java new file mode 100644 index 0000000..cb1665e --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/InlineKeyboardRow.java @@ -0,0 +1,69 @@ +package hdvtdev.telegram.objects; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonValue; +import org.jetbrains.annotations.NotNull; + +import java.util.AbstractList; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + + +public final class InlineKeyboardRow extends AbstractList { + + @JsonIgnore + private final ArrayList buttonsList = new ArrayList<>(); + + public InlineKeyboardRow() { + + } + + public InlineKeyboardButton remove(int i) { + return this.buttonsList.remove(i); + } + + @JsonIgnore + @Override + public void clear() { + this.buttonsList.clear(); + } + + @JsonIgnore + @Override + public int size() { + return this.buttonsList.size(); + } + + @JsonIgnore + @Override + public boolean addAll(@NotNull Collection buttons) { + return this.buttonsList.addAll(buttons); + } + + public void addAll(InlineKeyboardButton... buttons) { + this.buttonsList.addAll(List.of(buttons)); + } + + public InlineKeyboardRow(InlineKeyboardButton... buttons) { + this.buttonsList.addAll(List.of(buttons)); + } + + @JsonIgnore + @Override + public boolean add(InlineKeyboardButton button) { + return this.buttonsList.add(button); + } + + @JsonIgnore + @Override + public InlineKeyboardButton get(int i) { + return this.buttonsList.get(i); + } + + @JsonValue + public List buttons() { + return buttonsList; + } + +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/InlineQuery.java b/core/src/main/java/hdvtdev/telegram/objects/InlineQuery.java new file mode 100644 index 0000000..2738525 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/InlineQuery.java @@ -0,0 +1,17 @@ +package hdvtdev.telegram.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 +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/Invoice.java b/core/src/main/java/hdvtdev/telegram/objects/Invoice.java new file mode 100644 index 0000000..04b2ca1 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/Invoice.java @@ -0,0 +1,16 @@ +package hdvtdev.telegram.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 Invoice( + @JsonProperty("title") String title, + @JsonProperty("description") String description, + @JsonProperty("start_parameter") String startParameter, + @JsonProperty("currency") String currency, + @JsonProperty("total_amount") int totalAmount +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/KeyboardButton.java b/core/src/main/java/hdvtdev/telegram/objects/KeyboardButton.java new file mode 100644 index 0000000..6e82940 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/KeyboardButton.java @@ -0,0 +1,18 @@ +package hdvtdev.telegram.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 KeyboardButton( + @JsonProperty("text") String text, + @JsonProperty("request_users") KeyboardButtonRequestUsers requestUsers, + @JsonProperty("request_chat") KeyboardButtonRequestChat requestChat, + @JsonProperty("request_contact") boolean requestContact, + @JsonProperty("request_location") boolean requestLocation, + @JsonProperty("request_poll") KeyboardButtonPollType requestPoll, + @JsonProperty("web_app") WebAppInfo webApp +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/KeyboardButtonPollType.java b/core/src/main/java/hdvtdev/telegram/objects/KeyboardButtonPollType.java new file mode 100644 index 0000000..3f6c38b --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/KeyboardButtonPollType.java @@ -0,0 +1,12 @@ +package hdvtdev.telegram.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 KeyboardButtonPollType( + @JsonProperty("type") String type +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/KeyboardButtonRequestChat.java b/core/src/main/java/hdvtdev/telegram/objects/KeyboardButtonRequestChat.java new file mode 100644 index 0000000..d5181f1 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/KeyboardButtonRequestChat.java @@ -0,0 +1,22 @@ +package hdvtdev.telegram.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 KeyboardButtonRequestChat( + @JsonProperty("request_id") Integer requestId, + @JsonProperty("chat_is_channel") boolean chatIsChannel, + @JsonProperty("chat_is_forum") boolean chatIsForum, + @JsonProperty("chat_has_username") boolean chatHasUsername, + @JsonProperty("chat_is_created") boolean chatIsCreated, + @JsonProperty("user_administrator_rights") ChatAdministratorRights userAdministratorRights, + @JsonProperty("bot_administrator_rights") ChatAdministratorRights botAdministratorRights, + @JsonProperty("bot_is_member") boolean botIsMember, + @JsonProperty("request_title") boolean requestTitle, + @JsonProperty("request_username") boolean requestUsername, + @JsonProperty("request_photo") boolean requestPhoto +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/KeyboardButtonRequestUsers.java b/core/src/main/java/hdvtdev/telegram/objects/KeyboardButtonRequestUsers.java new file mode 100644 index 0000000..9f417c4 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/KeyboardButtonRequestUsers.java @@ -0,0 +1,18 @@ +package hdvtdev.telegram.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 KeyboardButtonRequestUsers( + @JsonProperty("request_id") Integer requestId, + @JsonProperty("user_is_bot") boolean userIsBot, + @JsonProperty("user_is_premium") boolean userIsPremium, + @JsonProperty("max_quantity") Integer maxQuantity, + @JsonProperty("request_name") Boolean requestName, + @JsonProperty("request_username") Boolean requestUsername, + @JsonProperty("request_photo") Boolean requestPhoto +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/LinkPreviewOptions.java b/core/src/main/java/hdvtdev/telegram/objects/LinkPreviewOptions.java new file mode 100644 index 0000000..9aefc6e --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/LinkPreviewOptions.java @@ -0,0 +1,17 @@ +package hdvtdev.telegram.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 LinkPreviewOptions( + @JsonProperty("is_disabled") boolean isDisabled, + @JsonProperty("url") String url, + @JsonProperty("prefer_small_media") boolean preferSmallMedia, + @JsonProperty("prefer_large_media") boolean preferLargeMedia, + @JsonProperty("show_above_text") boolean showAboveText + +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/Location.java b/core/src/main/java/hdvtdev/telegram/objects/Location.java new file mode 100644 index 0000000..23f669b --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/Location.java @@ -0,0 +1,17 @@ +package hdvtdev.telegram.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 +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/LoginUrl.java b/core/src/main/java/hdvtdev/telegram/objects/LoginUrl.java new file mode 100644 index 0000000..6fce8da --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/LoginUrl.java @@ -0,0 +1,15 @@ +package hdvtdev.telegram.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 +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/MaskPosition.java b/core/src/main/java/hdvtdev/telegram/objects/MaskPosition.java new file mode 100644 index 0000000..deb02df --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/MaskPosition.java @@ -0,0 +1,15 @@ +package hdvtdev.telegram.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 +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/MaybeInaccessibleMessage.java b/core/src/main/java/hdvtdev/telegram/objects/MaybeInaccessibleMessage.java new file mode 100644 index 0000000..bb27697 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/MaybeInaccessibleMessage.java @@ -0,0 +1,15 @@ +package hdvtdev.telegram.objects; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +@JsonDeserialize(using = MaybeInaccessibleMessageDeserializer.class) +public interface MaybeInaccessibleMessage { + long chatId(); + + Chat chat(); + + int messageId(); + + long date(); + +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/MaybeInaccessibleMessageDeserializer.java b/core/src/main/java/hdvtdev/telegram/objects/MaybeInaccessibleMessageDeserializer.java new file mode 100644 index 0000000..44ecc07 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/MaybeInaccessibleMessageDeserializer.java @@ -0,0 +1,16 @@ +package hdvtdev.telegram.objects; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; + +import java.io.IOException; + +public class MaybeInaccessibleMessageDeserializer extends JsonDeserializer { + + @Override + public MaybeInaccessibleMessage deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { + Message msg = p.getCodec().readValue(p, Message.class); + return msg.date() == 0 ? new InaccessibleMessage(msg.chat(), msg.messageId(), 0) : msg; + } +} \ No newline at end of file diff --git a/core/src/main/java/hdvtdev/telegram/objects/Message.java b/core/src/main/java/hdvtdev/telegram/objects/Message.java new file mode 100644 index 0000000..64ba755 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/Message.java @@ -0,0 +1,274 @@ +package hdvtdev.telegram.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 Message( + @JsonProperty("message_id") int messageId, + @JsonProperty("message_thread_id") Long messageThreadId, + @JsonProperty("from") User user, + @JsonProperty("sender_chat") Chat senderChat, + @JsonProperty("sender_boost_count") Integer senderBoostCount, + @JsonProperty("sender_business_bot") User senderBusinessBot, + @JsonProperty("date") long date, + @JsonProperty("business_connection_id") String businessConnectionId, + @JsonProperty("chat") Chat chat, + @JsonProperty("forward_origin") MessageOrigin forwardOrigin, + @JsonProperty("is_topic_message") boolean isTopicMessage, + @JsonProperty("is_automatic_forward") boolean isAutomaticForward, + @JsonProperty("reply_to_message") Message replyToMessage, + @JsonProperty("external_reply") ExternalReplyInfo externalReply, + @JsonProperty("quote") TextQuote quote, + @JsonProperty("reply_to_story") Story replyToStory, + @JsonProperty("via_bot") User viaBot, + @JsonProperty("edit_date") long editDate, + @JsonProperty("has_protected_content") boolean hasProtectedContent, + @JsonProperty("is_from_offline") boolean isFromOnline, + @JsonProperty("media_group_id") String mediaGroupId, + @JsonProperty("author_signature") String authorSignature, + @JsonProperty("text") String text, + @JsonProperty("entities") MessageEntity[] entities, + @JsonProperty("link_preview_options") LinkPreviewOptions linkPreviewOptions, + @JsonProperty("effect_id") String effectId, + @JsonProperty("animation") Animation animation, + @JsonProperty("audio") Audio audio, + @JsonProperty("document") Document document, + @JsonProperty("paid_media") PaidMediaInfo paidMediaInfo, + @JsonProperty("photo") PhotoSize[] photo, + @JsonProperty("sticker") Sticker sticker, + @JsonProperty("story") Story story, + @JsonProperty("video") Video video, + @JsonProperty("video_note") VideoNote videoNote, + @JsonProperty("voice") Voice voice, + @JsonProperty("caption") String caption, + @JsonProperty("caption_entities") MessageEntity[] captionEntities, + @JsonProperty("show_caption_above_media") boolean showCaptionAboveMedia, + @JsonProperty("has_media_spoiler") boolean hasMediaSpoiler, + @JsonProperty("contact") Contact contact, + @JsonProperty("dice") Dice dice, + @JsonProperty("game") Game game, + @JsonProperty("poll") Poll poll, + @JsonProperty("venue") Venue venue, + @JsonProperty("location") Location location, + @JsonProperty("new_chat_members") User[] newChatMembers, + @JsonProperty("left_chat_member") User leftChatMember, + @JsonProperty("new_chat_title") String newChatTitle, + @JsonProperty("new_chat_photo") PhotoSize[] newChatPhoto, + @JsonProperty("delete_chat_photo") boolean deleteChatPhoto, + @JsonProperty("group_chat_created") boolean groupChatCreated, + @JsonProperty("supergroup_chat_created") boolean supergroupChatCreated, + @JsonProperty("channel_chat_created") boolean channelChatCreated, + @JsonProperty("message_auto_delete_timer_changed") MessageAutoDeleteTimerChanged messageAutoDeleteTimerChanged, + @JsonProperty("migrate_to_chat_id") Long migrateToChatId, + @JsonProperty("migrate_from_chat_id") Long migrateFromChatId, + @JsonProperty("pinned_message") MaybeInaccessibleMessage pinnedMessage, + @JsonProperty("invoice") Invoice invoice, + @JsonProperty("successful_payment") SuccessfulPayment successfulPayment, + @JsonProperty("refunded_payment") RefundedPayment refundedPayment, + @JsonProperty("users_shared") UsersShared usersShared, + @JsonProperty("chat_shared") ChatShared chatShared, + @JsonProperty("connected_website") String connectedWebsite, + @JsonProperty("write_access_allowed") WriteAccessAllowed writeAccessAllowed, + @JsonProperty("passport_data") PassportData passportData, + @JsonProperty("proximity_alert_triggered") ProximityAlertTriggered proximityAlertTriggered, + @JsonProperty("boost_added") ChatBoostAdded chatBoostAdded, + @JsonProperty("chat_background_set") ChatBackground chatBackground, + @JsonProperty("forum_topic_created") ForumTopicCreated forumTopicCreated, + @JsonProperty("forum_topic_edited") ForumTopicEdited forumTopicEdited, + @JsonProperty("forum_topic_closed") ForumTopicClosed forumTopicClosed, + @JsonProperty("forum_topic_reopened") ForumTopicReopened forumTopicReopened, + @JsonProperty("general_forum_topic_hidden") GeneralForumTopicHidden generalForumTopicHidden, + @JsonProperty("general_forum_topic_unhidden") GeneralForumTopicUnhidden generalForumTopicUnhidden, + @JsonProperty("giveaway_created") GiveawayCreated giveawayCreated, + @JsonProperty("giveaway") Giveaway giveaway, + @JsonProperty("giveaway_winners") GiveawayWinners giveawayWinners, + @JsonProperty("giveaway_completed") GiveawayCompleted giveawayCompleted, + @JsonProperty("video_chat_scheduled") VideoChatScheduled videoChatScheduled, + @JsonProperty("video_chat_started") VideoChatStarted videoChatStarted, + @JsonProperty("video_chat_ended") VideoChatEnded videoChatEnded, + @JsonProperty("video_chat_participants_invited") VideoChatParticipantsInvited videoChatParticipantsInvited, + @JsonProperty("web_app_data") WebAppData webAppData, + @JsonProperty("reply_markup") InlineKeyboardMarkup inlineKeyboardMarkup + +) implements MaybeInaccessibleMessage { + + public boolean hasMessageThreadId() { + return messageThreadId != null; + } + + public boolean hasSenderChat() { + return senderChat != null; + } + + public boolean hasSenderBoostCount() { + return senderBoostCount != null; + } + + public boolean hasSenderBusinessBot() { + return senderBusinessBot != null; + } + + public boolean hasBusinessConnectionId() { + return businessConnectionId != null; + } + + public boolean hasForwardOrigin() { + return forwardOrigin != null; + } + + public boolean hasReplyToMessage() { + return replyToMessage != null; + } + + public boolean hasExternalReply() { + return externalReply != null; + } + + public boolean hasQuote() { + return quote != null; + } + + public boolean hasReplyToStory() { + return replyToStory != null; + } + + public boolean hasViaBot() { + return viaBot != null; + } + + public boolean hasEditDate() { + return editDate != 0; + } + + public boolean hasMediaGroupId() { + return mediaGroupId != null; + } + + public boolean hasAuthorSignature() { + return authorSignature != null; + } + + public boolean hasText() { + return text != null; + } + + public boolean hasEntities() { + return entities != null; + } + + public boolean hasLinkPreviewOptions() { + return linkPreviewOptions != null; + } + + public boolean hasEffectId() { + return effectId != null; + } + + public boolean hasAnimation() { + return animation != null; + } + + public boolean hasAudio() { + return audio != null; + } + + public boolean hasDocument() { + return document != null; + } + + public boolean hasPaidMediaInfo() { + return paidMediaInfo != null; + } + + public boolean hasPhoto() { + return photo != null; + } + + public boolean hasSticker() { + return sticker != null; + } + + public boolean hasStory() { + return story != null; + } + + public boolean hasVideo() { + return video != null; + } + + public boolean hasVideoNote() { + return videoNote != null; + } + + public boolean hasVoice() { + return voice != null; + } + + public boolean hasCaption() { + return caption != null; + } + + public boolean hasCaptionEntities() { + return captionEntities != null; + } + + public boolean hasContact() { + return contact != null; + } + + public boolean hasDice() { + return dice != null; + } + + public boolean hasGame() { + return game != null; + } + + public boolean hasPoll() { + return poll != null; + } + + public boolean hasVenue() { + return venue != null; + } + + public boolean hasLocation() { + return location != null; + } + + public boolean hasNewChatMembers() { + return newChatMembers != null; + } + + public boolean hasLeftChatMember() { + return leftChatMember != null; + } + + public boolean hasNewChatTitle() { + return newChatTitle != null; + } + + public boolean hasNewChatPhoto() { + return newChatPhoto != null; + } + + public boolean hasMessageAutoDeleteTimerChanged() { + return messageAutoDeleteTimerChanged != null; + } + + public boolean hasMigrateToChatId() { + return migrateToChatId != null; + } + + public boolean hasMigrateFromChatId() { + return migrateFromChatId != null; + } + + @Override + public long chatId() { + return this.chat.id(); + } +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/MessageAutoDeleteTimerChanged.java b/core/src/main/java/hdvtdev/telegram/objects/MessageAutoDeleteTimerChanged.java new file mode 100644 index 0000000..d2b30a0 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/MessageAutoDeleteTimerChanged.java @@ -0,0 +1,10 @@ +package hdvtdev.telegram.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 MessageAutoDeleteTimerChanged(@JsonProperty("message_auto_delete_time") long messageAutoDeleteTime) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/MessageEntity.java b/core/src/main/java/hdvtdev/telegram/objects/MessageEntity.java new file mode 100644 index 0000000..68f6bb5 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/MessageEntity.java @@ -0,0 +1,18 @@ +package hdvtdev.telegram.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 MessageEntity( + @JsonProperty("type") String type, + @JsonProperty("offset") int offset, + @JsonProperty("length") int length, + @JsonProperty("url") String url, + @JsonProperty("user") User user, + @JsonProperty("language") String language, + @JsonProperty("custom_emoji_id") String customEmojiId +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/MessageOrigin.java b/core/src/main/java/hdvtdev/telegram/objects/MessageOrigin.java new file mode 100644 index 0000000..4716239 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/MessageOrigin.java @@ -0,0 +1,19 @@ +package hdvtdev.telegram.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 = MessageOriginUser.class, name = "user"), + @JsonSubTypes.Type(value = MessageOriginHiddenUser.class, name = "hidden_user"), + @JsonSubTypes.Type(value = MessageOriginChat.class, name = "chat"), + @JsonSubTypes.Type(value = MessageOriginChannel.class, name = "channel") +}) +public interface MessageOrigin { + +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/MessageOriginChannel.java b/core/src/main/java/hdvtdev/telegram/objects/MessageOriginChannel.java new file mode 100644 index 0000000..73903e3 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/MessageOriginChannel.java @@ -0,0 +1,16 @@ +package hdvtdev.telegram.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 MessageOriginChannel( + @JsonProperty("type") String type, + @JsonProperty("date") long date, + @JsonProperty("chat") Chat chat, + @JsonProperty("message_id") long messageId, + @JsonProperty("author_signature") String authorSignature +) implements MessageOrigin { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/MessageOriginChat.java b/core/src/main/java/hdvtdev/telegram/objects/MessageOriginChat.java new file mode 100644 index 0000000..558e3a7 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/MessageOriginChat.java @@ -0,0 +1,15 @@ +package hdvtdev.telegram.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 MessageOriginChat( + @JsonProperty("type") String type, + @JsonProperty("date") long date, + @JsonProperty("sender_chat") Chat senderChat, + @JsonProperty("author_signature") String authorSignature +) implements MessageOrigin { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/MessageOriginHiddenUser.java b/core/src/main/java/hdvtdev/telegram/objects/MessageOriginHiddenUser.java new file mode 100644 index 0000000..ea5b8ca --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/MessageOriginHiddenUser.java @@ -0,0 +1,14 @@ +package hdvtdev.telegram.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 MessageOriginHiddenUser( + @JsonProperty("type") String type, + @JsonProperty("date") long date, + @JsonProperty("sender_user_name") String senderUserName +) implements MessageOrigin { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/MessageOriginUser.java b/core/src/main/java/hdvtdev/telegram/objects/MessageOriginUser.java new file mode 100644 index 0000000..1b3614e --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/MessageOriginUser.java @@ -0,0 +1,14 @@ +package hdvtdev.telegram.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 MessageOriginUser( + @JsonProperty("type") String type, + @JsonProperty("date") long date, + @JsonProperty("sender_user") User senderUser +) implements MessageOrigin { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/MessageReactionCountUpdated.java b/core/src/main/java/hdvtdev/telegram/objects/MessageReactionCountUpdated.java new file mode 100644 index 0000000..ef74f64 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/MessageReactionCountUpdated.java @@ -0,0 +1,15 @@ +package hdvtdev.telegram.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 MessageReactionCountUpdated( + @JsonProperty("chat") Chat chat, + @JsonProperty("message_id") long messageId, + @JsonProperty("date") long date, + @JsonProperty("reactions") ReactionCount[] reactions +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/MessageReactionUpdated.java b/core/src/main/java/hdvtdev/telegram/objects/MessageReactionUpdated.java new file mode 100644 index 0000000..fea1ccc --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/MessageReactionUpdated.java @@ -0,0 +1,18 @@ +package hdvtdev.telegram.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 MessageReactionUpdated( + @JsonProperty("chat") Chat chat, + @JsonProperty("message_id") long messageId, + @JsonProperty("user") User user, + @JsonProperty("actor_chat") Chat actorChat, + @JsonProperty("date") long date, + @JsonProperty("old_reaction") ReactionType[] oldReaction, + @JsonProperty("new_reaction") ReactionType[] newReaction +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/OrderInfo.java b/core/src/main/java/hdvtdev/telegram/objects/OrderInfo.java new file mode 100644 index 0000000..f214e41 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/OrderInfo.java @@ -0,0 +1,15 @@ +package hdvtdev.telegram.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 OrderInfo( + @JsonProperty("name") String name, + @JsonProperty("phone_number") String phoneNumber, + @JsonProperty("email") String email, + @JsonProperty("shipping_address") ShippingAddress shippingAddress +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/PaidMedia.java b/core/src/main/java/hdvtdev/telegram/objects/PaidMedia.java new file mode 100644 index 0000000..73703a3 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/PaidMedia.java @@ -0,0 +1,17 @@ +package hdvtdev.telegram.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 = PaidMediaPreview.class, name = "preview"), + @JsonSubTypes.Type(value = PaidMediaPhoto.class, name = "photo"), + @JsonSubTypes.Type(value = PaidMediaVideo.class, name = "video") +}) +public interface PaidMedia { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/PaidMediaInfo.java b/core/src/main/java/hdvtdev/telegram/objects/PaidMediaInfo.java new file mode 100644 index 0000000..ff95de6 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/PaidMediaInfo.java @@ -0,0 +1,13 @@ +package hdvtdev.telegram.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 PaidMediaInfo( + @JsonProperty("star_count") int startCount, + @JsonProperty("paid_media") PaidMedia[] paidMedia +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/PaidMediaPhoto.java b/core/src/main/java/hdvtdev/telegram/objects/PaidMediaPhoto.java new file mode 100644 index 0000000..a78e5b9 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/PaidMediaPhoto.java @@ -0,0 +1,13 @@ +package hdvtdev.telegram.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 PaidMediaPhoto( + @JsonProperty("type") String type, + @JsonProperty("photo") PhotoSize[] photo +) implements PaidMedia { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/PaidMediaPreview.java b/core/src/main/java/hdvtdev/telegram/objects/PaidMediaPreview.java new file mode 100644 index 0000000..f763a38 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/PaidMediaPreview.java @@ -0,0 +1,15 @@ +package hdvtdev.telegram.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 PaidMediaPreview( + @JsonProperty("type") String type, + @JsonProperty("width") int width, + @JsonProperty("height") int height, + @JsonProperty("duration") int duration +) implements PaidMedia { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/PaidMediaPurchased.java b/core/src/main/java/hdvtdev/telegram/objects/PaidMediaPurchased.java new file mode 100644 index 0000000..32475dd --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/PaidMediaPurchased.java @@ -0,0 +1,13 @@ +package hdvtdev.telegram.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 PaidMediaPurchased( + @JsonProperty("from") User from, + @JsonProperty("paid_media_payload") String paidMediaPayload +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/PaidMediaVideo.java b/core/src/main/java/hdvtdev/telegram/objects/PaidMediaVideo.java new file mode 100644 index 0000000..dc65b58 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/PaidMediaVideo.java @@ -0,0 +1,13 @@ +package hdvtdev.telegram.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 PaidMediaVideo( + @JsonProperty("type") String type, + @JsonProperty("video") Video video +) implements PaidMedia { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/PassportData.java b/core/src/main/java/hdvtdev/telegram/objects/PassportData.java new file mode 100644 index 0000000..6633ae8 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/PassportData.java @@ -0,0 +1,13 @@ +package hdvtdev.telegram.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 PassportData( + @JsonProperty("data") EncryptedPassportElement[] data, + @JsonProperty("credentials") EncryptedCredentials credentials +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/PassportFile.java b/core/src/main/java/hdvtdev/telegram/objects/PassportFile.java new file mode 100644 index 0000000..6247580 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/PassportFile.java @@ -0,0 +1,15 @@ +package hdvtdev.telegram.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 PassportFile( + @JsonProperty("file_id") String fileId, + @JsonProperty("file_unique_id") String fileUniqueId, + @JsonProperty("file_size") long fileSize, + @JsonProperty("file_date") long fileDate +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/PhotoSize.java b/core/src/main/java/hdvtdev/telegram/objects/PhotoSize.java new file mode 100644 index 0000000..6fcf9ad --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/PhotoSize.java @@ -0,0 +1,16 @@ +package hdvtdev.telegram.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 PhotoSize( + @JsonProperty("file_id") String fileId, + @JsonProperty("file_unique_id") String fileUniqueId, + @JsonProperty("width") int width, + @JsonProperty("height") int height, + @JsonProperty("file_size") long file_size +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/Poll.java b/core/src/main/java/hdvtdev/telegram/objects/Poll.java new file mode 100644 index 0000000..43637d8 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/Poll.java @@ -0,0 +1,25 @@ +package hdvtdev.telegram.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 Poll( + @JsonProperty("id") String id, + @JsonProperty("question") String question, + @JsonProperty("question_entities") MessageEntity[] questionEntities, + @JsonProperty("options") PollOption[] options, + @JsonProperty("total_voter_count") int totalVoterCount, + @JsonProperty("is_closed") boolean isClosed, + @JsonProperty("is_anonymous") boolean isAnonymous, + @JsonProperty("type") String type, + @JsonProperty("allows_multiple_answers") boolean allowMultipleAnswers, + @JsonProperty("correct_option_id") int correctOptionId, + @JsonProperty("explanation") String explanation, + @JsonProperty("explanation_entities") MessageEntity[] explanationEntities, + @JsonProperty("open_period") long openPeriod, + @JsonProperty("close_date") long closeDate +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/PollAnswer.java b/core/src/main/java/hdvtdev/telegram/objects/PollAnswer.java new file mode 100644 index 0000000..beea375 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/PollAnswer.java @@ -0,0 +1,15 @@ +package hdvtdev.telegram.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 PollAnswer( + @JsonProperty("poll_id") String pollId, + @JsonProperty("voter_chat") Chat voterChat, + @JsonProperty("user") User user, + @JsonProperty("option_ids") int[] optionsIds +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/PollOption.java b/core/src/main/java/hdvtdev/telegram/objects/PollOption.java new file mode 100644 index 0000000..2616815 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/PollOption.java @@ -0,0 +1,14 @@ +package hdvtdev.telegram.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 PollOption( + @JsonProperty("text") String text, + @JsonProperty("text_entities") MessageEntity[] textEntities, + @JsonProperty("voter_count") int voterCount +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/PreCheckoutQuery.java b/core/src/main/java/hdvtdev/telegram/objects/PreCheckoutQuery.java new file mode 100644 index 0000000..d42e5c4 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/PreCheckoutQuery.java @@ -0,0 +1,18 @@ +package hdvtdev.telegram.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 PreCheckoutQuery( + @JsonProperty("id") String id, + @JsonProperty("from") User from, + @JsonProperty("currency") String currency, + @JsonProperty("total_amount") int totalAmount, + @JsonProperty("invoice_payload") String invoicePayload, + @JsonProperty("shipping_option_id") String shippingOptionId, + @JsonProperty("order_info") OrderInfo orderInfo +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ProximityAlertTriggered.java b/core/src/main/java/hdvtdev/telegram/objects/ProximityAlertTriggered.java new file mode 100644 index 0000000..303c3b8 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ProximityAlertTriggered.java @@ -0,0 +1,14 @@ +package hdvtdev.telegram.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 +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ReactionCount.java b/core/src/main/java/hdvtdev/telegram/objects/ReactionCount.java new file mode 100644 index 0000000..9ace7e4 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ReactionCount.java @@ -0,0 +1,13 @@ +package hdvtdev.telegram.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 ReactionCount( + @JsonProperty("type") ReactionType type, + @JsonProperty("total_count") int totalCount +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ReactionType.java b/core/src/main/java/hdvtdev/telegram/objects/ReactionType.java new file mode 100644 index 0000000..76aaff4 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ReactionType.java @@ -0,0 +1,17 @@ +package hdvtdev.telegram.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 = ReactionTypeEmoji.class, name = "emoji"), + @JsonSubTypes.Type(value = ReactionTypeCustomEmoji.class, name = "custom_emoji"), + @JsonSubTypes.Type(value = ReactionTypePaid.class, name = "paid") +}) +public interface ReactionType { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ReactionTypeCustomEmoji.java b/core/src/main/java/hdvtdev/telegram/objects/ReactionTypeCustomEmoji.java new file mode 100644 index 0000000..2b5ee8f --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ReactionTypeCustomEmoji.java @@ -0,0 +1,13 @@ +package hdvtdev.telegram.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 ReactionTypeCustomEmoji( + @JsonProperty("type") String type, + @JsonProperty("custom_emoji_id") String customEmojiId +) implements ReactionType { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ReactionTypeEmoji.java b/core/src/main/java/hdvtdev/telegram/objects/ReactionTypeEmoji.java new file mode 100644 index 0000000..a6b31f2 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ReactionTypeEmoji.java @@ -0,0 +1,16 @@ +package hdvtdev.telegram.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 ReactionTypeEmoji( + @JsonProperty("type") String type, + @JsonProperty("emoji") String emoji +) implements ReactionType { + public ReactionTypeEmoji(String emoji) { + this("emoji", emoji); + } +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ReactionTypePaid.java b/core/src/main/java/hdvtdev/telegram/objects/ReactionTypePaid.java new file mode 100644 index 0000000..cc639b8 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ReactionTypePaid.java @@ -0,0 +1,12 @@ +package hdvtdev.telegram.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 ReactionTypePaid( + @JsonProperty("type") String type +) implements ReactionType { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/RefundedPayment.java b/core/src/main/java/hdvtdev/telegram/objects/RefundedPayment.java new file mode 100644 index 0000000..3c98a87 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/RefundedPayment.java @@ -0,0 +1,16 @@ +package hdvtdev.telegram.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 RefundedPayment( + @JsonProperty("currency") String currency, + @JsonProperty("total_amount") int totalAmount, + @JsonProperty("invoice_payload") String invoicePayload, + @JsonProperty("telegram_payment_charge_id") String telegramPaymentChargeId, + @JsonProperty("provider_payment_charge_id") String providerPaymentChargeId +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ReplyKeyboardMarkup.java b/core/src/main/java/hdvtdev/telegram/objects/ReplyKeyboardMarkup.java new file mode 100644 index 0000000..e34dec0 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ReplyKeyboardMarkup.java @@ -0,0 +1,17 @@ +package hdvtdev.telegram.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 ReplyKeyboardMarkup( + @JsonProperty("keyboard") KeyboardButton[][] keyboard, + @JsonProperty("is_persistent") boolean isPersistent, + @JsonProperty("resize_keyboard") boolean resizeKeyboard, + @JsonProperty("one_time_keyboard") boolean oneTimeKeyboard, + @JsonProperty("input_field_placeholder") String inputFieldPlaceholder, + @JsonProperty("selective") boolean selective +) implements ReplyMarkup { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ReplyKeyboardRemove.java b/core/src/main/java/hdvtdev/telegram/objects/ReplyKeyboardRemove.java new file mode 100644 index 0000000..cf1c8f9 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ReplyKeyboardRemove.java @@ -0,0 +1,13 @@ +package hdvtdev.telegram.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 ReplyKeyboardRemove( + @JsonProperty("remove_keyboard") boolean removeKeyboard, + @JsonProperty("selective") boolean selective +) implements ReplyMarkup { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ReplyMarkup.java b/core/src/main/java/hdvtdev/telegram/objects/ReplyMarkup.java new file mode 100644 index 0000000..42abbbb --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ReplyMarkup.java @@ -0,0 +1,16 @@ +package hdvtdev.telegram.objects; + +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; + +@JsonTypeInfo( + use = JsonTypeInfo.Id.DEDUCTION, + defaultImpl = Void.class +) +@JsonSubTypes({ + @JsonSubTypes.Type(value = ReplyKeyboardMarkup.class), + @JsonSubTypes.Type(value = InlineKeyboardMarkup.class), + @JsonSubTypes.Type(value = ReplyKeyboardRemove.class) +}) +public interface ReplyMarkup { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ReplyParameters.java b/core/src/main/java/hdvtdev/telegram/objects/ReplyParameters.java new file mode 100644 index 0000000..cf10443 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ReplyParameters.java @@ -0,0 +1,28 @@ +package hdvtdev.telegram.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)); + } + + +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/SharedUser.java b/core/src/main/java/hdvtdev/telegram/objects/SharedUser.java new file mode 100644 index 0000000..540c0cb --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/SharedUser.java @@ -0,0 +1,16 @@ +package hdvtdev.telegram.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 +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ShippingAddress.java b/core/src/main/java/hdvtdev/telegram/objects/ShippingAddress.java new file mode 100644 index 0000000..a894bc9 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ShippingAddress.java @@ -0,0 +1,17 @@ +package hdvtdev.telegram.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 ShippingAddress( + @JsonProperty("country_code") String countryCode, + @JsonProperty("state") String state, + @JsonProperty("city") String city, + @JsonProperty("street_line1") String firstStreetLine, + @JsonProperty("street_line2") String secondStreetLine, + @JsonProperty("post_code") String postCode +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/ShippingQuery.java b/core/src/main/java/hdvtdev/telegram/objects/ShippingQuery.java new file mode 100644 index 0000000..6916978 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/ShippingQuery.java @@ -0,0 +1,15 @@ +package hdvtdev.telegram.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 ShippingQuery( + @JsonProperty("id") String id, + @JsonProperty("from") User from, + @JsonProperty("invoice_payload") String invoicePayload, + @JsonProperty("shipping_address") ShippingAddress shippingAddress +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/Sticker.java b/core/src/main/java/hdvtdev/telegram/objects/Sticker.java new file mode 100644 index 0000000..859a71a --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/Sticker.java @@ -0,0 +1,26 @@ +package hdvtdev.telegram.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 Sticker( + @JsonProperty("file_id") String fileId, + @JsonProperty("file_unique_id") String fileUniqueId, + @JsonProperty("type") String type, + @JsonProperty("width") int width, + @JsonProperty("height") int height, + @JsonProperty("is_animated") boolean isAnimated, + @JsonProperty("is_video") boolean isVideo, + @JsonProperty("thumbnail") PhotoSize thumbnail, + @JsonProperty("emoji") String emoji, + @JsonProperty("set_name") String setName, + @JsonProperty("premium_animation") TelegramFile premiumAnimation, + @JsonProperty("mask_position") MaskPosition maskPosition, + @JsonProperty("custom_emoji_id") String customEmojiId, + @JsonProperty("needs_repairing") boolean needsRepairing, + @JsonProperty("file_size") long fileSize +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/Story.java b/core/src/main/java/hdvtdev/telegram/objects/Story.java new file mode 100644 index 0000000..518583e --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/Story.java @@ -0,0 +1,13 @@ +package hdvtdev.telegram.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 Story( + @JsonProperty("chat") Chat chat, + @JsonProperty("id") long id +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/SuccessfulPayment.java b/core/src/main/java/hdvtdev/telegram/objects/SuccessfulPayment.java new file mode 100644 index 0000000..a4e2029 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/SuccessfulPayment.java @@ -0,0 +1,21 @@ +package hdvtdev.telegram.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 SuccessfulPayment( + @JsonProperty("currency") String currency, + @JsonProperty("total_amount") int totalAmount, //price + @JsonProperty("invoice_payload") String invoicePayload, + @JsonProperty("subscription_expiration_date") long subscriptionExpirationDate, + @JsonProperty("is_recurring") boolean isRecurring, + @JsonProperty("is_first_recurring") boolean isFirstRecurring, + @JsonProperty("shipping_option_id") String shippingOptionId, + @JsonProperty("order_info") OrderInfo orderInfo, + @JsonProperty("telegram_payment_charge_id") String telegramPaymentChargeId, + @JsonProperty("provider_payment_charge_id") String providerPaymentChargeId +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/SwitchInlineQueryChosenChat.java b/core/src/main/java/hdvtdev/telegram/objects/SwitchInlineQueryChosenChat.java new file mode 100644 index 0000000..42282c6 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/SwitchInlineQueryChosenChat.java @@ -0,0 +1,16 @@ +package hdvtdev.telegram.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 SwitchInlineQueryChosenChat( + @JsonProperty("query") String query, + @JsonProperty("allow_user_chats") boolean allowUserChats, + @JsonProperty("allow_bot_chats") boolean allowBotChats, + @JsonProperty("allow_group_chats") boolean allowGroupChats, + @JsonProperty("allow_channel_chats") boolean allowChannelChats +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/TelegramFile.java b/core/src/main/java/hdvtdev/telegram/objects/TelegramFile.java new file mode 100644 index 0000000..2f4f403 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/TelegramFile.java @@ -0,0 +1,17 @@ +package hdvtdev.telegram.objects; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonRootName; + +@JsonRootName("file") +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record TelegramFile( + @JsonProperty("file_id") String fileId, + @JsonProperty("file_unique_id") String fileUniqueId, + @JsonProperty("file_size") long fileSize, + @JsonProperty("file_path") String filePath //link to file +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/TextQuote.java b/core/src/main/java/hdvtdev/telegram/objects/TextQuote.java new file mode 100644 index 0000000..11ccc52 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/TextQuote.java @@ -0,0 +1,11 @@ +package hdvtdev.telegram.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 TextQuote(String text, MessageEntity[] entities, int position, + @JsonProperty("is_manual") boolean isManual) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/Update.java b/core/src/main/java/hdvtdev/telegram/objects/Update.java new file mode 100644 index 0000000..f1f460b --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/Update.java @@ -0,0 +1,139 @@ +package hdvtdev.telegram.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 getAnyText() { + if (hasMessage()) { + if (message.hasText()) return Optional.of(message.text()); + if (message.hasCaption()) return Optional.of(message.caption()); + } + return Optional.empty(); + } + +} + diff --git a/core/src/main/java/hdvtdev/telegram/objects/User.java b/core/src/main/java/hdvtdev/telegram/objects/User.java new file mode 100644 index 0000000..c202248 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/User.java @@ -0,0 +1,62 @@ +package hdvtdev.telegram.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; + } + + + } +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/UsersShared.java b/core/src/main/java/hdvtdev/telegram/objects/UsersShared.java new file mode 100644 index 0000000..4fe05e1 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/UsersShared.java @@ -0,0 +1,13 @@ +package hdvtdev.telegram.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 +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/Venue.java b/core/src/main/java/hdvtdev/telegram/objects/Venue.java new file mode 100644 index 0000000..df26408 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/Venue.java @@ -0,0 +1,18 @@ +package hdvtdev.telegram.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 +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/Video.java b/core/src/main/java/hdvtdev/telegram/objects/Video.java new file mode 100644 index 0000000..8ff8749 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/Video.java @@ -0,0 +1,22 @@ +package hdvtdev.telegram.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 Video( + @JsonProperty("file_id") String fileId, + @JsonProperty("file_unique_id") String fileUniqueId, + @JsonProperty("width") int width, + @JsonProperty("height") int height, + @JsonProperty("duration") int duration, + @JsonProperty("thumbnail") PhotoSize thumbnail, + @JsonProperty("cover") PhotoSize[] cover, + @JsonProperty("start_timestamp") int startTimestamp, + @JsonProperty("file_name") String fileName, + @JsonProperty("mime_type") String mimeType, + @JsonProperty("file_size") long fileSize +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/VideoChatEnded.java b/core/src/main/java/hdvtdev/telegram/objects/VideoChatEnded.java new file mode 100644 index 0000000..4b44303 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/VideoChatEnded.java @@ -0,0 +1,10 @@ +package hdvtdev.telegram.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 VideoChatEnded(@JsonProperty("duration") long duration) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/VideoChatParticipantsInvited.java b/core/src/main/java/hdvtdev/telegram/objects/VideoChatParticipantsInvited.java new file mode 100644 index 0000000..915409f --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/VideoChatParticipantsInvited.java @@ -0,0 +1,10 @@ +package hdvtdev.telegram.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 VideoChatParticipantsInvited(@JsonProperty("users") User[] users) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/VideoChatScheduled.java b/core/src/main/java/hdvtdev/telegram/objects/VideoChatScheduled.java new file mode 100644 index 0000000..681892f --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/VideoChatScheduled.java @@ -0,0 +1,10 @@ +package hdvtdev.telegram.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 VideoChatScheduled(@JsonProperty("start_date") long startDate) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/VideoChatStarted.java b/core/src/main/java/hdvtdev/telegram/objects/VideoChatStarted.java new file mode 100644 index 0000000..db138ef --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/VideoChatStarted.java @@ -0,0 +1,9 @@ +package hdvtdev.telegram.objects; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record VideoChatStarted() { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/VideoNote.java b/core/src/main/java/hdvtdev/telegram/objects/VideoNote.java new file mode 100644 index 0000000..f328034 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/VideoNote.java @@ -0,0 +1,17 @@ +package hdvtdev.telegram.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 VideoNote( + @JsonProperty("file_id") String fileId, + @JsonProperty("file_unique_id") String fileUniqueId, + @JsonProperty("length") long length, + @JsonProperty("duration") int duration, + @JsonProperty("thumbnail") PhotoSize thumbnail, + @JsonProperty("file_size") long fileSize +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/Voice.java b/core/src/main/java/hdvtdev/telegram/objects/Voice.java new file mode 100644 index 0000000..1ad4777 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/Voice.java @@ -0,0 +1,16 @@ +package hdvtdev.telegram.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 Voice( + @JsonProperty("file_id") String fileId, + @JsonProperty("file_unique_id") String fileUniqueId, + @JsonProperty("duration") int duration, + @JsonProperty("mime_type") String mimeType, + @JsonProperty("file_size") long fileSize +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/WebAppData.java b/core/src/main/java/hdvtdev/telegram/objects/WebAppData.java new file mode 100644 index 0000000..1b7e9e4 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/WebAppData.java @@ -0,0 +1,10 @@ +package hdvtdev.telegram.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) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/WebAppInfo.java b/core/src/main/java/hdvtdev/telegram/objects/WebAppInfo.java new file mode 100644 index 0000000..ada9c9d --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/WebAppInfo.java @@ -0,0 +1,10 @@ +package hdvtdev.telegram.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) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/WriteAccessAllowed.java b/core/src/main/java/hdvtdev/telegram/objects/WriteAccessAllowed.java new file mode 100644 index 0000000..47b2777 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/WriteAccessAllowed.java @@ -0,0 +1,14 @@ +package hdvtdev.telegram.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 +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/bot/BotCommand.java b/core/src/main/java/hdvtdev/telegram/objects/bot/BotCommand.java new file mode 100644 index 0000000..5d030d8 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/bot/BotCommand.java @@ -0,0 +1,13 @@ +package hdvtdev.telegram.objects.bot; + +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 BotCommand( + @JsonProperty("command") String name, + @JsonProperty("description") String description +) { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/bot/BotCommandScope.java b/core/src/main/java/hdvtdev/telegram/objects/bot/BotCommandScope.java new file mode 100644 index 0000000..c1fad84 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/bot/BotCommandScope.java @@ -0,0 +1,22 @@ +package hdvtdev.telegram.objects.bot; + +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 = BotCommandScopeDefault.class, name = "default"), + @JsonSubTypes.Type(value = BotCommandScopeAllPrivateChats.class, name = "all_private_chats"), + @JsonSubTypes.Type(value = BotCommandScopeAllGroupChats.class, name = "all_group_chats"), + @JsonSubTypes.Type(value = BotCommandScopeAllChatAdministrators.class, name = "all_chat_administrators"), + @JsonSubTypes.Type(value = BotCommandScopeChat.class, name = "chat"), + @JsonSubTypes.Type(value = BotCommandScopeChatAdministrators.class, name = "chat_administrators"), + @JsonSubTypes.Type(value = BotCommandScopeChatMember.class, name = "chat_member") +}) +public interface BotCommandScope { + String type(); +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/bot/BotCommandScopeAllChatAdministrators.java b/core/src/main/java/hdvtdev/telegram/objects/bot/BotCommandScopeAllChatAdministrators.java new file mode 100644 index 0000000..dda2c07 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/bot/BotCommandScopeAllChatAdministrators.java @@ -0,0 +1,10 @@ +package hdvtdev.telegram.objects.bot; + +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 BotCommandScopeAllChatAdministrators(@JsonProperty("type") String type) implements BotCommandScope { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/bot/BotCommandScopeAllGroupChats.java b/core/src/main/java/hdvtdev/telegram/objects/bot/BotCommandScopeAllGroupChats.java new file mode 100644 index 0000000..593fe3c --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/bot/BotCommandScopeAllGroupChats.java @@ -0,0 +1,10 @@ +package hdvtdev.telegram.objects.bot; + +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 BotCommandScopeAllGroupChats(@JsonProperty("type") String type) implements BotCommandScope { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/bot/BotCommandScopeAllPrivateChats.java b/core/src/main/java/hdvtdev/telegram/objects/bot/BotCommandScopeAllPrivateChats.java new file mode 100644 index 0000000..4b1b44f --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/bot/BotCommandScopeAllPrivateChats.java @@ -0,0 +1,10 @@ +package hdvtdev.telegram.objects.bot; + +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 BotCommandScopeAllPrivateChats(@JsonProperty("type") String type) implements BotCommandScope { +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/bot/BotCommandScopeChat.java b/core/src/main/java/hdvtdev/telegram/objects/bot/BotCommandScopeChat.java new file mode 100644 index 0000000..54cb0c7 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/bot/BotCommandScopeChat.java @@ -0,0 +1,14 @@ +package hdvtdev.telegram.objects.bot; + +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 BotCommandScopeChat(@JsonProperty("type") String type, + @JsonProperty("chat_id") String chatId) implements BotCommandScope { + public BotCommandScopeChat(@JsonProperty("type") String type, @JsonProperty("chat_id") long chatId) { + this(type, String.valueOf(chatId)); + } +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/bot/BotCommandScopeChatAdministrators.java b/core/src/main/java/hdvtdev/telegram/objects/bot/BotCommandScopeChatAdministrators.java new file mode 100644 index 0000000..74a96d0 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/bot/BotCommandScopeChatAdministrators.java @@ -0,0 +1,14 @@ +package hdvtdev.telegram.objects.bot; + +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 BotCommandScopeChatAdministrators(@JsonProperty("type") String type, + @JsonProperty("chat_id") String chatId) implements BotCommandScope { + public BotCommandScopeChatAdministrators(@JsonProperty("type") String type, @JsonProperty("chat_id") long chatId) { + this(type, String.valueOf(chatId)); + } +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/bot/BotCommandScopeChatMember.java b/core/src/main/java/hdvtdev/telegram/objects/bot/BotCommandScopeChatMember.java new file mode 100644 index 0000000..c89d343 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/bot/BotCommandScopeChatMember.java @@ -0,0 +1,27 @@ +package hdvtdev.telegram.objects.bot; + +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 BotCommandScopeChatMember( + @JsonProperty("type") String type, + @JsonProperty("chat_id") String chatId, + @JsonProperty("user_id") long userId +) implements BotCommandScope { + + public BotCommandScopeChatMember(@JsonProperty("type") String type, @JsonProperty("chat_id") long chatId, @JsonProperty("user_id") long userId) { + this(type, String.valueOf(chatId), userId); + } + + public BotCommandScopeChatMember(@JsonProperty("type") String type, @JsonProperty("chat_id") long chatId, @JsonProperty("user_id") String userId) { + this(type, String.valueOf(chatId), Long.parseLong(userId)); + } + + public BotCommandScopeChatMember(@JsonProperty("type") String type, @JsonProperty("chat_id") String chatId, @JsonProperty("user_id") String userId) { + this(type, chatId, Long.parseLong(userId)); + } + +} diff --git a/core/src/main/java/hdvtdev/telegram/objects/bot/BotCommandScopeDefault.java b/core/src/main/java/hdvtdev/telegram/objects/bot/BotCommandScopeDefault.java new file mode 100644 index 0000000..817b3fe --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/objects/bot/BotCommandScopeDefault.java @@ -0,0 +1,10 @@ +package hdvtdev.telegram.objects.bot; + +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 BotCommandScopeDefault(@JsonProperty("type") String type) implements BotCommandScope { +} diff --git a/core/src/main/java/hdvtdev/telegram/util/ClassFinder.java b/core/src/main/java/hdvtdev/telegram/util/ClassFinder.java new file mode 100644 index 0000000..3bafd11 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/util/ClassFinder.java @@ -0,0 +1,136 @@ +package hdvtdev.telegram.util; + +import hdvtdev.telegram.annotations.handlers.CallbackQueryHandler; +import hdvtdev.telegram.annotations.handlers.TextMessageHandler; +import hdvtdev.telegram.objects.CallbackQuery; +import hdvtdev.telegram.objects.Message; +import hdvtdev.telegram.objects.Update; + +import java.io.File; +import java.io.IOException; +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; +import java.security.CodeSource; +import java.util.*; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; + +public abstract class ClassFinder { + + private static final Set> annotationsToSearch = Set.of(TextMessageHandler.class, CallbackQueryHandler.class); + private static final Set> methodsArgumentType = Set.of(Message.class, Update.class, CallbackQuery.class); + + private static ErrorHandler errorHandler; + + public static Map, Map> getClasses() { + + Map, Map> allMethods = new HashMap<>(); + annotationsToSearch.forEach(annotation -> allMethods.put(annotation, new HashMap<>())); + + CodeSource codeSource = ClassFinder.class.getProtectionDomain().getCodeSource(); + if (codeSource != null) { + try { + String path = codeSource.getLocation().toURI().getPath(); + File file = new File(URLDecoder.decode(path, StandardCharsets.UTF_8)); + + if (file.isFile() && file.getName().endsWith(".jar")) { + processJar(file, allMethods); + } else if (file.isDirectory()) { + processDirectory(file, "", allMethods); + } + } catch (Exception e) { + return Map.of(); + } + } + + return Collections.unmodifiableMap(allMethods); + } + + private static void processDirectory(File directory, String packageName, Map, Map> methods) { + File[] files = directory.listFiles(); + if (files == null) return; + + for (File file : files) { + if (file.isDirectory()) { + processDirectory(file, packageName + file.getName() + ".", methods); + } else if (file.getName().endsWith(".class")) { + + String className = packageName + file.getName().replace(".class", ""); + loadClass(className, methods); + } + } + } + + private static void processJar(File jarFile, Map, Map> methods) { + try (JarFile jar = new JarFile(jarFile)) { + Enumeration entries = jar.entries(); + while (entries.hasMoreElements()) { + JarEntry entry = entries.nextElement(); + if (entry.getName().endsWith(".class")) { + String className = entry.getName() + .replace("/", ".") + .replace(".class", ""); + + loadClass(className, methods); + } + } + } catch (IOException ignored) { + } + } + + public static Map, Map> localScan(Class cls) { + Map, Map> allMethods = new HashMap<>(); + annotationsToSearch.forEach(annotation -> allMethods.put(annotation, new HashMap<>())); + loadClass(cls.getName(), allMethods); + return allMethods; + } + + + private static void loadClass(String className, Map, Map> methods) { + try { + Class c = Class.forName(className); + + for (Method method : c.getDeclaredMethods()) { + + Class[] parameters = method.getParameterTypes(); + + if (parameters.length != 0 && !methodsArgumentType.contains(parameters[0])) { + continue; + } + + if (method.isAnnotationPresent(CallbackQueryHandler.class)) { + if (Modifier.isStatic(method.getModifiers())) { + for (String value : method.getAnnotation(CallbackQueryHandler.class).value()) { + methods.get(CallbackQueryHandler.class).put(value, new InvokeMethod(method, parameters[0])); + } + } else + System.err.println(method + " is annotated with @CallbackQueryHandler, but it is not static. For the annotation to work, the method must be static."); + } + + if (method.isAnnotationPresent(TextMessageHandler.class)) { + if (Modifier.isStatic(method.getModifiers())) { + for (String value : method.getAnnotation(TextMessageHandler.class).value()) { + methods.get(TextMessageHandler.class).put(value, new InvokeMethod(method, parameters[0])); + } + } else + System.err.println(method + " is annotated with @TextMessageHandler, but it is not static. For the annotation to work, the method must be static."); + } + + } + } catch (NoClassDefFoundError | UnsupportedClassVersionError | ClassNotFoundException e) { + if (errorHandler != null) errorHandler.onError(e); + } + } + + public void setErrorHandler(ErrorHandler errorHandler) { + ClassFinder.errorHandler = errorHandler; + } + + public interface ErrorHandler { + void onError(Throwable throwable); + } + +} diff --git a/core/src/main/java/hdvtdev/telegram/util/InvokeMethod.java b/core/src/main/java/hdvtdev/telegram/util/InvokeMethod.java new file mode 100644 index 0000000..e30980a --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/util/InvokeMethod.java @@ -0,0 +1,7 @@ +package hdvtdev.telegram.util; + +import java.lang.reflect.Method; + +public record InvokeMethod(Method method, Class parameterType) { + +} diff --git a/core/src/main/java/hdvtdev/telegram/util/ParseMode.java b/core/src/main/java/hdvtdev/telegram/util/ParseMode.java new file mode 100644 index 0000000..3837775 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/util/ParseMode.java @@ -0,0 +1,7 @@ +package hdvtdev.telegram.util; + +public enum ParseMode { + MARKDOWN, + MARKDOWNV2, + HTML +} \ No newline at end of file diff --git a/core/src/main/java/hdvtdev/telegram/util/Util.java b/core/src/main/java/hdvtdev/telegram/util/Util.java new file mode 100644 index 0000000..457268e --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/util/Util.java @@ -0,0 +1,98 @@ +package hdvtdev.telegram.util; + +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 lines = Files.readAllLines(filePath); + HashSet linesSet = new HashSet<>(lines); + ArrayList 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); + } + +} diff --git a/core/src/main/java/module-info.java b/core/src/main/java/module-info.java new file mode 100644 index 0000000..5b2ffe2 --- /dev/null +++ b/core/src/main/java/module-info.java @@ -0,0 +1,3 @@ +module hdvtdev.telegram.core { + exports hdvtdev.telegram.core; +} \ No newline at end of file diff --git a/longpolling-okhttp/build.gradle b/longpolling-okhttp/build.gradle new file mode 100644 index 0000000..77cd762 --- /dev/null +++ b/longpolling-okhttp/build.gradle @@ -0,0 +1,24 @@ +plugins { + id 'java' +} + +group = 'com.github.hdvtdev' +version = '1.0.0' + +repositories { + mavenCentral() +} + +dependencies { + implementation 'com.fasterxml.jackson.core:jackson-databind:2.18.3' + implementation 'com.squareup.okhttp3:okhttp:4.12.0' + implementation(project(":core")) +} + +tasks.register('fat') { + jar { + from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } } + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + } +} + diff --git a/longpolling-okhttp/src/main/java/hdvtdev/telegram/longpolling/okhttp/OkHttpTelegramBot.java b/longpolling-okhttp/src/main/java/hdvtdev/telegram/longpolling/okhttp/OkHttpTelegramBot.java new file mode 100644 index 0000000..f186644 --- /dev/null +++ b/longpolling-okhttp/src/main/java/hdvtdev/telegram/longpolling/okhttp/OkHttpTelegramBot.java @@ -0,0 +1,335 @@ +package hdvtdev.telegram.longpolling; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +import hdvtdev.telegram.annotations.handlers.CallbackQueryHandler; +import hdvtdev.telegram.annotations.handlers.TextMessageHandler; +import hdvtdev.telegram.annotations.util.Jsonable; +import hdvtdev.telegram.core.TelegramBot; +import hdvtdev.telegram.exceptions.TelegramApiException; +import hdvtdev.telegram.exceptions.TelegramApiNetworkException; +import hdvtdev.telegram.exceptions.TelegramMethodParsingException; +import hdvtdev.telegram.methods.GetUpdates; +import hdvtdev.telegram.methods.TelegramApiMethod; +import hdvtdev.telegram.objects.CallbackQuery; +import hdvtdev.telegram.objects.Message; +import hdvtdev.telegram.objects.TelegramFile; +import hdvtdev.telegram.objects.Update; +import hdvtdev.telegram.util.ClassFinder; +import hdvtdev.telegram.util.InvokeMethod; + +import okhttp3.*; + +import org.jetbrains.annotations.NotNull; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.net.HttpURLConnection; +import java.net.URI; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.*; +import java.util.concurrent.atomic.AtomicLong; + + +public class OkHttpTelegramBot implements TelegramBot { + + private final String TELEGRAM_API_URL; + private final String TELEGRAM_FILE_API_URL; + private final ObjectMapper json = new ObjectMapper(); + + static { + try { + HttpURLConnection connection = (HttpURLConnection) URI.create("https://api.telegram.org").toURL().openConnection(); + connection.setRequestMethod("HEAD"); + connection.setConnectTimeout(5000); + connection.setReadTimeout(5000); + int responseCode = connection.getResponseCode(); + + if (responseCode != 200) { + throw new TelegramApiNetworkException("Telegram API is unreachable. Response code: " + responseCode); + } + } catch (IOException e) { + throw new TelegramApiNetworkException("Error checking Telegram API connectivity.", e); + } + } + + private ExecutorService thread; + private AtomicLong lastUpdateId; + private int updateLimit = 10; + private int updateTimeout = 25; + private final OkHttpClient client = buildOkHttpClient(); + + private OkHttpClient buildOkHttpClient() { + Dispatcher dispatcher = new Dispatcher(); + dispatcher.setMaxRequests(100); + dispatcher.setMaxRequestsPerHost(100); + + return new OkHttpClient.Builder() + .dispatcher(dispatcher) + .connectionPool(new ConnectionPool( + 100, + 75, + TimeUnit.SECONDS + )) + .readTimeout(updateTimeout + 10, TimeUnit.SECONDS) + .writeTimeout(updateTimeout, TimeUnit.SECONDS) + .connectTimeout(updateTimeout, TimeUnit.SECONDS) + .retryOnConnectionFailure(true) + .build(); + } + + private UpdateConsumer updateConsumer; + + private boolean enableHandlers = false; + private Map messageHandlers; + private Map callbackQueryHandlers; + + private UserState userState; + private Map userStateStorage; + + public UserState getUserState(String id) { + return userStateStorage.getOrDefault(id, userState); + } + + public void setUserState(String id, UserState userState) { + userStateStorage.put(id, userState); + } + + public boolean compareUserState(String id, UserState userState) { + return getUserState(id).equals(userState); + } + + public OkHttpTelegramBot(String token) { + this.TELEGRAM_API_URL = "https://api.telegram.org/bot" + token + "/"; + this.TELEGRAM_FILE_API_URL = "https://api.telegram.org/file/bot" + token + "/"; + } + + private OkHttpTelegramBot(Builder builder) { + updateLimit = builder.updateLimit; + updateTimeout = builder.updateTimeout; + enableHandlers = builder.enableHandlers; + userStateStorage = builder.userStateStorage; + userState = builder.userState; + if (builder.updateConsumer != null) setUpdateConsumer(builder.updateConsumer); + if (enableHandlers) { + Class updateConsumerClass = builder.updateConsumer == null ? UpdateConsumer.class : builder.updateConsumer.getClass(); + Map, Map> handlers = builder.enableScan ? ClassFinder.getClasses() : ClassFinder.localScan(updateConsumerClass); + this.messageHandlers = Collections.unmodifiableMap(handlers.get(TextMessageHandler.class)); + this.callbackQueryHandlers = Collections.unmodifiableMap(handlers.get(CallbackQueryHandler.class)); + } + this.TELEGRAM_API_URL = "https://api.telegram.org/bot" + builder.token + "/"; + this.TELEGRAM_FILE_API_URL = "https://api.telegram.org/file/bot" + builder.token + "/"; + } + + /** + * Enables the default long polling update consumer for handlers. + *

+ * This method is effective only if {@link #enableHandlers} is{@code true}, + * otherwise, it just marks updates as read/processed without invoking any handlers. + *

+ *


+     * Equivalent to: setUpdateConsumer(null);
+     * 
+ * @throws IllegalStateException if an {@code UpdateConsumer} is already defined + * @see #setUpdateConsumer(UpdateConsumer) + * @see #enableHandlers + * @since 0.0.1 + */ + public void enableDefaultUpdateConsumer() throws IllegalStateException { + setUpdateConsumer(null); + } + + /** + * Enables a long polling update consumer. If {@link #enableHandlers} is {@code true}, + * the specified handlers will be invoked for each received update. + * + * @param updateConsumer class that implements {@code UpdateConsumer} + * @throws IllegalStateException if an {@code UpdateConsumer} is already defined + * @see #enableDefaultUpdateConsumer() + * @see #enableHandlers + * @since 0.0.1 + */ + public void setUpdateConsumer(UpdateConsumer updateConsumer) throws IllegalStateException { + if (thread != null) + throw new IllegalStateException("Update Consumer is already defined. You must first stop the previous"); + this.updateConsumer = updateConsumer; + this.lastUpdateId = new AtomicLong(0); + thread = Executors.newSingleThreadExecutor(); + thread.execute(this::getUpdates); + } + + private void getUpdates() { + List updates = List.of(awaitExecute(new GetUpdates(lastUpdateId.get() + 1, updateLimit, updateTimeout))); + System.out.println("UPDATE"); + if (!updates.isEmpty()) { + try { + if (enableHandlers) { + for (Update update : updates) { + CompletableFuture.runAsync(() -> { + if (update.hasMessage()) { + Message message = update.message(); + if (message.hasText() && !messageHandlers.isEmpty()) { + String key = message.text(); + invokeAnnotatedMethod(messageHandlers.containsKey("*") ? messageHandlers.get("*") : messageHandlers.get(key), update); + } + } + if (update.hasCallbackQuery()) { + CallbackQuery callbackQuery = update.callbackQuery(); + if (callbackQuery.hasMessage()) { + Message message = (Message) callbackQuery.message(); + if (message.hasText() && !callbackQueryHandlers.isEmpty()) { + invokeAnnotatedMethod(callbackQueryHandlers.containsKey("*") ? callbackQueryHandlers.get("*") : callbackQueryHandlers.get(message.text()), update); + } + } + } + }); + } + } + if (updateConsumer != null) CompletableFuture.runAsync(() -> updateConsumer.getUpdates(updates)); + } finally { + lastUpdateId.set(updates.getLast().updateId()); + if (!thread.isShutdown()) getUpdates(); + } + } + + } + + private static void invokeAnnotatedMethod(InvokeMethod invokeMethod, Update update) { + + if (invokeMethod != null) { + Method method = invokeMethod.method(); + method.setAccessible(true); + try { + switch (invokeMethod.parameterType().getSimpleName()) { + case "Message" -> method.invoke(null, update.message()); + case "Update" -> method.invoke(null, update); + case "CallbackQuery" -> method.invoke(null, update.callbackQuery()); + default -> method.invoke(null); + } + } catch (IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + } + + public void shutdownUpdateConsumer() { + this.thread.close(); + } + + public T awaitExecute(TelegramApiMethod telegramApiMethod) throws TelegramApiException, TelegramApiNetworkException, TelegramMethodParsingException { + + RequestBody body = telegramApiMethod.getBody(); + + Request.Builder request = new Request.Builder() + .url(TELEGRAM_API_URL + telegramApiMethod.getMethodName()); + if (body == null) { + if (telegramApiMethod.getClass().isAnnotationPresent(Jsonable.class)) { + try { + request.post(RequestBody.create(json.writeValueAsString(telegramApiMethod), MediaType.get("application/json; charset=utf-8"))); + } catch (JsonProcessingException e) { + throw new TelegramMethodParsingException(e); + } + } + } else request.post(body); + + try (Response response = client.newCall(request.build()).execute()) { + String responseBody = Objects.requireNonNull(response.body()).string(); + if (response.isSuccessful()) { + JsonNode rootNode = json.readTree(responseBody); + JsonNode resultNode = rootNode.path("result"); + return json.treeToValue(resultNode, telegramApiMethod.getResponseClass()); + } else { + throw new TelegramApiException(json.readValue(responseBody, TelegramApiException.ErrorResponse.class)); + } + } catch (IOException e) { + throw new TelegramApiNetworkException(e); + } + + + } + + @NotNull + private File getFile(TelegramFile telegramFile, Path targetDirectory) { + try (Response response = client.newCall(new Request.Builder().url(TELEGRAM_FILE_API_URL + telegramFile.filePath()).build()).execute()) { + ResponseBody responseBody = Objects.requireNonNull(response.body()); + if (!response.isSuccessful()) + throw new TelegramApiException(json.readValue(responseBody.string(), TelegramApiException.ErrorResponse.class)); + Path filePath = Files.isDirectory(targetDirectory) ? targetDirectory.resolve(Path.of(telegramFile.filePath()).getFileName()) : targetDirectory; + Files.copy(responseBody.byteStream(), filePath, StandardCopyOption.REPLACE_EXISTING); + return new File(filePath.toUri()); + } catch (IOException e) { + throw new TelegramApiNetworkException(e); + } + } + + public File awaitDownloadFile(TelegramFile telegramFile, Path targetDirectory) { + return getFile(telegramFile, targetDirectory); + } + + + public static final class Builder { + private int updateLimit = 10; + private int updateTimeout = 25; + private boolean enableHandlers = false; + private boolean enableScan = false; + private final String token; + private Map userStateStorage; + private UserState userState; + private UpdateConsumer updateConsumer; + + public Builder(String token) { + this.token = token; + } + + public Builder updateConsumer(Main.Upd updateConsumer) { + this.updateConsumer = updateConsumer; + return this; + } + + public Builder enableUserStateStorage(UserState defaultValue, Map userStateStorage) { + this.userState = defaultValue; + this.userStateStorage = userStateStorage; + return this; + } + + public Builder enableUserStateStorage(UserState defaultValue) { + return enableUserStateStorage(defaultValue, new ConcurrentHashMap<>()); + } + + public Builder updateLimit(int updateLimit) { + this.updateLimit = updateLimit; + return this; + } + + public Builder updateTimeout(int updateTimeout) { + this.updateTimeout = updateTimeout; + return this; + } + + public Builder enableHandlers() { + this.enableHandlers = true; + return this; + } + + public Builder enableHandlers(boolean enableScan) { + this.enableHandlers = true; + this.enableScan = enableScan; + return this; + } + + public OkHttpTelegramBot build() { + return new OkHttpTelegramBot(this); + } + } +} diff --git a/longpolling-okhttp/src/main/java/module-info.java b/longpolling-okhttp/src/main/java/module-info.java new file mode 100644 index 0000000..46bf3f8 --- /dev/null +++ b/longpolling-okhttp/src/main/java/module-info.java @@ -0,0 +1,6 @@ +module longpolling.okhttp { + exports hdvtdev.telegram.longpolling; + requires com.fasterxml.jackson.databind; + requires core; + requires okhttp3; +} diff --git a/test/build.gradle b/test/build.gradle new file mode 100644 index 0000000..d4eb6b4 --- /dev/null +++ b/test/build.gradle @@ -0,0 +1,17 @@ +plugins { + id 'java' +} + +group = 'com.github.hdvtdev' +version = '1.0.0' + +repositories { + mavenCentral() +} + +dependencies { + implementation(project(":core")) + implementation(project(":longpolling-okhttp")) +} + + diff --git a/test/src/main/java/Main.java b/test/src/main/java/Main.java new file mode 100644 index 0000000..1e936b3 --- /dev/null +++ b/test/src/main/java/Main.java @@ -0,0 +1,4 @@ +package PACKAGE_NAME; + +public class Main { +}