Files
IOT_API/Service/Interface/Inspection/IAlertNotifier.cs
T

68 lines
2.3 KiB
C#

using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace Service.Interface
{
/// <summary>
/// 通知消息(Notifier 统一入参:与具体渠道报文格式解耦)
/// </summary>
public class AlertNotifyMessage
{
/// <summary>
/// 消息标题
/// </summary>
public string Title { get; set; } = "设备告警";
/// <summary>
/// 消息正文(markdown 语法,各 Notifier 按需降级为纯文本)
/// </summary>
public string Content { get; set; } = string.Empty;
/// <summary>
/// @ 手机号列表(钉钉/企微支持;飞书文本追加展示)
/// </summary>
public List<string> AtMobiles { get; set; } = new();
}
/// <summary>
/// 通知发送结果
/// </summary>
public class NotifyResult
{
/// <summary>
/// 是否成功
/// </summary>
public bool Success { get; set; }
/// <summary>
/// 错误信息(失败时填写,含渠道响应原文摘要)
/// </summary>
public string? ErrorMsg { get; set; }
public static NotifyResult Ok() => new() { Success = true };
public static NotifyResult Fail(string msg) => new() { Success = false, ErrorMsg = msg };
}
/// <summary>
/// 告警通知渠道发送器抽象(一期:飞书/钉钉/企微 Webhook 机器人)
/// 扩展新渠道(如短信网关)只需实现本接口并在 DependencyInjection.AddAlertNotification 注册,调用方零改动
/// </summary>
public interface IAlertNotifier
{
/// <summary>
/// 本发送器支持的渠道类型
/// </summary>
Model.Entity.Inspection.NotifyChannelTypeEnum ChannelType { get; }
/// <summary>
/// 发送消息
/// </summary>
/// <param name="message">统一通知消息</param>
/// <param name="webhookUrl">渠道 Webhook 地址</param>
/// <param name="secret">加签密钥(可空:未开启加签)</param>
/// <param name="ct">取消令牌</param>
Task<NotifyResult> SendAsync(AlertNotifyMessage message, string webhookUrl, string? secret, CancellationToken ct = default);
}
}