如何使用机器人将文件上传到松弛通道

How to upload a file to a slack channel using a bot

我有一个 slack 机器人,以 xoxb 开头的令牌用于将文件上传到频道。

我使用以下格式

curl -F token="${SLACK_TOKEN}" -F file=e2e.sh -F channel="${SLACK_CHANNEL}" -F  as_user=true https://slack.com/api/files.upload

这抛出

{"ok":false,"error":"no_file_data"}

您在 file=e2e.sh 参数中缺少 @ 来让 curl 知道您要传输文件。以下应该可以解决问题:

curl \
  -F token="${SLACK_TOKEN}" \
  -F file=@e2e.sh \
  -F channel="${SLACK_CHANNEL}" \
  -F as_user=true \
  https://slack.com/api/files.upload

p.s。将长卷曲分成多行可以帮助您看得更清楚;)