question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to run SlackTask using EnvVarSecret

See original GitHub issue

I’m trying to send a slack message using prefect.tasks.notifications.slack_task.SlackTask and prefect.tasks.secrets.EnvVarSecret to post to Slack.

from prefect import task, Flow
from prefect.tasks.secrets import EnvVarSecret
from prefect.tasks.notifications.slack_task import SlackTask


@task
def notify_slack():
    slack_secret = EnvVarSecret('SLACK_WEBHOOK_URL')
    task = SlackTask(webhook_secret=slack_secret)
    task.run(message='Test slack message')


with Flow('slack test') as slack_flow:
    result = notify_slack()


slack_flow.run()

This throws this exception

ValueError: Local Secret "<Task: SLACK_WEBHOOK_URL>" was not found.

The environment variable SLACK_WEBHOOK_URL has a valid value in it.

How can I use SlackTask and EnvVarSecret to successfully send a message to slack?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
joshmeekcommented, May 13, 2020

Ah @petermorrow my bad. The SlackTask needs to be instantiated before it’s called so you could do something like one of the two options below:

from prefect import task, Flow
from prefect.tasks.notifications.slack_task import SlackTask

slack_task = SlackTask(webhook_secret="SLACK_WEBHOOK_URL")

with Flow('slack test') as slack_flow:
    slack_task(message="Test slack message")

slack_flow.run()
from prefect import task, Flow
from prefect.tasks.notifications.slack_task import SlackTask

with Flow('slack test') as slack_flow:
    SlackTask(webhook_secret="SLACK_WEBHOOK_URL", message="Test slack message")()

slack_flow.run()

Also, glad you have it working with a custom task! 😄

0reactions
peterth3commented, May 13, 2020

That did the trick, thanks @joshmeek!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to send Slack notifications using the SlackTask
1. Create a slack webhook First, to create a webhook, go to Slack API: Applications | Slack → Create a New App →...
Read more >
Expose build ENV variables to tasks · Issue #494 - GitHub
Hi there! We use Pivotal Tracker to provide visibility into what our team is working on. A story for this issue has been...
Read more >
Make your Slack app accessible directly from a message
Enter an App Name and select your development workspace, then click the Create App button. ... Next, at Basic Information, scroll down to...
Read more >
Workflow Builder Steps from Apps - Slack API
Now, go to Features > App Home. Make sure the Home Tab is checked. This app will update the user's app home with...
Read more >
Hello World, Bolt ⚡️ - Building your very first app with Bolt
Once you create, at Settings > Basic Information screen, scroll down to App Credentials, and find your Signing secret by clicking Show to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found