feat: publish dbussmsforward refactor
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
using DbusSmsForward.Helper;
|
||||
using DbusSmsForward.Services;
|
||||
using DbusSmsForward.SettingModel;
|
||||
using DbusSmsForward.SMSModel;
|
||||
using System.Web;
|
||||
|
||||
namespace DbusSmsForward.Notifications;
|
||||
|
||||
public sealed class TelegramNotificationSender(DbusSmsForwardOptions options) : NotificationSenderBase("telegram")
|
||||
{
|
||||
private readonly TelegramBotConfig _config = options.Notifications.TelegramBot;
|
||||
|
||||
public override bool IsEnabled => _config.Enabled && !string.IsNullOrWhiteSpace(_config.BotToken) && !string.IsNullOrWhiteSpace(_config.ChatId);
|
||||
|
||||
public override async Task SendAsync(SmsContentModel sms, string body, string deviceName, CancellationToken cancellationToken)
|
||||
{
|
||||
string apiBase = _config.EnableCustomApi && !string.IsNullOrWhiteSpace(_config.CustomApi)
|
||||
? _config.CustomApi.TrimEnd('/')
|
||||
: "https://api.telegram.org";
|
||||
|
||||
string text = body;
|
||||
string url = $"{apiBase}/bot{_config.BotToken}/sendMessage?chat_id={HttpUtility.UrlEncode(_config.ChatId)}&text={HttpUtility.UrlEncode(text)}";
|
||||
await HttpHelper.HttpGetAsync(url, _config.SkipTlsValidation, cancellationToken);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user