diff --git a/samples/javascript_nodejs/49.qnamaker-all-features/bots/QnABot.js b/samples/javascript_nodejs/49.qnamaker-all-features/bots/QnABot.js index 3becbd1e88..86955540ee 100644 --- a/samples/javascript_nodejs/49.qnamaker-all-features/bots/QnABot.js +++ b/samples/javascript_nodejs/49.qnamaker-all-features/bots/QnABot.js @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. const { ActivityHandler } = require('botbuilder'); diff --git a/samples/javascript_nodejs/49.qnamaker-all-features/dialogs/qnamakerBaseDialog.js b/samples/javascript_nodejs/49.qnamaker-all-features/dialogs/qnamakerBaseDialog.js deleted file mode 100644 index e382b0c0c9..0000000000 --- a/samples/javascript_nodejs/49.qnamaker-all-features/dialogs/qnamakerBaseDialog.js +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -const { QnAMakerDialog } = require('botbuilder-ai'); -const { MessageFactory } = require('botbuilder'); - -/// QnA Maker dialog. -const QNAMAKER_BASE_DIALOG = 'qnamaker-base-dialog'; - -class QnAMakerBaseDialog extends QnAMakerDialog { - /** - * Core logic of QnA Maker dialog. - * @param {string} knowledgeBaseId A QnAMaker service object. - * @param {string} endpointKey A QnAMaker service object. - * @param {string} endpointHostName A QnAMaker service object. - * @param {string} defaultAnswer A QnAMaker service object. - */ - constructor( - knowledgeBaseId, - endpointKey, - endpointHostName, - defaultAnswer, - ) { - let noAnswer; - if (typeof defaultAnswer === 'string') { - noAnswer = MessageFactory.text(defaultAnswer); - } - - super(knowledgeBaseId, endpointKey, endpointHostName, noAnswer); - this.id = QNAMAKER_BASE_DIALOG; - } -} - -module.exports.QnAMakerBaseDialog = QnAMakerBaseDialog; -module.exports.QNAMAKER_BASE_DIALOG = QNAMAKER_BASE_DIALOG; diff --git a/samples/javascript_nodejs/49.qnamaker-all-features/dialogs/rootDialog.js b/samples/javascript_nodejs/49.qnamaker-all-features/dialogs/rootDialog.js index 859a6ddfaa..0326f68134 100644 --- a/samples/javascript_nodejs/49.qnamaker-all-features/dialogs/rootDialog.js +++ b/samples/javascript_nodejs/49.qnamaker-all-features/dialogs/rootDialog.js @@ -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; } diff --git a/samples/javascript_nodejs/49.qnamaker-all-features/index.js b/samples/javascript_nodejs/49.qnamaker-all-features/index.js index 5e3880c8ce..e87309f2f5 100644 --- a/samples/javascript_nodejs/49.qnamaker-all-features/index.js +++ b/samples/javascript_nodejs/49.qnamaker-all-features/index.js @@ -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 });