Slackapipostoperator

airflow_slack_notifications.md

commented Mar 6, 2020

Hi @ddelange, where i can find the method extract_domain?

commented Mar 6, 2020

@StefanoGITA here you go https://github.com/ddelange/PyArmyKnife/blob/69c76b70ca799f936667541d5a8d546c18e9c293/src/pyarmyknife/www.py#L38

commented Mar 6, 2020

Not getting Slack Notifications when dags fail, tried SlackWebhookOperator and SlackAPIPostOperator. Data engineer here, and a bit stuck! This is my code using SlackWebhookOperator, I used the same formatting when trying to use SlackAPIPostOperator except I had 'token' not webhooktoken'. Module Contents¶ class airflow.providers.slack.operators.slack.SlackAPIOperator (., slackconnid: Optional = None, token: Optional = None, method: Optional = None, apiparams: Optional Dict = None,. kwargs) source ¶. Bases: airflow.models.BaseOperator Base Slack Operator The SlackAPIPostOperator is derived from this operator. In the future additional Slack API Operators will. Note: This article covers information about legacy methods for adding integrations to your Slack workspace. Visit Slack API for the latest on platform features. API tokens can be created for both members and bot users. For added security, it’s a good idea to rotate these tokens periodically. In addition to these basic building blocks, there are many more specific operators: DockerOperator, HiveOperator, S3FileTransformOperator, PrestoToMySqlTransfer, SlackAPIOperator, etc. Using the Slack Web API The Slack Web API is an interface for querying information from and enacting change in a Slack workspace. Use it on the fly for ad-hoc queries, or as part of a more complex tapestry of platform features in a Slack app. What can you do with the Web API?

ThanksIl giorno ven 6 mar 2020 alle ore 13:42 david <[email protected]> hascritto:
@StefanoGITA <https://github.com/StefanoGITA> here you go https://github.com/ddelange/PyArmyKnife/blob/69c76b70ca799f936667541d5a8d546c18e9c293/src/pyarmyknife/www.py#L38 — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <https://gist.github.com/6e33f8f0df3a97d4a371d055aa2d58ac?email_source=notifications&email_token=AF4B4H4HQKCXEENZGMSBNFLRGDVR3A5CNFSM4LC6JQCKYY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAGDPE2#gistcomment-3202637>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AF4B4HYQXC6LKG476TN6JQDRGDVR3ANCNFSM4LC6JQCA> .
Slackapipostoperator
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Module Contents¶

class airflow.providers.slack.operators.slack.SlackAPIOperator(*, slack_conn_id:Optional[str]=None, token:Optional[str]=None, method:Optional[str]=None, api_params:Optional[Dict]=None, **kwargs)[source]

Bases: airflow.models.BaseOperator

Base Slack OperatorThe SlackAPIPostOperator is derived from this operator.In the future additional Slack API Operators will be derived from this class as wellOnly one of slack_conn_id and token is required.

Parameters
  • slack_conn_id (str) – Slack connection ID which its password is Slack API token. Optional

  • token (str) – Slack API token (https://api.slack.com/web). Optional

  • method (str) – The Slack API Method to Call (https://api.slack.com/methods). Optional

  • api_params (dict) – API Method call parameters (https://api.slack.com/methods). Optional

  • client_args – Slack Hook parameters. Optional. Check airflow.providers.slack.hooks.SlackHook

construct_api_call_params(self)[source]

Used by the execute function. Allows templating on the source fieldsof the api_call_params dict before construction

Override in child classes.Each SlackAPIOperator child class is responsible forhaving a construct_api_call_params functionwhich sets self.api_call_params with a dict ofAPI call parameters (https://api.slack.com/methods)

execute(self, **kwargs)[source]

SlackAPIOperator calls will not fail even if the call is not unsuccessful.It should not prevent a DAG from completing in success

class airflow.providers.slack.operators.slack.SlackAPIPostOperator(channel:str='#general', username:str='Airflow', text:str='No message has been set.nHere is a cat video insteadnhttps://www.youtube.com/watch?v=J---aiyznGQ', icon_url:str='https://raw.githubusercontent.com/apache/airflow/master/airflow/www/static/pin_100.png', attachments:Optional[List]=None, blocks:Optional[List]=None, **kwargs)[source]

Slackapipostoperator

Bases: airflow.providers.slack.operators.slack.SlackAPIOperator

Posts messages to a slack channelExamples:

Parameters
  • channel (str) – channel in which to post message on slack name (#general) orID (C12318391). (templated)

  • username (str) – Username that airflow will be posting to Slack as. (templated)

  • text (str) – message to send to slack. (templated)

  • icon_url (str) – url to icon used for this message

  • attachments (list of hashes) – extra formatting details. (templated)- see https://api.slack.com/docs/attachments.

  • blocks (list of hashes) – extra block layouts. (templated)- see https://api.slack.com/reference/block-kit/blocks.

template_fields = ['username', 'text', 'attachments', 'blocks', 'channel'][source]

Slackapipostoperator Example

ui_color = #FFBA40[source]
construct_api_call_params(self)[source]
class airflow.providers.slack.operators.slack.SlackAPIFileOperator(channel:str='#general', initial_comment:str='No message has been set!', filename:str='default_name.csv', filetype:str='csv', content:str='default,content,csv,file', **kwargs)[source]

Bases: airflow.providers.slack.operators.slack.SlackAPIOperator

Send a file to a slack channelExamples:

Slackapipostoperator Airflow

Parameters
  • channel (str) – channel in which to sent file on slack name (templated)

  • initial_comment (str) – message to send to slack. (templated)

  • filename (str) – name of the file (templated)

  • filetype (str) – slack filetype. (templated)- see https://api.slack.com/types/file

  • content (str) – file content. (templated)

template_fields = ['channel', 'initial_comment', 'filename', 'filetype', 'content'][source]
ui_color = #44BEDF[source]
construct_api_call_params(self)[source]