private bool TryGetUser(TelegramConfig config, string authorId, out User user) { if (config == null) { _logger.LogError("Update request received, but no config present"); } user = config?.Users.FirstOrDefault(u => u.UserNames.Contains(authorId)); return(user != null); }
public ConfigProvider( // IKafkaConsumer<string, string> consumer, TelegramConfig defaultConfig) { _configs = new BehaviorSubject <Result <TelegramConfig> >(Result <TelegramConfig> .Success(defaultConfig)); // consumer.Messages // .Where(ConfigBelongsToTelegram) // .Select(DeserializeConfig) // .Subscribe(_configs.OnNext); }
private async Task <Option <ITelegramBotClient> > CreateNewTelegramBotClient(TelegramConfig config) { try { return(Option.Some( await _clientProvider.CreateAsync(config))); } catch (Exception e) { _logger.LogError(e, "Failed to create TelegramBotClient with new config"); return(Option.None <ITelegramBotClient>()); } }
public async Task <ITelegramBotClient> CreateAsync(TelegramConfig config) { var client = new TelegramBotClient(config.AccessToken); Telegram.Bot.Types.User identity = await client.GetMeAsync(); _logger.LogInformation( "Registered as {} {} (Username = {}, Id = {})", identity.FirstName, identity.LastName, identity.Username, identity.Id); return(client); }
private async Task OnConfigReceivedAsync(TelegramConfig config) { _logger.LogInformation( "Received new config {}, trying to create new TelegramBotClient with it", config); var client = await CreateNewTelegramBotClient(config); if (client.HasValue) { lock (_configLock) { _sender = new MessageSender(client.ValueOrDefault(), _loggerFactory); _config = config; } } }
public MessageBuilder(TelegramConfig config) { _filterRules = config.FilterRules ?? new List <FilterRule>(); }