Slack Edge Framework

1.3.16 · active · verified Sun Apr 19

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

Warnings

Install

Imports

Quickstart

Demonstrates a basic Slack app on Cloudflare Workers, handling a slash command. It uses `slack-edge`'s core `SlackApp` and integrates with `slack-cloudflare-workers` to manage the edge function request/response lifecycle, showcasing both synchronous acknowledgment and asynchronous lazy listeners.

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

view raw JSON →