【发布时间】:2020-06-06 09:00:33
【问题描述】:
我正在尝试简单的事情,使用 python 脚本将本地图片添加到我的 slack 频道。我还没有找到答案。我已经为我的频道创建了 Slack 应用程序,并拥有验证令牌和 APP ID。
我尝试了以下但没有结果:
import requests
files = {
'file': ('dog.jpg', open('dog.jpg', 'rb')),
'channels': (None, 'App ID,#channel'),
'token': (None, 'Verification Token'),
}
还有:
import os
from slack import WebClient
from slack.errors import SlackApiError
client = WebClient(token=os.environ['SLACK_API_TOKEN'])
try:
filepath="./tmp.txt"
response = client.files_upload(
channels='#random',
file=filepath)
assert response["file"] # the uploaded file
except SlackApiError as e:
# You will get a SlackApiError if "ok" is False
assert e.response["ok"] is False
assert e.response["error"] # str like 'invalid_auth', 'channel_not_found'
print(f"Got an error: {e.response['error']}")
response = requests.post('https://slack.com/api/files.upload', files=files)
在这里,当我将我的 Slack 应用程序令牌插入 SLACK_API_TOKEN 时,它会给我令牌错误。 任何人都知道将本地图像发布到 Slack 的快速简便的方法?
谢谢!
【问题讨论】: