使用 files.upload 图像作为松弛消息块中的图像

Use a files.upload image as an image in a slack message block

我想在块中使用本地文件(图像)。 据我所知,没有办法直接在消息块中使用本地图像,所以我决定尝试使用 files.upload 先将图像上传到 slack,然后使用 link 到块中的那个图像。

  1. 使用files.upload上传图片
  2. 为该图像获取 link
  3. Post 带有 link 图片的消息块。

问题是无论我做什么,我似乎都无法获得可以在消息块中使用的有效 link。 (我得到的只是 "downloading image failed" 个错误)。

我不希望图像 public 可以访问。我希望只有登录到我们的松弛工作区的松弛用户才能访问它。所以我需要一个我的 slackbot 可以使用的 link 但不是 public link.

有什么办法吗?

我已经检查了 并按照那里的说明尝试让我的机器人可以使用 link 但我无法让它工作。

非常感谢您的帮助。

我正在尝试发送的块: (现在我没有动态构建 link,只是尝试手动构建,直到我得到一个可用的 link)

webclient.chat_postMessage(
channel=channel_id,
blocks=[
    {
        "type": "section",
        "text": {
            "type": "mrkdwn",
            "text": "TEST TEST TEST"
        },
        "accessory": {
            "type": "image",
            "image_url": "https://slack-files.com/files-pri/T024G****-FU85H****/file?pub_secret=e54507****",
            "alt_text": "User's picture"
        }
    }
]

Files.upload 回复:

{'text': '', 'files': [{'id': 'FU85H****', 'created': 158279****, 'timestamp': 158279****, 'name': 'file', 'title': "User's image:", 'mimetype': 'image/png', 'filetype': 'png', 'pretty_type': 'PNG', 'user': 'UPTM1****', 'editable': False, 'size': 114035, 'mode': 'hosted', 'is_external': False, 'external_type': '', 'is_public': False, 'public_url_shared': False, 'display_as_bot': False, 'username': '', 'url_private': 'https://files.slack.com/files-pri/T024G****-FU85H****/file', 'url_private_download': 'https://files.slack.com/files-pri/T024G****-FU85H****/download/file', 'thumb_64': 'https://files.slack.com/files-tmb/T024G****-FU85H****-9513e3****/file_64.png', 'thumb_80': 'https://files.slack.com/files-tmb/T024G****-FU85H****-9513e3****/file_80.png', 'thumb_360': 'https://files.slack.com/files-tmb/T024G****-FU85H****-9513e3****/file_360.png', 'thumb_360_w': 291, 'thumb_360_h': 256, 'thumb_160': 'https://files.slack.com/files-tmb/T024G****-FU85H****-9513e3****/file_160.png', 'image_exif_rotation': 1, 'original_w': 291, 'original_h': 256, 'thumb_tiny': 'AwAqADBYCFJ3EgEY4qx5kRB+8OAOnpSC3T1NKYEA6mgBGnhQ7mYjknp60xZYHA2OSVHHHSq5RWnfdyFOBmlkiVcFTgjnilcdie4lWQDGeKr7gDVw2yHuaYbRPVqegiXdQW4qIvUEl0icZyfQUAOYDc2R3zSoodgOvaoomaXLnjngelSOXjQupwRzUlrYvGmmq****/DHY3v0qbNUQZ11KVUKDyetVKmuv9b+FQUAWrST5yD3qS8k+UKD15qrF98fUf****/1x+goHfQhJycmrlnOeIzz6V****/160CP/9k=', 'permalink': 'https://gaia.slack.com/files/UPTM1****/FU85H****/file', 'permalink_public': 'https://slack-files.com/T024G****-FU85H****-e54507****', 'is_starred': False, 'has_rich_preview': False}], 'upload': True, 'user': 'UPTM1****', 'display_as_bot': False, 'team': 'T024G****', 'source_team': 'T024G****', 'user_team': 'T024G****', 'channel': 'DUFV5****', 'event_ts': '158279****.002500', 'ts': '158279****.002500'}

OP 想用私有图像创建消息块 URL。那是不可能的。

消息块(和附件)中的图像 URL 需要 public。

另一种方法是直接在频道中分享上传的图片文件并附上一条消息。

this answer 中描述了有关如何在消息中包含图像的详细信息。