The Slack connector can be used to send messages to channels or individuals in Slack from your scripts in Peliqan. For example, you can implement data monitoring apps that send alerts to Slack in case of data problems such as missing data.
Connect Slack
In Peliqan, go to Connections, click “Add connection”, and select Slack from the list.
Complete the authorization flow by granting the Peliqan app access to your Slack account.
Send a message to Slack
Here’s an example on how to send a message to a Slack channel:
slack = pq.connect("Slack") # use your name of the connection
slack.add("message", channel = "QA", text = "Data quality alert")Example with a custom bot name:
slack.add("message",
channel = "QA",
text = "Data quality alert",
username = "my bot"
)Example sending a message to an individual on Slack (not a channel):
slack.add("message",
channel = "@some_user_name", # don't forget the "@" sign
text = "Data quality alert",
username = "my bot"
)Send a chart or other data visualisation to a Slack channel
Sending an image (file) to Slack is done in 3 steps:
- Get an upload URL from Slack and provide the file size:
slack_api.get('uploadurl', { 'length': file_size, 'filename': "chart.png" }) - Upload the file to the received upload URL:
requests.post(upload_url, files = {'file': open('chart.png', 'rb')}) - Tell Slack that the upload completed and post in a channel:
slack_api.add('uploadcomplete', { 'file_id': file_id, 'title': 'My chart', 'channel_id': channel_id })
Share a report in Slack
Similar to the above example, where we build an image of a report which was prepared in HTML.