Log icon
SlackIncomingWebhook icon

Reusable Slack Block Kit Alert Subflow

Centralize rich Slack alerting in one Kestra subflow that renders a Block Kit payload with header and mrkdwn section, safely JSON escaped via toJson.

Categories
Core

Upgrade your pipeline alerts from plain text to rich, structured Slack messages, and maintain the formatting in exactly one place. This Kestra blueprint is a reusable subflow: any pipeline calls it with a header and a text body, and it renders a Slack Block Kit payload with a bold header block and an mrkdwn section, then posts it through an incoming webhook. Both inputs pass through the toJson filter, so multi line error messages, quotes, and special characters never break the JSON payload, a classic failure mode of hand built Slack alerts.

How it works

  1. The flow accepts two inputs: header (defaults to Pipeline Alert) and text, the message body which supports Slack mrkdwn formatting.
  2. The slack_payload variable holds the Block Kit JSON template with a header block and a section block. Inputs are injected with {{ inputs.header | toJson }} and {{ inputs.text | toJson }}, which serializes them as safely escaped JSON strings.
  3. Because Kestra renders variables lazily, both tasks use {{ renderOnce(vars.slack_payload) }} to expand the template exactly one time with the caller's inputs.
  4. The log task (io.kestra.plugin.core.log.Log) writes the final payload to the execution logs, which makes debugging formatting issues trivial.
  5. The slack task (io.kestra.plugin.slack.notifications.SlackIncomingWebhook) posts the rendered payload to the webhook URL stored as a secret.
  6. Callers invoke it with io.kestra.plugin.core.flow.Subflow, typically from an errors block, passing the failure context as the text input.

What you get

  • One source of truth for Slack alert formatting shared by every pipeline.
  • Rich Block Kit messages with a scannable header instead of a wall of plain text.
  • Safe JSON escaping via toJson, so stack traces and quotes cannot corrupt the payload.
  • A logged copy of every rendered payload for quick debugging.
  • The renderOnce pattern for building complex templated payloads in flow variables.

Who it's for

  • Data and platform teams standardizing failure notifications across many flows.
  • Anyone who has shipped a Slack alert that silently failed because of an unescaped quote.
  • Teams that want alert formatting changes to roll out everywhere with one deployment.

Why orchestrate this with Kestra

Copy pasting webhook tasks into every flow guarantees drift: some alerts get the new format, others keep the old one, and each copy escapes JSON slightly differently. Kestra subflows turn the alert into a versioned, callable unit with typed inputs. The variable plus renderOnce pattern keeps the Block Kit template readable, the secret store keeps the webhook out of source, and every alert sent is itself an execution you can inspect and replay.

Prerequisites

  • A Slack app or integration with an incoming webhook pointing at the target channel.
  • Calling flows that pass their failure context, for example "{{ errorLogs() }}" or a link to the execution, as the text input.

Secrets

  • SLACK_WEBHOOK: the Slack incoming webhook URL used by SlackIncomingWebhook.

Quick start

  1. Add the SLACK_WEBHOOK secret to your Kestra namespace.
  2. Deploy the flow and execute it manually with a test text value to confirm the channel and formatting.
  3. In any pipeline, add an errors block with an io.kestra.plugin.core.flow.Subflow task targeting this flow's id and namespace, passing text and optionally header.
  4. Force a failure in the calling flow and watch the formatted alert arrive in Slack.

How to extend

  • Add a severity input that switches header wording or emoji per level.
  • Append a context block with the execution id and a deep link to the Kestra UI.
  • Add an image or divider block to the payload for richer layouts.
  • Route to different webhooks per team by making the secret name an input.
  • Pair it with a Flow trigger to turn this into fully automatic, centralized failure alerting.

Links

Orchestrate with Kestra
Orchestrate Slack with Kestra
Share this Blueprint
See How

New to Kestra?

Use blueprints to kickstart your first workflows.