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


Step 1: Creating a QnA Maker service

Step 2: Linking a knowledge base

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

Step 3: Creating the bot

Step 4: Setting up the bot development environment

npm install -g msbot
npm install --save restify botbuilder-ai
msbot secret -b YOUR_BOT_NAME.bot --secret "YOUR_SECRET" --clear
node .\index.js

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'
const { EchoBot } = require('./bot');
const bot = new EchoBot(conversationState);
const endpointConfig = botConfig.findServiceByNameOrId(BOT_CONFIGURATION);
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
az login
az account set --subscription "<subscriptionID>"
az bot publish --name <bot-resource-name> --resource-group <resource-group-name> --code-dir '.' --verbose

Next step: Publishing to various channels

Entrepreneur, ex-Software Engineer @ Microsoft. I write about things related to Technology & Learning