requestsでSlackに画像送信 [Python]
Incoming Webhookをチャンネルにインストールし、TOKENとCHANNEL IDを取得していることが前提条件。
import requestsTOKEN = "xxxxxxxxxxxxxxxxxxx"CHANNEL = "yyyyyyyyyyyyyyyy"
src = "/home/ubuntu/picture/hoge.jpg"
files = {"file": open(src, "rb")}
param = { "token":TOKEN, "channels":CHANNEL, "filename":"hoge.jpg", "initial_comment":"hello world!", "title":"this is title" }
requests.post(url="https://slack.com/api/files.upload", params=param, files=files)