diff --git a/pom.xml b/pom.xml index 9f8c6c6..29dc98e 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ dev.struchkov.godfather telegram-bot - 0.0.5 + 0.0.6 pom diff --git a/telegram-core/pom.xml b/telegram-core/pom.xml index 615235f..34332d2 100644 --- a/telegram-core/pom.xml +++ b/telegram-core/pom.xml @@ -5,7 +5,7 @@ dev.struchkov.godfather telegram-bot - 0.0.5 + 0.0.6 telegram-core @@ -13,10 +13,6 @@ Telegram Core Allows you to create bots for Telegram - - false - - dev.struchkov.godfather diff --git a/telegram-core/src/main/java/dev/struchkov/godfather/telegram/listen/TelegramSender.java b/telegram-core/src/main/java/dev/struchkov/godfather/telegram/listen/TelegramSender.java index d602d69..0961f3c 100644 --- a/telegram-core/src/main/java/dev/struchkov/godfather/telegram/listen/TelegramSender.java +++ b/telegram-core/src/main/java/dev/struchkov/godfather/telegram/listen/TelegramSender.java @@ -12,6 +12,9 @@ import dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard; import dev.struchkov.godfather.telegram.domain.keyboard.MarkupKeyBoard; import dev.struchkov.godfather.telegram.domain.keyboard.button.ButtonUrl; import dev.struchkov.godfather.telegram.service.SendPreProcessing; +import dev.struchkov.haiti.context.exception.ConvertException; +import dev.struchkov.haiti.utils.Inspector; +import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.telegram.telegrambots.meta.api.methods.send.SendMessage; @@ -31,6 +34,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import static dev.struchkov.haiti.utils.Inspector.isNotNull; + /** * TODO: Добавить описание класса. * @@ -53,7 +58,8 @@ public class TelegramSender implements Sending { this.sendPreProcessing = sendPreProcessing; } - public void send(Long telegramId, BoxAnswer boxAnswer) { + public void send(@NotNull Long telegramId, @NotNull BoxAnswer boxAnswer) { + isNotNull(telegramId, boxAnswer); try { if (boxAnswer.isReplace() && map.containsKey(telegramId)) { final EditMessageText editMessageText = new EditMessageText(); @@ -109,26 +115,31 @@ public class TelegramSender implements Sending { } private ReplyKeyboard convertMarkupKeyBoard(MarkupKeyBoard keyBoard) { - final ReplyKeyboardMarkup keyboardMarkup = new ReplyKeyboardMarkup(); - keyboardMarkup.setOneTimeKeyboard(keyBoard.isOneTime()); - keyboardMarkup.setInputFieldPlaceholder(keyBoard.getInputFieldPlaceholder()); - keyboardMarkup.setResizeKeyboard(keyBoard.isResizeKeyboard()); - keyboardMarkup.setKeyboard( - keyBoard.getLines().stream() - .map(this::convertMarkupLine) - .toList() - ); - return keyboardMarkup; + if (keyBoard != null) { + final ReplyKeyboardMarkup keyboardMarkup = new ReplyKeyboardMarkup(); + keyboardMarkup.setOneTimeKeyboard(keyBoard.isOneTime()); + keyboardMarkup.setInputFieldPlaceholder(keyBoard.getInputFieldPlaceholder()); + keyboardMarkup.setResizeKeyboard(keyBoard.isResizeKeyboard()); + keyboardMarkup.setKeyboard( + keyBoard.getLines().stream() + .map(this::convertMarkupLine) + .toList() + ); + return keyboardMarkup; + } } private InlineKeyboardMarkup convertInlineKeyBoard(InlineKeyBoard keyBoard) { - final InlineKeyboardMarkup inlineKeyboardMarkup = new InlineKeyboardMarkup(); - inlineKeyboardMarkup.setKeyboard( - keyBoard.getLines().stream() - .map(this::convertInlineLine) - .toList() - ); - return inlineKeyboardMarkup; + if (keyBoard != null) { + final InlineKeyboardMarkup inlineKeyboardMarkup = new InlineKeyboardMarkup(); + inlineKeyboardMarkup.setKeyboard( + keyBoard.getLines().stream() + .map(this::convertInlineLine) + .toList() + ); + return inlineKeyboardMarkup; + } + return null; } private List convertInlineLine(KeyBoardLine line) { @@ -155,7 +166,7 @@ public class TelegramSender implements Sending { button.setUrl(buttonUrl.getUrl()); button.setText(buttonUrl.getLabel()); } - default -> throw new RuntimeException("Ошибка преобразования кнопки"); + default -> throw new ConvertException("Ошибка преобразования кнопки"); } return button; } @@ -166,8 +177,9 @@ public class TelegramSender implements Sending { case SimpleButton.TYPE -> { final SimpleButton simpleButton = (SimpleButton) keyBoardButton; button.setText(simpleButton.getLabel()); + Inspector.isNull(simpleButton.getCallbackData(), ConvertException.supplier("CallbackData поддерживает только Inline клавитаура")); } - default -> throw new RuntimeException("Ошибка преобразования кнопки"); + default -> throw new ConvertException("Ошибка преобразования кнопки"); } return button; }