4 Commits

14 changed files with 38 additions and 38 deletions
+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>ru.penkrat.stbf</groupId> <groupId>ru.penkrat.stbf</groupId>
<artifactId>stbf-parent</artifactId> <artifactId>stbf-parent</artifactId>
<version>0.0.3-SNAPSHOT</version> <version>0.0.4-SNAPSHOT</version>
<name>stbf-parent</name> <name>stbf-parent</name>
<description>Simple Telegram Bot Facade</description> <description>Simple Telegram Bot Facade</description>
+1 -1
View File
@@ -5,7 +5,7 @@
<parent> <parent>
<groupId>ru.penkrat.stbf</groupId> <groupId>ru.penkrat.stbf</groupId>
<artifactId>stbf-parent</artifactId> <artifactId>stbf-parent</artifactId>
<version>0.0.3-SNAPSHOT</version> <version>0.0.4-SNAPSHOT</version>
</parent> </parent>
<artifactId>stbf-api</artifactId> <artifactId>stbf-api</artifactId>
+2 -2
View File
@@ -4,7 +4,7 @@
<parent> <parent>
<artifactId>stbf-parent</artifactId> <artifactId>stbf-parent</artifactId>
<groupId>ru.penkrat.stbf</groupId> <groupId>ru.penkrat.stbf</groupId>
<version>0.0.3-SNAPSHOT</version> <version>0.0.4-SNAPSHOT</version>
</parent> </parent>
<artifactId>stbf-common</artifactId> <artifactId>stbf-common</artifactId>
@@ -14,7 +14,7 @@
<dependency> <dependency>
<groupId>ru.penkrat.stbf</groupId> <groupId>ru.penkrat.stbf</groupId>
<artifactId>stbf-api</artifactId> <artifactId>stbf-api</artifactId>
<version>0.0.3-SNAPSHOT</version> <version>0.0.4-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
+1 -1
View File
@@ -4,7 +4,7 @@
<parent> <parent>
<artifactId>stbf-parent</artifactId> <artifactId>stbf-parent</artifactId>
<groupId>ru.penkrat.stbf</groupId> <groupId>ru.penkrat.stbf</groupId>
<version>0.0.3-SNAPSHOT</version> <version>0.0.4-SNAPSHOT</version>
</parent> </parent>
<groupId>ru.penkrat.stbf</groupId> <groupId>ru.penkrat.stbf</groupId>
+2 -2
View File
@@ -5,7 +5,7 @@
<parent> <parent>
<groupId>ru.penkrat.stbf</groupId> <groupId>ru.penkrat.stbf</groupId>
<artifactId>stbf-parent</artifactId> <artifactId>stbf-parent</artifactId>
<version>0.0.3-SNAPSHOT</version> <version>0.0.4-SNAPSHOT</version>
</parent> </parent>
<artifactId>stbf-pengrad</artifactId> <artifactId>stbf-pengrad</artifactId>
@@ -16,7 +16,7 @@
<dependency> <dependency>
<groupId>ru.penkrat.stbf</groupId> <groupId>ru.penkrat.stbf</groupId>
<artifactId>stbf-api</artifactId> <artifactId>stbf-api</artifactId>
<version>0.0.3-SNAPSHOT</version> <version>0.0.4-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.github.pengrad</groupId> <groupId>com.github.pengrad</groupId>
@@ -32,7 +32,7 @@ public class BotResponseImpl implements BotResponse {
public void send(Screen screen) { public void send(Screen screen) {
log.trace("Send trace: \n============\n{}\n============", screen.getText().trim()); log.trace("Send trace: \n============\n{}\n============", screen.getText().trim());
AbstractSendRequest<? extends AbstractSendRequest> sendMessage = SendMethodUtils.createFromScreen(chatId(), screen); AbstractSendRequest<? extends AbstractSendRequest<?>> sendMessage = SendMethodUtils.createFromScreen(chatId(), screen);
if (screen.getKeyboard() instanceof KeyboardImpl) { if (screen.getKeyboard() instanceof KeyboardImpl) {
KeyboardImpl kk = (KeyboardImpl) screen.getKeyboard(); KeyboardImpl kk = (KeyboardImpl) screen.getKeyboard();
@@ -110,14 +110,14 @@ public class BotResponseImpl implements BotResponse {
private Long chatId() { private Long chatId() {
if (update.callbackQuery() != null) { if (update.callbackQuery() != null) {
return update.callbackQuery().message().chat().id(); return update.callbackQuery().maybeInaccessibleMessage().chat().id();
} }
return update.message().chat().id(); return update.message().chat().id();
} }
private Integer messageId() { private Integer messageId() {
if (update.callbackQuery() != null) { if (update.callbackQuery() != null) {
return update.callbackQuery().message().messageId(); return update.callbackQuery().maybeInaccessibleMessage().messageId();
} }
return update.message().messageId(); return update.message().messageId();
} }
@@ -15,11 +15,11 @@ import java.util.stream.Stream;
@Value @Value
class KeyboardImpl implements Keyboard { class KeyboardImpl implements Keyboard {
private KeyboardButton[][] keyboard; KeyboardButton[][] keyboard;
private InlineKeyboardButton[][] inlineKeyboard; InlineKeyboardButton[][] inlineKeyboard;
private Map<Object, String> text = new HashMap<>(); Map<Object, String> text = new HashMap<>();
@Override @Override
public String toString() { public String toString() {
@@ -118,9 +118,14 @@ public class PengradKeyboardBuilder implements KeyboardBuilder {
private void put(Action action) { private void put(Action action) {
if (action.isInline()) { if (action.isInline()) {
put(new InlineKeyboardButton(action.getText()) InlineKeyboardButton inlineKeyboardButton = new InlineKeyboardButton(action.getText());
.callbackData(action.getCallbackData()) if (action.getCallbackData() != null) {
.url(action.getUrl())); inlineKeyboardButton.setCallbackData(action.getCallbackData());
}
if (action.getUrl() != null) {
inlineKeyboardButton.url(action.getUrl());
}
put(inlineKeyboardButton);
} else { } else {
put(new KeyboardButton(action.getText()) put(new KeyboardButton(action.getText())
.requestContact(action.isRequestContact()) .requestContact(action.isRequestContact())
@@ -17,6 +17,7 @@ public class PengradTelegramBot extends TelegramBot implements AutoCloseable {
final Long chatId = findChatId(update); final Long chatId = findChatId(update);
if (chatId == null) { if (chatId == null) {
log.warn("Chat not found, Update [id={}]", update.updateId()); log.warn("Chat not found, Update [id={}]", update.updateId());
log.info("Details: {}", update);
continue; continue;
} }
log.debug("New message in chat {}", chatId); log.debug("New message in chat {}", chatId);
@@ -33,7 +34,7 @@ public class PengradTelegramBot extends TelegramBot implements AutoCloseable {
} }
@Override @Override
public void close() throws Exception { public void close() {
removeGetUpdatesListener(); removeGetUpdatesListener();
log.debug("Bot closed."); log.debug("Bot closed.");
} }
@@ -24,7 +24,7 @@ import java.util.function.Consumer;
@UtilityClass @UtilityClass
class SendMethodUtils { class SendMethodUtils {
public AbstractSendRequest<? extends AbstractSendRequest> createFromScreen(@NonNull Object chatIdObj, @NonNull Screen screen) { public AbstractSendRequest<? extends AbstractSendRequest<?>> createFromScreen(@NonNull Object chatIdObj, @NonNull Screen screen) {
long chatId = chatIdObj instanceof Long ? (Long) chatIdObj : 0; long chatId = chatIdObj instanceof Long ? (Long) chatIdObj : 0;
if (isMedia(screen)) { if (isMedia(screen)) {
final Media media = screen.getMedia(); final Media media = screen.getMedia();
@@ -80,7 +80,6 @@ class SendMethodUtils {
return new SendMessage(chatId, screen.getText().trim()) return new SendMessage(chatId, screen.getText().trim())
.parseMode(screen.getScreenProperties().isParseModeHtml() ? ParseMode.HTML : ParseMode.MarkdownV2) .parseMode(screen.getScreenProperties().isParseModeHtml() ? ParseMode.HTML : ParseMode.MarkdownV2)
.linkPreviewOptions(new LinkPreviewOptions().isDisabled(screen.getScreenProperties().isDisableWebPagePreview())) .linkPreviewOptions(new LinkPreviewOptions().isDisabled(screen.getScreenProperties().isDisableWebPagePreview()))
// .disableWebPagePreview(screen.getScreenProperties().isDisableWebPagePreview())
.disableNotification(screen.getScreenProperties().isDisableNotification()); .disableNotification(screen.getScreenProperties().isDisableNotification());
} }
@@ -105,8 +104,7 @@ class SendMethodUtils {
} }
@NotNull @NotNull
private SendVoice createSendVoice(@NotNull Object chatIdObj, Media media) { private SendVoice createSendVoice(long chatId, Media media) {
long chatId = chatIdObj instanceof Long ? (Long) chatIdObj : 0;
if (media.getData() != null) { if (media.getData() != null) {
return new SendVoice(chatId, media.getData().get()); return new SendVoice(chatId, media.getData().get());
} }
@@ -117,8 +115,7 @@ class SendMethodUtils {
} }
@NotNull @NotNull
private SendVideo createSendVideo(@NotNull Object chatIdObj, Media media) { private SendVideo createSendVideo(long chatId, Media media) {
long chatId = chatIdObj instanceof Long ? (Long) chatIdObj : 0;
if (media.getData() != null) { if (media.getData() != null) {
return new SendVideo(chatId, media.getData().get()); return new SendVideo(chatId, media.getData().get());
} }
@@ -129,8 +126,7 @@ class SendMethodUtils {
} }
@NotNull @NotNull
private SendAudio createSendAudio(@NotNull Object chatIdObj, Media media) { private SendAudio createSendAudio(long chatId, Media media) {
long chatId = chatIdObj instanceof Long ? (Long) chatIdObj : 0;
if (media.getData() != null) { if (media.getData() != null) {
return new SendAudio(chatId, media.getData().get()); return new SendAudio(chatId, media.getData().get());
} }
@@ -141,8 +137,7 @@ class SendMethodUtils {
} }
@NotNull @NotNull
private SendAnimation createSendAnimation(@NotNull Object chatIdObj, Media media) { private SendAnimation createSendAnimation(long chatId, Media media) {
long chatId = chatIdObj instanceof Long ? (Long) chatIdObj : 0;
if (media.getData() != null) { if (media.getData() != null) {
return new SendAnimation(chatId, media.getData().get()); return new SendAnimation(chatId, media.getData().get());
} }
@@ -153,8 +148,7 @@ class SendMethodUtils {
} }
@NotNull @NotNull
private SendPhoto createSendPhoto(@NotNull Object chatIdObj, Media media) { private SendPhoto createSendPhoto(long chatId, Media media) {
long chatId = chatIdObj instanceof Long ? (Long) chatIdObj : 0;
if (media.getData() != null) { if (media.getData() != null) {
return new SendPhoto(chatId, media.getData().get()); return new SendPhoto(chatId, media.getData().get());
} }
+2 -2
View File
@@ -4,7 +4,7 @@
<parent> <parent>
<artifactId>stbf-parent</artifactId> <artifactId>stbf-parent</artifactId>
<groupId>ru.penkrat.stbf</groupId> <groupId>ru.penkrat.stbf</groupId>
<version>0.0.3-SNAPSHOT</version> <version>0.0.4-SNAPSHOT</version>
</parent> </parent>
<artifactId>stbf-rubenlagus</artifactId> <artifactId>stbf-rubenlagus</artifactId>
@@ -15,7 +15,7 @@
<dependency> <dependency>
<groupId>ru.penkrat.stbf</groupId> <groupId>ru.penkrat.stbf</groupId>
<artifactId>stbf-api</artifactId> <artifactId>stbf-api</artifactId>
<version>0.0.3-SNAPSHOT</version> <version>0.0.4-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.telegram</groupId> <groupId>org.telegram</groupId>
+1 -1
View File
@@ -4,7 +4,7 @@
<parent> <parent>
<artifactId>stbf-parent</artifactId> <artifactId>stbf-parent</artifactId>
<groupId>ru.penkrat.stbf</groupId> <groupId>ru.penkrat.stbf</groupId>
<version>0.0.3-SNAPSHOT</version> <version>0.0.4-SNAPSHOT</version>
</parent> </parent>
<artifactId>stbf-templates</artifactId> <artifactId>stbf-templates</artifactId>
<properties> <properties>
@@ -83,7 +83,7 @@ class FlowScreenResolverDelegate implements ScreenResolver {
if (context instanceof KeyboardProvider) { if (context instanceof KeyboardProvider) {
final Keyboard keyboard = ((KeyboardProvider) context).getKeyboard(); final Keyboard keyboard = ((KeyboardProvider) context).getKeyboard();
if (keyboard == null) { if (keyboard == null) {
log.warn("Method 'getKeyboard' returns NULL value!", wrapper.getFactoryMethod()); log.warn("Method 'getKeyboard' {} returns NULL value!", wrapper.getFactoryMethod());
} }
return keyboard; return keyboard;
} }
@@ -106,12 +106,12 @@ class FlowScreenResolverDelegate implements ScreenResolver {
for (ButtonsRow row : wrapper.getRows()) { for (ButtonsRow row : wrapper.getRows()) {
List<Action> buttons = row.getButtons().stream() List<Action> buttons = row.getButtons().stream()
.filter(btn -> checkIfCondition(context, btn.getIfCondition())) .filter(btn -> checkIfCondition(context, btn.getIfCondition()))
.map(btn -> getAction(btn)) .map(this::getAction)
.collect(Collectors.toList()); .collect(Collectors.toList());
log.info("Keyboard: {}", buttons); log.info("Keyboard: {}", buttons);
builder.row(buttons.toArray(new Action[buttons.size()])); builder.row(buttons.toArray(new Action[0]));
} }
keyboard = builder.build(); keyboard = builder.build();
+3 -3
View File
@@ -4,7 +4,7 @@
<parent> <parent>
<artifactId>stbf-parent</artifactId> <artifactId>stbf-parent</artifactId>
<groupId>ru.penkrat.stbf</groupId> <groupId>ru.penkrat.stbf</groupId>
<version>0.0.3-SNAPSHOT</version> <version>0.0.4-SNAPSHOT</version>
</parent> </parent>
<artifactId>stbf-test</artifactId> <artifactId>stbf-test</artifactId>
@@ -14,12 +14,12 @@
<dependency> <dependency>
<groupId>ru.penkrat.stbf</groupId> <groupId>ru.penkrat.stbf</groupId>
<artifactId>stbf-api</artifactId> <artifactId>stbf-api</artifactId>
<version>0.0.3-SNAPSHOT</version> <version>0.0.4-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>ru.penkrat.stbf</groupId> <groupId>ru.penkrat.stbf</groupId>
<artifactId>stbf-common</artifactId> <artifactId>stbf-common</artifactId>
<version>0.0.3-SNAPSHOT</version> <version>0.0.4-SNAPSHOT</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>