@vercel/slack-bolt 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Vercel, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,139 @@
1
+ # @vercel/slack-bolt
2
+
3
+ A custom [Slack Bolt](https://slack.dev/bolt-js/) receiver built for Vercel's [Fluid Compute](https://vercel.com/docs/fluid-compute).
4
+
5
+ - **Vercel Fluid Compute** Fully compabatible with Vercel Fluid Compute and [Active CPU Pricing](https://vercel.com/changelog/lower-pricing-with-active-cpu-pricing-for-fluid-compute)
6
+ - **Easy integration:** Use with your existing Bolt app code
7
+ - **Customizable:** Supports custom response handlers and property extraction
8
+ - **TypeScript ready:** Fully typed for modern development
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ pnpm add @vercel/slack-bolt
14
+ ```
15
+
16
+ ## Quick Start
17
+
18
+ ### 1. Environment Setup
19
+
20
+ Add your `SLACK_SIGNING_SECRET` and `SLACK_BOT_TOKEN` to your environment variables:
21
+
22
+ ```bash
23
+ SLACK_SIGNING_SECRET=your_slack_signing_secret_here
24
+ SLACK_BOT_TOKEN=your_slack_bot_token
25
+ ```
26
+
27
+ ### 2. Add the Vercel Receiver to your Bolt app
28
+
29
+ ```typescript
30
+ // app.ts
31
+
32
+ import { App } from "@slack/bolt";
33
+ import { VercelReceiver } from "@vercel/slack-bolt";
34
+
35
+ const receiver = new VercelReceiver();
36
+
37
+ const app = new App({
38
+ token: process.env.SLACK_BOT_TOKEN,
39
+ signingSecret: process.env.SLACK_SIGNING_SECRET,
40
+ receiver,
41
+ deferInitialization: true,
42
+ });
43
+
44
+ app.message(/^(hi|hello|hey).*/, async ({ say }) => {
45
+ await say("Hello, world!");
46
+ });
47
+
48
+ export { app, receiver };
49
+ ```
50
+
51
+ ### 3. Create an API folder and events.ts route
52
+
53
+ Your project structure should look like this:
54
+
55
+ ```
56
+ root/
57
+ ├── api/
58
+ │ └── events.ts # Vercel API endpoint to handle requests
59
+ ├── app.ts # Bolt app
60
+ ├── package.json
61
+ └── .env # Environment variables
62
+ ```
63
+
64
+ ### 4. Create a POST request handler using `createHandler` from `@vercel/slack-bolt`
65
+
66
+ ```typescript
67
+ // api/events.ts
68
+
69
+ import { createHandler } from "@vercel/slack-bolt";
70
+ import { app, receiver } from "../app";
71
+
72
+ const handler = createHandler(app, receiver);
73
+
74
+ export const POST = async (req: Request) => {
75
+ return handler(req);
76
+ };
77
+ ```
78
+
79
+ > **Note:**
80
+ > The `handler` returned by `createHandler` works with standard `WebRequest` objects.
81
+ > You can use it directly in your Vercel API routes or with any framework that provides compatible request objects.
82
+
83
+ ### 5. Update your Slack App Manifest
84
+
85
+ - Disable socket mode on your app
86
+ - Update your `request_url` to match your Vercel deployment
87
+ - If using features such as `commands`, `shortcuts`, and `interactivity` you must update their `urls` as well.
88
+
89
+ See the [example](./manifest.example.json) for reference.
90
+
91
+ ## Local Development
92
+
93
+ This package is compatible with the Slack CLI and can be used with the `slack run` command.
94
+
95
+ ### 1. Update the `start` command in your `./slack/hooks.json` file
96
+
97
+ ```json
98
+ // ./slack/hooks.json
99
+ {
100
+ "hooks": {
101
+ "get-hooks": "npx -q --no-install -p @slack/cli-hooks slack-cli-get-hooks",
102
+ "start": "vc dev"
103
+ }
104
+ }
105
+ ```
106
+
107
+ ### 2. If you'd like to use your local `manifest.json`, update your `config.json` file. (optional)
108
+
109
+ ```json
110
+ {
111
+ // ./slack/config.json
112
+ "manifest": {
113
+ "source": "local" // remote pulls the manifest from your Slack's remote manifest
114
+ },
115
+ "project_id": "<your-project-id>"
116
+ }
117
+ ```
118
+
119
+ ### 3. Expose your local server with `ngrok` or a similar tunneling tool
120
+
121
+ ```bash
122
+ ngrok http 3000
123
+ ```
124
+
125
+ ### 4. Update your app manifest to use your tunnel URL
126
+
127
+ Example: https://slack-agent.ngrok.dev/api/events
128
+
129
+ ## Contributing
130
+
131
+ Contributions are welcome! Please feel free to submit a Pull Request.
132
+
133
+ ## Support
134
+
135
+ For issues and questions:
136
+
137
+ - Check the [Slack Bolt documentation](https://slack.dev/bolt-js/)
138
+ - Review [Vercel Functions documentation](https://vercel.com/docs/functions)
139
+ - Open an issue in this repository
@@ -0,0 +1,156 @@
1
+ import { StringIndexed, ReceiverEvent, Receiver, App } from '@slack/bolt';
2
+ import { Logger, LogLevel } from '@slack/logger';
3
+
4
+ /**
5
+ * A function to handle the request from the Slack app.
6
+ * @param req - The request from the Slack app.
7
+ * @returns A response object.
8
+ */
9
+ type VercelHandler = (req: Request) => Promise<Response>;
10
+ /**
11
+ * Configuration options for the VercelReceiver.
12
+ * @property signingSecret - The signing secret for the Slack app.
13
+ * @property signatureVerification - If true, verifies the Slack request signature.
14
+ * @property logger - The logger to use for the VercelReceiver.
15
+ * @property logLevel - The log level to use for the VercelReceiver.
16
+ * @property customPropertiesExtractor - A function to extract custom properties from the request.
17
+ * @property customResponseHandler - A function to handle the response from the Slack app.
18
+ */
19
+ interface VercelReceiverOptions {
20
+ /**
21
+ * The signing secret for the Slack app.
22
+ * @default process.env.SLACK_SIGNING_SECRET
23
+ */
24
+ signingSecret?: string;
25
+ /**
26
+ * If true, verifies the Slack request signature.
27
+ * @default true
28
+ */
29
+ signatureVerification?: boolean;
30
+ /**
31
+ * The logger to use for the VercelReceiver.
32
+ * @default new ConsoleLogger()
33
+ */
34
+ logger?: Logger;
35
+ /**
36
+ * The log level to use for the VercelReceiver.
37
+ * @default LogLevel.INFO
38
+ */
39
+ logLevel?: LogLevel;
40
+ /**
41
+ * A function to extract custom properties from incoming events.
42
+ * @default undefined
43
+ * @returns An object with custom properties.
44
+ */
45
+ customPropertiesExtractor?: (req: Request) => StringIndexed;
46
+ /**
47
+ * A function to handle the response from the Slack app.
48
+ * @default undefined
49
+ * @returns A response object.
50
+ */
51
+ customResponseHandler?: (event: ReceiverEvent) => Promise<Response>;
52
+ }
53
+ /**
54
+ * A Slack Bolt receiver implementation designed for Vercel's serverless environment.
55
+ * Handles Slack events, interactions, and slash commands with automatic request verification,
56
+ * background processing, and timeout management.
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * import { App } from '@slack/bolt';
61
+ * import { VercelReceiver, createHandler } from '@vercel/slack-bolt';
62
+ *
63
+ * const receiver = new VercelReceiver();
64
+ *
65
+ * const app = new App({
66
+ * receiver,
67
+ * token: process.env.SLACK_BOT_TOKEN,
68
+ * signingSecret: process.env.SLACK_SIGNING_SECRET,
69
+ * });
70
+ * ```
71
+ *
72
+ */
73
+ declare class VercelReceiver implements Receiver {
74
+ private readonly signingSecret;
75
+ private readonly signatureVerification;
76
+ private readonly logger;
77
+ private readonly customPropertiesExtractor?;
78
+ private readonly customResponseHandler?;
79
+ private app?;
80
+ /**
81
+ * Gets the logger instance used by this receiver.
82
+ * @returns The logger instance
83
+ */
84
+ getLogger(): Logger;
85
+ /**
86
+ * Creates a new VercelReceiver instance.
87
+ *
88
+ * @param options - Configuration options for the receiver
89
+ * @throws {VercelReceiverError} When signing secret is not provided
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * const receiver = new VercelReceiver();
94
+ * ```
95
+ */
96
+ constructor({ signingSecret, signatureVerification, logger, logLevel, customPropertiesExtractor, customResponseHandler, }?: VercelReceiverOptions);
97
+ /**
98
+ * Initializes the receiver with a Slack Bolt app instance.
99
+ * This method is called automatically by the Bolt framework.
100
+ *
101
+ * @param app - The Slack Bolt app instance
102
+ */
103
+ init(app: App): void;
104
+ /**
105
+ * Starts the receiver and returns a handler function for processing requests.
106
+ * This method is called automatically by the Bolt framework.
107
+ *
108
+ * @returns A handler function that processes incoming Slack requests
109
+ */
110
+ start(): Promise<VercelHandler>;
111
+ /**
112
+ * Stops the receiver. This method is called automatically by the Bolt framework.
113
+ */
114
+ stop(): Promise<void>;
115
+ /**
116
+ * Creates a handler function that processes incoming Slack requests.
117
+ * This is the main entry point for handling Slack events in Vercel.
118
+ * It is called automatically by the Bolt framework in the start() method.
119
+ *
120
+ * @returns A handler function compatible with Vercel's function signature
121
+ */
122
+ toHandler(): VercelHandler;
123
+ private parseRequestBody;
124
+ private handleSlackEvent;
125
+ private verifySlackRequest;
126
+ private createSlackReceiverEvent;
127
+ private handleError;
128
+ private createScopedLogger;
129
+ }
130
+ /**
131
+ * Creates a Vercel-compatible handler function for a Slack Bolt app.
132
+ * This is the recommended way to create handlers for deployment on Vercel.
133
+ *
134
+ * @param {App} app - The initialized Slack Bolt app instance.
135
+ * @param {VercelReceiver} receiver - The VercelReceiver instance.
136
+ * @returns {VercelHandler} A handler function compatible with Vercel's function signature.
137
+ *
138
+ * @example
139
+ * ```typescript
140
+ * // api/events.ts
141
+ * import { createHandler } from '@vercel/slack-bolt';
142
+ * import { app, receiver } from '../app';
143
+ *
144
+ * const handler = createHandler(app, receiver);
145
+ *
146
+ * export const POST = async (req: Request) => {
147
+ * return handler(req);
148
+ * };
149
+ * ```
150
+ *
151
+ * @throws {Error} If app initialization fails.
152
+ * @throws {VercelReceiverError} If request processing fails.
153
+ */
154
+ declare function createHandler(app: App, receiver: VercelReceiver): VercelHandler;
155
+
156
+ export { type VercelHandler, VercelReceiver, type VercelReceiverOptions, createHandler };
@@ -0,0 +1,156 @@
1
+ import { StringIndexed, ReceiverEvent, Receiver, App } from '@slack/bolt';
2
+ import { Logger, LogLevel } from '@slack/logger';
3
+
4
+ /**
5
+ * A function to handle the request from the Slack app.
6
+ * @param req - The request from the Slack app.
7
+ * @returns A response object.
8
+ */
9
+ type VercelHandler = (req: Request) => Promise<Response>;
10
+ /**
11
+ * Configuration options for the VercelReceiver.
12
+ * @property signingSecret - The signing secret for the Slack app.
13
+ * @property signatureVerification - If true, verifies the Slack request signature.
14
+ * @property logger - The logger to use for the VercelReceiver.
15
+ * @property logLevel - The log level to use for the VercelReceiver.
16
+ * @property customPropertiesExtractor - A function to extract custom properties from the request.
17
+ * @property customResponseHandler - A function to handle the response from the Slack app.
18
+ */
19
+ interface VercelReceiverOptions {
20
+ /**
21
+ * The signing secret for the Slack app.
22
+ * @default process.env.SLACK_SIGNING_SECRET
23
+ */
24
+ signingSecret?: string;
25
+ /**
26
+ * If true, verifies the Slack request signature.
27
+ * @default true
28
+ */
29
+ signatureVerification?: boolean;
30
+ /**
31
+ * The logger to use for the VercelReceiver.
32
+ * @default new ConsoleLogger()
33
+ */
34
+ logger?: Logger;
35
+ /**
36
+ * The log level to use for the VercelReceiver.
37
+ * @default LogLevel.INFO
38
+ */
39
+ logLevel?: LogLevel;
40
+ /**
41
+ * A function to extract custom properties from incoming events.
42
+ * @default undefined
43
+ * @returns An object with custom properties.
44
+ */
45
+ customPropertiesExtractor?: (req: Request) => StringIndexed;
46
+ /**
47
+ * A function to handle the response from the Slack app.
48
+ * @default undefined
49
+ * @returns A response object.
50
+ */
51
+ customResponseHandler?: (event: ReceiverEvent) => Promise<Response>;
52
+ }
53
+ /**
54
+ * A Slack Bolt receiver implementation designed for Vercel's serverless environment.
55
+ * Handles Slack events, interactions, and slash commands with automatic request verification,
56
+ * background processing, and timeout management.
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * import { App } from '@slack/bolt';
61
+ * import { VercelReceiver, createHandler } from '@vercel/slack-bolt';
62
+ *
63
+ * const receiver = new VercelReceiver();
64
+ *
65
+ * const app = new App({
66
+ * receiver,
67
+ * token: process.env.SLACK_BOT_TOKEN,
68
+ * signingSecret: process.env.SLACK_SIGNING_SECRET,
69
+ * });
70
+ * ```
71
+ *
72
+ */
73
+ declare class VercelReceiver implements Receiver {
74
+ private readonly signingSecret;
75
+ private readonly signatureVerification;
76
+ private readonly logger;
77
+ private readonly customPropertiesExtractor?;
78
+ private readonly customResponseHandler?;
79
+ private app?;
80
+ /**
81
+ * Gets the logger instance used by this receiver.
82
+ * @returns The logger instance
83
+ */
84
+ getLogger(): Logger;
85
+ /**
86
+ * Creates a new VercelReceiver instance.
87
+ *
88
+ * @param options - Configuration options for the receiver
89
+ * @throws {VercelReceiverError} When signing secret is not provided
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * const receiver = new VercelReceiver();
94
+ * ```
95
+ */
96
+ constructor({ signingSecret, signatureVerification, logger, logLevel, customPropertiesExtractor, customResponseHandler, }?: VercelReceiverOptions);
97
+ /**
98
+ * Initializes the receiver with a Slack Bolt app instance.
99
+ * This method is called automatically by the Bolt framework.
100
+ *
101
+ * @param app - The Slack Bolt app instance
102
+ */
103
+ init(app: App): void;
104
+ /**
105
+ * Starts the receiver and returns a handler function for processing requests.
106
+ * This method is called automatically by the Bolt framework.
107
+ *
108
+ * @returns A handler function that processes incoming Slack requests
109
+ */
110
+ start(): Promise<VercelHandler>;
111
+ /**
112
+ * Stops the receiver. This method is called automatically by the Bolt framework.
113
+ */
114
+ stop(): Promise<void>;
115
+ /**
116
+ * Creates a handler function that processes incoming Slack requests.
117
+ * This is the main entry point for handling Slack events in Vercel.
118
+ * It is called automatically by the Bolt framework in the start() method.
119
+ *
120
+ * @returns A handler function compatible with Vercel's function signature
121
+ */
122
+ toHandler(): VercelHandler;
123
+ private parseRequestBody;
124
+ private handleSlackEvent;
125
+ private verifySlackRequest;
126
+ private createSlackReceiverEvent;
127
+ private handleError;
128
+ private createScopedLogger;
129
+ }
130
+ /**
131
+ * Creates a Vercel-compatible handler function for a Slack Bolt app.
132
+ * This is the recommended way to create handlers for deployment on Vercel.
133
+ *
134
+ * @param {App} app - The initialized Slack Bolt app instance.
135
+ * @param {VercelReceiver} receiver - The VercelReceiver instance.
136
+ * @returns {VercelHandler} A handler function compatible with Vercel's function signature.
137
+ *
138
+ * @example
139
+ * ```typescript
140
+ * // api/events.ts
141
+ * import { createHandler } from '@vercel/slack-bolt';
142
+ * import { app, receiver } from '../app';
143
+ *
144
+ * const handler = createHandler(app, receiver);
145
+ *
146
+ * export const POST = async (req: Request) => {
147
+ * return handler(req);
148
+ * };
149
+ * ```
150
+ *
151
+ * @throws {Error} If app initialization fails.
152
+ * @throws {VercelReceiverError} If request processing fails.
153
+ */
154
+ declare function createHandler(app: App, receiver: VercelReceiver): VercelHandler;
155
+
156
+ export { type VercelHandler, VercelReceiver, type VercelReceiverOptions, createHandler };