Однако я хотел бы указать что-то вроде as_user (который доступен, когда используяchat.PostMessage), в результате чего загрузка будет выглядеть так, как если бы она была загружена указанным пользователем Slack. Возможно ли это?
У меня так:
Код: Выделить всё
upload_file(filepath='/path/to/file.jpg',
channels='#uploads',
title='my image',
initial_comment='pls give me some feedback!')
Код: Выделить всё
import os
import requests
TOKEN = your_token_here
def upload_file(
filepath,
channels,
filename=None,
content=None,
title=None,
initial_comment=None):
"""Upload file to channel
Note:
URLs can be constructed from:
https://api.slack.com/methods/files.upload/test
"""
if filename is None:
filename = os.path.basename(filepath)
data = {}
data['token'] = TOKEN
data['file'] = filepath
data['filename'] = filename
data['channels'] = channels
if content is not None:
data['content'] = content
if title is not None:
data['title'] = title
if initial_comment is not None:
data['initial_comment'] = initial_comment
filepath = data['file']
files = {
'file': (filepath, open(filepath, 'rb'), 'image/jpg', {
'Expires': '0'
})
}
data['media'] = files
response = requests.post(
url='https://slack.com/api/files.upload',
data=data,
headers={'Accept': 'application/json'},
files=files)
return response.text
Подробнее здесь: https://stackoverflow.com/questions/425 ... pi-as-user
Мобильная версия