Detect end of conversation and ask for a feedback in azure Bot

半世苍凉 提交于 2020-02-01 09:12:34

问题


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.


回答1:


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

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

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.

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.

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

Hope of help!


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:

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

class MainDialog extends FeedbackDialog {
  [...]
}

module.exports.MainDialog = MainDialog;

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;


来源:https://stackoverflow.com/questions/57149147/detect-end-of-conversation-and-ask-for-a-feedback-in-azure-bot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!