Flag realtime feature in Labels.
This commit is contained in:
parent
45341eb02e
commit
0159c35661
|
|
@ -74,7 +74,7 @@ public class TwilioInboundController : TwilioController
|
|||
}
|
||||
else
|
||||
{
|
||||
if (agent.Profiles.Contains("realtime"))
|
||||
if (agent.Labels.Contains("realtime"))
|
||||
{
|
||||
response = twilio.ReturnBidirectionalMediaStreamsInstructions(instruction, agent);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using BotSharp.Plugin.Twilio.Models;
|
||||
using BotSharp.Plugin.Twilio.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace BotSharp.Plugin.Twilio.Controllers;
|
||||
|
|
@ -24,7 +25,17 @@ public class TwilioReconnectController : TwilioController
|
|||
var connect = new Connect();
|
||||
var host = _settings.CallbackHost.Split("://").Last();
|
||||
connect.Stream(url: $"wss://{host}/twilio/stream/{request.AgentId}/{request.ConversationId}");
|
||||
response.Pause(1);
|
||||
if (!string.IsNullOrEmpty(request.InitAudioFile))
|
||||
{
|
||||
var twilio = _services.GetRequiredService<TwilioService>();
|
||||
var audioUrl = twilio.GetSpeechPath(request.ConversationId, request.InitAudioFile);
|
||||
response.Play(new Uri(audioUrl));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Leave a pause to allow disposing objects.
|
||||
response.Pause(1);
|
||||
}
|
||||
response.Append(connect);
|
||||
return TwiML(response);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ using BotSharp.Abstraction.Routing;
|
|||
using Task = System.Threading.Tasks.Task;
|
||||
using Twilio.Rest.Api.V2010.Account;
|
||||
using BotSharp.Plugin.Twilio.Interfaces;
|
||||
using BotSharp.Plugin.Twilio.Models;
|
||||
|
||||
namespace BotSharp.Plugin.Twilio.Hooks;
|
||||
|
||||
|
|
@ -23,17 +24,31 @@ public class TwilioConversationHook : ConversationHookBase, IConversationHook
|
|||
public override async Task OnFunctionExecuted(RoleDialogModel message)
|
||||
{
|
||||
var hooks = _services.GetServices<ITwilioSessionHook>();
|
||||
|
||||
var routing = _services.GetRequiredService<IRoutingService>();
|
||||
var conversationId = routing.Context.ConversationId;
|
||||
|
||||
var states = _services.GetRequiredService<IConversationStateService>();
|
||||
var sid = states.GetState("twilio_call_sid");
|
||||
|
||||
var request = new ConversationalVoiceRequest
|
||||
{
|
||||
AgentId = message.CurrentAgentId,
|
||||
ConversationId = conversationId,
|
||||
CallSid = sid,
|
||||
};
|
||||
|
||||
foreach (var hook in hooks)
|
||||
{
|
||||
if (await hook.ShouldReconnect(message))
|
||||
if (await hook.ShouldReconnect(request, message))
|
||||
{
|
||||
var states = _services.GetRequiredService<IConversationStateService>();
|
||||
var sid = states.GetState("twilio_call_sid");
|
||||
|
||||
var routing = _services.GetRequiredService<IRoutingService>();
|
||||
var conversationId = routing.Context.ConversationId;
|
||||
var processUrl = $"{_setting.CallbackHost}/twilio/stream/reconnect?agent-id={message.CurrentAgentId}&conversation-id={conversationId}";
|
||||
|
||||
if (!string.IsNullOrEmpty(request.InitAudioFile))
|
||||
{
|
||||
processUrl += $"&init-audio-file={request.InitAudioFile}";
|
||||
}
|
||||
|
||||
// Save all states before reconnect
|
||||
states.Save();
|
||||
|
||||
|
|
|
|||
|
|
@ -86,6 +86,6 @@ public interface ITwilioSessionHook
|
|||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> ShouldReconnect(RoleDialogModel message)
|
||||
Task<bool> ShouldReconnect(ConversationalVoiceRequest request, RoleDialogModel message)
|
||||
=> Task.FromResult(false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ public class OutboundPhoneCallFn : IFunctionCallback
|
|||
var agent = await agentService.GetAgent(message.CurrentAgentId);
|
||||
|
||||
// Set up process URL streaming or synchronous
|
||||
if (agent.Profiles.Contains("realtime"))
|
||||
if (agent.Labels.Contains("realtime"))
|
||||
{
|
||||
processUrl += "/inbound";
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue