using Newtonsoft.Json; using Telegram.Bot.Types; using West.TelegramBot.ContentStore.Model; namespace West.TelegramBot.ContentStore.Service; public abstract class AnimalAsAService : IRandomMediaService { private readonly HttpClient _httpClient; public abstract StoreItem StoreItem { get; } protected AnimalAsAService(IHttpClientFactory factory, Uri baseAddress) { _httpClient = factory.CreateClient(); _httpClient.BaseAddress = baseAddress; } public async Task GetRandomMediaAsync() { var resp = await _httpClient.GetAsync("images/search"); var catImage = JsonConvert.DeserializeObject>(await resp.Content.ReadAsStringAsync())![0]; return new RandomMedia(new InputFileUrl(catImage.Url)); } }