node.js - 尝试将 Microsoft QnA 制造商服务与 Bot Framework 连接,但未从我的机器人那里得到任何回复
问题描述
Bot Framework Emulator
[18:48:31] -> POST 202 [conversationUpdate]
[18:48:31] -> POST 202 [conversationUpdate]
[18:48:36] -> POST 202 [message] hello
[18:48:37] Warning: The Bot Framework State API is not recommended for production environments, and may be deprecated in a
future release. Learn how to implement your own storage adapter.
[18:48:37] <- GET 200 getPrivateConversationData
[18:48:37] <- GET 200 getUserData
[18:48:37] <- GET 200 getConversationData
[18:48:37] <- POST 200 setPrivateConversationData
[18:48:37] <- POST 200 Reply[event] Debug Event
我是 Microsoft bot 框架的新手,正在尝试使用 QnA maker 构建基本 bot
但我被困在将 QnA 制造商服务与app.js
.
没有得到 QnA 制造商的回复。
$ nodemon app.js
[nodemon] 1.17.5
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node app.js`
restify listening to http://[::]:3978
WARN: ChatConnector: receive - emulator running without security enabled.
ChatConnector: message received.
WARN: ChatConnector: receive - emulator running without security enabled.
ChatConnector: message received.
WARN: ChatConnector: receive - emulator running without security enabled.
ChatConnector: message received.
The Bot State API is deprecated. Please refer to https://aka.ms/I6swrh for details on how to replace with your own storage.
UniversalBot("*") routing "hello" from "emulator"
Session.beginDialog(/)
/ - Session.sendBatch() sending 0 message(s)
The Bot State API is deprecated. Please refer to https://aka.ms/I6swrh for details on how to replace with your own storage.
应用程序.js
const restify = require('restify');
const builder = require('botbuilder');
const cognitiveServices = require('botbuilder-cognitiveservices');
//connecting to server
const server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978,
function () {
console.log('%s listening to %s',server.name,server.url);
}
);
const connector = new builder.ChatConnector({
appId: process.env.MicrosoftAppId,
appPassword: process.env.MicrosoftAppPassword
});
//listening post from server
server.post('/api/messages', connector.listen());
var bot = new builder.UniversalBot(connector);
const recognizer = new cognitiveServices.QnAMakerRecognizer({
knowledgeBaseId: "ffek8d39-dldc-48df-a9db-d902efc18cda",
subscriptionKey: "881jc9eb-1a5b-4a10-bi89-233afh83ce98",
});
const qnaMakerDialog = new cognitiveServices.QnAMakerDialog({
recognizers: [recognizer],
defaultMessage: "Sorry I don't understand the question",
qnaThreshold: 0.4,
});
bot.dialog('/', qnaMakerDialog);
解决方案
QnAMaker 当前处于 GA 版本,不再处于预览状态。这看起来并不多,但它确实意味着单个识别器变量的区别:endpointHostName。
您目前拥有:
const recognizer = new cognitiveServices.QnAMakerRecognizer({
knowledgeBaseId: "kbid",
subscriptionKey: "subKey"
});
相反,它应该如下所示:
const recognizer = new cognitiveServices.QnAMakerRecognizer({
knowledgeBaseId: "kbid",
authKey: "subKey",
endpointHostName: "https://NAMEOFMYQNABOTHERE.azurewebsites.net/qnamaker"
});
端点在 QnAMaker.ai 的代码片段中列为“HOST”。
至于您没有收到任何回复的原因,那是因为您没有必要的代码让您的机器人告诉您它不知道您在谈论哪个 QnAMaker 知识库。对最终的 bot.dialog 部分稍作改动将对此有所帮助。
bot.dialog('qnaMakerDialog', qnaMakerDialog);
bot.dialog('/',
[
function (session) {
var qnaKnowledgebaseId = "kbid";
var qnaAuthKey = "subKey";
var endpointHostName = "https://NAMEOFMYQNABOTHERE.azurewebsites.net/qnamaker";
// QnA Subscription Key and KnowledgeBase Id null verification
if ((qnaAuthKey == null || qnaAuthKey == '') || (qnaKnowledgebaseId == null || qnaKnowledgebaseId == ''))
session.send('Please set QnAKnowledgebaseId, QnAAuthKey and QnAEndpointHostName (if applicable) in App Settings. Learn how to get them at https://aka.ms/qnaabssetup.');
else {
session.replaceDialog('qnaMakerDialog');
}
}
]);
这样,如果其中任何一个丢失或不正确,您的机器人将返回上面显示的预设消息,让您知道缺少某些内容。
快乐编码!
推荐阅读
- vb.net - 未定义 Visual Studio 'null'
- sql - Python SQL 中的嵌套查询导致空数据框
- ruby - 如何在 Ruby 中始终如一地获得 ASCII-8BIT 编码?
- kotlin - 如何在 MVVM 中更新实时数据
- google-bigquery - Maxmind 为 GeoLite 提供的 Big Query 公共数据集中是否有英文地理位置数据?
- assembly - NASM 错误:COFF 格式不支持非 32 位重定位
- git - OpenSSL SSL_connect: SSL_ERROR_SYSCALL 连接到 gitlab:443
- ios - 斯威夫特 | 从图像数组中创建视频
- python - 使用 GitHub API 尝试评论拉取请求时收到错误“解析 JSON 的问题”
- javascript - 从通过 DataTables 和 Ajax 进行服务器端数据处理的网站抓取数据