blob: e1574e4593d829dc26001408a90764f66a9650d6 [file] [log] [blame]
:py:mod:`airflow.providers.slack.operators.slack`
=================================================
.. py:module:: airflow.providers.slack.operators.slack
Module Contents
---------------
Classes
~~~~~~~
.. autoapisummary::
airflow.providers.slack.operators.slack.SlackAPIOperator
airflow.providers.slack.operators.slack.SlackAPIPostOperator
airflow.providers.slack.operators.slack.SlackAPIFileOperator
.. py:class:: SlackAPIOperator(*, slack_conn_id = None, token = None, method = None, api_params = None, **kwargs)
Bases: :py:obj:`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.
:param slack_conn_id: :ref:`Slack API Connection <howto/connection:slack>`
which its password is Slack API token. Optional
:param token: Slack API token (https://api.slack.com/web). Optional
:param method: The Slack API Method to Call (https://api.slack.com/methods). Optional
:param api_params: API Method call parameters (https://api.slack.com/methods). Optional
:param client_args: Slack Hook parameters. Optional. Check airflow.providers.slack.hooks.SlackHook
.. py:method:: hook()
Slack Hook.
.. py:method:: construct_api_call_params()
:abstractmethod:
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)
.. py:method:: execute(**kwargs)
This is the main method to derive when creating an operator.
Context is the same dictionary used as when rendering jinja templates.
Refer to get_template_context for more context.
.. py:class:: 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', attachments = None, blocks = None, **kwargs)
Bases: :py:obj:`SlackAPIOperator`
Posts messages to a slack channel
Examples:
.. code-block:: python
slack = SlackAPIPostOperator(
task_id="post_hello",
dag=dag,
token="XXX",
text="hello there!",
channel="#random",
)
:param channel: channel in which to post message on slack name (#general) or
ID (C12318391). (templated)
:param username: Username that airflow will be posting to Slack as. (templated)
:param text: message to send to slack. (templated)
:param icon_url: url to icon used for this message
:param attachments: extra formatting details. (templated)
- see https://api.slack.com/docs/attachments.
:param blocks: extra block layouts. (templated)
- see https://api.slack.com/reference/block-kit/blocks.
.. py:attribute:: template_fields
:annotation: :Sequence[str] = ['username', 'text', 'attachments', 'blocks', 'channel']
.. py:attribute:: ui_color
:annotation: = #FFBA40
.. py:method:: construct_api_call_params()
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)
.. py:class:: SlackAPIFileOperator(channels = None, initial_comment = None, filename = None, filetype = None, content = None, title = None, channel = None, **kwargs)
Bases: :py:obj:`SlackAPIOperator`
Send a file to a slack channels
Examples:
.. code-block:: python
# 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",
)
:param channels: 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)
:param initial_comment: message to send to slack. (templated)
:param filename: name of the file (templated)
:param filetype: slack filetype. (templated) See: https://api.slack.com/types/file#file_types
:param content: file content. (templated)
:param title: title of file. (templated)
:param channel: (deprecated) channel in which to sent file on slack name
.. py:attribute:: template_fields
:annotation: :Sequence[str] = ['channels', 'initial_comment', 'filename', 'filetype', 'content', 'title']
.. py:attribute:: ui_color
:annotation: = #44BEDF
.. py:method:: execute(**kwargs)
This is the main method to derive when creating an operator.
Context is the same dictionary used as when rendering jinja templates.
Refer to get_template_context for more context.