2018-04-17 11:52:08 +02:00
|
|
|
package org.telegram.telegrambots.starter;
|
|
|
|
|
2019-10-30 10:16:16 +01:00
|
|
|
import org.springframework.beans.factory.ObjectProvider;
|
2018-04-17 11:52:08 +02:00
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
2018-06-09 20:02:22 +02:00
|
|
|
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
|
2019-10-30 10:16:16 +01:00
|
|
|
@ConditionalOnProperty(prefix = "telegrambots", name = "enabled", havingValue = "true", matchIfMissing = true)
|
2018-05-12 08:52:57 +02:00
|
|
|
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
|
|
|
}
|
2018-07-16 19:37:30 +02:00
|
|
|
|
2018-06-09 20:02:22 +02:00
|
|
|
@Bean
|
2019-10-30 10:16:16 +01:00
|
|
|
@ConditionalOnMissingBean
|
|
|
|
public TelegramBotInitializer telegramBotInitializer(TelegramBotsApi telegramBotsApi,
|
|
|
|
ObjectProvider<List<LongPollingBot>> longPollingBots,
|
2020-11-01 23:46:36 +01:00
|
|
|
ObjectProvider<List<SpringWebhookBot>> webHookBots) {
|
2019-10-30 10:16:16 +01:00
|
|
|
return new TelegramBotInitializer(telegramBotsApi,
|
|
|
|
longPollingBots.getIfAvailable(Collections::emptyList),
|
|
|
|
webHookBots.getIfAvailable(Collections::emptyList));
|
2018-06-09 20:02:22 +02:00
|
|
|
}
|
2018-04-17 11:52:08 +02:00
|
|
|
}
|