-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
35 lines (30 loc) · 1.23 KB
/
bot.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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
const { ActivityTypes } = require('botbuilder');
class MyBot {
/**
*
* @param {TurnContext} on turn context object.
*/
constructor(qnaServices) {
this.qnaServices = qnaServices;
}
async onTurn(turnContext) {
// See https://aka.ms/about-bot-activity-message to learn more about the message and other activity types.
if (turnContext.activity.type === ActivityTypes.Message) {
for (let i = 0; i < this.qnaServices.length; i++) {
const qnaResults = await this.qnaServices[i].getAnswers(turnContext);
if(qnaResults[0]) {
await turnContext.sendActivity(qnaResults[0].answer);
return;
}
}
await turnContext('No QnA Maker answers were found. '
+ 'This example uses a QnA Maker Knowledge Base that focuses on smart light bulbs. '
+ `Ask the bot questions like "Why won't it turn on?" or "I need help."`);
} else {
await turnContext.sendActivity(`[${ turnContext.activity.type } event detected]`);
}
}
}
module.exports.MyBot = MyBot;