airflow.providers.slack.operators.slack
¶
Module Contents¶
Classes¶
Base Slack Operator class. |
|
Post messages to a Slack channel. |
|
Send a file to a Slack channel. |
- class airflow.providers.slack.operators.slack.SlackAPIOperator(*, slack_conn_id=SlackHook.default_conn_name, method=None, api_params=None, base_url=None, proxy=None, timeout=None, retry_handlers=None, **kwargs)[source]¶
Bases:
airflow.models.BaseOperator
Base Slack Operator class.
- Parameters
slack_conn_id (str) – Slack API Connection which its password is Slack API token.
method (str | None) – The Slack API Method to Call (https://api.slack.com/methods).
api_params (dict | None) – API Method call parameters (https://api.slack.com/methods). Optional
timeout (int | None) – The maximum number of seconds the client will wait to connect and receive a response from Slack. Optional
base_url (str | None) – A string representing the Slack API base URL. Optional
proxy (str | None) – Proxy to make the Slack API call. Optional
retry_handlers (list[slack_sdk.http_retry.RetryHandler] | None) – List of handlers to customize retry logic in
slack_sdk.WebClient
. Optional
- abstract construct_api_call_params()[source]¶
Construct API call parameters used by the execute function.
Allow templating on the source fields of the
api_call_params
dict before construction.Child classes should override this. Each SlackAPIOperator child class is responsible for having function set
self.api_call_params
with a dict of API call parameters (https://api.slack.com/methods)
- class airflow.providers.slack.operators.slack.SlackAPIPostOperator(channel='#general', username='Airflow', text='No message has been set.\nHere is a cat video instead\nhttps://www.youtube.com/watch?v=J---aiyznGQ', icon_url='https://raw.githubusercontent.com/apache/airflow/main/airflow/www/static/pin_100.png', blocks=None, attachments=None, **kwargs)[source]¶
Bases:
SlackAPIOperator
Post messages to a Slack channel.
slack = SlackAPIPostOperator( task_id="post_hello", dag=dag, text="hello there!", channel="#random", )
- Parameters
channel (str) – channel in which to post message on slack name (#general) or ID (C12318391). (templated)
username (str) – Username that airflow will be posting to Slack as. (templated)
text (str) – message to send to slack. (templated)
icon_url (str) – URL to icon used for this message
blocks (list | None) – A list of blocks to send with the message. (templated) See https://api.slack.com/reference/block-kit/blocks
attachments (list | None) – (legacy) A list of attachments to send with the message. (templated) See https://api.slack.com/docs/attachments
- construct_api_call_params()[source]¶
Construct API call parameters used by the execute function.
Allow templating on the source fields of the
api_call_params
dict before construction.Child classes should override this. Each SlackAPIOperator child class is responsible for having function set
self.api_call_params
with a dict of API call parameters (https://api.slack.com/methods)
- class airflow.providers.slack.operators.slack.SlackAPIFileOperator(channels=None, initial_comment=None, filename=None, filetype=None, content=None, title=None, method_version='v2', channel=NOTSET, snippet_type=None, **kwargs)[source]¶
Bases:
SlackAPIOperator
Send a file to a Slack channel.
# Send file with filename and filetype slack_operator_file = SlackAPIFileOperator( task_id="slack_file_upload_1", dag=dag, slack_conn_id="slack", channels="#general,#random", initial_comment="Hello World!", filename="/files/dags/test.txt", filetype="txt", ) # Send file content slack_operator_file_content = SlackAPIFileOperator( task_id="slack_file_upload_2", dag=dag, slack_conn_id="slack", channels="#general", initial_comment="Hello World!", content="file content in txt", )
- Parameters
channels (str | Sequence[str] | None) – Comma-separated list of channel names or IDs where the file will be shared. If set this argument to None, then file will send to associated workspace. (templated)
initial_comment (str | None) – message to send to slack. (templated)
filename (str | None) – name of the file (templated)
filetype (str | None) – slack filetype. (templated) See: https://api.slack.com/types/file#file_types
content (str | None) – file content. (templated)
title (str | None) – title of file. (templated)
snippet_type (str | None) – Syntax type for the snippet being uploaded.(templated)
method_version (typing_extensions.Literal[v1, v2]) – The version of the method of Slack SDK Client to be used, either “v1” or “v2”.