Skip to content

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

Open

Description

@cognifloyd

"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.

Activity

  1. blag commented on May 14, 2019

    @blag
    Contributor

    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.

  2. cognifloyd commented on May 16, 2019

    @cognifloyd
    MemberAuthor

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

  3. cognifloyd commented on May 16, 2019

    @cognifloyd
    MemberAuthor

    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.

  4. blag commented on May 16, 2019

    @blag
    Contributor

    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?

  5. cognifloyd commented on Apr 18, 2020

    @cognifloyd
    MemberAuthor

    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.

  6. blag commented on Jun 18, 2020

    @blag
    Contributor

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions