From 1281e120772227f3853d1a78fe1cfc9da01c9f97 Mon Sep 17 00:00:00 2001 From: "nick.yi" Date: Tue, 1 Dec 2026 08:50:43 +0800 Subject: [PATCH] fix(twilio): save the hang-up and transfer lines the caller hears to the dialogs The hang-up response_content and the transfer transition_message are played as audio files by the redirect endpoints, not spoken in the realtime stream, so they never reached the conversation dialogs. Append them as an assistant message before the redirect, which closes the stream and disposes the scope, and only when the audio file exists. Co-Authored-By: Claude Opus 5.5 --- .../Functions/HangupPhoneCallFn.cs | 8 ++++++++ .../Functions/TransferPhoneCallFn.cs | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Functions/HangupPhoneCallFn.cs b/src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Functions/HangupPhoneCallFn.cs index d8d432319..8cf02e30f 100644 --- a/src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Functions/HangupPhoneCallFn.cs +++ b/src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Functions/HangupPhoneCallFn.cs @@ -52,6 +52,14 @@ public async Task Execute(RoleDialogModel message) if (!string.IsNullOrEmpty(initAudioFile)) { processUrl += $"&init-audio-file={initAudioFile}"; + + // The caller hears this as audio, so keep it in the dialogs too. Save it before the redirect, + // which closes the stream and disposes this scope. + var storage = _services.GetRequiredService(); + await storage.Append(conversationId, new RoleDialogModel(AgentRole.Assistant, args.ResponseContent) + { + CurrentAgentId = message.CurrentAgentId + }); } } diff --git a/src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Functions/TransferPhoneCallFn.cs b/src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Functions/TransferPhoneCallFn.cs index 0144f5b5c..f760e2e8d 100644 --- a/src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Functions/TransferPhoneCallFn.cs +++ b/src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Functions/TransferPhoneCallFn.cs @@ -57,6 +57,14 @@ public async Task Execute(RoleDialogModel message) if (!string.IsNullOrEmpty(initAudioFile)) { processUrl += $"&init-audio-file={initAudioFile}"; + + // The caller hears this as audio, so keep it in the dialogs too. Save it before the redirect, + // which closes the stream and disposes this scope. + var storage = _services.GetRequiredService(); + await storage.Append(conversationId, new RoleDialogModel(AgentRole.Assistant, args.TransitionMessage) + { + CurrentAgentId = message.CurrentAgentId + }); } }