From 7d6883abd21304be84ecc05a954021433935f87d Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Sat, 25 Feb 2023 11:10:30 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D1=8C=20=D0=BE=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D1=82=D1=8C?= =?UTF-8?q?=20=D1=83=D0=B2=D0=B5=D0=B4=D0=BE=D0=BC=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=20=D1=81=D1=82=D0=B0?= =?UTF-8?q?=D1=80=D1=82=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gitlab/telegram/service/StartNotify.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/StartNotify.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/StartNotify.java index 2faea2a..98f4fa5 100644 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/StartNotify.java +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/StartNotify.java @@ -8,20 +8,31 @@ import dev.struchkov.godfather.simple.domain.BoxAnswer; import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending; import jakarta.annotation.PostConstruct; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; import org.springframework.stereotype.Component; +import java.io.IOException; + 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; /** * @author upagge 19.01.2021 */ @Component +@Slf4j @RequiredArgsConstructor public class StartNotify { + private final OkHttpClient client = new OkHttpClient(); + private final TelegramSending sending; private final AppProperty appProperty; private final AppSettingService settingService; @@ -48,6 +59,32 @@ public class StartNotify { .payload(DISABLE_WEB_PAGE_PREVIEW, true) .build(); sending.send(boxAnswer); + + sendNotice(); + } + } + + /** + * Используется для уведомления пользователя о выходе новой версии. + */ + private void sendNotice() { + final String requestUrl = "https://metrika.struchkov.dev/gitlab-notify/start-notice"; + final Request request = new Request.Builder() + .get() + .url(requestUrl) + .build(); + try { + final Response response = client.newCall(request).execute(); + 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); + } + } + } catch (IOException e) { + log.warn(e.getMessage()); } }