Apache Airflow Slack Provider

9.9.0 · active · verified Thu Apr 09

The Apache Airflow Slack provider package enables interaction with Slack, offering operators and hooks to send messages, upload files, and integrate with Slack workflows. It includes `SlackOperator` for the Slack API and `SlackWebhookOperator` for incoming webhooks. The current version is 9.9.0, and provider packages typically release independently of core Airflow, often aligning with Airflow's major releases or critical bug fixes.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the `SlackWebhookOperator` to send a message to a Slack channel. You need to configure an Airflow Connection named `slack_webhook_default` of type `HTTP` with your Slack Incoming Webhook URL in the 'Host' field.

from airflow.providers.slack.operators.slack_webhook import SlackWebhookOperator
from airflow.models.dag import DAG
from datetime import datetime

# IMPORTANT: For this DAG to send messages, an Airflow Connection named 'slack_webhook_default'
# must be configured. It should be an 'HTTP' connection type, with your Slack Incoming Webhook URL
# placed in the 'Host' field (e.g., https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX).
# For local testing without sending actual messages, you can create a dummy HTTP connection.

with DAG(
    dag_id='slack_webhook_quickstart',
    start_date=datetime(2023, 1, 1),
    schedule=None, # This DAG runs manually
    catchup=False,
    tags=['slack', 'example'],
) as dag:
    send_message_to_slack = SlackWebhookOperator(
        task_id='send_message_to_slack',
        slack_webhook_conn_id='slack_webhook_default',
        message="Hello from Airflow! This is a test message from the quickstart DAG. :airflow:",
        channel="#general" # Specify the Slack channel (optional, overrides default webhook channel)
    )

view raw JSON →