Slack Alerter

Sending automated alerts to a Slack channel.

The SlackAlerter enables you to send messages or ask questions within a dedicated Slack channel directly from within your ZenML pipelines and steps.

How to Create

Set up a Slack app

In order to use the SlackAlerter, you first need to have a Slack workspace set up with a channel that you want your pipelines to post to.

Then, you need to create a Slack App with a bot in your workspace. Make sure to give it the following permissions in the OAuth & Permissions tab under Scopes:

  • chat:write,

  • channels:read

  • channels:history

Slack OAuth Permissions

In order to be able to use the ask() functionality, you need to invite the app to your channel. You can either use the /invite command directly in the desired channel or add it through the channel settings:

Slack OAuth Permissions

Registering a Slack Alerter in ZenML

To create a SlackAlerter, you first need to install ZenML's slack integration:

Once the integration is installed, you can use the ZenML CLI to create a secret and register an alerter linked to the app you just created:

Using Secrets for Token Management: The example above demonstrates the recommended approach of storing your Slack token as a ZenML secret and referencing it using the {{secret_name.key}} syntax. This keeps sensitive information secure and follows security best practices.

Learn more about referencing secrets in stack component attributes and settings.

Here is where you can find the required parameters:

  • <SLACK_CHANNEL_ID>: The channel ID can be found in the channel details. It starts with C.....

  • <SLACK_TOKEN>: This is the Slack token of your bot. You can find it in the Slack app settings under OAuth & Permissions.

Slack Token Image

After you have registered the slack_alerter, you can add it to your stack like this:

How to Use

In ZenML, you can use alerters in various ways.

Use the post() and ask() directly

You can use the client to fetch the active alerter within your stack and use the post and ask methods directly:

Use it with custom settings

The Slack alerter comes equipped with a set of options that you can set during runtime:

Use it with SlackAlerterParameters and SlackAlerterPayload

You can use these additional classes to further edit your messages:

Use the predefined steps

If you want to only use it in a simple manner, you can also use the steps slack_alerter_post_step and slack_alerter_ask_step, that are built-in to the Slack integration of ZenML:

Default Response Keywords and Ask Step Behavior

The ask() method and slack_alerter_ask_step recognize these keywords by default:

Approval: approve, LGTM, ok, yes Disapproval: decline, disapprove, no, reject

Important Notes:

  • The ask step returns a boolean (True for approval, False for disapproval/timeout)

  • Response keywords are case-insensitive - keywords are converted to lowercase before matching (e.g., both LGTM and lgtm work)

  • If no valid response is received within the timeout period, the step returns False

  • The default timeout is 300 seconds (5 minutes) but can be configured

Slack Case Handling: The Slack alerter implementation automatically converts all response keywords to lowercase before matching, making responses case-insensitive. You can respond with LGTM, lgtm, or Lgtm - they'll all work.

For more information and a full list of configurable attributes of the Slack alerter, check out the SDK Docs .

ZenML Scarf

Last updated

Was this helpful?