Add richContent for future UI rendering
This commit is contained in:
parent
209a009aa1
commit
46710c14cc
|
|
@ -31,8 +31,4 @@
|
|||
<PackageReference Include="System.Text.Json" Version="7.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Messaging\Models\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ namespace BotSharp.Abstraction.Conversations;
|
|||
/// </summary>
|
||||
public interface IConversationStateService
|
||||
{
|
||||
string GetConversationId();
|
||||
ConversationState Load(string conversationId);
|
||||
string GetState(string name, string defaultValue = "");
|
||||
bool ContainsState(string name);
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ public class RoleDialogModel
|
|||
/// </summary>
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public object Data { get; set; }
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public object? RichContent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Stop conversation completion
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
namespace BotSharp.Abstraction.Messaging.Models.RichContent
|
||||
{
|
||||
public class QuickReplyElement
|
||||
{
|
||||
[JsonPropertyName("content_type")]
|
||||
public string ContentType { get; set; } = string.Empty;
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public string? Payload { get; set; }
|
||||
[JsonPropertyName("image_url")]
|
||||
public string? ImageUrl { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
namespace BotSharp.Abstraction.Messaging.Models.RichContent
|
||||
{
|
||||
public class QuickReplyMessage : TextMessage
|
||||
{
|
||||
[JsonPropertyName("quick_replies")]
|
||||
public List<QuickReplyElement> QuickReplies { get; set; } = new List<QuickReplyElement>();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
namespace BotSharp.Abstraction.Messaging.Models.RichContent
|
||||
{
|
||||
public class Recipient
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
namespace BotSharp.Abstraction.Messaging.Models.RichContent
|
||||
{
|
||||
public class RichContent<T>
|
||||
{
|
||||
public Recipient? Recipient { get; set; }
|
||||
/// <summary>
|
||||
/// RESPONSE
|
||||
/// </summary>
|
||||
[JsonPropertyName("messaging_type")]
|
||||
public string MessageingType { get; set; } = string.Empty;
|
||||
public T Message { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
namespace BotSharp.Abstraction.Messaging.Models.RichContent.Template
|
||||
{
|
||||
public class AttachmentTemplate<T>
|
||||
{
|
||||
public string Type => "template";
|
||||
public T Payload { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
|
||||
namespace BotSharp.Abstraction.Messaging.Models.RichContent.Template
|
||||
{
|
||||
public class ButtonTemplate : TextMessage
|
||||
{
|
||||
public string TemplateType => "button";
|
||||
public List<ButtonElement> Buttons { get; set; } = new List<ButtonElement>();
|
||||
}
|
||||
|
||||
public class ButtonElement
|
||||
{
|
||||
public string? Type { get; set; }
|
||||
public string? Url { get; set; }
|
||||
public string? Title { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
namespace BotSharp.Abstraction.Messaging.Models.RichContent.Template
|
||||
{
|
||||
public class CommonTemplate<T>
|
||||
{
|
||||
public string TemplateType { get; set; } = string.Empty;
|
||||
public T Elements { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace BotSharp.Abstraction.Messaging.Models.RichContent.Template
|
||||
{
|
||||
public class TemplateMessage<T>
|
||||
{
|
||||
public AttachmentTemplate<T> Attachment { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
namespace BotSharp.Abstraction.Messaging.Models.RichContent
|
||||
{
|
||||
public class TextMessage
|
||||
{
|
||||
public string? Text { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -28,6 +28,8 @@ public class ConversationStateService : IConversationStateService, IDisposable
|
|||
_states = new ConversationState();
|
||||
}
|
||||
|
||||
public string GetConversationId() => _conversationId;
|
||||
|
||||
public IConversationStateService SetState<T>(string name, T value)
|
||||
{
|
||||
if (value == null)
|
||||
|
|
|
|||
|
|
@ -66,11 +66,13 @@ public class ConversationController : ControllerBase, IApiAdapter
|
|||
{
|
||||
response.Function = fnExecuted.FunctionName;
|
||||
response.Data = fnExecuted.Data;
|
||||
response.RichContent = fnExecuted.RichContent;
|
||||
});
|
||||
|
||||
response.Text = string.Join("\r\n", stackMsg.Select(x => x.Content));
|
||||
response.Data = response.Data ?? stackMsg.Last().Data;
|
||||
response.Function = stackMsg.Last().FunctionName;
|
||||
response.RichContent = response.RichContent ?? stackMsg.Last().RichContent;
|
||||
|
||||
return response;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,4 +5,5 @@ public class MessageResponseModel
|
|||
public string Text { get; set; }
|
||||
public string Function { get; set; }
|
||||
public object Data { get; set; }
|
||||
public object? RichContent { get; set; }
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue