Files
telegram-bot/modules/ContentStore/Service/AnimalAsAService.cs
T

24 lines
825 B
C#
Raw Normal View History

2022-02-16 17:07:30 +02:00
using Newtonsoft.Json;
2023-01-02 19:01:03 +02:00
using Telegram.Bot.Types;
2022-02-16 17:07:30 +02:00
using West.TelegramBot.ContentStore.Model;
namespace West.TelegramBot.ContentStore.Service;
public abstract class AnimalAsAService : IRandomMediaService
{
private readonly HttpClient _httpClient;
2022-02-16 18:08:02 +02:00
public abstract StoreItem StoreItem { get; }
2022-02-16 17:07:30 +02:00
2023-07-28 23:14:36 +03:00
protected AnimalAsAService(IHttpClientFactory factory, Uri baseAddress)
2022-02-16 17:07:30 +02:00
{
2023-07-28 23:14:36 +03:00
_httpClient = factory.CreateClient();
_httpClient.BaseAddress = baseAddress;
2022-02-16 17:07:30 +02:00
}
2023-07-28 23:14:36 +03:00
public async Task<RandomMedia> GetRandomMediaAsync(Chat chat, User user)
2022-02-16 17:07:30 +02:00
{
var resp = await _httpClient.GetAsync("images/search");
2023-01-02 19:01:03 +02:00
var catImage = JsonConvert.DeserializeObject<List<AnimalImage>>(await resp.Content.ReadAsStringAsync())![0];
return new RandomMedia(new InputFileUrl(catImage.Url));
2022-02-16 17:07:30 +02:00
}
}