Hello :wave: Is it possible to somehow get the url...
# prefect-community
m
Hello 👋 Is it possible to somehow get the url of a currently running flow? I'd like to have a task which sends a slack notification, which would include a link to the current flow. I can't seem to find anything like that in the docs, but I thought I'd ask, maybe I'm missing something.
j
Hey @Magda Stożek you can create an alert in Prefect Cloud when a Flow run starts which will include the link to the flow run in Cloud.
r
Yes, you can use state handlers for what @Jacob Blanco described, as follows:
Copy code
from prefect.utilities.notifications import slack_notifier

# Setup for Slack notifications
handler = slack_notifier(
    backend_info=True,
    only_states=[prefect.engine.state.Success, prefect.engine.state.Failed],
)

prefect.context.secrets = {
    "SLACK_WEBHOOK_URL": "<https://hooks.slack.com/services/>..."
}

with Flow(
    name=flow_name,
    state_handlers=[handler],
    ) as flow:
  ...
https://api.slack.com/messaging/webhooks
j
Thanks for the example @Robin I’m being lazy. You can also create these in Cloud itself if you want to quickly experiment with stuff.
m
thanks. I did have a look at the slack notifier built-in in Prefect, but it seems that I don’t have the possibility to fine-tune the text of the notification (e.g. add people to mention, etc) - is that right?
j
hmmm I’m not sure about that.
🤷‍♂️ 1
r
looking at the source code, it seems that it is currently not possible. However, it should not be too much of an effort to add **kwargs and custom text...
m
thanks @Robin!
BTW, do you happen to know if this section of the docs
Sooner rather than later, you will be able to store your slack webhook URL in your secure database of Prefect Secrets under `"SLACK_WEBHOOK_URL"`; until then, you need to include it in the
[context.secrets]
section of your prefect configuration file
is still accurate? Do I understand correctly that there’s currently no way to securely pass the webhook url to be used by the slack_notifier?
r
Good question, I was wondering also how secure the slack apps are. Do you have background knowledge about it?
Concerning the custom texts, I created the following feature enhancement issue, as we are also interested in this enhancement: https://github.com/PrefectHQ/prefect/issues/3531 Feel free to edit the issue! Not sure when I will have time to look into it...
m
I know that the incoming webhook url is something you should keep secret if you don’t want other people posting to your slack 🙂
r
OK, thanks! I only worry about other people listening to our notifications atm 😄
👍 1
m
Thanks for creating the issue 🙂 I’ll keep an eye on it
BTW I tried it out and it’s possible to just set
SLACK_WEBHOOK_URL
prefect secret (using the UI) to the webhook url, and slack_notifier picks it up, so it’s fine security-wise, it’s just that this piece of docs was misleading. Phew 🙂
👌 2
I’ve added a PR to the docs to clarify that: https://github.com/PrefectHQ/prefect/pull/3532
🦜 2