airflow.providers.slack.hooks.slack
¶
Hook for Slack
Module Contents¶
-
class
airflow.providers.slack.hooks.slack.
SlackHook
(token: Optional[str] = None, slack_conn_id: Optional[str] = None, **client_args)[source]¶ Bases:
airflow.hooks.base.BaseHook
Creates a Slack connection, to be used for calls. Takes both Slack API token directly and connection that has Slack API token. If both supplied, Slack API token will be used. Exposes also the rest of slack.WebClient args Examples:
# Create hook slack_hook = SlackHook(token="xxx") # or slack_hook = SlackHook(slack_conn_id="slack") # Call generic API with parameters (errors are handled by hook) # For more details check https://api.slack.com/methods/chat.postMessage slack_hook.call("chat.postMessage", json={"channel": "#random", "text": "Hello world!"}) # Call method from Slack SDK (you have to handle errors yourself) # For more details check https://slack.dev/python-slack-sdk/web/index.html#messaging slack_hook.client.chat_postMessage(channel="#random", text="Hello world!")
- Parameters
token (str) -- Slack API token
slack_conn_id (str) -- connection that has Slack API token in the password field
use_session (bool) -- A boolean specifying if the client should take advantage of connection pooling. Default is True.
base_url (str) -- A string representing the Slack API base URL. Default is
https://www.slack.com/api/
timeout (int) -- The maximum number of seconds the client will wait to connect and receive a response from Slack. Default is 30 seconds.
-
call
(self, api_method: str, *args, **kwargs)[source]¶ Calls Slack WebClient WebClient.api_call with given arguments.
- Parameters
api_method (str) -- The target Slack API method. e.g. 'chat.postMessage'. Required.
http_verb (str) -- HTTP Verb. Optional (defaults to 'POST')
files (dict) -- Files to multipart upload. e.g. {imageORfile: file_objectORfile_path}
data (dict or aiohttp.FormData) -- The body to attach to the request. If a dictionary is provided, form-encoding will take place. Optional.
params (dict) -- The URL parameters to append to the URL. Optional.
json (dict) -- JSON for the body to attach to the request. Optional.