airflow.providers.slack.operators.slack

Module Contents

Classes

SlackAPIOperator

Base Slack Operator class.

SlackAPIPostOperator

Post messages to a Slack channel.

SlackAPIFileOperator

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, **kwargs)[source]

Bases: airflow.models.BaseOperator

Base Slack Operator class.

Parameters
hook()[source]

Slack Hook.

abstract construct_api_call_params()[source]

API call parameters used by the execute function.

Allows 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)

execute(**kwargs)[source]

Derive when creating an operator.

Context is the same dictionary used as when rendering jinja templates.

Refer to get_template_context for more context.

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', attachments=None, blocks=None, **kwargs)[source]

Bases: SlackAPIOperator

Post messages to a Slack channel.

slack = SlackAPIPostOperator(
    task_id="post_hello",
    dag=dag,
    token="...",
    text="hello there!",
    channel="#random",
)
Parameters
template_fields: Sequence[str] = ('username', 'text', 'attachments', 'blocks', 'channel')[source]
ui_color = '#FFBA40'[source]
construct_api_call_params()[source]

API call parameters used by the execute function.

Allows 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, channel=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)

  • channel (str | None) – (deprecated) channel in which to sent file on slack name

template_fields: Sequence[str] = ('channels', 'initial_comment', 'filename', 'filetype', 'content', 'title')[source]
ui_color = '#44BEDF'[source]
execute(**kwargs)[source]

Derive when creating an operator.

Context is the same dictionary used as when rendering jinja templates.

Refer to get_template_context for more context.

Was this entry helpful?