获取 DialogSet.add():测试时添加的对话框无效
Getting DialogSet.add(): Invalid dialog being added when testing
我正在尝试为我的机器人对话构建一些测试。我对两个具有相同对话框名称的不同机器人使用相同的测试代码(和修改后的测试数据)。因此,两个机器人的 test.js 文件是相同的。但是,当我尝试在第二个机器人上通过 Mocha 运行 我的测试时,我收到每个测试的 Error: DialogSet.add(): Invalid dialog being added.
消息。我的第一个机器人不会发生这种情况。我什至尝试将第二个机器人中的对话框文件替换为第一个(工作)机器人中的对话框文件,但我仍然遇到同样的错误。因此,我找不到机器人之间的任何不同之处。我什至用第一个机器人的文件替换了所有有问题的文件(测试、测试 data/conversation 和对话框本身),但仍然出现相同的错误。最后,所有 botbuilder 包和其他依赖项在机器人之间都是相同的版本。我在这里不知所措...有人有什么想法吗?
这是正在调用的对话框。我省略了实际的对话步骤,但这与问题无关,因为所有对话添加 activity 都发生在构造函数中。
const { TextPrompt, ChoicePrompt, ConfirmPrompt, ChoiceFactory, ComponentDialog, WaterfallDialog, DialogSet, DialogTurnStatus } = require('botbuilder-dialogs');
const { VistaServiceHelper } = require('../helpers/vistaServiceHelper');
const { TrackingServiceHelper } = require('../helpers/trackingServiceHelper');
const { CosmosDbStorage } = require('botbuilder-azure');
const LINE_PROMPT = 'linePrompt';
const ORDER_PROMPT = 'orderPrompt';
const CRITERIA_PROMPT = 'criteriaPrompt';
const SEARCH_CRITERIA = ['GO', 'PO'];
const WATERFALL_DIALOG = 'waterfallDialog';
const CONFIRM_PROMPT = 'confirmPrompt';
// Static texts
const escalateMessage = `Escalation message here`
const msDay = 86400000;
class viewOrderDialog extends ComponentDialog {
constructor(dialogId, userDialogStateAccessor, userState) {
super(dialogId);
this.addDialog(new ChoicePrompt(CRITERIA_PROMPT));
this.addDialog(new TextPrompt(ORDER_PROMPT));
this.addDialog(new TextPrompt(LINE_PROMPT, this.validateLineNumber));
this.addDialog(new ConfirmPrompt(CONFIRM_PROMPT));
this.addDialog(new WaterfallDialog(WATERFALL_DIALOG, [
this.requestOrderNumber.bind(this),
this.selectSearchCriteria.bind(this),
this.displayLineItems.bind(this),
this.displayLineStatus.bind(this),
this.loopStep.bind(this)
]));
this.initialDialogId = WATERFALL_DIALOG;
this.integrationLog = new CosmosDbStorage({
serviceEndpoint: process.env.ACTUAL_SERVICE_ENDPOINT,
authKey: process.env.ACTUAL_AUTH_KEY,
databaseId: process.env.DATABASE,
collectionId: 'integration-logs'
});
this.queryData = {};
} // End constructor
我能够通过删除项目 node_modules 文件夹中的 botbuilder-testing 文件夹并重新 运行ning npm install botbuilder-testing
来解决这个问题(即使我已经在 package.json 和 package-lock.json 正在显示最新版本并且有 运行 npm install
和 npm update
).
看来这确实源于某种 versioning issue,无论出于何种原因,只能完全删除文件夹并重新安装才能修复它。
您可能还想验证 package.json 文件中的 botbuilder 版本,因为所有这些包都必须是同一版本
例如:
"botbuilder": "~4.10.3",
"botbuilder-ai": "~4.10.3",
"botbuilder-dialogs": "~4.10.3",
"botbuilder-testing": "~4.10.3",
我认为接受的答案并非在所有情况下都有效。正确的答案是拥有相同的 botbuilder 和 botbuilder-testing 版本。
我遇到了同样的问题并放置了相同的版本(或者至少没有将 botbuilder 测试版本放在 botbuilder 之上工作)
Example
以下是协同工作的示例版本:
"botbuilder": "~4.13.6",
"botbuilder-dialogs": "~4.13.6",
"botbuilder-testing": "^4.13.6",
我正在尝试为我的机器人对话构建一些测试。我对两个具有相同对话框名称的不同机器人使用相同的测试代码(和修改后的测试数据)。因此,两个机器人的 test.js 文件是相同的。但是,当我尝试在第二个机器人上通过 Mocha 运行 我的测试时,我收到每个测试的 Error: DialogSet.add(): Invalid dialog being added.
消息。我的第一个机器人不会发生这种情况。我什至尝试将第二个机器人中的对话框文件替换为第一个(工作)机器人中的对话框文件,但我仍然遇到同样的错误。因此,我找不到机器人之间的任何不同之处。我什至用第一个机器人的文件替换了所有有问题的文件(测试、测试 data/conversation 和对话框本身),但仍然出现相同的错误。最后,所有 botbuilder 包和其他依赖项在机器人之间都是相同的版本。我在这里不知所措...有人有什么想法吗?
这是正在调用的对话框。我省略了实际的对话步骤,但这与问题无关,因为所有对话添加 activity 都发生在构造函数中。
const { TextPrompt, ChoicePrompt, ConfirmPrompt, ChoiceFactory, ComponentDialog, WaterfallDialog, DialogSet, DialogTurnStatus } = require('botbuilder-dialogs');
const { VistaServiceHelper } = require('../helpers/vistaServiceHelper');
const { TrackingServiceHelper } = require('../helpers/trackingServiceHelper');
const { CosmosDbStorage } = require('botbuilder-azure');
const LINE_PROMPT = 'linePrompt';
const ORDER_PROMPT = 'orderPrompt';
const CRITERIA_PROMPT = 'criteriaPrompt';
const SEARCH_CRITERIA = ['GO', 'PO'];
const WATERFALL_DIALOG = 'waterfallDialog';
const CONFIRM_PROMPT = 'confirmPrompt';
// Static texts
const escalateMessage = `Escalation message here`
const msDay = 86400000;
class viewOrderDialog extends ComponentDialog {
constructor(dialogId, userDialogStateAccessor, userState) {
super(dialogId);
this.addDialog(new ChoicePrompt(CRITERIA_PROMPT));
this.addDialog(new TextPrompt(ORDER_PROMPT));
this.addDialog(new TextPrompt(LINE_PROMPT, this.validateLineNumber));
this.addDialog(new ConfirmPrompt(CONFIRM_PROMPT));
this.addDialog(new WaterfallDialog(WATERFALL_DIALOG, [
this.requestOrderNumber.bind(this),
this.selectSearchCriteria.bind(this),
this.displayLineItems.bind(this),
this.displayLineStatus.bind(this),
this.loopStep.bind(this)
]));
this.initialDialogId = WATERFALL_DIALOG;
this.integrationLog = new CosmosDbStorage({
serviceEndpoint: process.env.ACTUAL_SERVICE_ENDPOINT,
authKey: process.env.ACTUAL_AUTH_KEY,
databaseId: process.env.DATABASE,
collectionId: 'integration-logs'
});
this.queryData = {};
} // End constructor
我能够通过删除项目 node_modules 文件夹中的 botbuilder-testing 文件夹并重新 运行ning npm install botbuilder-testing
来解决这个问题(即使我已经在 package.json 和 package-lock.json 正在显示最新版本并且有 运行 npm install
和 npm update
).
看来这确实源于某种 versioning issue,无论出于何种原因,只能完全删除文件夹并重新安装才能修复它。
您可能还想验证 package.json 文件中的 botbuilder 版本,因为所有这些包都必须是同一版本
例如:
"botbuilder": "~4.10.3",
"botbuilder-ai": "~4.10.3",
"botbuilder-dialogs": "~4.10.3",
"botbuilder-testing": "~4.10.3",
我认为接受的答案并非在所有情况下都有效。正确的答案是拥有相同的 botbuilder 和 botbuilder-testing 版本。 我遇到了同样的问题并放置了相同的版本(或者至少没有将 botbuilder 测试版本放在 botbuilder 之上工作) Example 以下是协同工作的示例版本:
"botbuilder": "~4.13.6",
"botbuilder-dialogs": "~4.13.6",
"botbuilder-testing": "^4.13.6",