Image for post
Image for post

End-to-end chatbot creation in node.js with Bot Framework v4 & QnA Maker

Intro

Step 1: Creating a QnA Maker service

Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

Step 2: Linking a knowledge base

Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
POST /knowledgebases/<kbID>/generateAnswer
Host: <hostName>/qnamaker
Authorization: EndpointKey <endpointKey>
Content-Type: application/json
{"question":"<Your question>"}

Step 3: Creating the bot

Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

Step 4: Setting up the bot development environment

npm install -g msbot
Image for post
Image for post
botFilePath=./your_bot_name.bot
botFileSecret=""
npm install --save restify botbuilder-ai
msbot secret -b YOUR_BOT_NAME.bot --secret "YOUR_SECRET" --clear
Image for post
Image for post
node .\index.js
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

Step 5: Building the bot logic

,{
'type': 'qna',
'name': 'DemoKB',
'kbId': 'YOUR_KBID',
'subscriptionKey': 'YOUR_SUBSCRIPTION_KEY',
'endpointKey': 'YOUR_ENDPOINT_KEY',
'hostname': 'YOUR_HOSTNAME',
'id': '117'
}
Image for post
Image for post
Image for post
Image for post
const BOT_CONFIGURATION = (process.env.NODE_ENV || DEV_ENVIRONMENT);
const { EchoBot } = require('./bot');
const bot = new EchoBot(conversationState);
const endpointConfig = botConfig.findServiceByNameOrId(BOT_CONFIGURATION);
Image for post
Image for post
await turnContext.sendActivity('Welcome to the QnA Maker sample! Ask me a question and I will try to answer it.');
await turnContext.sendActivity('No QnA Maker answers were found. This example uses a QnA Maker Knowledge Base that focuses on smart light bulbs. To see QnA Maker in action, ask the bot questions like "Why won\'t it turn on?" or "I need help."');

Step 6: Deploying the bot to Azure

msbot secret --new
Image for post
Image for post
az login
az account set --subscription "<subscriptionID>"
Image for post
Image for post
az bot publish --name <bot-resource-name> --resource-group <resource-group-name> --code-dir '.' --verbose
Image for post
Image for post
Image for post
Image for post

Next step: Publishing to various channels

Image for post
Image for post

Software Engineer @ Microsoft. I write about things related to Technology & Learning

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store