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