添加项目文件。
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace MessageService.Domain.KeyObjects
|
||||
{
|
||||
public class MessageContent
|
||||
{
|
||||
// 兜底文本
|
||||
[JsonPropertyName("fallback")]
|
||||
public string Fallback { get; init; }
|
||||
|
||||
// 核心 Payload,反序列化时根据外层 MessageType 转换为具体子类
|
||||
public string RawBody { get; init; }
|
||||
public string RawExt { get; set; } = string.Empty;
|
||||
[JsonPropertyName("body")]
|
||||
// 业务代码使用的对象
|
||||
[NotMapped]
|
||||
public object Body => string.IsNullOrEmpty(RawBody) ? null : JsonSerializer.Deserialize<object>(RawBody);
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<string, string> Ext => string.IsNullOrEmpty(RawExt)
|
||||
? new()
|
||||
: JsonSerializer.Deserialize<Dictionary<string, string>>(RawExt);
|
||||
|
||||
// 引用信息
|
||||
[JsonPropertyName("quote")]
|
||||
public QuoteInfo Quote { get; set; } = new();
|
||||
|
||||
private MessageContent() { }
|
||||
public MessageContent(string fallback, object body)
|
||||
{
|
||||
Fallback = fallback;
|
||||
RawBody = body == null ? null : JsonSerializer.Serialize(body);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user