-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
118 lines (111 loc) · 4.38 KB
/
index.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
const rootPrefix = '.',
configProvider = require(rootPrefix + '/lib/configProvider'),
slackAppConstants = require(rootPrefix + '/lib/constants/slackApp'),
slackWrapper = require(rootPrefix + '/lib/slack/Wrapper'),
formatPayload = require(rootPrefix + '/middlewares/formatPayload'),
assignParams = require(rootPrefix + '/middlewares/assignParams'),
sanitizer = require(rootPrefix + '/lib/helpers/sanitizer'),
extractResponseUrlFromPayload = require(rootPrefix + '/middlewares/extractResponseUrlFromPayload'),
extractText = require(rootPrefix + '/middlewares/extractText'),
extractResponseUrlFromBody = require(rootPrefix + '/middlewares/extractResponseUrlFromBody'),
extractSlackParams = require(rootPrefix + '/middlewares/extractSlackParams'),
parseApiParameters = require(rootPrefix + '/middlewares/parseApiParams'),
extractTriggerId = require(rootPrefix + '/middlewares/extractTriggerId'),
authenticator = require(rootPrefix + '/middlewares/authentication/Authenticator'),
Message = require(rootPrefix + '/lib/slack/Message'),
Modal = require(rootPrefix + '/lib/slack/Modal');
/**
* Class for Slack Admin.
*
* @class SlackAdmin
*
* @param {array} appConfigs
* @param {object} whitelistedChannelIds
* @param {string} domain
* @param {array} whitelistedUsers
*
*/
class SlackAdmin {
constructor(appConfigs, whitelistedChannelIds, domain, whitelistedUsers) {
configProvider.set('app_config', appConfigs);
configProvider.set('whitelisted_channel_ids', whitelistedChannelIds);
configProvider.set('domain', domain);
configProvider.set('whitelisted_users', whitelistedUsers);
slackAppConstants.setSlackAppConfigById();
slackWrapper.init();
}
/**
* Slack admin middlewares
*
* @returns {{validateSignature: Authenticator.validateSlackSignature, assignParams, extractResponseUrlFromPayload, extractResponseUrlFromBody, validateSlackChannel: Authenticator.validateSlackChannel, extractText, extractSlackParams, validateSlackApiAppId: Authenticator.validateSlackApiAppId, formatPayload, sanitizeHeaderParams: Sanitizer.sanitizeHeaderParams, parseApiParameters, sanitizeBodyAndQuery: Sanitizer.sanitizeBodyAndQuery, sanitizeDynamicUrlParams: Sanitizer.sanitizeDynamicUrlParams, validateSlackUser: Authenticator.validateSlackUser, extractTriggerId}}
*/
get middlewares() {
return {
formatPayload: formatPayload,
sanitizeBodyAndQuery: sanitizer.sanitizeBodyAndQuery,
assignParams: assignParams,
sanitizeDynamicUrlParams: sanitizer.sanitizeDynamicUrlParams,
sanitizeHeaderParams: sanitizer.sanitizeHeaderParams,
extractSlackParams: extractSlackParams,
validateSignature: authenticator.validateSlackSignature,
validateSlackUser: authenticator.validateSlackUser,
validateSlackChannel: authenticator.validateSlackChannel,
validateSlackApiAppId: authenticator.validateSlackApiAppId,
extractResponseUrlFromPayload: extractResponseUrlFromPayload,
extractText: extractText,
extractResponseUrlFromBody: extractResponseUrlFromBody,
parseApiParameters: parseApiParameters,
extractTriggerId: extractTriggerId
};
}
/**
* Slack admin common middlewares
*
* @returns {(*|Sanitizer.sanitizeBodyAndQuery|Authenticator.validateSlackSignature)[]}
*/
get commonMiddlewares() {
return [
formatPayload,
sanitizer.sanitizeBodyAndQuery,
assignParams,
extractSlackParams,
authenticator.validateSlackSignature,
authenticator.validateSlackUser
];
}
/**
* Slack admin interactive endpoints middlewares
*
* @returns {(Sanitizer.sanitizeDynamicUrlParams|Sanitizer.sanitizeHeaderParams|Authenticator.validateSlackApiAppId|*)[]}
*/
get interactiveEndpointMiddlewares() {
return [
sanitizer.sanitizeDynamicUrlParams,
sanitizer.sanitizeHeaderParams,
authenticator.validateSlackApiAppId,
extractTriggerId,
extractResponseUrlFromPayload,
parseApiParameters
];
}
/**
* Slack command middlewares
*
* @returns {(Authenticator.validateSlackChannel|*)[]}
*/
get slashCommandMiddlewares() {
return [authenticator.validateSlackChannel, extractText, extractResponseUrlFromBody];
}
/**
* Slack interactive element middlewares
*
* @returns {{Message, Modal}}
*/
get interactiveElements() {
return {
Message: Message,
Modal: Modal
};
}
}
module.exports = SlackAdmin;