BotSharp/src/Plugins/BotSharp.Plugin.ChatHub/ChatHubPlugin.cs

44 lines
1.7 KiB
C#
Raw Normal View History

2025-05-07 21:34:39 +00:00
using BotSharp.Abstraction.Crontab;
2025-06-27 18:49:44 +00:00
using BotSharp.Abstraction.Observables.Models;
2025-06-17 18:17:28 +00:00
using BotSharp.Core.Observables.Queues;
2023-11-22 16:27:55 +00:00
using BotSharp.Plugin.ChatHub.Hooks;
2025-06-17 18:17:28 +00:00
using BotSharp.Plugin.ChatHub.Observers;
using Microsoft.AspNetCore.Builder;
2023-11-22 16:27:55 +00:00
using Microsoft.Extensions.Configuration;
namespace BotSharp.Plugin.ChatHub;
/// <summary>
/// The dialogue channel connects users, AI assistants and customer service representatives.
/// </summary>
2025-06-17 18:17:28 +00:00
public class ChatHubPlugin : IBotSharpPlugin, IBotSharpAppPlugin
2023-11-22 16:27:55 +00:00
{
2024-01-12 22:20:22 +00:00
public string Id => "6e52d42d-1e23-406b-8599-36af36c83209";
2023-11-22 16:27:55 +00:00
public string Name => "Chat Hub";
2023-12-26 03:16:41 +00:00
public string Description => "A communication channel connects agents and users in real-time.";
2024-01-06 22:24:22 +00:00
public string IconUrl => "https://media.zeemly.com/media/product/chatrandom.png";
2023-11-22 16:27:55 +00:00
public void RegisterDI(IServiceCollection services, IConfiguration config)
{
2025-02-13 20:52:46 +00:00
var settings = new ChatHubSettings();
config.Bind("ChatHub", settings);
services.AddSingleton(x => settings);
2023-11-22 16:27:55 +00:00
// Register hooks
services.AddScoped<IConversationHook, ChatHubConversationHook>();
2024-01-24 23:47:57 +00:00
services.AddScoped<IConversationHook, StreamingLogHook>();
2024-03-07 18:27:29 +00:00
services.AddScoped<IConversationHook, WelcomeHook>();
2024-02-28 16:21:14 +00:00
services.AddScoped<IRoutingHook, StreamingLogHook>();
2024-03-07 18:27:29 +00:00
services.AddScoped<IContentGeneratingHook, StreamingLogHook>();
2024-12-05 17:11:16 +00:00
services.AddScoped<ICrontabHook, ChatHubCrontabHook>();
2023-11-22 16:27:55 +00:00
}
2025-06-17 18:17:28 +00:00
public void Configure(IApplicationBuilder app)
{
var services = app.ApplicationServices;
2025-06-27 18:49:44 +00:00
var queue = services.GetRequiredService<MessageHub<HubObserveData>>();
var logger = services.GetRequiredService<ILogger<MessageHub<HubObserveData>>>();
2025-06-17 18:17:28 +00:00
queue.Events.Subscribe(new ChatHubObserver(logger));
}
2023-11-22 16:27:55 +00:00
}