/// <summary> /// /// </summary> public virtual void Run() { var options = TelegramBotConfig.GetOptions(AppConfig.OptionsName); if (options == null) { throw new Exception($"Telegram bot options not configured! Options name: {AppConfig.OptionsName}"); } _container = options.Container; _servicesProvider = options.ServicesProvider; options.ServicesRegistrator?.Register(_container, options); _container.Initialize(); var commandFactory = _servicesProvider.GetService <ITelegramBotCommandFactory>(); commandFactory.Initialize(); AppConfig.Configure(this); var clientManager = _servicesProvider.GetService <ITelegramBotClientManager>(); clientManager.Token = AppConfig.Token; clientManager.Initialize(); }
/// <summary> /// /// </summary> /// <param name="services"></param> public static void AddTelegramBot(this IServiceCollection services, string optionKey) { var container = new TelegramBotAspNetCoreServicesContainer(services); var provider = new TelegramBotAspNetCoreServicesProvider(); var options = TelegramBotConfig.GetOptions(optionKey); options.Container = container; options.ServicesProvider = provider; options.ServicesRegistrator.Register(container, options); options.ServicesRegistrator = null; }
/// <summary> /// /// </summary> /// <param name="app"></param> /// <param name="optionKey"></param> /// <param name="optionKey"></param> public static void UseTelegramBot(this IApplicationBuilder app, string botToken, string optionKey) { var option = TelegramBotConfig.GetOptions(optionKey); var servicesProvider = (TelegramBotAspNetCoreServicesProvider)option.ServicesProvider; servicesProvider.ServiceProvider = app.ApplicationServices; var config = new TelegramBotAppConfig(); config.OptionsName = optionKey; config.Token = botToken; TelegramBotApplication.Run(config); }