using System.Text.Json; using CommonSocketLibrary.Abstract; using CommonSocketLibrary.Common; using HermesSocketLibrary.Socket.Data; using Serilog; using TwitchChatTTS.Hermes.Socket.Requests; namespace TwitchChatTTS.Hermes.Socket.Handlers { public class RequestAckHandler : IWebSocketHandler { private readonly RequestAckManager _manager; private readonly ILogger _logger; public int OperationCode { get; } = 4; public RequestAckHandler( RequestAckManager manager, ILogger logger ) { _manager = manager; _logger = logger; } public async Task Execute(SocketClient sender, Data data) { if (data is not RequestAckMessage message || message == null) return; if (message.Request == null) { _logger.Warning("Received a Hermes request message without a proper request."); return; } _logger.Debug($"Received a Hermes request message [type: {message.Request.Type}][data: {string.Join(',', message.Request.Data?.Select(entry => entry.Key + '=' + entry.Value) ?? Array.Empty())}]"); var json = message.Data?.ToString(); if (message.Request.Type == null) { return; } _manager.Fulfill(message.Request.Type, message.Request.RequestId, json, message.Request.Data); } } public class HermesRequestData { public Action?>? Callback { get; set; } public IDictionary? Data { get; set; } } }