@slack/bolt 3.5.0 → 3.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/LICENSE +1 -1
  3. package/README.md +11 -4
  4. package/dist/package.json +88 -0
  5. package/package.json +18 -20
  6. package/dist/App.d.ts +0 -156
  7. package/dist/App.d.ts.map +0 -1
  8. package/dist/App.js +0 -721
  9. package/dist/App.js.map +0 -1
  10. package/dist/WorkflowStep.d.ts +0 -106
  11. package/dist/WorkflowStep.d.ts.map +0 -1
  12. package/dist/WorkflowStep.js +0 -199
  13. package/dist/WorkflowStep.js.map +0 -1
  14. package/dist/conversation-store.d.ts +0 -31
  15. package/dist/conversation-store.d.ts.map +0 -1
  16. package/dist/conversation-store.js +0 -72
  17. package/dist/conversation-store.js.map +0 -1
  18. package/dist/errors.d.ts +0 -71
  19. package/dist/errors.d.ts.map +0 -1
  20. package/dist/errors.js +0 -104
  21. package/dist/errors.js.map +0 -1
  22. package/dist/helpers.d.ts +0 -24
  23. package/dist/helpers.d.ts.map +0 -1
  24. package/dist/helpers.js +0 -99
  25. package/dist/helpers.js.map +0 -1
  26. package/dist/index.d.ts +0 -13
  27. package/dist/index.d.ts.map +0 -1
  28. package/dist/index.js +0 -43
  29. package/dist/index.js.map +0 -1
  30. package/dist/middleware/builtin.d.ts +0 -52
  31. package/dist/middleware/builtin.d.ts.map +0 -1
  32. package/dist/middleware/builtin.js +0 -330
  33. package/dist/middleware/builtin.js.map +0 -1
  34. package/dist/middleware/process.d.ts +0 -5
  35. package/dist/middleware/process.d.ts.map +0 -1
  36. package/dist/middleware/process.js +0 -26
  37. package/dist/middleware/process.js.map +0 -1
  38. package/dist/receivers/AwsLambdaReceiver.d.ts +0 -50
  39. package/dist/receivers/AwsLambdaReceiver.d.ts.map +0 -1
  40. package/dist/receivers/AwsLambdaReceiver.js +0 -192
  41. package/dist/receivers/AwsLambdaReceiver.js.map +0 -1
  42. package/dist/receivers/ExpressReceiver.d.ts +0 -64
  43. package/dist/receivers/ExpressReceiver.d.ts.map +0 -1
  44. package/dist/receivers/ExpressReceiver.js +0 -365
  45. package/dist/receivers/ExpressReceiver.js.map +0 -1
  46. package/dist/receivers/HTTPReceiver.d.ts +0 -60
  47. package/dist/receivers/HTTPReceiver.d.ts.map +0 -1
  48. package/dist/receivers/HTTPReceiver.js +0 -357
  49. package/dist/receivers/HTTPReceiver.js.map +0 -1
  50. package/dist/receivers/SocketModeReceiver.d.ts +0 -44
  51. package/dist/receivers/SocketModeReceiver.d.ts.map +0 -1
  52. package/dist/receivers/SocketModeReceiver.js +0 -111
  53. package/dist/receivers/SocketModeReceiver.js.map +0 -1
  54. package/dist/receivers/render-html-for-install-path.d.ts +0 -2
  55. package/dist/receivers/render-html-for-install-path.d.ts.map +0 -1
  56. package/dist/receivers/render-html-for-install-path.js +0 -20
  57. package/dist/receivers/render-html-for-install-path.js.map +0 -1
  58. package/dist/receivers/verify-request.d.ts +0 -40
  59. package/dist/receivers/verify-request.d.ts.map +0 -1
  60. package/dist/receivers/verify-request.js +0 -94
  61. package/dist/receivers/verify-request.js.map +0 -1
  62. package/dist/types/actions/block-action.d.ts +0 -224
  63. package/dist/types/actions/block-action.d.ts.map +0 -1
  64. package/dist/types/actions/block-action.js +0 -3
  65. package/dist/types/actions/block-action.js.map +0 -1
  66. package/dist/types/actions/dialog-action.d.ts +0 -47
  67. package/dist/types/actions/dialog-action.d.ts.map +0 -1
  68. package/dist/types/actions/dialog-action.js +0 -3
  69. package/dist/types/actions/dialog-action.js.map +0 -1
  70. package/dist/types/actions/index.d.ts +0 -46
  71. package/dist/types/actions/index.d.ts.map +0 -1
  72. package/dist/types/actions/index.js +0 -17
  73. package/dist/types/actions/index.js.map +0 -1
  74. package/dist/types/actions/interactive-message.d.ts +0 -66
  75. package/dist/types/actions/interactive-message.d.ts.map +0 -1
  76. package/dist/types/actions/interactive-message.js +0 -3
  77. package/dist/types/actions/interactive-message.js.map +0 -1
  78. package/dist/types/actions/workflow-step-edit.d.ts +0 -49
  79. package/dist/types/actions/workflow-step-edit.d.ts.map +0 -1
  80. package/dist/types/actions/workflow-step-edit.js +0 -3
  81. package/dist/types/actions/workflow-step-edit.js.map +0 -1
  82. package/dist/types/command/index.d.ts +0 -36
  83. package/dist/types/command/index.d.ts.map +0 -1
  84. package/dist/types/command/index.js +0 -3
  85. package/dist/types/command/index.js.map +0 -1
  86. package/dist/types/events/base-events.d.ts +0 -622
  87. package/dist/types/events/base-events.d.ts.map +0 -1
  88. package/dist/types/events/base-events.js +0 -5
  89. package/dist/types/events/base-events.js.map +0 -1
  90. package/dist/types/events/index.d.ts +0 -63
  91. package/dist/types/events/index.d.ts.map +0 -1
  92. package/dist/types/events/index.js +0 -14
  93. package/dist/types/events/index.js.map +0 -1
  94. package/dist/types/events/message-events.d.ts +0 -312
  95. package/dist/types/events/message-events.d.ts.map +0 -1
  96. package/dist/types/events/message-events.js +0 -3
  97. package/dist/types/events/message-events.js.map +0 -1
  98. package/dist/types/helpers.d.ts +0 -17
  99. package/dist/types/helpers.d.ts.map +0 -1
  100. package/dist/types/helpers.js +0 -3
  101. package/dist/types/helpers.js.map +0 -1
  102. package/dist/types/index.d.ts +0 -10
  103. package/dist/types/index.d.ts.map +0 -1
  104. package/dist/types/index.js +0 -22
  105. package/dist/types/index.js.map +0 -1
  106. package/dist/types/middleware.d.ts +0 -56
  107. package/dist/types/middleware.d.ts.map +0 -1
  108. package/dist/types/middleware.js +0 -3
  109. package/dist/types/middleware.js.map +0 -1
  110. package/dist/types/options/index.d.ts +0 -192
  111. package/dist/types/options/index.d.ts.map +0 -1
  112. package/dist/types/options/index.js +0 -3
  113. package/dist/types/options/index.js.map +0 -1
  114. package/dist/types/receiver.d.ts +0 -13
  115. package/dist/types/receiver.d.ts.map +0 -1
  116. package/dist/types/receiver.js +0 -3
  117. package/dist/types/receiver.js.map +0 -1
  118. package/dist/types/shortcuts/global-shortcut.d.ts +0 -29
  119. package/dist/types/shortcuts/global-shortcut.d.ts.map +0 -1
  120. package/dist/types/shortcuts/global-shortcut.js +0 -3
  121. package/dist/types/shortcuts/global-shortcut.js.map +0 -1
  122. package/dist/types/shortcuts/index.d.ts +0 -23
  123. package/dist/types/shortcuts/index.d.ts.map +0 -1
  124. package/dist/types/shortcuts/index.js +0 -16
  125. package/dist/types/shortcuts/index.js.map +0 -1
  126. package/dist/types/shortcuts/message-shortcut.d.ts +0 -43
  127. package/dist/types/shortcuts/message-shortcut.d.ts.map +0 -1
  128. package/dist/types/shortcuts/message-shortcut.js +0 -3
  129. package/dist/types/shortcuts/message-shortcut.js.map +0 -1
  130. package/dist/types/utilities.d.ts +0 -23
  131. package/dist/types/utilities.d.ts.map +0 -1
  132. package/dist/types/utilities.js +0 -3
  133. package/dist/types/utilities.js.map +0 -1
  134. package/dist/types/view/index.d.ts +0 -175
  135. package/dist/types/view/index.d.ts.map +0 -1
  136. package/dist/types/view/index.js +0 -3
  137. package/dist/types/view/index.js.map +0 -1
@@ -1,330 +0,0 @@
1
- "use strict";
2
- /* eslint-disable @typescript-eslint/dot-notation */
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.directMention = exports.subtype = exports.ignoreSelf = exports.matchEventType = exports.matchCommandName = exports.matchMessage = exports.matchConstraints = exports.onlyViewActions = exports.onlyEvents = exports.onlyOptions = exports.onlyCommands = exports.onlyShortcuts = exports.onlyActions = void 0;
5
- const errors_1 = require("../errors");
6
- /**
7
- * Middleware that filters out any event that isn't an action
8
- */
9
- const onlyActions = async ({ action, next }) => {
10
- // Filter out any non-actions
11
- if (action === undefined) {
12
- return;
13
- }
14
- // It matches so we should continue down this middleware listener chain
15
- // TODO: remove the non-null assertion operator
16
- await next();
17
- };
18
- exports.onlyActions = onlyActions;
19
- /**
20
- * Middleware that filters out any event that isn't a shortcut
21
- */
22
- // tslint:disable-next-line: max-line-length
23
- const onlyShortcuts = async ({ shortcut, next, }) => {
24
- // Filter out any non-shortcuts
25
- if (shortcut === undefined) {
26
- return;
27
- }
28
- // It matches so we should continue down this middleware listener chain
29
- // TODO: remove the non-null assertion operator
30
- await next();
31
- };
32
- exports.onlyShortcuts = onlyShortcuts;
33
- /**
34
- * Middleware that filters out any event that isn't a command
35
- */
36
- const onlyCommands = async ({ command, next }) => {
37
- // Filter out any non-commands
38
- if (command === undefined) {
39
- return;
40
- }
41
- // It matches so we should continue down this middleware listener chain
42
- // TODO: remove the non-null assertion operator
43
- await next();
44
- };
45
- exports.onlyCommands = onlyCommands;
46
- /**
47
- * Middleware that filters out any event that isn't an options
48
- */
49
- const onlyOptions = async ({ options, next }) => {
50
- // Filter out any non-options requests
51
- if (options === undefined) {
52
- return;
53
- }
54
- // It matches so we should continue down this middleware listener chain
55
- // TODO: remove the non-null assertion operator
56
- await next();
57
- };
58
- exports.onlyOptions = onlyOptions;
59
- /**
60
- * Middleware that filters out any event that isn't an event
61
- */
62
- const onlyEvents = async ({ event, next }) => {
63
- // Filter out any non-events
64
- if (event === undefined) {
65
- return;
66
- }
67
- // It matches so we should continue down this middleware listener chain
68
- // TODO: remove the non-null assertion operator
69
- await next();
70
- };
71
- exports.onlyEvents = onlyEvents;
72
- /**
73
- * Middleware that filters out any event that isn't a view_submission or view_closed event
74
- */
75
- const onlyViewActions = async ({ view, next }) => {
76
- // Filter out anything that doesn't have a view
77
- if (view === undefined) {
78
- return;
79
- }
80
- // It matches so we should continue down this middleware listener chain
81
- // TODO: remove the non-null assertion operator
82
- await next();
83
- };
84
- exports.onlyViewActions = onlyViewActions;
85
- /**
86
- * Middleware that checks for matches given constraints
87
- */
88
- function matchConstraints(constraints) {
89
- return async ({ payload, body, next, context }) => {
90
- // TODO: is putting matches in an array actually helpful? there's no way to know which of the regexps contributed
91
- // which matches (and in which order)
92
- let tempMatches;
93
- // Narrow type for ActionConstraints
94
- if ('block_id' in constraints || 'action_id' in constraints) {
95
- if (!isBlockPayload(payload)) {
96
- return;
97
- }
98
- // Check block_id
99
- if (constraints.block_id !== undefined) {
100
- if (typeof constraints.block_id === 'string') {
101
- if (payload.block_id !== constraints.block_id) {
102
- return;
103
- }
104
- }
105
- else {
106
- tempMatches = payload.block_id.match(constraints.block_id);
107
- if (tempMatches !== null) {
108
- context['blockIdMatches'] = tempMatches;
109
- }
110
- else {
111
- return;
112
- }
113
- }
114
- }
115
- // Check action_id
116
- if (constraints.action_id !== undefined) {
117
- if (typeof constraints.action_id === 'string') {
118
- if (payload.action_id !== constraints.action_id) {
119
- return;
120
- }
121
- }
122
- else {
123
- tempMatches = payload.action_id.match(constraints.action_id);
124
- if (tempMatches !== null) {
125
- context['actionIdMatches'] = tempMatches;
126
- }
127
- else {
128
- return;
129
- }
130
- }
131
- }
132
- }
133
- // Check callback_id
134
- if ('callback_id' in constraints && constraints.callback_id !== undefined) {
135
- let callbackId = '';
136
- if (isViewBody(body)) {
137
- callbackId = body['view']['callback_id'];
138
- }
139
- else if (isCallbackIdentifiedBody(body)) {
140
- callbackId = body['callback_id'];
141
- }
142
- else {
143
- return;
144
- }
145
- if (typeof constraints.callback_id === 'string') {
146
- if (callbackId !== constraints.callback_id) {
147
- return;
148
- }
149
- }
150
- else {
151
- tempMatches = callbackId.match(constraints.callback_id);
152
- if (tempMatches !== null) {
153
- context['callbackIdMatches'] = tempMatches;
154
- }
155
- else {
156
- return;
157
- }
158
- }
159
- }
160
- // Check type
161
- if ('type' in constraints) {
162
- if (body.type !== constraints.type)
163
- return;
164
- }
165
- // TODO: remove the non-null assertion operator
166
- await next();
167
- };
168
- }
169
- exports.matchConstraints = matchConstraints;
170
- /*
171
- * Middleware that filters out messages that don't match pattern
172
- */
173
- function matchMessage(pattern) {
174
- return async ({ event, context, next }) => {
175
- let tempMatches;
176
- if (!('text' in event) || event.text === undefined) {
177
- return;
178
- }
179
- // Filter out messages or app mentions that don't contain the pattern
180
- if (typeof pattern === 'string') {
181
- if (!event.text.includes(pattern)) {
182
- return;
183
- }
184
- }
185
- else {
186
- tempMatches = event.text.match(pattern);
187
- if (tempMatches !== null) {
188
- context['matches'] = tempMatches;
189
- }
190
- else {
191
- return;
192
- }
193
- }
194
- // TODO: remove the non-null assertion operator
195
- await next();
196
- };
197
- }
198
- exports.matchMessage = matchMessage;
199
- /**
200
- * Middleware that filters out any command that doesn't match the pattern
201
- */
202
- function matchCommandName(pattern) {
203
- return async ({ command, next }) => {
204
- // Filter out any commands that do not match the correct command name or pattern
205
- if (!matchesPattern(pattern, command.command)) {
206
- return;
207
- }
208
- // TODO: remove the non-null assertion operator
209
- await next();
210
- };
211
- }
212
- exports.matchCommandName = matchCommandName;
213
- function matchesPattern(pattern, candidate) {
214
- if (typeof pattern === 'string') {
215
- return pattern === candidate;
216
- }
217
- return pattern.test(candidate);
218
- }
219
- /*
220
- * Middleware that filters out events that don't match pattern
221
- */
222
- function matchEventType(pattern) {
223
- return async ({ event, context, next }) => {
224
- let tempMatches;
225
- if (!('type' in event) || event.type === undefined) {
226
- return;
227
- }
228
- // Filter out events that don't contain the pattern
229
- if (typeof pattern === 'string') {
230
- if (event.type !== pattern) {
231
- return;
232
- }
233
- }
234
- else {
235
- tempMatches = event.type.match(pattern);
236
- if (tempMatches !== null) {
237
- context['matches'] = tempMatches;
238
- }
239
- else {
240
- return;
241
- }
242
- }
243
- // TODO: remove the non-null assertion operator
244
- await next();
245
- };
246
- }
247
- exports.matchEventType = matchEventType;
248
- function ignoreSelf() {
249
- return async (args) => {
250
- // When context does not have a botId in it, then this middleware cannot perform its job. Bail immediately.
251
- if (args.context.botId === undefined) {
252
- throw new errors_1.ContextMissingPropertyError('botId', 'Cannot ignore events from the app without a bot ID. Ensure authorize callback returns a botId.');
253
- }
254
- const botId = args.context.botId;
255
- const botUserId = args.context.botUserId !== undefined ? args.context.botUserId : undefined;
256
- if (isEventArgs(args)) {
257
- // Once we've narrowed the type down to SlackEventMiddlewareArgs, there's no way to further narrow it down to
258
- // SlackEventMiddlewareArgs<'message'> without a cast, so the following couple lines do that.
259
- if (args.message !== undefined) {
260
- const message = args.message;
261
- // TODO: revisit this once we have all the message subtypes defined to see if we can do this better with
262
- // type narrowing
263
- // Look for an event that is identified as a bot message from the same bot ID as this app, and return to skip
264
- if (message.subtype === 'bot_message' && message.bot_id === botId) {
265
- return;
266
- }
267
- }
268
- // Its an Events API event that isn't of type message, but the user ID might match our own app. Filter these out.
269
- // However, some events still must be fired, because they can make sense.
270
- const eventsWhichShouldBeKept = ['member_joined_channel', 'member_left_channel'];
271
- const isEventShouldBeKept = eventsWhichShouldBeKept.includes(args.event.type);
272
- if (botUserId !== undefined && 'user' in args.event && args.event.user === botUserId && !isEventShouldBeKept) {
273
- return;
274
- }
275
- }
276
- // If all the previous checks didn't skip this message, then its okay to resume to next
277
- // TODO: remove the non-null assertion operator
278
- await args.next();
279
- };
280
- }
281
- exports.ignoreSelf = ignoreSelf;
282
- function subtype(subtype1) {
283
- // eslint-disable-line no-shadow
284
- return async ({ message, next }) => {
285
- if (message.subtype === subtype1) {
286
- // TODO: remove the non-null assertion operator
287
- await next();
288
- }
289
- };
290
- }
291
- exports.subtype = subtype;
292
- const slackLink = /<(?<type>[@#!])?(?<link>[^>|]+)(?:\|(?<label>[^>]+))?>/;
293
- function directMention() {
294
- return async ({ message, context, next }) => {
295
- // When context does not have a botUserId in it, then this middleware cannot perform its job. Bail immediately.
296
- if (context.botUserId === undefined) {
297
- throw new errors_1.ContextMissingPropertyError('botUserId', 'Cannot match direct mentions of the app without a bot user ID. Ensure authorize callback returns a botUserId.');
298
- }
299
- if (!('text' in message) || message.text === undefined) {
300
- return;
301
- }
302
- // Match the message text with a user mention format
303
- const text = message.text.trim();
304
- const matches = slackLink.exec(text);
305
- if (matches === null || // stop when no matches are found
306
- matches.index !== 0 || // stop if match isn't at the beginning
307
- // stop if match isn't a user mention with the right user ID
308
- matches.groups === undefined ||
309
- matches.groups.type !== '@' ||
310
- matches.groups.link !== context.botUserId) {
311
- return;
312
- }
313
- // TODO: remove the non-null assertion operator
314
- await next();
315
- };
316
- }
317
- exports.directMention = directMention;
318
- function isBlockPayload(payload) {
319
- return payload.action_id !== undefined;
320
- }
321
- function isCallbackIdentifiedBody(body) {
322
- return body.callback_id !== undefined;
323
- }
324
- function isViewBody(body) {
325
- return body.view !== undefined;
326
- }
327
- function isEventArgs(args) {
328
- return args.event !== undefined;
329
- }
330
- //# sourceMappingURL=builtin.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"builtin.js","sourceRoot":"","sources":["../../src/middleware/builtin.ts"],"names":[],"mappings":";AAAA,oDAAoD;;;AA6BpD,sCAAwD;AAExD;;GAEG;AACI,MAAM,WAAW,GAA6D,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE;IAC9G,6BAA6B;IAC7B,IAAI,MAAM,KAAK,SAAS,EAAE;QACxB,OAAO;KACR;IAED,uEAAuE;IACvE,+CAA+C;IAC/C,MAAM,IAAK,EAAE,CAAC;AAChB,CAAC,CAAC;AATW,QAAA,WAAW,eAStB;AAEF;;GAEG;AACH,4CAA4C;AACrC,MAAM,aAAa,GAAiE,KAAK,EAAE,EAChG,QAAQ,EACR,IAAI,GACL,EAAE,EAAE;IACH,+BAA+B;IAC/B,IAAI,QAAQ,KAAK,SAAS,EAAE;QAC1B,OAAO;KACR;IAED,uEAAuE;IACvE,+CAA+C;IAC/C,MAAM,IAAK,EAAE,CAAC;AAChB,CAAC,CAAC;AAZW,QAAA,aAAa,iBAYxB;AAEF;;GAEG;AACI,MAAM,YAAY,GAA+D,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE;IAClH,8BAA8B;IAC9B,IAAI,OAAO,KAAK,SAAS,EAAE;QACzB,OAAO;KACR;IAED,uEAAuE;IACvE,+CAA+C;IAC/C,MAAM,IAAK,EAAE,CAAC;AAChB,CAAC,CAAC;AATW,QAAA,YAAY,gBASvB;AAEF;;GAEG;AACI,MAAM,WAAW,GAA+D,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE;I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AC,KAAK,KAAK,SAAS,CAAC;AAChE,CAAC"}
@@ -1,5 +0,0 @@
1
- import { WebClient } from '@slack/web-api';
2
- import { Logger } from '@slack/logger';
3
- import { Middleware, AnyMiddlewareArgs, Context } from '../types';
4
- export declare function processMiddleware(middleware: Middleware<AnyMiddlewareArgs>[], initialArgs: AnyMiddlewareArgs, context: Context, client: WebClient, logger: Logger, last: () => Promise<void>): Promise<void>;
5
- //# sourceMappingURL=process.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../../src/middleware/process.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAElE,wBAAsB,iBAAiB,CACrC,UAAU,EAAE,UAAU,CAAC,iBAAiB,CAAC,EAAE,EAC3C,WAAW,EAAE,iBAAiB,EAC9B,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GACxB,OAAO,CAAC,IAAI,CAAC,CAwBf"}
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.processMiddleware = void 0;
4
- async function processMiddleware(middleware, initialArgs, context, client, logger, last) {
5
- let lastCalledMiddlewareIndex = -1;
6
- async function invokeMiddleware(toCallMiddlewareIndex) {
7
- if (lastCalledMiddlewareIndex >= toCallMiddlewareIndex) {
8
- // TODO: use a coded error
9
- throw Error('next() called multiple times');
10
- }
11
- if (toCallMiddlewareIndex < middleware.length) {
12
- lastCalledMiddlewareIndex = toCallMiddlewareIndex;
13
- return middleware[toCallMiddlewareIndex]({
14
- next: () => invokeMiddleware(toCallMiddlewareIndex + 1),
15
- ...initialArgs,
16
- context,
17
- client,
18
- logger,
19
- });
20
- }
21
- return last();
22
- }
23
- return invokeMiddleware(0);
24
- }
25
- exports.processMiddleware = processMiddleware;
26
- //# sourceMappingURL=process.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"process.js","sourceRoot":"","sources":["../../src/middleware/process.ts"],"names":[],"mappings":";;;AAIO,KAAK,UAAU,iBAAiB,CACrC,UAA2C,EAC3C,WAA8B,EAC9B,OAAgB,EAChB,MAAiB,EACjB,MAAc,EACd,IAAyB;IAEzB,IAAI,yBAAyB,GAAG,CAAC,CAAC,CAAC;IAEnC,KAAK,UAAU,gBAAgB,CAAC,qBAA6B;QAC3D,IAAI,yBAAyB,IAAI,qBAAqB,EAAE;YACtD,0BAA0B;YAC1B,MAAM,KAAK,CAAC,8BAA8B,CAAC,CAAC;SAC7C;QAED,IAAI,qBAAqB,GAAG,UAAU,CAAC,MAAM,EAAE;YAC7C,yBAAyB,GAAG,qBAAqB,CAAC;YAClD,OAAO,UAAU,CAAC,qBAAqB,CAAC,CAAC;gBACvC,IAAI,EAAE,GAAG,EAAE,CAAC,gBAAgB,CAAC,qBAAqB,GAAG,CAAC,CAAC;gBACvD,GAAG,WAAW;gBACd,OAAO;gBACP,MAAM;gBACN,MAAM;aACP,CAAC,CAAC;SACJ;QAED,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC;IAED,OAAO,gBAAgB,CAAC,CAAC,CAAC,CAAC;AAC7B,CAAC;AA/BD,8CA+BC"}
@@ -1,50 +0,0 @@
1
- import { Logger, LogLevel } from '@slack/logger';
2
- import App from '../App';
3
- import { Receiver } from '../types/receiver';
4
- export interface AwsEvent {
5
- body: string | null;
6
- headers: any;
7
- multiValueHeaders: any;
8
- httpMethod: string;
9
- isBase64Encoded: boolean;
10
- path: string;
11
- pathParameters: any | null;
12
- queryStringParameters: any | null;
13
- multiValueQueryStringParameters: any | null;
14
- stageVariables: any | null;
15
- requestContext: any;
16
- resource: string;
17
- }
18
- export declare type AwsCallback = (error?: Error | string | null, result?: any) => void;
19
- export interface AwsResponse {
20
- statusCode: number;
21
- headers?: {
22
- [header: string]: boolean | number | string;
23
- };
24
- multiValueHeaders?: {
25
- [header: string]: Array<boolean | number | string>;
26
- };
27
- body: string;
28
- isBase64Encoded?: boolean;
29
- }
30
- export declare type AwsHandler = (event: AwsEvent, context: any, callback: AwsCallback) => Promise<AwsResponse>;
31
- export interface AwsLambdaReceiverOptions {
32
- signingSecret: string;
33
- logger?: Logger;
34
- logLevel?: LogLevel;
35
- }
36
- export default class AwsLambdaReceiver implements Receiver {
37
- private signingSecret;
38
- private app?;
39
- private logger;
40
- constructor({ signingSecret, logger, logLevel }: AwsLambdaReceiverOptions);
41
- init(app: App): void;
42
- start(..._args: any[]): Promise<AwsHandler>;
43
- stop(..._args: any[]): Promise<void>;
44
- toHandler(): AwsHandler;
45
- private getRawBody;
46
- private parseRequestBody;
47
- private isValidRequestSignature;
48
- private getHeaderValue;
49
- }
50
- //# sourceMappingURL=AwsLambdaReceiver.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AwsLambdaReceiver.d.ts","sourceRoot":"","sources":["../../src/receivers/AwsLambdaReceiver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAiB,QAAQ,EAAE,MAAM,eAAe,CAAC;AAIhE,OAAO,GAAG,MAAM,QAAQ,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAiB,MAAM,mBAAmB,CAAC;AAG5D,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,EAAE,GAAG,CAAC;IACb,iBAAiB,EAAE,GAAG,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,OAAO,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,GAAG,GAAG,IAAI,CAAC;IAC3B,qBAAqB,EAAE,GAAG,GAAG,IAAI,CAAC;IAClC,+BAA+B,EAAE,GAAG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AC;IAYf,IAAI,CAET,GAAG,KAAK,EAAE,GAAG,EAAE,GACd,OAAO,CAAC,IAAI,CAAC;IAOT,SAAS,IAAI,UAAU;IAqG9B,OAAO,CAAC,UAAU;IAWlB,OAAO,CAAC,gBAAgB;IAuBxB,OAAO,CAAC,uBAAuB;IA4B/B,OAAO,CAAC,cAAc;CAIvB"}
@@ -1,192 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const logger_1 = require("@slack/logger");
7
- const querystring_1 = __importDefault(require("querystring"));
8
- const crypto_1 = __importDefault(require("crypto"));
9
- const tsscmp_1 = __importDefault(require("tsscmp"));
10
- const errors_1 = require("../errors");
11
- /*
12
- * Receiver implementation for AWS API Gateway + Lambda apps
13
- *
14
- * Note that this receiver does not support Slack OAuth flow.
15
- * For OAuth flow endpoints, deploy another Lambda function built with ExpressReceiver.
16
- */
17
- class AwsLambdaReceiver {
18
- constructor({ signingSecret, logger = undefined, logLevel = logger_1.LogLevel.INFO }) {
19
- // Initialize instance variables, substituting defaults for each value
20
- this.signingSecret = signingSecret;
21
- this.logger = logger !== null && logger !== void 0 ? logger : (() => {
22
- const defaultLogger = new logger_1.ConsoleLogger();
23
- defaultLogger.setLevel(logLevel);
24
- return defaultLogger;
25
- })();
26
- }
27
- init(app) {
28
- this.app = app;
29
- }
30
- start(
31
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
32
- ..._args) {
33
- return new Promise((resolve, reject) => {
34
- try {
35
- const handler = this.toHandler();
36
- resolve(handler);
37
- }
38
- catch (error) {
39
- reject(error);
40
- }
41
- });
42
- }
43
- // eslint-disable-next-line class-methods-use-this
44
- stop(
45
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
46
- ..._args) {
47
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
48
- return new Promise((resolve, _reject) => {
49
- resolve();
50
- });
51
- }
52
- toHandler() {
53
- return async (awsEvent,
54
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
55
- _awsContext,
56
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
57
- _awsCallback) => {
58
- var _a;
59
- this.logger.debug(`AWS event: ${JSON.stringify(awsEvent, null, 2)}`);
60
- const rawBody = this.getRawBody(awsEvent);
61
- const body = this.parseRequestBody(rawBody, this.getHeaderValue(awsEvent.headers, 'Content-Type'), this.logger);
62
- // ssl_check (for Slash Commands)
63
- if (typeof body !== 'undefined' &&
64
- body != null &&
65
- typeof body.ssl_check !== 'undefined' &&
66
- body.ssl_check != null) {
67
- return Promise.resolve({ statusCode: 200, body: '' });
68
- }
69
- // request signature verification
70
- const signature = this.getHeaderValue(awsEvent.headers, 'X-Slack-Signature');
71
- const ts = Number(this.getHeaderValue(awsEvent.headers, 'X-Slack-Request-Timestamp'));
72
- if (!this.isValidRequestSignature(this.signingSecret, rawBody, signature, ts)) {
73
- return Promise.resolve({ statusCode: 401, body: '' });
74
- }
75
- // url_verification (Events API)
76
- if (typeof body !== 'undefined' &&
77
- body != null &&
78
- typeof body.type !== 'undefined' &&
79
- body.type != null &&
80
- body.type === 'url_verification') {
81
- return Promise.resolve({
82
- statusCode: 200,
83
- headers: { 'Content-Type': 'application/json' },
84
- body: JSON.stringify({ challenge: body.challenge }),
85
- });
86
- }
87
- // Setup ack timeout warning
88
- let isAcknowledged = false;
89
- setTimeout(() => {
90
- if (!isAcknowledged) {
91
- this.logger.error('An incoming event was not acknowledged within 3 seconds. ' +
92
- 'Ensure that the ack() argument is called in a listener.');
93
- }
94
- }, 3001);
95
- // Structure the ReceiverEvent
96
- let storedResponse;
97
- const event = {
98
- body,
99
- ack: async (response) => {
100
- if (isAcknowledged) {
101
- throw new errors_1.ReceiverMultipleAckError();
102
- }
103
- isAcknowledged = true;
104
- if (typeof response === 'undefined' || response == null) {
105
- storedResponse = '';
106
- }
107
- else {
108
- storedResponse = response;
109
- }
110
- },
111
- };
112
- // Send the event to the app for processing
113
- try {
114
- await ((_a = this.app) === null || _a === void 0 ? void 0 : _a.processEvent(event));
115
- if (storedResponse !== undefined) {
116
- if (typeof storedResponse === 'string') {
117
- return { statusCode: 200, body: storedResponse };
118
- }
119
- return {
120
- statusCode: 200,
121
- headers: { 'Content-Type': 'application/json' },
122
- body: JSON.stringify(storedResponse),
123
- };
124
- }
125
- }
126
- catch (err) {
127
- this.logger.error('An unhandled error occurred while Bolt processed an event');
128
- this.logger.debug(`Error details: ${err}, storedResponse: ${storedResponse}`);
129
- return { statusCode: 500, body: 'Internal server error' };
130
- }
131
- return { statusCode: 404, body: '' };
132
- };
133
- }
134
- // eslint-disable-next-line class-methods-use-this
135
- getRawBody(awsEvent) {
136
- if (typeof awsEvent.body === 'undefined' || awsEvent.body == null) {
137
- return '';
138
- }
139
- if (awsEvent.isBase64Encoded) {
140
- return Buffer.from(awsEvent.body, 'base64').toString('ascii');
141
- }
142
- return awsEvent.body;
143
- }
144
- // eslint-disable-next-line class-methods-use-this
145
- parseRequestBody(stringBody, contentType, logger) {
146
- if (contentType === 'application/x-www-form-urlencoded') {
147
- const parsedBody = querystring_1.default.parse(stringBody);
148
- if (typeof parsedBody.payload === 'string') {
149
- return JSON.parse(parsedBody.payload);
150
- }
151
- return parsedBody;
152
- }
153
- if (contentType === 'application/json') {
154
- return JSON.parse(stringBody);
155
- }
156
- logger.warn(`Unexpected content-type detected: ${contentType}`);
157
- try {
158
- // Parse this body anyway
159
- return JSON.parse(stringBody);
160
- }
161
- catch (e) {
162
- logger.error(`Failed to parse body as JSON data for content-type: ${contentType}`);
163
- throw e;
164
- }
165
- }
166
- // eslint-disable-next-line class-methods-use-this
167
- isValidRequestSignature(signingSecret, body, signature, requestTimestamp) {
168
- if (!signature || !requestTimestamp) {
169
- return false;
170
- }
171
- // Divide current date to match Slack ts format
172
- // Subtract 5 minutes from current time
173
- const fiveMinutesAgo = Math.floor(Date.now() / 1000) - 60 * 5;
174
- if (requestTimestamp < fiveMinutesAgo) {
175
- return false;
176
- }
177
- const hmac = crypto_1.default.createHmac('sha256', signingSecret);
178
- const [version, hash] = signature.split('=');
179
- hmac.update(`${version}:${requestTimestamp}:${body}`);
180
- if (!tsscmp_1.default(hash, hmac.digest('hex'))) {
181
- return false;
182
- }
183
- return true;
184
- }
185
- // eslint-disable-next-line class-methods-use-this
186
- getHeaderValue(headers, key) {
187
- const caseInsensitiveKey = Object.keys(headers).find((it) => key.toLowerCase() === it.toLowerCase());
188
- return caseInsensitiveKey !== undefined ? headers[caseInsensitiveKey] : undefined;
189
- }
190
- }
191
- exports.default = AwsLambdaReceiver;
192
- //# sourceMappingURL=AwsLambdaReceiver.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AwsLambdaReceiver.js","sourceRoot":"","sources":["../../src/receivers/AwsLambdaReceiver.ts"],"names":[],"mappings":";;;;;AAAA,0CAAgE;AAChE,8DAAsC;AACtC,oDAA4B;AAC5B,oDAA4B;AAG5B,sCAAqD;AAuCrD;;;;;GAKG;AACH,MAAqB,iBAAiB;IAOpC,YAAY,EAAE,aAAa,EAAE,MAAM,GAAG,SAAS,EAAE,QAAQ,GAAG,iBAAQ,CAAC,IAAI,EAA4B;QACnG,sEAAsE;QACtE,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,MAAM,GACT,MAAM,aAAN,MAAM,cAAN,MAAM,GACN,CAAC,GAAG,EAAE;YACJ,MAAM,aAAa,GAAG,IAAI,sBAAa,EAAE,CAAC;YAC1C,aAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YACjC,OAAO,aAAa,CAAC;QACvB,CAAC,CAAC,EAAE,CAAC;IACT,CAAC;IAEM,IAAI,CAAC,GAAQ;QAClB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAEM,KAAK;IACV,6DAA6D;IAC7D,GAAG,KAAY;QAEf,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAA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