簡體   English   中英

如何在botframework v4中重新提示?

[英]How to reprompt in botframework v4?

我無法使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();
    }

當您符合要求向客戶端發送提示對話框的條件時,您可以簡單地使用以下代碼:

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

讓我知道您是否需要更多信息。 看來您真的只是錯過了底線。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM