Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
"files": {
"ignore": ["examples/**/dist"]
"ignore": ["examples/**/dist", "examples/deploy-cloudflare-workers/worker-configuration.d.ts"]
},
"formatter": {
"enabled": true,
Expand Down
8 changes: 8 additions & 0 deletions examples/deploy-cloudflare-workers/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules/
.wrangler/
.dev.vars*
!.dev.vars.example
.env*
!.env.example
.DS_Store
\*.tsbuildinfo
41 changes: 41 additions & 0 deletions examples/deploy-cloudflare-workers/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Cloudflare Workers

STOP. Your knowledge of Cloudflare Workers APIs and limits may be outdated. Always retrieve current documentation before any Workers, KV, R2, D1, Durable Objects, Queues, Vectorize, AI, or Agents SDK task.

## Docs

- https://developers.cloudflare.com/workers/
- MCP: `https://docs.mcp.cloudflare.com/mcp`

For all limits and quotas, retrieve from the product's `/platform/limits/` page. eg. `/workers/platform/limits`

## Commands

| Command | Purpose |
|---------|---------|
| `npx wrangler dev` | Local development |
| `npx wrangler deploy` | Deploy to Cloudflare |
| `npx wrangler types` | Generate TypeScript types |

Run `wrangler types` after changing bindings in wrangler.jsonc.

## Node.js Compatibility

https://developers.cloudflare.com/workers/runtime-apis/nodejs/

## Errors

- **Error 1102** (CPU/Memory exceeded): Retrieve limits from `/workers/platform/limits/`
- **All errors**: https://developers.cloudflare.com/workers/observability/errors/

## Product Docs

Retrieve API references and limits from:
`/kv/` · `/r2/` · `/d1/` · `/durable-objects/` · `/queues/` · `/vectorize/` · `/workers-ai/` · `/agents/`

## Best Practices (conditional)

If the application uses Durable Objects or Workflows, refer to the relevant best practices:

- Durable Objects: https://developers.cloudflare.com/durable-objects/best-practices/rules-of-durable-objects/
- Workflows: https://developers.cloudflare.com/workflows/build/rules-of-workflows/
21 changes: 21 additions & 0 deletions examples/deploy-cloudflare-workers/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Slack Technologies, LLC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
155 changes: 155 additions & 0 deletions examples/deploy-cloudflare-workers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# Deploying to Cloudflare Workers ⚡️ Bolt for JavaScript

> Slack app example for using the CloudflareWorkerReceiver of Bolt for JavaScript

## Overview

This is an example app that updates the [Getting Started ⚡️ Bolt for JavaScript app][bolt-app] to use the CloudflareWorkerReceiver and be deployed to [Cloudflare Workers][cloudflare-workers] using [Wrangler][wrangler].
You can learn how to build this example app by following Cloudflare's [CLI guide][cloudflare-getting-started] for Workers.

Before you begin, you may want to follow our [Getting Started guide][bolt-guide] to learn how to build your first Slack app using the [Bolt for JavaScript framework][bolt-website].

## Getting started

1. [Bootstrap a Worker project](#1-bootstrap-a-worker-project)
2. [Set up local project](#2-set-up-local-project)
3. [Create a Slack app](#3-create-a-slack-app)
4. [Develop on local machine](#4-develop-on-local-machine)
5. [Update Slack app settings](#5-update-slack-app-settings)
6. [Test your Slack app](#6-test-your-slack-app)
7. [Deploy to Cloudflare Workers](#7-deploy-to-cloudflare-workers)

## 1. Bootstrap a Worker project

Follow Cloudflare's C3 bootstrap flow to create a new Worker project:

```zsh
npm create cloudflare@latest -- my-first-worker
```

For setup, select the following options:

1. For `What would you like to start with?`, choose `Hello World example`
2. For `Which template would you like to use?`, choose `Worker only`
3. For `Which language do you want to use?`, choose `TypeScript`
4. For `Do you want to use git for version control?`, choose `Yes`
5. For `Do you want to deploy your application?`, choose `No`

Move into the new project folder:

```zsh
cd my-first-worker
```

## 2. Set up local project

You can install the app's local development dependencies with the following command:

```zsh
npm install
```

Set your local secrets in `.dev.vars` so Wrangler can load them during development. Cloudflare recommends this file for local-only values:

```zsh
SLACK_SIGNING_SECRET=<your-signing-secret>
SLACK_BOT_TOKEN=<your-xoxb-bot-token>
```

## 3. Create a Slack app

### Create an app on api.slack.com

1. Go to https://api.slack.com/apps
2. Select **Create New App**
* Name your app, _don't worry you can change it later!_
3. Select **OAuth & Permissions**
1. Scroll down to **Bot Token Scopes**
2. Add the following bot scopes:
1. Add the scope `app_mentions:read`
2. Add the scope `channels:history`
3. Add the scope `chat:write`
4. Add the scope `groups:history`
5. Add the scope `im:history`
6. Add the scope `mpim:history`
3. Select **Install App to Workspace** at the top of the page

## 4. Develop on local machine

1. Open a terminal session to start Wrangler dev:

```zsh
npm run dev
```

Wrangler serves the Worker locally at `http://localhost:8787`.

2. Open a second terminal session and expose that local server with Cloudflare Tunnel:

```zsh
npx cloudflared tunnel --url http://localhost:8787
```

Cloudflared prints a public `https://<random>.trycloudflare.com` URL. Keep this terminal running while you test.

3. Keep your local secrets in `.dev.vars` as described above.

4. Follow [Update Slack app settings](#5-update-slack-app-settings) to point Slack at the tunnel URL from Cloudflared.

## 5. Update Slack app settings

While developing locally, point Slack at your Cloudflare Tunnel URL. After you deploy, come back to this section and replace it with the `workers.dev` URL from the final section.

1. Go to https://api.slack.com/apps
2. Select your app
3. Select **Event Subscriptions**
1. Enable **Events**
2. Set the **Request URL** to `https://<your-cloudflared-url>/slack/events`
3. Scroll down to **Subscribe to Bot Events**
4. Add the following bot events:
- `app_mention`
- `message.channels`
- `message.groups`
- `message.im`
- `message.mpim`
5. Select **Save Changes**
4. Select **Interactivity & Shortcuts**
1. Enable **Interactivity**
2. Set the **Request URL** to `https://<your-cloudflared-url>/slack/events`
3. Select **Save Changes**

## 6. Test your Slack app

You can test your app by opening a Slack workspace and saying "hello" (lower-case):

> 💬 hello
>
> 🤖 Hey there @Jane!

_Remember, your app must be in the channel or DM where you say hello._

## 7. Deploy to Cloudflare Workers

Before you deploy, add both secrets with `npx wrangler secret put`:

```zsh
npx wrangler secret put SLACK_SIGNING_SECRET
npx wrangler secret put SLACK_BOT_TOKEN
```

Then run the following command to deploy to Cloudflare Workers:

```zsh
npm run deploy
# ...
# deployed to https://<your-worker-name>.<your-subdomain>.workers.dev
```

After deployment, repeat [Update Slack app settings](#5-update-slack-app-settings) and replace the tunnel URL with `https://<your-worker-name>.<your-subdomain>.workers.dev/slack/events`.

[bolt-app]: https://github.com/slackapi/bolt-js-getting-started-app
[bolt-guide]: https://docs.slack.dev/bolt-js/getting-started/
[bolt-website]: https://docs.slack.dev/bolt-js/
[cloudflare-getting-started]: https://developers.cloudflare.com/workers/get-started/guide/
[cloudflare-workers]: https://developers.cloudflare.com/workers/
[wrangler]: https://developers.cloudflare.com/workers/wrangler/
29 changes: 29 additions & 0 deletions examples/deploy-cloudflare-workers/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"display_information": {
"name": "Bolt on Cloudflare Workers Example"
},
"features": {
"bot_user": {
"display_name": "Bolt on Cloudflare Workers Example",
"always_online": true
}
},
"oauth_config": {
"scopes": {
"bot": ["app_mentions:read", "channels:history", "chat:write", "groups:history", "im:history", "mpim:history"]
}
},
"settings": {
"event_subscriptions": {
"request_url": "https://example-worker.example.workers.dev/slack/events",
"bot_events": ["app_mention", "message.channels", "message.groups", "message.im", "message.mpim"]
},
"interactivity": {
"is_enabled": true,
"request_url": "https://example-worker.example.workers.dev/slack/events"
},
"org_deploy_enabled": false,
"socket_mode_enabled": false,
"token_rotation_enabled": false
}
}
Loading