Skip to content

Commit 97c25e5

Browse files
Refactor workers-builds-notifications-template with improved Slack formatting (#886)
Co-authored-by: James Delorey <[email protected]>
1 parent dba81da commit 97c25e5

File tree

14 files changed

+1240
-939
lines changed

14 files changed

+1240
-939
lines changed

pnpm-lock.yaml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
"package_json_hash": "2025452f6c9e9011a8ed2681ff2f348f4b16908c"
8989
},
9090
"workers-builds-notifications-template": {
91-
"package_json_hash": "dfb8694ab1e7792fa8000d70fa05fe9eac3804fa"
91+
"package_json_hash": "7a93751a69e03ceed9c79190f02f28e9a2ef983f"
9292
}
9393
}
9494
}
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# Slack incoming webhook URL
22
# Get this from: https://api.slack.com/apps → Your App → Incoming Webhooks
3-
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/YOUR/WEBHOOK/URL
3+
SLACK_WEBHOOK_URL=
44

55
# Cloudflare API token
6-
# Create at: https://dash.cloudflare.com/profile/api-tokens
7-
# Select:
8-
# - **Edit Cloudflare Workers** template
9-
CLOUDFLARE_API_TOKEN=your-api-token-here
6+
# Create a custom token at: https://dash.cloudflare.com/profile/api-tokens
7+
# Required permissions:
8+
# - Workers Builds Configuration: Read
9+
# - Workers Scripts: Read
10+
CLOUDFLARE_API_TOKEN=

workers-builds-notifications-template/README.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ Get notified when your Workers Builds complete, fail, or are cancelled. This tem
88

99
## Features
1010

11-
- 🔔 Real time notifications for build success, failure, and cancellation
11+
- 🔔 Real-time notifications for build success, failure, and cancellation
1212
- 🔗 Works with any webhook (Slack, Discord, custom endpoints)
13-
- 📋 Includes build details: project name, status, duration, and other metadata
14-
- 📜 Optional build logs, preview URL, and live deployment URL fetched via Cloudflare API
13+
- 📋 Includes build details: project name, branch, commit, and author
14+
- 📜 Smart error extraction for failed builds, preview URL and live deployment URL for successful builds
1515

1616
## How It Works
1717

@@ -112,8 +112,10 @@ Modify the payload format in `src/index.ts` to match your webhook's expected for
112112
### 4. Create a Cloudflare API Token
113113

114114
1. Go to [Cloudflare API Tokens](https://dash.cloudflare.com/profile/api-tokens)
115-
2. Click **Create Token**
116-
3. Select **Edit Cloudflare Workers** template
115+
2. Click **Create Token****Create Custom Token**
116+
3. Add the following permissions:
117+
- **Workers Builds Configuration**: Read
118+
- **Workers Scripts**: Read
117119
4. Click **Continue to summary****Create Token**
118120
5. Copy the token
119121

@@ -161,8 +163,8 @@ Subscribe your queue to Workers Builds events.
161163
```bash
162164
wrangler queues subscription create builds-event-subscriptions \
163165
--source workersBuilds.worker \
164-
--events build.started,build.succeeded,build.failed \
165-
--worker-name [YOUR WORKER NAME HERE]
166+
--events build.succeeded,build.failed \
167+
--worker-name <YOUR_CONSUMER_WORKER_NAME>
166168
```
167169

168170
> For more details, see [Event Subscriptions Documentation](https://developers.cloudflare.com/queues/event-subscriptions/)
@@ -196,9 +198,10 @@ Trigger a build on any worker in your account. You should see a notification in
196198
| ------------------------------- | ----------------- |
197199
| ✅ Build succeeded (production) | Live Worker URL |
198200
| ✅ Build succeeded (preview) | Preview URL |
199-
| ❌ Build failed | Build logs inline |
200-
| ⚠️ Build cancelled | Build logs inline |
201-
| 🚀 Build started | Build started |
201+
| ❌ Build failed | Error message |
202+
| ⚠️ Build cancelled | Cancellation note |
203+
204+
> **Note:** Build started/queued events are acknowledged but do not send notifications.
202205
203206
---
204207

@@ -249,10 +252,10 @@ Trigger a build on any worker in your account. You should see a notification in
249252

250253
### Environment Variables
251254

252-
| Variable | Description |
253-
| ---------------------- | ----------------------------------------------------- |
254-
| `SLACK_WEBHOOK_URL` | Webhook URL (Slack, Discord, or custom) |
255-
| `CLOUDFLARE_API_TOKEN` | API token with Workers Builds and Scripts read access |
255+
| Variable | Description |
256+
| ---------------------- | --------------------------------------------------------------------------- |
257+
| `SLACK_WEBHOOK_URL` | Webhook URL (Slack, Discord, or custom) |
258+
| `CLOUDFLARE_API_TOKEN` | API token with Workers Builds Configuration: Read and Workers Scripts: Read |
256259

257260
### Queue Settings (wrangler.jsonc)
258261

@@ -279,7 +282,7 @@ The queue must be created before deploying. See [Step 1: Create a Queue](#1-crea
279282
### "Invalid token" error in logs
280283

281284
- Verify `CLOUDFLARE_API_TOKEN` is set in worker settings
282-
- Ensure token has correct permissions (Edit Cloudflare Workers template)
285+
- Ensure token has correct permissions (Workers Builds Configuration: Read, Workers Scripts: Read)
283286

284287
### URLs not appearing
285288

workers-builds-notifications-template/package-lock.json

Lines changed: 48 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

workers-builds-notifications-template/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"devDependencies": {
2727
"@cloudflare/vitest-pool-workers": "^0.11.1",
2828
"@cloudflare/workers-types": "^4.20241230.0",
29+
"@slack/types": "^2.19.0",
2930
"typescript": "^5.5.2",
3031
"vitest": "~3.0.0",
3132
"wrangler": "^4.45.0"
-180 KB
Loading

workers-builds-notifications-template/public/index.html

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -358,18 +358,20 @@ <h2>Event Types</h2>
358358
</tr>
359359
<tr>
360360
<td><span class="event-icon"></span> Build failed</td>
361-
<td>Build logs inline</td>
361+
<td>Error message extracted from logs</td>
362362
</tr>
363363
<tr>
364-
<td><span class="event-icon">⚠️</span> Build canceled</td>
365-
<td>Build logs inline</td>
366-
</tr>
367-
<tr>
368-
<td><span class="event-icon">🚀</span> Build started</td>
369-
<td>Build started notification</td>
364+
<td><span class="event-icon">⚠️</span> Build cancelled</td>
365+
<td>Cancellation note</td>
370366
</tr>
371367
</tbody>
372368
</table>
369+
<p
370+
style="margin-top: 1rem; font-size: 0.875rem; color: var(--gray-600)"
371+
>
372+
<strong>Note:</strong> Build started/queued events are acknowledged
373+
but do not send notifications.
374+
</p>
373375
</section>
374376

375377
<section class="section">

0 commit comments

Comments
 (0)