如何在botframework v4中重新提示? [英] How to reprompt in botframework v4?

查看:83
本文介绍了如何在botframework v4中重新提示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I can't make RepromptDialogAsync() to work. When dialog b is chosen it should re-prompt the choice prompt showing all the choices again. But when choosing dialog b it is doing nothing. Am I doing it wrong? I can't find any RepromptDialogAsync() tutorial on docs. Any help would be greatly appreciated. Thank you!

代码:

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();
    }

推荐答案

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

When you have met the criteria that requires a prompt dialog being sent to the client, you can simply use the following code:

// 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);

如果您需要更多信息,请告诉我.看来您真的只是在漏掉底线.

Let me know if you need any more info on this. It looks like you were really just missing the bottom line.

这篇关于如何在botframework v4中重新提示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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