本文介绍了检测对话结束并在天蓝色的Bot中寻求反馈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Node.js中的azure bot框架创建聊天机器人.QnA制造商可以存储问题答案和一个LUIS应用程序.现在,我想检测对话的结束(通过检查长时间未回复的内容或刷新网页),并在对话结束时添加反馈卡.

I am creating a chat bot using azure bot framework in Nodejs.QnA maker to store question answers and one LUIS app.Now I want to detect end of conversation(either by checking no reply from long time or refreshing a webpage) and add feedback card at the end of conversation.

推荐答案

您可以通过使用onEndDialog方法并使用单独的类来管理反馈过程来实现此目的.

You can achieve this by use of the onEndDialog method and the use of a separate class to manage the feedback process.

首先,我有一个组件对话框,该对话框导入feedback.js文件并在onEndDialog中调用关联的onTurn()方法.

First, I have a component dialog that imports the feedback.js file and calls the associated onTurn() method within onEndDialog.

接下来,我在其中创建MainDialog extends FeedbackDialog的mainDialog.js文件.这样,FeedbackDialog坐在MainDialog的顶部",以侦听特定的用户输入或活动.在这种情况下,它正在监听EndDialog()被调用.您可能希望添加其他验证,以确保仅在调用所需的EndDialg()时触发.

Next, I create the mainDialog.js file in which MainDialog extends FeedbackDialog. In this way, FeedbackDialog sits "on top" of MainDialog listening for specific user inputs or activities. In this case, it is listening for EndDialog() to be called. You will likely want to add additional validation to be sure it only fires when the EndDialg() you want is called.

最后,在feedback.js文件中,这是您的反馈代码/逻辑所在的位置.为简单起见,我使用社区项目botbuilder-feedback生成用户反馈界面.大部分代码都集中在创建和管理基本"对话框上.其他对话框活动来自botbuilder-feedback程序包.

Lastly, in the feedback.js file, this is where your feedback code/logic lives. For simplicity, I'm using a community project, botbuilder-feedback, for generating a user feedback interface. The majority of the code is focused on creating and managing the "base" dialog. Additional dialog activity comes from within the botbuilder-feedback package.

作为参考,此代码部分基于在Botbuilder-Samples存储库中找到的13.core-bot 示例.

For reference, this code is based partly on the 13.core-bot sample found in the Botbuilder-Samples repo.

希望有帮助!

feedbackDialog.js:

feedbackDialog.js:

const { ComponentDialog } = require('botbuilder-dialogs');
const { Feedback } = require('./feedback');

class FeedbackDialog extends ComponentDialog {
  constructor() {
    super();
    this.feedback = new Feedback();
  }

  async onEndDialog ( innerDc ) {
    return await this.feedback.onTurn( innerDc );
  }
}

module.exports.FeedbackDialog = FeedbackDialog;

mainDialog.js:

mainDialog.js:

const { FeedbackDialog } = require( './feedbackDialog' );

class MainDialog extends FeedbackDialog {
  [...]
}

module.exports.MainDialog = MainDialog;

feedback.js:

feedback.js:

const { ActivityTypes } = require('botbuilder');
const { DialogTurnStatus } = require('botbuilder-dialogs');
const Botbuilder_Feedback = require('botbuilder-feedback').Feedback;

class Feedback {
  async onTurn(turnContext, next) {
    if (turnContext.activity.type === ActivityTypes.Message) {
      await Botbuilder_Feedback.sendFeedbackActivity(turnContext, 'Please rate this dialog');
      return { 'status': DialogTurnStatus.waiting };
    } else {
      return { 'status': DialogTurnStatus.cancelled };
    }
    await next();
  };
}

module.exports.Feedback = Feedback;

这篇关于检测对话结束并在天蓝色的Bot中寻求反馈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 14:28