From c21255979b1b502f0e3809c07addf467f5e648e9 Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Mon, 13 Nov 2023 10:47:27 -0600 Subject: [PATCH] Remove ChatHub. --- .../Plugins/Models/PluginDef.cs | 1 + .../BotSharp.Core/Plugins/PluginLoader.cs | 1 + .../BotSharp.OpenAPI/BotSharp.OpenAPI.csproj | 1 - .../BotSharp.OpenAPI/ChatHub.cs | 47 ---------- .../Controllers/ChatHubController.cs | 85 ------------------- .../MetaMessengerPlugin.cs | 2 + .../BotSharp.Plugin.Twilio/TwilioPlugin.cs | 6 +- .../PizzaBotPlugin.cs | 1 + 8 files changed, 8 insertions(+), 136 deletions(-) delete mode 100644 src/Infrastructure/BotSharp.OpenAPI/ChatHub.cs delete mode 100644 src/Infrastructure/BotSharp.OpenAPI/Controllers/ChatHubController.cs diff --git a/src/Infrastructure/BotSharp.Abstraction/Plugins/Models/PluginDef.cs b/src/Infrastructure/BotSharp.Abstraction/Plugins/Models/PluginDef.cs index 85128209..c297286b 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Plugins/Models/PluginDef.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Plugins/Models/PluginDef.cs @@ -2,6 +2,7 @@ namespace BotSharp.Abstraction.Plugins.Models; public class PluginDef { + public string Id { get; set; } public string Name { get; set; } public string Description { get; set; } public string Assembly { get; set; } diff --git a/src/Infrastructure/BotSharp.Core/Plugins/PluginLoader.cs b/src/Infrastructure/BotSharp.Core/Plugins/PluginLoader.cs index 3f28d22c..aefe2e8b 100644 --- a/src/Infrastructure/BotSharp.Core/Plugins/PluginLoader.cs +++ b/src/Infrastructure/BotSharp.Core/Plugins/PluginLoader.cs @@ -51,6 +51,7 @@ public class PluginLoader _modules.Add(module); _plugins.Add(new PluginDef { + Id = module.GetType().FullName, Name = name, Description = module.Description, Assembly = assemblyName diff --git a/src/Infrastructure/BotSharp.OpenAPI/BotSharp.OpenAPI.csproj b/src/Infrastructure/BotSharp.OpenAPI/BotSharp.OpenAPI.csproj index f0de437a..cef8a0e6 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/BotSharp.OpenAPI.csproj +++ b/src/Infrastructure/BotSharp.OpenAPI/BotSharp.OpenAPI.csproj @@ -11,7 +11,6 @@ - diff --git a/src/Infrastructure/BotSharp.OpenAPI/ChatHub.cs b/src/Infrastructure/BotSharp.OpenAPI/ChatHub.cs deleted file mode 100644 index 2131a412..00000000 --- a/src/Infrastructure/BotSharp.OpenAPI/ChatHub.cs +++ /dev/null @@ -1,47 +0,0 @@ -using Microsoft.AspNetCore.SignalR; - -namespace BotSharp.OpenAPI; - -public class ChatHub : Hub -{ - private readonly IServiceProvider _services; - private readonly ILogger _logger; - private readonly IUserIdentity _user; - - public ChatHub(IServiceProvider services, - ILogger logger, - IUserIdentity user) - { - _services = services; - _logger = logger; - _user = user; - } - - public async Task OnMessageReceivedFromClient(string message) - { - // await Clients.User(_user.Id).SendAsync("ReceiveMessage", message); - } - - /// - /// Received message from client - /// - /// - /// - /// - public async Task SendMessage(string user, string message) - { - // await Clients.User(_user.Id).SendAsync("ReceiveMessage", message); - } - - public async Task SendMessageToCaller(string user, string message) - => await Clients.Caller.SendAsync("ReceiveMessage", user, message); - - public async Task SendMessageToGroup(string user, string message) - => await Clients.Group("SignalR Users").SendAsync("ReceiveMessage", user, message); - - public override Task OnConnectedAsync() - { - Console.WriteLine($"ChatHub: {""} connected in {Context.ConnectionId}"); - return base.OnConnectedAsync(); - } -} diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ChatHubController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ChatHubController.cs deleted file mode 100644 index 20d6e807..00000000 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ChatHubController.cs +++ /dev/null @@ -1,85 +0,0 @@ -using BotSharp.Abstraction.Agents.Enums; -using BotSharp.Abstraction.ApiAdapters; -using BotSharp.Abstraction.Conversations.Models; -using BotSharp.OpenAPI.ViewModels.Conversations; -using Microsoft.AspNetCore.SignalR; - -namespace BotSharp.OpenAPI.Controllers; - -[Authorize] -[ApiController] -public class ChatHubController : ControllerBase, IApiAdapter -{ - private readonly IServiceProvider _services; - private readonly ILogger _logger; - private readonly IHubContext _chatHub; - private readonly IUserIdentity _user; - - public ChatHubController(IServiceProvider services, - ILogger logger, - IHubContext chatHub, - IUserIdentity user) - { - _services = services; - _logger = logger; - _chatHub = chatHub; - _user = user; - } - - [HttpPost("/chat-hub/client/{agentId}/{conversationId}")] - public async Task OnMessageReceivedFromClient([FromRoute] string agentId, - [FromRoute] string conversationId, - [FromBody] NewMessageModel input) - { - var conv = _services.GetRequiredService(); - conv.SetConversationId(conversationId, input.States); - conv.States.SetState("channel", input.Channel); - - var response = new MessageResponseModel(); - var inputMsg = new RoleDialogModel("user", input.Text); - await conv.SendMessage(agentId, inputMsg, - async msg => - { - response.Text = msg.Content; - response.Function = msg.FunctionName; - response.RichContent = msg.RichContent; - response.Instruction = msg.Instruction; - response.Data = msg.Data; - }, - async fnExecuting => - { - - }, - async fnExecuted => - { - - }); - - var state = _services.GetRequiredService(); - response.States = state.GetStates(); - response.MessageId = inputMsg.MessageId; - - // Update console conversation UI for CSR - await _chatHub.Clients.All.SendAsync("OnMessageReceivedFromClient", new RoleDialogModel(AgentRole.User, input.Text) - { - - }); - - await _chatHub.Clients.All.SendAsync("OnMessageReceivedFromAssistant", new RoleDialogModel(AgentRole.Assistant, response.Text) - { - - }); - } - - [HttpPost("/chat-hub/csr/{agentId}/{conversationId}")] - public async Task OnMessageReceivedFromCsr([FromRoute] string agentId, - [FromRoute] string conversationId, - [FromBody] NewMessageModel input) - { - // Update console conversation UI for User - await _chatHub.Clients.All.SendAsync("OnMessageReceivedFromCsr", new RoleDialogModel(AgentRole.CSR, input.Text) - { - - }); - } -} diff --git a/src/Plugins/BotSharp.Plugin.MetaMessenger/MetaMessengerPlugin.cs b/src/Plugins/BotSharp.Plugin.MetaMessenger/MetaMessengerPlugin.cs index fe84b407..73cdedb0 100644 --- a/src/Plugins/BotSharp.Plugin.MetaMessenger/MetaMessengerPlugin.cs +++ b/src/Plugins/BotSharp.Plugin.MetaMessenger/MetaMessengerPlugin.cs @@ -16,6 +16,8 @@ namespace BotSharp.Plugin.MetaMessenger; /// public class MetaMessengerPlugin : IBotSharpPlugin { + public string Name => "Meta Messenger"; + public void RegisterDI(IServiceCollection services, IConfiguration config) { var settings = new MetaMessengerSetting(); diff --git a/src/Plugins/BotSharp.Plugin.Twilio/TwilioPlugin.cs b/src/Plugins/BotSharp.Plugin.Twilio/TwilioPlugin.cs index ff8884b2..80b2b5df 100644 --- a/src/Plugins/BotSharp.Plugin.Twilio/TwilioPlugin.cs +++ b/src/Plugins/BotSharp.Plugin.Twilio/TwilioPlugin.cs @@ -1,12 +1,12 @@ -using BotSharp.Abstraction.Plugins; using BotSharp.Plugin.Twilio.Settings; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; namespace BotSharp.Plugin.Twilio; public class TwilioPlugin : IBotSharpPlugin { + public string Name => "Twilio"; + public string Description => "Communication APIs for SMS, Voice, Video & Authentication"; + public void RegisterDI(IServiceCollection services, IConfiguration config) { var setting = new TwilioSetting(); diff --git a/tests/BotSharp.Plugin.PizzaBot/PizzaBotPlugin.cs b/tests/BotSharp.Plugin.PizzaBot/PizzaBotPlugin.cs index 096ead98..3ee956d8 100644 --- a/tests/BotSharp.Plugin.PizzaBot/PizzaBotPlugin.cs +++ b/tests/BotSharp.Plugin.PizzaBot/PizzaBotPlugin.cs @@ -5,6 +5,7 @@ namespace BotSharp.Plugin.PizzaBot; public class PizzaBotPlugin : IBotSharpPlugin { + public string Name => "Pizza AI Assistant"; public void RegisterDI(IServiceCollection services, IConfiguration config) { // Register hooks