sozsoft-platform/api/modules/Sozsoft.Sender/Telegram/TelegramHttpClient.cs
2026-10-17 21:51:10 +03:00

34 lines
1.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Volo.Abp.Settings;
namespace Sozsoft.Sender.Telegram;
public interface ITelegramHttpClient
{
Task<TelegramSendResultDto?> SendMessageAsync(string ChatId, string Message);
}
public sealed class TelegramHttpClient : SettingHttpClientBase, ITelegramHttpClient
{
public TelegramHttpClient(HttpClient httpClient, ISettingProvider settingProvider)
: base(httpClient, settingProvider)
{
}
public async Task<TelegramSendResultDto?> SendMessageAsync(string ChatId, string Message)
{
var url = await GetSettingAsync(TelegramSettingNames.Url);
var botToken = await GetSettingAsync(TelegramSettingNames.BotToken);
var parseMode = await GetSettingAsync(TelegramSettingNames.ParseMode);
// Bot API hatayı 4xx gövdesinde açıklar; durum kodunu fırlatmak açıklamayı kaybettirir.
return await PostJsonAsync<TelegramSendResultDto>(
$"{url?.TrimEnd('/')}/bot{botToken}/sendMessage",
new TelegramPostMessageInput
{
chat_id = ChatId,
text = Message,
parse_mode = parseMode.IsNullOrWhiteSpace() ? null : parseMode,
disable_web_page_preview = true
});
}
}