How to correctly format and render flow run URL with Jinja templating when sending custom Slack notifications via Automations?

When you create an Automation that sends Slack notifications, it’s great to see this URL as a nicely formatted text with a hyperlink. However, Slack has a very specific markdown language.

Here is an example template syntax for Slack:

Flow run {{ }}/{{ }} entered state `{{ }}` at {{ flow_run.state.timestamp }}.
Flow ID: {{ flow_run.flow_id }}
Flow run ID: {{ }}
Flow run URL: <{{ flow_run|ui_url }}|link to the flow run page in the Prefect Cloud UI>
State message: {{ flow_run.state.message }}

You can paste that into the message body in the Automation Action UI:

The message will be rendered as follows in Slack: