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
13 changes: 9 additions & 4 deletions workers-builds-notifications-template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,20 @@ Subscribe your queue to Workers Builds events.
wrangler queues subscription create builds-event-subscriptions \
--source workersBuilds.worker \
--events build.succeeded,build.failed \
--worker-name <YOUR_CONSUMER_WORKER_NAME>
--worker-name <YOUR_SOURCE_BUILD_WORKER_NAME>
```

> `--worker-name` is the source Worker being built (the project you want notifications for), not the queue consumer Worker.
>
> To receive notifications for multiple projects, create one subscription per source Worker name.
>
> For more details, see [Event Subscriptions Documentation](https://developers.cloudflare.com/queues/event-subscriptions/)

---

### 7. Test It!

Trigger a build on any worker in your account. You should see a notification in your channel within seconds!
Trigger a build on a worker you subscribed to. You should see a notification in your channel within seconds!

---

Expand All @@ -182,11 +186,12 @@ Trigger a build on any worker in your account. You should see a notification in
```
┌─────────────────┐ ┌─────────────┐ ┌──────────────────┐ ┌─────────┐
│ Workers Builds │────▶│ Queue │────▶│ This Consumer │────▶│ Webhook │
│ (any worker) │ │ │ │ Worker │ │ │
│ (subscribed │ │ │ │ Worker │ │ │
│ worker(s)) │ │ │ │ │ │ │
└─────────────────┘ └─────────────┘ └──────────────────┘ └─────────┘
```

1. **Any worker** in your account triggers a build
1. A **subscribed worker** in your account triggers a build
2. **Workers Builds** publishes an event to your **Queue**
3. **This consumer worker** processes the event and sends a notification to your **webhook**

Expand Down
20 changes: 15 additions & 5 deletions workers-builds-notifications-template/src/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
// =============================================================================

export interface SlackPayload {
text?: string;
blocks: KnownBlock[];
}

Expand Down Expand Up @@ -128,7 +129,7 @@ function buildSuccessMessage(
blocks.push(buildContextBlock(contextElements));
}

return { blocks };
return { text: `✅ ${title}: ${workerName}`, blocks };
}

function buildFailureMessage(
Expand Down Expand Up @@ -159,7 +160,7 @@ function buildFailureMessage(
text: { type: "mrkdwn", text: `\`\`\`${error}\`\`\`` },
});

return { blocks };
return { text: `❌ Build Failed: ${workerName}`, blocks };
}

function buildCancelledMessage(event: CloudflareEvent): SlackPayload {
Expand All @@ -179,11 +180,12 @@ function buildCancelledMessage(event: CloudflareEvent): SlackPayload {
blocks.push(buildContextBlock(contextElements));
}

return { blocks };
return { text: `⚠️ Build Cancelled: ${workerName}`, blocks };
}

function buildFallbackMessage(event: CloudflareEvent): SlackPayload {
return {
text: `📢 ${event.type || "Unknown event"}`,
blocks: [
{
type: "section",
Expand Down Expand Up @@ -232,13 +234,21 @@ export async function sendSlackNotification(
webhookUrl: string,
payload: SlackPayload,
): Promise<void> {
const body = JSON.stringify({
...payload,
text: payload.text || "Workers Build Notification",
});
Comment on lines +237 to +240
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new top-level text field added to fix Discord webhook compatibility is not covered by tests. Consider adding test assertions to verify that the text field is present in the payload sent to the webhook and contains the expected values for different event types (success, failure, cancelled, fallback).

Copilot uses AI. Check for mistakes.

const response = await fetch(webhookUrl, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
body,
});

if (!response.ok) {
console.error("Slack API error:", response.status, await response.text());
const responseText = await response.text();
console.error(
`Slack API error: ${response.status} - ${responseText}. Payload: ${body}`,
);
}
}
Loading