图片 link 网址使用 slack rtm API 显示每张图片的两个副本

Image link urls are showing two copies of every image using slack rtm API

这是我们正在使用的代码,直到大约一周前它都运行良好:

rtm.sendMessage("https://cdn3.vectorstock.com/i/1000x1000/28/72/set-of-art-calligraphy-letter-i-with-flourish-of-vector-13972872.jpg", 当前频道)

直到大约一周前,这种类型的图像才会展开并只显示图像的一个副本。现在我们正在展开图像的两个副本。展开图像的第二个副本略微缩进,并附有说明(已编辑),即使未进行任何编辑。有什么想法吗?

补充说明:使用 chat.postMessage 而不是 rtm api 时也会发生同样的问题。

Image unfurls, then an exact same copy of the image unfurls below, with a tag that says "edited", even though no editing has taken place

问题:

两件大事:

  1. 您应该使用 chat.postMessage() 而不是 rtm.sendMessage()。你尝试这样做是对的,但如果你想解决这个问题,你需要坚持下去 - 来自文档:
    • RTM: Formatting Messages: The RTM API only supports posting simple messages formatted using our default message formatting mode. It does not support attachments or other message formatting modes.

    • node-slack-sdk/rtm-api: simple means that it cannot send messages that include attachments or blocks, but it can include text, mentions, and links which unfurl.

  2. 您正在以纯文本形式发送消息,而不是以附件、图像块或其他类型的富媒体消息形式发送。
    • 这基本上与用户将图像 URL 粘贴到松弛通道中具有相同的效果。在大多数情况下,slack 将 "unfurl" 图像。
    • 我不是 100% 确定它在展开后显示为 "edited",但我的猜测是 Slack 认为 "unfurling" 是对您原始消息的编辑,他们正在尝试表明 他们(如 Slack)编辑了消息以展开它。双图像可能是暂时的故障,也可能是缓存问题,Slack 正在提供缓存版本,然后更新为新版本。

正确的解决方案:

要解决这两个问题,您需要使用 chat.postMessage() 或传入的 webhook 发送消息,并将图像包含为旧格式的 an attachment or in an image block (recommended). The docs cover this in great detail, and you can even play around with their block kit builder tool, which lets you preview how messages will show based on the JSON payload you will be sending via the API (or message builder

为了让您完成大部分工作,here is a preview 的最小 JSON 有效载荷用于发送您的图像。并且,在代码中:

chat.postMessage({
    "blocks": [
        {
            "type": "image",
            "image_url": "https://cdn3.vectorstock.com/i/1000x1000/28/72/set-of-art-calligraphy-letter-i-with-flourish-of-vector-13972872.jpg",
            "alt_text": "Calligraphy, Letter I"
        }
    ]
}, currentchannel);