Slack 入站 Webhook 运算符

SlackWebhookOperator

使用 SlackWebhookOperator 通过 入站 Webhook 向预定义的 Slack 频道发布消息

使用运算符

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

tests/system/providers/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/providers/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",
)

此条目是否有用?