node.js - 如何从另一个调用同一个对话框的对话框中调用一个对话框?
问题描述
我有一系列单独的对话框,其中一个对话框嵌入了 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;
解决方案
推荐阅读
- javascript - 在 React JS 中渲染图像的问题
- vba - 检查子表单中的记录集时引用无效
- python - Airflow Dag 不会因 python 脚本失败而失败
- arrays - 为什么在使用 ReadBytesExt 从字节片中读取整数时出现错误“特征界限不满足”?
- powershell - 如何更改 dir cmd 列出的文件的顺序
- android - 何时在 Android 中使用无头活动和服务?
- angular - HTML
带有脚本示例的标记无法在 TypeScript / Angular 应用程序中编译
- python-3.x - 如何使用 python 在 Windows 系统上编辑 docx 和/或 doc 文件标签?
- c++ - 从双向链表末尾删除节点时出现分段错误
- php - 按字段对对象数组进行排序没有区别