需要一个简单的提示的WaterfallDialog吗?

时间:2019-03-07 21:31:14

标签: c# asp.net-core botframework

我是来自v3的BotFramework v4的新手,很难理解v4的对话框概念

我试图询问用户例如他的年龄,然后我想结束对话,我试图将对话框动态添加到DialogSet,但是ContinueDialogAsyncResumeDialogAsync都会不被打电话。提示后,对话立即结束,将不等待答案。

这是TextPrompt的调用:

dialogContext.Dialogs.Add(new TextPrompt("age"));
return await dialogContext.PromptAsync("age", new PromptOptions
{
    Prompt = MessageFactory.Text("How old are you?")
});

我真的需要一步实现瀑布对话框吗?

2 个答案:

答案 0 :(得分:0)

您不需要使用瀑布对话框。 Simple Prompt Bot Sample应该会让您入门。

Relevant code snippet

if (results.Status == DialogTurnStatus.Empty)
{
    // A prompt dialog can be started directly on the DialogContext. The prompt text is given in the PromptOptions.
    await dialogContext.PromptAsync(
        "name",
        new PromptOptions { Prompt = MessageFactory.Text("Please enter your name.") },
        cancellationToken);
}

// We had a dialog run (it was the prompt). Now it is Complete.
else if (results.Status == DialogTurnStatus.Complete)
{
    // Check for a result.
    if (results.Result != null)
    {
        // Finish by sending a message to the user. Next time ContinueAsync is called it will return DialogTurnStatus.Empty.
        await turnContext.SendActivityAsync(MessageFactory.Text($"Thank you, I have your name as '{results.Result}'."));
    }
}
}

有关其他信息,我发布了与this question类似的答案,而我的同事也有类似的答案here

答案 1 :(得分:0)

好的,我想一个人回答这个问题: botframework v4具有一个IBot接口,并且所有消息都通过已实现接口的单例实例进行路由。因此,我认为启动的对话框将直接获得用户的响应。相反,您对IBot的实现需要创建一个dialogContext,还需要在OnTurnAsync方法中继续活动对话框:

var dialogContext = await _dialogs.CreateContextAsync(context, cancellationToken);

if (dialogContext.ActiveDialog is null)
{
    await dialogContext.BeginDialogAsync(nameof(AgeDialog),
        cancellationToken: cancellationToken);
}
else
{
    await dialogContext.ContinueDialogAsync(cancellationToken);
}


await _accessor.ConversationState.SaveChangesAsync(context, false, cancellationToken);