Answers for "python code to send file in slack bot"

1

slack send message python

import os
import slack

slack_token = os.environ["SLACK_API_TOKEN"]
client = slack.WebClient(token=slack_token)

client.chat_postMessage(
  channel="C0XXXXXX",
  text="Hello from your app! :tada:"
)
Posted by: Guest on January-11-2020
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"
        }
Posted by: Guest on August-13-2020

Code answers related to "python code to send file in slack bot"

Python Answers by Framework

Browse Popular Code Answers by Language