airflow.providers.slack.operators.slack
¶
Module Contents¶
Classes¶
Base Slack Operator |
|
Posts messages to a slack channel |
|
Send a file to a slack channel |
- class airflow.providers.slack.operators.slack.SlackAPIOperator(*, slack_conn_id: Optional[str] = None, token: Optional[str] = None, method: Optional[str] = None, api_params: Optional[Dict] = None, **kwargs)[source]¶
Bases:
airflow.models.BaseOperator
Base Slack Operator The SlackAPIPostOperator is derived from this operator. In the future additional Slack API Operators will be derived from this class as well. Only one of slack_conn_id and token is required.
- Parameters
slack_conn_id (str) -- Slack connection id which its password is Slack API token. Optional
token (str) -- Slack API token (https://api.slack.com/web). Optional
method (str) -- The Slack API Method to Call (https://api.slack.com/methods). Optional
api_params (dict) -- API Method call parameters (https://api.slack.com/methods). Optional
client_args (dict) -- Slack Hook parameters. Optional. Check airflow.providers.slack.hooks.SlackHook
- abstract construct_api_call_params(self) Any [source]¶
Used by the execute function. Allows templating on the source fields of the api_call_params dict before construction
Override in child classes. Each SlackAPIOperator child class is responsible for having a construct_api_call_params function which sets self.api_call_params with a dict of API call parameters (https://api.slack.com/methods)
- class airflow.providers.slack.operators.slack.SlackAPIPostOperator(channel: str = '#general', username: str = 'Airflow', text: str = 'No message has been set.\nHere is a cat video instead\nhttps://www.youtube.com/watch?v=J---aiyznGQ', icon_url: str = 'https://raw.githubusercontent.com/apache/airflow/main/airflow/www/static/pin_100.png', attachments: Optional[List] = None, blocks: Optional[List] = None, **kwargs)[source]¶
Bases:
SlackAPIOperator
Posts messages to a slack channel Examples:
slack = SlackAPIPostOperator( task_id="post_hello", dag=dag, token="XXX", 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
attachments (list of hashes) -- extra formatting details. (templated) - see https://api.slack.com/docs/attachments.
blocks (list of hashes) -- extra block layouts. (templated) - see https://api.slack.com/reference/block-kit/blocks.
- construct_api_call_params(self) Any [source]¶
Used by the execute function. Allows templating on the source fields of the api_call_params dict before construction
Override in child classes. Each SlackAPIOperator child class is responsible for having a construct_api_call_params function which sets self.api_call_params with a dict of API call parameters (https://api.slack.com/methods)
- class airflow.providers.slack.operators.slack.SlackAPIFileOperator(channel: str = '#general', initial_comment: str = 'No message has been set!', filename: Optional[str] = None, filetype: Optional[str] = None, content: Optional[str] = None, **kwargs)[source]¶
Bases:
SlackAPIOperator
Send a file to a slack channel Examples:
# Send file with filename and filetype slack_operator_file = SlackAPIFileOperator( task_id="slack_file_upload_1", dag=dag, slack_conn_id="slack", channel="#general", 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", channel="#general", initial_comment="Hello World!", content="file content in txt", )
- Parameters
channel (str) -- channel in which to sent file on slack name (templated)
initial_comment (str) -- message to send to slack. (templated)
filename (str) -- name of the file (templated)
filetype (str) -- slack filetype. (templated) - see https://api.slack.com/types/file
content (str) -- file content. (templated)