首页 > 解决方案 > How might I share a message URL that renders a preview the same way Slack does?

问题描述

I'd like to include Slack message URLs in a post message (using blocks, if at all possible) in such a way that it's rendered the same way Slack would render the message URL; "Posted in #channel | Dec 11th | View message", etc.

I've tried using the Block Builder Kit to test this out. Slack will render this URL as plain text (which I guess is obvious), but verbatim: false isn't an option for plain_text. My options seem limited and I'm wondering if maybe I'm overlooking an alternative way to do this?

{
    "blocks": [
        {
            "type": "section",
            "text": {
                "type": "plain_text",
                "text": "https://mycompany.com/archives/C0H0DMAEB/p1576068001171300"
            }
        }
    ]
}

Example of what I mean showing Block Builder vs. URL paste: https://imgur.com/a/ThIuxrk

Any guidance would be greatly appreciated.

标签: slackslack-api

解决方案


然后你需要避免使用块,因为基于文本的链接不会自动展开。"unfurl_links": true如果您使用 Python的chat.postMessageslackclient,您需要传入

response = client.chat_postMessage(
  channel=channel_id,
  text='<https://mycompany.com/archives/C0H0DMAEB/p1576068001171300>',
  unfurl_links = True,

)
assert response["ok"]

您还可以指示在遇到消息中的链接时松弛如何表现,在此处找到更多详细信息


推荐阅读