gpt4 book ai didi

node.js - Card显示后,如何在sdk v4.4中继续 waterfall 式对话框流程

转载 作者:太空宇宙 更新时间:2023-11-03 22:20:30 25 4
gpt4 key购买 nike

我引用了示例代码并尝试了简单的场景来显示卡片。卡片显示后如何继续Waterfall_Dialog?

我指的是示例代码 05.multi-turn-prompt 和 06.using-cards - ( https://github.com/microsoft/BotBuilder-Samples/blob/master/samples/javascript_nodejs/05.multi-turn-prompt/dialogs/userProfileDialog.js )

      ...this.addDialog(new WaterfallDialog(WATERFALL_DIALOG, [
this.initialData.bind(this),
this.displayCard.bind(this),
this.text.bind(this)
])); ...

async run(turnContext, accessor) {
...}

async initialData(step) {
return await step.prompt(NAME_PROMPT, `Type anything to display card`);
}

async displayCard(step) {
await step.context.sendActivity({ attachments: [this.createAdaptiveCard()]});
}

async text(step) {
console.log("step.res"+step.context.activity.text);
await step.context.sendActivity("Thank you for selecting an option");

}
<小时/>
async displayCard(step) {
await step.context.sendActivity({ attachments: [this.createAdaptiveCard()]});
return await this.text(step);
}

显示卡片并继续 waterfall 对话框。

显示卡片后,它应该继续流程并显示“感谢您选择一个选项”,

  1. 但是它将进入 Begin_Dialog 并要求“键入任何内容以显示卡片”

  2. 如果我通过调用下一个对话框来尝试其他方法。我得到“哎呀。出了点问题!”“[onTurnError]:TypeError:无法读取未定义的属性“状态””

最佳答案

要前进到下一个对话框步骤,您需要在包含该卡的步骤之后调用 NextAsync。

例如,

private async Task<DialogTurnResult> StartSelectionStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
// Set the user's age to what they entered in response to the age prompt.
var userProfile = (UserProfile)stepContext.Values[UserInfo];
userProfile.Age = (int)stepContext.Result;

if (userProfile.Age < 25)
{
// If they are too young, skip the review selection dialog, and pass an empty list to the next step.
await stepContext.Context.SendActivityAsync(
MessageFactory.Text("You must be 25 or older to participate."),
cancellationToken);
return await stepContext.NextAsync(new List<string>(), cancellationToken);
}
else
{
// Otherwise, start the review selection dialog.
return await stepContext.BeginDialogAsync(nameof(ReviewSelectionDialog), null, cancellationToken);
}
}

在上面的代码片段中,如果用户的年龄不正确,则会显示一条消息说明同样的情况。调用 return wait stepContext.NextAsync() ,使对话框前进到下一步。如果用户已成年,则开始新的对话框(“ReviewSelectionDialog”)。该代码片段来自“使用分支和循环创建高级对话流”的文档,位于 here ,你可以引用一下。

希望得到帮助!

关于node.js - Card显示后,如何在sdk v4.4中继续 waterfall 式对话框流程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56488297/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com