获取值存储在botframework建议的变量中 [英] Getting value stored in a variable in botframework suggested actions

查看:79
本文介绍了获取值存储在botframework建议的变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将值是"或否"存储到变量中?我试图在用户单击按钮时存储值是"或否",但是它没有将值带入k

how to get the value "yes" or "no" stored into a variable? i am trying to store the value yes or no when a user clicks the button but it is not taking the value into k

var activity1 = MessageFactory.SuggestedActions(  
new CardAction[]
{
    new CardAction(title: "YES", type: ActionTypes.ImBack,value:"yes"),
    new CardAction( title: "NO", type: ActionTypes.ImBack, value: "no")
}, text: "Do you want to continue Shopping?");
var k=await context.SendActivityAsync(activity1);

推荐答案

不幸的是,

Unfortunately, context.SendActivityAsync() does not return the value that the user input, it simply sends the activity without even waiting for the user to respond.

有两种选择可以满足您的需求.

There's a couple of options to accomplish what you're looking for.

您可以将代码保持原样,并在OnTurnAsync()中使用以下内容访问用户输入的值:

You can keep your code mostly like it is and access the value of the user input within OnTurnAsync() with something like:

var k = turnContext.Activity.Text

您可以根据自己的情况去做. 简单提示示例还向您展示了如何执行此操作.

What you do from there is up to you. The Simple Prompt Sample shows you how you can do this, too.

我建议使用ChoicePrompt,而不是CardAction.

与您相关的代码类似于(请注意,这是对其他必需的WaterfallDialog代码的补充):

Relevant code for you would be something like (note that this would be in addition to other necessary WaterfallDialog code):

private static async Task<DialogTurnResult> FirstStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken = default(CancellationToken))
{
    return await stepContext.PromptAsync(
        "choicePrompt",
        new PromptOptions
        {
            Prompt = MessageFactory.Text("Select an Action"),
            Choices = new List<Choice> { new Choice("Yes"), new Choice("No") },
        });
}

private static async Task<DialogTurnResult> SecondStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken = default(CancellationToken))
{
    var k = ((FoundChoice)stepContext.Result).Value.ToString();
    return await stepContext.NextAsync();
}

基本Bot示例有使用瀑布对话框的很好的例子.

The Basic Bot Sample has very good examples of using Waterfall Dialogs.

  • Prompting Users for Input
  • Sequential Conversation Flow
  • Getting Input from Dialog Prompts

这篇关于获取值存储在botframework建议的变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆