pyhton code to send file to slack

Solutions on MaxInterview for pyhton code to send file to slack by the best coders in the world

showing results for - "pyhton code to send file to slack"
Simon
23 May 2020
1def send_file_to_slack(file_path):
2	url = "https://slack.com/api/files.upload"
3
4    # this is where you add your query string. Please chage token value
5    querystring = {"token": xxxxxxx}
6
7    # this is where you define who do you want to send it to. Change channels to your target one
8    payload = {
9        "channels": xxxxxxxx,  # slack channel id 
10        "initial_comment": comment above the file should be here"
11    }
12
13    file_upload = {
14        "file": (file_path, open(file_path, 'rb'), 'csv')
15    }
16
17    response = requests.post(url, data=payload, params=querystring, files=file_upload)
18
19    if response.ok:
20        return {
21            "message": "Successfully uploaded the file to slack"
22        }