mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
[quote] Crappy chat quote implementation.
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Newtonsoft.Json;
|
||||
using Telegram.Bot.Types;
|
||||
using West.TelegramBot.ChatQuotes.Model;
|
||||
|
||||
namespace West.TelegramBot.ChatQuotes;
|
||||
|
||||
public class QuoteGeneratorService
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
|
||||
public QuoteGeneratorService(IConfiguration configuration)
|
||||
{
|
||||
_httpClient = new HttpClient
|
||||
{
|
||||
BaseAddress = new Uri(configuration.GetValue<string>("QuoteApiUrl"))
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<Stream> GenerateQuoteImage(Message msg)
|
||||
{
|
||||
var request = new QuoteRequest(msg);
|
||||
var content = new ByteArrayContent(Encoding.UTF8.GetBytes(request.ToJson().ToCharArray()))
|
||||
{
|
||||
Headers =
|
||||
{
|
||||
ContentType = MediaTypeHeaderValue.Parse("application/json")
|
||||
}
|
||||
};
|
||||
|
||||
var resp = await _httpClient.PostAsync("/generate", content);
|
||||
var quoteResponse = JsonConvert.DeserializeObject<QuoteResponse>(await resp.Content.ReadAsStringAsync());
|
||||
|
||||
return new MemoryStream(Convert.FromBase64String(quoteResponse.Result.Image));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user