Add Conversation status.

This commit is contained in:
Haiping Chen 2023-11-15 07:33:46 -06:00
parent 8fc3d94a28
commit 3eb2e7664e
9 changed files with 78 additions and 15 deletions

View file

@ -65,10 +65,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Plugin.GoogleAI",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Plugin.SemanticKernel", "src\Plugins\BotSharp.Plugin.SemanticKernel\BotSharp.Plugin.SemanticKernel.csproj", "{73EE2CD0-3B27-4F02-A67B-762CBDD740D0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Plugin.SemanticKernel.UnitTests", "tests\BotSharp.Plugin.SemanticKernel.UnitTests\BotSharp.Plugin.SemanticKernel.UnitTests.csproj", "{BC57D428-A1A4-4D38-A2D0-AC6CA943F247}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Plugin.SemanticKernel.UnitTests", "tests\BotSharp.Plugin.SemanticKernel.UnitTests\BotSharp.Plugin.SemanticKernel.UnitTests.csproj", "{BC57D428-A1A4-4D38-A2D0-AC6CA943F247}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Plugin.Twilio", "src\Plugins\BotSharp.Plugin.Twilio\BotSharp.Plugin.Twilio.csproj", "{E627F1E3-BE03-443A-83A2-86A855A278EB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Plugin.WebDriver", "src\Plugins\BotSharp.Plugin.WebDriver\BotSharp.Plugin.WebDriver.csproj", "{F06B22CB-B143-4680-8FFF-35B9E50E6C47}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -253,6 +255,14 @@ Global
{E627F1E3-BE03-443A-83A2-86A855A278EB}.Release|Any CPU.Build.0 = Release|Any CPU
{E627F1E3-BE03-443A-83A2-86A855A278EB}.Release|x64.ActiveCfg = Release|Any CPU
{E627F1E3-BE03-443A-83A2-86A855A278EB}.Release|x64.Build.0 = Release|Any CPU
{F06B22CB-B143-4680-8FFF-35B9E50E6C47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F06B22CB-B143-4680-8FFF-35B9E50E6C47}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F06B22CB-B143-4680-8FFF-35B9E50E6C47}.Debug|x64.ActiveCfg = Debug|Any CPU
{F06B22CB-B143-4680-8FFF-35B9E50E6C47}.Debug|x64.Build.0 = Debug|Any CPU
{F06B22CB-B143-4680-8FFF-35B9E50E6C47}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F06B22CB-B143-4680-8FFF-35B9E50E6C47}.Release|Any CPU.Build.0 = Release|Any CPU
{F06B22CB-B143-4680-8FFF-35B9E50E6C47}.Release|x64.ActiveCfg = Release|Any CPU
{F06B22CB-B143-4680-8FFF-35B9E50E6C47}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -287,6 +297,7 @@ Global
{73EE2CD0-3B27-4F02-A67B-762CBDD740D0} = {D5293208-2BEF-42FC-A64C-5954F61720BA}
{BC57D428-A1A4-4D38-A2D0-AC6CA943F247} = {32FAFFFE-A4CB-4FEE-BF7C-84518BBC6DCC}
{E627F1E3-BE03-443A-83A2-86A855A278EB} = {64264688-0F5C-4AB0-8F2B-B59B717CCE00}
{F06B22CB-B143-4680-8FFF-35B9E50E6C47} = {51AFE054-AE99-497D-A593-69BAEFB5106F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A9969D89-C98B-40A5-A12B-FC87E55B3A19}

View file

@ -0,0 +1,7 @@
namespace BotSharp.Abstraction.Conversations.Enums;
public class ConversationStatus
{
public const string Open = "open";
public const string Closed = "closed";
}

View file

@ -1,4 +1,4 @@
using System.Text.Json.Serialization;
using BotSharp.Abstraction.Conversations.Enums;
namespace BotSharp.Abstraction.Conversations.Models;
@ -8,11 +8,15 @@ public class Conversation
public string AgentId { get; set; } = string.Empty;
public string UserId { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
[JsonIgnore]
public string Dialog { get; set; } = string.Empty;
[JsonIgnore]
public ConversationState States { get; set; }
public string Status { get; set; } = ConversationStatus.Open;
public DateTime UpdatedTime { get; set; } = DateTime.UtcNow;
public DateTime CreatedTime { get; set; } = DateTime.UtcNow;
}

View file

@ -101,7 +101,7 @@ public class UserService : IUserService
return user;
}
[MemoryCache(60)]
[MemoryCache(10 * 60)]
public async Task<User> GetUser(string id)
{
var db = _services.GetRequiredService<IBotSharpRepository>();

View file

@ -44,18 +44,7 @@ public class ConversationController : ControllerBase, IApiAdapter
var service = _services.GetRequiredService<IConversationService>();
var conversations = await service.GetConversations();
var userService = _services.GetRequiredService<IUserService>();
var list = conversations.Select(x => new ConversationViewModel
{
Id = x.Id,
AgentId = x.AgentId,
Title = x.Title,
User = new UserViewModel
{
Id = x.UserId,
},
CreatedTime = x.CreatedTime,
UpdatedTime = x.UpdatedTime
}).ToList();
var list = conversations.Select(x => ConversationViewModel.FromSession(x)).ToList();
foreach (var item in list)
{

View file

@ -1,16 +1,30 @@
using BotSharp.Abstraction.Conversations.Models;
using BotSharp.OpenAPI.ViewModels.Users;
using System.Text.Json.Serialization;
namespace BotSharp.OpenAPI.ViewModels.Conversations;
public class ConversationViewModel
{
public string Id { get; set; }
[JsonPropertyName("agent_id")]
public string AgentId { get; set; }
public string Title { get; set; } = string.Empty;
public UserViewModel User { get; set; } = new UserViewModel();
[JsonPropertyName("unread_msg_count")]
public int UnreadMsgCount { get; set; }
public string Event { get; set; }
public string Status { get; set; }
[JsonPropertyName("updated_time")]
public DateTime UpdatedTime { get; set; } = DateTime.UtcNow;
[JsonPropertyName("created_time")]
public DateTime CreatedTime { get; set; } = DateTime.UtcNow;
public static ConversationViewModel FromSession(Conversation sess)
@ -24,6 +38,7 @@ public class ConversationViewModel
},
AgentId = sess.AgentId,
Title = sess.Title,
Status = sess.Status,
CreatedTime = sess.CreatedTime,
UpdatedTime = sess.UpdatedTime
};

View file

@ -1,3 +1,4 @@
using BotSharp.Abstraction.Agents.Enums;
using BotSharp.Abstraction.Users.Enums;
using BotSharp.Abstraction.Users.Models;
using System.Text.Json.Serialization;
@ -18,6 +19,16 @@ public class UserViewModel
public static UserViewModel FromUser(User user)
{
if (user == null)
{
return new UserViewModel
{
FirstName = "AI",
LastName = "Assistant",
Role = AgentRole.Assistant
};
}
return new UserViewModel
{
Id = user.Id,

View file

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Infrastructure\BotSharp.Abstraction\BotSharp.Abstraction.csproj" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,14 @@
using BotSharp.Abstraction.Plugins;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace BotSharp.Plugin.WebDriver;
public class WebDriverPlugin : IBotSharpPlugin
{
public string Name => "Web Driver";
public void RegisterDI(IServiceCollection services, IConfiguration config)
{
}
}