| :py:mod:`airflow.providers.slack.hooks.slack` |
| ============================================= |
| |
| .. py:module:: airflow.providers.slack.hooks.slack |
| |
| .. autoapi-nested-parse:: |
| |
| Hook for Slack |
| |
| |
| |
| Module Contents |
| --------------- |
| |
| Classes |
| ~~~~~~~ |
| |
| .. autoapisummary:: |
| |
| airflow.providers.slack.hooks.slack.SlackHook |
| |
| |
| |
| |
| .. py:class:: SlackHook(token = None, slack_conn_id = None, **client_args) |
| |
| Bases: :py:obj:`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 are |
| supplied, Slack API token will be used. Also exposes the rest of slack.WebClient args. |
| Examples: |
| .. code-block:: python |
| |
| # 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!") |
| |
| :param token: Slack API token |
| :param slack_conn_id: :ref:`Slack connection id <howto/connection:slack>` |
| that has Slack API token in the password field. |
| :param use_session: A boolean specifying if the client should take advantage of |
| connection pooling. Default is True. |
| :param base_url: A string representing the Slack API base URL. Default is |
| ``https://www.slack.com/api/`` |
| :param timeout: The maximum number of seconds the client will wait |
| to connect and receive a response from Slack. Default is 30 seconds. |
| |
| .. py:method:: call(self, api_method, **kwargs) |
| |
| Calls Slack WebClient `WebClient.api_call` with given arguments. |
| |
| :param api_method: The target Slack API method. e.g. 'chat.postMessage'. Required. |
| :param http_verb: HTTP Verb. Optional (defaults to 'POST') |
| :param files: Files to multipart upload. e.g. {imageORfile: file_objectORfile_path} |
| :param data: The body to attach to the request. If a dictionary is provided, |
| form-encoding will take place. Optional. |
| :param params: The URL parameters to append to the URL. Optional. |
| :param json: JSON for the body to attach to the request. Optional. |
| :return: 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. |
| |
| |
| |