Skip to content

Instantly share code, notes, and snippets.

@zyouyowa
Created February 27, 2017 13:33
Show Gist options
  • Save zyouyowa/18403983df9a0f5aef399dfb75638bc0 to your computer and use it in GitHub Desktop.
Save zyouyowa/18403983df9a0f5aef399dfb75638bc0 to your computer and use it in GitHub Desktop.
Slack APIのfiles.uploadで画像を投稿するやつ
# -*- coding: utf-8 -*-
import requests
url = 'https://slack.com/api/'
token = 'Slack Bot API Token'
def upload(filename, image, channels, filetype='jpg'):
joind_channels = ','.join(channels)
arguments = {
'token': token,
'title': filename,
'channels': joind_channels
}
res = requests.post(url + 'files.upload', params=arguments, files={'file':image})
print(res.json())
if __name__ == '__main__':
with open('mazaiosamu.jpg', 'rb') as file:
upload('mazaiosamu.jpg', file.read(), ['test'], 'jpg')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment