Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 154f6471d8 | |||
| 10b1b430e6 | |||
| fc7ba16fab | |||
| 0e1b44a920 | |||
| 6fc2748779 | |||
| 87de3ff874 | |||
| c43ba2ea8b | |||
| a06f9940ff | |||
| 8453ba42f8 |
@@ -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.2-SNAPSHOT</version>
|
<version>0.0.3</version>
|
||||||
<name>stbf-parent</name>
|
<name>stbf-parent</name>
|
||||||
|
|
||||||
<description>Simple Telegram Bot Facade</description>
|
<description>Simple Telegram Bot Facade</description>
|
||||||
@@ -14,8 +14,8 @@
|
|||||||
<scm>
|
<scm>
|
||||||
<connection>scm:git:https://git.penkrat.ru/ruslan/stbf.git</connection>
|
<connection>scm:git:https://git.penkrat.ru/ruslan/stbf.git</connection>
|
||||||
<developerConnection>scm:git:https://git.penkrat.ru/ruslan/stbf.git</developerConnection>
|
<developerConnection>scm:git:https://git.penkrat.ru/ruslan/stbf.git</developerConnection>
|
||||||
<tag>HEAD</tag>
|
<tag>stbf-parent-0.0.3</tag>
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
<licenses>
|
<licenses>
|
||||||
<license>
|
<license>
|
||||||
@@ -65,6 +65,43 @@
|
|||||||
<target>${java.version}</target>
|
<target>${java.version}</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>attach-sources</id>
|
||||||
|
<phase>deploy</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>jar-no-fork</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>attach-javadocs</id>
|
||||||
|
<phase>deploy</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>jar</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<!-- explicitly define maven-deploy-plugin after other to force exec order -->
|
||||||
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>deploy</id>
|
||||||
|
<phase>deploy</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>deploy</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-release-plugin</artifactId>
|
<artifactId>maven-release-plugin</artifactId>
|
||||||
|
|||||||
+1
-1
@@ -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.2-SNAPSHOT</version>
|
<version>0.0.3</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>stbf-api</artifactId>
|
<artifactId>stbf-api</artifactId>
|
||||||
|
|||||||
+2
-2
@@ -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.2-SNAPSHOT</version>
|
<version>0.0.3</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.2-SNAPSHOT</version>
|
<version>0.0.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
|
|||||||
+20
@@ -0,0 +1,20 @@
|
|||||||
|
package ru.penkrat.stbf.common.command;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import ru.penkrat.stbf.api.BotRequest;
|
||||||
|
import ru.penkrat.stbf.api.BotResponse;
|
||||||
|
import ru.penkrat.stbf.api.CommandChain;
|
||||||
|
import ru.penkrat.stbf.api.SessionProvider;
|
||||||
|
import ru.penkrat.stbf.common.session.SessionAwareBotRequest;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class SessionAwareCommandChain implements CommandChain {
|
||||||
|
|
||||||
|
private final CommandChain delegate;
|
||||||
|
private final SessionProvider sessionProvider;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void processCommand(BotRequest botRequest, BotResponse botResponse) {
|
||||||
|
delegate.processCommand(new SessionAwareBotRequest(botRequest, sessionProvider), botResponse);
|
||||||
|
}
|
||||||
|
}
|
||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
package ru.penkrat.stbf.common.command;
|
||||||
|
|
||||||
|
import ru.penkrat.stbf.api.BotRequest;
|
||||||
|
import ru.penkrat.stbf.api.BotResponse;
|
||||||
|
import ru.penkrat.stbf.api.CommandChain;
|
||||||
|
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
public class ThreadPolledCommandChain implements CommandChain {
|
||||||
|
|
||||||
|
private final CommandChain delegate;
|
||||||
|
private final ExecutorService executor;
|
||||||
|
|
||||||
|
public ThreadPolledCommandChain(CommandChain delegate) {
|
||||||
|
this(delegate, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ThreadPolledCommandChain(CommandChain delegate, int nThreads) {
|
||||||
|
this.delegate = delegate;
|
||||||
|
this.executor = Executors.newFixedThreadPool(nThreads);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void processCommand(BotRequest botRequest, BotResponse botResponse) {
|
||||||
|
executor.execute(() -> {
|
||||||
|
delegate.processCommand(botRequest, botResponse);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package ru.penkrat.stbf.common.session;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import ru.penkrat.stbf.api.BotRequest;
|
||||||
|
import ru.penkrat.stbf.api.BotSession;
|
||||||
|
import ru.penkrat.stbf.api.SessionProvider;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class SessionAwareBotRequest implements BotRequest {
|
||||||
|
|
||||||
|
private final BotRequest delegate;
|
||||||
|
|
||||||
|
private final SessionProvider sessionProvider;
|
||||||
|
|
||||||
|
private BotSession botSession;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BotSession getSession() {
|
||||||
|
if (botSession == null) {
|
||||||
|
botSession = sessionProvider.get(getChatId());
|
||||||
|
Objects.requireNonNull(botSession, "Session can not be null");
|
||||||
|
}
|
||||||
|
return botSession;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<String> getMessageText() {
|
||||||
|
return this.delegate.getMessageText();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<String> getPhoneNumber() {
|
||||||
|
return this.delegate.getPhoneNumber();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<String> getCallbackData() {
|
||||||
|
return this.delegate.getCallbackData();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<String> getCallbackMessageText() {
|
||||||
|
return this.delegate.getCallbackMessageText();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getChatId() {
|
||||||
|
return this.delegate.getChatId();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+1
-1
@@ -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.2-SNAPSHOT</version>
|
<version>0.0.3</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<groupId>ru.penkrat.stbf</groupId>
|
<groupId>ru.penkrat.stbf</groupId>
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import org.slf4j.LoggerFactory;
|
|||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
import ru.penkrat.stbf.api.BotCommandChain;
|
import ru.penkrat.stbf.api.BotCommandChain;
|
||||||
import ru.penkrat.stbf.api.CommandChain;
|
import ru.penkrat.stbf.api.CommandChain;
|
||||||
|
import ru.penkrat.stbf.common.command.SessionAwareCommandChain;
|
||||||
|
import ru.penkrat.stbf.common.command.ThreadPolledCommandChain;
|
||||||
import ru.penkrat.stbf.common.session.InMemBotSessionProvider;
|
import ru.penkrat.stbf.common.session.InMemBotSessionProvider;
|
||||||
import ru.penkrat.stbf.impl.pengrad.PengradTelegramBot;
|
import ru.penkrat.stbf.impl.pengrad.PengradTelegramBot;
|
||||||
import ru.penkrat.stbf.templates.xml.XmlFlowResolver;
|
import ru.penkrat.stbf.templates.xml.XmlFlowResolver;
|
||||||
@@ -12,58 +14,58 @@ import ru.penkrat.stbf.templates.xml.XmlFlowResolver;
|
|||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
@CommandLine.Command(name = "java -jar stbf-demo.jar", mixinStandardHelpOptions = true, description = "Run bot",
|
@CommandLine.Command(name = "java -jar stbf-demo.jar", mixinStandardHelpOptions = true, description = "Run bot",
|
||||||
version = "Simple Telegram bot framework Demo app v. 0.0.1")
|
version = "Simple Telegram bot framework Demo app v. 0.0.2")
|
||||||
public class App implements Runnable {
|
public class App implements Runnable {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(App.class);
|
private static final Logger log = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
private static AtomicReference<PengradTelegramBot> botAtomicReference = new AtomicReference<>();
|
private static final AtomicReference<PengradTelegramBot> botAtomicReference = new AtomicReference<>();
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-f", "--file"}, description = "The file with config.")
|
@CommandLine.Option(names = {"-f", "--file"}, description = "The file with config.")
|
||||||
private String flowFile = "classpath:/flow.xml";
|
private String flowFile = "classpath:/flow.xml";
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-t", "--token"}, required = true, description = "bot token 1234:abscdf...")
|
@CommandLine.Option(names = {"-t", "--token"}, required = true, description = "bot token 1234:abscdf...")
|
||||||
private String botToken = "";
|
private String botToken = "";
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
new CommandLine(new App()).execute(args);
|
new CommandLine(new App()).execute(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
private BotCommandChain getCommandChain(String filename) {
|
private CommandChain getCommandChain(String filename) {
|
||||||
XmlFlowResolver flow = new XmlFlowResolver(filename);
|
XmlFlowResolver flow = new XmlFlowResolver(filename);
|
||||||
|
|
||||||
BotCommandChain chain = new BotCommandChain();
|
BotCommandChain chain = new BotCommandChain();
|
||||||
flow.getCommands().forEach(chain::add);
|
flow.getCommands().forEach(chain::add);
|
||||||
|
|
||||||
return chain;
|
return new ThreadPolledCommandChain(new SessionAwareCommandChain(chain, new InMemBotSessionProvider()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Runnable start(String token, CommandChain chain) {
|
private Runnable start(String token, CommandChain chain) {
|
||||||
return () -> botAtomicReference.set(new PengradTelegramBot(token, chain, new InMemBotSessionProvider()));
|
return () -> botAtomicReference.set(new PengradTelegramBot(token, chain));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onShutdown() {
|
private void onShutdown() {
|
||||||
try {
|
try {
|
||||||
if (botAtomicReference.get() != null) {
|
if (botAtomicReference.get() != null) {
|
||||||
botAtomicReference.get().close();
|
botAtomicReference.get().close();
|
||||||
log.info("Bot finished.");
|
log.info("Bot finished.");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Error:", e);
|
log.error("Error:", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Thread botThread = new Thread(start(botToken, getCommandChain(flowFile)));
|
Thread botThread = new Thread(start(botToken, getCommandChain(flowFile)));
|
||||||
botThread.setDaemon(false);
|
botThread.setDaemon(false);
|
||||||
botThread.setName("stbf-bot-thread");
|
botThread.setName("stbf-bot-thread");
|
||||||
|
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(this::onShutdown));
|
Runtime.getRuntime().addShutdownHook(new Thread(this::onShutdown));
|
||||||
|
|
||||||
log.info("Starting bot...");
|
log.info("Starting bot...");
|
||||||
botThread.start();
|
botThread.start();
|
||||||
log.info("Bot started.");
|
log.info("Bot started.");
|
||||||
log.info("Press Ctrl+C to exit.");
|
log.info("Press Ctrl+C to exit.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.2-SNAPSHOT</version>
|
<version>0.0.3</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>stbf-pengrad</artifactId>
|
<artifactId>stbf-pengrad</artifactId>
|
||||||
@@ -16,12 +16,12 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ru.penkrat.stbf</groupId>
|
<groupId>ru.penkrat.stbf</groupId>
|
||||||
<artifactId>stbf-api</artifactId>
|
<artifactId>stbf-api</artifactId>
|
||||||
<version>0.0.2-SNAPSHOT</version>
|
<version>0.0.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.pengrad</groupId>
|
<groupId>com.github.pengrad</groupId>
|
||||||
<artifactId>java-telegram-bot-api</artifactId>
|
<artifactId>java-telegram-bot-api</artifactId>
|
||||||
<version>[4.9.0,5.2.0]</version>
|
<version>9.4.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|||||||
@@ -16,49 +16,49 @@ import static lombok.AccessLevel.PROTECTED;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class BotRequestImpl implements BotRequest {
|
public class BotRequestImpl implements BotRequest {
|
||||||
|
|
||||||
@Getter(PROTECTED)
|
@Getter(PROTECTED)
|
||||||
private final Update update;
|
private final Update update;
|
||||||
|
|
||||||
@Getter
|
@Override
|
||||||
private final BotSession session;
|
public Optional<String> getMessageText() {
|
||||||
|
if (update.message() != null) {
|
||||||
|
return Optional.ofNullable(update.message().text());
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> getMessageText() {
|
public Optional<String> getPhoneNumber() {
|
||||||
if (update.message() != null) {
|
return Optional.of(update)
|
||||||
return Optional.ofNullable(update.message().text());
|
.map(Update::message)
|
||||||
}
|
.map(Message::contact)
|
||||||
return Optional.empty();
|
.map(Contact::phoneNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> getPhoneNumber() {
|
public Optional<String> getCallbackData() {
|
||||||
return Optional.of(update)
|
return Optional.of(update)
|
||||||
.map(Update::message)
|
.map(Update::callbackQuery)
|
||||||
.map(Message::contact)
|
.map(CallbackQuery::data);
|
||||||
.map(Contact::phoneNumber);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> getCallbackData() {
|
public Optional<String> getCallbackMessageText() {
|
||||||
return Optional.of(update)
|
// unsupported ? todo: check doc
|
||||||
.map(Update::callbackQuery)
|
return Optional.empty();
|
||||||
.map(CallbackQuery::data);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> getCallbackMessageText() {
|
public Long getChatId() {
|
||||||
return Optional.of(update)
|
return Optional.of(update)
|
||||||
.map(Update::callbackQuery)
|
.map(Update::callbackQuery)
|
||||||
.map(CallbackQuery::message)
|
.map(CallbackQuery::maybeInaccessibleMessage)
|
||||||
.map(Message::text);
|
.orElseGet(update::message).chat().id();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getChatId() {
|
public BotSession getSession() {
|
||||||
return Optional.of(update)
|
throw new UnsupportedOperationException("Session is not supported");
|
||||||
.map(Update::callbackQuery)
|
}
|
||||||
.map(CallbackQuery::message)
|
|
||||||
.orElseGet(() -> update.message()).chat().id();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package ru.penkrat.stbf.impl.pengrad;
|
package ru.penkrat.stbf.impl.pengrad;
|
||||||
|
|
||||||
import com.pengrad.telegrambot.TelegramBot;
|
import com.pengrad.telegrambot.TelegramBot;
|
||||||
|
import com.pengrad.telegrambot.model.LinkPreviewOptions;
|
||||||
|
import com.pengrad.telegrambot.model.Message;
|
||||||
import com.pengrad.telegrambot.model.Update;
|
import com.pengrad.telegrambot.model.Update;
|
||||||
import com.pengrad.telegrambot.model.request.InlineKeyboardButton;
|
import com.pengrad.telegrambot.model.request.InlineKeyboardButton;
|
||||||
import com.pengrad.telegrambot.model.request.InlineKeyboardMarkup;
|
import com.pengrad.telegrambot.model.request.InlineKeyboardMarkup;
|
||||||
@@ -30,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();
|
||||||
@@ -58,7 +60,10 @@ public class BotResponseImpl implements BotResponse {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendFile(String filename, byte[] data) {
|
public void sendFile(String filename, byte[] data) {
|
||||||
telegramBot.execute(new SendDocument(chatId(), data).fileName(filename));
|
Message message = telegramBot.execute(new SendDocument((long) chatId(), data)
|
||||||
|
.fileName(filename)
|
||||||
|
).message();
|
||||||
|
log.debug("Send file message = {}", message.messageId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -66,14 +71,14 @@ public class BotResponseImpl implements BotResponse {
|
|||||||
public void editMessage(String text) {
|
public void editMessage(String text) {
|
||||||
telegramBot.execute(new EditMessageText(chatId(), messageId(), text)
|
telegramBot.execute(new EditMessageText(chatId(), messageId(), text)
|
||||||
.parseMode(ParseMode.HTML)
|
.parseMode(ParseMode.HTML)
|
||||||
.disableWebPagePreview(true));
|
.linkPreviewOptions(new LinkPreviewOptions().isDisabled(true)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void edit(Screen screen) {
|
public void edit(Screen screen) {
|
||||||
EditMessageText editMessage = new EditMessageText(chatId(), messageId(), screen.getText())
|
EditMessageText editMessage = new EditMessageText(chatId(), messageId(), screen.getText())
|
||||||
.parseMode(screen.getScreenProperties().isParseModeHtml() ? ParseMode.HTML : ParseMode.MarkdownV2)
|
.parseMode(screen.getScreenProperties().isParseModeHtml() ? ParseMode.HTML : ParseMode.MarkdownV2)
|
||||||
.disableWebPagePreview(screen.getScreenProperties().isDisableWebPagePreview());
|
.linkPreviewOptions(new LinkPreviewOptions().isDisabled(screen.getScreenProperties().isDisableWebPagePreview()));
|
||||||
|
|
||||||
if (screen.getKeyboard() instanceof KeyboardImpl) {
|
if (screen.getKeyboard() instanceof KeyboardImpl) {
|
||||||
KeyboardImpl kk = (KeyboardImpl) screen.getKeyboard();
|
KeyboardImpl kk = (KeyboardImpl) screen.getKeyboard();
|
||||||
@@ -105,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();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package ru.penkrat.stbf.impl.pengrad;
|
package ru.penkrat.stbf.impl.pengrad;
|
||||||
|
|
||||||
import com.google.gson.internal.reflect.ReflectionAccessor;
|
import com.google.gson.internal.reflect.ReflectionHelper;
|
||||||
import com.pengrad.telegrambot.model.request.InlineKeyboardButton;
|
import com.pengrad.telegrambot.model.request.InlineKeyboardButton;
|
||||||
import com.pengrad.telegrambot.model.request.KeyboardButton;
|
import com.pengrad.telegrambot.model.request.KeyboardButton;
|
||||||
import lombok.Value;
|
import lombok.Value;
|
||||||
@@ -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() {
|
||||||
@@ -58,7 +58,7 @@ class KeyboardImpl implements Keyboard {
|
|||||||
return text.computeIfAbsent(btn, o -> {
|
return text.computeIfAbsent(btn, o -> {
|
||||||
try {
|
try {
|
||||||
Field text = btn.getClass().getDeclaredField("text");
|
Field text = btn.getClass().getDeclaredField("text");
|
||||||
ReflectionAccessor.getInstance().makeAccessible(text);
|
ReflectionHelper.makeAccessible(text);
|
||||||
return String.valueOf(text.get(btn));
|
return String.valueOf(text.get(btn));
|
||||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||||
return "*error*";
|
return "*error*";
|
||||||
|
|||||||
@@ -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())
|
||||||
|
|||||||
@@ -2,50 +2,52 @@ package ru.penkrat.stbf.impl.pengrad;
|
|||||||
|
|
||||||
import com.pengrad.telegrambot.TelegramBot;
|
import com.pengrad.telegrambot.TelegramBot;
|
||||||
import com.pengrad.telegrambot.UpdatesListener;
|
import com.pengrad.telegrambot.UpdatesListener;
|
||||||
import com.pengrad.telegrambot.model.CallbackQuery;
|
|
||||||
import com.pengrad.telegrambot.model.Update;
|
import com.pengrad.telegrambot.model.Update;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import ru.penkrat.stbf.api.CommandChain;
|
import ru.penkrat.stbf.api.CommandChain;
|
||||||
import ru.penkrat.stbf.api.SessionProvider;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class PengradTelegramBot extends TelegramBot implements AutoCloseable {
|
public class PengradTelegramBot extends TelegramBot implements AutoCloseable {
|
||||||
|
|
||||||
public PengradTelegramBot(String botToken, CommandChain commandChain) {
|
public PengradTelegramBot(String botToken, CommandChain commandChain) {
|
||||||
this(botToken, commandChain, (id) -> {
|
super(botToken);
|
||||||
throw new IllegalArgumentException("'SessionProvider' is not defined");
|
this.setUpdatesListener(updates -> {
|
||||||
});
|
for (Update update : updates) {
|
||||||
}
|
try {
|
||||||
|
final Long chatId = findChatId(update);
|
||||||
|
if (chatId == null) {
|
||||||
|
log.warn("Chat not found, Update [id={}]", update.updateId());
|
||||||
|
log.info("Details: {}", update);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
log.debug("New message in chat {}", chatId);
|
||||||
|
|
||||||
public PengradTelegramBot(String botToken, CommandChain commandChain, SessionProvider sessionProvider) {
|
commandChain.processCommand(
|
||||||
super(botToken);
|
new BotRequestImpl(update),
|
||||||
this.setUpdatesListener(updates -> {
|
new BotResponseImpl(update, this));
|
||||||
for (Update update : updates) {
|
} catch (Exception e) {
|
||||||
try {
|
log.error("Bot Error:", e);
|
||||||
final Long chatId = Optional.of(update)
|
}
|
||||||
.map(Update::callbackQuery)
|
}
|
||||||
.map(CallbackQuery::message)
|
return UpdatesListener.CONFIRMED_UPDATES_ALL;
|
||||||
.orElseGet(() -> update.message()).chat().id();
|
});
|
||||||
|
}
|
||||||
|
|
||||||
log.debug("New message in chat {}", chatId);
|
@Override
|
||||||
|
public void close() {
|
||||||
|
removeGetUpdatesListener();
|
||||||
|
log.debug("Bot closed.");
|
||||||
|
}
|
||||||
|
|
||||||
commandChain.processCommand(
|
private Long findChatId(Update update) {
|
||||||
new BotRequestImpl(update, sessionProvider.get(chatId)),
|
if (update.callbackQuery() != null && update.callbackQuery().maybeInaccessibleMessage() != null) {
|
||||||
new BotResponseImpl(update, this));
|
return update.callbackQuery().maybeInaccessibleMessage().chat().id();
|
||||||
} catch (Exception e) {
|
}
|
||||||
log.error("Bot Error:", e);
|
if (update.message() != null) {
|
||||||
}
|
return update.message().chat().id();
|
||||||
}
|
}
|
||||||
return UpdatesListener.CONFIRMED_UPDATES_ALL;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
return null;
|
||||||
public void close() throws Exception {
|
}
|
||||||
removeGetUpdatesListener();
|
|
||||||
log.debug("Bot closed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package ru.penkrat.stbf.impl.pengrad;
|
package ru.penkrat.stbf.impl.pengrad;
|
||||||
|
|
||||||
|
import com.pengrad.telegrambot.model.LinkPreviewOptions;
|
||||||
import com.pengrad.telegrambot.model.Message;
|
import com.pengrad.telegrambot.model.Message;
|
||||||
import com.pengrad.telegrambot.model.request.ParseMode;
|
import com.pengrad.telegrambot.model.request.ParseMode;
|
||||||
import com.pengrad.telegrambot.request.AbstractSendRequest;
|
import com.pengrad.telegrambot.request.AbstractSendRequest;
|
||||||
@@ -23,7 +24,8 @@ import java.util.function.Consumer;
|
|||||||
@UtilityClass
|
@UtilityClass
|
||||||
class SendMethodUtils {
|
class SendMethodUtils {
|
||||||
|
|
||||||
public AbstractSendRequest<? extends AbstractSendRequest> createFromScreen(@NonNull Object chatId, @NonNull Screen screen) {
|
public AbstractSendRequest<? extends AbstractSendRequest<?>> createFromScreen(@NonNull Object chatIdObj, @NonNull Screen screen) {
|
||||||
|
long chatId = chatIdObj instanceof Long ? (Long) chatIdObj : 0;
|
||||||
if (isMedia(screen)) {
|
if (isMedia(screen)) {
|
||||||
final Media media = screen.getMedia();
|
final Media media = screen.getMedia();
|
||||||
switch (media.getMediaType()) {
|
switch (media.getMediaType()) {
|
||||||
@@ -77,7 +79,7 @@ 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)
|
||||||
.disableWebPagePreview(screen.getScreenProperties().isDisableWebPagePreview())
|
.linkPreviewOptions(new LinkPreviewOptions().isDisabled(screen.getScreenProperties().isDisableWebPagePreview()))
|
||||||
.disableNotification(screen.getScreenProperties().isDisableNotification());
|
.disableNotification(screen.getScreenProperties().isDisableNotification());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +104,7 @@ class SendMethodUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private SendVoice createSendVoice(@NotNull Object chatId, Media media) {
|
private SendVoice createSendVoice(long chatId, Media media) {
|
||||||
if (media.getData() != null) {
|
if (media.getData() != null) {
|
||||||
return new SendVoice(chatId, media.getData().get());
|
return new SendVoice(chatId, media.getData().get());
|
||||||
}
|
}
|
||||||
@@ -113,7 +115,7 @@ class SendMethodUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private SendVideo createSendVideo(@NotNull Object chatId, Media media) {
|
private SendVideo createSendVideo(long chatId, Media media) {
|
||||||
if (media.getData() != null) {
|
if (media.getData() != null) {
|
||||||
return new SendVideo(chatId, media.getData().get());
|
return new SendVideo(chatId, media.getData().get());
|
||||||
}
|
}
|
||||||
@@ -124,7 +126,7 @@ class SendMethodUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private SendAudio createSendAudio(@NotNull Object chatId, Media media) {
|
private SendAudio createSendAudio(long chatId, Media media) {
|
||||||
if (media.getData() != null) {
|
if (media.getData() != null) {
|
||||||
return new SendAudio(chatId, media.getData().get());
|
return new SendAudio(chatId, media.getData().get());
|
||||||
}
|
}
|
||||||
@@ -135,7 +137,7 @@ class SendMethodUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private SendAnimation createSendAnimation(@NotNull Object chatId, Media media) {
|
private SendAnimation createSendAnimation(long chatId, Media media) {
|
||||||
if (media.getData() != null) {
|
if (media.getData() != null) {
|
||||||
return new SendAnimation(chatId, media.getData().get());
|
return new SendAnimation(chatId, media.getData().get());
|
||||||
}
|
}
|
||||||
@@ -146,7 +148,7 @@ class SendMethodUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private SendPhoto createSendPhoto(@NotNull Object chatId, Media media) {
|
private SendPhoto createSendPhoto(long chatId, Media media) {
|
||||||
if (media.getData() != null) {
|
if (media.getData() != null) {
|
||||||
return new SendPhoto(chatId, media.getData().get());
|
return new SendPhoto(chatId, media.getData().get());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.2-SNAPSHOT</version>
|
<version>0.0.3</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.2-SNAPSHOT</version>
|
<version>0.0.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.telegram</groupId>
|
<groupId>org.telegram</groupId>
|
||||||
|
|||||||
@@ -16,46 +16,48 @@ import static lombok.AccessLevel.PROTECTED;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
class BotRequestImpl implements BotRequest {
|
class BotRequestImpl implements BotRequest {
|
||||||
|
|
||||||
@Getter(PROTECTED)
|
@Getter(PROTECTED)
|
||||||
private final Update update;
|
private final Update update;
|
||||||
|
|
||||||
@Getter
|
@Override
|
||||||
private final BotSession session;
|
public Optional<String> getMessageText() {
|
||||||
|
if (update.hasMessage()) {
|
||||||
|
return Optional.ofNullable(update.getMessage().getText());
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> getMessageText() {
|
public Optional<String> getPhoneNumber() {
|
||||||
if (update.hasMessage()) {
|
return Optional.of(update)
|
||||||
return Optional.ofNullable(update.getMessage().getText());
|
.map(Update::getMessage)
|
||||||
}
|
.map(Message::getContact)
|
||||||
return Optional.empty();
|
.map(Contact::getPhoneNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> getPhoneNumber() {
|
public Optional<String> getCallbackData() {
|
||||||
return Optional.of(update)
|
return Optional.of(update)
|
||||||
.map(Update::getMessage)
|
.map(Update::getCallbackQuery)
|
||||||
.map(Message::getContact)
|
.map(CallbackQuery::getData);
|
||||||
.map(Contact::getPhoneNumber);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> getCallbackData() {
|
public Optional<String> getCallbackMessageText() {
|
||||||
return Optional.of(update)
|
return Optional.of(update)
|
||||||
.map(Update::getCallbackQuery)
|
.map(Update::getCallbackQuery)
|
||||||
.map(CallbackQuery::getData);
|
.map(CallbackQuery::getMessage)
|
||||||
}
|
.map(Message::getText);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> getCallbackMessageText() {
|
public Long getChatId() {
|
||||||
return Optional.of(update)
|
return Utils.getChatId(update);
|
||||||
.map(Update::getCallbackQuery)
|
}
|
||||||
.map(CallbackQuery::getMessage)
|
|
||||||
.map(Message::getText);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getChatId() {
|
public BotSession getSession() {
|
||||||
return Utils.getChatId(update);
|
throw new UnsupportedOperationException("Session is not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+33
-42
@@ -7,56 +7,47 @@ import org.telegram.telegrambots.meta.api.objects.Update;
|
|||||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
|
||||||
import org.telegram.telegrambots.updatesreceivers.DefaultBotSession;
|
import org.telegram.telegrambots.updatesreceivers.DefaultBotSession;
|
||||||
import ru.penkrat.stbf.api.BotCommandChain;
|
import ru.penkrat.stbf.api.BotCommandChain;
|
||||||
import ru.penkrat.stbf.api.SessionProvider;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class RubenlagusTelegramBot extends TelegramLongPollingBot {
|
public class RubenlagusTelegramBot extends TelegramLongPollingBot {
|
||||||
|
|
||||||
private final String botUsername;
|
private final String botUsername;
|
||||||
private final String botToken;
|
private final String botToken;
|
||||||
private final BotCommandChain commandChain;
|
private final BotCommandChain commandChain;
|
||||||
private final SessionProvider sessionProvider;
|
|
||||||
|
|
||||||
public RubenlagusTelegramBot(String botUsername, String botToken, BotCommandChain botCommandChain) {
|
public RubenlagusTelegramBot(String botUsername, String botToken, BotCommandChain botCommandChain) {
|
||||||
this(botUsername, botToken, botCommandChain, (id) -> {
|
this.botUsername = botUsername;
|
||||||
throw new IllegalArgumentException("'SessionProvider' is not defined");
|
this.botToken = botToken;
|
||||||
});
|
this.commandChain = botCommandChain;
|
||||||
}
|
|
||||||
|
|
||||||
public RubenlagusTelegramBot(String botUsername, String botToken, BotCommandChain botCommandChain, SessionProvider sessionProvider) {
|
TelegramBotsApi telegramBotsApi;
|
||||||
this.botUsername = botUsername;
|
try {
|
||||||
this.botToken = botToken;
|
telegramBotsApi = new TelegramBotsApi(DefaultBotSession.class);
|
||||||
this.commandChain = botCommandChain;
|
telegramBotsApi.registerBot(this);
|
||||||
this.sessionProvider = sessionProvider;
|
} catch (TelegramApiException e) {
|
||||||
|
log.error("Error", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TelegramBotsApi telegramBotsApi;
|
@Override
|
||||||
try {
|
public void onUpdateReceived(Update update) {
|
||||||
telegramBotsApi = new TelegramBotsApi(DefaultBotSession.class);
|
try {
|
||||||
telegramBotsApi.registerBot(this);
|
commandChain.processCommand(
|
||||||
} catch (TelegramApiException e) {
|
new BotRequestImpl(update),
|
||||||
log.error("Error", e);
|
new BotResponseImpl(update, this));
|
||||||
}
|
} catch (Exception e) {
|
||||||
}
|
log.error("Bot Error:", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdateReceived(Update update) {
|
public String getBotUsername() {
|
||||||
try {
|
return botUsername;
|
||||||
commandChain.processCommand(
|
}
|
||||||
new BotRequestImpl(update, sessionProvider.get(Utils.getChatId(update))),
|
|
||||||
new BotResponseImpl(update, this));
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("Bot Error:", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getBotUsername() {
|
public String getBotToken() {
|
||||||
return botUsername;
|
return botToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getBotToken() {
|
|
||||||
return botToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.2-SNAPSHOT</version>
|
<version>0.0.3</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>stbf-templates</artifactId>
|
<artifactId>stbf-templates</artifactId>
|
||||||
<properties>
|
<properties>
|
||||||
|
|||||||
+3
-3
@@ -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
@@ -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.2-SNAPSHOT</version>
|
<version>0.0.3</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.2-SNAPSHOT</version>
|
<version>0.0.3</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.2-SNAPSHOT</version>
|
<version>0.0.3</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
Reference in New Issue
Block a user