airflow.providers.slack.hooks.slack_webhook

Module Contents

Classes

SlackWebhookHook

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

Functions

check_webhook_response(func)

Function decorator that check WebhookResponse and raise an error if status code != 200.

Attributes

DEFAULT_SLACK_WEBHOOK_ENDPOINT

LEGACY_INTEGRATION_PARAMS

airflow.providers.slack.hooks.slack_webhook.DEFAULT_SLACK_WEBHOOK_ENDPOINT = https://hooks.slack.com/services[source]
airflow.providers.slack.hooks.slack_webhook.LEGACY_INTEGRATION_PARAMS = ['channel', 'username', 'icon_emoji', 'icon_url'][source]
airflow.providers.slack.hooks.slack_webhook.check_webhook_response(func)[source]

Function decorator that check WebhookResponse and raise an error if status code != 200.

class airflow.providers.slack.hooks.slack_webhook.SlackWebhookHook(slack_webhook_conn_id=None, webhook_token=None, timeout=None, proxy=None, retry_handlers=None, **kwargs)[source]

Bases: airflow.hooks.base.BaseHook

This class provide a thin wrapper around the slack_sdk.WebhookClient. This hook allows you to post messages to Slack by using Incoming Webhooks.

Note

You cannot override the default channel (chosen by the user who installed your app), username, or icon when you’re using Incoming Webhooks to post messages. Instead, these values will always inherit from the associated Slack App configuration (link). It is possible to change this values only in Legacy Slack Integration Incoming Webhook.

Warning

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

Examples:
# Create hook
hook = SlackWebhookHook(slack_webhook_conn_id="slack_default")

# Post message in Slack channel by JSON formatted message
# See: https://api.slack.com/messaging/webhooks#posting_with_webhooks
hook.send_dict({"text": "Hello world!"})

# Post simple message in Slack channel
hook.send_text("Hello world!")

# Use ``slack_sdk.WebhookClient``
hook.client.send(text="Hello world!")
Parameters
  • slack_webhook_conn_id (str | None) – Slack Incoming Webhook connection id that has Incoming Webhook 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 WebhookClient value will use.

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

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

  • webhook_token (str | None) – (deprecated) Slack Incoming Webhook token. Use instead Slack Incoming Webhook connection password field.

conn_name_attr = slack_webhook_conn_id[source]
default_conn_name = slack_default[source]
conn_type = slackwebhook[source]
hook_name = Slack Incoming Webhook[source]
client()[source]

Get the underlying slack_sdk.webhook.WebhookClient (cached).

get_conn()[source]

Get the underlying slack_sdk.webhook.WebhookClient (cached).

webhook_token()[source]

Return Slack Webhook Token URL.

send_dict(body, *, headers=None)[source]

Performs a Slack Incoming Webhook request with given JSON data block.

Parameters
  • body (dict[str, Any] | str) – JSON data structure, expected dict or JSON-string.

  • headers (dict[str, str] | None) – Request headers for this request.

send(*, text=None, attachments=None, blocks=None, response_type=None, replace_original=None, delete_original=None, unfurl_links=None, unfurl_media=None, headers=None, **kwargs)[source]

Performs a Slack Incoming Webhook request with given arguments.

Parameters
  • text (str | None) – The text message (even when having blocks, setting this as well is recommended as it works as fallback).

  • attachments (list[dict[str, Any]] | None) – A collection of attachments.

  • blocks (list[dict[str, Any]] | None) – A collection of Block Kit UI components.

  • response_type (str | None) – The type of message (either ‘in_channel’ or ‘ephemeral’).

  • replace_original (bool | None) – True if you use this option for response_url requests.

  • delete_original (bool | None) – True if you use this option for response_url requests.

  • unfurl_links (bool | None) – Option to indicate whether text url should unfurl.

  • unfurl_media (bool | None) – Option to indicate whether media url should unfurl.

  • headers (dict[str, str] | None) – Request headers for this request.

send_text(text, *, unfurl_links=None, unfurl_media=None, headers=None)[source]

Performs a Slack Incoming Webhook request with given text.

Parameters
  • text (str) – The text message.

  • unfurl_links (bool | None) – Option to indicate whether text url should unfurl.

  • unfurl_media (bool | None) – Option to indicate whether media url should unfurl.

  • headers (dict[str, str] | None) – Request headers for this request.

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.

execute()[source]

Remote Popen (actually execute the slack webhook call).

Note

This method exist for compatibility with previous version of operator and expected that Slack Incoming Webhook message constructing from class attributes rather than pass as method arguments.

Was this entry helpful?