refine json

This commit is contained in:
Jicheng Lu 2024-04-18 13:54:43 -05:00
parent 02be7532c9
commit 59958bcf8b
13 changed files with 65 additions and 1 deletions

View file

@ -1,12 +1,15 @@
using BotSharp.Abstraction.Messaging.Enums;
using Newtonsoft.Json;
namespace BotSharp.Abstraction.Messaging;
public interface IRichMessage
{
[JsonPropertyName("text")]
[JsonProperty("text")]
string Text { get; set; }
[JsonPropertyName("rich_type")]
[JsonProperty("rich_type")]
string RichType => RichTypeEnum.Text;
}

View file

@ -1,7 +1,10 @@
using Newtonsoft.Json;
namespace BotSharp.Abstraction.Messaging;
public interface ITemplateMessage
{
[JsonPropertyName("template_type")]
[JsonProperty("template_type")]
string TemplateType => string.Empty;
}

View file

@ -1,3 +1,6 @@
using Newtonsoft.Json;
using JsonIgnoreAttribute = System.Text.Json.Serialization.JsonIgnoreAttribute;
namespace BotSharp.Abstraction.Messaging.Models.RichContent;
public class ElementAction
@ -8,6 +11,7 @@ public class ElementAction
public string Url { get; set; }
[JsonPropertyName("webview_height_ratio")]
[JsonProperty("webview_height_ratio")]
public string WebViewHeightRatio { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]

View file

@ -1,3 +1,6 @@
using Newtonsoft.Json;
using JsonIgnoreAttribute = System.Text.Json.Serialization.JsonIgnoreAttribute;
namespace BotSharp.Abstraction.Messaging.Models.RichContent;
/// <summary>
@ -16,11 +19,14 @@ public class ElementButton
public string Payload { get; set; }
[JsonPropertyName("is_primary")]
[JsonProperty("is_primary")]
public bool IsPrimary { get; set; }
[JsonPropertyName("is_secondary")]
[JsonProperty("is_secondary")]
public bool IsSecondary { get; set; }
[JsonPropertyName("post_action_disclaimer")]
[JsonProperty("post_action_disclaimer")]
public string? PostActionDisclaimer { get; set; }
}

View file

@ -1,3 +1,6 @@
using Newtonsoft.Json;
using JsonIgnoreAttribute = System.Text.Json.Serialization.JsonIgnoreAttribute;
namespace BotSharp.Abstraction.Messaging.Models.RichContent;
public class QuickReplyElement
@ -9,6 +12,7 @@ public class QuickReplyElement
public string? Payload { get; set; }
[JsonPropertyName("image_url")]
[JsonProperty("image_url")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? ImageUrl { get; set; }
}

View file

@ -1,13 +1,16 @@
using BotSharp.Abstraction.Messaging.Enums;
using Newtonsoft.Json;
namespace BotSharp.Abstraction.Messaging.Models.RichContent;
public class QuickReplyMessage : IRichMessage
{
[JsonPropertyName("rich_type")]
[JsonProperty("rich_type")]
public string RichType => RichTypeEnum.QuickReply;
public string Text { get; set; } = string.Empty;
[JsonPropertyName("quick_replies")]
[JsonProperty("quick_replies")]
public List<QuickReplyElement> QuickReplies { get; set; } = new List<QuickReplyElement>();
}

View file

@ -1,4 +1,5 @@
using BotSharp.Abstraction.Messaging.Enums;
using Newtonsoft.Json;
namespace BotSharp.Abstraction.Messaging.Models.RichContent.Template;
@ -8,17 +9,22 @@ namespace BotSharp.Abstraction.Messaging.Models.RichContent.Template;
public class ButtonTemplateMessage : IRichMessage, ITemplateMessage
{
[JsonPropertyName("rich_type")]
[JsonProperty("rich_type")]
public string RichType => RichTypeEnum.ButtonTemplate;
[JsonPropertyName("text")]
[JsonProperty("text")]
public string Text { get; set; } = string.Empty;
[JsonPropertyName("template_type")]
[JsonProperty("template_type")]
public string TemplateType => TemplateTypeEnum.Button;
[JsonPropertyName("buttons")]
[JsonProperty("buttons")]
public ElementButton[] Buttons { get; set; } = new ElementButton[0];
[JsonPropertyName("is_horizontal")]
[JsonProperty("is_horizontal")]
public bool IsHorizontal { get; set; }
}

View file

@ -1,4 +1,5 @@
using BotSharp.Abstraction.Messaging.Enums;
using Newtonsoft.Json;
namespace BotSharp.Abstraction.Messaging.Models.RichContent.Template;
@ -9,30 +10,40 @@ namespace BotSharp.Abstraction.Messaging.Models.RichContent.Template;
public class CouponTemplateMessage : IRichMessage, ITemplateMessage
{
[JsonPropertyName("rich_type")]
[JsonProperty("rich_type")]
public string RichType => RichTypeEnum.CouponTemplate;
[JsonPropertyName("text")]
[JsonProperty("text")]
public string Text { get; set; }
public string Title { get; set; }
public string Subtitle { get; set; }
[JsonPropertyName("template_type")]
[JsonProperty("template_type")]
public string TemplateType => TemplateTypeEnum.Coupon;
[JsonPropertyName("coupon_code")]
[JsonProperty("coupon_code")]
public string CouponCode { get; set; }
[JsonPropertyName("coupon_url")]
[JsonProperty("coupon_url")]
public string CouponUrl { get; set; }
[JsonPropertyName("coupon_url_button_title")]
[JsonProperty("coupon_url_button_title")]
public string CouponUrlButtonTitle { get; set; } = "Shop now";
[JsonPropertyName("coupon_pre_message")]
[JsonProperty("coupon_pre_message")]
public string CouponPreMessage { get; set; } = "Here's a deal just for you!";
[JsonPropertyName("image_url")]
[JsonProperty("image_url")]
public string ImageUrl { get; set; }
[JsonPropertyName("payload")]
[JsonProperty("payload")]
public string Payload { get; set; }
}

View file

@ -1,28 +1,36 @@
using BotSharp.Abstraction.Messaging.Enums;
using Newtonsoft.Json;
namespace BotSharp.Abstraction.Messaging.Models.RichContent.Template;
public class GenericTemplateMessage<T> : IRichMessage, ITemplateMessage
{
[JsonPropertyName("rich_type")]
[JsonProperty("rich_type")]
public string RichType => RichTypeEnum.GenericTemplate;
[JsonPropertyName("text")]
[JsonProperty("text")]
public string Text { get; set; } = string.Empty;
[JsonPropertyName("template_type")]
[JsonProperty("template_type")]
public virtual string TemplateType { get; set; } = TemplateTypeEnum.Generic;
[JsonPropertyName("elements")]
[JsonProperty("elements")]
public List<T> Elements { get; set; } = new List<T>();
[JsonPropertyName("is_horizontal")]
[JsonProperty("is_horizontal")]
public bool IsHorizontal { get; set; }
[JsonPropertyName("is_popup")]
[JsonProperty("is_popup")]
public bool IsPopup { get; set; }
[JsonPropertyName("element_type")]
[JsonProperty("element_type")]
public string ElementType => typeof(T).Name;
}
@ -30,9 +38,13 @@ public class GenericElement
{
public string Title { get; set; }
public string Subtitle { get; set; }
[JsonPropertyName("image_url")]
[JsonProperty("image_url")]
public string ImageUrl { get; set; }
[JsonPropertyName("default_action")]
[JsonProperty("default_action")]
public ElementAction DefaultAction { get; set; }
public ElementButton[] Buttons { get; set; }
}

View file

@ -1,21 +1,28 @@
using BotSharp.Abstraction.Messaging.Enums;
using Newtonsoft.Json;
namespace BotSharp.Abstraction.Messaging.Models.RichContent.Template;
public class MultiSelectTemplateMessage : IRichMessage, ITemplateMessage
{
[JsonPropertyName("rich_type")]
[JsonProperty("rich_type")]
public string RichType => RichTypeEnum.MultiSelectTemplate;
[JsonPropertyName("text")]
[JsonProperty("text")]
public string Text { get; set; } = string.Empty;
[JsonPropertyName("template_type")]
[JsonProperty("template_type")]
public string TemplateType => TemplateTypeEnum.MultiSelect;
[JsonPropertyName("options")]
[JsonProperty("options")]
public List<OptionElement> Options { get; set; } = new List<OptionElement>();
[JsonPropertyName("is_horizontal")]
[JsonProperty("is_horizontal")]
public bool IsHorizontal { get; set; }
}

View file

@ -1,16 +1,20 @@
using BotSharp.Abstraction.Messaging.Enums;
using Newtonsoft.Json;
namespace BotSharp.Abstraction.Messaging.Models.RichContent.Template;
public class ProductTemplateMessage : IRichMessage, ITemplateMessage
{
[JsonPropertyName("rich_type")]
[JsonProperty("rich_type")]
public string RichType => RichTypeEnum.GenericTemplate;
[JsonPropertyName("text")]
[JsonProperty("text")]
public string Text { get; set; } = string.Empty;
[JsonPropertyName("template_type")]
[JsonProperty("template_type")]
public string TemplateType => TemplateTypeEnum.Product;
}

View file

@ -1,10 +1,12 @@
using BotSharp.Abstraction.Messaging.Enums;
using Newtonsoft.Json;
namespace BotSharp.Abstraction.Messaging.Models.RichContent;
public class TextMessage : IRichMessage
{
[JsonPropertyName("rich_type")]
[JsonProperty("rich_type")]
public string RichType => RichTypeEnum.Text;
public string Text { get; set; } = string.Empty;

View file

@ -5,7 +5,6 @@ using System.Drawing;
using System.IO;
using System.Reflection;
using System.Xml;
using BotSharp.Abstraction.Repositories;
namespace BotSharp.Core.Plugins;