TelegramBots/telegrambots-spring-boot-starter/src/main/java/org/telegram/telegrambots/starter/TelegramBotStarterConfiguration.java

38 lines
1.6 KiB
Java
Raw Normal View History

2018-04-17 11:52:08 +02:00
package org.telegram.telegrambots.starter;
import org.springframework.beans.factory.ObjectProvider;
2018-04-17 11:52:08 +02:00
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
2018-04-17 11:52:08 +02:00
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
2018-07-08 01:41:21 +02:00
import org.telegram.telegrambots.meta.TelegramBotsApi;
2020-11-03 03:57:36 +01:00
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
2018-07-08 01:41:21 +02:00
import org.telegram.telegrambots.meta.generics.LongPollingBot;
2020-11-03 03:57:36 +01:00
import org.telegram.telegrambots.updatesreceivers.DefaultBotSession;
2020-11-01 23:46:36 +01:00
import java.util.Collections;
import java.util.List;
2018-04-17 11:52:08 +02:00
/**
* #TelegramBotsApi added to spring context as well
*/
@Configuration
@ConditionalOnProperty(prefix = "telegrambots", name = "enabled", havingValue = "true", matchIfMissing = true)
public class TelegramBotStarterConfiguration {
2018-04-17 11:52:08 +02:00
@Bean
@ConditionalOnMissingBean(TelegramBotsApi.class)
2020-11-03 03:57:36 +01:00
public TelegramBotsApi telegramBotsApi() throws TelegramApiException {
return new TelegramBotsApi(DefaultBotSession.class);
2018-04-17 11:52:08 +02:00
}
@Bean
@ConditionalOnMissingBean
public TelegramBotInitializer telegramBotInitializer(TelegramBotsApi telegramBotsApi,
ObjectProvider<List<LongPollingBot>> longPollingBots,
2020-11-01 23:46:36 +01:00
ObjectProvider<List<SpringWebhookBot>> webHookBots) {
return new TelegramBotInitializer(telegramBotsApi,
longPollingBots.getIfAvailable(Collections::emptyList),
webHookBots.getIfAvailable(Collections::emptyList));
}
2018-04-17 11:52:08 +02:00
}