SqlToSlackApiFileOperator¶
Use the SqlToSlackApiFileOperator
to post query result as a file
to Slack channel(s) through Slack API.
Using the Operator¶
Note
Operator supports two methods for upload files, which controlled by slack_method_version
,
by default it use Slack SDK method upload_files_v2
it is possible to use legacy upload_files
method by set v1
to slack_method_version
however this not recommended because it
might impact a performance, cause random API errors and is being sunset on March 11, 2025 in addition
beginning May 8, 2024, newly-created apps will be unable to use this API method.
If you previously use v1
you should check that your application has appropriate scopes:
files:write - for write files.
files:read - for read files (not required if you use Slack SDK >= 3.23.0).
channels:read - get list of public channels, for convert Channel Name to Channel ID.
groups:read - get list of private channels, for convert Channel Name to Channel ID
mpim:read - additional permission for API method conversations.list
im:read - additional permission for API method conversations.list
This operator will execute a custom query in the provided SQL connection and publish a file to Slack channel(s).
An example usage of the SqlToSlackApiFileOperator is as follows:
SqlToSlackApiFileOperator(
task_id="sql_to_slack_api_file",
sql_conn_id=SQL_CONN_ID,
sql="SELECT 6 as multiplier, 9 as multiplicand, 42 as answer",
slack_channels="C123456",
slack_conn_id="slack_api_default",
slack_filename="awesome.json.gz",
slack_initial_comment="Awesome compressed multiline JSON.",
df_kwargs={"orient": "records", "lines": True},
)