diff --git a/src/Infrastructure/BotSharp.Abstraction/BotSharp.Abstraction.csproj b/src/Infrastructure/BotSharp.Abstraction/BotSharp.Abstraction.csproj index 1419d509..98449d96 100644 --- a/src/Infrastructure/BotSharp.Abstraction/BotSharp.Abstraction.csproj +++ b/src/Infrastructure/BotSharp.Abstraction/BotSharp.Abstraction.csproj @@ -8,6 +8,12 @@ Icon.png + + + + + + True @@ -22,8 +28,4 @@ - - - - diff --git a/src/Infrastructure/BotSharp.Abstraction/Utilities/StringExtensions.cs b/src/Infrastructure/BotSharp.Abstraction/Utilities/StringExtensions.cs new file mode 100644 index 00000000..8352bcff --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Utilities/StringExtensions.cs @@ -0,0 +1,7 @@ +namespace BotSharp.Abstraction.Utilities; + +public static class StringExtensions +{ + public static string IfNullOrEmptyAs(this string str, string defaultValue) + => string.IsNullOrEmpty(str) ? defaultValue : str; +} diff --git a/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj b/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj index 4f5e5df0..5d00e58d 100644 --- a/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj +++ b/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj @@ -34,14 +34,25 @@ https://raw.githubusercontent.com/SciSharp/BotSharp/master/docs/static/logos/BotSharp.png https://raw.githubusercontent.com/SciSharp/BotSharp/master/LICENSE Icon.png + enable TRACE;DEBUG + 1701;1702 TRACE; + 1701;1702 + + + + 1701;1702 + + + + 1701;1702 diff --git a/src/Infrastructure/BotSharp.Core/Conversations/ConversationController.cs b/src/Infrastructure/BotSharp.Core/Conversations/ConversationController.cs index 3cc82b0c..debb5db3 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/ConversationController.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/ConversationController.cs @@ -26,6 +26,7 @@ public class ConversationController : ControllerBase, IApiAdapter var service = _services.GetRequiredService(); var sess = new Conversation { + UserId = _user.Id, AgentId = agentId }; sess = await service.NewConversation(sess); @@ -49,7 +50,7 @@ public class ConversationController : ControllerBase, IApiAdapter return new MessageResponseModel { - Content = result + Text = result }; } } diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs index 03ab2b36..9f89a15f 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs @@ -53,8 +53,8 @@ public class ConversationService : IConversationService var db = _services.GetRequiredService(); var record = ConversationRecord.FromConversation(sess); - record.Id = sess.Id ?? Guid.NewGuid().ToString(); - record.UserId = sess.UserId ?? _user.Id; + record.Id = sess.Id.IfNullOrEmptyAs(Guid.NewGuid().ToString()); + record.UserId = sess.UserId.IfNullOrEmptyAs(_user.Id); record.Title = "New Conversation"; db.Transaction(delegate diff --git a/src/Infrastructure/BotSharp.Core/Conversations/ViewModels/MessageResponseModel.cs b/src/Infrastructure/BotSharp.Core/Conversations/ViewModels/MessageResponseModel.cs index 2a2f050d..68f58a5f 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/ViewModels/MessageResponseModel.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/ViewModels/MessageResponseModel.cs @@ -2,5 +2,5 @@ namespace BotSharp.Core.Conversations.ViewModels; public class MessageResponseModel { - public string Content { get; set; } + public string Text { get; set; } } diff --git a/src/Infrastructure/BotSharp.Core/Using.cs b/src/Infrastructure/BotSharp.Core/Using.cs index 28976df7..304bcf8c 100644 --- a/src/Infrastructure/BotSharp.Core/Using.cs +++ b/src/Infrastructure/BotSharp.Core/Using.cs @@ -10,6 +10,7 @@ global using BotSharp.Abstraction.Agents; global using BotSharp.Abstraction.Conversations; global using BotSharp.Abstraction.Knowledges; global using BotSharp.Abstraction.Users; +global using BotSharp.Abstraction.Utilities; global using BotSharp.Core.Repository; global using BotSharp.Core.Repository.Abstraction; global using BotSharp.Core.Repository.DbTables; diff --git a/src/Plugins/BotSharp.Plugin.ChatbotUI/ChatbotUiController.cs b/src/Plugins/BotSharp.Plugin.ChatbotUI/ChatbotUiController.cs index ab671a2f..0337c983 100644 --- a/src/Plugins/BotSharp.Plugin.ChatbotUI/ChatbotUiController.cs +++ b/src/Plugins/BotSharp.Plugin.ChatbotUI/ChatbotUiController.cs @@ -16,9 +16,11 @@ using BotSharp.Plugin.ChatbotUI.ViewModels; using Microsoft.Extensions.DependencyInjection; using BotSharp.Abstraction.Conversations; using BotSharp.Abstraction.Conversations.Models; +using Microsoft.AspNetCore.Authorization; namespace BotSharp.Plugin.ChatbotUI.Controllers; +[Authorize] [ApiController] public class ChatbotUiController : ControllerBase, IApiAdapter { @@ -72,7 +74,6 @@ public class ChatbotUiController : ControllerBase, IApiAdapter var sess = new Conversation { Id = input.ConversationId, - UserId = Guid.Empty.ToString(), AgentId = input.AgentId }; converation = await conversationService.NewConversation(sess);