voice copilot support postback

voice copilot support postback
This commit is contained in:
易磊 2024-10-18 14:24:57 +08:00 committed by GitHub
parent e9194b8247
commit effe494571
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -67,10 +67,10 @@ namespace BotSharp.Plugin.Twilio.Services
var progressService = sp.GetRequiredService<IConversationProgressService>();
InitProgressService(message, sessionManager, progressService);
InitConversation(message, inputMsg, conv, routing);
var result = await conv.SendMessage(config.AgentId,
inputMsg,
replyMessage: null,
replyMessage: BuildPostbackMessageModel(conv),
async msg =>
{
reply = new AssistantMessage()
@ -88,6 +88,20 @@ namespace BotSharp.Plugin.Twilio.Services
await sessionManager.SetAssistantReplyAsync(message.ConversationId, message.SeqNumber, reply);
}
private PostbackMessageModel BuildPostbackMessageModel(IConversationService conv)
{
var messages = conv.GetDialogHistory(1);
if (!messages.Any()) return null;
var lastMessage = messages[0];
if (string.IsNullOrEmpty(lastMessage.PostbackFunctionName)) return null;
return new PostbackMessageModel
{
FunctionName = lastMessage.PostbackFunctionName,
ParentId = lastMessage.MessageId,
Payload = lastMessage.Payload
};
}
private static void InitConversation(CallerMessage message, RoleDialogModel inputMsg, IConversationService conv, IRoutingService routing)
{
routing.Context.SetMessageId(message.ConversationId, inputMsg.MessageId);