Исправление преобразования клавиаутры
This commit is contained in:
parent
760c771e8d
commit
2524de40f3
2
pom.xml
2
pom.xml
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
<groupId>dev.struchkov.godfather</groupId>
|
<groupId>dev.struchkov.godfather</groupId>
|
||||||
<artifactId>telegram-bot</artifactId>
|
<artifactId>telegram-bot</artifactId>
|
||||||
<version>0.0.5</version>
|
<version>0.0.6</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>dev.struchkov.godfather</groupId>
|
<groupId>dev.struchkov.godfather</groupId>
|
||||||
<artifactId>telegram-bot</artifactId>
|
<artifactId>telegram-bot</artifactId>
|
||||||
<version>0.0.5</version>
|
<version>0.0.6</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>telegram-core</artifactId>
|
<artifactId>telegram-core</artifactId>
|
||||||
@ -13,10 +13,6 @@
|
|||||||
<name>Telegram Core</name>
|
<name>Telegram Core</name>
|
||||||
<description>Allows you to create bots for Telegram</description>
|
<description>Allows you to create bots for Telegram</description>
|
||||||
|
|
||||||
<properties>
|
|
||||||
<skip.deploy>false</skip.deploy>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>dev.struchkov.godfather</groupId>
|
<groupId>dev.struchkov.godfather</groupId>
|
||||||
|
@ -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.MarkupKeyBoard;
|
||||||
import dev.struchkov.godfather.telegram.domain.keyboard.button.ButtonUrl;
|
import dev.struchkov.godfather.telegram.domain.keyboard.button.ButtonUrl;
|
||||||
import dev.struchkov.godfather.telegram.service.SendPreProcessing;
|
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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
|
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
|
||||||
@ -31,6 +34,8 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static dev.struchkov.haiti.utils.Inspector.isNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: Добавить описание класса.
|
* TODO: Добавить описание класса.
|
||||||
*
|
*
|
||||||
@ -53,7 +58,8 @@ public class TelegramSender implements Sending {
|
|||||||
this.sendPreProcessing = sendPreProcessing;
|
this.sendPreProcessing = sendPreProcessing;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void send(Long telegramId, BoxAnswer boxAnswer) {
|
public void send(@NotNull Long telegramId, @NotNull BoxAnswer boxAnswer) {
|
||||||
|
isNotNull(telegramId, boxAnswer);
|
||||||
try {
|
try {
|
||||||
if (boxAnswer.isReplace() && map.containsKey(telegramId)) {
|
if (boxAnswer.isReplace() && map.containsKey(telegramId)) {
|
||||||
final EditMessageText editMessageText = new EditMessageText();
|
final EditMessageText editMessageText = new EditMessageText();
|
||||||
@ -109,6 +115,7 @@ public class TelegramSender implements Sending {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ReplyKeyboard convertMarkupKeyBoard(MarkupKeyBoard keyBoard) {
|
private ReplyKeyboard convertMarkupKeyBoard(MarkupKeyBoard keyBoard) {
|
||||||
|
if (keyBoard != null) {
|
||||||
final ReplyKeyboardMarkup keyboardMarkup = new ReplyKeyboardMarkup();
|
final ReplyKeyboardMarkup keyboardMarkup = new ReplyKeyboardMarkup();
|
||||||
keyboardMarkup.setOneTimeKeyboard(keyBoard.isOneTime());
|
keyboardMarkup.setOneTimeKeyboard(keyBoard.isOneTime());
|
||||||
keyboardMarkup.setInputFieldPlaceholder(keyBoard.getInputFieldPlaceholder());
|
keyboardMarkup.setInputFieldPlaceholder(keyBoard.getInputFieldPlaceholder());
|
||||||
@ -120,8 +127,10 @@ public class TelegramSender implements Sending {
|
|||||||
);
|
);
|
||||||
return keyboardMarkup;
|
return keyboardMarkup;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private InlineKeyboardMarkup convertInlineKeyBoard(InlineKeyBoard keyBoard) {
|
private InlineKeyboardMarkup convertInlineKeyBoard(InlineKeyBoard keyBoard) {
|
||||||
|
if (keyBoard != null) {
|
||||||
final InlineKeyboardMarkup inlineKeyboardMarkup = new InlineKeyboardMarkup();
|
final InlineKeyboardMarkup inlineKeyboardMarkup = new InlineKeyboardMarkup();
|
||||||
inlineKeyboardMarkup.setKeyboard(
|
inlineKeyboardMarkup.setKeyboard(
|
||||||
keyBoard.getLines().stream()
|
keyBoard.getLines().stream()
|
||||||
@ -130,6 +139,8 @@ public class TelegramSender implements Sending {
|
|||||||
);
|
);
|
||||||
return inlineKeyboardMarkup;
|
return inlineKeyboardMarkup;
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private List<InlineKeyboardButton> convertInlineLine(KeyBoardLine line) {
|
private List<InlineKeyboardButton> convertInlineLine(KeyBoardLine line) {
|
||||||
return line.getButtons().stream().map(this::convertInlineButton).toList();
|
return line.getButtons().stream().map(this::convertInlineButton).toList();
|
||||||
@ -155,7 +166,7 @@ public class TelegramSender implements Sending {
|
|||||||
button.setUrl(buttonUrl.getUrl());
|
button.setUrl(buttonUrl.getUrl());
|
||||||
button.setText(buttonUrl.getLabel());
|
button.setText(buttonUrl.getLabel());
|
||||||
}
|
}
|
||||||
default -> throw new RuntimeException("Ошибка преобразования кнопки");
|
default -> throw new ConvertException("Ошибка преобразования кнопки");
|
||||||
}
|
}
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
@ -166,8 +177,9 @@ public class TelegramSender implements Sending {
|
|||||||
case SimpleButton.TYPE -> {
|
case SimpleButton.TYPE -> {
|
||||||
final SimpleButton simpleButton = (SimpleButton) keyBoardButton;
|
final SimpleButton simpleButton = (SimpleButton) keyBoardButton;
|
||||||
button.setText(simpleButton.getLabel());
|
button.setText(simpleButton.getLabel());
|
||||||
|
Inspector.isNull(simpleButton.getCallbackData(), ConvertException.supplier("CallbackData поддерживает только Inline клавитаура"));
|
||||||
}
|
}
|
||||||
default -> throw new RuntimeException("Ошибка преобразования кнопки");
|
default -> throw new ConvertException("Ошибка преобразования кнопки");
|
||||||
}
|
}
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user