Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support editor in rich content. #350

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace BotSharp.Abstraction.Messaging.Enums;

public static class EditorTypeEnum
{
/// <summary>
/// Disable user input freeform text
/// </summary>
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";

/// <summary>
/// Regex, set the expression in editor_attributes
/// </summary>
public const string Regex = "regex";
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using BotSharp.Abstraction.Messaging.Enums;

namespace BotSharp.Abstraction.Messaging.Models.RichContent;

public class RichContent<T> where T : IRichMessage
Expand All @@ -16,6 +18,14 @@ public class RichContent<T> 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()
{

Expand All @@ -25,4 +35,9 @@ public RichContent(T message)
{
Message = message;
}

public override string ToString()
{
return $"{MessagingType} {typeof(T).Name}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public override async Task OnResponseGenerated(RoleDialogModel message)
{
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```";
Expand Down