【发布时间】:2022-01-12 19:05:22
【问题描述】:
尽管有人问过这个问题。我正在尝试通过 slack chat.post 消息 api this link 向 slack 频道发送消息 但是消息没有发送到频道,我正在收到
successfully completed post_reports_to_slack and status code 200
代码是:
import requests
def post_image():
url="https://slack.com/api/chat.postMessage"
data = {
"token": "xoxb-7701412070-tooken",
"channels": ['#channel_name'],
"text":"Message to send",
}
response = requests.post(
url=url, data=data,
headers={"Content-Type": "application/json"})
#response = requests.post(url=url, data=payload, params=data, files=file_upload)
if response.status_code == 200:
print("successfully completed post_reports_to_slack "
"and status code %s" % response.status_code)
else:
print("Failed to post report on slack channel "
"and status code %s" % response.status_code)
post_image()
我也尝试使用 post file api 发送文件,它工作正常。使用 webhooks 也工作正常。但我想通过 chat.post 消息 API 发送消息。
【问题讨论】:
标签: python api slack slack-api