From 6cc63913d4bad0b46c7d35f4469e53d40b16204c Mon Sep 17 00:00:00 2001 From: Haiping Chen <101423@smsassist.com> Date: Tue, 19 Mar 2024 11:08:28 -0500 Subject: [PATCH] Support editor in rich content. --- .../Messaging/Enums/EditorTypeEnum.cs | 20 +++++++++++++++++++ .../Models/RichContent/RichContent.cs | 15 ++++++++++++++ .../Services/ConversationStorage.cs | 2 -- .../Hooks/StreamingLogHook.cs | 2 +- 4 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 src/Infrastructure/BotSharp.Abstraction/Messaging/Enums/EditorTypeEnum.cs diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/Enums/EditorTypeEnum.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/Enums/EditorTypeEnum.cs new file mode 100644 index 00000000..f190e5e5 --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/Enums/EditorTypeEnum.cs @@ -0,0 +1,20 @@ +namespace BotSharp.Abstraction.Messaging.Enums; + +public static class EditorTypeEnum +{ + /// + /// Disable user input freeform text + /// + public const string None = "none"; + public const string Text = "text"; + public const string Address = "address"; + public const string Phone = "phone"; + public const string DateTimePicker = "datetime-picker"; + public const string DateTimeRangePicker = "datetime-range-picker"; + public const string Email = "email"; + + /// + /// Regex, set the expression in editor_attributes + /// + public const string Regex = "regex"; +} diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/RichContent.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/RichContent.cs index 6ba617e7..c8c3b3fe 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/RichContent.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/RichContent.cs @@ -1,3 +1,5 @@ +using BotSharp.Abstraction.Messaging.Enums; + namespace BotSharp.Abstraction.Messaging.Models.RichContent; public class RichContent where T : IRichMessage @@ -16,6 +18,14 @@ public class RichContent where T : IRichMessage [JsonPropertyName("fill_postback")] public bool FillPostback { get; set; } + [JsonPropertyName("editor")] + public string Editor { get; set; } = EditorTypeEnum.Text; + + [JsonPropertyName("editor_attributes")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? EditorAttributes { get; set; } + + public RichContent() { @@ -25,4 +35,9 @@ public class RichContent where T : IRichMessage { Message = message; } + + public override string ToString() + { + return $"{MessagingType} {typeof(T).Name}"; + } } diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs index 24ee97be..33717410 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs @@ -2,8 +2,6 @@ using BotSharp.Abstraction.Messaging; using BotSharp.Abstraction.Messaging.JsonConverters; using BotSharp.Abstraction.Messaging.Models.RichContent; using BotSharp.Abstraction.Options; -using BotSharp.Abstraction.Repositories; -using System; using System.IO; namespace BotSharp.Core.Conversations.Services; diff --git a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs index ffc1c987..bc90877a 100644 --- a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs +++ b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs @@ -139,7 +139,7 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR { var agent = await _agentService.LoadAgent(message.CurrentAgentId); var log = $"{message.Content}"; - if (message.RichContent != null && message.RichContent.Message.RichType != "text") + if (message.RichContent != null) { var richContent = JsonSerializer.Serialize(message.RichContent, _options.JsonSerializerOptions); log += $"\r\n```json\r\n{richContent}\r\n```";