ComponentDialogs中的瀑布

时间:2019-03-07 09:51:01

标签: node.js botframework azure-bot-service

WaterfallDialogs中由LUIS触发的ComponentDialogs中实现BotFramework V4.2时遇到问题。第一步之后,对话框不会继续瀑布。 我真的不明白持久化ComponentDialog的正确方法是什么:保存ConversationState?设置step.context?我已经尝试过两种方法,但到目前为止都没有对我有用

这是我的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提供,其中我具有WaterfallDialogPrompts的逻辑:

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
        }          
    }

1 个答案:

答案 0 :(得分:0)

我不确定您要达到的目标,但是如果您使用的是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);