Allow settings to disable audio generation.
This commit is contained in:
parent
330b10a0de
commit
0af3a8c01d
|
|
@ -215,7 +215,7 @@ public class TwilioVoiceController : TwilioController
|
|||
var reply = await sessionManager.GetAssistantReplyAsync(request.ConversationId, request.SeqNum);
|
||||
VoiceResponse response;
|
||||
|
||||
if (request.AIResponseWaitTime > 5)
|
||||
if (request.AIResponseWaitTime > 10)
|
||||
{
|
||||
// Wait AI Response Timeout
|
||||
await HookEmitter.Emit<ITwilioSessionHook>(_services, async hook =>
|
||||
|
|
@ -256,12 +256,20 @@ public class TwilioVoiceController : TwilioController
|
|||
{
|
||||
AgentId = request.AgentId,
|
||||
ConversationId = request.ConversationId,
|
||||
SpeechPaths = [$"twilio/voice/speeches/{request.ConversationId}/{reply.SpeechFileName}"],
|
||||
CallbackPath = $"twilio/voice/receive/{nextSeqNum}?agent-id={request.AgentId}&conversation-id={request.ConversationId}&{twilio.GenerateStatesParameter(request.States)}",
|
||||
ActionOnEmptyResult = true,
|
||||
Hints = reply.Hints
|
||||
};
|
||||
|
||||
if (!string.IsNullOrEmpty(reply.SpeechFileName))
|
||||
{
|
||||
instruction.SpeechPaths = [$"twilio/voice/speeches/{request.ConversationId}/{reply.SpeechFileName}"];
|
||||
}
|
||||
else
|
||||
{
|
||||
instruction.Text = reply.Content;
|
||||
}
|
||||
|
||||
await HookEmitter.Emit<ITwilioSessionHook>(_services, async hook =>
|
||||
{
|
||||
await hook.OnAgentResponsing(request, instruction);
|
||||
|
|
|
|||
|
|
@ -5,14 +5,10 @@ public class ConversationalVoiceResponse
|
|||
public string AgentId { get; set; } = null!;
|
||||
public string ConversationId { get; set; } = null!;
|
||||
public List<string> SpeechPaths { get; set; } = [];
|
||||
public string? Text { get; set; }
|
||||
public string CallbackPath { get; set; }
|
||||
public bool ActionOnEmptyResult { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Timeout in seconds
|
||||
/// </summary>
|
||||
public int Timeout { get; set; } = 3;
|
||||
|
||||
public string Hints { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ public class TwilioMessageQueueService : BackgroundService
|
|||
{
|
||||
_queue = queue;
|
||||
_serviceProvider = serviceProvider;
|
||||
_throttler = new SemaphoreSlim(10, 10);
|
||||
_throttler = new SemaphoreSlim(20, 20);
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
|
|
@ -103,7 +103,13 @@ public class TwilioMessageQueueService : BackgroundService
|
|||
};
|
||||
}
|
||||
);
|
||||
reply.SpeechFileName = await GetReplySpeechFileName(message.ConversationId, reply, sp);
|
||||
|
||||
var settings = sp.GetRequiredService<TwilioSetting>();
|
||||
if (settings.GenerateReplyAudio)
|
||||
{
|
||||
reply.SpeechFileName = await GetReplySpeechFileName(message.ConversationId, reply, sp);
|
||||
}
|
||||
|
||||
reply.Hints = GetHints(reply);
|
||||
await sessionManager.SetAssistantReplyAsync(message.ConversationId, message.SeqNumber, reply);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ public class TwilioService
|
|||
Enhanced = true,
|
||||
SpeechModel = _settings.SpeechModel,
|
||||
SpeechTimeout = "auto", // timeout > 0 ? timeout.ToString() : "3",
|
||||
Timeout = conversationalVoiceResponse.Timeout > 0 ? conversationalVoiceResponse.Timeout : 3,
|
||||
Timeout = Math.Max(_settings.GatherTimeout, 1),
|
||||
ActionOnEmptyResult = conversationalVoiceResponse.ActionOnEmptyResult,
|
||||
Hints = conversationalVoiceResponse.Hints
|
||||
};
|
||||
|
|
@ -80,6 +80,12 @@ public class TwilioService
|
|||
gather.Play(new Uri($"{_settings.CallbackHost}/{speechPath}"));
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(conversationalVoiceResponse.Text))
|
||||
{
|
||||
gather.Say(conversationalVoiceResponse.Text);
|
||||
}
|
||||
|
||||
response.Append(gather);
|
||||
return response;
|
||||
}
|
||||
|
|
@ -108,7 +114,7 @@ public class TwilioService
|
|||
Enhanced = true,
|
||||
SpeechModel = _settings.SpeechModel,
|
||||
SpeechTimeout = "auto", // conversationalVoiceResponse.Timeout > 0 ? conversationalVoiceResponse.Timeout.ToString() : "3",
|
||||
Timeout = voiceResponse.Timeout > 0 ? voiceResponse.Timeout : 3,
|
||||
Timeout = Math.Max(_settings.GatherTimeout, 1),
|
||||
ActionOnEmptyResult = voiceResponse.ActionOnEmptyResult,
|
||||
};
|
||||
response.Append(gather);
|
||||
|
|
|
|||
|
|
@ -7,12 +7,11 @@ public class TwilioSetting
|
|||
/// </summary>
|
||||
public string? PhoneNumber { get; set; }
|
||||
|
||||
public string AccountSID { get; set; }
|
||||
public string AuthToken { get; set; }
|
||||
public string AccountSID { get; set; } = null!;
|
||||
public string AppSID { get; set; }
|
||||
public string ApiKeySID { get; set; }
|
||||
public string ApiSecret { get; set; }
|
||||
public string CallbackHost { get; set; }
|
||||
public string CallbackHost { get; set; } = null!;
|
||||
|
||||
public string SpeechModel { get; set; } = "googlev2_telephony";
|
||||
public string? MessagingShortCode { get; set; }
|
||||
|
|
@ -22,11 +21,15 @@ public class TwilioSetting
|
|||
/// </summary>
|
||||
public string? CsrAgentNumber { get; set; }
|
||||
|
||||
public int MaxGatherAttempts { get; set; } = 4;
|
||||
public int MaxGatherAttempts { get; set; } = 10;
|
||||
|
||||
public int GatherTimeout { get; set; } = 1;
|
||||
|
||||
public string? MachineDetection { get; set; }
|
||||
public int MachineDetectionSilenceTimeout { get; set; } = 2500;
|
||||
|
||||
public bool RecordingEnabled { get; set; } = false;
|
||||
public bool TranscribeEnabled { get; set; } = false;
|
||||
|
||||
public bool GenerateReplyAudio { get; set; } = true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue