public TelegramBotService(INgrokHostedService ngrokHostedService, IEncryptor encryptor, IOptions <BotConfiguration> botConfiguration, IWebHostEnvironment enviroment) { _botConfiguration = botConfiguration.Value; var token = encryptor.DecryptStringFromBase64String(_botConfiguration.BotToken, Encoding.UTF8); TelegramBotClient = new TelegramBotClient(token); if (!string.IsNullOrEmpty(_botConfiguration.Socks5Host)) { TelegramBotClient = new TelegramBotClient(token, new HttpToSocks5Proxy(_botConfiguration.Socks5Host, _botConfiguration.Socks5Port)); } var httpsTunnel = ngrokHostedService.GetTunnelsAsync().Result.Single(t => t.Proto == "https"); if (enviroment.IsDevelopment()) { TelegramBotClient.SetWebhookAsync($"{httpsTunnel.PublicURL}/api/update").Wait(); } if (enviroment.IsProduction()) { TelegramBotClient.SetWebhookAsync($"{httpsTunnel.PublicURL}/SecretSantaTelegramBot/api/update").Wait(); } Commands = GetCommands().AsReadOnly(); }
public HomeController(ILogger <HomeController> logger, INgrokHostedService ngrokService) { _logger = logger; _ngrokService = ngrokService; }