forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
skillBot.js
39 lines (31 loc) · 1.24 KB
/
skillBot.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
36
37
38
39
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
const { ActivityHandler } = require('botbuilder');
const { runDialog } = require('botbuilder-dialogs');
class SkillBot extends ActivityHandler {
/**
*
* @param {ConversationState} conversationState
* @param {Dialog} dialog
*/
constructor(conversationState, dialog) {
super();
if (!conversationState) throw new Error('[SkillBot]: Missing parameter. conversationState is required');
if (!dialog) throw new Error('[SkillBot]: Missing parameter. dialog is required');
this.conversationState = conversationState;
this.dialog = dialog;
this.onTurn(async (context, next) => {
await runDialog(this.dialog, context, this.conversationState.createProperty('DialogState'));
await next();
});
}
/**
* Override the ActivityHandler.run() method to save state changes after the bot logic completes.
*/
async run(context) {
await super.run(context);
// Save any state changes. The load happened during the execution of the Dialog.
await this.conversationState.saveChanges(context, false);
}
}
module.exports.SkillBot = SkillBot;