You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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!
fromairflow.utils.decoratorsimportapply_defaultsfromairflow.operators.slack_operatorimportSlackAPIOperatorclassSlackAPIFileOperator(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) :type content: str """template_fields= ('channel', 'initial_comment', 'filename', 'filetype', 'content')
ui_color='#44BEDF'@apply_defaultsdef__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=channelself.initial_comment=initial_commentself.filename=filenameself.filetype=filetypeself.content=contentsuper(SlackAPIFileOperator, self).__init__(method=self.method, *args, **kwargs)
defconstruct_api_call_params(self):
self.api_params= {
'channels': self.channel,
'content': self.content,
'filename': self.filename,
'filetype': self.filetype,
'initial_comment': self.initial_comment
}
The text was updated successfully, but these errors were encountered:
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)
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!
The text was updated successfully, but these errors were encountered: