You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/05/22 20:09:00 UTC
[GitHub] [airflow] mikaeld opened a new issue #8980: Add a SlackAPIFileOperator to send files on Slack
mikaeld opened a new issue #8980:
URL: https://github.com/apache/airflow/issues/8980
**Description**
airflow.operators.slack_operator only has the SlackAPIPostOperator implementing 'chat.postMessage' Slack API method. I created an Operator for the 'files.upload' API method for a project. Here's the code. It uses the same structure as SlackAPIPostOperator, inheriting from SlackAPIOperator.
**Use case / motivation**
Being able to send files to Slack using the API. Webhooks do not allow for files.
**Related Issues**
Code could be improved to be more generic. Open to suggestions!
```python
from airflow.utils.decorators import apply_defaults
from airflow.operators.slack_operator import SlackAPIOperator
class SlackAPIFileOperator(SlackAPIOperator):
"""
Send a file to a slack channel
:param channel: channel in which to sent file on slack name (#general) or
ID (C12318391). (templated)
:type channel: str
:param initial_comment: message to send to slack. (templated)
:type initial_comment: str
:param filename: name of the file
:type filename: str
:param filetype: slack filetype. (templated)
- see https://api.slack.com/types/file
:type filetype: str
:param content: file content. (templated)
- see https://api.slack.com/reference/block-kit/blocks.
:type content: str
"""
template_fields = ('channel', 'initial_comment', 'filename', 'filetype', 'content')
ui_color = '#44BEDF'
@apply_defaults
def __init__(self,
channel='#general',
initial_comment='No message has been set!',
filename='default_name.csv',
filetype='csv',
content='default,content,csv,file',
*args, **kwargs):
self.method = 'files.upload'
self.channel = channel
self.initial_comment = initial_comment
self.filename = filename
self.filetype = filetype
self.content = content
super(SlackAPIFileOperator, self).__init__(method=self.method, *args, **kwargs)
def construct_api_call_params(self):
self.api_params = {
'channels': self.channel,
'content': self.content,
'filename': self.filename,
'filetype': self.filetype,
'initial_comment': self.initial_comment
}
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] boring-cyborg[bot] commented on issue #8980: Add a SlackAPIFileOperator to send files on Slack
Posted by GitBox <gi...@apache.org>.
boring-cyborg[bot] commented on issue #8980:
URL: https://github.com/apache/airflow/issues/8980#issuecomment-632892218
Thanks for opening your first issue here! Be sure to follow the issue template!
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] mikaeld closed issue #8980: Add a SlackAPIFileOperator to send files on Slack
Posted by GitBox <gi...@apache.org>.
mikaeld closed issue #8980:
URL: https://github.com/apache/airflow/issues/8980
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] mikaeld commented on issue #8980: Add a SlackAPIFileOperator to send files on Slack
Posted by GitBox <gi...@apache.org>.
mikaeld commented on issue #8980:
URL: https://github.com/apache/airflow/issues/8980#issuecomment-633563635
Got it! PR https://github.com/apache/airflow/pull/9004
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] mik-laj commented on issue #8980: Add a SlackAPIFileOperator to send files on Slack
Posted by GitBox <gi...@apache.org>.
mik-laj commented on issue #8980:
URL: https://github.com/apache/airflow/issues/8980#issuecomment-632998881
Can you open PR? You don't need to create a isue if you want to share the code. The issue is only needed if it is a long-term task or you want someone else to do the task (communication tool)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org