我用微软的BotFramework实现了一个机器人。为了收集用户数据,我使用ChoicePrompts。当用户没有选择所建议的选项之一时,ChoicePrompt会重复执行,直到用户输入一个有效选项(这是提示方法中的默认行为)。
不幸的是,在没有选择一个有效的选择选项后,用户状态将被刷新。这意味着,在此之前,我将丢失所有收集的用户数据。
这种行为是有意的还是有办法防止这种情况发生?
发布于 2019-03-19 00:16:03
您提供的链接上的代码有几个问题。由于我看不到您的完整代码,所以我对某些部分进行了猜测。
const DIALOG_STATE_PROPERTY = 'dialogState';
const USER_PROFILE_PROPERTY = 'user';
const EDUCATION_PROMPT = 'education_prompt';
const MAJOR_PROMPT = 'major_prompt';
constructor(conversationState, userState) {
this.conversationState = conversationState;
this.userState = userState;
this.dialogState = this.conversationState.createProperty(DIALOG_STATE_PROPERTY);
this.userData = this.userState.createProperty(USER_PROFILE_PROPERTY);
this.dialogs = new DialogSet(this.dialogState);
// Add prompts that will be used by the main dialogs.
this.dialogs
.add(new TextPrompt(NAME_PROMPT))
.add(new TextPrompt(AGE_PROMPT))
.add(new TextPrompt(GENDER_PROMPT))
.add(new ChoicePrompt(EDUCATION_PROMPT))
.add(new ChoicePrompt(MAJOR_PROMPT));
// Create dialog for prompting user for profile data
this.dialogs.add(new WaterfallDialog(START_DIALOG, [
this.promptForName.bind(this),
this.promptForAge.bind(this),
this.promptForGender.bind(this),
this.promptForEducation.bind(this),
this.promptForMajor.bind(this),
this.returnUser.bind(this)
]));
this.majors = ['English', 'History', 'Computer Science'];
}.add(new TextPrompt(GENDER_PROMPT))
.add(new ChoicePrompt(EDUCATION_PROMPT))
...
if (!user.gender) {
user.gender = step.result;
// Give user object back to UserState storage
await this.userData.set(step.context, user);
console.log(user);
}this.majors = ['English', 'History', 'Computer Science'];
...
if (!user.major) {
// Copy List of majors and add "Other" entry
let majorsOther = this.majors.slice(0, this.majors.length);
majorsOther.push('Einen anderen Studiengang');
// return await step.prompt(MAJOR_PROMPT, this.userData.major, majorsOther);
return await step.prompt(MAJOR_PROMPT, 'List of majors:', majorsOther);
}

// Save changes to the user state.
await this.userState.saveChanges(turnContext);
// End this turn by saving changes to the conversation state.
await this.conversationState.saveChanges(turnContext);如果您实现了上述功能,则应该设置。我能够在没有任何问题和国家损失的情况下竞选。此外,在最后提供适当的响应之前,反复不响应ChoicePrompt并不会破坏状态。

希望得到帮助!
https://stackoverflow.com/questions/54825916
复制相似问题