forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimpleWaterfallDialog.js
35 lines (30 loc) · 1.28 KB
/
SimpleWaterfallDialog.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
var util = require('util');
var builder = require('botbuilder');
// This Dialog works as a waterfall dialogs, with the option to control flow within each step.
// Each step is reponsible for calling next() in order to advance. Flow is returned to parent dialog when next() is invoked from the last steps closure. You can pass an optional argument to the last step that will be returned to the parent dialog.
function SimpleWaterfallDialog(dialogSteps) {
function fn(session, args) {
if (session.dialogData.step === undefined) {
session.dialogData.step = 0;
}
var next = function (args) {
session.dialogData.step++;
var dialogStep = dialogSteps[session.dialogData.step];
if (!dialogStep) {
// no more steps
if (args) {
session.endDialogWithResult(args);
} else {
session.endDialog();
}
} else {
dialogStep(session, args, next);
}
};
// run step
dialogSteps[session.dialogData.step](session, args, next);
}
SimpleWaterfallDialog.super_.call(this, fn);
}
util.inherits(SimpleWaterfallDialog, builder.SimpleDialog);
module.exports = SimpleWaterfallDialog;