com.orgyflame.springtelegrambotapi.bot.DefaultBotUpdateHandlerService Maven / Gradle / Ivy
package com.orgyflame.springtelegrambotapi.bot;
import com.orgyflame.springtelegrambotapi.api.method.AnswerCallbackQuery;
import com.orgyflame.springtelegrambotapi.api.object.Update;
import com.orgyflame.springtelegrambotapi.api.service.TelegramApiService;
import com.orgyflame.springtelegrambotapi.bot.mapping.BotApiMapping;
import com.orgyflame.springtelegrambotapi.bot.container.BotApiMappingContainer;
import com.orgyflame.springtelegrambotapi.bot.container.BotCallbackQueryContainer;
import com.orgyflame.springtelegrambotapi.bot.inline.menu.CallbackQueryMethod;
import com.orgyflame.springtelegrambotapi.exceptions.TelegramApiValidationException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Parameter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static com.orgyflame.springtelegrambotapi.bot.BotUtil.parseUpdateForParameter;
public class DefaultBotUpdateHandlerService implements BotUpdateHandlerService{
private final BotApiMappingContainer botApiMappingContainer;
private final BotCallbackQueryContainer botCallbackQueryContainer;
private final TelegramApiService telegramApiService;
public DefaultBotUpdateHandlerService(BotCallbackQueryContainer botCallbackQueryContainer, BotApiMappingContainer botApiMappingContainer, TelegramApiService telegramApiService) {
this.botCallbackQueryContainer = botCallbackQueryContainer;
this.botApiMappingContainer = botApiMappingContainer;
this.telegramApiService = telegramApiService;
}
public void handle(Update update) {
if (update.hasCallbackQuery()) {
handleCallback(update);
} else {
handleMessage(update);
}
}
private void handleMessage(Update update) {
String path;
BotApiMapping mapping = null;
if (update.hasMessage() && update.getMessage().hasText()) {
path = update.getMessage().getText().split(" ")[0].trim();
if (path.charAt(0) == '/') {
mapping = botApiMappingContainer.getBotApiMapping(path);
update.getMessage().setText(
Arrays.stream(update.getMessage().getText().split(" "))
.skip(1)
.reduce((s, s2) -> s + s2)
.orElse("")
.trim()
);
}
}
if (mapping == null) mapping = botApiMappingContainer.getBotApiMapping("");
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy