oleander-whirlwind
10/13/2025, 8:41 AMMarvin
10/13/2025, 8:42 AMMarvin
10/13/2025, 8:44 AMprefect block register -m prefect.blocks.notifications
- Confirm the block type slug exists:
prefect block type ls
Look for ms-teams-webhook (this is the slug Prefect uses)
3) Create the block (UI or Python)
Option A — via Prefect UI
- Generate a link to create the block:
prefect block create ms-teams-webhook
- Click the link, give the block a name (this is your BLOCK_NAME), and paste the Teams webhook URL
Option B — via Python
from prefect.blocks.notifications import MicrosoftTeamsWebhook
from pydantic import SecretStr
teams = MicrosoftTeamsWebhook(
url=SecretStr("<https://outlook.office.com/webhook/your-teams-webhook-url>"),
# optional:
# notify_type="prefect_default", # or "info" | "success" | "warning" | "failure"
# include_image=True,
# wrap=True,
)
teams.save("BLOCK_NAME", overwrite=True)
4) Use the block in your code
Your example is correct once the block exists:
from prefect.blocks.notifications import MicrosoftTeamsWebhook
teams_webhook_block = MicrosoftTeamsWebhook.load("BLOCK_NAME")
teams_webhook_block.notify("Hello from Prefect!")
Optional: Use this block for flow run notifications
- In Prefect Cloud, create an Automation (Automations > New Automation)
- Choose a trigger (e.g., Flow run fails)
- Add action > Send notification > select your Microsoft Teams block
- Docs: Automations in Prefect 3
Notes and tips
- The block type slug is ms-teams-webhook (not microsoft-teams-webhook).
- Keep your webhook URL secret—blocks are the right place to store it.
- If you get “Block type not found,” run the register command above.
References
- Prefect Blocks overview: Blocks in Prefect 3
- Notifications API reference (includes MicrosoftTeamsWebhook): prefect.blocks.notifications