-
Notifications
You must be signed in to change notification settings - Fork 256
/
bot-builder.js
82 lines (73 loc) · 2.76 KB
/
bot-builder.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
'use strict';
const ApiBuilder = require('claudia-api-builder');
const fbSetup = require('./facebook/setup');
const slackSetup = require('./slack/setup');
const telegramSetup = require('./telegram/setup');
const skypeSetup = require('./skype/setup');
const twilioSetup = require('./twilio/setup');
const kikSetup = require('./kik/setup');
const groupmeSetup = require('./groupme/setup');
const lineSetup = require('./line/setup');
const viberSetup = require('./viber/setup');
const alexaSetup = require('./alexa/setup');
const fbTemplate = require('./facebook/format-message');
const slackTemplate = require('./slack/format-message');
const slackDialog = require('./slack/format-dialog');
const telegramTemplate = require('./telegram/format-message');
const viberTemplate = require('./viber/format-message');
const skypeTemplate = require('./skype/format-message');
const AlexaTemplate = require('alexa-message-builder');
const slackDelayedReply = require('./slack/delayed-reply');
let logError = function (err) {
console.error(err);
};
module.exports = function botBuilder(messageHandler, options, optionalLogError) {
logError = optionalLogError || logError;
const api = new ApiBuilder(),
messageHandlerPromise = function (message, originalApiBuilderRequest) {
return Promise.resolve(message).then(message => messageHandler(message, originalApiBuilderRequest));
};
api.get('/', () => 'Ok');
let isEnabled = function isEnabled(platform) {
return !options || !options.platforms || options.platforms.indexOf(platform) > -1;
};
if (isEnabled('facebook')) {
fbSetup(api, messageHandlerPromise, logError);
}
if (isEnabled('slackSlashCommand')) {
slackSetup(api, messageHandlerPromise, logError);
}
if (isEnabled('telegram')) {
telegramSetup(api, messageHandlerPromise, logError);
}
if (isEnabled('skype')) {
skypeSetup(api, messageHandlerPromise, logError);
}
if (isEnabled('twilio')) {
twilioSetup(api, messageHandlerPromise, logError);
}
if (isEnabled('kik')) {
kikSetup(api, messageHandlerPromise, logError);
}
if (isEnabled('groupme')) {
groupmeSetup(api, messageHandlerPromise, logError);
}
if (isEnabled('line')) {
lineSetup(api, messageHandlerPromise, logError);
}
if (isEnabled('viber')) {
viberSetup(api, messageHandlerPromise, logError);
}
if (isEnabled('alexa')) {
alexaSetup(api, messageHandlerPromise, logError);
}
return api;
};
module.exports.fbTemplate = fbTemplate;
module.exports.slackTemplate = slackTemplate;
module.exports.slackDialog = slackDialog;
module.exports.telegramTemplate = telegramTemplate;
module.exports.viberTemplate = viberTemplate;
module.exports.skypeTemplate = skypeTemplate;
module.exports.AlexaTemplate = AlexaTemplate;
module.exports.slackDelayedReply = slackDelayedReply;