-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbotbuilder-formflow.js
42 lines (36 loc) · 1.51 KB
/
botbuilder-formflow.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
40
41
42
const constants = require('./src/constants');
const MenuDialog = require('./src/custom/MenuDialog');
const MenuPrompt = require('./src/custom/MenuPrompt');
const SwitchDialog = require('./src/custom/SwitchDialog');
const messaging = require('./src/messaging');
const matchItem = require('./src/matchItem');
const PromptDialogs = require('./src/PromptDialogs');
const getFormFlowWrapper = require('./src/getFormFlowWrapper');
const EventEmitter = require('events');
const library = new EventEmitter();
library.SwitchDialog = SwitchDialog;
library.MenuDialog = MenuDialog;
library.MenuPrompt = MenuPrompt;
library.constants = constants;
/**
* DEPRECATED since 0.5 version
* @type {string[]}
*/
library.SupportedTypes = PromptDialogs.SUPPORTED_TYPES;
library.create = function (bot, dialogName, config) {
let formFlow = getFormFlowWrapper(library, bot, config);
bot.dialog(dialogName, formFlow);
return formFlow;
};
library.on(constants.BUILD_FIELD_DIALOG_EVENT, (bot, id, stepConfig, steps) => {
if (matchItem(stepConfig, 'dialog', () => Array.isArray(stepConfig.dialog))) {
stepConfig.dialog.forEach((item) => steps.push(item));
} else if (messaging.isMessaging(stepConfig)) {
steps.push(messaging.processMessage(stepConfig));
} else if (PromptDialogs.isPrompt(stepConfig)) {
PromptDialogs(id, stepConfig).forEach((step) => steps.push(step));
}
});
library.on(constants.BUILD_FIELD_DIALOG_EVENT, SwitchDialog.factory)
library.on(constants.BUILD_FIELD_DIALOG_EVENT, MenuDialog.factory)
module.exports = library;