Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a csv attachment to slack webhook in python

I'm trying to use a Slack webhook to notify a channel about a csv file for that day as well as post a link to it to attach. https://api.slack.com/docs/message-attachments doesn't use any examples of actual attachments and only includes links. I'm wondering if its even possible to send a csv file that my code is generating and attaching it from its path via os.path.basename(csvfile)

I'm trying use the format thats demonstrated here: https://gist.github.com/devStepsize/b1b795309a217d24566dcc0ad136f784 but am not sure if this allows for actual file attachments. So, I'd appreciate any help/direction in this matter. Is it even possible to send file attachments via a Slack webhook and if so, how should one go about doing so?

like image 290
Keyadun Avatar asked Oct 21 '25 14:10

Keyadun


1 Answers

No, you can not attach a file via webhook. You can only include media links for specific formats that will then automatically be unfurled, e.g. images or videos.

To send a file into a channel you need to upload and share it in the channel via Slack API. The API method files.upload has that exact purpose. Make sure to include the channel ID in the channels property to enable the optional sharing function.

Note that for using the Slack Web API you will need a token.

like image 182
Erik Kalkoken Avatar answered Oct 24 '25 05:10

Erik Kalkoken



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!