Slack Edge Framework
This library, currently at version 1.3.16, provides a framework for building Slack applications optimized for edge runtimes like Cloudflare Workers, Vercel Edge Functions, and Supabase Edge Functions. It also supports Deno, Bun, and Node.js. `slack-edge` emphasizes TypeScript support, offering enhanced type safety for Slack events and API interactions. It differentiates itself from Slack's Bolt framework by being specifically designed for edge environments, including out-of-the-box support for "lazy listeners" for asynchronous processing, similar to Bolt-Python. The project maintains a frequent release cadence, primarily focusing on bug fixes, dependency upgrades, and support for new Slack API event types. A key aspect is its minimal dependency footprint, relying primarily on `slack-web-api-client` for Slack API interactions. This design choice contributes to faster cold starts and lower resource consumption, making it ideal for serverless and edge computing architectures.
Common errors
-
HTTP 401: Invalid Signature
-
Signature verification failed
-
TypeError: app.run is not a function
-
Request timed out
-
ReferenceError: process is not defined
Warnings
- gotcha Edge functions have strict execution time limits (typically 3 seconds for initial Slack event responses). Any long-running operations in your synchronous handlers will cause timeouts.
- gotcha Direct usage of `slack-edge` for an edge runtime requires installing and configuring a platform-specific adapter package (e.g., `slack-cloudflare-workers`, `slack-vercel-edge`) to handle the request/response context.
- gotcha Prior to version 1.3.8, there was a bug where `oauth.start` might have been incorrectly used for OIDC endpoint customization, potentially leading to misconfiguration.
- gotcha Incorrect or missing Slack environment variables (`SLACK_SIGNING_SECRET`, `SLACK_BOT_TOKEN`, etc.) are a very common cause of application startup failures or request validation errors, especially during local development.
Install
-
npm install slack-edge -
yarn add slack-edge -
pnpm add slack-edge
Imports
- SlackApp
const SlackApp = require('slack-edge');import { SlackApp } from 'slack-edge'; - SlackEnv
import { SlackEnv } from 'slack-edge';import type { SlackEnv } from 'slack-edge'; - LazyListener
import { LazyListener } from 'slack-edge';import type { LazyListener } from 'slack-edge'; - CodedError
import { CodedError } from 'slack-edge';import type { CodedError } from 'slack-edge';
Quickstart
import { SlackApp } from "slack-edge";
import { SlackEdgeAppEnv } from "slack-cloudflare-workers";
export default {
async fetch(
request: Request,
env: SlackEdgeAppEnv,
ctx: ExecutionContext
): Promise<Response> {
// Initialize the SlackApp with environment variables provided by the adapter
const app = new SlackApp({ env })
.command("/hello-cf-workers",
async (req) => {
// Synchronous handler, responsible for acknowledging the request within 3 seconds
return ":wave: This app runs on Cloudflare Workers!";
// If no immediate response is needed, simply `async () => {}` works
},
async ({ context: { respond } }) => {
// Lazy listener, executed asynchronously for longer-running tasks
// This can take more than 3 seconds without timing out the initial request
await respond({ text: "This is an async reply. How are you doing?" });
}
);
// Run the app using the Cloudflare Workers adapter's `run` method
return await app.run(request, ctx);
}
};
// --- Local Development Environment Variables (e.g., in .dev.vars) ---
// SLACK_SIGNING_SECRET=...
// SLACK_BOT_TOKEN=xoxb-...
// SLACK_LOGGING_LEVEL=DEBUG