Compare commits
2 Commits
a06f9940ff
...
0.0.2
| Author | SHA1 | Date | |
|---|---|---|---|
| 87de3ff874 | |||
| c43ba2ea8b |
41
pom.xml
41
pom.xml
@@ -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.2</version>
|
||||||
<name>stbf-parent</name>
|
<name>stbf-parent</name>
|
||||||
|
|
||||||
<description>Simple Telegram Bot Facade</description>
|
<description>Simple Telegram Bot Facade</description>
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
<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>0.0.2</tag>
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
<licenses>
|
<licenses>
|
||||||
@@ -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>
|
||||||
|
|||||||
@@ -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.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>stbf-api</artifactId>
|
<artifactId>stbf-api</artifactId>
|
||||||
|
|||||||
@@ -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.2</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.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
|
|||||||
@@ -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.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<groupId>ru.penkrat.stbf</groupId>
|
<groupId>ru.penkrat.stbf</groupId>
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ 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";
|
||||||
|
|||||||
@@ -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.2</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.2</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>6.2.0</version>
|
<version>7.1.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|||||||
@@ -44,18 +44,16 @@ public class BotRequestImpl implements BotRequest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> getCallbackMessageText() {
|
public Optional<String> getCallbackMessageText() {
|
||||||
return Optional.of(update)
|
// unsupported ? todo: check doc
|
||||||
.map(Update::callbackQuery)
|
return Optional.empty();
|
||||||
.map(CallbackQuery::message)
|
|
||||||
.map(Message::text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getChatId() {
|
public Long getChatId() {
|
||||||
return Optional.of(update)
|
return Optional.of(update)
|
||||||
.map(Update::callbackQuery)
|
.map(Update::callbackQuery)
|
||||||
.map(CallbackQuery::message)
|
.map(CallbackQuery::maybeInaccessibleMessage)
|
||||||
.orElseGet(() -> update.message()).chat().id();
|
.orElseGet(update::message).chat().id();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -2,13 +2,10 @@ 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 java.util.Optional;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class PengradTelegramBot extends TelegramBot implements AutoCloseable {
|
public class PengradTelegramBot extends TelegramBot implements AutoCloseable {
|
||||||
|
|
||||||
@@ -17,11 +14,11 @@ public class PengradTelegramBot extends TelegramBot implements AutoCloseable {
|
|||||||
this.setUpdatesListener(updates -> {
|
this.setUpdatesListener(updates -> {
|
||||||
for (Update update : updates) {
|
for (Update update : updates) {
|
||||||
try {
|
try {
|
||||||
final Long chatId = Optional.of(update)
|
final Long chatId = findChatId(update);
|
||||||
.map(Update::callbackQuery)
|
if (chatId == null) {
|
||||||
.map(CallbackQuery::message)
|
log.warn("Chat not found, Update [id={}]", update.updateId());
|
||||||
.orElseGet(() -> update.message()).chat().id();
|
continue;
|
||||||
|
}
|
||||||
log.debug("New message in chat {}", chatId);
|
log.debug("New message in chat {}", chatId);
|
||||||
|
|
||||||
commandChain.processCommand(
|
commandChain.processCommand(
|
||||||
@@ -41,4 +38,15 @@ public class PengradTelegramBot extends TelegramBot implements AutoCloseable {
|
|||||||
log.debug("Bot closed.");
|
log.debug("Bot closed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Long findChatId(Update update) {
|
||||||
|
if (update.callbackQuery() != null && update.callbackQuery().maybeInaccessibleMessage() != null) {
|
||||||
|
return update.callbackQuery().maybeInaccessibleMessage().chat().id();
|
||||||
|
}
|
||||||
|
if (update.message() != null) {
|
||||||
|
return update.message().chat().id();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.2</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.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.telegram</groupId>
|
<groupId>org.telegram</groupId>
|
||||||
|
|||||||
@@ -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.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>stbf-templates</artifactId>
|
<artifactId>stbf-templates</artifactId>
|
||||||
<properties>
|
<properties>
|
||||||
|
|||||||
@@ -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.2</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.2</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.2</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
Reference in New Issue
Block a user