-
Notifications
You must be signed in to change notification settings - Fork 1
/
CustomQnAMakerTools.js
35 lines (34 loc) · 1.82 KB
/
CustomQnAMakerTools.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"use strict";
var builder = require("botbuilder");
var CustomQnAMakerTools = (function () {
function CustomQnAMakerTools() {
this.lib = new builder.Library('customQnAMakerTools');
this.lib.dialog('answerSelection', [
function (session, args) {
var qnaMakerResult = args;
session.dialogData.qnaMakerResult = qnaMakerResult;
var questionOptions = [];
qnaMakerResult.answers.forEach(function (qna) { questionOptions.push(qna.questions[0]); });
var promptOptions = { listStyle: builder.ListStyle.button };
builder.Prompts.choice(session, "There are multiple good matches. Please select from the following:", questionOptions, promptOptions);
},
function (session, results) {
var qnaMakerResult = session.dialogData.qnaMakerResult;
var filteredResult = qnaMakerResult.answers.filter(function (qna) { return qna.questions[0] === results.response.entity; });
var selectedQnA = filteredResult[0];
session.send(selectedQnA.answer);
// The following ends the dialog and returns the selected response to the parent dialog, which logs the record in QnA Maker service
// You can simply end the dialog, in case you don't want to learn from these selections using session.endDialog()
session.endDialogWithResult(selectedQnA);
},
]);
}
CustomQnAMakerTools.prototype.createLibrary = function () {
return this.lib;
};
CustomQnAMakerTools.prototype.answerSelector = function (session, options) {
session.beginDialog('customQnAMakerTools:answerSelection', options || {});
};
return CustomQnAMakerTools;
}());
exports.CustomQnAMakerTools = CustomQnAMakerTools;