16

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.

nithishr
  • 596
  • 1
  • 7
  • 17

4 Answers4

51

It appears Slack introduced this feature recently.

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

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

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

Daniel
  • 1,236
  • 1
  • 9
  • 13
  • Using URL appears to prevent it from triggering the "interactive_message_callback". Anybody else? – erodewald Apr 11 '18 at 19:03
  • 1
    It seems that message attachments are now deprecated in favour of the new [block kit API](https://api.slack.com/block-kit). Does anyone know of a way to make buttons open a link, but with the block kit? – anabella Jul 31 '19 at 09:23
  • This answer is also depreciated. See @anabella answer for updated api – Ali Sajid Sep 30 '19 at 11:49
8

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 :)

mackwerk
  • 1,689
  • 4
  • 21
  • 44
  • This is what I got from the slack developers group as well. "It's unfortunately not possible to accomplish it -- the Google Docs integration is an odd duck with some unique capabilities." – nithishr Nov 07 '16 at 08:50
  • Yep! Some things have special integrations, like spotify, soundcloud and youtube as well to name a few :) – mackwerk Nov 08 '16 at 07:01
  • 1
    This would be a fantastic feature. Add "url" to the actions block for messages. If the user clicks the button - open that URL. – zero_cool Nov 17 '17 at 22:35
  • 1
    This is no longer true, look for correct answer in other answers – Ali Sajid Sep 30 '19 at 11:52
5

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.

anabella
  • 116
  • 1
  • 5
  • 3
    Seems that if you does not send an acknowledgment response for provided url, you will get a little exclamation mark in triangle near buttons. [Documentation](https://api.slack.com/reference/block-kit/block-elements#button) says `If you're using url, you'll still receive an interaction payload and will need to send an acknowledgement response.` – Glebsa Jun 26 '20 at 23:45
2

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

Trần Hữu Hiền
  • 872
  • 1
  • 9
  • 22