Slack Incoming Webhook 操作符

SlackWebhookOperator

使用 SlackWebhookOperator 通过 Incoming Webhook 向预定义的 Slack 频道发送消息

使用操作符

您可以发送简单的文本消息

tests/system/slack/example_slack_webhook.py[源码]

slack_webhook_operator_text = SlackWebhookOperator(
    task_id="slack_webhook_send_text",
    slack_webhook_conn_id=SLACK_WEBHOOK_CONN_ID,
    message=(
        "Apache Airflow® is an open-source platform for developing, "
        "scheduling, and monitoring batch-oriented workflows."
    ),
)

或者您可以使用 Block Kit 来创建应用布局

tests/system/slack/example_slack_webhook.py[源码]

slack_webhook_operator_blocks = SlackWebhookOperator(
    task_id="slack_webhook_send_blocks",
    slack_webhook_conn_id=SLACK_WEBHOOK_CONN_ID,
    blocks=[
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": (
                    "*<https://github.com/apache/airflow|Apache Airflow®>* "
                    "is an open-source platform for developing, scheduling, "
                    "and monitoring batch-oriented workflows."
                ),
            },
            "accessory": {"type": "image", "image_url": IMAGE_URL, "alt_text": "Pinwheel"},
        }
    ],
    message="Fallback message",
)

此条目是否对您有帮助?