Bot QnA Maker sample
//DEMO-QNA2.JS
// Demonstrates use of the QnA Service
// Combines:
//https://stackoverflow.com/questions/42629688/begin-dialog-with-qna-maker-bot-framework-recognizer-node-js
//and
//https://github.com/Microsoft/BotBuilder-CognitiveServices/blob/master/Node/samples/QnAMakerSimpleBot/app.js
'use strict';
// 01. Include required files
require('dotenv-extended').load();
var restify = require('restify');
var builder = require('botbuilder');
var cognitiveservices = require('botbuilder-cognitiveservices');
// ---------------------------------------------------------------------------------------------------------------------
// 02. Setup Restify Server
var server = restify.createServer();
// 03. Configure listen for messages
server.listen(process.env.PORT || 3978, function()
{
console.log('%s listening to %s', server.name, server.url);
});
// 04. 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);
// 05. Listen for messages
server.post('/api/messages', connector.listen());
// 06. Serve static files
server.get(/.*/, restify.serveStatic({
directory: __dirname,
'default': 'index.html'
}));
var recognizer = new cognitiveservices.QnAMakerRecognizer({
knowledgeBaseId: '69b068c4-3487-4f08-9986-6c2e53df8b83',
subscriptionKey: '3f7dd24004444c8489eb23aa2d661102'});
var basicQnAMakerDialog = new cognitiveservices.QnAMakerDialog({
recognizers: [recognizer],
defaultMessage: 'No match! Try changing the query terms!',
qnaThreshold: 0.3
});
bot.dialog('/', [
function(session){
session.beginDialog('welcome');
},
function(session, results){
if (results.response == 'Rocco') {
session.say ('Hi boss!');
} else {
session.beginDialog('dialog');
}
}
]);
bot.dialog('welcome', [
function (session) {
// Send a greeting and show help.
builder.Prompts.text(session, "Hi! How can I help you?");
}
]);
bot.dialog('dialog', basicQnAMakerDialog);