Node.js 正在尝试将Microsoft QnA maker服务与Bot框架连接,但未从我的Bot获得任何答复
app.jsNode.js 正在尝试将Microsoft QnA maker服务与Bot框架连接,但未从我的Bot获得任何答复,node.js,botframework,qnamaker,Node.js,Botframework,Qnamaker,app.js $ 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 enab
$ 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.
只需确保您使用的是有效的
knowledgeBaseId
和authKey
,并使用提供的示例添加endpointHostName
,如下所述
QnAMaker目前是GA版本,不再预览。这看起来不太像,但它确实意味着单个识别器变量的区别:endpointHostName 您目前有:
var restify = require('restify');
var builder = require('botbuilder');
var cognitiveservices = require('../../../lib/botbuilder-cognitiveservices');
//=========================================================
// Bot Setup
//=========================================================
// Setup Restify Server
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
// Create chat bot
var connector = new builder.ChatConnector({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
});
var bot = new builder.UniversalBot(connector);
bot.set('storage', new builder.MemoryBotStorage()); // Register in-memory state storage
server.post('/api/messages', connector.listen());
//=========================================================
// Bots Dialogs
//=========================================================
var recognizer = new cognitiveservices.QnAMakerRecognizer({
knowledgeBaseId: 'set your kbid here',
authKey: 'set your authorization key here',
endpointHostName: 'set your endpoint host name'});
var basicQnAMakerDialog = new cognitiveservices.QnAMakerDialog({
recognizers: [recognizer],
defaultMessage: 'No match! Try changing the query terms!',
qnaThreshold: 0.3
});
bot.dialog('/', basicQnAMakerDialog);
相反,应改为:
const recognizer = new cognitiveServices.QnAMakerRecognizer({
knowledgeBaseId: "kbid",
subscriptionKey: "subKey"
});
该端点在QnAMaker.ai的代码段中列为“主机”
至于你没有收到任何回复的原因,那是因为你没有必要的代码让你的机器人告诉你它不知道你在谈论哪个QnAMaker知识库。对最后的bot.dialog部分稍作修改将有助于实现这一点
const recognizer = new cognitiveServices.QnAMakerRecognizer({
knowledgeBaseId: "kbid",
authKey: "subKey",
endpointHostName: "https://NAMEOFMYQNABOTHERE.azurewebsites.net/qnamaker"
});
这样,如果其中任何一个丢失或不正确,您的机器人将返回上面显示的屏蔽消息,让您知道丢失了什么
快乐编码 欢迎光临!请将您的评论编辑到您的问题中。此外,您的代码片段似乎已损坏。缺少响应可能是服务器上的某些环境问题,而不是编码问题。
const recognizer = new cognitiveServices.QnAMakerRecognizer({
knowledgeBaseId: "kbid",
subscriptionKey: "subKey"
});
const recognizer = new cognitiveServices.QnAMakerRecognizer({
knowledgeBaseId: "kbid",
authKey: "subKey",
endpointHostName: "https://NAMEOFMYQNABOTHERE.azurewebsites.net/qnamaker"
});
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');
}
}
]);