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机器人框架的新手,试图使用QnA制造商构建基本的机器人
但是我在将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.
app.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);
答案 0 :(得分:4)
QnAMaker当前处于GA版本,并且不再处于Preview状态。看起来似乎不多,但这确实意味着一个识别器变量的不同:endpointHostName。
您当前拥有:
const recognizer = new cognitiveServices.QnAMakerRecognizer({
knowledgeBaseId: "kbid",
subscriptionKey: "subKey"
});
INSTEAD,其内容应为:
const recognizer = new cognitiveServices.QnAMakerRecognizer({
knowledgeBaseId: "kbid",
authKey: "subKey",
endpointHostName: "https://NAMEOFMYQNABOTHERE.azurewebsites.net/qnamaker"
});
在QnAMaker.ai的代码段中,该端点被列为“主机”。
由于您没有得到任何答复的原因,这是因为您没有使机器人知道它所需要的代码,而不知道您在谈论哪个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');
}
}
]);
这样,如果其中任何一个丢失或不正确,您的机器人将返回上面显示的固定消息,让您知道某些丢失的东西。
编码愉快!
答案 1 :(得分:0)
只需确保您使用的是有效的knowledgeBaseId
和authKey
,然后使用GA announcement提供的示例,按照here所述添加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);