40 lines
1.7 KiB
Java
40 lines
1.7 KiB
Java
package com.myoa.engineering.crawl.ppomppu.receiver.configuration;
|
|
|
|
import java.util.List;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.telegram.telegrambots.meta.TelegramBotsApi;
|
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
|
|
import org.telegram.telegrambots.updatesreceivers.DefaultBotSession;
|
|
|
|
import com.myoa.engineering.crawl.ppomppu.receiver.configuration.properties.TelegramBotProperties;
|
|
import com.myoa.engineering.crawl.ppomppu.receiver.configuration.properties.TelegramBotProperties.TelegramBotPropertiesUnit;
|
|
import com.myoa.engineering.crawl.ppomppu.receiver.dispatch.MessageDispatcher;
|
|
import com.myoa.engineering.crawl.ppomppu.receiver.handler.message.MessageHandler;
|
|
|
|
/**
|
|
* TelegramBotConfiguration
|
|
* @author Shin Woo-jin (woo-jin.shin@linecorp.com)
|
|
* @since 2021-08-21
|
|
*
|
|
*/
|
|
@Configuration
|
|
public class TelegramBotConfiguration {
|
|
|
|
private static final String BOT_PROPERTIES_UNIT_NAME = "ppomppu_notify_bot";
|
|
@Bean
|
|
public TelegramBotsApi telegramBotsApi(MessageDispatcher messageDispatcher) throws TelegramApiException {
|
|
TelegramBotsApi api = new TelegramBotsApi(DefaultBotSession.class);
|
|
api.registerBot(messageDispatcher);
|
|
return api;
|
|
}
|
|
|
|
@Bean
|
|
public MessageDispatcher messageDispatcher(List<MessageHandler> messageHandlers,
|
|
TelegramBotProperties telegramBotProperties) {
|
|
TelegramBotPropertiesUnit propertiesUnit = telegramBotProperties.find(BOT_PROPERTIES_UNIT_NAME);
|
|
return new MessageDispatcher(messageHandlers, propertiesUnit.getName(), propertiesUnit.getToken());
|
|
}
|
|
}
|