使用 Slack API 从消息按钮在浏览器中打开 URL

Open URL in browser from Message Button using Slack API

我正在通过 Slack 应用程序向用户发送带有按钮的 Slack 消息。每次单击按钮,我都会生成一个新的 URL。

目前,我可以return URL 回复一条消息。用户单击消息以在浏览器中打开 URL。

我不想发回消息,而是想直接在浏览器中使用 slack API 打开 URL。

我怎样才能完成它?我似乎无法在文档中找到任何相关内容。

谢谢

PS:Google 驱动集成已经做到了。

很遗憾,slack 不支持从消息按钮打开 url。 不过,您可以在此处监控 slack 计划发布的内容:https://trello.com/b/ZnTQyumQ/slack-platform-roadmap-for-developers :)

Slack 似乎最近引入了此功能。

https://api.slack.com/docs/message-attachments#link_buttons

中所述
  "actions": [
    {
      "type": "button",
      "text": "Book flights ",
      "url": "https://flights.example.com/book/r123456"
    }

可以在 Slack's interactive message builder

中预览

根据 Slack 的说法,消息 attachments 是撰写消息的 "old way",它将被弃用,取而代之的是新的 Block Kit API

我在他们的文档中找到 this example 如何使用消息负载中的 actions 对象来执行按钮 links。

我还没有实现它,但您可以直接从文档将消息发送到您工作区中的频道并尝试,它确实会按预期在浏览器中打开 link。

更新 04/2022

{
    "blocks": [
        {
            "type": "actions",
            "elements": [
                {
                    "type": "button",
                    "text": {
                        "type": "plain_text",
                        "text": "View",
                        "emoji": true
                    },
                    "style": "primary",
                    "url": "https://flights.example.com/book/r123456"
                }
            ]
        }
    ]
}

在 Slack Blockit Builder 上测试:Link