Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,6 +21,7 @@
@EnableConfigurationProperties(TelegramBotProperties.class)
@ConditionalOnClass(TelegramBot.class)
@Import({
NoIngressModeConfiguration.class,
LongPollingMissingIngressConfiguration.class,
WebhookMissingIngressConfiguration.class,
CustomMissingIngressConfiguration.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ public class TelegramBotProperties {
* <li>{@code LONG_POLLING} – receive updates by polling the Telegram API</li>
* <li>{@code WEBHOOK} – receive updates via incoming HTTP requests</li>
* <li>{@code CUSTOM} – receive updates via custom ingress</li>
* <li>{@code NO_INGRESS} - run without any update ingress (outbound-only mode)</li>
* </ul>
*/
public enum TelegramBotMode {
LONG_POLLING,
WEBHOOK,
CUSTOM
CUSTOM,
NO_INGRESS
}

/**
Expand Down Expand Up @@ -173,5 +175,4 @@ public NoMatchStrategyProperties getNomatch() {
public void setNomatch(NoMatchStrategyProperties nomatch) {
this.nomatch = nomatch;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.ksilisk.telegrambot.autoconfigure.config.transport;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;

import io.ksilisk.telegrambot.core.ingress.NoIngressUpdateIngress;
import io.ksilisk.telegrambot.core.ingress.UpdateIngress;

class NoIngressModeConfigurationTest {

private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(NoIngressModeConfiguration.class));

@Test
void shouldCreateDisabledUpdateIngressWhenModeIsDisabled() {
contextRunner.withPropertyValues("telegram.bot.mode=NO_INGRESS")
.run(context -> {
assertThat(context).hasSingleBean(UpdateIngress.class);
assertThat(context).hasSingleBean(NoIngressUpdateIngress.class);
});
}

@Test
void shouldNotCreateBeanWhenModeIsNotDisabled() {
contextRunner.withPropertyValues("telegram.bot.mode=LONG_POLLING")
.run(context -> assertThat(context).doesNotHaveBean(NoIngressUpdateIngress.class));
}
}