Loup
12/01/2025, 1:16 AMMarvin
12/01/2025, 1:16 AMMarvin
12/01/2025, 1:20 AMfrom prefect.blocks.notifications import DiscordWebhook
DiscordWebhook(
webhook_id="YOUR_WEBHOOK_ID",
webhook_token="YOUR_WEBHOOK_TOKEN",
botname="Prefect Bot", # optional
include_image=True # optional
).save("discord-notifications", overwrite=True)
Docs: DiscordWebhook block
3) Create an Automation to send the notification
- In the Prefect UI: Automations > + New Automation
- Trigger: Event, Reactive
- Expect events for “not success”, e.g.:
- prefect.flow-run.Failed
- prefect.flow-run.Crashed
- prefect.flow-run.TimedOut
- prefect.flow-run.Cancelled
- (Optional) Filter to a specific deployment/flow with match fields
- Action: Send notification
- Select your Discord block (e.g., discord-notifications)
- Subject: e.g., Flow failed: {{ event.resource.name }}
- Body:
Event: {{ event.event }}
Flow: {{ event.resource.name }}
Run ID: {{ event.resource.id }}
Occurred: {{ event.occurred }}
Docs: Creating automations, Event triggers
Notes
- To alert on success, add prefect.flow-run.Completed.
- To scope to a specific deployment, add a match in the trigger (e.g., by deployment name).
- If you’re on Prefect 2.x, the approach is different; I’d recommend upgrading to 3.x for Automations.
Would you like this to fire for every flow in your workspace, or only specific deployments? And are you on Prefect Cloud or OSS? I can tailor the exact trigger filters for you.