SlackHook

Slack

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:

View Source

Last Updated: May. 14, 2021

Access Instructions

Install the Slack provider package into your Airflow environment.

Import the module into your DAG file and instantiate it with your desired params.

Parameters

tokenstrSlack API token
slack_conn_idstrconnection that has Slack API token in the password field
use_sessionboolA boolean specifying if the client should take advantage of connection pooling. Default is True.
base_urlstrA string representing the Slack API base URL. Default is https://www.slack.com/api/
timeoutintThe maximum number of seconds the client will wait to connect and receive a response from Slack. Default is 30 seconds.

Documentation

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!")

Example DAGs

Improve this module by creating an example DAG.

View Source
  1. Add an `example_dags` directory to the top-level source of the provider package with an empty `__init__.py` file.
  2. Add your DAG to this directory. Be sure to include a well-written and descriptive docstring
  3. Create a pull request against the source code. Once the package gets released, your DAG will show up on the Registry.

Was this page helpful?