【发布时间】:2017-05-29 15:50:27
【问题描述】:
我有一个简单的聊天机器人,它获取用户的姓名并回复询问它如何帮助他们。它在模拟器和网络聊天中运行良好,但是当我通过 DirectLine 尝试将其作为 android 应用程序时,我得到了一个额外的提示,它只是空的。所以我放了一些代码来记录机器人的对话,我发现机器人正在发送一条消息“未定义”以及我编程它发送的提示。
我的代码示例
bot.dialog('/', new builder.IntentDialog()
.matchesAny([/hi/i], [
function (session) {
session.send('Hi, I am a chatbot.');
session.beginDialog('/step2')
},
bot.dialog('/step2', [
function (session) {
builder.Prompts.text(session, 'What is your name?');
},
function (session, args, next) {
session.send('Hello, ' + args.response + '. How may I help you today?');
name = args.response;
session.endConversation();
}
])
]));
当我放入一些中间件日志时,我得到了以下输出:
用户:嗨
BOT:嗨,我是聊天机器人。
BOT:你叫什么名字?
用户:鲍勃
BOT:你好,鲍勃。今天有什么可以帮你的吗?
机器人:未定义
甚至我的节点控制台也显示最后发送了 2 条消息,而不是仅发送一条
ChatConnector: message received.
UniversalBot("*") routing "Anish" from "emulator"
Library("BotBuilder").findRoutes() explanation:
ActiveDialog(0.5)
..BotBuilder:prompt-text - Prompt.returning(Anish)
..BotBuilder:prompt-text - Session.endDialogWithResult()
./step2 - waterfall() step 2 of 2
./step2 - Session.send()
./step2 - Session.endConversation()
Session.sendBatch() sending 2 message(s)
为什么要发送未定义的消息?我怎样才能阻止它?
【问题讨论】:
-
删除
Session.endConversation()会发生什么? -
@EzequielJadib 哇,这行得通。为什么
Session.endconversation()会造成这种情况? -
但是如果我不使用
session.endconversation(),当我回复“我可以帮你什么”时,机器人就会循环询问我的名字 -
其实可以在endConversation方法中发送消息(接受的参数之一是文本);但是,您将看到相同的行为,一旦您回复,它将以相同的问题开始对话
标签: node.js botframework