diff --git a/src/Plugins/BotSharp.Plugin.Twilio/Controllers/TwilioVoiceController.cs b/src/Plugins/BotSharp.Plugin.Twilio/Controllers/TwilioVoiceController.cs index 75dce61e..d84ea5a1 100644 --- a/src/Plugins/BotSharp.Plugin.Twilio/Controllers/TwilioVoiceController.cs +++ b/src/Plugins/BotSharp.Plugin.Twilio/Controllers/TwilioVoiceController.cs @@ -213,7 +213,7 @@ public class TwilioVoiceController : TwilioController response = twilio.ReturnInstructions(new List { $"twilio/voice/speeches/{conversationId}/{reply.SpeechFileName}" - }, $"twilio/voice/{conversationId}/receive/{nextSeqNum}?states={states}", true); + }, $"twilio/voice/{conversationId}/receive/{nextSeqNum}?states={states}", true, hints:reply.Hints); } } diff --git a/src/Plugins/BotSharp.Plugin.Twilio/Models/AssistantMessage.cs b/src/Plugins/BotSharp.Plugin.Twilio/Models/AssistantMessage.cs index 521dba43..2587fed9 100644 --- a/src/Plugins/BotSharp.Plugin.Twilio/Models/AssistantMessage.cs +++ b/src/Plugins/BotSharp.Plugin.Twilio/Models/AssistantMessage.cs @@ -7,5 +7,6 @@ namespace BotSharp.Plugin.Twilio.Models public string Content { get; set; } public string MessageId { get; set; } public string SpeechFileName { get; set; } + public string Hints { get; set; } } } diff --git a/src/Plugins/BotSharp.Plugin.Twilio/Services/TwilioMessageQueueService.cs b/src/Plugins/BotSharp.Plugin.Twilio/Services/TwilioMessageQueueService.cs index 4679c653..cd5643f1 100644 --- a/src/Plugins/BotSharp.Plugin.Twilio/Services/TwilioMessageQueueService.cs +++ b/src/Plugins/BotSharp.Plugin.Twilio/Services/TwilioMessageQueueService.cs @@ -106,8 +106,27 @@ namespace BotSharp.Plugin.Twilio.Services var data = await completion.GenerateAudioFromTextAsync(reply.Content); var fileName = $"reply_{reply.MessageId}.mp3"; fileStorage.SaveSpeechFile(message.ConversationId, fileName, data); - reply.SpeechFileName = fileName; + var phrases = reply.Content.Split(',', StringSplitOptions.RemoveEmptyEntries); + int capcity = 100; + var hints = new List(capcity); + for (int i = phrases.Length - 1; i >= 0; i--) + { + var words = phrases[i].Split(' ', StringSplitOptions.RemoveEmptyEntries); + for (int j = words.Length - 1; j >= 0; j--) + { + hints.Add(words[j]); + if (hints.Count >= capcity) + { + break; + } + } + if (hints.Count >= capcity) + { + break; + } + } + reply.Hints = string.Join(',', hints); reply.Content = null; await sessionManager.SetAssistantReplyAsync(message.ConversationId, message.SeqNumber, reply); } diff --git a/src/Plugins/BotSharp.Plugin.Twilio/Services/TwilioService.cs b/src/Plugins/BotSharp.Plugin.Twilio/Services/TwilioService.cs index fa164d99..0955e65d 100644 --- a/src/Plugins/BotSharp.Plugin.Twilio/Services/TwilioService.cs +++ b/src/Plugins/BotSharp.Plugin.Twilio/Services/TwilioService.cs @@ -66,7 +66,7 @@ public class TwilioService return response; } - public VoiceResponse ReturnInstructions(List speechPaths, string callbackPath, bool actionOnEmptyResult, int timeout = 5) + public VoiceResponse ReturnInstructions(List speechPaths, string callbackPath, bool actionOnEmptyResult, int timeout = 3, string hints = null) { var response = new VoiceResponse(); var gather = new Gather() @@ -78,10 +78,10 @@ public class TwilioService }, Action = new Uri($"{_settings.CallbackHost}/{callbackPath}"), SpeechModel = Gather.SpeechModelEnum.PhoneCall, - SpeechTimeout = "auto", // timeout > 0 ? timeout.ToString() : "5", - Timeout = timeout > 0 ? timeout : 5, + SpeechTimeout = "auto", // timeout > 0 ? timeout.ToString() : "3", + Timeout = timeout > 0 ? timeout : 3, ActionOnEmptyResult = actionOnEmptyResult, - Hints = "Yes, No, Correct" + Hints = hints }; if (!speechPaths.IsNullOrEmpty())