<@ULVA73B9P> - I am trying to create a notificatio...
# ask-marvin
r
@Marvin - I am trying to create a notification alert using automations and the microsoft teams block, i am trying to send this body:
Copy code
Flow run **{{ flow.name }}/{{ deployment.name }}** observed in state `{{ flow_run.state.name }}` at {{ flow_run.state.timestamp }}.

**Flow run Tags:** {{ flow_run.tags }}

**Flow run URL:** {{ flow_run|ui_url }}

**State message:** {{ flow_run.state.message }}
But I dont get a flow run url
m
thought for 466.1 seconds
You’re on the right track using
{{ flow_run|ui_url }}
— in Prefect 3.x that Jinja filter should render a clickable Flow Run URL in automation notifications. If you’re getting an empty value, it’s usually one of these: 1) The automation wasn’t triggered by a flow run event - If your trigger isn’t a flow-run state change (e.g., it’s a work pool or custom event), the
flow_run
variable won’t be present, so
{{ flow_run|ui_url }}
renders blank. - Confirm your automation trigger is a Flow Run state event (e.g., “Flow run enters state Failed/Completed/etc.”). 2) Self-hosted: the UI base URL isn’t configured - The
ui_url
filter needs a base UI URL. In self-hosted (OSS) environments, set
PREFECT_UI_URL
to your UI’s base (e.g., http://your-ui-host) in the environment where Automations run. - Verify and set:
Copy code
prefect config view --show-defaults
prefect config set PREFECT_UI_URL=<http://your-ui-host>
3) Prefect Cloud: very rare, but if blank, confirm workspace context - On Cloud,
ui_url
should default to the Prefect Cloud UI and include your account/workspace automatically. If it’s still blank, please share your trigger details; we can dig deeper. Your template looks fine. This should work:
Copy code
Flow run *{{ flow.name }}/{{ deployment.name }}* observed in state `{{ flow_run.state.name }}` at {{ flow_run.state.timestamp }}.

*Flow run Tags:* {{ flow_run.tags }}

*Flow run URL:* {{ flow_run|ui_url }}

*State message:* {{ flow_run.state.message }}
Quick fallback (works anywhere): hardcode the base and append the ID - If you’re self-hosted and still sorting settings, you can do:
Copy code
Flow run URL: <https://your-ui-host/flow-runs/flow-run/{{> flow_run.id }}
Docs for reference: - Automations overview - Jinja filters (ui_url, ui_resource_events_url) - Template variables you can access If you can share: - Whether you’re on Prefect Cloud or self-hosted - The exact automation trigger you’re using I can pinpoint the cause and get you the URL rendering.
r
@Marvin Is it possible to include the artifact that is rendered and send it in an automation?
m
thought for 924.6 seconds
Short answer: not directly. Automation notification templates don’t expose artifacts, so you can’t embed an artifact’s rendered content in a Teams/Slack/Email notification body via Jinja today. Options/workarounds: - Link to the artifact in the UI - Include a link to the Flow Run and tell recipients to open the Artifacts tab:
Copy code
Flow run URL: {{ flow_run|ui_url }}
- If you give your artifact a key, it will also appear on the UI’s Artifacts page; you can mention the key in the message for easy lookup. - Send the artifact content from your flow code - After creating the artifact, send a Teams message directly from your flow using the Microsoft Teams block:
Copy code
from prefect import flow
  from prefect.artifacts import create_markdown_artifact
  from prefect.blocks.notifications import MicrosoftTeamsWebhook

  @flow
  def my_flow():
      content = "# Run report\n- metric_a: 42"
      create_markdown_artifact(key="run-report", markdown=content)

      teams = MicrosoftTeamsWebhook.load("my-teams-block")
      teams.send(f"Run report:\n\n{content}")
- This bypasses automations and guarantees the artifact content is included. - Use a webhook action that fetches artifact(s) and posts them - In Automations, choose “Call a webhook” and point it at a small service you control. Your service can: 1) Receive the event with
flow_run.id
2) Call the Prefect REST API to fetch the latest artifact(s) for that flow run 3) Post a nicely formatted message (with the artifact content) to Teams/Slack - Docs for artifacts API and concepts: - Artifacts concepts - Create and manage artifacts - Artifacts REST API If you share whether you’re on Cloud or self-hosted and whether you want a link vs. full content in Teams, I can outline the exact steps (and example payloads) for the approach that fits best.