Slack connection¶
Send messages / alerts to Slack from a task via a managed Leoflow Connection.
Two conn types ship: slack (Slack API, a bot token) and slackwebhook (an
Incoming Webhook URL). Use slack for rich API calls, slackwebhook for a
fire-and-forget message to one channel.
Declare the provider¶
Fields the UI asks for¶
slack (API):
| Field | Where it goes | Notes |
|---|---|---|
| Conn Id | โ | e.g. slack_default. |
| Password | password | The bot token (xoxb-โฆ). Encrypted at rest (ADR 0019). |
| Base URL / Timeout | extra | Optional API tuning. |
slackwebhook: put the webhook path in the connection (host
hooks.slack.com, password = the T00/B00/XXXX token segment), or the full URL
in Extra {"webhook_token": "โฆ"}.
The token round-trip (reserved characters included) is pinned by
TestSlackConnectionURIShapeIntegration.
Example DAG (copy-paste)¶
Docs-only recipe (needs a Slack workspace + bot token). The hook is imported inside the task.
# dag.py
from __future__ import annotations
from airflow.sdk import DAG, task
@task
def notify() -> None:
from airflow.providers.slack.hooks.slack import SlackHook
hook = SlackHook(slack_conn_id="slack_default")
print("notify: posting message via SlackHook(slack_default)")
hook.call(
"chat.postMessage",
json={"channel": "#data-alerts", "text": "Leoflow run finished โ
"},
)
with DAG("slack_alert", schedule=None, catchup=False, tags=["example"]):
notify()
# leoflow.yaml
schema_version: "1.0"
dag_id: slack_alert
description: Post a message to Slack via SlackHook.
owner: examples
tags:
- example
python_version: "3.11"
connectors:
- slack
Run it¶
- Create a Slack app with a bot token (
chat:writescope), invite the bot to the channel. - Admin โ Connections โ +, type
slack, paste the token in Password. leoflow lite path/to/this/dagโ triggerslack_alertโ check the channel.
Security notes¶
- The bot token is a secret โ it is encrypted at rest and never echoed back by the
form. Scope it to the minimum (
chat:write). - Never
print()the URI โ it carries the token.
Related¶
docs/connections/index.mdโ Installing a connector's provider.- ADR 0019 / 0021 โ secret encryption + agent delivery.