ComponentDialogs 中的瀑布
Waterfall in ComponentDialogs
我在 ComponentDialogs
中实施 WaterfallDialogs
时遇到问题,由 BotFramework V4.2
中的 LUIS 触发。第一步之后,对话框不会继续 Waterfall。
我真的不明白坚持ComponentDialog
的正确方法应该是什么:保存ConversationState
?设置 step.context
?我都试过了,但 none 到目前为止对我有用
这是我的 bot.js 代码,其中我有一个 LUIS 实例作为对话框之间的协调器:
async onTurn(turnContext) {
...
switch (dialogResult.status) {
case DialogTurnStatus.empty:
// Call to LUIS recognizer to get intent + entities
const results = await this.luisRecognizer.recognize(dc.context);
const topIntent = results.luisResult.topScoringIntent;
switch (topIntent.intent) {
case FMM_INTENT:
return await dc.beginDialog(FeedbackDialog.Name);
...
}
case DialogTurnStatus.waiting:
// The active dialog is waiting for a response from the user, so do nothing
break;
...
}
这是我的 FeedbackDialog.js 代码,其中我有 WaterfallDialog
和 Prompts
的逻辑:
module.exports = {
FeedbackDialog: class extends ComponentDialog {
static get Name() { return DIALOG_NAME; }
constructor(conversationState, botConfig, feedbackStateAccessor, dialogId) {
(dialogId === undefined) ? super(DIALOG_NAME) : super(dialogId);
this.conversationState = conversationState;
this.feedbackStateAccessor = feedbackStateAccessor;
this.addDialog(new WaterfallDialog(FBK_EVAL, [
this.feedbackPrompt.bind(this),
this.feedbackEvaluation.bind(this)
]));
this.addDialog(new ChoicePrompt(FBK_PROMPT));
}
async feedbackPrompt(step) {
let fmmState = await this.feedbackStateAccessor.get(step.context);
if (fmmState === undefined) {
await this.feedbackStateAccessor.set(step.context);
//opciones válidas, las mayúsculas las detecta también
const options = ['',''];
return await step.prompt(FBK_PROMPT, {
prompt: `¿Te ha resultado útil la respuesta?`,
retryPrompt: `¿Qué te ha parecido la respuesta?`,
choices: options
});
}
}
async feedbackEvaluation(step) {
let fmmState = await this.feedbackStateAccessor.get(step.context);
if (fmmState === undefined && step.result){
if (step.result == ''){
await step.context.sendActivity("¡Gracias por el feedback!");
return await step.endDialog();
}else {
await step.context.sendActivity("¡Revisaremos tu pregunta para seguir mejorando!");
return await this.conversationState.saveChanges(step.context);
}
} else {
return await step.next();
//next steps omitted since the code doesn't reach this step
}
}
我不确定你想要达到什么目的,但如果你使用的是 ChoicePrompt,我相信步骤结果会返回到值键中,即而不是
if (step.result == '')
尝试
if (step.result.value === '')
然后您可以向用户发送回消息并结束对话,应该没问题:
await step.context.sendActivity("¡Gracias por el feedback!");
return step.endDialog();
或
await step.context.sendActivity("¡Revisaremos tu pregunta para seguir mejorando!");
return step.endDialog();
此外,请记住正确初始化对话框,即在您的 bot 文件中:
const { FeedbackDialog } = require('path/to/feedbackDialog')
const FEEDBACK_DIALOG = 'FeedbackDialog'
const FEEDBACK_PROPERTY = 'feedbackProperty'
并且在 bot 构造函数中(我使用 userState 作为状态访问器,而不是对话状态):
this.dialogs = new DialogSet(this.dialogState)
this.feedbackAccessor = userState.createProperty(FEEDBACK_PROPERTY)
this.dialogs.add(new FeedbackDialog(
FEEDBACK_DIALOG,
this.feedbackAccessor
))
然后将其命名为:
await dc.beginDialog(FEEDBACK_DIALOG);
我在 ComponentDialogs
中实施 WaterfallDialogs
时遇到问题,由 BotFramework V4.2
中的 LUIS 触发。第一步之后,对话框不会继续 Waterfall。
我真的不明白坚持ComponentDialog
的正确方法应该是什么:保存ConversationState
?设置 step.context
?我都试过了,但 none 到目前为止对我有用
这是我的 bot.js 代码,其中我有一个 LUIS 实例作为对话框之间的协调器:
async onTurn(turnContext) {
...
switch (dialogResult.status) {
case DialogTurnStatus.empty:
// Call to LUIS recognizer to get intent + entities
const results = await this.luisRecognizer.recognize(dc.context);
const topIntent = results.luisResult.topScoringIntent;
switch (topIntent.intent) {
case FMM_INTENT:
return await dc.beginDialog(FeedbackDialog.Name);
...
}
case DialogTurnStatus.waiting:
// The active dialog is waiting for a response from the user, so do nothing
break;
...
}
这是我的 FeedbackDialog.js 代码,其中我有 WaterfallDialog
和 Prompts
的逻辑:
module.exports = {
FeedbackDialog: class extends ComponentDialog {
static get Name() { return DIALOG_NAME; }
constructor(conversationState, botConfig, feedbackStateAccessor, dialogId) {
(dialogId === undefined) ? super(DIALOG_NAME) : super(dialogId);
this.conversationState = conversationState;
this.feedbackStateAccessor = feedbackStateAccessor;
this.addDialog(new WaterfallDialog(FBK_EVAL, [
this.feedbackPrompt.bind(this),
this.feedbackEvaluation.bind(this)
]));
this.addDialog(new ChoicePrompt(FBK_PROMPT));
}
async feedbackPrompt(step) {
let fmmState = await this.feedbackStateAccessor.get(step.context);
if (fmmState === undefined) {
await this.feedbackStateAccessor.set(step.context);
//opciones válidas, las mayúsculas las detecta también
const options = ['',''];
return await step.prompt(FBK_PROMPT, {
prompt: `¿Te ha resultado útil la respuesta?`,
retryPrompt: `¿Qué te ha parecido la respuesta?`,
choices: options
});
}
}
async feedbackEvaluation(step) {
let fmmState = await this.feedbackStateAccessor.get(step.context);
if (fmmState === undefined && step.result){
if (step.result == ''){
await step.context.sendActivity("¡Gracias por el feedback!");
return await step.endDialog();
}else {
await step.context.sendActivity("¡Revisaremos tu pregunta para seguir mejorando!");
return await this.conversationState.saveChanges(step.context);
}
} else {
return await step.next();
//next steps omitted since the code doesn't reach this step
}
}
我不确定你想要达到什么目的,但如果你使用的是 ChoicePrompt,我相信步骤结果会返回到值键中,即而不是
if (step.result == '')
尝试
if (step.result.value === '')
然后您可以向用户发送回消息并结束对话,应该没问题:
await step.context.sendActivity("¡Gracias por el feedback!");
return step.endDialog();
或
await step.context.sendActivity("¡Revisaremos tu pregunta para seguir mejorando!");
return step.endDialog();
此外,请记住正确初始化对话框,即在您的 bot 文件中:
const { FeedbackDialog } = require('path/to/feedbackDialog')
const FEEDBACK_DIALOG = 'FeedbackDialog'
const FEEDBACK_PROPERTY = 'feedbackProperty'
并且在 bot 构造函数中(我使用 userState 作为状态访问器,而不是对话状态):
this.dialogs = new DialogSet(this.dialogState)
this.feedbackAccessor = userState.createProperty(FEEDBACK_PROPERTY)
this.dialogs.add(new FeedbackDialog(
FEEDBACK_DIALOG,
this.feedbackAccessor
))
然后将其命名为:
await dc.beginDialog(FEEDBACK_DIALOG);