将HeroCards用作选项提示:无法选择选项

时间:2019-07-17 13:54:58

标签: .net-core botframework

当用户可以选择要走的路径时,我使用的是object_detection/utils而不是HeroCard。在PromptOption中显示了HeroCard中的选项之后,下一个瀑布步骤ProductStepAsync被跳过了,因为您没有机会选择一个选项,因此它将直接切换到默认值。我在做什么错了?

编辑:在ChoiceStepAsync中切换的默认情况下,我尝试返回上一个任务ChoiceStepAsync和当前任务,但是问题是它直接返回到默认任务中。切换。

这是我的代码:

(ProductStepAsync)

ProductDialog.cs

这里直接将其设置为默认值:

    public class ProductDialog : ComponentDialog
    {
        private const string UserInfoProduct = "values-userInfo-Product";
        public ProductDialog() : base(nameof(ProductDialog)) {

            AddDialog(new ChoicePrompt(nameof(ChoicePrompt)));

            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[]
               {
                   ProductStepAsync,
                   ChoiceStepAsync,
                   MoreInfoStepAsync,
                   MoreInfoChoiceStepAsync,

               }));
            AddDialog(new PhoneDialog());

            InitialDialogId = nameof(WaterfallDialog);
        }

        private static async Task<DialogTurnResult> ProductStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            stepContext.Values[UserInfoProduct] = new UserProfile();

            var getProduct = stepContext.Context.Activity.CreateReply();
            var ProductOptions = new HeroCard
            {
                Text = "What can I help you with?",
                Buttons = new List<CardAction>
            {
                            new CardAction() { Title = "? Contact", Type = ActionTypes.ImBack, Value = "Contact" },
                            new CardAction() { Title = "? Newsletter", Type = ActionTypes.ImBack, Value = "Newsletter" },
                            new CardAction() { Title = "?About us", Type = ActionTypes.ImBack, Value = "About us" },
            },
            };

            getProduct.Attachments = new List<Attachment>() { ProductOptions.ToAttachment() };


            await stepContext.Context.SendActivityAsync(getProduct, cancellationToken);
            return await stepContext.NextAsync(stepContext.Values[UserInfoProduct], cancellationToken);
        }

1 个答案:

答案 0 :(得分:0)

我弄清楚了,在HeroCard之后的PromptOptions()中添加了一个新的ChallengeStepAsync,然后使用PromptAsync。因此,我将ChallengeStepAsync更改为:

private static async Task<DialogTurnResult> ProductStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
    {
        stepContext.Values[UserInfoProduct] = new UserProfile();

        var getProduct = stepContext.Context.Activity.CreateReply();
        var ProductOptions = new HeroCard
        {
            Text = "What can I help you with?",
            Buttons = new List<CardAction>
        {
                        new CardAction() { Title = "? Contact", Type = ActionTypes.ImBack, Value = "Contact" },
                        new CardAction() { Title = "? Newsletter", Type = ActionTypes.ImBack, Value = "Newsletter" },
                        new CardAction() { Title = "?About us", Type = ActionTypes.ImBack, Value = "About us" },
        },
        };

        getProduct.Attachments = new List<Attachment>() { ProductOptions.ToAttachment() };

        var options = new PromptOptions() {
            Prompt = getChallenge,
            RetryPrompt = MessageFactory.Text("I don't recognize this option")
       };

        return await stepContext.PromptAsync(nameof(TextPrompt), options, cancellationToken);
    }