Compare commits
17 Commits
52c9264253
...
d80d4e3b94
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d80d4e3b94 | ||
|
|
6093465f0d | ||
|
|
92aa5cd951 | ||
|
|
f67cbf2df1 | ||
|
|
66d2172f51 | ||
|
|
97e93f7feb | ||
|
|
5fe53b2539 | ||
|
|
ab43f9cb52 | ||
|
|
111eafdc0a | ||
|
|
7b66404e3e | ||
|
|
a936b9d560 | ||
|
|
cb87ea0eee | ||
|
|
3c62306a93 | ||
|
|
e80de4eab7 | ||
|
|
dc877fa97e | ||
|
|
9d3f7e74ef | ||
|
|
00ada710ac |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -40,4 +40,4 @@ bin/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
||||
/src/main/java/hdvtdev/telegram/Count.java
|
||||
/core/src/main/java/hdvtdev/telegram/Count.java
|
||||
|
||||
6
.idea/AndroidProjectSystem.xml
generated
Normal file
6
.idea/AndroidProjectSystem.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="AndroidProjectSystem">
|
||||
<option name="providerId" value="com.android.tools.idea.GradleProjectSystem" />
|
||||
</component>
|
||||
</project>
|
||||
7
.idea/dictionaries/project.xml
generated
Normal file
7
.idea/dictionaries/project.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
<component name="ProjectDictionaryState">
|
||||
<dictionary name="project">
|
||||
<words>
|
||||
<w>jsonable</w>
|
||||
</words>
|
||||
</dictionary>
|
||||
</component>
|
||||
2
.idea/gradle.xml
generated
2
.idea/gradle.xml
generated
@@ -8,6 +8,8 @@
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/core" />
|
||||
<option value="$PROJECT_DIR$/longpolling-okhttp" />
|
||||
</set>
|
||||
</option>
|
||||
</GradleProjectSettings>
|
||||
|
||||
@@ -3,11 +3,7 @@
|
||||
|
||||
|
||||
Total lines of code:
|
||||
<span style="background-color: blue; color: white; padding: 2px 4px;">02 April 2025 20:52:22 3472</span>
|
||||
|
||||
<p>
|
||||
<span style="background-color: blue; color: white; padding: 2px 4px;">08 April 2025 22:05:30 code: 3440 docs: 0</span>
|
||||
<p>
|
||||
|
||||
<p>
|
||||
<span style="background-color: blue; color: white; padding: 2px 4px;">08 April 2025 22:07:16 code: 6094 docs: 173</span>
|
||||
|
||||
@@ -1,136 +0,0 @@
|
||||
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<Class<? extends Annotation>> annotationsToSearch = Set.of(TextMessageHandler.class, CallbackQueryHandler.class);
|
||||
private static final Set<Class<?>> methodsArgumentType = Set.of(Message.class, Update.class, CallbackQuery.class);
|
||||
|
||||
private static ErrorHandler errorHandler;
|
||||
|
||||
public static Map<Class<?>, Map<String, InvokeMethod>> getClasses() {
|
||||
|
||||
Map<Class<?>, Map<String, InvokeMethod>> 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<Class<?>, Map<String, InvokeMethod>> 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<Class<?>, Map<String, InvokeMethod>> methods) {
|
||||
try (JarFile jar = new JarFile(jarFile)) {
|
||||
Enumeration<JarEntry> 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<Class<?>, Map<String, InvokeMethod>> localScan(Class<?> cls) {
|
||||
Map<Class<?>, Map<String, InvokeMethod>> allMethods = new HashMap<>();
|
||||
annotationsToSearch.forEach(annotation -> allMethods.put(annotation, new HashMap<>()));
|
||||
loadClass(cls.getName(), allMethods);
|
||||
return allMethods;
|
||||
}
|
||||
|
||||
|
||||
private static void loadClass(String className, Map<Class<?>, Map<String, InvokeMethod>> 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);
|
||||
}
|
||||
|
||||
}
|
||||
19
build.gradle
19
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) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ plugins {
|
||||
group = 'com.github.hdvtdev'
|
||||
version = '1.0.0'
|
||||
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
@@ -13,7 +14,3 @@ dependencies {
|
||||
implementation 'com.fasterxml.jackson.core:jackson-databind:2.18.3'
|
||||
}
|
||||
|
||||
jar {
|
||||
from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
}
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
package hdvtdev.telegram;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import hdvtdev.telegram.annotations.handlers.TextMessageHandler;
|
||||
import hdvtdev.telegram.core.OkHttpTelegramBot;
|
||||
import hdvtdev.telegram.core.TelegramBot;
|
||||
import hdvtdev.telegram.core.UpdateConsumer;
|
||||
import hdvtdev.telegram.exceptions.TelegramApiException;
|
||||
import hdvtdev.telegram.methods.*;
|
||||
import hdvtdev.telegram.objects.*;
|
||||
import hdvtdev.telegram.util.ClassFinder;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class Main {
|
||||
|
||||
private static String apiKey;
|
||||
|
||||
private static long idd = 2027845508;
|
||||
|
||||
public static TelegramBot bot;
|
||||
|
||||
@TextMessageHandler("пинг")
|
||||
private static void ping(Message message) {
|
||||
bot.execute(new SendMessage(message.chatId(), String.valueOf(bot.getPing())));
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
bot = new OkHttpTelegramBot.Builder(args[0]).enableHandlers(true).build();
|
||||
bot.enableDefaultUpdateConsumer();
|
||||
|
||||
apiKey = args[2];
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static class Upd implements UpdateConsumer, ClassFinder.ErrorHandler {
|
||||
|
||||
@Override
|
||||
public void onError(Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void getUpdates(List<Update> updates) {
|
||||
updates.forEach(System.out::println);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
package hdvtdev.telegram.annotations.handlers;
|
||||
|
||||
import hdvtdev.telegram.objects.CallbackQuery;
|
||||
import hdvtdev.telegram.objects.Update;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Marks a static method as a handler for {@link CallbackQuery} updates with specific data values.
|
||||
* <p>
|
||||
* If {@code value} is set to "*", the method will handle all {@link CallbackQuery} data,
|
||||
* and other {@code @CallbackQueryHandler} methods will be ignored.
|
||||
* <p>
|
||||
* The annotated method must be {@code static} and may accept:
|
||||
* <ul>
|
||||
* <li>{@link Void} {@code (no params)}</li>
|
||||
* <li>{@link Update}</li>
|
||||
* <li>{@link CallbackQuery}</li>
|
||||
* </ul>
|
||||
* Only one parameter is allowed.
|
||||
* <p>
|
||||
* You do not need to call {@link CallbackQuery#hasData()} or {@link Update#hasCallbackQuery()},
|
||||
* as these checks are performed automatically before invocation.
|
||||
*
|
||||
* <h3>Usage example:</h3>
|
||||
* <pre><code>
|
||||
* {@code @CallbackQueryHandler({"stop",} "shutdown"})
|
||||
* private static void stop(CallbackQuery callbackQuery) {
|
||||
* long id = callbackQuery.message.chatId;
|
||||
* if (DatabaseManager.isAdmin(id)) {
|
||||
* bot.awaitExecute(new SendMessage(id, "Shutting down..."));
|
||||
* System.exit(0);
|
||||
* }
|
||||
* }
|
||||
* </code></pre>
|
||||
* <h5>Last documentation update: 2025-04-05</h5>
|
||||
* @see Update
|
||||
* @see CallbackQuery
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface CallbackQueryHandler {
|
||||
/**
|
||||
* Values to match against {@link CallbackQuery#data()}.
|
||||
* If set to "*", this method will handle all {@link CallbackQuery} updates,
|
||||
* overriding any other {@code @CallbackQueryHandler} annotations.
|
||||
*
|
||||
* @return array of matching strings
|
||||
*/
|
||||
@NotNull String[] value() default "*";
|
||||
}
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
package hdvtdev.telegram.annotations.handlers;
|
||||
|
||||
import hdvtdev.telegram.objects.Message;
|
||||
import hdvtdev.telegram.objects.Update;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Marks a static method as a handler for {@link Message} updates with specific data values.
|
||||
* <p>
|
||||
* If {@code value} is set to "*", the method will handle all {@link Message} text,
|
||||
* and other {@code @TextMessageHandler} methods will be ignored.
|
||||
* <p>
|
||||
* The annotated method must be {@code static} and may accept:
|
||||
* <ul>
|
||||
* <li>{@link Void} {@code (no params)}</li>
|
||||
* <li>{@link Update}</li>
|
||||
* <li>{@link Message}</li>
|
||||
* </ul>
|
||||
* Only one parameter is allowed.
|
||||
* <p>
|
||||
* You do not need to call {@link Message#hasText()} or {@link Update#hasMessage()},
|
||||
* as these checks are performed automatically before invocation.
|
||||
*
|
||||
* <h3>Usage example:</h3>
|
||||
* <pre><code>
|
||||
* {@code @TextMessageHandler}({"rock", "paper", "scissors"})
|
||||
* private static void cheaterRockPaperScissors(Message message) {
|
||||
* bot.execute(new SendMessage(message.chatId(), switch(message.text()) {
|
||||
* case "rock" -> "paper";
|
||||
* case "paper" -> "scissors";
|
||||
* default -> "rock";
|
||||
* }));
|
||||
*
|
||||
* {@code @TextMessageHandler}("/ping")
|
||||
* private static void ping(Message message) {
|
||||
* bot.execute(new SendMessage(message.chatId(), String.valueOf(bot.getPing())));
|
||||
* }
|
||||
* </code></pre>
|
||||
* <h5>Last documentation update: 2025-04-05</h5>
|
||||
* @see Update
|
||||
* @see Message
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface TextMessageHandler {
|
||||
/**
|
||||
* Values to match against {@link Message#text()}.
|
||||
* If set to "*", this method will handle all {@link Message} updates,
|
||||
* overriding any other {@code @TextMessageHandler} annotations.
|
||||
*
|
||||
* @return array of matching strings
|
||||
*/
|
||||
@NotNull String[] value() default "*";
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package hdvtdev.telegram.annotations.util;
|
||||
|
||||
import hdvtdev.telegram.methods.TelegramApiMethod;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* This annotation is used to indicate {@link TelegramApiMethod} that should be serialized into JSON.
|
||||
* <h5>Last documentation update: 2025-04-05</h5>
|
||||
* @see com.fasterxml.jackson.databind.ObjectMapper
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface Jsonable {
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package hdvtdev.telegram.annotations.util;
|
||||
|
||||
import hdvtdev.telegram.methods.TelegramApiMethod;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* This annotation is used to indicate {@link TelegramApiMethod} that is not tested, usually used if the method was created recently.
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Target({ElementType.METHOD, ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface NotTested {
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
package hdvtdev.telegram.core;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.annotations.handlers.TextMessageHandler;
|
||||
import hdvtdev.telegram.longpolling
|
||||
import hdvtdev.telegram.core.TelegramBot;
|
||||
import hdvtdev.telegram.core.UpdateConsumer;
|
||||
import hdvtdev.telegram.methods.*;
|
||||
import hdvtdev.telegram.objects.*;
|
||||
import hdvtdev.telegram.util.ClassFinder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class Main {
|
||||
|
||||
private static String apiKey;
|
||||
|
||||
private static long idd = 2027845508;
|
||||
|
||||
public static TelegramBot bot;
|
||||
|
||||
@TextMessageHandler("пинг")
|
||||
private static void ping(Message message) {
|
||||
bot.execute(new SendMessage(message.chatId(), String.valueOf(bot.getPing())));
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
bot = new OkHttpTelegramBot.Builder(args[0]).enableHandlers(true).build();
|
||||
bot.enableDefaultUpdateConsumer();
|
||||
|
||||
apiKey = args[2];
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static class Upd implements UpdateConsumer, ClassFinder.ErrorHandler {
|
||||
|
||||
@Override
|
||||
public void onError(Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void getUpdates(List<Update> updates) {
|
||||
updates.forEach(System.out::println);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package hdvtdev.telegram.core.bot;
|
||||
package hdvtdev.telegram.core;
|
||||
|
||||
import hdvtdev.telegram.exceptions.TelegramApiException;
|
||||
import hdvtdev.telegram.exceptions.TelegramApiNetworkException;
|
||||
import hdvtdev.telegram.exceptions.TelegramMethodParsingException;
|
||||
import hdvtdev.telegram.methods.TelegramApiMethod;
|
||||
import hdvtdev.telegram.objects.TelegramFile;
|
||||
import 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;
|
||||
@@ -19,12 +19,26 @@ public interface TelegramBot {
|
||||
|
||||
File awaitDownloadFile(TelegramFile telegramFile, Path targetDirectory);
|
||||
|
||||
default CompletableFuture<File> downloadFile(TelegramFile telegramFile, Path targetDirectory) throws TelegramApiException, TelegramApiNetworkException {
|
||||
return CompletableFuture.supplyAsync(() -> awaitDownloadFile(telegramFile, targetDirectory));
|
||||
void shutdown();
|
||||
|
||||
void start(UpdateConsumer updateConsumer);
|
||||
|
||||
default CompletableFuture<File> downloadFile(TelegramFile telegramFile, Path targetDirectory) {
|
||||
CompletableFuture<File> completableFuture = CompletableFuture.supplyAsync(() -> awaitDownloadFile(telegramFile, targetDirectory));
|
||||
completableFuture.exceptionally(e -> {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
});
|
||||
return completableFuture;
|
||||
}
|
||||
|
||||
default <T> CompletableFuture<T> execute(TelegramApiMethod<T> telegramApiMethod) throws TelegramApiException, TelegramApiNetworkException, TelegramMethodParsingException {
|
||||
return CompletableFuture.supplyAsync(() -> awaitExecute(telegramApiMethod));
|
||||
default <T> CompletableFuture<T> execute(TelegramApiMethod<T> telegramApiMethod) {
|
||||
CompletableFuture<T> completableFuture = CompletableFuture.supplyAsync(() -> awaitExecute(telegramApiMethod));
|
||||
completableFuture.exceptionally(e -> {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
});
|
||||
return completableFuture;
|
||||
}
|
||||
|
||||
default int getPing() throws TelegramApiNetworkException {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
package hdvtdev.telegram.core.bot;
|
||||
package hdvtdev.telegram.core;
|
||||
|
||||
|
||||
import hdvtdev.telegram.core.objects.Update;
|
||||
|
||||
@@ -6,6 +7,10 @@ import java.util.List;
|
||||
|
||||
public interface UpdateConsumer {
|
||||
|
||||
void getUpdates(List<Update> updates);
|
||||
|
||||
|
||||
default void onUpdate(Update update) {}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package hdvtdev.telegram.core.bot;
|
||||
package hdvtdev.telegram.core;
|
||||
|
||||
public interface UserState {
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
package hdvtdev.telegram.core.annotaions;
|
||||
|
||||
import hdvtdev.telegram.core.methods.TelegramApiMethod;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* This annotation is used to indicate {@link TelegramApiMethod} that should be serialized into JSON.
|
||||
* <h5>Last documentation update: 2025-04-05</h5>
|
||||
* @see com.fasterxml.jackson.databind.ObjectMapper
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface Jsonable {
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package hdvtdev.telegram.exceptions;
|
||||
package hdvtdev.telegram.core.exceptions;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package hdvtdev.telegram.exceptions;
|
||||
package hdvtdev.telegram.core.exceptions;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package hdvtdev.telegram.exceptions;
|
||||
package hdvtdev.telegram.core.exceptions;
|
||||
|
||||
public class TelegramMethodParsingException extends RuntimeException {
|
||||
public TelegramMethodParsingException(String message) {
|
||||
|
||||
@@ -1,22 +1,19 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
package hdvtdev.telegram.core.methods;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
import hdvtdev.telegram.objects.Game;
|
||||
import hdvtdev.telegram.core.objects.Game;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
/**
|
||||
* Use this method to send answers to callback queries sent from inline keyboards.
|
||||
* The answer will be displayed to the user as a notification at the top of the chat screen or as an alert.
|
||||
* Alternatively, the user can be redirected to the specified {@link Game} URL.
|
||||
* For this option to work, you must first create a game for your bot via @BotFather and accept the terms. Otherwise, you may use links like t.me/your_bot?start=XXXX that open your bot with a parameter.
|
||||
* 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 class AnswerCallbackQuery implements TelegramApiMethod<Boolean> {
|
||||
//@NotTested
|
||||
public final class AnswerCallbackQuery implements TelegramApiMethod<Boolean> {
|
||||
|
||||
/**
|
||||
* Unique identifier for the query to be answered
|
||||
@@ -33,7 +30,7 @@ public class AnswerCallbackQuery implements TelegramApiMethod<Boolean> {
|
||||
/**
|
||||
* URL that will be opened by the user's client.
|
||||
* If you have created a {@link Game} and accepted the conditions via @BotFather, specify the URL that opens your game.
|
||||
* Otherwise, you may use links like t.me/your_bot?start=XXXX that open your bot with a parameter.
|
||||
* 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;
|
||||
@@ -56,13 +53,14 @@ public class AnswerCallbackQuery implements TelegramApiMethod<Boolean> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
FormBody.Builder builder = new FormBody.Builder().add("callback_query_id", this.callbackQueryId);
|
||||
if (text != null) builder.add("text", this.text);
|
||||
if (showAlert != null) builder.add("show_alert", String.valueOf(this.showAlert));
|
||||
if (url != null) builder.add("url", this.url);
|
||||
if (cacheTime != null) builder.add("cache_time", String.valueOf(this.cacheTime));
|
||||
return builder.build();
|
||||
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
|
||||
|
||||
@@ -1,19 +1,14 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
package hdvtdev.telegram.core.methods;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
import hdvtdev.telegram.objects.ChatAdministratorRights;
|
||||
import hdvtdev.telegram.objects.Chat;
|
||||
import hdvtdev.telegram.objects.User;
|
||||
import hdvtdev.telegram.core.objects.chat.Chat;
|
||||
import hdvtdev.telegram.core.objects.chat.ChatAdministratorRights;
|
||||
import hdvtdev.telegram.core.objects.User;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Use this method to approve a chat join request.
|
||||
* The bot must be an <u>administrator</u> in the chat for this to work and must have the {@link ChatAdministratorRights#canInviteUsers()} administrator right.
|
||||
* Returns True on success.
|
||||
* The command must be an <u>administrator</u> in the chat for this to work and must have the {@link ChatAdministratorRights#canInviteUsers()} administrator right.
|
||||
* Returns {@code 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
|
||||
@@ -21,8 +16,9 @@ import org.jetbrains.annotations.NotNull;
|
||||
* @see Chat#id()
|
||||
* @since 0.1.0
|
||||
*/
|
||||
@NotTested
|
||||
public record ApproveChatJoinRequest(@NotNull String chatId, long userId) implements TelegramApiMethod<Boolean> {
|
||||
//TODO NotTested
|
||||
|
||||
public record ApproveChatJoinRequest(String chatId, long userId) implements TelegramApiMethod<Boolean> {
|
||||
|
||||
/**
|
||||
* @param chatId Unique identifier for the target chat
|
||||
@@ -35,8 +31,11 @@ public record ApproveChatJoinRequest(@NotNull String chatId, long userId) implem
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return new FormBody.Builder().add("chat_id", chatId).add("user_id", String.valueOf(userId)).build();
|
||||
public TelegramApiMethodBody getBody() {
|
||||
TelegramApiMethodBody body = new TelegramApiMethodBody();
|
||||
body.add("chat_id", chatId);
|
||||
body.add("user_id", String.valueOf(userId));
|
||||
return body;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
package hdvtdev.telegram.core.methods;
|
||||
|
||||
|
||||
import hdvtdev.telegram.core.objects.chat.ChatAdministratorRights;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
import hdvtdev.telegram.objects.ChatAdministratorRights;
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
/**
|
||||
* Use this method to ban a user in a group, a supergroup or a channel.
|
||||
* In the case of supergroups and channels, the user will not be able to return
|
||||
* to the chat on their own using invite links, etc., unless unbanned first.
|
||||
* The bot must be an administrator in the chat for this to work and must have
|
||||
* The 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
|
||||
*/
|
||||
@NotTested
|
||||
//TODO NotTested
|
||||
public final class BanChatMember implements TelegramApiMethod<Boolean> {
|
||||
|
||||
/**
|
||||
@@ -33,8 +32,8 @@ public final class BanChatMember implements TelegramApiMethod<Boolean> {
|
||||
*/
|
||||
private Long untilDate;
|
||||
/**
|
||||
* Pass true to delete all messages from the chat for the user that is being removed.
|
||||
* If false, the user will be able to see messages in the group that were sent before the user was removed.
|
||||
* 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;
|
||||
@@ -65,11 +64,13 @@ public final class BanChatMember implements TelegramApiMethod<Boolean> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
FormBody.Builder builder = new FormBody.Builder().add("chat_id", this.chatId).add("user_id", String.valueOf(userId));
|
||||
if (untilDate != null) builder.add("until_date", String.valueOf(untilDate));
|
||||
if (revokeMessages != null) builder.add("revoke_messages", String.valueOf(revokeMessages));
|
||||
return builder.build();
|
||||
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
|
||||
|
||||
@@ -1,29 +1,25 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
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 messages on behalf of
|
||||
* their channels. The bot must be an administrator in the supergroup or channel for this to
|
||||
* 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
|
||||
*/
|
||||
@NotTested
|
||||
public record BanChatSenderChat(@NotNull String chatId, long userId) implements TelegramApiMethod<Boolean> {
|
||||
//TODO NotTested
|
||||
public record BanChatSenderChat(String chatId, long userId) implements TelegramApiMethod<Boolean> {
|
||||
|
||||
public BanChatSenderChat(long chatId, long userId) {
|
||||
this(String.valueOf(chatId), userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return new FormBody.Builder().add("chat_id", chatId).add("user_id", String.valueOf(userId)).build();
|
||||
public TelegramApiMethodBody getBody() {
|
||||
TelegramApiMethodBody body = new TelegramApiMethodBody();
|
||||
body.add("chat_id", chatId);
|
||||
body.add("user_id", String.valueOf(userId));
|
||||
return body;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
package hdvtdev.telegram.core.methods;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
import hdvtdev.telegram.objects.ChatAdministratorRights;
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
import hdvtdev.telegram.core.objects.chat.ChatAdministratorRights;
|
||||
|
||||
/**
|
||||
* Use this method to close an open topic in a forum supergroup chat.
|
||||
* The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights,
|
||||
* 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()
|
||||
*/
|
||||
@NotTested
|
||||
//TODO NotTested
|
||||
public record CloseForumTopic(String chatId, long messageThreadId) implements TelegramApiMethod<Boolean> {
|
||||
|
||||
public CloseForumTopic(long chatId, long messageThreadId) {
|
||||
@@ -21,8 +18,11 @@ public record CloseForumTopic(String chatId, long messageThreadId) implements Te
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return new FormBody.Builder().add("chat_id", chatId).add("message_thread_id", String.valueOf(messageThreadId)).build();
|
||||
public TelegramApiMethodBody getBody() {
|
||||
TelegramApiMethodBody body = new TelegramApiMethodBody();
|
||||
body.add("chat_id", chatId);
|
||||
body.add("message_thread_id", String.valueOf(messageThreadId));
|
||||
return body;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,19 +1,15 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
package hdvtdev.telegram.core.methods;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
import hdvtdev.telegram.objects.ChatAdministratorRights;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
import hdvtdev.telegram.core.objects.chat.ChatAdministratorRights;
|
||||
|
||||
/**
|
||||
* Use this method to close an open 'General' topic in a forum supergroup chat.
|
||||
* The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights.
|
||||
* 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)
|
||||
*/
|
||||
@NotTested
|
||||
// TODO NotTested
|
||||
public record CloseGeneralForumTopic(String chatId) implements TelegramApiMethod<Boolean> {
|
||||
|
||||
public CloseGeneralForumTopic(long chatId) {
|
||||
@@ -21,8 +17,10 @@ public record CloseGeneralForumTopic(String chatId) implements TelegramApiMethod
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return new FormBody.Builder().add("chat_id", chatId).build();
|
||||
public TelegramApiMethodBody getBody() {
|
||||
TelegramApiMethodBody body = new TelegramApiMethodBody();
|
||||
body.add("chat_id", chatId);
|
||||
return body;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,32 +1,28 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
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.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
import hdvtdev.telegram.objects.MessageEntity;
|
||||
import hdvtdev.telegram.objects.Poll;
|
||||
import hdvtdev.telegram.objects.ReplyMarkup;
|
||||
import hdvtdev.telegram.objects.ReplyParameters;
|
||||
import hdvtdev.telegram.util.ParseMode;
|
||||
import 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 okhttp3.RequestBody;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Use this method to copy messages of any kind.
|
||||
* Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied.
|
||||
* A quiz {@link Poll} can be copied only if the value of the field correct_option_id is known to the bot.
|
||||
* 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
|
||||
*/
|
||||
@NotTested
|
||||
@Jsonable
|
||||
//TODO NotTested
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public final class CopyMessage implements TelegramApiMethod<Long> {
|
||||
|
||||
@@ -140,7 +136,13 @@ public final class CopyMessage implements TelegramApiMethod<Long> {
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
public boolean isJsonable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public TelegramApiMethodBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,29 +1,26 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
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.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.objects.Poll;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
import hdvtdev.telegram.core.objects.poll.Poll;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Use this method to copy messages of any kind.
|
||||
* If some of the specified messages can't be found or copied, they are skipped.
|
||||
* Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied.
|
||||
* A quiz {@link Poll} can be copied only if the value of the field correct_option_id is known to the bot.
|
||||
* The method is analogous to the method {@link ForwardMessages}, but the copied messages don't have a link to the original message.
|
||||
* Album grouping is kept for copied messages.
|
||||
* On success, an array of MessageId as {@link Long}{@code []} of the sent messages is returned.
|
||||
* 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<Long[]> {
|
||||
|
||||
@@ -44,8 +41,8 @@ public final class CopyMessages implements TelegramApiMethod<Long[]> {
|
||||
|
||||
/**
|
||||
* @param chatId Username of the target channel (in the format @channelusername)
|
||||
* @param fromChatId Channel username in the format @channelusername for the chat where the original messages were sent
|
||||
* @param messageIds List of 1-100 identifiers of messages in the chat to copy.
|
||||
* @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<Long> messageIds) {
|
||||
this.chatId = chatId;
|
||||
@@ -57,8 +54,8 @@ public final class CopyMessages implements TelegramApiMethod<Long[]> {
|
||||
|
||||
/**
|
||||
* @param chatId Unique identifier for the target chat
|
||||
* @param fromChatId Channel username in the format @channelusername for the chat where the original messages were sent
|
||||
* @param messageIds List of 1-100 identifiers of messages in the chat to copy.
|
||||
* @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<Long> messageIds) {
|
||||
this(String.valueOf(chatId), fromChatId, messageIds);
|
||||
@@ -66,17 +63,17 @@ public final class CopyMessages implements TelegramApiMethod<Long[]> {
|
||||
|
||||
/**
|
||||
* @param chatId Unique identifier for the target chat
|
||||
* @param fromChatId Unique identifier for the chat where the original messages were sent
|
||||
* @param messageIds List of 1-100 identifiers of messages in the chat to copy.
|
||||
* @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<Long> messageIds) {
|
||||
this(String.valueOf(chatId), String.valueOf(fromChatId), messageIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param chatId Channel username in the format @channelusername for the chat where the original messages were sent
|
||||
* @param 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 messages in the chat to copy.
|
||||
* @param messageIds List of 1-100 identifiers of message in the chat to copy.
|
||||
*/
|
||||
public CopyMessages(String chatId, long fromChatId, List<Long> messageIds) {
|
||||
this(chatId, String.valueOf(fromChatId), messageIds);
|
||||
@@ -110,7 +107,7 @@ public final class CopyMessages implements TelegramApiMethod<Long[]> {
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
public TelegramApiMethodBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -126,6 +123,12 @@ public final class CopyMessages implements TelegramApiMethod<Long[]> {
|
||||
return Long[].class;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public boolean isJsonable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private final String chatId;
|
||||
private Long messageThreadId;
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
package hdvtdev.telegram.core.methods;
|
||||
|
||||
import hdvtdev.telegram.objects.ChatAdministratorRights;
|
||||
import hdvtdev.telegram.objects.ChatInviteLink;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
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 bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
|
||||
* 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()
|
||||
*/
|
||||
@@ -54,12 +51,14 @@ public final class CreateChatInviteLink implements TelegramApiMethod<ChatInviteL
|
||||
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
FormBody.Builder builder = new FormBody.Builder().add("chat_id", chatId);
|
||||
if (expireDate != null) builder.add("expire_date", String.valueOf(expireDate));
|
||||
if (memberLimit != null) builder.add("member_limit", String.valueOf(memberLimit));
|
||||
if (createsJoinRequest != null) builder.add("creates_join_request", String.valueOf(createsJoinRequest));
|
||||
return builder.build();
|
||||
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
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
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.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.objects.Message;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
import hdvtdev.telegram.core.objects.message.Message;
|
||||
|
||||
/**
|
||||
* Use this method to forward messages of any kind.
|
||||
* Service messages and messages with protected content can't be forwarded.
|
||||
* 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<Message> {
|
||||
|
||||
@@ -75,7 +72,7 @@ public final class ForwardMessage implements TelegramApiMethod<Message> {
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
public TelegramApiMethodBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -91,6 +88,12 @@ public final class ForwardMessage implements TelegramApiMethod<Message> {
|
||||
return Message.class;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public boolean isJsonable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private final String chatId;
|
||||
private Long messageThreadId;
|
||||
|
||||
@@ -1,26 +1,21 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
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.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
import hdvtdev.telegram.objects.Message;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
import hdvtdev.telegram.core.objects.message.Message;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Use this method to forward multiple messages of any kind. If some of the specified messages can't be found or forwarded, they are skipped.
|
||||
* Service messages and messages with protected content can't be forwarded. Album grouping is kept for forwarded messages.
|
||||
* On success, an array of MessageId as {@link Long} of the sent messages is returned.
|
||||
* 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()
|
||||
*/
|
||||
@Jsonable
|
||||
@NotTested
|
||||
// TODO NotTested
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public final class ForwardMessages implements TelegramApiMethod<Long[]> {
|
||||
|
||||
@@ -80,7 +75,7 @@ public final class ForwardMessages implements TelegramApiMethod<Long[]> {
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
public TelegramApiMethodBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -96,6 +91,11 @@ public final class ForwardMessages implements TelegramApiMethod<Long[]> {
|
||||
return Long[].class;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public boolean isJsonable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private final String chatId;
|
||||
|
||||
@@ -1,27 +1,23 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
package hdvtdev.telegram.core.methods;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
import hdvtdev.telegram.objects.ChatMember;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
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
|
||||
*/
|
||||
@NotTested
|
||||
public record GetChatAdministrators(@NotNull String chatId) implements TelegramApiMethod<ChatMember[]> {
|
||||
//TODO NotTested
|
||||
public record GetChatAdministrators(String chatId) implements TelegramApiMethod<ChatMember[]> {
|
||||
|
||||
public GetChatAdministrators(long chatId) {
|
||||
this(String.valueOf(chatId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return new FormBody.Builder().add("chat_id", chatId).build();
|
||||
public TelegramApiMethodBody getBody() {
|
||||
TelegramApiMethodBody body = new TelegramApiMethodBody();
|
||||
body.add("chat_id", chatId);
|
||||
return body;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
package hdvtdev.telegram.core.methods;
|
||||
|
||||
import hdvtdev.telegram.objects.ChatMember;
|
||||
import hdvtdev.telegram.core.objects.chat.ChatMember;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record GetChatMember(@NotNull String chatId, long userId) implements TelegramApiMethod<ChatMember> {
|
||||
public record GetChatMember(String chatId, long userId) implements TelegramApiMethod<ChatMember> {
|
||||
|
||||
public GetChatMember(long chatId, long userId) {
|
||||
this(String.valueOf(chatId), userId);
|
||||
@@ -22,8 +17,11 @@ public record GetChatMember(@NotNull String chatId, long userId) implements Tele
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return new FormBody.Builder().add("chat_id", chatId).add("user_id", String.valueOf(userId)).build();
|
||||
public TelegramApiMethodBody getBody() {
|
||||
TelegramApiMethodBody body = new TelegramApiMethodBody();
|
||||
body.add("chat_id", chatId);
|
||||
body.add("user_id", String.valueOf(userId));
|
||||
return body;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
package hdvtdev.telegram.core.methods;
|
||||
|
||||
import hdvtdev.telegram.objects.TelegramFile;
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
import hdvtdev.telegram.core.objects.media.TelegramFile;
|
||||
|
||||
public record GetFile(String fileId) implements TelegramApiMethod<TelegramFile> {
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return new FormBody.Builder().add("file_id", fileId).build();
|
||||
public TelegramApiMethodBody getBody() {
|
||||
TelegramApiMethodBody body = new TelegramApiMethodBody();
|
||||
body.add("file_id", fileId);
|
||||
return body;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
package hdvtdev.telegram.core.methods;
|
||||
|
||||
import hdvtdev.telegram.objects.User;
|
||||
import okhttp3.RequestBody;
|
||||
import hdvtdev.telegram.core.objects.User;
|
||||
|
||||
public final class GetMe implements TelegramApiMethod<User.Bot> {
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
public TelegramApiMethodBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,25 +1,21 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
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.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.objects.bot.BotCommand;
|
||||
import hdvtdev.telegram.objects.bot.BotCommandScope;
|
||||
import hdvtdev.telegram.objects.bot.BotCommandScopeDefault;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
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 bot's commands for the given scope and user language.
|
||||
* 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,
|
||||
@@ -40,7 +36,7 @@ public record GetMyCommands(
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
public TelegramApiMethodBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -55,4 +51,10 @@ public record GetMyCommands(
|
||||
public Class<BotCommand[]> getResponseClass() {
|
||||
return BotCommand[].class;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public boolean isJsonable() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
package hdvtdev.telegram.core.methods;
|
||||
|
||||
public record GetMyDescription(String languageCode) implements TelegramApiMethod<GetMyDescription.BotDescription> {
|
||||
|
||||
@@ -12,8 +7,14 @@ public record GetMyDescription(String languageCode) implements TelegramApiMethod
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return languageCode == null ? null : new FormBody.Builder().add("language_code", languageCode).build();
|
||||
public TelegramApiMethodBody getBody() {
|
||||
if (languageCode == null) {
|
||||
return null;
|
||||
} else {
|
||||
TelegramApiMethodBody body = new TelegramApiMethodBody();
|
||||
body.add("language_code", languageCode);
|
||||
return body;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -27,7 +28,7 @@ public record GetMyDescription(String languageCode) implements TelegramApiMethod
|
||||
}
|
||||
|
||||
public record BotDescription(String description) {
|
||||
@NotNull
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return description;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
package hdvtdev.telegram.core.methods;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record GetMyName(String languageCode) implements TelegramApiMethod<GetMyName.BotName> {
|
||||
@@ -11,8 +9,14 @@ public record GetMyName(String languageCode) implements TelegramApiMethod<GetMyN
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return this.languageCode == null ? null : new FormBody.Builder().add("language_code", this.languageCode).build();
|
||||
public TelegramApiMethodBody getBody() {
|
||||
if (languageCode == null) {
|
||||
return null;
|
||||
} else {
|
||||
TelegramApiMethodBody body = new TelegramApiMethodBody();
|
||||
body.add("language_code", languageCode);
|
||||
return body;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -27,9 +31,8 @@ public record GetMyName(String languageCode) implements TelegramApiMethod<GetMyN
|
||||
|
||||
public record BotName(String name) {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toString() {
|
||||
public @NotNull String toString() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
package hdvtdev.telegram.core.methods;
|
||||
|
||||
|
||||
import hdvtdev.telegram.objects.Update;
|
||||
import okhttp3.RequestBody;
|
||||
import hdvtdev.telegram.core.objects.Update;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -17,7 +15,7 @@ public record GetUpdates(
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
public TelegramApiMethodBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,28 +1,26 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
package hdvtdev.telegram.core.methods;
|
||||
|
||||
import hdvtdev.telegram.objects.ChatInviteLink;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import hdvtdev.telegram.core.objects.chat.ChatInviteLink;
|
||||
|
||||
/**
|
||||
* Use this method to revoke an invite link created by the bot. If the primary link is revoked, a new link is automatically generated.
|
||||
* The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
|
||||
* 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(@NotNull String chatId, @NotNull String link) implements TelegramApiMethod<ChatInviteLink> {
|
||||
public record RevokeChatInviteLink(String chatId, String link) implements TelegramApiMethod<ChatInviteLink> {
|
||||
|
||||
public RevokeChatInviteLink(long chatId, @NotNull String link) {
|
||||
public RevokeChatInviteLink(long chatId, String link) {
|
||||
this(String.valueOf(chatId), link);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return new FormBody.Builder().add("chat_id", chatId).add("link", link).build();
|
||||
public TelegramApiMethodBody getBody() {
|
||||
TelegramApiMethodBody body = new TelegramApiMethodBody(2);
|
||||
body.add("chat_id", chatId);
|
||||
body.add("link", link);
|
||||
return body;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
package hdvtdev.telegram.core.methods;
|
||||
|
||||
public final class SendChatAction implements TelegramApiMethod<Boolean> {
|
||||
|
||||
@@ -13,7 +7,7 @@ public final class SendChatAction implements TelegramApiMethod<Boolean> {
|
||||
private Long messageThreadId;
|
||||
private final ChatAction chatAction;
|
||||
|
||||
public SendChatAction(@Nullable String businessConnectionId, @NotNull String chatId, @Nullable Long messageThreadId, @NotNull ChatAction chatAction) {
|
||||
public SendChatAction(String businessConnectionId, String chatId, Long messageThreadId, ChatAction chatAction) {
|
||||
this.businessConnectionId = businessConnectionId;
|
||||
this.chatId = chatId;
|
||||
this.messageThreadId = messageThreadId;
|
||||
@@ -41,14 +35,13 @@ public final class SendChatAction implements TelegramApiMethod<Boolean> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
|
||||
FormBody.Builder builder = new FormBody.Builder().add("chat_id", chatId).add("action", chatAction.equals(ChatAction.UPLOAD_FILE) ? ChatAction.UPLOAD_DOCUMENT.name() : chatAction.name());
|
||||
|
||||
if (businessConnectionId != null) builder.add("business_connection_id", businessConnectionId);
|
||||
if (messageThreadId != null) builder.add("message_thread_id", String.valueOf(messageThreadId));
|
||||
|
||||
return builder.build();
|
||||
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
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
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.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.objects.Message;
|
||||
import hdvtdev.telegram.objects.ReplyMarkup;
|
||||
import hdvtdev.telegram.objects.ReplyParameters;
|
||||
import hdvtdev.telegram.core.objects.message.Message;
|
||||
import hdvtdev.telegram.core.objects.markup.ReplyMarkup;
|
||||
import hdvtdev.telegram.core.objects.ReplyParameters;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
@Jsonable
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public final class SendDice implements TelegramApiMethod<Message> {
|
||||
|
||||
@@ -92,7 +88,7 @@ public final class SendDice implements TelegramApiMethod<Message> {
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
public TelegramApiMethodBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -108,6 +104,12 @@ public final class SendDice implements TelegramApiMethod<Message> {
|
||||
return Message.class;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public boolean isJsonable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public enum Emoji {
|
||||
DICE("🎲"),
|
||||
DART("🎯"),
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
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.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.objects.*;
|
||||
import hdvtdev.telegram.util.ParseMode;
|
||||
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;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
@Jsonable
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public final class SendMessage implements TelegramApiMethod<Message> {
|
||||
|
||||
@@ -118,7 +119,7 @@ public final class SendMessage implements TelegramApiMethod<Message> {
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
public TelegramApiMethodBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -134,6 +135,12 @@ public final class SendMessage implements TelegramApiMethod<Message> {
|
||||
return Message.class;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public boolean isJsonable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private final String chatId;
|
||||
private final String text;
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
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.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.objects.ReactionType;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
import hdvtdev.telegram.core.objects.reaction.ReactionType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Jsonable
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class SetMessageReaction implements TelegramApiMethod<Boolean> {
|
||||
|
||||
@@ -51,7 +47,7 @@ public class SetMessageReaction implements TelegramApiMethod<Boolean> {
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
public TelegramApiMethodBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -67,6 +63,12 @@ public class SetMessageReaction implements TelegramApiMethod<Boolean> {
|
||||
return Boolean.class;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public boolean isJsonable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private final String chatId;
|
||||
private final long messageId;
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
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.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.objects.bot.BotCommand;
|
||||
import hdvtdev.telegram.objects.bot.BotCommandScope;
|
||||
import okhttp3.RequestBody;
|
||||
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<Boolean> {
|
||||
|
||||
@@ -53,7 +50,7 @@ public final class SetMyCommands implements TelegramApiMethod<Boolean> {
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
public TelegramApiMethodBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -69,6 +66,12 @@ public final class SetMyCommands implements TelegramApiMethod<Boolean> {
|
||||
return Boolean.class;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public boolean isJsonable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public static final class Builder {
|
||||
private final List<BotCommand> commands;
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
package hdvtdev.telegram.core.methods;
|
||||
|
||||
/**
|
||||
* Use this method to change the bot's description, which is shown in the chat with the bot if the chat is empty.
|
||||
* 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 bot description; 0-512 characters. Pass an empty string to remove the dedicated description for the given language.
|
||||
* @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<Boolean> {
|
||||
@@ -20,13 +17,15 @@ public record SetMyDescription(String description, String languageCode) implemen
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
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;
|
||||
}
|
||||
FormBody.Builder builder = new FormBody.Builder().add("description", description);
|
||||
if (languageCode != null) builder.add("language_code", languageCode);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
package hdvtdev.telegram.core.methods;
|
||||
|
||||
public record SetMyName(String name, String languageCode) implements TelegramApiMethod<Boolean> {
|
||||
|
||||
@@ -10,10 +7,11 @@ public record SetMyName(String name, String languageCode) implements TelegramApi
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
FormBody.Builder builder = new FormBody.Builder().add("name", this.name);
|
||||
if (languageCode != null) builder.add("language_code", this.languageCode);
|
||||
return builder.build();
|
||||
public TelegramApiMethodBody getBody() {
|
||||
TelegramApiMethodBody body = new TelegramApiMethodBody(2);
|
||||
body.add("name", this.name);
|
||||
body.add("language_code", this.languageCode);
|
||||
return body;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
package hdvtdev.telegram.core.methods;
|
||||
|
||||
public interface TelegramApiMethod<T> {
|
||||
|
||||
RequestBody getBody();
|
||||
TelegramApiMethodBody getBody();
|
||||
|
||||
String getMethodName();
|
||||
|
||||
Class<T> getResponseClass();
|
||||
|
||||
default boolean isJsonable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package hdvtdev.telegram.core.bot;
|
||||
package hdvtdev.telegram.core.methods;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public final class TelegramApiMethodBody {
|
||||
|
||||
@@ -19,8 +18,12 @@ public final class TelegramApiMethodBody {
|
||||
if (value != null) this.elements.add(new Element(name, value));
|
||||
}
|
||||
|
||||
public void forEach(Consumer<? super Element> action) {
|
||||
this.elements.forEach(action);
|
||||
public int size() {
|
||||
return this.elements.size();
|
||||
}
|
||||
|
||||
public Element get(int i) {
|
||||
return this.elements.get(i);
|
||||
}
|
||||
|
||||
public record Element(String name, String value) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package hdvtdev.telegram.core;
|
||||
package hdvtdev.telegram.core.methods.util;
|
||||
|
||||
public enum ParseMode {
|
||||
MARKDOWN,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package hdvtdev.telegram.core;
|
||||
package hdvtdev.telegram.core.methods.util;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileWriter;
|
||||
|
||||
@@ -1,113 +0,0 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
import hdvtdev.telegram.objects.Game;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
/**
|
||||
* Use this method to send answers to callback queries sent from inline keyboards.
|
||||
* The answer will be displayed to the user as a notification at the top of the chat screen or as an alert.
|
||||
* Alternatively, the user can be redirected to the specified {@link Game} URL.
|
||||
* For this option to work, you must first create a game for your bot via @BotFather and accept the terms. Otherwise, you may use links like t.me/your_bot?start=XXXX that open your bot with a parameter.
|
||||
* @apiNote On success, {@code Boolean == true} is returned.
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
@NotTested
|
||||
public class AnswerCallbackQuery implements TelegramApiMethod<Boolean> {
|
||||
|
||||
/**
|
||||
* Unique identifier for the query to be answered
|
||||
*/
|
||||
private final String callbackQueryId;
|
||||
/**
|
||||
* Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters
|
||||
*/
|
||||
private String text;
|
||||
/**
|
||||
* If True, an alert will be shown by the client instead of a notification at the top of the chat screen. Defaults to false.
|
||||
*/
|
||||
private Boolean showAlert;
|
||||
/**
|
||||
* URL that will be opened by the user's client.
|
||||
* If you have created a {@link Game} and accepted the conditions via @BotFather, specify the URL that opens your game.
|
||||
* Otherwise, you may use links like t.me/your_bot?start=XXXX that open your bot with a parameter.
|
||||
* @apiNote this will only work if the query comes from a callback_game button.
|
||||
*/
|
||||
private String url;
|
||||
/**
|
||||
* The maximum amount of time in seconds that the result of the callback query may be cached client-side.
|
||||
* Telegram apps will support caching starting in version 3.14. Defaults to 0.
|
||||
*/
|
||||
private Integer cacheTime;
|
||||
|
||||
public AnswerCallbackQuery(String callbackQueryId) {
|
||||
this.callbackQueryId = callbackQueryId;
|
||||
}
|
||||
|
||||
private AnswerCallbackQuery(Builder builder) {
|
||||
callbackQueryId = builder.callbackQueryId;
|
||||
text = builder.text;
|
||||
showAlert = builder.showAlert;
|
||||
url = builder.url;
|
||||
cacheTime = builder.cacheTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
FormBody.Builder builder = new FormBody.Builder().add("callback_query_id", this.callbackQueryId);
|
||||
if (text != null) builder.add("text", this.text);
|
||||
if (showAlert != null) builder.add("show_alert", String.valueOf(this.showAlert));
|
||||
if (url != null) builder.add("url", this.url);
|
||||
if (cacheTime != null) builder.add("cache_time", String.valueOf(this.cacheTime));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "answerCallbackQuery";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Boolean> getResponseClass() {
|
||||
return Boolean.class;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private final String callbackQueryId;
|
||||
private String text;
|
||||
private Boolean showAlert;
|
||||
private String url;
|
||||
private Integer cacheTime;
|
||||
|
||||
public Builder(String callbackQueryId) {
|
||||
this.callbackQueryId = callbackQueryId;
|
||||
}
|
||||
|
||||
public Builder text(String text) {
|
||||
this.text = text;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder showAlert(Boolean showAlert) {
|
||||
this.showAlert = showAlert;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder url(String url) {
|
||||
this.url = url;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder cacheTime(Integer cacheTime) {
|
||||
this.cacheTime = cacheTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AnswerCallbackQuery build() {
|
||||
return new AnswerCallbackQuery(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
import hdvtdev.telegram.objects.ChatAdministratorRights;
|
||||
import hdvtdev.telegram.objects.Chat;
|
||||
import hdvtdev.telegram.objects.User;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Use this method to approve a chat join request.
|
||||
* The bot must be an <u>administrator</u> in the chat for this to work and must have the {@link ChatAdministratorRights#canInviteUsers()} administrator right.
|
||||
* Returns True on success.
|
||||
* @param chatId Unique username of the target channel in the format @channelusername
|
||||
* @param userId Unique identifier of the target user
|
||||
* @see ChatAdministratorRights
|
||||
* @see Chat
|
||||
* @see Chat#id()
|
||||
* @since 0.1.0
|
||||
*/
|
||||
@NotTested
|
||||
public record ApproveChatJoinRequest(@NotNull String chatId, long userId) implements TelegramApiMethod<Boolean> {
|
||||
|
||||
/**
|
||||
* @param chatId Unique identifier for the target chat
|
||||
* @param userId Unique identifier of the target user
|
||||
* @see User#id()
|
||||
* @see Chat#id()
|
||||
*/
|
||||
public ApproveChatJoinRequest(long chatId, long userId) {
|
||||
this(String.valueOf(chatId), userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return new FormBody.Builder().add("chat_id", chatId).add("user_id", String.valueOf(userId)).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "approveChatJoinRequest";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Boolean> getResponseClass() {
|
||||
return Boolean.class;
|
||||
}
|
||||
}
|
||||
@@ -1,110 +0,0 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
import hdvtdev.telegram.objects.ChatAdministratorRights;
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
/**
|
||||
* Use this method to ban a user in a group, a supergroup or a channel.
|
||||
* In the case of supergroups and channels, the user will not be able to return
|
||||
* to the chat on their own using invite links, etc., unless unbanned first.
|
||||
* The bot must be an administrator in the chat for this to work and must have
|
||||
* the appropriate administrator rights: {@link ChatAdministratorRights#canRestrictMembers()}. Returns True on success.
|
||||
* @see ChatAdministratorRights
|
||||
* @since 0.1.1
|
||||
*/
|
||||
@NotTested
|
||||
public final class BanChatMember implements TelegramApiMethod<Boolean> {
|
||||
|
||||
/**
|
||||
* Unique identifier for the target group or username of the target supergroup or channel (in the format @channelusername)
|
||||
*/
|
||||
private final String chatId;
|
||||
/**
|
||||
* Unique identifier of the target user
|
||||
*/
|
||||
private final long userId;
|
||||
/**
|
||||
* Date when the user will be unbanned; Unix time.
|
||||
* If user is banned for more than 366 days or less than 30 seconds from
|
||||
* the current time they are considered to be banned forever.
|
||||
* Applied for supergroups and channels only.
|
||||
*/
|
||||
private Long untilDate;
|
||||
/**
|
||||
* Pass true to delete all messages from the chat for the user that is being removed.
|
||||
* If false, the user will be able to see messages in the group that were sent before the user was removed.
|
||||
* Always True for supergroups and channels.
|
||||
*/
|
||||
private Boolean revokeMessages;
|
||||
|
||||
public BanChatMember(String chatId, long userId) {
|
||||
this.chatId = chatId;
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public BanChatMember(long chatId, long userId) {
|
||||
this.chatId = String.valueOf(chatId);
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
private BanChatMember(Builder builder) {
|
||||
chatId = builder.chatId;
|
||||
userId = builder.userId;
|
||||
setUntilDate(builder.untilDate);
|
||||
setRevokeMessages(builder.revokeMessages);
|
||||
}
|
||||
|
||||
public void setUntilDate(Long untilDate) {
|
||||
this.untilDate = untilDate;
|
||||
}
|
||||
|
||||
public void setRevokeMessages(Boolean revokeMessages) {
|
||||
this.revokeMessages = revokeMessages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
FormBody.Builder builder = new FormBody.Builder().add("chat_id", this.chatId).add("user_id", String.valueOf(userId));
|
||||
if (untilDate != null) builder.add("until_date", String.valueOf(untilDate));
|
||||
if (revokeMessages != null) builder.add("revoke_messages", String.valueOf(revokeMessages));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "banChatMember";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Boolean> getResponseClass() {
|
||||
return Boolean.class;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private final String chatId;
|
||||
private final long userId;
|
||||
private Long untilDate;
|
||||
private Boolean revokeMessages;
|
||||
|
||||
public Builder(String chatId, long userId) {
|
||||
this.chatId = chatId;
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public Builder untilDate(Long untilDate) {
|
||||
this.untilDate = untilDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder revokeMessages(Boolean revokeMessages) {
|
||||
this.revokeMessages = revokeMessages;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BanChatMember build() {
|
||||
return new BanChatMember(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Use this method to ban a channel chat in a supergroup or a channel.
|
||||
* Until the chat is unbanned, the owner of the banned chat won't be able to send messages on behalf of
|
||||
* their channels. The bot must be an administrator in the supergroup or channel for this to
|
||||
* work and must have the appropriate administrator rights. Returns True on success.
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@NotTested
|
||||
public record BanChatSenderChat(@NotNull String chatId, long userId) implements TelegramApiMethod<Boolean> {
|
||||
|
||||
public BanChatSenderChat(long chatId, long userId) {
|
||||
this(String.valueOf(chatId), userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return new FormBody.Builder().add("chat_id", chatId).add("user_id", String.valueOf(userId)).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "banChatSenderChat";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Boolean> getResponseClass() {
|
||||
return Boolean.class;
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
import hdvtdev.telegram.objects.ChatAdministratorRights;
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
/**
|
||||
* Use this method to close an open topic in a forum supergroup chat.
|
||||
* The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights,
|
||||
* unless it is the creator of the topic. Returns {@code true} on success.
|
||||
* @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
|
||||
* @param messageThreadId Unique identifier for the target message thread of the forum topic
|
||||
* @see ChatAdministratorRights#canManageTopics()
|
||||
*/
|
||||
@NotTested
|
||||
public record CloseForumTopic(String chatId, long messageThreadId) implements TelegramApiMethod<Boolean> {
|
||||
|
||||
public CloseForumTopic(long chatId, long messageThreadId) {
|
||||
this(String.valueOf(chatId), messageThreadId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return new FormBody.Builder().add("chat_id", chatId).add("message_thread_id", String.valueOf(messageThreadId)).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "closeForumTopic";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Boolean> getResponseClass() {
|
||||
return Boolean.class;
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
import hdvtdev.telegram.objects.ChatAdministratorRights;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
/**
|
||||
* Use this method to close an open 'General' topic in a forum supergroup chat.
|
||||
* The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights.
|
||||
* Returns {@code true} on success.
|
||||
* @see ChatAdministratorRights#canManageTopics()
|
||||
* @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
|
||||
*/
|
||||
@NotTested
|
||||
public record CloseGeneralForumTopic(String chatId) implements TelegramApiMethod<Boolean> {
|
||||
|
||||
public CloseGeneralForumTopic(long chatId) {
|
||||
this(String.valueOf(chatId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return new FormBody.Builder().add("chat_id", chatId).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "closeGeneralForumTopic";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Boolean> getResponseClass() {
|
||||
return Boolean.class;
|
||||
}
|
||||
}
|
||||
@@ -1,244 +0,0 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
import hdvtdev.telegram.objects.MessageEntity;
|
||||
import hdvtdev.telegram.objects.Poll;
|
||||
import hdvtdev.telegram.objects.ReplyMarkup;
|
||||
import hdvtdev.telegram.objects.ReplyParameters;
|
||||
import hdvtdev.telegram.util.ParseMode;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Use this method to copy messages of any kind.
|
||||
* Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied.
|
||||
* A quiz {@link Poll} can be copied only if the value of the field correct_option_id is known to the bot.
|
||||
* The method is analogous to the method {@link ForwardMessage}, but the copied message doesn't have a link to the original message.
|
||||
* Returns the messageId as {@link Long} of the sent message on success.
|
||||
* @see Poll#correctOptionId()
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@NotTested
|
||||
@Jsonable
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public final class CopyMessage implements TelegramApiMethod<Long> {
|
||||
|
||||
@JsonProperty("chat_id")
|
||||
private final String chatId;
|
||||
@JsonProperty("message_thread_id")
|
||||
private Long messageThreadId;
|
||||
@JsonProperty("from_chat_id")
|
||||
private final String fromChatId;
|
||||
@JsonProperty("message_id")
|
||||
private final long messageId;
|
||||
@JsonProperty("video_start_timestamp")
|
||||
private long videoStartTimestamp;
|
||||
@JsonProperty("caption")
|
||||
private String caption;
|
||||
@JsonProperty("parse_mode")
|
||||
private ParseMode parseMode;
|
||||
@JsonProperty("caption_entities")
|
||||
private List<MessageEntity> captionEntities;
|
||||
@JsonProperty("show_caption_above_media")
|
||||
private Boolean showCaptionAboveMedia;
|
||||
@JsonProperty("disable_notification")
|
||||
private Boolean disableNotification;
|
||||
@JsonProperty("protect_content")
|
||||
private Boolean protectContent;
|
||||
@JsonProperty("allow_paid_broadcast")
|
||||
private Boolean allowPaidBroadcast;
|
||||
@JsonProperty("reply_parameters")
|
||||
private ReplyParameters replyParameters;
|
||||
@JsonProperty("reply_markup")
|
||||
private ReplyMarkup replyMarkup;
|
||||
|
||||
public CopyMessage(String chatId, String fromChatId, long messageId) {
|
||||
this.chatId = chatId;
|
||||
this.fromChatId = fromChatId;
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
public CopyMessage(long chatId, String fromChatId, long messageId) {
|
||||
this(String.valueOf(chatId), fromChatId, messageId);
|
||||
}
|
||||
|
||||
public CopyMessage(long chatId, long fromChatId, long messageId) {
|
||||
this(String.valueOf(chatId), String.valueOf(fromChatId), messageId);
|
||||
}
|
||||
|
||||
public CopyMessage(String chatId, long fromChatId, long messageId) {
|
||||
this(chatId, String.valueOf(fromChatId), messageId);
|
||||
}
|
||||
|
||||
private CopyMessage(Builder builder) {
|
||||
chatId = builder.chatId;
|
||||
setMessageThreadId(builder.messageThreadId);
|
||||
fromChatId = builder.fromChatId;
|
||||
messageId = builder.messageId;
|
||||
setVideoStartTimestamp(builder.videoStartTimestamp);
|
||||
setCaption(builder.caption);
|
||||
setParseMode(builder.parseMode);
|
||||
setCaptionEntities(builder.captionEntities);
|
||||
setShowCaptionAboveMedia(builder.showCaptionAboveMedia);
|
||||
setDisableNotification(builder.disableNotification);
|
||||
setProtectContent(builder.protectContent);
|
||||
setAllowPaidBroadcast(builder.allowPaidBroadcast);
|
||||
setReplyParameters(builder.replyParameters);
|
||||
setReplyMarkup(builder.replyMarkup);
|
||||
}
|
||||
|
||||
public void setMessageThreadId(Long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
}
|
||||
|
||||
public void setVideoStartTimestamp(long videoStartTimestamp) {
|
||||
this.videoStartTimestamp = videoStartTimestamp;
|
||||
}
|
||||
|
||||
public void setCaption(String caption) {
|
||||
this.caption = caption;
|
||||
}
|
||||
|
||||
public void setParseMode(ParseMode parseMode) {
|
||||
this.parseMode = parseMode;
|
||||
}
|
||||
|
||||
public void setCaptionEntities(List<MessageEntity> captionEntities) {
|
||||
this.captionEntities = captionEntities;
|
||||
}
|
||||
|
||||
public void setShowCaptionAboveMedia(Boolean showCaptionAboveMedia) {
|
||||
this.showCaptionAboveMedia = showCaptionAboveMedia;
|
||||
}
|
||||
|
||||
public void setDisableNotification(Boolean disableNotification) {
|
||||
this.disableNotification = disableNotification;
|
||||
}
|
||||
|
||||
public void setProtectContent(Boolean protectContent) {
|
||||
this.protectContent = protectContent;
|
||||
}
|
||||
|
||||
public void setAllowPaidBroadcast(Boolean allowPaidBroadcast) {
|
||||
this.allowPaidBroadcast = allowPaidBroadcast;
|
||||
}
|
||||
|
||||
public void setReplyParameters(ReplyParameters replyParameters) {
|
||||
this.replyParameters = replyParameters;
|
||||
}
|
||||
|
||||
public void setReplyMarkup(ReplyMarkup replyMarkup) {
|
||||
this.replyMarkup = replyMarkup;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "copyMessage";
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Class<Long> getResponseClass() {
|
||||
return Long.class;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private final String chatId;
|
||||
private Long messageThreadId;
|
||||
private final String fromChatId;
|
||||
private final long messageId;
|
||||
private long videoStartTimestamp;
|
||||
private String caption;
|
||||
private ParseMode parseMode;
|
||||
private List<MessageEntity> captionEntities;
|
||||
private Boolean showCaptionAboveMedia;
|
||||
private Boolean disableNotification;
|
||||
private Boolean protectContent;
|
||||
private Boolean allowPaidBroadcast;
|
||||
private ReplyParameters replyParameters;
|
||||
private ReplyMarkup replyMarkup;
|
||||
|
||||
public Builder(String chatId, String fromChatId, long messageId) {
|
||||
this.chatId = chatId;
|
||||
this.fromChatId = fromChatId;
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
public Builder(long chatId, String fromChatId, long messageId) {
|
||||
this(String.valueOf(chatId), fromChatId, messageId);
|
||||
}
|
||||
|
||||
public Builder messageThreadId(Long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder videoStartTimestamp(long videoStartTimestamp) {
|
||||
this.videoStartTimestamp = videoStartTimestamp;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder caption(String caption) {
|
||||
this.caption = caption;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder parseMode(ParseMode parseMode) {
|
||||
this.parseMode = parseMode;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder captionEntities(List<MessageEntity> captionEntities) {
|
||||
this.captionEntities = captionEntities;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder showCaptionAboveMedia(Boolean showCaptionAboveMedia) {
|
||||
this.showCaptionAboveMedia = showCaptionAboveMedia;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder disableNotification(Boolean disableNotification) {
|
||||
this.disableNotification = disableNotification;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder protectContent(Boolean protectContent) {
|
||||
this.protectContent = protectContent;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder allowPaidBroadcast(Boolean allowPaidBroadcast) {
|
||||
this.allowPaidBroadcast = allowPaidBroadcast;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder replyParameters(ReplyParameters replyParameters) {
|
||||
this.replyParameters = replyParameters;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder replyMarkup(ReplyMarkup replyMarkup) {
|
||||
this.replyMarkup = replyMarkup;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CopyMessage build() {
|
||||
return new CopyMessage(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,181 +0,0 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.objects.Poll;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Use this method to copy messages of any kind.
|
||||
* If some of the specified messages can't be found or copied, they are skipped.
|
||||
* Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied.
|
||||
* A quiz {@link Poll} can be copied only if the value of the field correct_option_id is known to the bot.
|
||||
* The method is analogous to the method {@link ForwardMessages}, but the copied messages don't have a link to the original message.
|
||||
* Album grouping is kept for copied messages.
|
||||
* On success, an array of MessageId as {@link Long}{@code []} of the sent messages is returned.
|
||||
* @see Poll#correctOptionId()
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Jsonable
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public final class CopyMessages implements TelegramApiMethod<Long[]> {
|
||||
|
||||
@JsonProperty("chat_id")
|
||||
private final String chatId;
|
||||
@JsonProperty("message_thread_id")
|
||||
private Long messageThreadId;
|
||||
@JsonProperty("from_chat_id")
|
||||
private final String fromChatId;
|
||||
@JsonProperty("message_id")
|
||||
private final List<Long> messageIds;
|
||||
@JsonProperty("disable_notification")
|
||||
private Boolean disableNotification;
|
||||
@JsonProperty("protect_content")
|
||||
private Boolean protectContent;
|
||||
@JsonProperty("remove_caption")
|
||||
private Boolean removeCaption;
|
||||
|
||||
/**
|
||||
* @param chatId Username of the target channel (in the format @channelusername)
|
||||
* @param fromChatId Channel username in the format @channelusername for the chat where the original messages were sent
|
||||
* @param messageIds List of 1-100 identifiers of messages in the chat to copy.
|
||||
*/
|
||||
public CopyMessages(String chatId, String fromChatId, List<Long> messageIds) {
|
||||
this.chatId = chatId;
|
||||
this.fromChatId = fromChatId;
|
||||
ArrayList<Long> sortedMessageIds = new ArrayList<>(messageIds.subList(0, Math.min(messageIds.size(), 100)));
|
||||
sortedMessageIds.sort(null);
|
||||
this.messageIds = sortedMessageIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param chatId Unique identifier for the target chat
|
||||
* @param fromChatId Channel username in the format @channelusername for the chat where the original messages were sent
|
||||
* @param messageIds List of 1-100 identifiers of messages in the chat to copy.
|
||||
*/
|
||||
public CopyMessages(long chatId, String fromChatId, List<Long> messageIds) {
|
||||
this(String.valueOf(chatId), fromChatId, messageIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param chatId Unique identifier for the target chat
|
||||
* @param fromChatId Unique identifier for the chat where the original messages were sent
|
||||
* @param messageIds List of 1-100 identifiers of messages in the chat to copy.
|
||||
*/
|
||||
public CopyMessages(long chatId, long fromChatId, List<Long> messageIds) {
|
||||
this(String.valueOf(chatId), String.valueOf(fromChatId), messageIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param chatId Channel username in the format @channelusername for the chat where the original messages were sent
|
||||
* @param fromChatId Unique identifier for the target chat
|
||||
* @param messageIds List of 1-100 identifiers of messages in the chat to copy.
|
||||
*/
|
||||
public CopyMessages(String chatId, long fromChatId, List<Long> messageIds) {
|
||||
this(chatId, String.valueOf(fromChatId), messageIds);
|
||||
}
|
||||
|
||||
private CopyMessages(Builder builder) {
|
||||
chatId = builder.chatId;
|
||||
setMessageThreadId(builder.messageThreadId);
|
||||
fromChatId = builder.fromChatId;
|
||||
messageIds = builder.messageIds;
|
||||
setDisableNotification(builder.disableNotification);
|
||||
setProtectContent(builder.protectContent);
|
||||
setRemoveCaption(builder.removeCaption);
|
||||
}
|
||||
|
||||
public void setMessageThreadId(Long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
}
|
||||
|
||||
public void setDisableNotification(Boolean disableNotification) {
|
||||
this.disableNotification = disableNotification;
|
||||
}
|
||||
|
||||
public void setProtectContent(Boolean protectContent) {
|
||||
this.protectContent = protectContent;
|
||||
}
|
||||
|
||||
public void setRemoveCaption(Boolean removeCaption) {
|
||||
this.removeCaption = removeCaption;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "copyMessages";
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Class<Long[]> getResponseClass() {
|
||||
return Long[].class;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private final String chatId;
|
||||
private Long messageThreadId;
|
||||
private final String fromChatId;
|
||||
private final List<Long> messageIds;
|
||||
private Boolean disableNotification;
|
||||
private Boolean protectContent;
|
||||
private Boolean removeCaption;
|
||||
|
||||
public Builder(String chatId, String fromChatId, List<Long> messageIds) {
|
||||
this.chatId = chatId;
|
||||
this.fromChatId = fromChatId;
|
||||
ArrayList<Long> sortedMessageIds = new ArrayList<>(messageIds.subList(0, Math.min(messageIds.size(), 100)));
|
||||
sortedMessageIds.sort(null);
|
||||
this.messageIds = sortedMessageIds;
|
||||
}
|
||||
public Builder(long chatId, String fromChatId, List<Long> messageIds) {
|
||||
this(String.valueOf(chatId), fromChatId, messageIds);
|
||||
}
|
||||
|
||||
public Builder(long chatId, long fromChatId, List<Long> messageIds) {
|
||||
this(String.valueOf(chatId), String.valueOf(fromChatId), messageIds);
|
||||
}
|
||||
|
||||
public Builder(String chatId, long fromChatId, List<Long> messageIds) {
|
||||
this(chatId, String.valueOf(fromChatId), messageIds);
|
||||
}
|
||||
|
||||
public Builder messageThreadId(Long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder disableNotification(Boolean disableNotification) {
|
||||
this.disableNotification = disableNotification;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder protectContent(Boolean protectContent) {
|
||||
this.protectContent = protectContent;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder removeCaption(Boolean removeCaption) {
|
||||
this.removeCaption = removeCaption;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CopyMessages build() {
|
||||
return new CopyMessages(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.objects.ChatAdministratorRights;
|
||||
import hdvtdev.telegram.objects.ChatInviteLink;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
/**
|
||||
* Use this method to create an additional invite link for a chat.
|
||||
* The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
|
||||
* The link can be revoked using the method {@link RevokeChatInviteLink}. Returns the new invite link as {@link ChatInviteLink} object.
|
||||
* @see ChatAdministratorRights#canInviteUsers()
|
||||
*/
|
||||
public final class CreateChatInviteLink implements TelegramApiMethod<ChatInviteLink> {
|
||||
|
||||
private final String chatId;
|
||||
private String name;
|
||||
private Long expireDate;
|
||||
private Integer memberLimit;
|
||||
private Boolean createsJoinRequest;
|
||||
|
||||
public CreateChatInviteLink(String chatId) {
|
||||
this.chatId = chatId;
|
||||
}
|
||||
|
||||
public CreateChatInviteLink(long chatId) {
|
||||
this(String.valueOf(chatId));
|
||||
}
|
||||
|
||||
private CreateChatInviteLink(Builder builder) {
|
||||
chatId = builder.chatId;
|
||||
setName(builder.name);
|
||||
setExpireDate(builder.expireDate);
|
||||
setMemberLimit(builder.memberLimit);
|
||||
setCreatesJoinRequest(builder.createsJoinRequest);
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setExpireDate(Long expireDate) {
|
||||
this.expireDate = expireDate;
|
||||
}
|
||||
|
||||
public void setMemberLimit(Integer memberLimit) {
|
||||
this.memberLimit = memberLimit;
|
||||
}
|
||||
|
||||
public void setCreatesJoinRequest(Boolean createsJoinRequest) {
|
||||
this.createsJoinRequest = createsJoinRequest;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
FormBody.Builder builder = new FormBody.Builder().add("chat_id", chatId);
|
||||
if (expireDate != null) builder.add("expire_date", String.valueOf(expireDate));
|
||||
if (memberLimit != null) builder.add("member_limit", String.valueOf(memberLimit));
|
||||
if (createsJoinRequest != null) builder.add("creates_join_request", String.valueOf(createsJoinRequest));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "createChatInviteLink";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<ChatInviteLink> getResponseClass() {
|
||||
return ChatInviteLink.class;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private final String chatId;
|
||||
private String name;
|
||||
private Long expireDate;
|
||||
private Integer memberLimit;
|
||||
private Boolean createsJoinRequest;
|
||||
|
||||
public Builder(String chatId) {
|
||||
this.chatId = chatId;
|
||||
}
|
||||
|
||||
public Builder(long chatId) {
|
||||
this(String.valueOf(chatId));
|
||||
}
|
||||
|
||||
public Builder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder expireDate(Long expireDate) {
|
||||
this.expireDate = expireDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder memberLimit(Integer memberLimit) {
|
||||
this.memberLimit = memberLimit;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder createsJoinRequest(Boolean createsJoinRequest) {
|
||||
this.createsJoinRequest = createsJoinRequest;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CreateChatInviteLink build() {
|
||||
return new CreateChatInviteLink(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.objects.Message;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
/**
|
||||
* Use this method to forward messages of any kind.
|
||||
* Service messages and messages with protected content can't be forwarded.
|
||||
* On success, the sent {@link Message} is returned.
|
||||
*/
|
||||
@Jsonable
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public final class ForwardMessage implements TelegramApiMethod<Message> {
|
||||
|
||||
@JsonProperty("chat_id")
|
||||
private final String chatId;
|
||||
@JsonProperty("message_thread_id")
|
||||
private Long messageThreadId;
|
||||
@JsonProperty("from_chat_id")
|
||||
private final String fromChatId;
|
||||
@JsonProperty("message_id")
|
||||
private final long messageId;
|
||||
@JsonProperty("disable_notification")
|
||||
private Boolean disableNotification;
|
||||
@JsonProperty("protect_content")
|
||||
private Boolean protectContent;
|
||||
@JsonProperty("video_start_timestamp")
|
||||
private long videoStartTimestamp;
|
||||
|
||||
public ForwardMessage(String chatId, String fromChatId, long messageId) {
|
||||
this.chatId = chatId;
|
||||
this.fromChatId = fromChatId;
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
public ForwardMessage(long chatId, String fromChatId, long messageId) {
|
||||
this(String.valueOf(chatId), fromChatId, messageId);
|
||||
}
|
||||
|
||||
public ForwardMessage(long chatId, long fromChatId, long messageId) {
|
||||
this(String.valueOf(chatId), String.valueOf(fromChatId), messageId);
|
||||
}
|
||||
|
||||
private ForwardMessage(Builder builder) {
|
||||
chatId = builder.chatId;
|
||||
setMessageThreadId(builder.messageThreadId);
|
||||
fromChatId = builder.fromChatId;
|
||||
messageId = builder.messageId;
|
||||
setDisableNotification(builder.disableNotification);
|
||||
setProtectContent(builder.protectContent);
|
||||
setVideoStartTimestamp(builder.videoStartTimestamp);
|
||||
}
|
||||
|
||||
public void setMessageThreadId(Long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
}
|
||||
|
||||
public void setDisableNotification(Boolean disableNotification) {
|
||||
this.disableNotification = disableNotification;
|
||||
}
|
||||
|
||||
public void setProtectContent(Boolean protectContent) {
|
||||
this.protectContent = protectContent;
|
||||
}
|
||||
|
||||
public void setVideoStartTimestamp(long videoStartTimestamp) {
|
||||
this.videoStartTimestamp = videoStartTimestamp;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "forwardMessage";
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Class<Message> getResponseClass() {
|
||||
return Message.class;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private final String chatId;
|
||||
private Long messageThreadId;
|
||||
private final String fromChatId;
|
||||
private final long messageId;
|
||||
private Boolean disableNotification;
|
||||
private Boolean protectContent;
|
||||
private long videoStartTimestamp;
|
||||
|
||||
public Builder(String chatId, String fromChatId, long messageId) {
|
||||
this.chatId = chatId;
|
||||
this.fromChatId = fromChatId;
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
public Builder messageThreadId(Long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder disableNotification(Boolean disableNotification) {
|
||||
this.disableNotification = disableNotification;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder protectContent(Boolean protectContent) {
|
||||
this.protectContent = protectContent;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder videoStartTimestamp(long videoStartTimestamp) {
|
||||
this.videoStartTimestamp = videoStartTimestamp;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ForwardMessage build() {
|
||||
return new ForwardMessage(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,147 +0,0 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import hdvtdev.telegram.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
import hdvtdev.telegram.objects.Message;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Use this method to forward multiple messages of any kind. If some of the specified messages can't be found or forwarded, they are skipped.
|
||||
* Service messages and messages with protected content can't be forwarded. Album grouping is kept for forwarded messages.
|
||||
* On success, an array of MessageId as {@link Long} of the sent messages is returned.
|
||||
* @see Message#hasProtectedContent()
|
||||
*/
|
||||
@Jsonable
|
||||
@NotTested
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public final class ForwardMessages implements TelegramApiMethod<Long[]> {
|
||||
|
||||
@JsonProperty("chat_id")
|
||||
private final String chatId;
|
||||
@JsonProperty("message_thread_id")
|
||||
private Long messageThreadId;
|
||||
@JsonProperty("from_chat_id")
|
||||
private final String fromChatId;
|
||||
@JsonProperty("message_id")
|
||||
private final List<Long> messageIds;
|
||||
@JsonProperty("disable_notification")
|
||||
private Boolean disableNotification;
|
||||
@JsonProperty("protect_content")
|
||||
private Boolean protectContent;
|
||||
|
||||
public ForwardMessages(String chatId, String fromChatId, List<Long> messageIds) {
|
||||
ArrayList<Long> sortedMessageIds = new ArrayList<>(messageIds.size() > 100 ? messageIds.subList(0, 100) : messageIds);
|
||||
sortedMessageIds.sort(null);
|
||||
this.chatId = chatId;
|
||||
this.fromChatId = fromChatId;
|
||||
this.messageIds = sortedMessageIds;
|
||||
}
|
||||
|
||||
public ForwardMessages(long chatId, String fromChatId, List<Long> messageIds) {
|
||||
this(String.valueOf(chatId), fromChatId, messageIds);
|
||||
}
|
||||
|
||||
public ForwardMessages(String chatId, long fromChatId, List<Long> messageIds) {
|
||||
this(chatId, String.valueOf(fromChatId), messageIds);
|
||||
}
|
||||
|
||||
public ForwardMessages(long chatId, long fromChatId, List<Long> messageIds) {
|
||||
this(String.valueOf(chatId), String.valueOf(fromChatId), messageIds);
|
||||
}
|
||||
|
||||
private ForwardMessages(Builder builder) {
|
||||
chatId = builder.chatId;
|
||||
messageThreadId = builder.messageThreadId;
|
||||
fromChatId = builder.fromChatId;
|
||||
messageIds = builder.messageIds;
|
||||
disableNotification = builder.disableNotification;
|
||||
protectContent = builder.protectContent;
|
||||
}
|
||||
|
||||
public void setMessageThreadId(long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
}
|
||||
|
||||
public void setDisableNotification(boolean disableNotification) {
|
||||
this.disableNotification = disableNotification;
|
||||
}
|
||||
|
||||
public void setProtectContent(boolean protectContent) {
|
||||
this.protectContent = protectContent;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "forwardMessages";
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Class<Long[]> getResponseClass() {
|
||||
return Long[].class;
|
||||
}
|
||||
|
||||
|
||||
public static final class Builder {
|
||||
private final String chatId;
|
||||
private Long messageThreadId;
|
||||
private final String fromChatId;
|
||||
private final List<Long> messageIds;
|
||||
private Boolean disableNotification;
|
||||
private Boolean protectContent;
|
||||
|
||||
public Builder(String chatId, String fromChatId, List<Long> messageIds) {
|
||||
ArrayList<Long> sortedMessageIds = new ArrayList<>(messageIds.size() > 100 ? messageIds.subList(0, 100) : messageIds);
|
||||
sortedMessageIds.sort(null);
|
||||
this.chatId = chatId;
|
||||
this.fromChatId = fromChatId;
|
||||
this.messageIds = sortedMessageIds;
|
||||
}
|
||||
|
||||
public Builder(long chatId, String fromChatId, List<Long> messageIds) {
|
||||
this(String.valueOf(chatId), fromChatId, messageIds);
|
||||
}
|
||||
|
||||
public Builder(String chatId, long fromChatId, List<Long> messageIds) {
|
||||
this(chatId, String.valueOf(fromChatId), messageIds);
|
||||
}
|
||||
|
||||
public Builder(long chatId, long fromChatId, List<Long> messageIds) {
|
||||
this(String.valueOf(chatId), String.valueOf(fromChatId), messageIds);
|
||||
}
|
||||
|
||||
public Builder messageThreadId(long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder disableNotification(boolean disableNotification) {
|
||||
this.disableNotification = disableNotification;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder protectContent(boolean protectContent) {
|
||||
this.protectContent = protectContent;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ForwardMessages build() {
|
||||
return new ForwardMessages(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,9 @@ 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)
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.NotTested;
|
||||
import hdvtdev.telegram.objects.ChatMember;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Use this method to get a list of administrators in a chat, which aren't bots. Returns an Array of {@link ChatMember} objects.
|
||||
* @param chatId
|
||||
*/
|
||||
@NotTested
|
||||
public record GetChatAdministrators(@NotNull String chatId) implements TelegramApiMethod<ChatMember[]> {
|
||||
|
||||
public GetChatAdministrators(long chatId) {
|
||||
this(String.valueOf(chatId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return new FormBody.Builder().add("chat_id", chatId).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "getChatAdministrators";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<ChatMember[]> getResponseClass() {
|
||||
return ChatMember[].class;
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.objects.ChatMember;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record GetChatMember(@NotNull String chatId, long userId) implements TelegramApiMethod<ChatMember> {
|
||||
|
||||
public GetChatMember(long chatId, long userId) {
|
||||
this(String.valueOf(chatId), userId);
|
||||
}
|
||||
|
||||
public GetChatMember(String chatId, String userId) {
|
||||
this(chatId, Long.parseLong(userId));
|
||||
}
|
||||
|
||||
public GetChatMember(long chatId, String userId) {
|
||||
this(String.valueOf(chatId), userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return new FormBody.Builder().add("chat_id", chatId).add("user_id", String.valueOf(userId)).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "getChatMember";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<ChatMember> getResponseClass() {
|
||||
return ChatMember.class;
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.objects.TelegramFile;
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
public record GetFile(String fileId) implements TelegramApiMethod<TelegramFile> {
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return new FormBody.Builder().add("file_id", fileId).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "getFile";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<TelegramFile> getResponseClass() {
|
||||
return TelegramFile.class;
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.objects.User;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
public final class GetMe implements TelegramApiMethod<User.Bot> {
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "getMe";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<User.Bot> getResponseClass() {
|
||||
return User.Bot.class;
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.objects.bot.BotCommand;
|
||||
import hdvtdev.telegram.objects.bot.BotCommandScope;
|
||||
import hdvtdev.telegram.objects.bot.BotCommandScopeDefault;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
/**
|
||||
* Use this method to get the current list of the bot's commands for the given scope and user language.
|
||||
* Returns an Array of {@link BotCommand} objects. If commands aren't set, an empty list is returned.
|
||||
* @param scope Scope of users. Defaults to {@link BotCommandScopeDefault}.
|
||||
* @param languageCode A two-letter ISO 639-1 language code or an empty string
|
||||
* @see BotCommandScope
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Jsonable
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public record GetMyCommands(
|
||||
@JsonProperty("scope") BotCommandScope scope,
|
||||
@JsonProperty("language_code") String languageCode
|
||||
) implements TelegramApiMethod<BotCommand[]> {
|
||||
|
||||
public GetMyCommands() {
|
||||
this(null, null);
|
||||
}
|
||||
|
||||
public GetMyCommands(String languageCode) {
|
||||
this(null, languageCode);
|
||||
}
|
||||
|
||||
public GetMyCommands(BotCommandScope scope) {
|
||||
this(scope, null);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "getMyCommands";
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Class<BotCommand[]> getResponseClass() {
|
||||
return BotCommand[].class;
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record GetMyDescription(String languageCode) implements TelegramApiMethod<GetMyDescription.BotDescription> {
|
||||
|
||||
public GetMyDescription() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return languageCode == null ? null : new FormBody.Builder().add("language_code", languageCode).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "getMyDescription";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<BotDescription> getResponseClass() {
|
||||
return BotDescription.class;
|
||||
}
|
||||
|
||||
public record BotDescription(String description) {
|
||||
@NotNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return description.isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record GetMyName(String languageCode) implements TelegramApiMethod<GetMyName.BotName> {
|
||||
|
||||
public GetMyName() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return this.languageCode == null ? null : new FormBody.Builder().add("language_code", this.languageCode).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "getMyName";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<BotName> getResponseClass() {
|
||||
return BotName.class;
|
||||
}
|
||||
|
||||
public record BotName(String name) {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
|
||||
import hdvtdev.telegram.objects.Update;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public record GetUpdates(
|
||||
Long offset,
|
||||
Integer limit,
|
||||
Integer timeout
|
||||
) implements TelegramApiMethod<Update[]> {
|
||||
|
||||
public GetUpdates() {
|
||||
this(null, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
ArrayList<String> params = new ArrayList<>(3);
|
||||
if (offset != null) params.add("offset=" + offset);
|
||||
if (limit != null) params.add("limit=" + limit);
|
||||
if (timeout != null) params.add("timeout=" + timeout);
|
||||
|
||||
if (params.isEmpty()) {
|
||||
return "getUpdates";
|
||||
} else {
|
||||
return "getUpdates?" + String.join("&", params);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Update[]> getResponseClass() {
|
||||
return Update[].class;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ 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)
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import hdvtdev.telegram.objects.ChatInviteLink;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Use this method to revoke an invite link created by the bot. If the primary link is revoked, a new link is automatically generated.
|
||||
* The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
|
||||
* Returns the revoked invite link as {@link ChatInviteLink} object.
|
||||
* @param chatId Unique identifier of the target chat or username of the target channel (in the format @channelusername)
|
||||
* @param link The invite link to revoke
|
||||
*/
|
||||
public record RevokeChatInviteLink(@NotNull String chatId, @NotNull String link) implements TelegramApiMethod<ChatInviteLink> {
|
||||
|
||||
public RevokeChatInviteLink(long chatId, @NotNull String link) {
|
||||
this(String.valueOf(chatId), link);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return new FormBody.Builder().add("chat_id", chatId).add("link", link).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "revokeChatInviteLink";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<ChatInviteLink> getResponseClass() {
|
||||
return ChatInviteLink.class;
|
||||
}
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public final class SendChatAction implements TelegramApiMethod<Boolean> {
|
||||
|
||||
private String businessConnectionId;
|
||||
private final String chatId;
|
||||
private Long messageThreadId;
|
||||
private final ChatAction chatAction;
|
||||
|
||||
public SendChatAction(@Nullable String businessConnectionId, @NotNull String chatId, @Nullable Long messageThreadId, @NotNull ChatAction chatAction) {
|
||||
this.businessConnectionId = businessConnectionId;
|
||||
this.chatId = chatId;
|
||||
this.messageThreadId = messageThreadId;
|
||||
this.chatAction = chatAction;
|
||||
}
|
||||
|
||||
public SendChatAction(String chatId, ChatAction chatAction) {
|
||||
this(null, chatId, null, chatAction);
|
||||
}
|
||||
|
||||
public SendChatAction(long chatId, ChatAction chatAction) {
|
||||
this(String.valueOf(chatId), chatAction);
|
||||
}
|
||||
|
||||
private SendChatAction(Builder builder) {
|
||||
this(builder.businessConnectionId, builder.chatId, builder.messageThreadId, builder.chatAction);
|
||||
}
|
||||
|
||||
public void setBusinessConnectionId(String businessConnectionId) {
|
||||
this.businessConnectionId = businessConnectionId;
|
||||
}
|
||||
|
||||
public void setMessageThreadId(Long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
|
||||
FormBody.Builder builder = new FormBody.Builder().add("chat_id", chatId).add("action", chatAction.equals(ChatAction.UPLOAD_FILE) ? ChatAction.UPLOAD_DOCUMENT.name() : chatAction.name());
|
||||
|
||||
if (businessConnectionId != null) builder.add("business_connection_id", businessConnectionId);
|
||||
if (messageThreadId != null) builder.add("message_thread_id", String.valueOf(messageThreadId));
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "sendChatAction";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Boolean> getResponseClass() {
|
||||
return Boolean.class;
|
||||
}
|
||||
|
||||
public enum ChatAction {
|
||||
TYPING,
|
||||
UPLOAD_PHOTO,
|
||||
RECORD_VIDEO,
|
||||
UPLOAD_VIDEO,
|
||||
RECORD_VOICE,
|
||||
UPLOAD_VOICE,
|
||||
UPLOAD_DOCUMENT,
|
||||
UPLOAD_FILE,
|
||||
CHOOSE_STICKER,
|
||||
FIND_LOCATION,
|
||||
RECORD_VIDEO_NOTE,
|
||||
UPLOAD_VIDEO_NOTE
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private String businessConnectionId;
|
||||
private final String chatId;
|
||||
private Long messageThreadId;
|
||||
private final ChatAction chatAction;
|
||||
|
||||
public Builder(String chatId, ChatAction chatAction) {
|
||||
this.chatId = chatId;
|
||||
this.chatAction = chatAction;
|
||||
}
|
||||
|
||||
public Builder businessConnectionId(String businessConnectionId) {
|
||||
this.businessConnectionId = businessConnectionId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder messageThreadId(Long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SendChatAction build() {
|
||||
return new SendChatAction(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.objects.Message;
|
||||
import hdvtdev.telegram.objects.ReplyMarkup;
|
||||
import hdvtdev.telegram.objects.ReplyParameters;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
@Jsonable
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public final class SendDice implements TelegramApiMethod<Message> {
|
||||
|
||||
@JsonProperty("chat_id")
|
||||
private final String chatId;
|
||||
@JsonProperty("business_connection_id")
|
||||
private String businessConnectionId;
|
||||
@JsonProperty("message_thread_id")
|
||||
private Long messageThreadId;
|
||||
@JsonProperty("emoji")
|
||||
private String emoji;
|
||||
@JsonProperty("disable_notification")
|
||||
private Boolean disableNotification;
|
||||
@JsonProperty("protect_content")
|
||||
private Boolean protectContent;
|
||||
@JsonProperty("allow_paid_broadcast")
|
||||
private Boolean allowPaidBroadcast;
|
||||
@JsonProperty("message_effect_id")
|
||||
private String messageEffectId;
|
||||
@JsonProperty("reply_parameters")
|
||||
private ReplyParameters replyParameters;
|
||||
@JsonProperty("reply_markup")
|
||||
private ReplyMarkup replyMarkup;
|
||||
|
||||
public SendDice(String chatId) {
|
||||
this.chatId = chatId;
|
||||
}
|
||||
|
||||
public SendDice(long chatId) {
|
||||
this(String.valueOf(chatId));
|
||||
}
|
||||
|
||||
public SendDice(String chatId, Emoji emoji) {
|
||||
this.emoji = emoji.getEmoji();
|
||||
this.chatId = chatId;
|
||||
}
|
||||
|
||||
public SendDice(long chatId, Emoji emoji) {
|
||||
this(String.valueOf(chatId), emoji);
|
||||
}
|
||||
|
||||
|
||||
public void setBusinessConnectionId(String businessConnectionId) {
|
||||
this.businessConnectionId = businessConnectionId;
|
||||
}
|
||||
|
||||
public void setMessageThreadId(Long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
}
|
||||
|
||||
public void setEmoji(Emoji emoji) {
|
||||
this.emoji = emoji.getEmoji();
|
||||
}
|
||||
|
||||
public void setDisableNotification(Boolean disableNotification) {
|
||||
this.disableNotification = disableNotification;
|
||||
}
|
||||
|
||||
public void setProtectContent(Boolean protectContent) {
|
||||
this.protectContent = protectContent;
|
||||
}
|
||||
|
||||
public void setAllowPaidBroadcast(Boolean allowPaidBroadcast) {
|
||||
this.allowPaidBroadcast = allowPaidBroadcast;
|
||||
}
|
||||
|
||||
public void setMessageEffectId(String messageEffectId) {
|
||||
this.messageEffectId = messageEffectId;
|
||||
}
|
||||
|
||||
public void setReplyParameters(ReplyParameters replyParameters) {
|
||||
this.replyParameters = replyParameters;
|
||||
}
|
||||
|
||||
public void setReplyMarkup(ReplyMarkup replyMarkup) {
|
||||
this.replyMarkup = replyMarkup;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "sendDice";
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Class<Message> getResponseClass() {
|
||||
return Message.class;
|
||||
}
|
||||
|
||||
public enum Emoji {
|
||||
DICE("🎲"),
|
||||
DART("🎯"),
|
||||
BASKETBALL("🏀"),
|
||||
FOOTBALL("⚽"),
|
||||
BOWLING("🎳"),
|
||||
SLOT_MACHINE("🎰");
|
||||
|
||||
private final String emoji;
|
||||
|
||||
Emoji(String emoji) {
|
||||
this.emoji = emoji;
|
||||
}
|
||||
|
||||
public String getEmoji() {
|
||||
return emoji;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,226 +0,0 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.objects.*;
|
||||
import hdvtdev.telegram.util.ParseMode;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
@Jsonable
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public final class SendMessage implements TelegramApiMethod<Message> {
|
||||
|
||||
@JsonProperty("chat_id")
|
||||
private final String chatId;
|
||||
@JsonProperty("text")
|
||||
private final String text;
|
||||
@JsonProperty("business_connection_id")
|
||||
private String businessConnectionId;
|
||||
@JsonProperty("message_thread_id")
|
||||
private Long messageThreadId;
|
||||
@JsonProperty("parse_mode")
|
||||
private ParseMode parseMode;
|
||||
@JsonProperty("entities")
|
||||
private MessageEntity[] entities;
|
||||
@JsonProperty("link_preview_options")
|
||||
private LinkPreviewOptions linkPreviewOptions;
|
||||
@JsonProperty("disable_notification")
|
||||
private Boolean disableNotification;
|
||||
@JsonProperty("protect_content")
|
||||
private Boolean protectContent;
|
||||
@JsonProperty("allow_paid_broadcast")
|
||||
private Boolean allowPaidBroadcast;
|
||||
@JsonProperty("message_effect_id")
|
||||
private String messageEffectId;
|
||||
@JsonProperty("reply_parameters")
|
||||
private ReplyParameters replyParameters;
|
||||
@JsonProperty("reply_markup")
|
||||
private ReplyMarkup replyMarkup;
|
||||
|
||||
private SendMessage(Builder builder) {
|
||||
chatId = builder.chatId;
|
||||
text = builder.text;
|
||||
setBusinessConnectionId(builder.businessConnectionId);
|
||||
setMessageThreadId(builder.messageThreadId);
|
||||
setParseMode(builder.parseMode);
|
||||
setEntities(builder.entities);
|
||||
setLinkPreviewOptions(builder.linkPreviewOptions);
|
||||
setDisableNotification(builder.disableNotification);
|
||||
setProtectContent(builder.protectContent);
|
||||
setAllowPaidBroadcast(builder.allowPaidBroadcast);
|
||||
setMessageEffectId(builder.messageEffectId);
|
||||
setReplyParameters(builder.replyParameters);
|
||||
setReplyMarkup(builder.replyMarkup);
|
||||
}
|
||||
|
||||
public void setLinkPreviewOptions(LinkPreviewOptions linkPreviewOptions) {
|
||||
this.linkPreviewOptions = linkPreviewOptions;
|
||||
}
|
||||
|
||||
public void setBusinessConnectionId(String businessConnectionId) {
|
||||
this.businessConnectionId = businessConnectionId;
|
||||
}
|
||||
|
||||
public void setMessageThreadId(Long messageThreadId) {
|
||||
this.messageThreadId = messageThreadId;
|
||||
}
|
||||
|
||||
public void setParseMode(ParseMode parseMode) {
|
||||
this.parseMode = parseMode;
|
||||
}
|
||||
|
||||
public void setEntities(MessageEntity[] entities) {
|
||||
this.entities = entities;
|
||||
}
|
||||
|
||||
public void setDisableNotification(Boolean disableNotification) {
|
||||
this.disableNotification = disableNotification;
|
||||
}
|
||||
|
||||
public void setProtectContent(Boolean protectContent) {
|
||||
this.protectContent = protectContent;
|
||||
}
|
||||
|
||||
public void setAllowPaidBroadcast(Boolean allowPaidBroadcast) {
|
||||
this.allowPaidBroadcast = allowPaidBroadcast;
|
||||
}
|
||||
|
||||
public void setMessageEffectId(String messageEffectId) {
|
||||
this.messageEffectId = messageEffectId;
|
||||
}
|
||||
|
||||
public void setReplyParameters(ReplyParameters replyParameters) {
|
||||
this.replyParameters = replyParameters;
|
||||
}
|
||||
|
||||
public void setReplyToMessage(long messageId) {
|
||||
this.replyParameters = new ReplyParameters(messageId, chatId);
|
||||
}
|
||||
|
||||
public void setReplyMarkup(ReplyMarkup replyMarkup) {
|
||||
this.replyMarkup = replyMarkup;
|
||||
}
|
||||
|
||||
public SendMessage(String chatId, String text) {
|
||||
if (chatId.isEmpty() || text.isEmpty())
|
||||
throw new IllegalArgumentException("chatId or/and message (text) cannot be empty.");
|
||||
this.chatId = chatId;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public SendMessage(long chatIdAsLong, String text) {
|
||||
this(String.valueOf(chatIdAsLong), text);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "sendMessage";
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Class<Message> getResponseClass() {
|
||||
return Message.class;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private final String chatId;
|
||||
private final String text;
|
||||
private String businessConnectionId;
|
||||
private Long messageThreadId;
|
||||
private ParseMode parseMode;
|
||||
private MessageEntity[] entities;
|
||||
private LinkPreviewOptions linkPreviewOptions;
|
||||
private Boolean disableNotification;
|
||||
private Boolean protectContent;
|
||||
private Boolean allowPaidBroadcast;
|
||||
private String messageEffectId;
|
||||
private ReplyParameters replyParameters;
|
||||
private ReplyMarkup replyMarkup;
|
||||
|
||||
public Builder(long chatId, String text) {
|
||||
this(String.valueOf(chatId), text);
|
||||
}
|
||||
|
||||
public Builder(String chatId, String text) {
|
||||
this.chatId = chatId;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public Builder businessConnectionId(String val) {
|
||||
businessConnectionId = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder messageThreadId(Long val) {
|
||||
messageThreadId = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder parseMode(ParseMode val) {
|
||||
parseMode = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder entities(MessageEntity[] val) {
|
||||
entities = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder linkPreviewOptions(LinkPreviewOptions val) {
|
||||
linkPreviewOptions = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder disableNotification() {
|
||||
disableNotification = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder protectContent() {
|
||||
protectContent = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder allowPaidBroadcast() {
|
||||
allowPaidBroadcast = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder messageEffectId(String val) {
|
||||
messageEffectId = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder replyParameters(ReplyParameters val) {
|
||||
replyParameters = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder replyToMessage(long val) {
|
||||
replyParameters = new ReplyParameters(val, this.chatId);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder replyMarkup(ReplyMarkup val) {
|
||||
replyMarkup = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SendMessage build() {
|
||||
return new SendMessage(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.objects.ReactionType;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Jsonable
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class SetMessageReaction implements TelegramApiMethod<Boolean> {
|
||||
|
||||
@JsonProperty("chat_id")
|
||||
private final String chatId;
|
||||
@JsonProperty("message_id")
|
||||
private final long messageId;
|
||||
@JsonProperty("reaction")
|
||||
private List<ReactionType> reactions;
|
||||
@JsonProperty("is_big")
|
||||
private Boolean isBig;
|
||||
|
||||
public SetMessageReaction(String chatId, long messageId) {
|
||||
this.chatId = chatId;
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
public SetMessageReaction(long chatId, long messageId) {
|
||||
this.chatId = String.valueOf(chatId);
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
private SetMessageReaction(Builder builder) {
|
||||
chatId = builder.chatId;
|
||||
messageId = builder.messageId;
|
||||
setReactions(builder.reactions);
|
||||
isBig = builder.isBig;
|
||||
}
|
||||
|
||||
public void setReactions(List<ReactionType> reactions) {
|
||||
this.reactions = reactions;
|
||||
}
|
||||
|
||||
public void setBig(Boolean big) {
|
||||
isBig = big;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "setMessageReaction";
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Class<Boolean> getResponseClass() {
|
||||
return Boolean.class;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private final String chatId;
|
||||
private final long messageId;
|
||||
private List<ReactionType> reactions;
|
||||
private Boolean isBig;
|
||||
|
||||
public Builder(String chatId, long messageId) {
|
||||
this.chatId = chatId;
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
public Builder(long chatId, long messageId) {
|
||||
this.chatId = String.valueOf(chatId);
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
public Builder reactions(List<ReactionType> reactions) {
|
||||
this.reactions = reactions;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder isBig(Boolean isBig) {
|
||||
this.isBig = isBig;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SetMessageReaction build() {
|
||||
return new SetMessageReaction(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import hdvtdev.telegram.annotations.util.Jsonable;
|
||||
import hdvtdev.telegram.objects.bot.BotCommand;
|
||||
import hdvtdev.telegram.objects.bot.BotCommandScope;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Jsonable
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public final class SetMyCommands implements TelegramApiMethod<Boolean> {
|
||||
|
||||
@JsonProperty("commands")
|
||||
private final List<BotCommand> commands;
|
||||
@JsonProperty("scope")
|
||||
private Object scope;
|
||||
@JsonProperty("language_code")
|
||||
private String languageCode;
|
||||
|
||||
public SetMyCommands(List<BotCommand> commands, Object scope, String languageCode) {
|
||||
this.commands = commands;
|
||||
this.scope = scope;
|
||||
this.languageCode = languageCode;
|
||||
}
|
||||
|
||||
public SetMyCommands(BotCommand... commands) {
|
||||
this.commands = List.of(commands);
|
||||
}
|
||||
|
||||
public SetMyCommands(List<BotCommand> commands) {
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
private SetMyCommands(Builder builder) {
|
||||
commands = builder.commands;
|
||||
setScope(builder.scope);
|
||||
setLanguageCode(builder.languageCode);
|
||||
}
|
||||
|
||||
public void setScope(Object scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
public void setLanguageCode(String languageCode) {
|
||||
this.languageCode = languageCode;
|
||||
}
|
||||
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "setMyCommands";
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Class<Boolean> getResponseClass() {
|
||||
return Boolean.class;
|
||||
}
|
||||
|
||||
|
||||
public static final class Builder {
|
||||
private final List<BotCommand> commands;
|
||||
private Object scope;
|
||||
private String languageCode;
|
||||
|
||||
public Builder(List<BotCommand> commands) {
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
public Builder(BotCommand... commands) {
|
||||
this.commands = List.of(commands);
|
||||
}
|
||||
|
||||
public Builder scope(BotCommandScope scope) {
|
||||
this.scope = scope;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder languageCode(String languageCode) {
|
||||
this.languageCode = languageCode;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SetMyCommands build() {
|
||||
return new SetMyCommands(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
/**
|
||||
* Use this method to change the bot's description, which is shown in the chat with the bot if the chat is empty.
|
||||
* Returns {@code true} on success.
|
||||
* @param description New bot description; 0-512 characters. Pass an empty string to remove the dedicated description for the given language.
|
||||
* @param languageCode A two-letter ISO 639-1 language code. If empty, the description will be applied to all users for whose language there is no dedicated description.
|
||||
*/
|
||||
public record SetMyDescription(String description, String languageCode) implements TelegramApiMethod<Boolean> {
|
||||
|
||||
public SetMyDescription() {
|
||||
this(null, null);
|
||||
}
|
||||
|
||||
public SetMyDescription(String description) {
|
||||
this(description, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
if (description == null) {
|
||||
return null;
|
||||
}
|
||||
FormBody.Builder builder = new FormBody.Builder().add("description", description);
|
||||
if (languageCode != null) builder.add("language_code", languageCode);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "setMyDescription";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Boolean> getResponseClass() {
|
||||
return Boolean.class;
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
public record SetMyName(String name, String languageCode) implements TelegramApiMethod<Boolean> {
|
||||
|
||||
public SetMyName(String name) {
|
||||
this(name, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody getBody() {
|
||||
FormBody.Builder builder = new FormBody.Builder().add("name", this.name);
|
||||
if (languageCode != null) builder.add("language_code", this.languageCode);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return "setMyName";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Boolean> getResponseClass() {
|
||||
return Boolean.class;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ 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)
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
public interface TelegramApiMethod<T> {
|
||||
|
||||
RequestBody getBody();
|
||||
|
||||
String getMethodName();
|
||||
|
||||
Class<T> getResponseClass();
|
||||
|
||||
}
|
||||
@@ -4,6 +4,25 @@ 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 org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@@ -33,8 +52,15 @@ public record Update(
|
||||
@JsonProperty("chat_join_request") ChatJoinRequest chatJoinRequest,
|
||||
@JsonProperty("chat_boost") ChatBoostUpdated chatBoost,
|
||||
@JsonProperty("removed_chat_boost") ChatBoostRemoved chatBoostRemoved
|
||||
) {
|
||||
) implements GeneralObject {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Message message() {
|
||||
return message;
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
public boolean hasMessage() {
|
||||
return this.message != null;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
package hdvtdev.telegram.core.objects.background;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
|
||||
@@ -1,4 +1,27 @@
|
||||
package hdvtdev.telegram.core.objects.background;
|
||||
|
||||
public class BackgroundFillDeserializer {
|
||||
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<BackgroundFill> {
|
||||
|
||||
@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);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
package hdvtdev.telegram.core.objects.background;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
package hdvtdev.telegram.core.objects.background;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
package hdvtdev.telegram.core.objects.background;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
@@ -1,19 +1,8 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
package hdvtdev.telegram.core.objects.background;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
|
||||
@JsonTypeInfo(
|
||||
use = JsonTypeInfo.Id.NAME,
|
||||
include = JsonTypeInfo.As.EXISTING_PROPERTY,
|
||||
property = "type"
|
||||
)
|
||||
@JsonSubTypes({
|
||||
@JsonSubTypes.Type(value = BackgroundTypeFill.class, name = "fill"),
|
||||
@JsonSubTypes.Type(value = BackgroundTypeWallpaper.class, name = "wallpaper"),
|
||||
@JsonSubTypes.Type(value = BackgroundTypePattern.class, name = "pattern"),
|
||||
@JsonSubTypes.Type(value = BackgroundTypeChatTheme.class, name = "chat_theme")
|
||||
})
|
||||
@JsonDeserialize(using = BackgroundTypeDeserializer.class)
|
||||
public interface BackgroundType {
|
||||
String type();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
package hdvtdev.telegram.core.objects.background;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
@@ -1,4 +1,28 @@
|
||||
package hdvtdev.telegram.core.objects.background;
|
||||
|
||||
public class BackgroundTypeDeserializer {
|
||||
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<BackgroundType> {
|
||||
|
||||
@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);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
package hdvtdev.telegram.core.objects.background;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
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)
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
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)
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
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)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
package hdvtdev.telegram.core.objects.business;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
package hdvtdev.telegram.core.objects.callback;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package hdvtdev.telegram.core.objects;
|
||||
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.GeneralObject;
|
||||
import hdvtdev.telegram.core.objects.User;
|
||||
import hdvtdev.telegram.core.objects.message.MaybeInaccessibleMessage;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@@ -15,7 +17,7 @@ public record CallbackQuery(
|
||||
@JsonProperty("chat_instance") String chatInstance,
|
||||
@JsonProperty("data") String data,
|
||||
@JsonProperty("game_short_name") String gameShortName
|
||||
) {
|
||||
) implements GeneralObject {
|
||||
|
||||
public boolean hasMessage() {
|
||||
return this.message != null;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user