@slack/bolt 3.10.0 → 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/dist/errors.d.ts +1 -1
- package/dist/errors.d.ts.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/receivers/BufferedIncomingMessage.d.ts +6 -0
- package/dist/receivers/BufferedIncomingMessage.d.ts.map +1 -0
- package/dist/receivers/BufferedIncomingMessage.js +3 -0
- 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 +7 -0
- 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 +20 -2
- 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/package.json +8 -5
- package/CHANGELOG.md +0 -5
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
7
4
|
const url_1 = require("url");
|
|
@@ -9,15 +6,14 @@ const socket_mode_1 = require("@slack/socket-mode");
|
|
|
9
6
|
const http_1 = require("http");
|
|
10
7
|
const logger_1 = require("@slack/logger");
|
|
11
8
|
const oauth_1 = require("@slack/oauth");
|
|
12
|
-
const render_html_for_install_path_1 = __importDefault(require("./render-html-for-install-path"));
|
|
13
9
|
const custom_routes_1 = require("./custom-routes");
|
|
14
10
|
const verify_redirect_opts_1 = require("./verify-redirect-opts");
|
|
11
|
+
const SocketModeFunctions_1 = require("./SocketModeFunctions");
|
|
15
12
|
/**
|
|
16
13
|
* Receives Events, Slash Commands, and Actions of a web socket connection
|
|
17
14
|
*/
|
|
18
15
|
class SocketModeReceiver {
|
|
19
|
-
constructor({ appToken, logger = undefined, logLevel = logger_1.LogLevel.INFO, clientId = undefined, clientSecret = undefined, stateSecret = undefined, redirectUri = undefined, installationStore = undefined, scopes = undefined, installerOptions = {}, customRoutes = [], customPropertiesExtractor = (_args) => ({}), }) {
|
|
20
|
-
var _a;
|
|
16
|
+
constructor({ appToken, logger = undefined, logLevel = logger_1.LogLevel.INFO, clientId = undefined, clientSecret = undefined, stateSecret = undefined, redirectUri = undefined, installationStore = undefined, scopes = undefined, installerOptions = {}, customRoutes = [], customPropertiesExtractor = (_args) => ({}), processEventErrorHandler = SocketModeFunctions_1.SocketModeFunctions.defaultProcessEventErrorHandler, }) {
|
|
21
17
|
this.installer = undefined;
|
|
22
18
|
this.client = new socket_mode_1.SocketModeClient({
|
|
23
19
|
appToken,
|
|
@@ -30,7 +26,8 @@ class SocketModeReceiver {
|
|
|
30
26
|
defaultLogger.setLevel(logLevel);
|
|
31
27
|
return defaultLogger;
|
|
32
28
|
})();
|
|
33
|
-
this.routes = (0, custom_routes_1.
|
|
29
|
+
this.routes = (0, custom_routes_1.buildReceiverRoutes)(customRoutes);
|
|
30
|
+
this.processEventErrorHandler = processEventErrorHandler;
|
|
34
31
|
// Verify redirect options if supplied, throws coded error if invalid
|
|
35
32
|
(0, verify_redirect_opts_1.verifyRedirectOpts)({ redirectUri, redirectUriPath: installerOptions.redirectUriPath });
|
|
36
33
|
if (clientId !== undefined &&
|
|
@@ -46,20 +43,21 @@ class SocketModeReceiver {
|
|
|
46
43
|
installationStore,
|
|
47
44
|
logLevel,
|
|
48
45
|
logger,
|
|
46
|
+
directInstall: installerOptions.directInstall,
|
|
49
47
|
stateStore: installerOptions.stateStore,
|
|
50
48
|
stateVerification: installerOptions.stateVerification,
|
|
51
|
-
|
|
49
|
+
legacyStateVerification: installerOptions.legacyStateVerification,
|
|
50
|
+
stateCookieName: installerOptions.stateCookieName,
|
|
51
|
+
stateCookieExpirationSeconds: installerOptions.stateCookieExpirationSeconds,
|
|
52
|
+
renderHtmlForInstallPath: installerOptions.renderHtmlForInstallPath,
|
|
53
|
+
authVersion: installerOptions.authVersion,
|
|
52
54
|
clientOptions: installerOptions.clientOptions,
|
|
53
55
|
authorizationUrl: installerOptions.authorizationUrl,
|
|
54
56
|
});
|
|
55
57
|
}
|
|
56
58
|
// Add OAuth and/or custom routes to receiver
|
|
57
59
|
if (this.installer !== undefined || customRoutes.length) {
|
|
58
|
-
// use default or passed in redirect path
|
|
59
|
-
const redirectUriPath = installerOptions.redirectUriPath === undefined ? '/slack/oauth_redirect' : installerOptions.redirectUriPath;
|
|
60
|
-
// use default or passed in installPath
|
|
61
60
|
const installPath = installerOptions.installPath === undefined ? '/slack/install' : installerOptions.installPath;
|
|
62
|
-
const directInstallEnabled = installerOptions.directInstall !== undefined && installerOptions.directInstall;
|
|
63
61
|
this.httpServerPort = installerOptions.port === undefined ? 3000 : installerOptions.port;
|
|
64
62
|
this.httpServer = (0, http_1.createServer)(async (req, res) => {
|
|
65
63
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
@@ -74,43 +72,24 @@ class SocketModeReceiver {
|
|
|
74
72
|
redirectUri,
|
|
75
73
|
};
|
|
76
74
|
// Installation has been initiated
|
|
75
|
+
const redirectUriPath = installerOptions.redirectUriPath === undefined ? '/slack/oauth_redirect' : installerOptions.redirectUriPath;
|
|
77
76
|
if (req.url && req.url.startsWith(redirectUriPath)) {
|
|
78
77
|
const { stateVerification, callbackOptions } = installerOptions;
|
|
79
78
|
if (stateVerification === false) {
|
|
80
79
|
// if stateVerification is disabled make install options available to handler
|
|
81
80
|
// since they won't be encoded in the state param of the generated url
|
|
82
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
83
81
|
await this.installer.handleCallback(req, res, callbackOptions, installUrlOptions);
|
|
84
82
|
}
|
|
85
83
|
else {
|
|
86
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
87
84
|
await this.installer.handleCallback(req, res, callbackOptions);
|
|
88
85
|
}
|
|
89
86
|
return;
|
|
90
87
|
}
|
|
91
88
|
// Visiting the installation endpoint
|
|
92
89
|
if (req.url && req.url.startsWith(installPath)) {
|
|
93
|
-
const {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const url = await this.installer.generateInstallUrl(installUrlOptions, stateVerification);
|
|
97
|
-
if (directInstallEnabled) {
|
|
98
|
-
res.writeHead(302, { Location: url });
|
|
99
|
-
res.end('');
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
res.writeHead(200, {});
|
|
103
|
-
const renderHtml = renderHtmlForInstallPath !== undefined ?
|
|
104
|
-
renderHtmlForInstallPath :
|
|
105
|
-
render_html_for_install_path_1.default;
|
|
106
|
-
res.end(renderHtml(url));
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
catch (err) {
|
|
111
|
-
const e = err;
|
|
112
|
-
throw new Error(e);
|
|
113
|
-
}
|
|
90
|
+
const { installPathOptions } = installerOptions;
|
|
91
|
+
await this.installer.handleInstallPath(req, res, installPathOptions, installUrlOptions);
|
|
92
|
+
return;
|
|
114
93
|
}
|
|
115
94
|
}
|
|
116
95
|
// Handle request for custom routes
|
|
@@ -143,7 +122,19 @@ class SocketModeReceiver {
|
|
|
143
122
|
retryReason: retry_reason,
|
|
144
123
|
customProperties: customPropertiesExtractor(args),
|
|
145
124
|
};
|
|
146
|
-
|
|
125
|
+
try {
|
|
126
|
+
await ((_a = this.app) === null || _a === void 0 ? void 0 : _a.processEvent(event));
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
const shouldBeAcked = await this.processEventErrorHandler({
|
|
130
|
+
error: error,
|
|
131
|
+
logger: this.logger,
|
|
132
|
+
event,
|
|
133
|
+
});
|
|
134
|
+
if (shouldBeAcked) {
|
|
135
|
+
await ack();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
147
138
|
});
|
|
148
139
|
}
|
|
149
140
|
init(app) {
|
|
@@ -161,7 +152,8 @@ class SocketModeReceiver {
|
|
|
161
152
|
if (this.httpServer !== undefined) {
|
|
162
153
|
// This HTTP server is only for the OAuth flow support
|
|
163
154
|
this.httpServer.close((error) => {
|
|
164
|
-
|
|
155
|
+
if (error)
|
|
156
|
+
this.logger.error(`Failed to shutdown the HTTP server for OAuth flow: ${error}`);
|
|
165
157
|
});
|
|
166
158
|
}
|
|
167
159
|
return new Promise((resolve, reject) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SocketModeReceiver.js","sourceRoot":"","sources":["../../src/receivers/SocketModeReceiver.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SocketModeReceiver.js","sourceRoot":"","sources":["../../src/receivers/SocketModeReceiver.ts"],"names":[],"mappings":";;AAAA,uDAAuD;AACvD,6BAA0B;AAC1B,oDAAsD;AACtD,+BAA6E;AAC7E,0CAAgE;AAChE,wCAA+H;AAM/H,mDAAsE;AACtE,iEAA4D;AAC5D,+DAG+B;AA+C/B;;GAEG;AACH,MAAqB,kBAAkB;IAkBrC,YAAmB,EACjB,QAAQ,EACR,MAAM,GAAG,SAAS,EAClB,QAAQ,GAAG,iBAAQ,CAAC,IAAI,EACxB,QAAQ,GAAG,SAAS,EACpB,YAAY,GAAG,SAAS,EACxB,WAAW,GAAG,SAAS,EACvB,WAAW,GAAG,SAAS,EACvB,iBAAiB,GAAG,SAAS,EAC7B,MAAM,GAAG,SAAS,EAClB,gBAAgB,GAAG,EAAE,EACrB,YAAY,GAAG,EAAE,EACjB,yBAAyB,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAC3C,wBAAwB,GAAG,yCAAc,CAAC,+BAA+B,GAC/C;QAxBrB,cAAS,GAAgC,SAAS,CAAC;QAyBxD,IAAI,CAAC,MAAM,GAAG,IAAI,8BAAgB,CAAC;YACjC,QA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,cAAc,CAAC,CAAC;SAC7C;QACD,2BAA2B;QAC3B,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;IAEM,IAAI;QACT,IAAI,IAAI,CAAC,UAAU,KAAK,SAAS,EAAE;YACjC,sDAAsD;YACtD,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;gBAC9B,IAAI,KAAK;oBAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,sDAAsD,KAAK,EAAE,CAAC,CAAC;YAC9F,CAAC,CAAC,CAAC;SACJ;QACD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI;gBACF,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;gBACzB,OAAO,EAAE,CAAC;aACX;YAAC,OAAO,KAAK,EAAE;gBACd,MAAM,CAAC,KAAK,CAAC,CAAC;aACf;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAlMD,qCAkMC"}
|
|
@@ -10,5 +10,5 @@ export interface ReceiverRoutes {
|
|
|
10
10
|
[method: string]: (req: IncomingMessage, res: ServerResponse) => void;
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
|
-
export declare function
|
|
13
|
+
export declare function buildReceiverRoutes(customRoutes: CustomRoute[]): ReceiverRoutes;
|
|
14
14
|
//# sourceMappingURL=custom-routes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-routes.d.ts","sourceRoot":"","sources":["../../src/receivers/custom-routes.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAGvD,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC1B,OAAO,EAAE,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,cAAc,KAAK,IAAI,CAAC;CAC9D;AAED,MAAM,WAAW,cAAc;IAC7B,CAAC,GAAG,EAAE,MAAM,GAAG;QACb,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,cAAc,KAAK,IAAI,CAAC;KACvE,CAAC;CACH;AAED,wBAAgB,
|
|
1
|
+
{"version":3,"file":"custom-routes.d.ts","sourceRoot":"","sources":["../../src/receivers/custom-routes.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAGvD,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC1B,OAAO,EAAE,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,cAAc,KAAK,IAAI,CAAC;CAC9D;AAED,MAAM,WAAW,cAAc;IAC7B,CAAC,GAAG,EAAE,MAAM,GAAG;QACb,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,cAAc,KAAK,IAAI,CAAC;KACvE,CAAC;CACH;AAED,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,WAAW,EAAE,GAAG,cAAc,CAa/E"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.buildReceiverRoutes = void 0;
|
|
4
4
|
const errors_1 = require("../errors");
|
|
5
|
-
function
|
|
5
|
+
function buildReceiverRoutes(customRoutes) {
|
|
6
6
|
const routes = {};
|
|
7
7
|
validateCustomRoutes(customRoutes);
|
|
8
8
|
customRoutes.forEach((r) => {
|
|
@@ -13,7 +13,7 @@ function prepareRoutes(customRoutes) {
|
|
|
13
13
|
});
|
|
14
14
|
return routes;
|
|
15
15
|
}
|
|
16
|
-
exports.
|
|
16
|
+
exports.buildReceiverRoutes = buildReceiverRoutes;
|
|
17
17
|
function validateCustomRoutes(customRoutes) {
|
|
18
18
|
const requiredKeys = ['path', 'method', 'handler'];
|
|
19
19
|
const missingKeys = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-routes.js","sourceRoot":"","sources":["../../src/receivers/custom-routes.ts"],"names":[],"mappings":";;;AACA,sCAA2D;AAc3D,SAAgB,
|
|
1
|
+
{"version":3,"file":"custom-routes.js","sourceRoot":"","sources":["../../src/receivers/custom-routes.ts"],"names":[],"mappings":";;;AACA,sCAA2D;AAc3D,SAAgB,mBAAmB,CAAC,YAA2B;IAC7D,MAAM,MAAM,GAAmB,EAAE,CAAC;IAElC,oBAAoB,CAAC,YAAY,CAAC,CAAC;IAEnC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;QACzB,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;YACzC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;YAC7E,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;QAC1C,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,GAAG,SAAS,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IACpF,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC;AAbD,kDAaC;AAED,SAAS,oBAAoB,CAAC,YAA2B;IACvD,MAAM,YAAY,GAA0B,CAAC,MAAM,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;IAC1E,MAAM,WAAW,GAA0B,EAAE,CAAC;IAE9C,kCAAkC;IAClC,YAAY,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;QAC7B,YAAY,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YAC3B,IAAI,KAAK,CAAC,GAAG,CAAC,KAAK,SAAS,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;gBAC1D,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;aACvB;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE;QAC1B,MAAM,QAAQ,GAAG,iEAAiE,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3G,MAAM,IAAI,uCAA8B,CAAC,QAAQ,CAAC,CAAC;KACpD;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-utils.d.ts","sourceRoot":"","sources":["../../src/receivers/http-utils.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"http-utils.d.ts","sourceRoot":"","sources":["../../src/receivers/http-utils.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAMvC,wBAAgB,eAAe,CAAC,GAAG,EAAE,eAAe,GAAG,MAAM,GAAG,SAAS,CAGxE;AAGD,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,eAAe,GAAG,MAAM,GAAG,SAAS,CAG3E"}
|
|
@@ -1,35 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.extractRetryReason = exports.extractRetryNum = void 0;
|
|
4
|
+
const logger_1 = require("@slack/logger");
|
|
5
|
+
const HTTPModuleFunctions_1 = require("./HTTPModuleFunctions");
|
|
6
|
+
const logger = new logger_1.ConsoleLogger();
|
|
7
|
+
// Deprecated: this function will be removed in the near future
|
|
4
8
|
function extractRetryNum(req) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
if (retryNumHeaderValue === undefined) {
|
|
8
|
-
retryNum = undefined;
|
|
9
|
-
}
|
|
10
|
-
else if (typeof retryNumHeaderValue === 'string') {
|
|
11
|
-
retryNum = parseInt(retryNumHeaderValue, 10);
|
|
12
|
-
}
|
|
13
|
-
else if (Array.isArray(retryNumHeaderValue) && retryNumHeaderValue.length > 0) {
|
|
14
|
-
retryNum = parseInt(retryNumHeaderValue[0], 10);
|
|
15
|
-
}
|
|
16
|
-
return retryNum;
|
|
9
|
+
logger.warn('This method is deprecated. Use HTTPModuleFunctions.extractRetryNumFromHTTPRequest(req) instead.');
|
|
10
|
+
return HTTPModuleFunctions_1.HTTPModuleFunctions.extractRetryNumFromHTTPRequest(req);
|
|
17
11
|
}
|
|
18
12
|
exports.extractRetryNum = extractRetryNum;
|
|
13
|
+
// Deprecated: this function will be removed in the near future
|
|
19
14
|
function extractRetryReason(req) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (retryReasonHeaderValue === undefined) {
|
|
23
|
-
retryReason = undefined;
|
|
24
|
-
}
|
|
25
|
-
else if (typeof retryReasonHeaderValue === 'string') {
|
|
26
|
-
retryReason = retryReasonHeaderValue;
|
|
27
|
-
}
|
|
28
|
-
else if (Array.isArray(retryReasonHeaderValue) && retryReasonHeaderValue.length > 0) {
|
|
29
|
-
// eslint-disable-next-line prefer-destructuring
|
|
30
|
-
retryReason = retryReasonHeaderValue[0];
|
|
31
|
-
}
|
|
32
|
-
return retryReason;
|
|
15
|
+
logger.warn('This method is deprecated. Use HTTPModuleFunctions.extractRetryReasonFromHTTPRequest(req) instead.');
|
|
16
|
+
return HTTPModuleFunctions_1.HTTPModuleFunctions.extractRetryReasonFromHTTPRequest(req);
|
|
33
17
|
}
|
|
34
18
|
exports.extractRetryReason = extractRetryReason;
|
|
35
19
|
//# sourceMappingURL=http-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-utils.js","sourceRoot":"","sources":["../../src/receivers/http-utils.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"http-utils.js","sourceRoot":"","sources":["../../src/receivers/http-utils.ts"],"names":[],"mappings":";;;AAAA,0CAA8C;AAE9C,+DAA4D;AAE5D,MAAM,MAAM,GAAG,IAAI,sBAAa,EAAE,CAAC;AAEnC,+DAA+D;AAC/D,SAAgB,eAAe,CAAC,GAAoB;IAClD,MAAM,CAAC,IAAI,CAAC,iGAAiG,CAAC,CAAC;IAC/G,OAAO,yCAAmB,CAAC,8BAA8B,CAAC,GAAG,CAAC,CAAC;AACjE,CAAC;AAHD,0CAGC;AAED,+DAA+D;AAC/D,SAAgB,kBAAkB,CAAC,GAAoB;IACrD,MAAM,CAAC,IAAI,CAAC,oGAAoG,CAAC,CAAC;IAClH,OAAO,yCAAmB,CAAC,iCAAiC,CAAC,GAAG,CAAC,CAAC;AACpE,CAAC;AAHD,gDAGC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-html-for-install-path.d.ts","sourceRoot":"","sources":["../../src/receivers/render-html-for-install-path.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"render-html-for-install-path.d.ts","sourceRoot":"","sources":["../../src/receivers/render-html-for-install-path.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,OAAO,UAAU,+BAA+B,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAgBrF;AAID,wBAAgB,wBAAwB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAEtE"}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.renderHtmlForInstallPath = void 0;
|
|
4
|
+
const logger_1 = require("@slack/logger");
|
|
5
|
+
const logger = new logger_1.ConsoleLogger();
|
|
6
|
+
// Deprecated: this function will be removed in the near future
|
|
7
|
+
// Use the ones from @slack/oauth (v2.5 or newer) instead
|
|
4
8
|
function defaultRenderHtmlForInstallPath(addToSlackUrl) {
|
|
9
|
+
logger.warn('This method is deprecated. Use defaultRenderHtmlForInstallPath from @slack/oatuh instead.');
|
|
10
|
+
// TODO: replace the internals of this method with the one from @slack/oauth@2.5 or newer
|
|
5
11
|
return `<html>
|
|
6
12
|
<body>
|
|
7
13
|
<a href="${addToSlackUrl}">
|
|
@@ -17,6 +23,7 @@ function defaultRenderHtmlForInstallPath(addToSlackUrl) {
|
|
|
17
23
|
</html>`;
|
|
18
24
|
}
|
|
19
25
|
exports.default = defaultRenderHtmlForInstallPath;
|
|
26
|
+
// Deprecated: this function will be removed in the near future
|
|
20
27
|
// For backward-compatibility
|
|
21
28
|
function renderHtmlForInstallPath(addToSlackUrl) {
|
|
22
29
|
return defaultRenderHtmlForInstallPath(addToSlackUrl);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-html-for-install-path.js","sourceRoot":"","sources":["../../src/receivers/render-html-for-install-path.ts"],"names":[],"mappings":";;;AAAA,SAAwB,+BAA+B,CAAC,aAAqB;IAC3E,OAAO;;mBAEU,aAAa;;;;;;;;;;YAUpB,CAAC;AACb,CAAC;
|
|
1
|
+
{"version":3,"file":"render-html-for-install-path.js","sourceRoot":"","sources":["../../src/receivers/render-html-for-install-path.ts"],"names":[],"mappings":";;;AAAA,0CAA8C;AAE9C,MAAM,MAAM,GAAG,IAAI,sBAAa,EAAE,CAAC;AAEnC,+DAA+D;AAC/D,yDAAyD;AACzD,SAAwB,+BAA+B,CAAC,aAAqB;IAC3E,MAAM,CAAC,IAAI,CAAC,2FAA2F,CAAC,CAAC;IACzG,yFAAyF;IACzF,OAAO;;mBAEU,aAAa;;;;;;;;;;YAUpB,CAAC;AACb,CAAC;AAhBD,kDAgBC;AAED,+DAA+D;AAC/D,6BAA6B;AAC7B,SAAgB,wBAAwB,CAAC,aAAqB;IAC5D,OAAO,+BAA+B,CAAC,aAAa,CAAC,CAAC;AACxD,CAAC;AAFD,4DAEC"}
|
|
@@ -1,41 +1,33 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Functions used to verify the authenticity of incoming HTTP requests from Slack.
|
|
3
|
-
*
|
|
4
|
-
* The functions in this file are intentionally generic (don't depend on any particular web framework) and
|
|
5
|
-
* time-independent (for testing) so they can be used in a wide variety of applications. The intention is to distribute
|
|
6
|
-
* these functions in its own package.
|
|
7
|
-
*
|
|
8
|
-
* For now, there is some duplication between the contents of this file and ExpressReceiver.ts. Later, the duplication
|
|
9
|
-
* can be reduced by implementing the equivalent functionality in terms of the functions in this file.
|
|
10
|
-
*/
|
|
11
1
|
/// <reference types="node" />
|
|
12
|
-
import
|
|
2
|
+
import { Logger } from '@slack/logger';
|
|
13
3
|
import type { IncomingMessage, ServerResponse } from 'http';
|
|
14
|
-
|
|
15
|
-
|
|
4
|
+
import { BufferedIncomingMessage } from './BufferedIncomingMessage';
|
|
5
|
+
import { RequestVerificationOptions } from './HTTPModuleFunctions';
|
|
6
|
+
export interface SlackRequestVerificationOptions {
|
|
16
7
|
signingSecret: string;
|
|
17
|
-
|
|
8
|
+
body: string;
|
|
9
|
+
headers: {
|
|
10
|
+
'x-slack-signature': string;
|
|
11
|
+
'x-slack-request-timestamp': number;
|
|
12
|
+
};
|
|
13
|
+
nowMilliseconds?: number;
|
|
18
14
|
logger?: Logger;
|
|
19
15
|
}
|
|
20
|
-
export interface BufferedIncomingMessage extends IncomingMessage {
|
|
21
|
-
rawBody: Buffer;
|
|
22
|
-
}
|
|
23
16
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* Verification requires consuming `req` as a Readable stream. If the `req` was consumed before this function is called,
|
|
32
|
-
* then this function expects it to be stored as a Buffer at `req.rawBody`. This is a convention used by infrastructure
|
|
33
|
-
* platforms such as Google Cloud Platform. When the function returns, the buffered body is stored at the `req.rawBody`
|
|
34
|
-
* property for further handling.
|
|
35
|
-
*
|
|
36
|
-
* The function is designed to be curry-able for use as a standard http RequestListener, and therefore keeps `req` and
|
|
37
|
-
* `res` are the last arguments. However, the function is also async, which means when it is curried for use as a
|
|
38
|
-
* RequestListener, the caller should also capture and use the return value.
|
|
17
|
+
* Verifies the signature of an incoming request from Slack.
|
|
18
|
+
* If the requst is invalid, this method throws an exception with the erorr details.
|
|
19
|
+
*/
|
|
20
|
+
export declare function verifySlackRequest(options: SlackRequestVerificationOptions): void;
|
|
21
|
+
/**
|
|
22
|
+
* Verifies the signature of an incoming request from Slack.
|
|
23
|
+
* If the requst is invalid, this method returns false.
|
|
39
24
|
*/
|
|
40
|
-
export declare function
|
|
25
|
+
export declare function isValidSlackRequest(options: SlackRequestVerificationOptions): boolean;
|
|
26
|
+
export interface VerifyOptions extends RequestVerificationOptions {
|
|
27
|
+
enabled?: boolean;
|
|
28
|
+
signingSecret: string;
|
|
29
|
+
nowMs?: () => number;
|
|
30
|
+
logger?: Logger;
|
|
31
|
+
}
|
|
32
|
+
export declare function verify(options: VerifyOptions, req: IncomingMessage, res?: ServerResponse): Promise<BufferedIncomingMessage>;
|
|
41
33
|
//# sourceMappingURL=verify-request.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify-request.d.ts","sourceRoot":"","sources":["../../src/receivers/verify-request.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"verify-request.d.ts","sourceRoot":"","sources":["../../src/receivers/verify-request.ts"],"names":[],"mappings":";AACA,OAAO,EAAiB,MAAM,EAAE,MAAM,eAAe,CAAC;AAGtD,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAC5D,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAuB,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAQxF,MAAM,WAAW,+BAA+B;IAC9C,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE;QACP,mBAAmB,EAAE,MAAM,CAAC;QAC5B,2BAA2B,EAAE,MAAM,CAAC;KACrC,CAAC;IACF,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,+BAA+B,GAAG,IAAI,CAkCjF;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,+BAA+B,GAAG,OAAO,CAUrF;AASD,MAAM,WAAW,aAAc,SAAQ,0BAA0B;IAC/D,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAGD,wBAAsB,MAAM,CAC1B,OAAO,EAAE,aAAa,EACtB,GAAG,EAAE,eAAe,EACpB,GAAG,CAAC,EAAE,cAAc,GACnB,OAAO,CAAC,uBAAuB,CAAC,CAGlC"}
|
|
@@ -1,58 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Functions used to verify the authenticity of incoming HTTP requests from Slack.
|
|
4
|
-
*
|
|
5
|
-
* The functions in this file are intentionally generic (don't depend on any particular web framework) and
|
|
6
|
-
* time-independent (for testing) so they can be used in a wide variety of applications. The intention is to distribute
|
|
7
|
-
* these functions in its own package.
|
|
8
|
-
*
|
|
9
|
-
* For now, there is some duplication between the contents of this file and ExpressReceiver.ts. Later, the duplication
|
|
10
|
-
* can be reduced by implementing the equivalent functionality in terms of the functions in this file.
|
|
11
|
-
*/
|
|
12
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
4
|
};
|
|
15
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.verify = void 0;
|
|
6
|
+
exports.verify = exports.isValidSlackRequest = exports.verifySlackRequest = void 0;
|
|
7
|
+
// Deprecated: this function will be removed in the near future. Use HTTPModuleFunctions instead.
|
|
8
|
+
const logger_1 = require("@slack/logger");
|
|
17
9
|
const crypto_1 = require("crypto");
|
|
18
|
-
const raw_body_1 = __importDefault(require("raw-body"));
|
|
19
10
|
const tsscmp_1 = __importDefault(require("tsscmp"));
|
|
11
|
+
const HTTPModuleFunctions_1 = require("./HTTPModuleFunctions");
|
|
12
|
+
// ------------------------------
|
|
13
|
+
// HTTP module independent methods
|
|
14
|
+
// ------------------------------
|
|
20
15
|
const verifyErrorPrefix = 'Failed to verify authenticity';
|
|
21
16
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* When verification succeeds, the returned promise is resolved. When verification fails, the returned promise is
|
|
25
|
-
* rejected with an error describing the reason. IMPORTANT: The error messages may contain sensitive information about
|
|
26
|
-
* failures, do not return the error message text to users in a production environment. It's recommended to catch all
|
|
27
|
-
* errors and return an opaque failure (HTTP status code 401, no body).
|
|
28
|
-
*
|
|
29
|
-
* Verification requires consuming `req` as a Readable stream. If the `req` was consumed before this function is called,
|
|
30
|
-
* then this function expects it to be stored as a Buffer at `req.rawBody`. This is a convention used by infrastructure
|
|
31
|
-
* platforms such as Google Cloud Platform. When the function returns, the buffered body is stored at the `req.rawBody`
|
|
32
|
-
* property for further handling.
|
|
33
|
-
*
|
|
34
|
-
* The function is designed to be curry-able for use as a standard http RequestListener, and therefore keeps `req` and
|
|
35
|
-
* `res` are the last arguments. However, the function is also async, which means when it is curried for use as a
|
|
36
|
-
* RequestListener, the caller should also capture and use the return value.
|
|
17
|
+
* Verifies the signature of an incoming request from Slack.
|
|
18
|
+
* If the requst is invalid, this method throws an exception with the erorr details.
|
|
37
19
|
*/
|
|
38
|
-
|
|
20
|
+
function verifySlackRequest(options) {
|
|
39
21
|
var _a;
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
const bufferedReq = await bufferIncomingMessage(req);
|
|
43
|
-
if (options.enabled !== undefined && !options.enabled) {
|
|
44
|
-
// As the validation is disabled, immediately return the bufferred reuest
|
|
45
|
-
return bufferedReq;
|
|
46
|
-
}
|
|
47
|
-
// Find the relevant request headers
|
|
48
|
-
const signature = getHeader(req, 'x-slack-signature');
|
|
49
|
-
const requestTimestampSec = Number(getHeader(req, 'x-slack-request-timestamp'));
|
|
22
|
+
const requestTimestampSec = options.headers['x-slack-request-timestamp'];
|
|
23
|
+
const signature = options.headers['x-slack-signature'];
|
|
50
24
|
if (Number.isNaN(requestTimestampSec)) {
|
|
51
25
|
throw new Error(`${verifyErrorPrefix}: header x-slack-request-timestamp did not have the expected type (${requestTimestampSec})`);
|
|
52
26
|
}
|
|
53
27
|
// Calculate time-dependent values
|
|
54
|
-
const
|
|
55
|
-
const nowMs = nowMsFn();
|
|
28
|
+
const nowMs = (_a = options.nowMilliseconds) !== null && _a !== void 0 ? _a : Date.now();
|
|
56
29
|
const fiveMinutesAgoSec = Math.floor(nowMs / 1000) - 60 * 5;
|
|
57
30
|
// Enforce verification rules
|
|
58
31
|
// Rule 1: Check staleness
|
|
@@ -67,32 +40,39 @@ async function verify(options, req, _res) {
|
|
|
67
40
|
throw new Error(`${verifyErrorPrefix}: unknown signature version`);
|
|
68
41
|
}
|
|
69
42
|
// Compute our own signature hash
|
|
70
|
-
const hmac = (0, crypto_1.createHmac)('sha256', signingSecret);
|
|
71
|
-
hmac.update(`${signatureVersion}:${requestTimestampSec}:${
|
|
43
|
+
const hmac = (0, crypto_1.createHmac)('sha256', options.signingSecret);
|
|
44
|
+
hmac.update(`${signatureVersion}:${requestTimestampSec}:${options.body}`);
|
|
72
45
|
const ourSignatureHash = hmac.digest('hex');
|
|
73
|
-
if (!(0, tsscmp_1.default)(signatureHash, ourSignatureHash)) {
|
|
46
|
+
if (!signatureHash || !(0, tsscmp_1.default)(signatureHash, ourSignatureHash)) {
|
|
74
47
|
throw new Error(`${verifyErrorPrefix}: signature mismatch`);
|
|
75
48
|
}
|
|
76
|
-
// Checks have passed! Return the value that has a side effect (the buffered request)
|
|
77
|
-
return bufferedReq;
|
|
78
49
|
}
|
|
79
|
-
exports.
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
50
|
+
exports.verifySlackRequest = verifySlackRequest;
|
|
51
|
+
/**
|
|
52
|
+
* Verifies the signature of an incoming request from Slack.
|
|
53
|
+
* If the requst is invalid, this method returns false.
|
|
54
|
+
*/
|
|
55
|
+
function isValidSlackRequest(options) {
|
|
56
|
+
try {
|
|
57
|
+
verifySlackRequest(options);
|
|
58
|
+
return true;
|
|
83
59
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
function isBufferedIncomingMessage(req) {
|
|
89
|
-
return Buffer.isBuffer(req.rawBody);
|
|
90
|
-
}
|
|
91
|
-
function getHeader(req, header) {
|
|
92
|
-
const value = req.headers[header];
|
|
93
|
-
if (value === undefined || Array.isArray(value)) {
|
|
94
|
-
throw new Error(`${verifyErrorPrefix}: header ${header} did not have the expected type (${value})`);
|
|
60
|
+
catch (e) {
|
|
61
|
+
if (options.logger) {
|
|
62
|
+
options.logger.debug(`Signature verification error: ${e}`);
|
|
63
|
+
}
|
|
95
64
|
}
|
|
96
|
-
return
|
|
65
|
+
return false;
|
|
97
66
|
}
|
|
67
|
+
exports.isValidSlackRequest = isValidSlackRequest;
|
|
68
|
+
// ------------------------------
|
|
69
|
+
// legacy methods (depreacted)
|
|
70
|
+
// ------------------------------
|
|
71
|
+
const consoleLogger = new logger_1.ConsoleLogger();
|
|
72
|
+
// Deprecated: this function will be removed in the near future. Use HTTPModuleFunctions instead.
|
|
73
|
+
async function verify(options, req, res) {
|
|
74
|
+
consoleLogger.warn('This method is deprecated. Use HTTPModuleFunctions.parseAndVerifyHTTPRequest(options, req, res) instead.');
|
|
75
|
+
return HTTPModuleFunctions_1.HTTPModuleFunctions.parseAndVerifyHTTPRequest(options, req, res);
|
|
76
|
+
}
|
|
77
|
+
exports.verify = verify;
|
|
98
78
|
//# sourceMappingURL=verify-request.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify-request.js","sourceRoot":"","sources":["../../src/receivers/verify-request.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"verify-request.js","sourceRoot":"","sources":["../../src/receivers/verify-request.ts"],"names":[],"mappings":";;;;;;AAAA,iGAAiG;AACjG,0CAAsD;AACtD,mCAAoC;AACpC,oDAA4B;AAG5B,+DAAwF;AAExF,iCAAiC;AACjC,kCAAkC;AAClC,iCAAiC;AAEjC,MAAM,iBAAiB,GAAG,+BAA+B,CAAC;AAa1D;;;GAGG;AACH,SAAgB,kBAAkB,CAAC,OAAwC;;IACzE,MAAM,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC,2BAA2B,CAAC,CAAC;IACzE,MAAM,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACvD,IAAI,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,EAAE;QACrC,MAAM,IAAI,KAAK,CACb,GAAG,iBAAiB,sEAAsE,mBAAmB,GAAG,CACjH,CAAC;KACH;IAED,kCAAkC;IAClC,MAAM,KAAK,GAAG,MAAA,OAAO,CAAC,eAAe,mCAAI,IAAI,CAAC,GAAG,EAAE,CAAC;IACpD,MAAM,iBAAiB,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAE5D,6BAA6B;IAE7B,0BAA0B;IAC1B,IAAI,mBAAmB,GAAG,iBAAiB,EAAE;QAC3C,MAAM,IAAI,KAAK,CAAC,GAAG,iBAAiB,SAAS,CAAC,CAAC;KACh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,CAAC,0GAA0G,CAAC,CAAC;IAC/H,OAAO,yCAAmB,CAAC,yBAAyB,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAC1E,CAAC;AAPD,wBAOC"}
|
|
@@ -6,7 +6,7 @@ import { MessageEvent as AllMessageEvents } from './message-events';
|
|
|
6
6
|
*
|
|
7
7
|
* This is a discriminated union. The discriminant is the `type` property.
|
|
8
8
|
*/
|
|
9
|
-
export declare type SlackEvent = AppRequestedEvent | AppHomeOpenedEvent | AppMentionEvent | AppUninstalledEvent | CallRejectedEvent | ChannelArchiveEvent | ChannelCreatedEvent | ChannelDeletedEvent | ChannelHistoryChangedEvent | ChannelIDChangedEvent | ChannelLeftEvent | ChannelRenameEvent | ChannelSharedEvent | ChannelUnarchiveEvent | ChannelUnsharedEvent | DNDUpdatedEvent | DNDUpdatedUserEvent | EmailDomainChangedEvent | EmojiChangedEvent | FileChangeEvent | FileCommentDeletedEvent | FileCreatedEvent | FileDeletedEvent | FilePublicEvent | FileSharedEvent | FileUnsharedEvent | GridMigrationFinishedEvent | GridMigrationStartedEvent | GroupArchiveEvent | GroupCloseEvent | GroupDeletedEvent | GroupHistoryChangedEvent | GroupLeftEvent | GroupOpenEvent | GroupRenameEvent | GroupUnarchiveEvent | IMCloseEvent | IMCreatedEvent | IMHistoryChangedEvent | IMOpenEvent | InviteRequestedEvent | LinkSharedEvent | MemberJoinedChannelEvent | MemberLeftChannelEvent | MessageEvent | PinAddedEvent | PinRemovedEvent | ReactionAddedEvent | ReactionRemovedEvent | SharedChannelInviteReceived | SharedChannelInviteAccepted | SharedChannelInviteApproved | SharedChannelInviteDeclined | StarAddedEvent | StarRemovedEvent | SubteamCreated | SubteamMembersChanged | SubteamSelfAddedEvent | SubteamSelfRemovedEvent | SubteamUpdatedEvent | TeamDomainChangedEvent | TeamJoinEvent | TeamRenameEvent | TokensRevokedEvent | UserChangeEvent | WorkflowDeletedEvent | WorkflowPublishedEvent | WorkflowUnpublishedEvent | WorkflowStepDeletedEvent | WorkflowStepExecuteEvent;
|
|
9
|
+
export declare type SlackEvent = AppRequestedEvent | AppHomeOpenedEvent | AppMentionEvent | AppRateLimitedEvent | AppUninstalledEvent | CallRejectedEvent | ChannelArchiveEvent | ChannelCreatedEvent | ChannelDeletedEvent | ChannelHistoryChangedEvent | ChannelIDChangedEvent | ChannelLeftEvent | ChannelRenameEvent | ChannelSharedEvent | ChannelUnarchiveEvent | ChannelUnsharedEvent | DNDUpdatedEvent | DNDUpdatedUserEvent | EmailDomainChangedEvent | EmojiChangedEvent | FileChangeEvent | FileCommentDeletedEvent | FileCreatedEvent | FileDeletedEvent | FilePublicEvent | FileSharedEvent | FileUnsharedEvent | GridMigrationFinishedEvent | GridMigrationStartedEvent | GroupArchiveEvent | GroupCloseEvent | GroupDeletedEvent | GroupHistoryChangedEvent | GroupLeftEvent | GroupOpenEvent | GroupRenameEvent | GroupUnarchiveEvent | IMCloseEvent | IMCreatedEvent | IMHistoryChangedEvent | IMOpenEvent | InviteRequestedEvent | LinkSharedEvent | MemberJoinedChannelEvent | MemberLeftChannelEvent | MessageEvent | PinAddedEvent | PinRemovedEvent | ReactionAddedEvent | ReactionRemovedEvent | SharedChannelInviteReceived | SharedChannelInviteAccepted | SharedChannelInviteApproved | SharedChannelInviteDeclined | StarAddedEvent | StarRemovedEvent | SubteamCreated | SubteamMembersChanged | SubteamSelfAddedEvent | SubteamSelfRemovedEvent | SubteamUpdatedEvent | TeamAccessGrantedEvent | TeamAccessRevokedEvent | TeamDomainChangedEvent | TeamJoinEvent | TeamRenameEvent | TokensRevokedEvent | UserChangeEvent | WorkflowDeletedEvent | WorkflowPublishedEvent | WorkflowUnpublishedEvent | WorkflowStepDeletedEvent | WorkflowStepExecuteEvent;
|
|
10
10
|
export declare type EventTypePattern = string | RegExp;
|
|
11
11
|
/**
|
|
12
12
|
* Any event in Slack's Events API
|
|
@@ -102,6 +102,7 @@ export interface AppMentionEvent {
|
|
|
102
102
|
bot_id?: string;
|
|
103
103
|
bot_profile?: BotProfile;
|
|
104
104
|
username: string;
|
|
105
|
+
team?: string;
|
|
105
106
|
user?: string;
|
|
106
107
|
text: string;
|
|
107
108
|
attachments?: MessageAttachment[];
|
|
@@ -113,7 +114,14 @@ export interface AppMentionEvent {
|
|
|
113
114
|
ts: string;
|
|
114
115
|
channel: string;
|
|
115
116
|
event_ts: string;
|
|
116
|
-
thread_ts
|
|
117
|
+
thread_ts?: string;
|
|
118
|
+
}
|
|
119
|
+
export interface AppRateLimitedEvent {
|
|
120
|
+
type: 'app_rate_limited';
|
|
121
|
+
token: string;
|
|
122
|
+
team_id: string;
|
|
123
|
+
minute_rate_limited: number;
|
|
124
|
+
api_app_id: string;
|
|
117
125
|
}
|
|
118
126
|
export interface AppUninstalledEvent {
|
|
119
127
|
type: 'app_uninstalled';
|
|
@@ -638,6 +646,16 @@ export interface SubteamUpdatedEvent {
|
|
|
638
646
|
subteam: Subteam;
|
|
639
647
|
event_ts: string;
|
|
640
648
|
}
|
|
649
|
+
export interface TeamAccessGrantedEvent {
|
|
650
|
+
type: 'team_access_granted';
|
|
651
|
+
team_ids: string[];
|
|
652
|
+
event_ts: string;
|
|
653
|
+
}
|
|
654
|
+
export interface TeamAccessRevokedEvent {
|
|
655
|
+
type: 'team_access_revoked';
|
|
656
|
+
team_ids: string[];
|
|
657
|
+
event_ts: string;
|
|
658
|
+
}
|
|
641
659
|
export interface TeamDomainChangedEvent {
|
|
642
660
|
type: 'team_domain_changed';
|
|
643
661
|
url: string;
|