从 slack bot 访问 Slack 文件 [英] Access Slack files from a slack bot

查看:67
本文介绍了从 slack bot 访问 Slack 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个能够接收和保存从 slack 聊天室发送的文件的 slack 机器人.

I need a slack bot that's able to receive and save files send from slack chatrooms.

问题是:slack 不发送文件内容,而是发送指向文件的链接数组.其中大多数,包括下载链接都是私有的,无法通过机器人访问.它确实发送了一个公共链接,但该链接指向文件预览,该文件本身没有文件 (这是一个例子).

The problem is: slack doesn't send file contents, but an array of links pointing to the file. Most of them, including download link are private and cannot be accessed via bot. It does send one public link, but that link points at the file preview, which does not have the file itself (here's an example).

所以问题是:我如何通过机器人访问上传的文件?

So the question is: how can I access uploaded files via bot?

推荐答案

当您执行 CURL 请求时,您可以通过在 HTTP 标头中提供访问令牌来从您的机器人访问私有 URL.

You can access private URLs from your bot by providing an access token in the HTTP header when you are doing you CURL request.

您的令牌需要具有范围 files.read 才能获得访问权限.

Your token needs to have the scope files.read in order to get access.

格式为:

Authorization: Bearer A_VALID_TOKEN

将 A_VALID_TOKEN 替换为您的 slack 访问令牌.

Replace A_VALID_TOKEN with your slack access token.

我刚刚使用一个简单的 PHP 脚本对其进行了测试,以通过其url_private"检索文件,并且运行良好.

I just tested it with a simple PHP script to retrieve a file by its "url_private" and it works nicely.

来源:Slack API 文档/文件对象/身份验证

这篇关于从 slack bot 访问 Slack 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆