【发布时间】:2018-12-05 08:03:59
【问题描述】:
我有一个使用来自@slack/client 的WebClient 的节点服务。
我正在使用机器人的访问令牌通过web.files.upload API 方法上传图像。然后,我想将上传的图像作为私人消息的附件发送给用户(即以D 开头的频道)。我希望仅限此团队中的 Slack 用户访问此图像(就像您共享文档或其他文件时一样)。
我尝试使用来自 files.upload 函数的响应来执行此操作,但似乎没有 res.file 的任何属性为我提供了这个 Slack 团队的所有成员都可以访问的 URL:
conversationId = 'Dxxxxxxxx'; // ID of private channel between bot and user
web.chat
.postMessage({
channel: conversationId,
text: 'Hello there',
attachments: [
{
fallback: 'Required plain-text summary of the attachment.',
color: '#36a64f',
title: 'Slack API Documentation',
title_link: 'https://api.slack.com/',
text: 'Optional text that appears within the attachment',
image_url: res.file.permalink_public,
ts: 123456789
}
]
});
从the docs 看来,这个文件在发送到公共频道之前对机器人来说是私有的。
我考虑的另一种方法是将文件上传到用户和机器人之间的私人消息通道,但这给了我以下错误:
{ Error: An API error occurred: invalid_channel
code: 'slackclient_platform_error',
data:
{ ok: false,
error: 'invalid_channel',
channel: '["Dxxxxxxxx"]',
scopes: [ 'identify', 'bot:basic' ],
acceptedScopes: [ 'files:write:user', 'post' ] } }
有没有办法实现我所追求的?
【问题讨论】: