Trying to connect Microsoft QnA maker service with Bot Framework but not getting any reply from my bot

  • A+
Category:Languages
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  

I'm new to Microsoft bot framework, trying to build basic bot using QnA maker

But I got stuck in connecting QnA maker service with app.js.

Not getting the response from QnA maker.

$ 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); 

 


The QnAMaker is currently in GA version, and is no longer in Preview. This doesn't seem like much, but it does mean the difference of a single recognizer variable: endpointHostName.

You currently have:

const recognizer = new cognitiveServices.QnAMakerRecognizer({     knowledgeBaseId: "kbid",     subscriptionKey: "subKey" }); 

INSTEAD, it should read as follows:

const recognizer = new cognitiveServices.QnAMakerRecognizer({     knowledgeBaseId: "kbid",     authKey: "subKey",     endpointHostName: "https://NAMEOFMYQNABOTHERE.azurewebsites.net/qnamaker" }); 

The endpoint is listed as 'HOST' on the code snippet from QnAMaker.ai.

As for the reason you're not getting any replies, it's because you don't have the code necessary for your bot to tell you it has no idea which QnAMaker Knowledgebase you're talking about. A minor alteration to your final bot.dialog portion will help this.

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');             }         }     ]); 

That way, if any of them are missing or incorrect, your bot will return the canned message shown above to let you know something's missing.

Happy coding!

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: