Files
DbusSmsForward/DbusTest/Notifications/BarkNotificationSender.cs
T

28 lines
1.2 KiB
C#

using DbusSmsForward.Helper;
using DbusSmsForward.ProcessSmsContent;
using DbusSmsForward.Services;
using DbusSmsForward.SettingModel;
using DbusSmsForward.SMSModel;
using System.Web;
namespace DbusSmsForward.Notifications;
public sealed class BarkNotificationSender(DbusSmsForwardOptions options) : NotificationSenderBase("bark")
{
private readonly BarkConfig _config = options.Notifications.Bark;
public override bool IsEnabled => _config.Enabled && !string.IsNullOrWhiteSpace(_config.ServerUrl) && !string.IsNullOrWhiteSpace(_config.BarkKey);
public override async Task SendAsync(SmsContentModel sms, string body, string deviceName, CancellationToken cancellationToken)
{
SmsCodeModel code = NotificationContentBuilder.ExtractCode(options, sms);
string url = $"{_config.ServerUrl.TrimEnd('/')}/{_config.BarkKey}/{HttpUtility.UrlEncode(body)}?group={HttpUtility.UrlEncode(sms.TelNumber)}&title={HttpUtility.UrlEncode(BuildTitle(sms.TelNumber, code.CodeValue))}";
if (!string.IsNullOrWhiteSpace(code.CodeValue))
{
url += $"&autoCopy=1&copy={HttpUtility.UrlEncode(code.CodeValue)}";
}
await HttpHelper.HttpGetAsync(url, _config.SkipTlsValidation, cancellationToken);
}
}