Remove ChatHub.
This commit is contained in:
parent
6a2343c757
commit
c21255979b
|
|
@ -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; }
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -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<ChatHub> logger,
|
||||
IUserIdentity user)
|
||||
{
|
||||
_services = services;
|
||||
_logger = logger;
|
||||
_user = user;
|
||||
}
|
||||
|
||||
public async Task OnMessageReceivedFromClient(string message)
|
||||
{
|
||||
// await Clients.User(_user.Id).SendAsync("ReceiveMessage", message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Received message from client
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="message"></param>
|
||||
/// <returns></returns>
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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> _chatHub;
|
||||
private readonly IUserIdentity _user;
|
||||
|
||||
public ChatHubController(IServiceProvider services,
|
||||
ILogger<ChatHubController> logger,
|
||||
IHubContext<ChatHub> 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<IConversationService>();
|
||||
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<IConversationStateService>();
|
||||
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)
|
||||
{
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -16,6 +16,8 @@ namespace BotSharp.Plugin.MetaMessenger;
|
|||
/// </summary>
|
||||
public class MetaMessengerPlugin : IBotSharpPlugin
|
||||
{
|
||||
public string Name => "Meta Messenger";
|
||||
|
||||
public void RegisterDI(IServiceCollection services, IConfiguration config)
|
||||
{
|
||||
var settings = new MetaMessengerSetting();
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue