diff --git a/README.md b/README.md index d5ba077..85e20ed 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,13 @@ The framework supports multiple update ingestion modes. Requires an explicit dependency and a public HTTPS endpoint. +- **NO_INGRESS** + + Runs the bot without any update ingress. + + Incoming updates from Telegram are not received. Suitable for outbound-only bots, + scheduled notifications, and integration-driven use cases. + ### **Custom ingress** - **CUSTOM** @@ -164,7 +171,7 @@ Transport selection is controlled via: ```yaml telegram: bot: - mode: LONG_POLLING | WEBHOOK | CUSTOM + mode: LONG_POLLING | WEBHOOK | CUSTOM | NO_INGRESS ``` In CUSTOM mode, application startup will fail if no UpdateIngress bean is provided. diff --git a/telegram-bot-core/src/main/java/io/ksilisk/telegrambot/core/ingress/NoIngressUpdateIngress.java b/telegram-bot-core/src/main/java/io/ksilisk/telegrambot/core/ingress/NoIngressUpdateIngress.java new file mode 100644 index 0000000..05f447f --- /dev/null +++ b/telegram-bot-core/src/main/java/io/ksilisk/telegrambot/core/ingress/NoIngressUpdateIngress.java @@ -0,0 +1,10 @@ +package io.ksilisk.telegrambot.core.ingress; + +/** + * An implementation of UpdateIngress that does nothing. + * Used when the bot is configured to not receive any updates. + */ +public class NoIngressUpdateIngress implements UpdateIngress { + public NoIngressUpdateIngress() { + } +} diff --git a/telegram-bot-spring-boot-autoconfigure/src/main/java/io/ksilisk/telegrambot/autoconfigure/TelegramBotAutoConfiguration.java b/telegram-bot-spring-boot-autoconfigure/src/main/java/io/ksilisk/telegrambot/autoconfigure/TelegramBotAutoConfiguration.java index 3b8bf92..7d8fe95 100644 --- a/telegram-bot-spring-boot-autoconfigure/src/main/java/io/ksilisk/telegrambot/autoconfigure/TelegramBotAutoConfiguration.java +++ b/telegram-bot-spring-boot-autoconfigure/src/main/java/io/ksilisk/telegrambot/autoconfigure/TelegramBotAutoConfiguration.java @@ -8,6 +8,7 @@ import io.ksilisk.telegrambot.autoconfigure.config.dispatch.RoutingConfiguration; import io.ksilisk.telegrambot.autoconfigure.config.transport.CustomMissingIngressConfiguration; import io.ksilisk.telegrambot.autoconfigure.config.transport.LongPollingMissingIngressConfiguration; +import io.ksilisk.telegrambot.autoconfigure.config.transport.NoIngressModeConfiguration; import io.ksilisk.telegrambot.autoconfigure.config.transport.TelegramClientConfiguration; import io.ksilisk.telegrambot.autoconfigure.config.transport.WebhookMissingIngressConfiguration; import io.ksilisk.telegrambot.autoconfigure.properties.TelegramBotProperties; @@ -20,6 +21,7 @@ @EnableConfigurationProperties(TelegramBotProperties.class) @ConditionalOnClass(TelegramBot.class) @Import({ + NoIngressModeConfiguration.class, LongPollingMissingIngressConfiguration.class, WebhookMissingIngressConfiguration.class, CustomMissingIngressConfiguration.class, diff --git a/telegram-bot-spring-boot-autoconfigure/src/main/java/io/ksilisk/telegrambot/autoconfigure/config/transport/NoIngressModeConfiguration.java b/telegram-bot-spring-boot-autoconfigure/src/main/java/io/ksilisk/telegrambot/autoconfigure/config/transport/NoIngressModeConfiguration.java new file mode 100644 index 0000000..a6396e4 --- /dev/null +++ b/telegram-bot-spring-boot-autoconfigure/src/main/java/io/ksilisk/telegrambot/autoconfigure/config/transport/NoIngressModeConfiguration.java @@ -0,0 +1,21 @@ +package io.ksilisk.telegrambot.autoconfigure.config.transport; + +import io.ksilisk.telegrambot.core.ingress.NoIngressUpdateIngress; +import io.ksilisk.telegrambot.core.ingress.UpdateIngress; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration(proxyBeanMethods = false) +@ConditionalOnProperty(prefix = "telegram.bot", name = "mode", havingValue = "NO_INGRESS") +public class NoIngressModeConfiguration { + private static final Logger log = LoggerFactory.getLogger(NoIngressModeConfiguration.class); + + @Bean + public UpdateIngress updateIngress() { + log.info("Telegram bot is running in NO_INGRESS mode. Incoming updates are disabled."); + return new NoIngressUpdateIngress(); + } +} diff --git a/telegram-bot-spring-boot-autoconfigure/src/main/java/io/ksilisk/telegrambot/autoconfigure/properties/TelegramBotProperties.java b/telegram-bot-spring-boot-autoconfigure/src/main/java/io/ksilisk/telegrambot/autoconfigure/properties/TelegramBotProperties.java index cdbbe66..eb6ee1c 100644 --- a/telegram-bot-spring-boot-autoconfigure/src/main/java/io/ksilisk/telegrambot/autoconfigure/properties/TelegramBotProperties.java +++ b/telegram-bot-spring-boot-autoconfigure/src/main/java/io/ksilisk/telegrambot/autoconfigure/properties/TelegramBotProperties.java @@ -31,12 +31,14 @@ public class TelegramBotProperties { *