Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new slack "blocks" instead of "attachments" #166

Open
cognifloyd opened this issue May 13, 2019 · 6 comments
Open

Use new slack "blocks" instead of "attachments" #166

cognifloyd opened this issue May 13, 2019 · 6 comments

Comments

@cognifloyd
Copy link
Member

"attachments" is now legacy. I'm filing this issue so that this is on the radar to figure out what that means for our hubot.

https://api.slack.com/reference/messaging/blocks
https://api.slack.com/reference/messaging/attachments#legacy_fields

Playing around, I can use do something like:

extra:
  slack:
    text: some msg
    attachments:
      - blocks:
          - type: section
            text:
              type: plain_text
              text: section header
          - type: divider

however, this failed

extra:
  slack:
    text: some msg
    attachments:
      - blocks:
          - type: section
            text:
              type: plain_text
              text: section header
          - type: divider
          - type: actions
            elements:
              type: button
              text: windows link to file on NAS
              url: "file://///nas_server/share/path/filename.csv"

Other stuff might be broken as well.

@blag
Copy link
Contributor

blag commented May 14, 2019

It looks like attachments is still used, but there are simply some deprecated keys for each attachment, and a new blocks key within the attachments array to replace the deprecated functionality.

When you say it's "broken", what do you mean? Are there any hints in the st2chatops logs?

Edit: attachments is an array.

@cognifloyd
Copy link
Member Author

By broken, I mean that if I include an actions type element in the list of blocks, it does not render in slack.

@cognifloyd
Copy link
Member Author

It's not deprecated, but it is legacy until they can get blocks ready enough to deprecate it.

A quote from Creating rich message layouts

This feature is a legacy part of messaging functionality for Slack apps. We recommend you stick with layout blocks as above, but if you still want to use attachments, read our caveats below.

And the most thorough advice that basically says it's deprecated even though it's not deprecated...

Secondary attachments are a legacy part of the messaging functionality. While we aren't deprecating them, you should understand that they might change in the future, in ways that reduce their visibility or utility.

We've already mentioned that we recommend the attachments array only contain secondary content that is less important to the intent of the published message.

Any content displayed within attachments may be wrapped, truncated, or hidden behind a "show more" style option by Slack clients. This isn't the case with the top-level blocks field.

In short, we recommend you use layout blocks for as much of your message composition as you can, and avoid using attachments if possible. Blocks have many more visual and interactive capabilities available.

And the big caveat just after that section explaining why attachments are NOT completely deprecated (yet).

At launch, messages built with blocks will not be supported in “All unreads”, “Threads”, “Pinned”, “Starred”, and “Shared Messages” views in Slack. Instead, users will see:
This message can't be shown in full here. View message
We’re working actively to support these views as soon as possible.

And another quote from the top of Reference: Secondary attachments

This feature is a legacy part of messaging functionality for Slack apps. We recommend you stick with layout blocks, but if you still want to use attachments, read our caveats.

@blag
Copy link
Contributor

blag commented May 16, 2019

I think we're talking past each other. The new blocks thing is just an object that goes in the attachments array, so semantically blocks are simply a special type of attachments. The attachments array is not going away.

Is there anything useful in the logs when it fails? Does anything show up in Slack when you try to use blocks? It's a little difficult to debug something when the only information I have to go on is "it doesn't work" or "it doesn't display".

Also, the Slack adapter doesn't do a whole lot of munging when it sees an extra.slack.attachments key, so I'm surprised this isn't working. Have you verified that your usage of blocks is correct with Slack?

@cognifloyd
Copy link
Member Author

Putting blocks under attachments was the only way I could get any blocks to work. blocks should actually replace attachments, so it would be something like:

extra:
  slack:
    text: some msg
    blocks:
      - type: section
        text:
          type: plain_text
          text: section header
      - type: divider
      - type: actions
        elements:
          type: button
          text: windows link to file on NAS
          url: "file://///nas_server/share/path/filename.csv"

When I used the workaround of putting blocks under attachments, iirc, there were no error messages in the log, but the actions never showed up in Slack.

@blag
Copy link
Contributor

blag commented Jun 18, 2020

Does something like this work? Can you test this out? It's straight out of the Slack docs:

result:
  format: ...
  extra:
    slack:
      icon_emoji: ":jira:"
      username: Jira Bot
      attachments:
        - blocks:
          - type: section
            text:
              type: mrkdwn
              text: "Danny Torrence left the following review for your property:"
          - type: divider
          - type: section
            block_id: section567
            text:
              type: mrkdwn
              text: >
                <https://example.com|Overlook Hotel>
                :star:
                Doors had too many axe holes, guest in room 237 was far too rowdy, whole place felt stuck in the 1920s.
            accessory:
              type: image
              image_url: https://is5-ssl.mzstatic.com/image/thumb/Purple3/v4/d3/72/5c/d3725c8f-c642-5d69-1904-aa36e4297885/source/256x256bb.jpg
              alt_text: Haunted hotel image
          - type: divider
          - type: section
            block_id: section789
            fields:
              - type: mrkdwn
                text: "*Average Rating*\n1.0"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants