diff --git a/.gitignore b/.gitignore index dae3f48..560059e 100644 --- a/.gitignore +++ b/.gitignore @@ -40,4 +40,4 @@ bin/ ### Mac OS ### .DS_Store -/src/main/java/hdvtdev/telegram/Count.java +/core/src/main/java/hdvtdev/telegram/Count.java diff --git a/.idea/gradle.xml b/.idea/gradle.xml index ce1c62c..f63ed0f 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -8,6 +8,8 @@ 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/build.gradle b/build.gradle index 8035c26..36534f4 100644 --- a/build.gradle +++ b/build.gradle @@ -10,18 +10,17 @@ repositories { } dependencies { - implementation 'com.fasterxml.jackson.core:jackson-databind:2.18.3' - implementation 'com.squareup.okhttp3:okhttp:4.12.0' + implementation(project(":core")) + implementation(project(":longpolling-okhttp")) } -jar { - - manifest { - attributes( - 'Main-Class': 'hdvtdev.telegram.Main' - ) - } - from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } } +tasks.register('fat', Jar) { + archiveClassifier.set('all') duplicatesStrategy = DuplicatesStrategy.EXCLUDE + from sourceSets.main.output + from { + configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } + } } + diff --git a/core/build.gradle b/core/build.gradle new file mode 100644 index 0000000..c816d58 --- /dev/null +++ b/core/build.gradle @@ -0,0 +1,16 @@ +plugins { + id 'java' +} + +group = 'com.github.hdvtdev' +version = '1.0.0' + + +repositories { + mavenCentral() +} + +dependencies { + implementation 'com.fasterxml.jackson.core:jackson-databind:2.18.3' +} + 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..0046255 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/InvokeMethod.java @@ -0,0 +1,7 @@ +package hdvtdev.telegram.core; + +import java.lang.reflect.Method; + +public record InvokeMethod(Method method, Class parameterType) { + +} 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..9085f3c --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/TelegramBot.java @@ -0,0 +1,57 @@ +package hdvtdev.telegram.core; + +import hdvtdev.telegram.core.exceptions.TelegramApiException; +import hdvtdev.telegram.core.exceptions.TelegramApiNetworkException; +import hdvtdev.telegram.core.exceptions.TelegramMethodParsingException; +import hdvtdev.telegram.core.methods.TelegramApiMethod; +import hdvtdev.telegram.core.objects.media.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); + + void shutdown(); + + default CompletableFuture downloadFile(TelegramFile telegramFile, Path targetDirectory) { + CompletableFuture completableFuture = CompletableFuture.supplyAsync(() -> awaitDownloadFile(telegramFile, targetDirectory)); + completableFuture.exceptionally(e -> { + e.printStackTrace(); + return null; + }); + return completableFuture; + } + + default CompletableFuture execute(TelegramApiMethod telegramApiMethod) { + CompletableFuture completableFuture = CompletableFuture.supplyAsync(() -> awaitExecute(telegramApiMethod)); + completableFuture.exceptionally(e -> { + e.printStackTrace(); + return null; + }); + return completableFuture; + } + + 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..6b96543 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/UpdateConsumer.java @@ -0,0 +1,32 @@ +package hdvtdev.telegram.core; + +import hdvtdev.telegram.core.objects.ChosenInlineResult; +import hdvtdev.telegram.core.objects.InlineQuery; +import hdvtdev.telegram.core.objects.Update; +import hdvtdev.telegram.core.objects.business.BusinessConnection; +import hdvtdev.telegram.core.objects.business.BusinessMessagesDeleted; +import hdvtdev.telegram.core.objects.callback.CallbackQuery; +import hdvtdev.telegram.core.objects.chat.ChatJoinRequest; +import hdvtdev.telegram.core.objects.chat.ChatMemberUpdated; +import hdvtdev.telegram.core.objects.chatboost.ChatBoostRemoved; +import hdvtdev.telegram.core.objects.chatboost.ChatBoostUpdated; +import hdvtdev.telegram.core.objects.media.paidmedia.PaidMediaPurchased; +import hdvtdev.telegram.core.objects.message.Message; +import hdvtdev.telegram.core.objects.message.MessageReactionCountUpdated; +import hdvtdev.telegram.core.objects.message.MessageReactionUpdated; +import hdvtdev.telegram.core.objects.payment.PreCheckoutQuery; +import hdvtdev.telegram.core.objects.payment.ShippingQuery; +import hdvtdev.telegram.core.objects.poll.Poll; +import hdvtdev.telegram.core.objects.poll.PollAnswer; + +import java.util.List; + +public interface UpdateConsumer { + + + + void onUpdates(List updates); + + + +} diff --git a/core/src/main/java/hdvtdev/telegram/core/UpdateHandler.java b/core/src/main/java/hdvtdev/telegram/core/UpdateHandler.java new file mode 100644 index 0000000..00cf08c --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/UpdateHandler.java @@ -0,0 +1,80 @@ +package hdvtdev.telegram.core; + +import hdvtdev.telegram.core.objects.ChosenInlineResult; +import hdvtdev.telegram.core.objects.InlineQuery; +import hdvtdev.telegram.core.objects.Update; +import hdvtdev.telegram.core.objects.business.BusinessConnection; +import hdvtdev.telegram.core.objects.business.BusinessMessagesDeleted; +import hdvtdev.telegram.core.objects.callback.CallbackQuery; +import hdvtdev.telegram.core.objects.chat.ChatJoinRequest; +import hdvtdev.telegram.core.objects.chat.ChatMemberUpdated; +import hdvtdev.telegram.core.objects.chatboost.ChatBoostRemoved; +import hdvtdev.telegram.core.objects.chatboost.ChatBoostUpdated; +import hdvtdev.telegram.core.objects.media.paidmedia.PaidMediaPurchased; +import hdvtdev.telegram.core.objects.message.Message; +import hdvtdev.telegram.core.objects.message.MessageReactionCountUpdated; +import hdvtdev.telegram.core.objects.message.MessageReactionUpdated; +import hdvtdev.telegram.core.objects.payment.PreCheckoutQuery; +import hdvtdev.telegram.core.objects.payment.ShippingQuery; +import hdvtdev.telegram.core.objects.poll.Poll; +import hdvtdev.telegram.core.objects.poll.PollAnswer; + +import java.util.List; + +public interface UpdateHandler extends UpdateConsumer { + + @Override + default void onUpdates(List updates) { + for (Update update : updates) { + if (update.hasMessage()) onMessage(update.message()); + if (update.hasEditedMessage()) onEditedMessage(update.editedMessage()); + if (update.hasChannelPost()) onChannelPost(update.channelPost()); + if (update.hasEditedChannelPost()) onEditedChannelPost(update.editedChannelPost()); + if (update.hasBusinessConnection()) onBusinessConnection(update.businessConnection()); + if (update.hasBusinessMessage()) onBusinessMessage(update.businessMessage()); + if (update.hasEditedBusinessMessage()) onEditedBusinessMessage(update.editedBusinessMessage()); + if (update.hasDeletedBusinessMessages()) onDeletedBusinessMessages(update.businessMessagesDeleted()); + if (update.hasMessageReaction()) onMessageReaction(update.messageReaction()); + if (update.hasMessageReactionCount()) onMessageReactionCount(update.messageReactionCount()); + if (update.hasInlineQuery()) onInlineQuery(update.inlineQuery()); + if (update.hasChosenInlineResult()) onChosenInlineResult(update.chosenInlineResult()); + if (update.hasCallbackQuery()) onCallbackQuery(update.callbackQuery()); + if (update.hasShippingQuery()) onShippingQuery(update.shippingQuery()); + if (update.hasPreCheckoutQuery()) onPreCheckoutQuery(update.preCheckoutQuery()); + if (update.hasPurchasedPaidMedia()) onPaidMediaPurchased(update.paidMediaPurchased()); + if (update.hasPoll()) onPoll(update.poll()); + if (update.hasPollAnswer()) onPollAnswer(update.pollAnswer()); + if (update.hasMyChatMember()) onMyChatMember(update.myChatMember()); + if (update.hasChatMember()) onChatMember(update.chatMember()); + if (update.hasChatJoinRequest()) onChatJoinRequest(update.chatJoinRequest()); + if (update.hasChatBoost()) onChatBoost(update.chatBoost()); + if (update.hasRemovedChatBoost()) onChatBoostRemoved(update.chatBoostRemoved()); + } + } + + default void onMessage(Message message) {} + default void onEditedMessage(Message message) {} + default void onChannelPost(Message message) {} + default void onEditedChannelPost(Message message) {} + default void onBusinessConnection(BusinessConnection connection) {} + default void onBusinessMessage(Message message) {} + default void onEditedBusinessMessage(Message message) {} + default void onDeletedBusinessMessages(BusinessMessagesDeleted deleted) {} + default void onMessageReaction(MessageReactionUpdated reaction) {} + default void onMessageReactionCount(MessageReactionCountUpdated count) {} + default void onInlineQuery(InlineQuery query) {} + default void onChosenInlineResult(ChosenInlineResult result) {} + default void onCallbackQuery(CallbackQuery callbackQuery) {} + default void onShippingQuery(ShippingQuery query) {} + default void onPreCheckoutQuery(PreCheckoutQuery query) {} + default void onPaidMediaPurchased(PaidMediaPurchased paidMedia) {} + default void onPoll(Poll poll) {} + default void onPollAnswer(PollAnswer answer) {} + default void onMyChatMember(ChatMemberUpdated member) {} + default void onChatMember(ChatMemberUpdated member) {} + default void onChatJoinRequest(ChatJoinRequest request) {} + default void onChatBoost(ChatBoostUpdated boost) {} + default void onChatBoostRemoved(ChatBoostRemoved removedBoost) {} + + +} 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..194d086 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/UserState.java @@ -0,0 +1,4 @@ +package hdvtdev.telegram.core; + +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..dc2e074 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/exceptions/TelegramApiException.java @@ -0,0 +1,29 @@ +package hdvtdev.telegram.core.exceptions; + +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..d294e6d --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/exceptions/TelegramApiNetworkException.java @@ -0,0 +1,17 @@ +package hdvtdev.telegram.core.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..a49568c --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/exceptions/TelegramMethodParsingException.java @@ -0,0 +1,11 @@ +package hdvtdev.telegram.core.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..0d61199 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/AnswerCallbackQuery.java @@ -0,0 +1,111 @@ +package hdvtdev.telegram.core.methods; + +import hdvtdev.telegram.core.objects.Game; + + +/** + * 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 command via @BotFather and accept the terms. Otherwise, you may use links like t.me/your_bot?start=XXXX that open your command with a parameter. + * @apiNote On success, {@code Boolean == true} is returned. + * @since 1.0.0 + */ + +//@NotTested +public final 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 command 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 TelegramApiMethodBody getBody() { + TelegramApiMethodBody body = new TelegramApiMethodBody(); + body.add("callback_query_id", this.callbackQueryId); + body.add("text", this.text); + body.add("show_alert", String.valueOf(this.showAlert)); + body.add("url", this.url); + body.add("cache_time", String.valueOf(this.cacheTime)); + return body; + } + + @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..8e1298a --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/ApproveChatJoinRequest.java @@ -0,0 +1,49 @@ +package hdvtdev.telegram.core.methods; + +import hdvtdev.telegram.core.objects.chat.Chat; +import hdvtdev.telegram.core.objects.chat.ChatAdministratorRights; +import hdvtdev.telegram.core.objects.User; + + +/** + * Use this method to approve a chat join request. + * The command 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 + */ +//TODO NotTested +public record ApproveChatJoinRequest(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 TelegramApiMethodBody getBody() { + TelegramApiMethodBody body = new TelegramApiMethodBody(); + body.add("chat_id", chatId); + body.add("user_id", String.valueOf(userId)); + return body; + } + + @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..5977514 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/BanChatMember.java @@ -0,0 +1,111 @@ +package hdvtdev.telegram.core.methods; + + +import hdvtdev.telegram.core.objects.chat.ChatAdministratorRights; + + +/** + * 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 command 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 + */ +//TODO 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 message from the chat for the user that is being removed. + * If false, the user will be able to see message 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 TelegramApiMethodBody getBody() { + TelegramApiMethodBody body = new TelegramApiMethodBody(); + body.add("chat_id", this.chatId); + body.add("user_id", String.valueOf(userId)); + body.add("until_date", String.valueOf(untilDate)); + body.add("revoke_messages", String.valueOf(revokeMessages)); + return body; + } + + @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..9dff2fb --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/BanChatSenderChat.java @@ -0,0 +1,34 @@ +package hdvtdev.telegram.core.methods; + +/** + * 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 message on behalf of + * their channels. The command 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 + */ +//TODO NotTested +public record BanChatSenderChat(String chatId, long userId) implements TelegramApiMethod { + + public BanChatSenderChat(long chatId, long userId) { + this(String.valueOf(chatId), userId); + } + + @Override + public TelegramApiMethodBody getBody() { + TelegramApiMethodBody body = new TelegramApiMethodBody(); + body.add("chat_id", chatId); + body.add("user_id", String.valueOf(userId)); + return body; + } + + @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..a401ec7 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/CloseForumTopic.java @@ -0,0 +1,37 @@ +package hdvtdev.telegram.core.methods; + +import hdvtdev.telegram.core.objects.chat.ChatAdministratorRights; + +/** + * Use this method to close an open topic in a forum supergroup chat. + * The command 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() + */ +//TODO NotTested +public record CloseForumTopic(String chatId, long messageThreadId) implements TelegramApiMethod { + + public CloseForumTopic(long chatId, long messageThreadId) { + this(String.valueOf(chatId), messageThreadId); + } + + @Override + public TelegramApiMethodBody getBody() { + TelegramApiMethodBody body = new TelegramApiMethodBody(); + body.add("chat_id", chatId); + body.add("message_thread_id", String.valueOf(messageThreadId)); + return body; + } + + @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..1b8394e --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/CloseGeneralForumTopic.java @@ -0,0 +1,35 @@ +package hdvtdev.telegram.core.methods; + +import hdvtdev.telegram.core.objects.chat.ChatAdministratorRights; + +/** + * Use this method to close an open 'General' topic in a forum supergroup chat. + * The command 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) + */ +// TODO NotTested +public record CloseGeneralForumTopic(String chatId) implements TelegramApiMethod { + + public CloseGeneralForumTopic(long chatId) { + this(String.valueOf(chatId)); + } + + @Override + public TelegramApiMethodBody getBody() { + TelegramApiMethodBody body = new TelegramApiMethodBody(); + body.add("chat_id", chatId); + return body; + } + + @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..172fd38 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/CopyMessage.java @@ -0,0 +1,242 @@ +package hdvtdev.telegram.core.methods; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import hdvtdev.telegram.core.annotaions.Jsonable; +import hdvtdev.telegram.core.methods.util.ParseMode; +import hdvtdev.telegram.core.objects.message.MessageEntity; +import hdvtdev.telegram.core.objects.poll.Poll; +import hdvtdev.telegram.core.objects.markup.ReplyMarkup; +import hdvtdev.telegram.core.objects.ReplyParameters; + + +import java.util.List; + +/** + * Use this method to copy message of any kind. + * Service message, paid media message, giveaway message, giveaway winners message, and invoice message 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 command. + * 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 + */ +//TODO 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 TelegramApiMethodBody 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..36d3e1a --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/CopyMessages.java @@ -0,0 +1,179 @@ +package hdvtdev.telegram.core.methods; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import hdvtdev.telegram.core.annotaions.Jsonable; +import hdvtdev.telegram.core.objects.poll.Poll; + +import java.util.ArrayList; +import java.util.List; + +/** + * Use this method to copy message of any kind. + * If some of the specified message can't be found or copied, they are skipped. + * Service message, paid media message, giveaway message, giveaway winners message, and invoice message 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 command. + * The method is analogous to the method {@link ForwardMessages}, but the copied message don't have a link to the original message. + * Album grouping is kept for copied message. + * On success, an array of MessageId as {@link Long}{@code []} of the sent message 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 message were sent + * @param messageIds List of 1-100 identifiers of message 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 message were sent + * @param messageIds List of 1-100 identifiers of message 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 message were sent + * @param messageIds List of 1-100 identifiers of message 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 message were sent + * @param fromChatId Unique identifier for the target chat + * @param messageIds List of 1-100 identifiers of message 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 TelegramApiMethodBody 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..83b2cc6 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/CreateChatInviteLink.java @@ -0,0 +1,113 @@ +package hdvtdev.telegram.core.methods; + +import hdvtdev.telegram.core.objects.chat.ChatAdministratorRights; +import hdvtdev.telegram.core.objects.chat.ChatInviteLink; + +/** + * Use this method to create an additional invite link for a chat. + * The command 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 TelegramApiMethodBody getBody() { + TelegramApiMethodBody body = new TelegramApiMethodBody(); + body.add("name", name); + body.add("chat_id", chatId); + body.add("expire_date", String.valueOf(expireDate)); + body.add("member_limit", String.valueOf(memberLimit)); + body.add("creates_join_request", String.valueOf(createsJoinRequest)); + return body; + } + + @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..2b7622f --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/ForwardMessage.java @@ -0,0 +1,132 @@ +package hdvtdev.telegram.core.methods; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import hdvtdev.telegram.core.annotaions.Jsonable; +import hdvtdev.telegram.core.objects.message.Message; + + +/** + * Use this method to forward message of any kind. + * Service message and message 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 TelegramApiMethodBody 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..d369ca1 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/ForwardMessages.java @@ -0,0 +1,144 @@ +package hdvtdev.telegram.core.methods; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import hdvtdev.telegram.core.annotaions.Jsonable; +import hdvtdev.telegram.core.objects.message.Message; + +import java.util.ArrayList; +import java.util.List; + +/** + * Use this method to forward multiple message of any kind. If some of the specified message can't be found or forwarded, they are skipped. + * Service message and message with protected content can't be forwarded. Album grouping is kept for forwarded message. + * On success, an array of MessageId as {@link Long} of the sent message is returned. + * @see Message#hasProtectedContent() + */ +// TODO NotTested +@Jsonable +@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 TelegramApiMethodBody 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..02d8d9f --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/GetChatAdministrators.java @@ -0,0 +1,32 @@ +package hdvtdev.telegram.core.methods; + +import hdvtdev.telegram.core.objects.chat.ChatMember; + +/** + * 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 + */ +//TODO NotTested +public record GetChatAdministrators(String chatId) implements TelegramApiMethod { + + public GetChatAdministrators(long chatId) { + this(String.valueOf(chatId)); + } + + @Override + public TelegramApiMethodBody getBody() { + TelegramApiMethodBody body = new TelegramApiMethodBody(); + body.add("chat_id", chatId); + return body; + } + + @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..9aa7a68 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/GetChatMember.java @@ -0,0 +1,36 @@ +package hdvtdev.telegram.core.methods; + +import hdvtdev.telegram.core.objects.chat.ChatMember; + +public record GetChatMember(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 TelegramApiMethodBody getBody() { + TelegramApiMethodBody body = new TelegramApiMethodBody(); + body.add("chat_id", chatId); + body.add("user_id", String.valueOf(userId)); + return body; + } + + @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..5f41461 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/GetFile.java @@ -0,0 +1,23 @@ +package hdvtdev.telegram.core.methods; + +import hdvtdev.telegram.core.objects.media.TelegramFile; + +public record GetFile(String fileId) implements TelegramApiMethod { + + @Override + public TelegramApiMethodBody getBody() { + TelegramApiMethodBody body = new TelegramApiMethodBody(); + body.add("file_id", fileId); + return body; + } + + @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..5e1b160 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/GetMe.java @@ -0,0 +1,21 @@ +package hdvtdev.telegram.core.methods; + +import hdvtdev.telegram.core.objects.User; + +public final class GetMe implements TelegramApiMethod { + + @Override + public TelegramApiMethodBody 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..1c04bd2 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/GetMyCommands.java @@ -0,0 +1,56 @@ +package hdvtdev.telegram.core.methods; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import hdvtdev.telegram.core.annotaions.Jsonable; +import hdvtdev.telegram.core.objects.command.BotCommand; +import hdvtdev.telegram.core.objects.command.BotCommandScope; +import hdvtdev.telegram.core.objects.command.BotCommandScopeDefault; + +/** + * Use this method to get the current list of the command'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 TelegramApiMethodBody 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..706ecc1 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/GetMyDescription.java @@ -0,0 +1,43 @@ +package hdvtdev.telegram.core.methods; + +public record GetMyDescription(String languageCode) implements TelegramApiMethod { + + public GetMyDescription() { + this(null); + } + + @Override + public TelegramApiMethodBody getBody() { + if (languageCode == null) { + return null; + } else { + TelegramApiMethodBody body = new TelegramApiMethodBody(); + body.add("language_code", languageCode); + return body; + } + } + + @Override + public String getMethodName() { + return "getMyDescription"; + } + + @Override + public Class getResponseClass() { + return BotDescription.class; + } + + public record BotDescription(String description) { + + @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..cf16657 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/GetMyName.java @@ -0,0 +1,39 @@ +package hdvtdev.telegram.core.methods; + +public record GetMyName(String languageCode) implements TelegramApiMethod { + + public GetMyName() { + this(null); + } + + @Override + public TelegramApiMethodBody getBody() { + if (languageCode == null) { + return null; + } else { + TelegramApiMethodBody body = new TelegramApiMethodBody(); + body.add("language_code", languageCode); + return body; + } + } + + @Override + public String getMethodName() { + return "getMyName"; + } + + @Override + public Class getResponseClass() { + return BotName.class; + } + + public record BotName(String name) { + + @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..a522601 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/GetUpdates.java @@ -0,0 +1,40 @@ +package hdvtdev.telegram.core.methods; + +import hdvtdev.telegram.core.objects.Update; + +import java.util.ArrayList; + +public record GetUpdates( + Long offset, + Integer limit, + Integer timeout +) implements TelegramApiMethod { + + public GetUpdates() { + this(null, null, null); + } + + @Override + public TelegramApiMethodBody 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..613b897 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/RevokeChatInviteLink.java @@ -0,0 +1,35 @@ +package hdvtdev.telegram.core.methods; + +import hdvtdev.telegram.core.objects.chat.ChatInviteLink; + +/** + * Use this method to revoke an invite link created by the command. If the primary link is revoked, a new link is automatically generated. + * The command 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(String chatId, String link) implements TelegramApiMethod { + + public RevokeChatInviteLink(long chatId, String link) { + this(String.valueOf(chatId), link); + } + + @Override + public TelegramApiMethodBody getBody() { + TelegramApiMethodBody body = new TelegramApiMethodBody(2); + body.add("chat_id", chatId); + body.add("link", link); + return body; + } + + @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..09201d0 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/SendChatAction.java @@ -0,0 +1,97 @@ +package hdvtdev.telegram.core.methods; + +public final class SendChatAction implements TelegramApiMethod { + + private String businessConnectionId; + private final String chatId; + private Long messageThreadId; + private final ChatAction chatAction; + + public SendChatAction(String businessConnectionId, String chatId, Long messageThreadId, 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 TelegramApiMethodBody getBody() { + TelegramApiMethodBody body = new TelegramApiMethodBody(); + body.add("chat_id", chatId); + body.add("action", chatAction.equals(ChatAction.UPLOAD_FILE) ? ChatAction.UPLOAD_DOCUMENT.name() : chatAction.name()); + body.add("business_connection_id", businessConnectionId); + body.add("message_thread_id", String.valueOf(messageThreadId)); + return body; + } + + @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..a275518 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/SendDice.java @@ -0,0 +1,131 @@ +package hdvtdev.telegram.core.methods; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import hdvtdev.telegram.core.annotaions.Jsonable; +import hdvtdev.telegram.core.objects.message.Message; +import hdvtdev.telegram.core.objects.markup.ReplyMarkup; +import hdvtdev.telegram.core.objects.ReplyParameters; + +@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 TelegramApiMethodBody 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..ac8ddf0 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/SendMessage.java @@ -0,0 +1,229 @@ +package hdvtdev.telegram.core.methods; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import hdvtdev.telegram.core.annotaions.Jsonable; +import hdvtdev.telegram.core.methods.util.ParseMode; +import hdvtdev.telegram.core.objects.*; +import hdvtdev.telegram.core.objects.markup.ReplyMarkup; +import hdvtdev.telegram.core.objects.message.LinkPreviewOptions; +import hdvtdev.telegram.core.objects.message.Message; +import hdvtdev.telegram.core.objects.message.MessageEntity; + + +@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 TelegramApiMethodBody 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..1d15539 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/SetMessageReaction.java @@ -0,0 +1,98 @@ +package hdvtdev.telegram.core.methods; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import hdvtdev.telegram.core.annotaions.Jsonable; +import hdvtdev.telegram.core.objects.reaction.ReactionType; + +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 TelegramApiMethodBody 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..c073a7c --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/SetMyCommands.java @@ -0,0 +1,99 @@ +package hdvtdev.telegram.core.methods; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import hdvtdev.telegram.core.annotaions.Jsonable; +import hdvtdev.telegram.core.objects.command.BotCommand; +import hdvtdev.telegram.core.objects.command.BotCommandScope; + +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 TelegramApiMethodBody 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..6ccfca8 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/SetMyDescription.java @@ -0,0 +1,40 @@ +package hdvtdev.telegram.core.methods; + +/** + * Use this method to change the command's description, which is shown in the chat with the command if the chat is empty. + * Returns {@code true} on success. + * @param description New command 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 TelegramApiMethodBody getBody() { + if (description == null) { + return null; + } else { + TelegramApiMethodBody body = new TelegramApiMethodBody(2); + body.add("language_code", languageCode); + body.add("description", description); + return body; + } + } + + @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..774e52e --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/SetMyName.java @@ -0,0 +1,26 @@ +package hdvtdev.telegram.core.methods; + +public record SetMyName(String name, String languageCode) implements TelegramApiMethod { + + public SetMyName(String name) { + this(name, null); + } + + @Override + public TelegramApiMethodBody getBody() { + TelegramApiMethodBody body = new TelegramApiMethodBody(2); + body.add("name", this.name); + body.add("language_code", this.languageCode); + return body; + } + + @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..8f4e8f4 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/TelegramApiMethod.java @@ -0,0 +1,11 @@ +package hdvtdev.telegram.core.methods; + +public interface TelegramApiMethod { + + TelegramApiMethodBody 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..804eea5 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/TelegramApiMethodBody.java @@ -0,0 +1,35 @@ +package hdvtdev.telegram.core.methods; + +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 int size() { + return this.elements.size(); + } + + public Element get(int i) { + return this.elements.get(i); + } + + 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..4191da3 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/util/ParseMode.java @@ -0,0 +1,7 @@ +package hdvtdev.telegram.core.methods.util; + +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..7d9a7cd --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/methods/util/Util.java @@ -0,0 +1,98 @@ +package hdvtdev.telegram.core.methods.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/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/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/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/Game.java b/core/src/main/java/hdvtdev/telegram/core/objects/Game.java new file mode 100644 index 0000000..1580981 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/Game.java @@ -0,0 +1,20 @@ +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.media.Animation; +import hdvtdev.telegram.core.objects.media.PhotoSize; +import hdvtdev.telegram.core.objects.message.MessageEntity; + +@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/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..5ba86e1 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/ReplyParameters.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 hdvtdev.telegram.core.objects.message.MessageEntity; + +@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/SharedUser.java b/core/src/main/java/hdvtdev/telegram/core/objects/SharedUser.java new file mode 100644 index 0000000..424bc63 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/SharedUser.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 hdvtdev.telegram.core.objects.media.PhotoSize; + +@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/Update.java b/core/src/main/java/hdvtdev/telegram/core/objects/Update.java new file mode 100644 index 0000000..442909d --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/Update.java @@ -0,0 +1,154 @@ +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.business.BusinessConnection; +import hdvtdev.telegram.core.objects.business.BusinessMessagesDeleted; +import hdvtdev.telegram.core.objects.callback.CallbackQuery; +import hdvtdev.telegram.core.objects.chat.ChatJoinRequest; +import hdvtdev.telegram.core.objects.chat.ChatMemberUpdated; +import hdvtdev.telegram.core.objects.chatboost.ChatBoostRemoved; +import hdvtdev.telegram.core.objects.chatboost.ChatBoostUpdated; +import hdvtdev.telegram.core.objects.media.paidmedia.PaidMediaPurchased; +import hdvtdev.telegram.core.objects.message.Message; +import hdvtdev.telegram.core.objects.message.MessageReactionCountUpdated; +import hdvtdev.telegram.core.objects.message.MessageReactionUpdated; +import hdvtdev.telegram.core.objects.payment.PreCheckoutQuery; +import hdvtdev.telegram.core.objects.payment.ShippingQuery; +import hdvtdev.telegram.core.objects.poll.Poll; +import hdvtdev.telegram.core.objects.poll.PollAnswer; + +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..0a8f660 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundFill.java @@ -0,0 +1,18 @@ +package hdvtdev.telegram.core.objects.background; + +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..1a3bc32 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundFillDeserializer.java @@ -0,0 +1,27 @@ +package hdvtdev.telegram.core.objects.background; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.ObjectCodec; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; + +import java.io.IOException; + +public final class BackgroundFillDeserializer extends JsonDeserializer { + + @Override + public BackgroundFill deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException { + ObjectCodec codec = parser.getCodec(); + JsonNode node = codec.readTree(parser); + + String type = node.get("type").asText(); + + return switch (type) { + case "solid" -> codec.treeToValue(node, BackgroundFillSolid.class); + case "gradient" -> codec.treeToValue(node, BackgroundFillGradient.class); + case "freeform_gradient" -> codec.treeToValue(node, BackgroundFillFreeformGradient.class); + default -> throw new IllegalArgumentException("Unknown type: " + type); + }; + } +} 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..d6912cb --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundFillFreeformGradient.java @@ -0,0 +1,13 @@ +package hdvtdev.telegram.core.objects.background; + +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..49c6101 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundFillGradient.java @@ -0,0 +1,15 @@ +package hdvtdev.telegram.core.objects.background; + +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..73accb8 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundFillSolid.java @@ -0,0 +1,13 @@ +package hdvtdev.telegram.core.objects.background; + +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..2abc41c --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundType.java @@ -0,0 +1,8 @@ +package hdvtdev.telegram.core.objects.background; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +@JsonDeserialize(using = BackgroundTypeDeserializer.class) +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..9718787 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundTypeChatTheme.java @@ -0,0 +1,13 @@ +package hdvtdev.telegram.core.objects.background; + +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..f389211 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundTypeDeserializer.java @@ -0,0 +1,28 @@ +package hdvtdev.telegram.core.objects.background; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.ObjectCodec; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; + +import java.io.IOException; + +public final class BackgroundTypeDeserializer extends JsonDeserializer { + + @Override + public BackgroundType deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException { + ObjectCodec codec = parser.getCodec(); + JsonNode node = codec.readTree(parser); + + String type = node.get("type").asText(); + + return switch (type) { + case "fill" -> codec.treeToValue(node, BackgroundTypeFill.class); + case "wallpaper" -> codec.treeToValue(node, BackgroundTypeWallpaper.class); + case "pattern" -> codec.treeToValue(node, BackgroundTypePattern.class); + case "chat_theme" -> codec.treeToValue(node, BackgroundTypeChatTheme.class); + default -> throw new IllegalArgumentException("Unknown type: " + type); + }; + } +} 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..a14dd9f --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundTypeFill.java @@ -0,0 +1,14 @@ +package hdvtdev.telegram.core.objects.background; + +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..c12749c --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundTypePattern.java @@ -0,0 +1,17 @@ +package hdvtdev.telegram.core.objects.background; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.media.Document; + +@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..7a3aae4 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/background/BackgroundTypeWallpaper.java @@ -0,0 +1,17 @@ +package hdvtdev.telegram.core.objects.background; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.media.Document; + +@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..8a8420a --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/business/BusinessConnection.java @@ -0,0 +1,18 @@ +package hdvtdev.telegram.core.objects.business; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.User; + +@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..f718169 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/business/BusinessMessagesDeleted.java @@ -0,0 +1,15 @@ +package hdvtdev.telegram.core.objects.business; + +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..a14d45c --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/callback/CallbackGame.java @@ -0,0 +1,9 @@ +package hdvtdev.telegram.core.objects.callback; + +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..efd8a83 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/callback/CallbackQuery.java @@ -0,0 +1,41 @@ +package hdvtdev.telegram.core.objects.callback; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.User; +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..6717445 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chat/Chat.java @@ -0,0 +1,35 @@ +package hdvtdev.telegram.core.objects.chat; + +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..e9a4bc9 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatAdministratorRights.java @@ -0,0 +1,26 @@ +package hdvtdev.telegram.core.objects.chat; + +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..0caf75d --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatBackground.java @@ -0,0 +1,12 @@ +package hdvtdev.telegram.core.objects.chat; + +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..9224bab --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatInviteLink.java @@ -0,0 +1,28 @@ +package hdvtdev.telegram.core.objects.chat; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import hdvtdev.telegram.core.objects.User; + +@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 +) { + @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..b60d304 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatJoinRequest.java @@ -0,0 +1,18 @@ +package hdvtdev.telegram.core.objects.chat; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.User; + +@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..ec1fbde --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatMember.java @@ -0,0 +1,29 @@ +package hdvtdev.telegram.core.objects.chat; + +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import hdvtdev.telegram.core.objects.User; + +@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..1ef4002 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatMemberAdministrator.java @@ -0,0 +1,31 @@ +package hdvtdev.telegram.core.objects.chat; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.User; + +@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..2915819 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatMemberBanned.java @@ -0,0 +1,15 @@ +package hdvtdev.telegram.core.objects.chat; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.User; + +@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..4f643b5 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatMemberLeft.java @@ -0,0 +1,14 @@ +package hdvtdev.telegram.core.objects.chat; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.User; + +@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..97b9cfc --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatMemberMember.java @@ -0,0 +1,15 @@ +package hdvtdev.telegram.core.objects.chat; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.User; + +@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..af38ed9 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatMemberOwner.java @@ -0,0 +1,16 @@ +package hdvtdev.telegram.core.objects.chat; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.User; + +@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..0240b47 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatMemberRestricted.java @@ -0,0 +1,30 @@ +package hdvtdev.telegram.core.objects.chat; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.User; + +@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..8f82c4c --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatMemberUpdated.java @@ -0,0 +1,20 @@ +package hdvtdev.telegram.core.objects.chat; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.User; + +@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..18d87f5 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chat/ChatShared.java @@ -0,0 +1,17 @@ +package hdvtdev.telegram.core.objects.chat; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.media.PhotoSize; + +@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..972adea --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chatboost/ChatBoost.java @@ -0,0 +1,15 @@ +package hdvtdev.telegram.core.objects.chatboost; + +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..5ca4d8c --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chatboost/ChatBoostAdded.java @@ -0,0 +1,12 @@ +package hdvtdev.telegram.core.objects.chatboost; + +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..1dd3f4c --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chatboost/ChatBoostRemoved.java @@ -0,0 +1,16 @@ +package hdvtdev.telegram.core.objects.chatboost; + +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 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..85afb55 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chatboost/ChatBoostSource.java @@ -0,0 +1,18 @@ +package hdvtdev.telegram.core.objects.chatboost; + +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..61e9ecd --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chatboost/ChatBoostSourceGiftCode.java @@ -0,0 +1,14 @@ +package hdvtdev.telegram.core.objects.chatboost; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.User; + +@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..18d6937 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chatboost/ChatBoostSourceGiveaway.java @@ -0,0 +1,17 @@ +package hdvtdev.telegram.core.objects.chatboost; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.User; + +@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..76259d5 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chatboost/ChatBoostSourcePremium.java @@ -0,0 +1,14 @@ +package hdvtdev.telegram.core.objects.chatboost; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.User; + +@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..97d3c53 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/chatboost/ChatBoostUpdated.java @@ -0,0 +1,14 @@ +package hdvtdev.telegram.core.objects.chatboost; + +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 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..3602670 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommand.java @@ -0,0 +1,13 @@ +package hdvtdev.telegram.core.objects.command; + +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..3fea65e --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommandScope.java @@ -0,0 +1,22 @@ +package hdvtdev.telegram.core.objects.command; + +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..8876594 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommandScopeAllChatAdministrators.java @@ -0,0 +1,10 @@ +package hdvtdev.telegram.core.objects.command; + +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..b5b3af7 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommandScopeAllGroupChats.java @@ -0,0 +1,10 @@ +package hdvtdev.telegram.core.objects.command; + +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..9d6c2fd --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommandScopeAllPrivateChats.java @@ -0,0 +1,10 @@ +package hdvtdev.telegram.core.objects.command; + +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..cac79ce --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommandScopeChat.java @@ -0,0 +1,14 @@ +package hdvtdev.telegram.core.objects.command; + +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..14e6440 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommandScopeChatAdministrators.java @@ -0,0 +1,14 @@ +package hdvtdev.telegram.core.objects.command; + +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..ff84bd4 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommandScopeChatMember.java @@ -0,0 +1,27 @@ +package hdvtdev.telegram.core.objects.command; + +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..d9e6cef --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/command/BotCommandScopeDefault.java @@ -0,0 +1,10 @@ +package hdvtdev.telegram.core.objects.command; + +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..236afe4 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/forum/ForumTopicClosed.java @@ -0,0 +1,9 @@ +package hdvtdev.telegram.core.objects.forum; + +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..b027e8c --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/forum/ForumTopicCreated.java @@ -0,0 +1,14 @@ +package hdvtdev.telegram.core.objects.forum; + +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..73caa6d --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/forum/ForumTopicEdited.java @@ -0,0 +1,13 @@ +package hdvtdev.telegram.core.objects.forum; + +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..da882ba --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/forum/ForumTopicReopened.java @@ -0,0 +1,9 @@ +package hdvtdev.telegram.core.objects.forum; + +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..86191e9 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/forum/GeneralForumTopicHidden.java @@ -0,0 +1,9 @@ +package hdvtdev.telegram.core.objects.forum; + +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..a62fd79 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/forum/GeneralForumTopicUnhidden.java @@ -0,0 +1,9 @@ +package hdvtdev.telegram.core.objects.forum; + +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..141a640 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/giveaway/Giveaway.java @@ -0,0 +1,21 @@ +package hdvtdev.telegram.core.objects.giveaway; + +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..054f039 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/giveaway/GiveawayCompleted.java @@ -0,0 +1,16 @@ +package hdvtdev.telegram.core.objects.giveaway; + +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..81aedbd --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/giveaway/GiveawayCreated.java @@ -0,0 +1,10 @@ +package hdvtdev.telegram.core.objects.giveaway; + +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..589cf9d --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/giveaway/GiveawayWinners.java @@ -0,0 +1,25 @@ +package hdvtdev.telegram.core.objects.giveaway; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.User; +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..ff614ab --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/markup/CopyTextButton.java @@ -0,0 +1,10 @@ +package hdvtdev.telegram.core.objects.markup; + +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..158c627 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/markup/ForceReply.java @@ -0,0 +1,14 @@ +package hdvtdev.telegram.core.objects.markup; + +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/core/objects/markup/InlineKeyboardButton.java b/core/src/main/java/hdvtdev/telegram/core/objects/markup/InlineKeyboardButton.java new file mode 100644 index 0000000..f48aa1d --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/markup/InlineKeyboardButton.java @@ -0,0 +1,252 @@ +package hdvtdev.telegram.core.objects.markup; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.*; +import hdvtdev.telegram.core.objects.callback.CallbackGame; + +@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..ebe09a1 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/markup/InlineKeyboardMarkup.java @@ -0,0 +1,35 @@ +package hdvtdev.telegram.core.objects.markup; + +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..4ecb637 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/markup/InlineKeyboardRow.java @@ -0,0 +1,68 @@ +package hdvtdev.telegram.core.objects.markup; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonValue; + +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(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..87c8790 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/markup/KeyboardButton.java @@ -0,0 +1,19 @@ +package hdvtdev.telegram.core.objects.markup; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.WebAppInfo; + +@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..ea1cca4 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/markup/KeyboardButtonPollType.java @@ -0,0 +1,12 @@ +package hdvtdev.telegram.core.objects.markup; + +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..027a9a6 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/markup/KeyboardButtonRequestChat.java @@ -0,0 +1,23 @@ +package hdvtdev.telegram.core.objects.markup; + +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..47dd7d7 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/markup/KeyboardButtonRequestUsers.java @@ -0,0 +1,18 @@ +package hdvtdev.telegram.core.objects.markup; + +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..31aed91 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/markup/ReplyKeyboardMarkup.java @@ -0,0 +1,17 @@ +package hdvtdev.telegram.core.objects.markup; + +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..1a3aca4 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/markup/ReplyKeyboardRemove.java @@ -0,0 +1,13 @@ +package hdvtdev.telegram.core.objects.markup; + +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..6c232a6 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/markup/ReplyMarkup.java @@ -0,0 +1,16 @@ +package hdvtdev.telegram.core.objects.markup; + +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..dadf0ab --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/markup/SwitchInlineQueryChosenChat.java @@ -0,0 +1,16 @@ +package hdvtdev.telegram.core.objects.markup; + +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..3f0b1f6 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/Animation.java @@ -0,0 +1,37 @@ +package hdvtdev.telegram.core.objects.media; + +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..95a383b --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/Audio.java @@ -0,0 +1,37 @@ +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 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..b2dfe10 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/Document.java @@ -0,0 +1,23 @@ +package hdvtdev.telegram.core.objects.media; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import hdvtdev.telegram.core.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 toGetFile() { + 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..eb2520b --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/PhotoSize.java @@ -0,0 +1,16 @@ +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 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..720fd49 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/Sticker.java @@ -0,0 +1,27 @@ +package hdvtdev.telegram.core.objects.media; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.MaskPosition; + +@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..f75e5e0 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/Story.java @@ -0,0 +1,14 @@ +package hdvtdev.telegram.core.objects.media; + +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..4a1a657 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/TelegramFile.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; +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..d6f6bbf --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/Voice.java @@ -0,0 +1,16 @@ +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 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..3d3c271 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/paidmedia/PaidMedia.java @@ -0,0 +1,17 @@ +package hdvtdev.telegram.core.objects.media.paidmedia; + +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..5736add --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/paidmedia/PaidMediaInfo.java @@ -0,0 +1,13 @@ +package hdvtdev.telegram.core.objects.media.paidmedia; + +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..d2d3e90 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/paidmedia/PaidMediaPhoto.java @@ -0,0 +1,14 @@ +package hdvtdev.telegram.core.objects.media.paidmedia; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.media.PhotoSize; + +@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..10f03aa --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/paidmedia/PaidMediaPreview.java @@ -0,0 +1,15 @@ +package hdvtdev.telegram.core.objects.media.paidmedia; + +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..e7ed083 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/paidmedia/PaidMediaPurchased.java @@ -0,0 +1,14 @@ +package hdvtdev.telegram.core.objects.media.paidmedia; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.User; + +@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..0ff3204 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/paidmedia/PaidMediaVideo.java @@ -0,0 +1,14 @@ +package hdvtdev.telegram.core.objects.media.paidmedia; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.media.video.Video; + +@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..ca30757 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/video/Video.java @@ -0,0 +1,23 @@ +package hdvtdev.telegram.core.objects.media.video; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.media.PhotoSize; + +@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..6e5edea --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/video/VideoChatEnded.java @@ -0,0 +1,10 @@ +package hdvtdev.telegram.core.objects.media.video; + +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..7dcf330 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/video/VideoChatParticipantsInvited.java @@ -0,0 +1,11 @@ +package hdvtdev.telegram.core.objects.media.video; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.User; + +@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..ee9bab4 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/video/VideoChatScheduled.java @@ -0,0 +1,10 @@ +package hdvtdev.telegram.core.objects.media.video; + +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..526f53b --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/video/VideoChatStarted.java @@ -0,0 +1,9 @@ +package hdvtdev.telegram.core.objects.media.video; + +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..f100e46 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/media/video/VideoNote.java @@ -0,0 +1,18 @@ +package hdvtdev.telegram.core.objects.media.video; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.media.PhotoSize; + +@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..bec0acf --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/message/ExternalReplyInfo.java @@ -0,0 +1,45 @@ +package hdvtdev.telegram.core.objects.message; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.*; +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.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..de319d5 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/message/InaccessibleMessage.java @@ -0,0 +1,16 @@ +package hdvtdev.telegram.core.objects.message; + +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 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..fc30855 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/message/LinkPreviewOptions.java @@ -0,0 +1,17 @@ +package hdvtdev.telegram.core.objects.message; + +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..6820944 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/message/MaybeInaccessibleMessage.java @@ -0,0 +1,26 @@ +package hdvtdev.telegram.core.objects.message; + +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; + +import hdvtdev.telegram.core.objects.chat.Chat; + +@JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, + include = JsonTypeInfo.As.EXISTING_PROPERTY, + property = "date", + defaultImpl = Message.class +) +@JsonSubTypes({ + @JsonSubTypes.Type(value = InaccessibleMessage.class, name = "0") +}) +public interface MaybeInaccessibleMessage { + long chatId(); + + Chat chat(); + + int messageId(); + + long date(); + +} 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..476f236 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/message/Message.java @@ -0,0 +1,295 @@ +package hdvtdev.telegram.core.objects.message; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import hdvtdev.telegram.core.objects.*; +import hdvtdev.telegram.core.objects.chat.Chat; +import hdvtdev.telegram.core.objects.chat.ChatBackground; +import hdvtdev.telegram.core.objects.chat.ChatShared; +import hdvtdev.telegram.core.objects.chatboost.ChatBoostAdded; +import hdvtdev.telegram.core.objects.forum.*; +import hdvtdev.telegram.core.objects.giveaway.Giveaway; +import hdvtdev.telegram.core.objects.giveaway.GiveawayCompleted; +import hdvtdev.telegram.core.objects.giveaway.GiveawayCreated; +import hdvtdev.telegram.core.objects.giveaway.GiveawayWinners; +import hdvtdev.telegram.core.objects.markup.InlineKeyboardMarkup; +import hdvtdev.telegram.core.objects.media.*; +import hdvtdev.telegram.core.objects.media.paidmedia.PaidMediaInfo; +import hdvtdev.telegram.core.objects.media.video.*; +import hdvtdev.telegram.core.objects.passport.PassportData; +import hdvtdev.telegram.core.objects.payment.Invoice; +import hdvtdev.telegram.core.objects.payment.RefundedPayment; +import hdvtdev.telegram.core.objects.payment.SuccessfulPayment; +import hdvtdev.telegram.core.objects.poll.Poll; + +@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..eb963a8 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageAutoDeleteTimerChanged.java @@ -0,0 +1,10 @@ +package hdvtdev.telegram.core.objects.message; + +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..99d7024 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageEntity.java @@ -0,0 +1,19 @@ +package hdvtdev.telegram.core.objects.message; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.User; + +@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..daad092 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageOrigin.java @@ -0,0 +1,19 @@ +package hdvtdev.telegram.core.objects.message; + +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..1ead486 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageOriginChannel.java @@ -0,0 +1,17 @@ +package hdvtdev.telegram.core.objects.message; + +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 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..a28beeb --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageOriginChat.java @@ -0,0 +1,16 @@ +package hdvtdev.telegram.core.objects.message; + +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 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..b8acfa2 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageOriginHiddenUser.java @@ -0,0 +1,14 @@ +package hdvtdev.telegram.core.objects.message; + +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..896640e --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageOriginUser.java @@ -0,0 +1,15 @@ +package hdvtdev.telegram.core.objects.message; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.User; + +@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..181068a --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageReactionCountUpdated.java @@ -0,0 +1,17 @@ +package hdvtdev.telegram.core.objects.message; + +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.reaction.ReactionCount; + +@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..595c94e --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/message/MessageReactionUpdated.java @@ -0,0 +1,21 @@ +package hdvtdev.telegram.core.objects.message; + +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.reaction.ReactionType; +import hdvtdev.telegram.core.objects.User; + +@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..3435ca0 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/message/TextQuote.java @@ -0,0 +1,11 @@ +package hdvtdev.telegram.core.objects.message; + +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/core/objects/passport/EncryptedCredentials.java b/core/src/main/java/hdvtdev/telegram/core/objects/passport/EncryptedCredentials.java new file mode 100644 index 0000000..4d7922a --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/passport/EncryptedCredentials.java @@ -0,0 +1,14 @@ +package hdvtdev.telegram.core.objects.passport; + +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..ffe82eb --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/passport/EncryptedPassportElement.java @@ -0,0 +1,21 @@ +package hdvtdev.telegram.core.objects.passport; + +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..e6d140e --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/passport/PassportData.java @@ -0,0 +1,13 @@ +package hdvtdev.telegram.core.objects.passport; + +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..f03d6f8 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/passport/PassportFile.java @@ -0,0 +1,15 @@ +package hdvtdev.telegram.core.objects.passport; + +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..9de230a --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/payment/Invoice.java @@ -0,0 +1,16 @@ +package hdvtdev.telegram.core.objects.payment; + +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..05f103d --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/payment/OrderInfo.java @@ -0,0 +1,15 @@ +package hdvtdev.telegram.core.objects.payment; + +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..b8749bd --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/payment/PreCheckoutQuery.java @@ -0,0 +1,19 @@ +package hdvtdev.telegram.core.objects.payment; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.User; + +@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..e95d068 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/payment/RefundedPayment.java @@ -0,0 +1,16 @@ +package hdvtdev.telegram.core.objects.payment; + +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..d7a8a96 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/payment/ShippingAddress.java @@ -0,0 +1,17 @@ +package hdvtdev.telegram.core.objects.payment; + +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..3a3d741 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/payment/ShippingQuery.java @@ -0,0 +1,16 @@ +package hdvtdev.telegram.core.objects.payment; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.User; + +@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..f523da4 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/payment/SuccessfulPayment.java @@ -0,0 +1,21 @@ +package hdvtdev.telegram.core.objects.payment; + +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..0b32f5b --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/poll/Poll.java @@ -0,0 +1,26 @@ +package hdvtdev.telegram.core.objects.poll; + +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..2bebc16 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/poll/PollAnswer.java @@ -0,0 +1,17 @@ +package hdvtdev.telegram.core.objects.poll; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import hdvtdev.telegram.core.objects.User; +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..582595e --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/poll/PollOption.java @@ -0,0 +1,15 @@ +package hdvtdev.telegram.core.objects.poll; + +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..10d0a79 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/reaction/ReactionCount.java @@ -0,0 +1,13 @@ +package hdvtdev.telegram.core.objects.reaction; + +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..0e486db --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/reaction/ReactionType.java @@ -0,0 +1,17 @@ +package hdvtdev.telegram.core.objects.reaction; + +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..055e766 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/reaction/ReactionTypeCustomEmoji.java @@ -0,0 +1,13 @@ +package hdvtdev.telegram.core.objects.reaction; + +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..13a6659 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/reaction/ReactionTypeEmoji.java @@ -0,0 +1,16 @@ +package hdvtdev.telegram.core.objects.reaction; + +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..9ed6149 --- /dev/null +++ b/core/src/main/java/hdvtdev/telegram/core/objects/reaction/ReactionTypePaid.java @@ -0,0 +1,12 @@ +package hdvtdev.telegram.core.objects.reaction; + +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/module-info.java b/core/src/main/java/module-info.java new file mode 100644 index 0000000..ef0e284 --- /dev/null +++ b/core/src/main/java/module-info.java @@ -0,0 +1,25 @@ +module core { + requires com.fasterxml.jackson.databind; + exports hdvtdev.telegram.core.exceptions; + exports hdvtdev.telegram.core.objects.command; + exports hdvtdev.telegram.core.annotaions; + exports hdvtdev.telegram.core.methods; + exports hdvtdev.telegram.core; + exports hdvtdev.telegram.core.objects; + exports hdvtdev.telegram.core.objects.callback; + exports hdvtdev.telegram.core.objects.message; + exports hdvtdev.telegram.core.objects.media; + exports hdvtdev.telegram.core.objects.media.paidmedia; + exports hdvtdev.telegram.core.objects.media.video; + exports hdvtdev.telegram.core.objects.background; + exports hdvtdev.telegram.core.objects.business; + exports hdvtdev.telegram.core.objects.chat; + exports hdvtdev.telegram.core.objects.chatboost; + exports hdvtdev.telegram.core.objects.forum; + exports hdvtdev.telegram.core.objects.giveaway; + exports hdvtdev.telegram.core.objects.markup; + exports hdvtdev.telegram.core.objects.passport; + exports hdvtdev.telegram.core.objects.payment; + exports hdvtdev.telegram.core.objects.poll; + exports hdvtdev.telegram.core.objects.reaction; +} \ 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..bfba11b --- /dev/null +++ b/longpolling-okhttp/src/main/java/hdvtdev/telegram/longpolling/okhttp/OkHttpTelegramBot.java @@ -0,0 +1,251 @@ +package hdvtdev.telegram.longpolling.okhttp; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +import hdvtdev.telegram.core.InvokeMethod; +import hdvtdev.telegram.core.TelegramBot; +import hdvtdev.telegram.core.UpdateConsumer; +import hdvtdev.telegram.core.annotaions.Jsonable; +import hdvtdev.telegram.core.exceptions.TelegramApiException; +import hdvtdev.telegram.core.exceptions.TelegramApiNetworkException; +import hdvtdev.telegram.core.exceptions.TelegramMethodParsingException; +import hdvtdev.telegram.core.methods.GetUpdates; +import hdvtdev.telegram.core.methods.TelegramApiMethod; +import hdvtdev.telegram.core.methods.TelegramApiMethodBody; +import hdvtdev.telegram.core.objects.Update; +import hdvtdev.telegram.core.objects.media.TelegramFile; + +import okhttp3.*; + +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.List; +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; + + 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; + + public OkHttpTelegramBot(String token) { + this.json = new ObjectMapper(); + 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; + json = builder.objectMapper == null ? new ObjectMapper() : builder.objectMapper; + /* + if (false) { + 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 + "/"; + if (builder.updateConsumer != null) setUpdateConsumer(builder.updateConsumer); + } + + /** + * 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 #enableHandlers + * @since 0.0.1 + */ + private 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))); + try { + if (!updates.isEmpty()) { + if (updateConsumer != null) CompletableFuture.runAsync(() -> updateConsumer.onUpdates(updates)); + lastUpdateId.set(updates.getLast().updateId()); + } + } finally { + if (!thread.isShutdown()) getUpdates(); + } + } + + @Override + public void shutdown() { + this.thread.close(); + } + + @Override + public T awaitExecute(TelegramApiMethod telegramApiMethod) throws TelegramApiException, TelegramApiNetworkException, TelegramMethodParsingException { + + TelegramApiMethodBody 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 { + FormBody.Builder requestBody = new FormBody.Builder(); + for (int i = 0; i < body.size(); i++) { + TelegramApiMethodBody.Element e = body.get(i); + requestBody.add(e.name(), e.value()); + } + request.post(requestBody.build()); + } + + 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); + } + + + } + + 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 UpdateConsumer updateConsumer; + private ObjectMapper objectMapper; + + public Builder(String token) { + this.token = token; + } + + public Builder objectMapper(ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + return this; + } + + public Builder updateConsumer(UpdateConsumer updateConsumer) { + this.updateConsumer = updateConsumer; + return this; + } + + 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..e7df579 --- /dev/null +++ b/longpolling-okhttp/src/main/java/module-info.java @@ -0,0 +1,6 @@ +module longpolling.okhttp { + exports hdvtdev.telegram.longpolling.okhttp; + requires core; + requires okhttp3; + requires com.fasterxml.jackson.databind; +} diff --git a/settings.gradle b/settings.gradle index ef3e3e5..8dac7dc 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,4 @@ rootProject.name = 'TeleJ' +include 'core' +include 'longpolling-okhttp'