Slack Incoming Webhook Operator¶
SlackWebhookOperator¶
使用 SlackWebhookOperator
将消息发布到预设的 Slack 频道,通过 Incoming Webhook
使用 Operator¶
你可以发送简单的文本消息
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",
)