Skip to content

Commit

Permalink
directly use SDK's QnAMakerDialog
Browse files Browse the repository at this point in the history
* unify sample headers
* cleanup additional unnecessary code
  • Loading branch information
stevengum committed Dec 14, 2020
1 parent 5c5f453 commit e306ca2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

const { ActivityHandler } = require('botbuilder');
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,33 +1,50 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

const { QnAMakerDialog } = require('botbuilder-ai');
const {
ComponentDialog,
DialogSet,
DialogTurnStatus,
WaterfallDialog
WaterfallDialog,
} = require('botbuilder-dialogs');

const {
QnAMakerBaseDialog
} = require('./qnamakerBaseDialog');
const { MessageFactory } = require('botbuilder');

const INITIAL_DIALOG = 'initial-dialog';
const ROOT_DIALOG = 'root-dialog';
const QNAMAKER_BASE_DIALOG = 'qnamaker-base-dailog';
const QNAMAKER_BASE_DIALOG = 'qnamaker-base-dialog';

/**
* Creates QnAMakerDialog instance with provided configuraton values.
*/
const createQnAMakerDialog = (knowledgeBaseId, endpointKey, endpointHostName, defaultAnswer) => {
let noAnswerActivity;
if (typeof defaultAnswer === 'string') {
noAnswerActivity = MessageFactory.text(defaultAnswer);
}

const qnaMakerDialog = new QnAMakerDialog(knowledgeBaseId, endpointKey, endpointHostName, noAnswerActivity);
qnaMakerDialog.id = QNAMAKER_BASE_DIALOG;

return qnaMakerDialog;
}

class RootDialog extends ComponentDialog {
/**
* Root dialog for this bot.
* @param {QnAMaker} qnaService A QnAMaker service object.
* Root dialog for this bot. Creates a QnAMakerDialog.
* @param {string} knowledgeBaseId Knowledge Base ID of the QnA Maker instance.
* @param {string} endpointKey Endpoint key needed to query QnA Maker.
* @param {string} endpointHostName Host name of the QnA Maker instance.
* @param {string} defaultAnswer (optional) Text used to create a fallback response when QnA Maker doesn't have an answer for a question.
*/
constructor(knowledgebaseId, authkey, host, defaultAnswer) {
constructor(knowledgeBaseId, endpointKey, endpointHostName, defaultAnswer) {
super(ROOT_DIALOG);
// Initial waterfall dialog.
this.addDialog(new WaterfallDialog(INITIAL_DIALOG, [
this.startInitialDialog.bind(this)
]));
this.addDialog(new QnAMakerBaseDialog(knowledgebaseId, authkey, host, defaultAnswer));

this.addDialog(createQnAMakerDialog(knowledgeBaseId, endpointKey, endpointHostName, defaultAnswer));
this.initialDialogId = INITIAL_DIALOG;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Import required packages
const path = require('path');

// Note: Ensure you have a .env file and include QnAMakerKnowledgeBaseId, QnAMakerEndpointKey and QnAMakerHost.
// Note: Ensure you have a .env file and include QnAKnowledgebaseId, QnAEndpointKey and QnAEndpointHostName.
const ENV_FILE = path.join(__dirname, '.env');
require('dotenv').config({ path: ENV_FILE });

Expand Down

0 comments on commit e306ca2

Please sign in to comment.