user_dtmf_receiving
This commit is contained in:
parent
af04feaabc
commit
871aeff181
|
|
@ -1,4 +1,5 @@
|
|||
using BotSharp.Abstraction.Utilities;
|
||||
using BotSharp.Core.Infrastructures;
|
||||
|
||||
namespace BotSharp.Core.Realtime.Hooks;
|
||||
|
||||
|
|
@ -29,6 +30,10 @@ public class RealtimeConversationHook : ConversationHookBase, IConversationHook
|
|||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Clear cache to force to rebuild the agent instruction
|
||||
Utilities.ClearCache();
|
||||
|
||||
var routing = _services.GetRequiredService<IRoutingService>();
|
||||
|
||||
message.Role = AgentRole.Function;
|
||||
|
|
|
|||
|
|
@ -49,6 +49,9 @@ public class RealtimeHub : IRealtimeHub
|
|||
{
|
||||
await _completer.AppenAudioBuffer(_conn.Data);
|
||||
}
|
||||
else if (_conn.Event == "user_dtmf_receiving")
|
||||
{
|
||||
}
|
||||
else if (_conn.Event == "user_dtmf_received")
|
||||
{
|
||||
await HandleUserDtmfReceived();
|
||||
|
|
|
|||
|
|
@ -164,6 +164,11 @@ public class RealTimeCompletionProvider : IRealTimeCompletion
|
|||
if (response.Type == "error")
|
||||
{
|
||||
_logger.LogError($"{response.Type}: {receivedText}");
|
||||
var error = JsonSerializer.Deserialize<ServerEventErrorResponse>(receivedText);
|
||||
if (error?.Body.Type == "server_error")
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (response.Type == "session.created")
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using BotSharp.Abstraction.Realtime;
|
||||
using BotSharp.Abstraction.Realtime.Models;
|
||||
using BotSharp.Plugin.Twilio.Interfaces;
|
||||
using BotSharp.Plugin.Twilio.Models.Stream;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
|
@ -100,6 +99,7 @@ public class TwilioStreamMiddleware
|
|||
}
|
||||
else
|
||||
{
|
||||
conn.Event = "user_dtmf_receiving";
|
||||
conn.KeypadInputBuffer += dtmfResponse.Body.Digit;
|
||||
}
|
||||
break;
|
||||
|
|
@ -115,6 +115,7 @@ public class TwilioStreamMiddleware
|
|||
streamSid = response.StreamSid,
|
||||
media = new { payload = message }
|
||||
};
|
||||
|
||||
conn.OnModelAudioResponseDone = () =>
|
||||
new
|
||||
{
|
||||
|
|
@ -122,12 +123,21 @@ public class TwilioStreamMiddleware
|
|||
streamSid = response.StreamSid,
|
||||
mark = new { name = "responsePart" }
|
||||
};
|
||||
|
||||
conn.OnModelUserInterrupted = () =>
|
||||
new
|
||||
{
|
||||
@event = "clear",
|
||||
streamSid = response.StreamSid
|
||||
};
|
||||
|
||||
/*if (response.Event == "dtmf")
|
||||
{
|
||||
// Send a Stop command to Twilio
|
||||
string stopPlaybackCommand = "{ \"action\": \"stop_playback\" }";
|
||||
var stopBytes = Encoding.UTF8.GetBytes(stopPlaybackCommand);
|
||||
webSocket.SendAsync(new ArraySegment<byte>(stopBytes), WebSocketMessageType.Text, true, CancellationToken.None);
|
||||
}*/
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue