mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
24 lines
825 B
C#
24 lines
825 B
C#
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<RandomMedia> GetRandomMediaAsync(Chat chat, User user)
|
|
{
|
|
var resp = await _httpClient.GetAsync("images/search");
|
|
var catImage = JsonConvert.DeserializeObject<List<AnimalImage>>(await resp.Content.ReadAsStringAsync())![0];
|
|
return new RandomMedia(new InputFileUrl(catImage.Url));
|
|
}
|
|
} |