Merge pull request #195 from ywang1110/add_richContent
Add and Default RichContent for UI Rendering Purpose
This commit is contained in:
commit
2146f6e95e
|
|
@ -31,8 +31,4 @@
|
||||||
<PackageReference Include="System.Text.Json" Version="7.0.3" />
|
<PackageReference Include="System.Text.Json" Version="7.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Messaging\Models\" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace BotSharp.Abstraction.Conversations;
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IConversationStateService
|
public interface IConversationStateService
|
||||||
{
|
{
|
||||||
|
string GetConversationId();
|
||||||
ConversationState Load(string conversationId);
|
ConversationState Load(string conversationId);
|
||||||
string GetState(string name, string defaultValue = "");
|
string GetState(string name, string defaultValue = "");
|
||||||
bool ContainsState(string name);
|
bool ContainsState(string name);
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,8 @@ public class RoleDialogModel : ITrackableMessage
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||||
public object Data { get; set; }
|
public object Data { get; set; }
|
||||||
|
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||||
|
public object? RichContent { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Stop conversation completion
|
/// Stop conversation completion
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
|
||||||
|
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; }
|
||||||
|
[JsonPropertyName("postback_url")]
|
||||||
|
public string? PostBackUrl { 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; } = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
namespace BotSharp.Abstraction.Messaging.Models.RichContent
|
||||||
|
{
|
||||||
|
public class RichContent<T>
|
||||||
|
{
|
||||||
|
public Recipient Recipient { get; set; } = new Recipient();
|
||||||
|
/// <summary>
|
||||||
|
/// RESPONSE
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("messaging_type")]
|
||||||
|
public string MessagingType => "RESPONSE";
|
||||||
|
public T Message { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
|
||||||
|
namespace BotSharp.Abstraction.Messaging.Models.RichContent
|
||||||
|
{
|
||||||
|
public class SenderActionMessage
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Requests to display sender action should only include the sender_action parameter and the recipient object.
|
||||||
|
* All other Send API properties, such as text and templates, should be sent in a separate request.
|
||||||
|
*/
|
||||||
|
public Recipient Recipient { get; set; } = new Recipient();
|
||||||
|
|
||||||
|
[JsonPropertyName("sender_action")]
|
||||||
|
public string SenderAction { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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,17 @@
|
||||||
|
|
||||||
|
namespace BotSharp.Abstraction.Messaging.Models.RichContent.Template
|
||||||
|
{
|
||||||
|
public class ButtonTemplate : TextMessage
|
||||||
|
{
|
||||||
|
[JsonPropertyName("template_type")]
|
||||||
|
public string TemplateType => "button";
|
||||||
|
public List<ButtonElement> Buttons { get; set; } = new List<ButtonElement>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ButtonElement
|
||||||
|
{
|
||||||
|
public string Type { get; set; } = string.Empty;
|
||||||
|
public string? Url { get; set; }
|
||||||
|
public string Title { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
|
||||||
|
namespace BotSharp.Abstraction.Messaging.Models.RichContent.Template
|
||||||
|
{
|
||||||
|
public class CommonTemplate<T>
|
||||||
|
{
|
||||||
|
[JsonPropertyName("template_type")]
|
||||||
|
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 T Attachment { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
|
||||||
|
namespace BotSharp.Abstraction.Messaging.Models.RichContent
|
||||||
|
{
|
||||||
|
public class TextMessage
|
||||||
|
{
|
||||||
|
public string Text { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using BotSharp.Abstraction.Agents.Models;
|
using BotSharp.Abstraction.Agents.Models;
|
||||||
|
using BotSharp.Abstraction.Messaging.Models.RichContent;
|
||||||
using BotSharp.Abstraction.Routing;
|
using BotSharp.Abstraction.Routing;
|
||||||
using BotSharp.Abstraction.Routing.Settings;
|
using BotSharp.Abstraction.Routing.Settings;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
|
@ -100,6 +101,14 @@ public partial class ConversationService
|
||||||
_logger.LogInformation(text);
|
_logger.LogInformation(text);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Only read content from RichContent for UI rendering. When richContent is null, create a basic text message for richContent.
|
||||||
|
var state = _services.GetRequiredService<IConversationStateService>();
|
||||||
|
message.RichContent = message.RichContent ?? new RichContent<TextMessage>
|
||||||
|
{
|
||||||
|
Recipient = new Recipient { Id = state.GetConversationId() },
|
||||||
|
Message = new TextMessage { Text = message.Content }
|
||||||
|
};
|
||||||
|
|
||||||
var hooks = _services.GetServices<IConversationHook>().ToList();
|
var hooks = _services.GetServices<IConversationHook>().ToList();
|
||||||
foreach (var hook in hooks)
|
foreach (var hook in hooks)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,8 @@ public class ConversationStateService : IConversationStateService, IDisposable
|
||||||
_states = new ConversationState();
|
_states = new ConversationState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string GetConversationId() => _conversationId;
|
||||||
|
|
||||||
public IConversationStateService SetState<T>(string name, T value)
|
public IConversationStateService SetState<T>(string name, T value)
|
||||||
{
|
{
|
||||||
if (value == null)
|
if (value == null)
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ public class ConversationController : ControllerBase, IApiAdapter
|
||||||
private readonly IServiceProvider _services;
|
private readonly IServiceProvider _services;
|
||||||
private readonly IUserIdentity _user;
|
private readonly IUserIdentity _user;
|
||||||
|
|
||||||
public ConversationController(IServiceProvider services,
|
public ConversationController(IServiceProvider services,
|
||||||
IUserIdentity user)
|
IUserIdentity user)
|
||||||
{
|
{
|
||||||
_services = services;
|
_services = services;
|
||||||
|
|
@ -40,8 +40,8 @@ public class ConversationController : ControllerBase, IApiAdapter
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("/conversation/{agentId}/{conversationId}")]
|
[HttpPost("/conversation/{agentId}/{conversationId}")]
|
||||||
public async Task<MessageResponseModel> SendMessage([FromRoute] string agentId,
|
public async Task<MessageResponseModel> SendMessage([FromRoute] string agentId,
|
||||||
[FromRoute] string conversationId,
|
[FromRoute] string conversationId,
|
||||||
[FromBody] NewMessageModel input)
|
[FromBody] NewMessageModel input)
|
||||||
{
|
{
|
||||||
var conv = _services.GetRequiredService<IConversationService>();
|
var conv = _services.GetRequiredService<IConversationService>();
|
||||||
|
|
@ -73,6 +73,7 @@ public class ConversationController : ControllerBase, IApiAdapter
|
||||||
response.Data = inputMsg.Data;
|
response.Data = inputMsg.Data;
|
||||||
response.Function = inputMsg.FunctionName;
|
response.Function = inputMsg.FunctionName;
|
||||||
response.Instruction = inputMsg.Instruction;
|
response.Instruction = inputMsg.Instruction;
|
||||||
|
response.RichContent = inputMsg.RichContent;
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
using BotSharp.Abstraction.Functions.Models;
|
using BotSharp.Abstraction.Functions.Models;
|
||||||
using BotSharp.Abstraction.Models;
|
using BotSharp.Abstraction.Models;
|
||||||
using BotSharp.Abstraction.Routing.Models;
|
|
||||||
|
|
||||||
namespace BotSharp.OpenAPI.ViewModels.Conversations;
|
namespace BotSharp.OpenAPI.ViewModels.Conversations;
|
||||||
|
|
||||||
|
|
@ -11,4 +10,5 @@ public class MessageResponseModel : ITrackableMessage
|
||||||
public string Function { get; set; }
|
public string Function { get; set; }
|
||||||
public object Data { get; set; }
|
public object Data { get; set; }
|
||||||
public FunctionCallFromLlm Instruction { get; set; }
|
public FunctionCallFromLlm Instruction { get; set; }
|
||||||
|
public object? RichContent { get; set; }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue