我使用 Microsoft BotFramework 创建简单的机器人,并使用 FormFlow
。
所以:
[Serializable]
public class Test
{
public String Name {get;set;}
public uint Age {get;set; }
}
internal static IDialog<Test> MakeRootDialog()
{
return Chain.From(() => FormDialog.FromForm(Test.BuildForm));
}
还有:
public async Task<Message> Post([FromBody]Message message)
{
if (message.Type == "Message")
{
return await Conversation.SendAsync(message, MakeRootDialog);
}
else
{
return HandleSystemMessage(message);
}
}
所以,Micrisoft BotEmulator 运行良好(并且是机器人),并询问我人员的姓名和年龄。 但是,如何获得这个选择的结果来使用它呢?
如何知道用户输入了什么?我应该使用 ConversationId 吗?
附注我的意思是如何从用户名和用户年龄获得结果? 我尝试使用:
var name= result.GetBotPerUserInConversationData<Test>("Name");
但它返回 null;
P.P.S:我使用 Bot Emulator:并获得像这样的 json 响应:
GetBotPerUserInConversationData:DialogState { some binary data }
所以,我使用
var name= result.GetBotPerUserInConversationData<Test>("DialogState");
但是出现错误:
"exceptionMessage": "Error converting value System.Byte[] to type 'Test'. Path ''.",
"exceptionType": "Newtonsoft.Json.JsonSerializationException"
最佳答案
您好,既然您正在构建表单,您可以在 FormFlowComplete 回调方法中获取结果,如下所示
private async Task yourFormFlowComplete(IDialogContext context, IAwaitable<yourclass> result)
{
var res = await result;//res will contain the result set, if you build the form with a class
}
关于c# - 如何在 Microsoft BotFramework 中使用 FormFlow 结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37497476/