nithishr
nithishr

Reputation: 646

Open URL in browser from Message Button using Slack API

I am sending the users a slack message with a button through a Slack App. On every click of the button, I generate a new URL.

At the moment, I am able to return the URL back as a message. The user clicks on the message to open the URL in the browser.

Instead of the sending a message back, I want to open the URL directly in the browser using slack API.

How can I accomplish it? I can't seem to find anything in the documentation that does that.

Thanks

PS: Google Drive integration does that already.

Upvotes: 20

Views: 25324

Answers (4)

Daniel
Daniel

Reputation: 1294

It appears Slack introduced this feature recently.

As documented in https://api.slack.com/reference/block-kit/block-elements#button

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

It's possible to preview in Slack's interactive message builder

Upvotes: 55

Trần Hữu Hiền
Trần Hữu Hiền

Reputation: 1044

Update 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"
                }
            ]
        }
    ]
}

Test on Slack Blockit Builder: Link

enter image description here

Upvotes: 3

anabella
anabella

Reputation: 116

According to Slack, message attachments is the "old way" of composing messages, which will be deprecated in favour of the new Block Kit API.

I found this example on how to do button links on their docs, using the actions object in the message payload.

I haven't implemented it yet, but you can send the message to a channel in your workspace straight from the docs and try it, and it does open the link in the browser as expected.

Upvotes: 5

mackwerk
mackwerk

Reputation: 1687

Unfortunately slack does not support opening urls from message buttons. You can monitor what slack is planning on releasing here though: https://trello.com/b/ZnTQyumQ/slack-platform-roadmap-for-developers :)

Upvotes: 7

Related Questions