触发动作方法的替代方法

时间:2019-06-20 06:22:23

标签: node.js botframework

在bot框架v3中,使用触发操作方法来处理LUIS中断。在bot框架v4 node.js中可以使用什么替代方案?

1 个答案:

答案 0 :(得分:0)

请查看来自Botbuilder-Samples GitHub 13.core-bot的示例repo

基本上,您有一个“取消”对话框,用于侦听中断。然后,将其他对话框扩展到“取消”对话框之外。这允许拾取标记为中断的用户语句(例如help),并发生任何关联的逻辑。在这种情况下,await innerDc.context.sendActivity('[ This is where to send sample help to the user... ]');作为help响应发送。

CancelAndHelpDialog:

class CancelAndHelpDialog extends ComponentDialog {
    async onBeginDialog(innerDc, options) {
        const result = await this.interrupt(innerDc);
        if(result) {
            return result;
        }
        return await super.onBeginDialog(innerDc, options);
    }
    async onContinueDialog(innerDc) {
        const result = await this.interrupt(innerDc);
        if(result) {
            return result;
        }
        return await super.onContinueDialog(innerDc);
    }
    async interrupt(innerDc) {
        const text = innerDc.context.activity.text.toLowerCase();
        switch(text) {
            case 'help':
            case '?':
                await innerDc.context.sendActivity('[ This is where to send sample help to the user... ]');
                return {
                    status: DialogTurnStatus.waiting
                };
            case 'cancel':
            case 'quit':
                await innerDc.context.sendActivity('Cancelling');
                return await innerDc.cancelAllDialogs();
        }
    }
}

BookingDialog扩展了CancelAndHelpDialog:

const { CancelAndHelpDialog } = require('./cancelAndHelpDialog');

class BookingDialog extends CancelAndHelpDialog {
  constructor(id) {
    super(id || 'bookingDialog');

    [...]
  }

  [...]
}

希望有帮助!