Add channel system with CLI, Telegram, and Web channel implementations
Define channel abstractions (IChannel, IChannelManager) with event-driven message and connection handling. Implement ChannelManager for multi-channel orchestration, CliChannel for terminal I/O, TelegramChannel with adapter pattern for bot API integration, and WebChannel stub. Includes DI registration and channel type enumeration.
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using Luna.Channels.Abstractions;
|
||||
using Luna.Core.Abstractions;
|
||||
using Luna.Shared;
|
||||
|
||||
namespace Luna.Channels.Web;
|
||||
|
||||
public class WebChannel(string channelId, IChatHubContext hubContext) : IChannel
|
||||
{
|
||||
public string ChannelId { get; } = channelId;
|
||||
public string ChannelType => Abstractions.ChannelType.Web;
|
||||
public string DisplayName { get; } = "Web Interface";
|
||||
public bool IsConnected { get; }
|
||||
|
||||
public event ChannelMessageReceivedEventHandler? MessageReceived;
|
||||
public event ChannelConnectionChangedEventHandler? ConnectionStateChanged;
|
||||
|
||||
public async Task SendStreamingMessageAsync(IAsyncEnumerable<ChatStreamUpdate> messageStream, CancellationToken cancellationToken = default)
|
||||
{
|
||||
await hubContext.SendStreamingResponseAsync(ChannelId, messageStream, cancellationToken);
|
||||
}
|
||||
|
||||
public async Task SendMessageAsync(ChannelMessage message, CancellationToken cancellationToken = default)
|
||||
{
|
||||
await hubContext.SendResponseAsync(ChannelId, message, cancellationToken);
|
||||
}
|
||||
|
||||
public void RaiseMessageReceived(object? sender, ChannelMessage message)
|
||||
{
|
||||
MessageReceived?.Invoke(sender, new ChannelMessageReceivedEventArgs
|
||||
{
|
||||
Channel = this,
|
||||
Message = message,
|
||||
IsHandled = false
|
||||
});
|
||||
}
|
||||
|
||||
public void Dispose() { }
|
||||
}
|
||||
Reference in New Issue
Block a user