gpt4 book ai didi

node.js - 从 bot.on ('send' 调用 processMessage())

转载 作者:行者123 更新时间:2023-11-28 20:28:18 28 4
gpt4 key购买 nike

我正在使用 Jest 为我的机器人编写测试,我有以下代码:

let bot;
let conn;
let index = 0;
let responses = [];
let expectedResponses = [];

beforeEach(() => {
let connector = new builder.ConsoleConnector();
bot = new builder.UniversalBot(connector);
conn = connector;
});

test('test case 1 jeff', () => {
bot.library(require('../dialogs/inputRecognizer').createLibrary());
// the main dialog "/" should start "inputRecognizer:/"
// as it can be seen [https://github.com/Microsoft/BotBuilder/blob/858aad96cdd1fabbf7f9a29ee797eb03111d7cba/Node/core/tests/Dialogs.js][1] the code below seems to be identical to the one shown in examples
bot.dialog('/', [
(session) => {
session.beginDialog('inputRecognizer:/');
}
]);

basicMessages.forEach(o => {if (o.in) {expectedResponses.push(o.in)}});

bot.on('send', function (message) {
responses.push(message.text);
index++;
if (index < testMessages.length) {
conn.processMessage(basicMessages[index].out);
} else {
expect(responses).toEqual(expectedResponses);
}
});

conn.processMessage(basicMessages[0].out);
});

代码运行良好,并将我的所有消息输入连接器。但是,第二条消息被视为新对话,以下所有消息也是如此。所以我得到的是对话一遍又一遍地开始。

我查看了 GitHub 上的 BotFramework 测试,看起来他们正在使用类似的方法(在“发送”事件处理程序之外触发第一个 processMessage,然后从处理程序调用下一个)。

如何让 processMessage 不每次都重新启动我的对话框?我想这可能是我的对话有问题,对吧?

我的对话代码(“inputRecognizer:/”):

lib.dialog('/', [
function (session) {
// it always executes this part
builder.Prompts.text(session,
`Please type your inquiry!`);
},
(session, result) => {
if (result.response) {
// and it never gets to here

编辑:basicMessages 是这样的:

module.exports = [
{
out: 'hi',
in: 'Please type your inquiry!',
},
{
out: 'aaa',
in: 'Please type your inquiry!'
},
{
out: 'aaa',
in: 'Please type your inquiry!'
},
{
out: 'aaaa',
in: 'Please type your inquiry!'
},
{
out: 'aa',
in: 'Please type your inquiry!'
}
];

最佳答案

看来你的 basicMessages 是错误的:你的 expectedResponses 数组看起来像:

["Please type your inquiry!", "Please type your inquiry!", "Please type your inquiry!", "Please type your inquiry!", "Please type your inquiry!"]

我不认为这是预期的,因为您将 messages.Text 添加到稍后用于断言的 responses 列表中。

此外,您不需要 createLibrary();

你可以只使用 bot.library(require('../dialogs/inputRecognizer'));

我重新创建了您的项目 ( GitHub ),代码在提示后顺利到达 waterfall 。

关于node.js - 从 bot.on ('send' 调用 processMessage()),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43590877/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com