Speech + Digits

This commit is contained in:
Haiping Chen 2024-08-26 17:33:47 -05:00
parent 20a7f61e86
commit 6366e14e50
2 changed files with 14 additions and 7 deletions

View file

@ -47,15 +47,16 @@ public class TwilioVoiceController : TwilioController
var messageQueue = _services.GetRequiredService<TwilioMessageQueue>();
var sessionManager = _services.GetRequiredService<ITwilioSessionManager>();
var messages = await sessionManager.RetrieveStagedCallerMessagesAsync(conversationId, seqNum);
if (!string.IsNullOrWhiteSpace(request.SpeechResult))
string text = (request.SpeechResult + "\r\n" + request.Digits).Trim();
if (!string.IsNullOrWhiteSpace(text))
{
messages.Add(request.SpeechResult);
await sessionManager.StageCallerMessageAsync(conversationId, seqNum, request.SpeechResult);
messages.Add(text);
await sessionManager.StageCallerMessageAsync(conversationId, seqNum, text);
}
VoiceResponse response;
if (messages.Count == 0 && seqNum == 0)
{
response = twilio.ReturnInstructions("twilio/welcome.mp3", $"twilio/voice/{conversationId}/receive/{seqNum}?states={states}", true);
response = twilio.ReturnInstructions("twilio/welcome.mp3", $"twilio/voice/{conversationId}/receive/{seqNum}?states={states}", true, timeout: 2);
}
else
{

View file

@ -54,7 +54,8 @@ public class TwilioService
{
Input = new List<Gather.InputEnum>()
{
Gather.InputEnum.Speech
Gather.InputEnum.Speech,
Gather.InputEnum.Dtmf
},
Action = new Uri($"{_settings.CallbackHost}/twilio/voice/{twilioSetting.AgentId}")
};
@ -70,7 +71,8 @@ public class TwilioService
{
Input = new List<Gather.InputEnum>()
{
Gather.InputEnum.Speech
Gather.InputEnum.Speech,
Gather.InputEnum.Dtmf
},
Action = new Uri($"{_settings.CallbackHost}/{callbackPath}"),
SpeechModel = Gather.SpeechModelEnum.PhoneCall,
@ -109,7 +111,11 @@ public class TwilioService
var response = new VoiceResponse();
var gather = new Gather()
{
Input = new List<Gather.InputEnum>() { Gather.InputEnum.Speech },
Input = new List<Gather.InputEnum>()
{
Gather.InputEnum.Speech,
Gather.InputEnum.Dtmf
},
Action = new Uri($"{_settings.CallbackHost}/twilio/voice/{twilioSetting.AgentId}"),
ActionOnEmptyResult = true
};