Pyhton code to send file to slack

Code examples

0
0

pyhton code to send file to slack

def send_file_to_slack(file_path):
	url = "https://slack.com/api/files.upload"

    # this is where you add your query string. Please chage token value
    querystring = {"token": xxxxxxx}

    # this is where you define who do you want to send it to. Change channels to your target one
    payload = {
        "channels": xxxxxxxx,  # slack channel id 
        "initial_comment": comment above the file should be here"
    }

    file_upload = {
        "file": (file_path, open(file_path, 'rb'), 'csv')
    }

    response = requests.post(url, data=payload, params=querystring, files=file_upload)

    if response.ok:
        return {
            "message": "Successfully uploaded the file to slack"
        }

Similar pages

Similar pages with examples

In other languages

This page is in other languages

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................