Hey all, I'm exploring migrating from v1 to v2, an...
# ask-community
n
Hey all, I'm exploring migrating from v1 to v2, and was looking to set up Notifications to a Slack channel. We have prefect-orion deployed via the helm chart, and currently have the Webhook url stored in an AWS Secret and would like to keep accessing it from there, but the only documentation I could find is for setting it up through the UI here. Is it possible to establish notification connections from outside the UI at all?
a
and you can create notification blocks via Python code
Copy code
from prefect import flow, task
from prefect.blocks.notifications import SlackWebhook


@task
def send_alert():
    slack_webhook_block = SlackWebhook.load("yourblock") 
    slack_webhook_block.notify("Hello from Prefect!") 

@flow(name="Important-2.0-Flow")
def notification_flow():
    send_alert()
to set up:
Copy code
from dotenv import load_dotenv
import os
from prefect.blocks.notifications import SlackWebhook

load_dotenv()

slack = SlackWebhook(url=os.environ.get("SLACK_WEBHOOK_URL"))
slack.save("default", overwrite=True)
n
gotcha, thank you!
🙌 1