【问题标题】:How to reprompt in botframework v4?如何在 botframework v4 中重新提示?
【发布时间】:2019-07-18 15:27:53
【问题描述】:

我无法让RepromptDialogAsync() 工作。选择对话框b时,它应该重新提示选择提示,再次显示所有选择。但选择对话框b它什么也没做。我做错了吗?我在文档上找不到任何 RepromptDialogAsync() 教程。任何帮助将不胜感激。谢谢!

代码:

public class MainDialog : ComponentDialog
{
    private const string InitialId = "mainDialog";
    private const string ChoicePrompt = "choicePrompt";
    private const string DialogAId = "dialogAId";

    public MainDialog(string dialogId)
        : base(dialogId)
    {
        WaterfallStep[] waterfallSteps = new WaterfallStep[]
         {
            FirstStepAsync,
            SecondStepAsync,
            ThirdStepAsync,
            FourthStepAsync
         };
        AddDialog(new WaterfallDialog(InitialId, waterfallSteps));
        AddDialog(new DialogA(DialogAId));
    }

    private static async Task<DialogTurnResult> FirstStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken = default(CancellationToken))
    {
        return await stepContext.PromptAsync(
            ChoicePrompt,
            new PromptOptions
            {
                Prompt = MessageFactory.Text($"Here are your choices:"),
                Choices = ChoiceFactory.ToChoices(new List<string> { "Open Dialog A", "Open Dialog B" })
                RetryPrompt = MessageFactory.Text($"Please choose one of the options."),
            });
    }

    private static async Task<DialogTurnResult> SecondStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken = default(CancellationToken))
    {
        var response = (stepContext.Result as FoundChoice)?.Value.ToLower();

        if (response == "open dialog a")
        {
            return await stepContext.BeginDialogAsync(DialogAId, cancellationToken: cancellationToken);
        }

        if (response == "open dialog b")
        {
            await stepContext.Context.SendActivityAsync(MessageFactory.Text($"Dialog B is not ready need to reprompt previous step."));
            await stepContext.RepromptDialogAsync();
        }

        return await stepContext.NextAsync();
    }

   private static async Task<DialogTurnResult> ThirdStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken = default(CancellationToken))
    {
       // do something else
        return await stepContext.NextAsync();
    }

    private static async Task<DialogTurnResult> FourthStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken = default(CancellationToken))
    {
        // what is the best way to end this?
        // return await stepContext.ReplaceDialogAsync(InitialId);
        return await stepContext.EndDialogAsync();
    }

【问题讨论】:

    标签: c# botframework prompt


    【解决方案1】:

    当您满足需要向客户端发送提示对话框的条件时,您可以简单地使用以下代码:

    // declare a prompt name at the top of your class
    private const string promptName = "nameofprompt";
    
    // add it to your list of dialogs
    this.AddDialog(new TextPrompt(promptName, [Validator goes here if you have one])); 
    
    // where you need to prompt use the below.
    var opts = new PromptOptions
    {
        // fill your activity with whatever data is needed for your client, 
        // we use custom channel data, but it's not necessary.
        Prompt = new Activity
        {
            Type = ActivityTypes.Message,
            Text = "I am prompting you for something here?",
            ChannelData = channelData,
        },
    };
    
    return await stepContext.PromptAsync(promptName, opts);
    

    如果您需要更多信息,请告诉我。看起来你真的只是错过了底线。

    【讨论】:

    • 在我的代码中,先生,我已经可以提示用户了。我需要的是当用户选择的选项不可用时。它将再次重新提示用户并重新显示选择提示。
    • 有什么理由不为此使用提示验证器?
    • 使用提示验证器先生时选择不会回来。
    • @user10860402 当你点击'await stepContext.RepromptDialogAsync();'时会发生什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-07
    • 1970-01-01
    • 2019-10-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-05
    相关资源
    最近更新 更多