Module Contents



Creates a Slack API Connection to be used for calls.

class airflow.providers.slack.hooks.slack.SlackHook(*, slack_conn_id=default_conn_name, base_url=None, timeout=None, proxy=None, retry_handlers=None, **extra_client_args)[source]

Bases: airflow.hooks.base.BaseHook

Creates a Slack API Connection to be used for calls.

This class provide a thin wrapper around the slack_sdk.WebClient.


This hook intend to use Slack API connection and might not work correctly with Slack Incoming Webhook and HTTP connections.

Takes both Slack API token directly and connection that has Slack API token. If both are supplied, Slack API token will be used. Also exposes the rest of slack.WebClient args.

# Create hook
slack_hook = SlackHook(slack_conn_id="slack_api_default")

# Call generic API with parameters (errors are handled by hook)
#  For more details check"chat.postMessage", json={"channel": "#random", "text": "Hello world!"})

# Call method from Slack SDK (you have to handle errors yourself)
#  For more details check
slack_hook.client.chat_postMessage(channel="#random", text="Hello world!")
  • slack_conn_id (str) – Slack connection id that has Slack API token in the password field.

  • timeout (int | None) – The maximum number of seconds the client will wait to connect and receive a response from Slack. If not set than default WebClient value will use.

  • base_url (str | None) – A string representing the Slack API base URL. If not set than default WebClient BASE_URL will use (

  • proxy (str | None) – Proxy to make the Slack API call.

  • retry_handlers (list[slack_sdk.http_retry.RetryHandler] | None) – List of handlers to customize retry logic in slack_sdk.WebClient.

conn_name_attr = 'slack_conn_id'[source]
default_conn_name = 'slack_api_default'[source]
conn_type = 'slack'[source]
hook_name = 'Slack API'[source]

Get the underlying slack_sdk.WebClient (cached).


Get the underlying slack_sdk.WebClient (cached).

call(api_method, **kwargs)[source]

Calls Slack WebClient WebClient.api_call with given arguments.

  • api_method (str) – The target Slack API method. e.g. ‘chat.postMessage’. Required.

  • http_verb – HTTP Verb. Optional (defaults to ‘POST’)

  • files – Files to multipart upload. e.g. {imageORfile: file_objectORfile_path}

  • data – The body to attach to the request. If a dictionary is provided, form-encoding will take place. Optional.

  • params – The URL parameters to append to the URL. Optional.

  • json – JSON for the body to attach to the request. Optional.


The server’s response to an HTTP request. Data from the response can be accessed like a dict. If the response included ‘next_cursor’ it can be iterated on to execute subsequent requests.

Return type


send_file(*, channels=None, file=None, content=None, filename=None, filetype=None, initial_comment=None, title=None)[source]

Create or upload an existing file.

  • channels (str | Sequence[str] | None) – Comma-separated list of channel names or IDs where the file will be shared. If omitting this parameter, then file will send to workspace.

  • file (str | pathlib.Path | None) – Path to file which need to be sent.

  • content (str | None) – File contents. If omitting this parameter, you must provide a file.

  • filename (str | None) – Displayed filename.

  • filetype (str | None) – A file type identifier.

  • initial_comment (str | None) – The message text introducing the file in specified channels.

  • title (str | None) – Title of file.


Tests the Slack API connection.

classmethod get_connection_form_widgets()[source]

Returns dictionary of widgets to be added for the hook to handle extra values.

classmethod get_ui_field_behaviour()[source]

Returns custom field behaviour.

Was this entry helpful?