Merge pull request #841 from wcao-lessen/fix/twilio-plugin

hang up after maximum gather attempts
This commit is contained in:
Haiping 2025-01-24 20:41:07 -06:00 committed by GitHub
commit 620d71cab4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 21 deletions

View file

@ -147,37 +147,20 @@ public class TwilioVoiceController : TwilioController
}
else
{
// keep waiting for user response
if (request.Attempts > 3)
if (request.Attempts > _settings.MaxGatherAttempts)
{
var instruction = new ConversationalVoiceResponse
{
SpeechPaths = new List<string>(),
CallbackPath = $"twilio/voice/{request.ConversationId}/receive/{request.SeqNum}?{GenerateStatesParameter(request.States)}",
ActionOnEmptyResult = true
};
// prompt user to speak clearly
if (request.SeqNum == 0)
{
instruction.SpeechPaths.Add("twilio/welcome.mp3");
}
else
{
var lastRepy = await sessionManager.GetAssistantReplyAsync(request.ConversationId, request.SeqNum - 1);
instruction.SpeechPaths.Add($"twilio/voice/speeches/{request.ConversationId}/{lastRepy.SpeechFileName}");
}
await HookEmitter.Emit<ITwilioSessionHook>(_services, async hook =>
{
await hook.OnWaitingUserResponse(request, instruction);
await hook.OnAgentHangUp(request);
}, new HookEmitOption
{
OnlyOnce = true
});
response = twilio.ReturnInstructions(instruction);
response = twilio.HangUp(null);
}
// keep waiting for user response
else
{
var instruction = new ConversationalVoiceResponse

View file

@ -11,4 +11,5 @@ public class TwilioSetting
public string CallbackHost { get; set; }
public string AgentId { get; set; }
public string CsrAgentNumber { get; set; }
public int MaxGatherAttempts { get; set; } = 4;
}