@slack/bolt 3.9.0-hermesBeta.2 → 3.11.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.
- package/README.md +1 -1
- package/dist/App.d.ts +11 -8
- package/dist/App.d.ts.map +1 -1
- package/dist/App.js +184 -142
- package/dist/App.js.map +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/helpers.d.ts +1 -2
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +0 -8
- package/dist/helpers.js.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -1
- package/dist/index.js.map +1 -1
- package/dist/middleware/builtin.js +1 -0
- package/dist/middleware/builtin.js.map +1 -1
- package/dist/middleware/process.d.ts.map +1 -1
- package/dist/middleware/process.js.map +1 -1
- package/dist/receivers/BufferedIncomingMessage.d.ts +6 -0
- package/dist/receivers/BufferedIncomingMessage.d.ts.map +1 -0
- package/dist/{types/subscription/index.js → receivers/BufferedIncomingMessage.js} +1 -1
- package/dist/receivers/BufferedIncomingMessage.js.map +1 -0
- package/dist/receivers/ExpressReceiver.d.ts +20 -6
- package/dist/receivers/ExpressReceiver.d.ts.map +1 -1
- package/dist/receivers/ExpressReceiver.js +68 -84
- package/dist/receivers/ExpressReceiver.js.map +1 -1
- package/dist/receivers/HTTPModuleFunctions.d.ts +47 -0
- package/dist/receivers/HTTPModuleFunctions.d.ts.map +1 -0
- package/dist/receivers/HTTPModuleFunctions.js +197 -0
- package/dist/receivers/HTTPModuleFunctions.js.map +1 -0
- package/dist/receivers/HTTPReceiver.d.ts +14 -32
- package/dist/receivers/HTTPReceiver.d.ts.map +1 -1
- package/dist/receivers/HTTPReceiver.js +44 -179
- package/dist/receivers/HTTPReceiver.js.map +1 -1
- package/dist/receivers/HTTPResponseAck.d.ts +29 -0
- package/dist/receivers/HTTPResponseAck.d.ts.map +1 -0
- package/dist/receivers/HTTPResponseAck.js +60 -0
- package/dist/receivers/HTTPResponseAck.js.map +1 -0
- package/dist/receivers/SocketModeFunctions.d.ts +12 -0
- package/dist/receivers/SocketModeFunctions.d.ts.map +1 -0
- package/dist/receivers/SocketModeFunctions.js +28 -0
- package/dist/receivers/SocketModeFunctions.js.map +1 -0
- package/dist/receivers/SocketModeReceiver.d.ts +10 -3
- package/dist/receivers/SocketModeReceiver.d.ts.map +1 -1
- package/dist/receivers/SocketModeReceiver.js +29 -37
- package/dist/receivers/SocketModeReceiver.js.map +1 -1
- package/dist/receivers/custom-routes.d.ts +1 -1
- package/dist/receivers/custom-routes.d.ts.map +1 -1
- package/dist/receivers/custom-routes.js +3 -3
- package/dist/receivers/custom-routes.js.map +1 -1
- package/dist/receivers/http-utils.d.ts.map +1 -1
- package/dist/receivers/http-utils.js +9 -25
- package/dist/receivers/http-utils.js.map +1 -1
- package/dist/receivers/render-html-for-install-path.d.ts.map +1 -1
- package/dist/receivers/render-html-for-install-path.js +8 -1
- package/dist/receivers/render-html-for-install-path.js.map +1 -1
- package/dist/receivers/verify-request.d.ts +25 -33
- package/dist/receivers/verify-request.d.ts.map +1 -1
- package/dist/receivers/verify-request.js +41 -61
- package/dist/receivers/verify-request.js.map +1 -1
- package/dist/types/events/base-events.d.ts +157 -19
- package/dist/types/events/base-events.d.ts.map +1 -1
- package/dist/types/events/base-events.js.map +1 -1
- package/dist/types/events/index.d.ts +1 -1
- package/dist/types/events/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +0 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/middleware.d.ts +1 -2
- package/dist/types/middleware.d.ts.map +1 -1
- package/package.json +10 -7
- package/CHANGELOG.md +0 -5
- package/dist/Subscription.d.ts +0 -61
- package/dist/Subscription.d.ts.map +0 -1
- package/dist/Subscription.js +0 -169
- package/dist/Subscription.js.map +0 -1
- package/dist/types/actions/notification-subscription.d.ts +0 -59
- package/dist/types/actions/notification-subscription.d.ts.map +0 -1
- package/dist/types/actions/notification-subscription.js +0 -3
- package/dist/types/actions/notification-subscription.js.map +0 -1
- package/dist/types/subscription/index.d.ts +0 -80
- package/dist/types/subscription/index.d.ts.map +0 -1
- package/dist/types/subscription/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -80,7 +80,7 @@ Most of the app's functionality will be inside listener functions (the `fn` para
|
|
|
80
80
|
| `say` | Function to send a message to the channel associated with the incoming event. This argument is only available when the listener is triggered for events that contain a `channel_id` (the most common being `message` events). `say` accepts simple strings (for plain-text messages) and objects (for messages containing blocks). `say` returns a promise that will resolve with a [`chat.postMessage` response](https://api.slack.com/methods/chat.postMessage).
|
|
81
81
|
| `ack` | Function that **must** be called to acknowledge that an incoming event was received by your app. `ack` exists for all actions, shortcuts, view, slash command and options requests. `ack` returns a promise that resolves when complete. Read more in [Acknowledging events](#acknowledging-events)
|
|
82
82
|
| `client` | Web API client that uses the token associated with that event. For single-workspace installations, the token is provided to the constructor. For multi-workspace installations, the token is returned by the `authorize` function.
|
|
83
|
-
| `respond` | Function that responds to an incoming event **if** it contains a `response_url` (shortcuts,
|
|
83
|
+
| `respond` | Function that responds to an incoming event **if** it contains a `response_url` (actions, shortcuts, view submissions, and slash commands). `respond` returns a promise that resolves with the results of responding using the `response_url`.
|
|
84
84
|
| `context` | Event context. This object contains data about the event and the app, such as the `botId`. Middleware can add additional context before the event is passed to listeners.
|
|
85
85
|
| `body` | Object that contains the entire body of the request (superset of `payload`). Some accessory data is only available outside of the payload (such as `trigger_id` and `authorizations`).
|
|
86
86
|
|
package/dist/App.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ import SocketModeReceiver from './receivers/SocketModeReceiver';
|
|
|
7
7
|
import HTTPReceiver, { HTTPReceiverOptions } from './receivers/HTTPReceiver';
|
|
8
8
|
import { ConversationStore } from './conversation-store';
|
|
9
9
|
import { WorkflowStep } from './WorkflowStep';
|
|
10
|
-
import { SubscriptionOptions } from './Subscription';
|
|
11
10
|
import { Middleware, AnyMiddlewareArgs, SlackActionMiddlewareArgs, SlackCommandMiddlewareArgs, SlackEventMiddlewareArgs, SlackOptionsMiddlewareArgs, SlackShortcutMiddlewareArgs, SlackViewMiddlewareArgs, SlackAction, SlackShortcut, Context, OptionsSource, BlockAction, SlackViewAction, Receiver, ReceiverEvent } from './types';
|
|
12
11
|
import { CodedError } from './errors';
|
|
13
12
|
/** App initialization options */
|
|
@@ -41,6 +40,7 @@ export interface AppOptions {
|
|
|
41
40
|
socketMode?: boolean;
|
|
42
41
|
developerMode?: boolean;
|
|
43
42
|
tokenVerificationEnabled?: boolean;
|
|
43
|
+
deferInitialization?: boolean;
|
|
44
44
|
extendedErrorHandler?: boolean;
|
|
45
45
|
}
|
|
46
46
|
export { LogLevel, Logger } from '@slack/logger';
|
|
@@ -127,7 +127,13 @@ export default class App {
|
|
|
127
127
|
private developerMode;
|
|
128
128
|
private extendedErrorHandler;
|
|
129
129
|
private hasCustomErrorHandler;
|
|
130
|
-
|
|
130
|
+
private argToken?;
|
|
131
|
+
private argAuthorize?;
|
|
132
|
+
private argAuthorization?;
|
|
133
|
+
private tokenVerificationEnabled;
|
|
134
|
+
private initialized;
|
|
135
|
+
constructor({ signingSecret, endpoints, port, customRoutes, agent, clientTls, receiver, convoStore, token, appToken, botId, botUserId, authorize, logger, logLevel, ignoreSelf, clientOptions, processBeforeResponse, signatureVerification, clientId, clientSecret, stateSecret, redirectUri, installationStore, scopes, installerOptions, socketMode, developerMode, tokenVerificationEnabled, extendedErrorHandler, deferInitialization, }?: AppOptions);
|
|
136
|
+
init(): Promise<void>;
|
|
131
137
|
/**
|
|
132
138
|
* Register a new middleware, processed in the order registered.
|
|
133
139
|
*
|
|
@@ -149,12 +155,6 @@ export default class App {
|
|
|
149
155
|
*/
|
|
150
156
|
start(...args: Parameters<HTTPReceiver['start'] | SocketModeReceiver['start']>): ReturnType<HTTPReceiver['start']>;
|
|
151
157
|
stop(...args: any[]): Promise<unknown>;
|
|
152
|
-
/**
|
|
153
|
-
* Register subcription middleware
|
|
154
|
-
*
|
|
155
|
-
* @param listeners middleware that process and react to subscription payloads
|
|
156
|
-
*/
|
|
157
|
-
subscription(options: SubscriptionOptions): this;
|
|
158
158
|
event<EventType extends string = string>(eventName: EventType, ...listeners: Middleware<SlackEventMiddlewareArgs<EventType>>[]): void;
|
|
159
159
|
event<EventType extends RegExp = RegExp>(eventName: EventType, ...listeners: Middleware<SlackEventMiddlewareArgs<string>>[]): void;
|
|
160
160
|
/**
|
|
@@ -215,5 +215,8 @@ export default class App {
|
|
|
215
215
|
* Global error handler. The final destination for all errors (hopefully).
|
|
216
216
|
*/
|
|
217
217
|
private handleError;
|
|
218
|
+
private initReceiver;
|
|
219
|
+
private initAuthorizeIfNoTokenIsGiven;
|
|
220
|
+
private initAuthorizeInConstructor;
|
|
218
221
|
}
|
|
219
222
|
//# sourceMappingURL=App.d.ts.map
|
package/dist/App.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../src/App.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,oBAAoB,EAAE,MAAM,KAAK,CAAC;AAE3C,OAAO,EAAE,SAAS,EAA4C,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvG,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAiB,MAAM,eAAe,CAAC;AAEhE,OAAO,kBAAkB,MAAM,gCAAgC,CAAC;AAChE,OAAO,YAAY,EAAE,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAe7E,OAAO,EAAE,iBAAiB,EAAoC,MAAM,sBAAsB,CAAC;AAC3F,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,
|
|
1
|
+
{"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../src/App.ts"],"names":[],"mappings":";AAAA,OAAO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G,aAAa,EACzD,WAAW,EAAE,iBAAiB,EAC9B,GAAG,SAAS,EAAE,UAAU,CAAC,0BAA0B,CAAC,MAAM,CAAC,CAAC,EAAE,GAC7D,IAAI;IAaA,IAAI,CAAC,cAAc,SAAS,eAAe,GAAG,eAAe,EAClE,UAAU,EAAE,MAAM,GAAG,MAAM,EAC3B,GAAG,SAAS,EAAE,UAAU,CAAC,uBAAuB,CAAC,cAAc,CAAC,CAAC,EAAE,GAClE,IAAI;IACA,IAAI,CAAC,cAAc,SAAS,eAAe,GAAG,eAAe,EAClE,WAAW,EAAE,eAAe,EAC5B,GAAG,SAAS,EAAE,UAAU,CAAC,uBAAuB,CAAC,cAAc,CAAC,CAAC,EAAE,GAClE,IAAI;IA8BA,KAAK,CAAC,YAAY,EAAE,YAAY,GAAG,IAAI;IACvC,KAAK,CAAC,YAAY,EAAE,oBAAoB,GAAG,IAAI;IAMtD;;OAEG;IACU,YAAY,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAkR9D;;OAEG;IACH,OAAO,CAAC,WAAW;IAYnB,OAAO,CAAC,YAAY;IAyEpB,OAAO,CAAC,6BAA6B;IAuCrC,OAAO,CAAC,0BAA0B;CAwBnC"}
|
package/dist/App.js
CHANGED
|
@@ -13,7 +13,6 @@ const HTTPReceiver_1 = __importDefault(require("./receivers/HTTPReceiver"));
|
|
|
13
13
|
const builtin_1 = require("./middleware/builtin");
|
|
14
14
|
const process_1 = __importDefault(require("./middleware/process"));
|
|
15
15
|
const conversation_store_1 = require("./conversation-store");
|
|
16
|
-
const Subscription_1 = require("./Subscription");
|
|
17
16
|
const helpers_1 = require("./helpers");
|
|
18
17
|
const errors_1 = require("./errors");
|
|
19
18
|
const middleware_1 = require("./types/middleware");
|
|
@@ -48,7 +47,7 @@ class WebClientPool {
|
|
|
48
47
|
* A Slack App
|
|
49
48
|
*/
|
|
50
49
|
class App {
|
|
51
|
-
constructor({ signingSecret = undefined, endpoints = undefined, port = undefined, customRoutes = undefined, agent = undefined, clientTls = undefined, receiver = undefined, convoStore = undefined, token = undefined, appToken = undefined, botId = undefined, botUserId = undefined, authorize = undefined, logger = undefined, logLevel = undefined, ignoreSelf = true, clientOptions = undefined, processBeforeResponse = false, signatureVerification = true, clientId = undefined, clientSecret = undefined, stateSecret = undefined, redirectUri = undefined, installationStore = undefined, scopes = undefined, installerOptions = undefined, socketMode = undefined, developerMode = false, tokenVerificationEnabled = true, extendedErrorHandler = false, } = {}) {
|
|
50
|
+
constructor({ signingSecret = undefined, endpoints = undefined, port = undefined, customRoutes = undefined, agent = undefined, clientTls = undefined, receiver = undefined, convoStore = undefined, token = undefined, appToken = undefined, botId = undefined, botUserId = undefined, authorize = undefined, logger = undefined, logLevel = undefined, ignoreSelf = true, clientOptions = undefined, processBeforeResponse = false, signatureVerification = true, clientId = undefined, clientSecret = undefined, stateSecret = undefined, redirectUri = undefined, installationStore = undefined, scopes = undefined, installerOptions = undefined, socketMode = undefined, developerMode = false, tokenVerificationEnabled = true, extendedErrorHandler = false, deferInitialization = false, } = {}) {
|
|
52
51
|
// this.logLevel = logLevel;
|
|
53
52
|
// Some payloads don't have teamId anymore. So we use EnterpriseId in those scenarios
|
|
54
53
|
this.clients = {};
|
|
@@ -139,97 +138,27 @@ class App {
|
|
|
139
138
|
},
|
|
140
139
|
};
|
|
141
140
|
}
|
|
142
|
-
|
|
143
|
-
if (receiver !== undefined) {
|
|
144
|
-
// Custom receiver supplied
|
|
145
|
-
if (this.socketMode === true) {
|
|
146
|
-
// socketMode = true should result in SocketModeReceiver being used as receiver
|
|
147
|
-
// TODO: Add case for when socketMode = true and receiver = SocketModeReceiver
|
|
148
|
-
// as this should not result in an error
|
|
149
|
-
throw new errors_1.AppInitializationError('You cannot supply a custom receiver when socketMode is set to true.');
|
|
150
|
-
}
|
|
151
|
-
this.receiver = receiver;
|
|
152
|
-
}
|
|
153
|
-
else if (this.socketMode === true) {
|
|
154
|
-
if (appToken === undefined) {
|
|
155
|
-
throw new errors_1.AppInitializationError('You must provide an appToken when socketMode is set to true. To generate an appToken see: https://api.slack.com/apis/connections/socket#token');
|
|
156
|
-
}
|
|
157
|
-
this.logger.debug('Initializing SocketModeReceiver');
|
|
158
|
-
this.receiver = new SocketModeReceiver_1.default({
|
|
159
|
-
appToken,
|
|
160
|
-
clientId,
|
|
161
|
-
clientSecret,
|
|
162
|
-
stateSecret,
|
|
163
|
-
redirectUri,
|
|
164
|
-
installationStore,
|
|
165
|
-
scopes,
|
|
166
|
-
logger,
|
|
167
|
-
logLevel: this.logLevel,
|
|
168
|
-
installerOptions: this.installerOptions,
|
|
169
|
-
customRoutes,
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
else if (signatureVerification === true && signingSecret === undefined) {
|
|
173
|
-
// Using default receiver HTTPReceiver, signature verification enabled, missing signingSecret
|
|
174
|
-
throw new errors_1.AppInitializationError('signingSecret is required to initialize the default receiver. Set signingSecret or use a ' +
|
|
175
|
-
'custom receiver. You can find your Signing Secret in your Slack App Settings.');
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
this.logger.debug('Initializing HTTPReceiver');
|
|
179
|
-
this.receiver = new HTTPReceiver_1.default({
|
|
180
|
-
signingSecret: signingSecret || '',
|
|
181
|
-
endpoints,
|
|
182
|
-
port,
|
|
183
|
-
customRoutes,
|
|
184
|
-
processBeforeResponse,
|
|
185
|
-
signatureVerification,
|
|
186
|
-
clientId,
|
|
187
|
-
clientSecret,
|
|
188
|
-
stateSecret,
|
|
189
|
-
redirectUri,
|
|
190
|
-
installationStore,
|
|
191
|
-
scopes,
|
|
192
|
-
logger,
|
|
193
|
-
logLevel: this.logLevel,
|
|
194
|
-
installerOptions: this.installerOptions,
|
|
195
|
-
});
|
|
196
|
-
}
|
|
141
|
+
this.receiver = this.initReceiver(receiver, signingSecret, endpoints, port, customRoutes, processBeforeResponse, signatureVerification, clientId, clientSecret, stateSecret, redirectUri, installationStore, scopes, appToken, logger);
|
|
197
142
|
/* ------------------------ Set authorize ----------------------------- */
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
if (httpReceiver.installer !== undefined &&
|
|
201
|
-
httpReceiver.installer.authorize !== undefined) {
|
|
202
|
-
// This supports using the built in HTTPReceiver, declaring your own HTTPReceiver
|
|
203
|
-
// and theoretically, doing a fully custom (non express) receiver that implements OAuth
|
|
204
|
-
usingOauth = true;
|
|
205
|
-
}
|
|
143
|
+
this.tokenVerificationEnabled = tokenVerificationEnabled;
|
|
144
|
+
let argAuthorization;
|
|
206
145
|
if (token !== undefined) {
|
|
207
|
-
|
|
208
|
-
if (usingOauth || authorize !== undefined) {
|
|
209
|
-
throw new errors_1.AppInitializationError(`You cannot provide a token along with either oauth installer options or authorize. ${tokenUsage}`);
|
|
210
|
-
}
|
|
211
|
-
this.authorize = singleAuthorization(this.client, {
|
|
146
|
+
argAuthorization = {
|
|
212
147
|
botId,
|
|
213
148
|
botUserId,
|
|
214
149
|
botToken: token,
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
else if (authorize === undefined && !usingOauth) {
|
|
218
|
-
throw new errors_1.AppInitializationError(`${tokenUsage} \n\nSince you have not provided a token or authorize, you might be missing one or more required oauth installer options. See https://slack.dev/bolt-js/concepts#authenticating-oauth for these required fields.\n`);
|
|
219
|
-
}
|
|
220
|
-
else if (authorize !== undefined && usingOauth) {
|
|
221
|
-
throw new errors_1.AppInitializationError(`You cannot provide both authorize and oauth installer options. ${tokenUsage}`);
|
|
222
|
-
}
|
|
223
|
-
else if (authorize === undefined && usingOauth) {
|
|
224
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
225
|
-
this.authorize = httpReceiver.installer.authorize;
|
|
150
|
+
};
|
|
226
151
|
}
|
|
227
|
-
|
|
228
|
-
this.
|
|
152
|
+
if (deferInitialization) {
|
|
153
|
+
this.argToken = token;
|
|
154
|
+
this.argAuthorize = authorize;
|
|
155
|
+
this.argAuthorization = argAuthorization;
|
|
156
|
+
this.initialized = false;
|
|
157
|
+
// You need to run `await app.init();` on your own
|
|
229
158
|
}
|
|
230
159
|
else {
|
|
231
|
-
this.
|
|
232
|
-
|
|
160
|
+
this.authorize = this.initAuthorizeInConstructor(token, authorize, argAuthorization);
|
|
161
|
+
this.initialized = true;
|
|
233
162
|
}
|
|
234
163
|
// Conditionally use a global middleware that ignores events (including messages) that are sent from this app
|
|
235
164
|
if (ignoreSelf) {
|
|
@@ -245,6 +174,40 @@ class App {
|
|
|
245
174
|
// Should be last to avoid exposing partially initialized app
|
|
246
175
|
this.receiver.init(this);
|
|
247
176
|
}
|
|
177
|
+
async init() {
|
|
178
|
+
this.initialized = true;
|
|
179
|
+
try {
|
|
180
|
+
const initializedAuthorize = this.initAuthorizeIfNoTokenIsGiven(this.argToken, this.argAuthorize);
|
|
181
|
+
if (initializedAuthorize !== undefined) {
|
|
182
|
+
this.authorize = initializedAuthorize;
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (this.argToken !== undefined && this.argAuthorization !== undefined) {
|
|
186
|
+
let authorization = this.argAuthorization;
|
|
187
|
+
if (this.tokenVerificationEnabled) {
|
|
188
|
+
const authTestResult = await this.client.auth.test({ token: this.argToken });
|
|
189
|
+
if (authTestResult.ok) {
|
|
190
|
+
authorization = {
|
|
191
|
+
botUserId: authTestResult.user_id,
|
|
192
|
+
botId: authTestResult.bot_id,
|
|
193
|
+
botToken: this.argToken,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
this.authorize = singleAuthorization(this.client, authorization, this.tokenVerificationEnabled);
|
|
198
|
+
this.initialized = true;
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
this.logger.error('Something has gone wrong. Please report this issue to the maintainers. https://github.com/slackapi/bolt-js/issues');
|
|
202
|
+
(0, helpers_1.assertNever)();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
catch (e) {
|
|
206
|
+
// Revert the flag change as the initialization failed
|
|
207
|
+
this.initialized = false;
|
|
208
|
+
throw e;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
248
211
|
/**
|
|
249
212
|
* Register a new middleware, processed in the order registered.
|
|
250
213
|
*
|
|
@@ -272,6 +235,9 @@ class App {
|
|
|
272
235
|
* @param args receiver-specific start arguments
|
|
273
236
|
*/
|
|
274
237
|
start(...args) {
|
|
238
|
+
if (!this.initialized) {
|
|
239
|
+
throw new errors_1.AppInitializationError('This App instance is not yet initialized. Call `await App#init()` before starting the app.');
|
|
240
|
+
}
|
|
275
241
|
// TODO: HTTPReceiver['start'] should be the actual receiver's return type
|
|
276
242
|
return this.receiver.start(...args);
|
|
277
243
|
}
|
|
@@ -279,22 +245,6 @@ class App {
|
|
|
279
245
|
stop(...args) {
|
|
280
246
|
return this.receiver.stop(...args);
|
|
281
247
|
}
|
|
282
|
-
/**
|
|
283
|
-
* Register subcription middleware
|
|
284
|
-
*
|
|
285
|
-
* @param listeners middleware that process and react to subscription payloads
|
|
286
|
-
*/
|
|
287
|
-
subscription(options) {
|
|
288
|
-
/*
|
|
289
|
-
* TODO If it becomes possible for users to set a custom unique resource id,
|
|
290
|
-
* custom id should be supplied in place of the default.
|
|
291
|
-
* */
|
|
292
|
-
const defaultId = 'DEFAULTID';
|
|
293
|
-
const s = new Subscription_1.Subscription(defaultId, options);
|
|
294
|
-
const m = s.getMiddleware();
|
|
295
|
-
this.middleware.push(m);
|
|
296
|
-
return this;
|
|
297
|
-
}
|
|
298
248
|
event(eventNameOrPattern, ...listeners) {
|
|
299
249
|
let invalidEventName = false;
|
|
300
250
|
if (typeof eventNameOrPattern === 'string') {
|
|
@@ -418,28 +368,31 @@ class App {
|
|
|
418
368
|
const isEnterpriseInstall = isBodyWithTypeEnterpriseInstall(bodyArg, type);
|
|
419
369
|
const source = buildSource(type, conversationId, bodyArg, isEnterpriseInstall);
|
|
420
370
|
let authorizeResult;
|
|
421
|
-
|
|
422
|
-
|
|
371
|
+
if (type === helpers_1.IncomingEventType.Event && isEventTypeToSkipAuthorize(event.body.event.type)) {
|
|
372
|
+
authorizeResult = {
|
|
373
|
+
enterpriseId: source.enterpriseId,
|
|
374
|
+
teamId: source.teamId,
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
else {
|
|
378
|
+
try {
|
|
423
379
|
authorizeResult = await this.authorize(source, bodyArg);
|
|
424
380
|
}
|
|
425
|
-
|
|
426
|
-
|
|
381
|
+
catch (error) {
|
|
382
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
383
|
+
const e = error;
|
|
384
|
+
this.logger.warn('Authorization of incoming event did not succeed. No listeners will be called.');
|
|
385
|
+
e.code = errors_1.ErrorCode.AuthorizationError;
|
|
386
|
+
// disabling due to https://github.com/typescript-eslint/typescript-eslint/issues/1277
|
|
387
|
+
// eslint-disable-next-line consistent-return
|
|
388
|
+
return this.handleError({
|
|
389
|
+
error: e,
|
|
390
|
+
logger: this.logger,
|
|
391
|
+
body: bodyArg,
|
|
392
|
+
context: {},
|
|
393
|
+
});
|
|
427
394
|
}
|
|
428
395
|
}
|
|
429
|
-
catch (error) {
|
|
430
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
431
|
-
const e = error;
|
|
432
|
-
this.logger.warn('Authorization of incoming event did not succeed. No listeners will be called.');
|
|
433
|
-
e.code = errors_1.ErrorCode.AuthorizationError;
|
|
434
|
-
// disabling due to https://github.com/typescript-eslint/typescript-eslint/issues/1277
|
|
435
|
-
// eslint-disable-next-line consistent-return
|
|
436
|
-
return this.handleError({
|
|
437
|
-
error: e,
|
|
438
|
-
logger: this.logger,
|
|
439
|
-
body: bodyArg,
|
|
440
|
-
context: {},
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
396
|
// Try to set teamId from AuthorizeResult before using one from source
|
|
444
397
|
if (authorizeResult.teamId === undefined && source.teamId !== undefined) {
|
|
445
398
|
authorizeResult.teamId = source.teamId;
|
|
@@ -634,6 +587,106 @@ class App {
|
|
|
634
587
|
this.errorHandler({ error: (0, errors_1.asCodedError)(error), ...rest }) :
|
|
635
588
|
this.errorHandler((0, errors_1.asCodedError)(error));
|
|
636
589
|
}
|
|
590
|
+
// ---------------------
|
|
591
|
+
// Private methods for initialization
|
|
592
|
+
// ---------------------
|
|
593
|
+
initReceiver(receiver, signingSecret, endpoints, port, customRoutes, processBeforeResponse, signatureVerification, clientId, clientSecret, stateSecret, redirectUri, installationStore, scopes, appToken, logger) {
|
|
594
|
+
if (receiver !== undefined) {
|
|
595
|
+
// Custom receiver supplied
|
|
596
|
+
if (this.socketMode === true) {
|
|
597
|
+
// socketMode = true should result in SocketModeReceiver being used as receiver
|
|
598
|
+
// TODO: Add case for when socketMode = true and receiver = SocketModeReceiver
|
|
599
|
+
// as this should not result in an error
|
|
600
|
+
throw new errors_1.AppInitializationError('You cannot supply a custom receiver when socketMode is set to true.');
|
|
601
|
+
}
|
|
602
|
+
return receiver;
|
|
603
|
+
}
|
|
604
|
+
if (this.socketMode === true) {
|
|
605
|
+
if (appToken === undefined) {
|
|
606
|
+
throw new errors_1.AppInitializationError('You must provide an appToken when socketMode is set to true. To generate an appToken see: https://api.slack.com/apis/connections/socket#token');
|
|
607
|
+
}
|
|
608
|
+
this.logger.debug('Initializing SocketModeReceiver');
|
|
609
|
+
return new SocketModeReceiver_1.default({
|
|
610
|
+
appToken,
|
|
611
|
+
clientId,
|
|
612
|
+
clientSecret,
|
|
613
|
+
stateSecret,
|
|
614
|
+
redirectUri,
|
|
615
|
+
installationStore,
|
|
616
|
+
scopes,
|
|
617
|
+
logger,
|
|
618
|
+
logLevel: this.logLevel,
|
|
619
|
+
installerOptions: this.installerOptions,
|
|
620
|
+
customRoutes,
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
if (signatureVerification === true && signingSecret === undefined) {
|
|
624
|
+
// Using default receiver HTTPReceiver, signature verification enabled, missing signingSecret
|
|
625
|
+
throw new errors_1.AppInitializationError('signingSecret is required to initialize the default receiver. Set signingSecret or use a ' +
|
|
626
|
+
'custom receiver. You can find your Signing Secret in your Slack App Settings.');
|
|
627
|
+
}
|
|
628
|
+
this.logger.debug('Initializing HTTPReceiver');
|
|
629
|
+
return new HTTPReceiver_1.default({
|
|
630
|
+
signingSecret: signingSecret || '',
|
|
631
|
+
endpoints,
|
|
632
|
+
port,
|
|
633
|
+
customRoutes,
|
|
634
|
+
processBeforeResponse,
|
|
635
|
+
signatureVerification,
|
|
636
|
+
clientId,
|
|
637
|
+
clientSecret,
|
|
638
|
+
stateSecret,
|
|
639
|
+
redirectUri,
|
|
640
|
+
installationStore,
|
|
641
|
+
scopes,
|
|
642
|
+
logger,
|
|
643
|
+
logLevel: this.logLevel,
|
|
644
|
+
installerOptions: this.installerOptions,
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
initAuthorizeIfNoTokenIsGiven(token, authorize) {
|
|
648
|
+
let usingOauth = false;
|
|
649
|
+
const httpReceiver = this.receiver;
|
|
650
|
+
if (httpReceiver.installer !== undefined &&
|
|
651
|
+
httpReceiver.installer.authorize !== undefined) {
|
|
652
|
+
// This supports using the built in HTTPReceiver, declaring your own HTTPReceiver
|
|
653
|
+
// and theoretically, doing a fully custom (non express) receiver that implements OAuth
|
|
654
|
+
usingOauth = true;
|
|
655
|
+
}
|
|
656
|
+
if (token !== undefined) {
|
|
657
|
+
if (usingOauth || authorize !== undefined) {
|
|
658
|
+
throw new errors_1.AppInitializationError(`You cannot provide a token along with either oauth installer options or authorize. ${tokenUsage}`);
|
|
659
|
+
}
|
|
660
|
+
return undefined;
|
|
661
|
+
}
|
|
662
|
+
if (authorize === undefined && !usingOauth) {
|
|
663
|
+
throw new errors_1.AppInitializationError(`${tokenUsage} \n\nSince you have not provided a token or authorize, you might be missing one or more required oauth installer options. See https://slack.dev/bolt-js/concepts#authenticating-oauth for these required fields.\n`);
|
|
664
|
+
}
|
|
665
|
+
else if (authorize !== undefined && usingOauth) {
|
|
666
|
+
throw new errors_1.AppInitializationError(`You cannot provide both authorize and oauth installer options. ${tokenUsage}`);
|
|
667
|
+
}
|
|
668
|
+
else if (authorize === undefined && usingOauth) {
|
|
669
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
670
|
+
return httpReceiver.installer.authorize;
|
|
671
|
+
}
|
|
672
|
+
else if (authorize !== undefined && !usingOauth) {
|
|
673
|
+
return authorize;
|
|
674
|
+
}
|
|
675
|
+
return undefined;
|
|
676
|
+
}
|
|
677
|
+
initAuthorizeInConstructor(token, authorize, authorization) {
|
|
678
|
+
const initializedAuthorize = this.initAuthorizeIfNoTokenIsGiven(token, authorize);
|
|
679
|
+
if (initializedAuthorize !== undefined) {
|
|
680
|
+
return initializedAuthorize;
|
|
681
|
+
}
|
|
682
|
+
if (token !== undefined && authorization !== undefined) {
|
|
683
|
+
return singleAuthorization(this.client, authorization, this.tokenVerificationEnabled);
|
|
684
|
+
}
|
|
685
|
+
const hasToken = token !== undefined && token.length > 0;
|
|
686
|
+
const errorMessage = `Something has gone wrong in #initAuthorizeInConstructor method (hasToken: ${hasToken}, authorize: ${authorize}). Please report this issue to the maintainers. https://github.com/slackapi/bolt-js/issues`;
|
|
687
|
+
this.logger.error(errorMessage);
|
|
688
|
+
throw new Error(errorMessage);
|
|
689
|
+
}
|
|
637
690
|
}
|
|
638
691
|
exports.default = App;
|
|
639
692
|
function defaultErrorHandler(logger) {
|
|
@@ -692,10 +745,6 @@ function buildSource(type, channelId, body, isEnterpriseInstall) {
|
|
|
692
745
|
if (type === helpers_1.IncomingEventType.Command) {
|
|
693
746
|
return body.team_id;
|
|
694
747
|
}
|
|
695
|
-
if (type === helpers_1.IncomingEventType.Subscription) {
|
|
696
|
-
const bodyAsSubscriptionInteraction = body;
|
|
697
|
-
return bodyAsSubscriptionInteraction.team.id;
|
|
698
|
-
}
|
|
699
748
|
if (type === helpers_1.IncomingEventType.Action ||
|
|
700
749
|
type === helpers_1.IncomingEventType.Options ||
|
|
701
750
|
type === helpers_1.IncomingEventType.ViewAction ||
|
|
@@ -724,10 +773,6 @@ function buildSource(type, channelId, body, isEnterpriseInstall) {
|
|
|
724
773
|
if (type === helpers_1.IncomingEventType.Command) {
|
|
725
774
|
return body.enterprise_id;
|
|
726
775
|
}
|
|
727
|
-
if (type === helpers_1.IncomingEventType.Subscription) {
|
|
728
|
-
const bodyAsSubscriptionInteraction = body;
|
|
729
|
-
return bodyAsSubscriptionInteraction.team.enterprise_id;
|
|
730
|
-
}
|
|
731
776
|
if (type === helpers_1.IncomingEventType.Action ||
|
|
732
777
|
type === helpers_1.IncomingEventType.Options ||
|
|
733
778
|
type === helpers_1.IncomingEventType.ViewAction ||
|
|
@@ -767,10 +812,6 @@ function buildSource(type, channelId, body, isEnterpriseInstall) {
|
|
|
767
812
|
}
|
|
768
813
|
return undefined;
|
|
769
814
|
}
|
|
770
|
-
if (type === helpers_1.IncomingEventType.Subscription) {
|
|
771
|
-
const bodyAsSubscriptionInteraction = body;
|
|
772
|
-
return bodyAsSubscriptionInteraction.user.id;
|
|
773
|
-
}
|
|
774
815
|
if (type === helpers_1.IncomingEventType.Action ||
|
|
775
816
|
type === helpers_1.IncomingEventType.Options ||
|
|
776
817
|
type === helpers_1.IncomingEventType.ViewAction ||
|
|
@@ -799,18 +840,13 @@ function isBodyWithTypeEnterpriseInstall(body, type) {
|
|
|
799
840
|
return !!bodyAsEvent.authorizations[0].is_enterprise_install;
|
|
800
841
|
}
|
|
801
842
|
}
|
|
802
|
-
|
|
803
|
-
|
|
843
|
+
// command payloads have this property set as a string
|
|
844
|
+
if (typeof body.is_enterprise_install === 'string') {
|
|
845
|
+
return body.is_enterprise_install === 'true';
|
|
804
846
|
}
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
return body.is_enterprise_install === 'true';
|
|
809
|
-
}
|
|
810
|
-
// all remaining types have a boolean property
|
|
811
|
-
if (body.is_enterprise_install !== undefined) {
|
|
812
|
-
return body.is_enterprise_install;
|
|
813
|
-
}
|
|
847
|
+
// all remaining types have a boolean property
|
|
848
|
+
if (body.is_enterprise_install !== undefined) {
|
|
849
|
+
return body.is_enterprise_install;
|
|
814
850
|
}
|
|
815
851
|
// as a fallback we assume it's a single team installation (but this should never happen)
|
|
816
852
|
return false;
|
|
@@ -828,6 +864,12 @@ function buildRespondFn(axiosInstance, responseUrl) {
|
|
|
828
864
|
return axiosInstance.post(responseUrl, normalizedArgs);
|
|
829
865
|
};
|
|
830
866
|
}
|
|
867
|
+
// token revocation use cases
|
|
868
|
+
// https://github.com/slackapi/bolt-js/issues/674
|
|
869
|
+
const eventTypesToSkipAuthorize = ['app_uninstalled', 'tokens_revoked'];
|
|
870
|
+
function isEventTypeToSkipAuthorize(eventType) {
|
|
871
|
+
return eventTypesToSkipAuthorize.includes(eventType);
|
|
872
|
+
}
|
|
831
873
|
// ----------------------------
|
|
832
874
|
// Instrumentation
|
|
833
875
|
// Don't change the position of the following code
|