Slack App Framework for Cloudflare Workers

1.3.9 · active · verified Sun Apr 19

slack-cloudflare-workers is an opinionated framework for building Slack applications designed specifically for Cloudflare Workers, leveraging their serverless environment. Inspired by Slack's popular Bolt framework but not strictly following its blueprint, it distinguishes itself with a strong TypeScript focus, built-in lazy listener capabilities (similar to bolt-python), and a commitment to zero additional runtime dependencies beyond its foundational `slack-edge` module. The current stable version is 1.3.9. This library caters to developers seeking highly performant, type-safe, and lightweight Slack integrations on the Cloudflare Workers platform, providing a streamlined experience compared to general-purpose Node.js frameworks. While release cadence isn't explicitly stated, the active development and frequent updates to the `slack-edge` ecosystem suggest a responsive maintenance schedule.

Common errors

Warnings

Install

Imports

Quickstart

Sets up a basic Cloudflare Worker handling Slack 'hello' messages and '/echo' slash commands, demonstrating app initialization and event listeners.

import { App } from 'slack-cloudflare-workers';

interface Env {
  SLACK_SIGNING_SECRET: string;
  SLACK_BOT_TOKEN: string;
}

const app = new App({
  signingSecret: process.env.SLACK_SIGNING_SECRET ?? 'your-signing-secret-if-not-env',
  token: process.env.SLACK_BOT_TOKEN ?? 'your-bot-token-if-not-env',
});

// Listen for a 'hello' message
app.message('hello', async ({ say, payload }) => {
  await say(`Hello, <@${payload.user}>! How can I help you?`);
});

// Respond to a slash command
app.command('/echo', async ({ command, ack, respond }) => {
  await ack(); // Acknowledge the command immediately
  await respond(`You said: ${command.text}`);
});

export default {
  async fetch(
    request: Request,
    env: Env,
    ctx: ExecutionContext
  ): Promise<Response> {
    // Ensure the app instance uses the environment variables from the Worker's context
    // This is crucial for local development vs. deployed Worker
    app.oauth = undefined; // Reset OAuth for each request to use correct env
    app.receiver.signingSecret = env.SLACK_SIGNING_SECRET;
    app.client.token = env.SLACK_BOT_TOKEN;
    
    return app.fetch(request, env, ctx);
  },
};

view raw JSON →