3 Commits

Author SHA1 Message Date
6fc2748779 [maven-release-plugin] prepare for next development iteration 2026-03-03 13:28:02 +03:00
87de3ff874 [maven-release-plugin] prepare release 0.0.2 2026-03-03 13:28:00 +03:00
c43ba2ea8b Update PengradTelegramBot to improve chat ID retrieval and upgrade Telegram API version
- Refactor chat ID extraction logic into a separate method for clarity and maintainability.
- Handle cases where chat ID may not be accessible, logging a warning when not found.
- Upgrade Telegram Bot API dependency version from 6.2.0 to 7.1.1.
- Adjust BotRequestImpl to accommodate changes in chat ID retrieval logic.
- Make botAtomicReference in App class final for better thread safety.
2026-03-03 13:26:14 +03:00
11 changed files with 74 additions and 31 deletions

39
pom.xml
View File

@@ -6,7 +6,7 @@
<groupId>ru.penkrat.stbf</groupId>
<artifactId>stbf-parent</artifactId>
<version>0.0.2-SNAPSHOT</version>
<version>0.0.3-SNAPSHOT</version>
<name>stbf-parent</name>
<description>Simple Telegram Bot Facade</description>
@@ -65,6 +65,43 @@
<target>${java.version}</target>
</configuration>
</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>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>ru.penkrat.stbf</groupId>
<artifactId>stbf-parent</artifactId>
<version>0.0.2-SNAPSHOT</version>
<version>0.0.3-SNAPSHOT</version>
</parent>
<artifactId>stbf-api</artifactId>

View File

@@ -4,7 +4,7 @@
<parent>
<artifactId>stbf-parent</artifactId>
<groupId>ru.penkrat.stbf</groupId>
<version>0.0.2-SNAPSHOT</version>
<version>0.0.3-SNAPSHOT</version>
</parent>
<artifactId>stbf-common</artifactId>
@@ -14,7 +14,7 @@
<dependency>
<groupId>ru.penkrat.stbf</groupId>
<artifactId>stbf-api</artifactId>
<version>0.0.2-SNAPSHOT</version>
<version>0.0.3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>

View File

@@ -4,7 +4,7 @@
<parent>
<artifactId>stbf-parent</artifactId>
<groupId>ru.penkrat.stbf</groupId>
<version>0.0.2-SNAPSHOT</version>
<version>0.0.3-SNAPSHOT</version>
</parent>
<groupId>ru.penkrat.stbf</groupId>

View File

@@ -19,7 +19,7 @@ public class App implements Runnable {
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.")
private String flowFile = "classpath:/flow.xml";

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>ru.penkrat.stbf</groupId>
<artifactId>stbf-parent</artifactId>
<version>0.0.2-SNAPSHOT</version>
<version>0.0.3-SNAPSHOT</version>
</parent>
<artifactId>stbf-pengrad</artifactId>
@@ -16,12 +16,12 @@
<dependency>
<groupId>ru.penkrat.stbf</groupId>
<artifactId>stbf-api</artifactId>
<version>0.0.2-SNAPSHOT</version>
<version>0.0.3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.github.pengrad</groupId>
<artifactId>java-telegram-bot-api</artifactId>
<version>6.2.0</version>
<version>7.1.1</version>
</dependency>
</dependencies>

View File

@@ -44,18 +44,16 @@ public class BotRequestImpl implements BotRequest {
@Override
public Optional<String> getCallbackMessageText() {
return Optional.of(update)
.map(Update::callbackQuery)
.map(CallbackQuery::message)
.map(Message::text);
// unsupported ? todo: check doc
return Optional.empty();
}
@Override
public Long getChatId() {
return Optional.of(update)
.map(Update::callbackQuery)
.map(CallbackQuery::message)
.orElseGet(() -> update.message()).chat().id();
.map(CallbackQuery::maybeInaccessibleMessage)
.orElseGet(update::message).chat().id();
}
@Override

View File

@@ -2,13 +2,10 @@ package ru.penkrat.stbf.impl.pengrad;
import com.pengrad.telegrambot.TelegramBot;
import com.pengrad.telegrambot.UpdatesListener;
import com.pengrad.telegrambot.model.CallbackQuery;
import com.pengrad.telegrambot.model.Update;
import lombok.extern.slf4j.Slf4j;
import ru.penkrat.stbf.api.CommandChain;
import java.util.Optional;
@Slf4j
public class PengradTelegramBot extends TelegramBot implements AutoCloseable {
@@ -17,11 +14,11 @@ public class PengradTelegramBot extends TelegramBot implements AutoCloseable {
this.setUpdatesListener(updates -> {
for (Update update : updates) {
try {
final Long chatId = Optional.of(update)
.map(Update::callbackQuery)
.map(CallbackQuery::message)
.orElseGet(() -> update.message()).chat().id();
final Long chatId = findChatId(update);
if (chatId == null) {
log.warn("Chat not found, Update [id={}]", update.updateId());
continue;
}
log.debug("New message in chat {}", chatId);
commandChain.processCommand(
@@ -41,4 +38,15 @@ public class PengradTelegramBot extends TelegramBot implements AutoCloseable {
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;
}
}

View File

@@ -4,7 +4,7 @@
<parent>
<artifactId>stbf-parent</artifactId>
<groupId>ru.penkrat.stbf</groupId>
<version>0.0.2-SNAPSHOT</version>
<version>0.0.3-SNAPSHOT</version>
</parent>
<artifactId>stbf-rubenlagus</artifactId>
@@ -15,7 +15,7 @@
<dependency>
<groupId>ru.penkrat.stbf</groupId>
<artifactId>stbf-api</artifactId>
<version>0.0.2-SNAPSHOT</version>
<version>0.0.3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.telegram</groupId>

View File

@@ -4,7 +4,7 @@
<parent>
<artifactId>stbf-parent</artifactId>
<groupId>ru.penkrat.stbf</groupId>
<version>0.0.2-SNAPSHOT</version>
<version>0.0.3-SNAPSHOT</version>
</parent>
<artifactId>stbf-templates</artifactId>
<properties>

View File

@@ -4,7 +4,7 @@
<parent>
<artifactId>stbf-parent</artifactId>
<groupId>ru.penkrat.stbf</groupId>
<version>0.0.2-SNAPSHOT</version>
<version>0.0.3-SNAPSHOT</version>
</parent>
<artifactId>stbf-test</artifactId>
@@ -14,12 +14,12 @@
<dependency>
<groupId>ru.penkrat.stbf</groupId>
<artifactId>stbf-api</artifactId>
<version>0.0.2-SNAPSHOT</version>
<version>0.0.3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>ru.penkrat.stbf</groupId>
<artifactId>stbf-common</artifactId>
<version>0.0.2-SNAPSHOT</version>
<version>0.0.3-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>