lamby / django-slack

Slack integration for Django, using the templating engine to generate messages
https://django-slack.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
241 stars 57 forks source link

Uploading a file with a message #94

Open camuthig opened 4 years ago

camuthig commented 4 years ago

I recently needed to implement a new feature where I uploaded a CSV file to Slack along with a the message I was sending. I was not able to implement this using django-slack natively, so had to access the files.upload Slack API directly instead. I haven't yet thought of a clean way to do it, but what are your thoughts on providing some sort of support for file uploads in this project?

lamby commented 4 years ago

The API docs are here: https://api.slack.com/methods/files.upload

No strong feelings about how this should be done, but looks like it will need a new top-level method we export publically in api.py. What do you think? Will probably have to abstract out a bunch of config handling...

camuthig commented 4 years ago

My initial thought was that it would need to be a new top-level method as well, but wasn't certain. For a first implementation, I think you could leave it up to the developer to create the content of the upload, rather than use file. I only did some basic testing, but using content worked well for me right out of the box with the default backend, at least.

Fields that would be fairly easy and could work with logic already present in the existing templates are:

Otherwise, the only new fields I think you need are

lamby commented 4 years ago

Cool, thanks for your input - really useful. (Just to let you know though - I don't have the ability to prioritise this volunteer work right now around my other work and stuff.)

camuthig commented 4 years ago

Not a problem. I have a working implementation on my side for specifically what I need. If I come across some time, I'll see if I can work through a PR for you as well.

lamby commented 4 years ago

If you could paste your code here that would be good, even without any other context or even if it's broken - will provide a good place to start. :+1: