using FrameworkDAL.DTO.EIPConversation; using GB5Shared.DTO.Framework.Login; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; namespace FrameworkBLL.EIPConversation.EIPHandlers.ChannelHandler { /// /// Handles voice channel responses. Does not make HTTP calls; instead it returns a /// structured response with TtsText and SsmlText so the calling voice platform /// (Twilio, Azure Bot, Google Dialogflow, etc.) can synthesise speech. /// /// The response is available in EIPChannelResponseDTO.AdditionalData: /// "TtsText" — plain text for platforms that don't support SSML /// "SsmlText" — SSML markup (falls back to plain text when VoiceHint is null) /// "IsCompleted" — whether the conversation flow is done /// public class VoiceChannelHandler : IEIPChannelHandler { public string ChannelName => "VOICE"; private readonly ILogger _logger; public VoiceChannelHandler(ILogger logger) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); } public bool CanHandle(string channel) => string.Equals(channel, ChannelName, StringComparison.OrdinalIgnoreCase); public Task SendAsync( EIPResponseContext context, LoginDTO loginDTO, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var plainText = context.Message ?? string.Empty; var ssmlText = context.VoiceHint ?? plainText; _logger.LogInformation( "VoiceChannelHandler: Tenant={Tenant} | IsCompleted={Done} | TtsLength={Len}", context.TenantId, context.IsCompleted, plainText.Length); var response = new EIPChannelResponseDTO { IsSent = true, Status = "VOICE_READY", AdditionalData = new Dictionary { ["TtsText"] = plainText, ["SsmlText"] = ssmlText, ["IsCompleted"] = context.IsCompleted ?? false } }; return Task.FromResult(response); } } }