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
however this might impact a performance and cause random API errors.
It is recommended to switch to Slack SDK method upload_files_v2
by set v2
to slack_method_version
,
however this action required to add additional scope to your application:
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},
)