首页 > 解决方案 > 如何从另一个调用同一个对话框的对话框中调用一个对话框?

问题描述

我有一系列单独的对话框,其中一个对话框嵌入了 LUIS。我正在从 .However 中调用所有其他对话框。LUISDialog但是,我希望其中一个对话框从中调用。但是LUISDialog在这样做时,我收到了一个错误DialogA is not a constructor

我到目前为止的代码:

const { ComponentDialog, TextPrompt, WaterfallDialog, DialogTurnStatus } = require("botbuilder-dialogs");
const { CardFactory, InputHints, MessageFactory, ActionTypes, ActivityTypes } = require("botbuilder");

const LUIS_DIALOG = "MainWaterfallDialog";

const { DialogA } = require("./DialogA");
const DIALOG_A = 'DIALOG_A';
const dialogA = new DialogA(DIALOG_A);

const { DialogB } = require("./DialogB");
const DIALOG_B = 'DIALOG_B';
const dialogB = new DialogB(DIALOG_B);

const { DialogC } = require("./DialogC");
const DIALOG_C = 'DIALOG_C';
const dialogC = new DialogC(DIALOG_C);

class LUISDialog extends ComponentDialog {
    constructor(id) {
        super(id);

        this.addDialog(new TextPrompt('TextPrompt'))
            .addDialog(new WaterfallDialog(LUIS_DIALOG, [
                this.actStep.bind(this),
            ]));

        this.addDialog(dialogC);
        this.addDialog(dialogA);
        this.addDialog(dialogB);

        this.initialDialogId = LUIS_DIALOG;

    }

    async actStep(stepContext) {

        //LUIS Content Goes Here
        switch(LUISIntent) {
            case "A": {
                 return await stepContext.beginDialog(DIALOG_A, stepContext.options);
            }
            case "B": {
                 return await stepContext.beginDialog(DIALOG_B, stepContext.options);
            }
            case "C": {
                 return await stepContext.beginDialog(DIALOG_C, stepContext.options);
            }
            "default" : {
                return await stepContext.endDialog();
            }
        }
    }

}

module.exports.LUISDialog = LUISDialog;

DialogA如下:

const { ComponentDialog, WaterfallDialog, TextPrompt, DialogTurnStatus } = require('botbuilder-dialogs');
const { MessageFactory, CardFactory, InputHints, ActivityTypes } = require('botbuilder');

const { LUISDialog } = require("./LUISDialog");
const LUIS_DIALOG = 'LUIS_DIALOG';
const luisDialog = new LUISDialog(LUIS_DIALOG);

const DIALOG_A = 'WaterfallDialog';
const TEXT_PROMPT = 'TextPrompt';

var data = {};

class DialogA extends ComponentDialog {

    constructor(id) {
        super(id);

        this.addDialog(
            new WaterfallDialog(DIALOG_A ,[
                this.getData.bind(this),
                this.setData.bind(this)
            ])
        ).addDialog(new TextPrompt(TEXT_PROMPT));
        
        this.addDialog(luisDialog);

        this.initialDialogId = DIALOG_A;

    }

    async getData(stepContext) 
    {
        //API Call to retrieve some data
        data = result;
        //Data displayed as adaptive card
        //Waiting for user to select card option
        return { status: DialogTurnStatus.waiting };
    }

    async setData(stepContext) {
        //If user does not select Card Action and type something else
        //Call the LUIS Dialog to recognize
        return await stepContext.beginDialog(LUIS_DIALOG, stepContext);
    }
}

module.exports.DialogA = DialogA;

标签: node.jsbotframework

解决方案


推荐阅读