<@ULVA73B9P> how to setup a block that is connecte...
# ask-marvin
o
@Marvin how to setup a block that is connected to microsoft teams? how to configure that? from prefect.blocks.notifications import MicrosoftTeamsWebhook teams_webhook_block = MicrosoftTeamsWebhook.load("BLOCK_NAME") teams_webhook_block.notify("Hello from Prefect!")
m
thought for 168.0 seconds
Great question! Here’s how to set up and use a Microsoft Teams notification block in Prefect 3.x. High-level steps 1) Create a Teams Incoming Webhook URL in Microsoft Teams - In Teams, go to the channel where you want messages posted - Click the “…” next to the channel name > Connectors (or Apps) > search for “Incoming Webhook” - Configure it, give it a name, and copy the webhook URL - Microsoft docs: Create an Incoming Webhook 2) Make sure the block type is available - If you don’t see the Microsoft Teams block, register the notifications module:
Copy code
prefect block register -m prefect.blocks.notifications
- Confirm the block type slug exists:
Copy code
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:
Copy code
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
Copy code
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:
Copy code
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