问题
I have a dialog where a prompt in the first step is getting skipped. I determined that what is happening is that somehow step.context.activity.text is automatically being interpreted as the prompt response. For example, if I trigger the dialog with "Expedite my order", step.context.activity.text in the first step is "Expedite my order", the prompt is skipped, and step.result in the next step is "Expedite my order".
I tried creating a "buffer step" as step 1 that just did return await step.next()
, but the same activity.text was then captured as the prompt response in step 2!
Interestingly, I created a mock dialog test with mocha and it did NOT exhibit these issues. I have other dialogs within the bot that also have a text prompt on step one and they are not exhibiting these issues either in mocha tests OR running in emulator (or deployed on Azure). I did note there is one difference within step.context: the dialogs that are working have step.context.responded = false
and the one which is skipping the prompt has step.context.responded = true`. But I have no idea why this is set in one case but not others. This seems to be an important part of the puzzle.
I did "solve" this by setting step.context.activity.text = ''
at the beginning of the step, but that seems like a bad practice. Any idea on why this is happening within this prompt? Below is my dialog code through that first step.
const { TextPrompt, ChoicePrompt, ChoiceFactory, ComponentDialog, WaterfallDialog } = require('botbuilder-dialogs');
const { oemLocatorHelper } = require('../helpers/oemLocatorHelper');
const WATERFALL_DIALOG = 'waterfallDialog2';
const CHOICE_PROMPT = 'choicePrompt';
const TEXT_PROMPT = 'textPrompt';
const ESCALATION_OPTIONS = ['Chat','Email','Call','No Thanks'];
class escalationDialog extends ComponentDialog {
constructor(dialogId, userDialogStateAccessor, userState) {
super(dialogId);
this.addDialog(new ChoicePrompt(CHOICE_PROMPT));
this.addDialog(new TextPrompt(TEXT_PROMPT));
this.addDialog(new WaterfallDialog(WATERFALL_DIALOG, [
this.promptAccount.bind(this),
this.promptChannel.bind(this),
this.promptSummary.bind(this)
]));
this.initialDialogId = WATERFALL_DIALOG;
// State accessors
this.userDialogStateAccessor = userDialogStateAccessor;
this.userState = userState;
} // End constructor
async promptAccount(step) {
if (step.context.responded) {
step.context.activity.text = '';
}
const userData = await this.userDialogStateAccessor.get(step.context, {});
if (userData.accountNumber) {
return userData.accountNumber;
} else {
return await step.prompt(TEXT_PROMPT, `To help me get you to the right agent, can you please provide me your account number?`);
}
}
EDIT: Should be step.context.activity.text, not step.activity.text. Updated in several spots. Also, the change now clears this value only if step.context.responded is true.
回答1:
I believe the problem is that your bot class is calling continueDialog
on the same turn that it begins escalationDialog
. I have commented on your private GitHub issue.
来源:https://stackoverflow.com/questions/59385126/waterfall-prompt-using-activity-text-instead-of-actually-prompting-user