Botbuilder自适应对话框,用于存储用户输入

时间:2019-12-19 10:23:14

标签: c# botframework

我正在使用botbuilder自适应对话框的预览来收集一些用户信息。我想将此信息存储在SQL中。所以我的问题是如何从文本输入中的“属性”中收集信息?

new TextInput
            {
                Prompt = new ActivityTemplate(question.Text),
                Property = "user.userProfile" + question.Id
            }

2 个答案:

答案 0 :(得分:2)

使用CodeAction或HttpRequest调用您的api来存储信息

使用它向任何端点发出HTTP请求。

new HttpRequest()
{
    // Set response from the http request to turn.httpResponse property in memory.
    ResultProperty = "turn.httpResponse",
    Method = HttpRequest.HttpMethod.POST,
    Headers = new Dictionary<string,string> (), /* request header */
    Body = JToken.FromObject(new
                                {
                                    data = "@{user.userProfile" + question.Id + "}",
                                    another = "@{user.another}"
                                })                                   /* request body */
}); 

代码操作

        private async Task<DialogTurnResult> CodeActionSampleFn(DialogContext dc, System.Object options)
        {
            var userState = JObject.FromObject(dc.GetState().FirstOrDefault(x => x.Key == "user").Value);
    //Get your data here
            var data = userState.Value<JObject>("userProfile" + question.Id);
    // call your API by HttpClient
//...
    return dc.ContinueDialogAsync();
        }

在此处查看更多详细信息 https://github.com/microsoft/BotBuilder-Samples/blob/master/experimental/adaptive-dialog/docs/recognizers-rules-steps-reference.md#HttpRequest

答案 1 :(得分:1)

您可以看到有关如何在enter image description here上访问state properties的示例:

new SendActivity("Hello, @{user.name}")