Добавил пин получаемой нотификации

This commit is contained in:
Struchkov Mark 2023-02-25 11:49:14 +03:00
parent 17d300fbef
commit f918e7cefc
Signed by: upagge
GPG Key ID: D3018BE7BA428CA6

View File

@ -5,7 +5,9 @@ import dev.struchkov.bot.gitlab.context.utils.Icons;
import dev.struchkov.bot.gitlab.core.config.properties.AppProperty;
import dev.struchkov.bot.gitlab.core.config.properties.PersonProperty;
import dev.struchkov.godfather.simple.domain.BoxAnswer;
import dev.struchkov.godfather.simple.domain.SentBox;
import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending;
import dev.struchkov.godfather.telegram.simple.context.service.TelegramService;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -15,10 +17,10 @@ import okhttp3.Response;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.Optional;
import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.DELETE_MESSAGE;
import static dev.struchkov.godfather.main.domain.keyboard.button.SimpleButton.simpleButton;
import static dev.struchkov.godfather.simple.domain.BoxAnswer.boxAnswer;
import static dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard.inlineKeyBoard;
import static dev.struchkov.godfather.telegram.main.context.BoxAnswerPayload.DISABLE_WEB_PAGE_PREVIEW;
import static dev.struchkov.haiti.utils.Checker.checkNotBlank;
@ -34,6 +36,8 @@ public class StartNotify {
private final OkHttpClient client = new OkHttpClient();
private final TelegramSending sending;
private final TelegramService telegramService;
private final AppProperty appProperty;
private final AppSettingService settingService;
private final PersonProperty personProperty;
@ -46,9 +50,9 @@ public class StartNotify {
.message(
"Hello \uD83D\uDC4B\nI wish you a productive day \uD83C\uDF40" +
"\n-- -- -- -- --\n" +
"\uD83E\uDD16 Bot Version: " + appProperty.getVersion() +
"\n\uD83D\uDC68\u200D\uD83D\uDCBB Developer: [uPagge](https://mark.struchkov.dev)\n" +
"\uD83C\uDFE0 [HomePage](https://git.struchkov.dev/Telegram-Bots/gitlab-notification) • \uD83D\uDC1B [Issues](https://github.com/uPagge/gitlab-notification/issues) • \uD83D\uDEE3 [RoadMap](https://git.struchkov.dev/Telegram-Bots/gitlab-notification/issues)"
"\uD83E\uDD16 Version: " + appProperty.getVersion() +
"\n\uD83D\uDC68\u200D\uD83D\uDCBB Developer: [Struchkov.Dev](https://mark.struchkov.dev)\n-- -- -- -- --\n" +
"\uD83C\uDFE0 [HomePage](https://docs.struchkov.dev/gitlab-notification/) • \uD83D\uDC1B [Report Bug](https://github.com/uPagge/gitlab-notification/issues) • \uD83C\uDD98 [Donation](https://docs.struchkov.dev/gitlab-notification/support-development/)"
)
.keyBoard(
inlineKeyBoard(
@ -78,9 +82,17 @@ public class StartNotify {
if (response.code() == 200) {
final String noticeMessage = response.body().string();
if (checkNotBlank(noticeMessage)) {
final BoxAnswer notice = boxAnswer(noticeMessage);
notice.setRecipientIfNull(personProperty.getTelegramId());
sending.send(notice);
final BoxAnswer notice = BoxAnswer.builder()
.message(noticeMessage)
.recipientPersonId(personProperty.getTelegramId())
// .payload(DISABLE_WEB_PAGE_PREVIEW, true)
.build();
final Optional<SentBox> optSentBox = sending.send(notice);
if (optSentBox.isPresent()) {
final SentBox sentBox = optSentBox.get();
final String messageId = sentBox.getMessageId();
telegramService.pinMessage(personProperty.getTelegramId(), messageId);
}
}
}
} catch (IOException e) {