Skip to content

attachment .blocks results in invalid_attachments response #415

@untra

Description

@untra

Issue Type

TODO:
Place an x in one of the [ ].

  • Bug
  • Enhancement / Feature request
  • Question
  • Documentation

Description

(using the sdk in kotlin, pardon any confusing syntax differences)

nonempty .blocks added to an attachment will not post to the slack api, responds 400 invalid_attachments. Might also be related to #184 and #187

I have been posting to our webhook with plain JSON, and this seems to work fine:

curl -X POST -H 'Content-type: application/json' --data '{ "attachments": [ { "color": "#00FF00", "blocks": [ { "type": "section", "text": { "type": "mrkdwn", "text": "*I would expect this text to show*" } } ] } ] }' https://hooks.slack.com/services/MY/WEBHOOK

However when I try to use the sdk payload builder, it wont send at all (and I think this is being constructed right)

val payload = Payload.builder()
.attachments(asAttachments(
    attachment { a -> a.color("#00FF00").blocks(asBlocks(
        section { s -> s.text(markdownText("*I would expect this text to show*")) }
    )) }
))
.build()

I can however send this payload (empty blocks):

val payload = Payload.builder()
.attachments(asAttachments(
    attachment { a -> a.color("#00FF00").blocks(asBlocks()) }
))
.build()

and this payload will send too (separate blocks and attachments):

val payload = Payload.builder()
.blocks(asBlocks(
    section { s -> s.text(markdownText("block text!")) }
))
.attachments(asAttachments(
    attachment { a -> a.color("#00FF00").text("attachment text!) }
))
.build()

but to construct our message as intended, we cant seem to get payloads constructed with attachments with blocks to post at all at runtime.

The issue is reproducible in:

  • Module Version: 1.0.2
  • JDK Version: TODO: Run java -version and pates the result here
openjdk version "11" 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)
  • OS Version etc: TODO: if the issue happens only with specific OS

The steps to reproduce are:

val slack = Slack.getInstance()
val payload = Payload.builder()
.attachments(asAttachments(
    attachment { a -> a.color("#00FF00").blocks(asBlocks(
        section { s -> s.text(markdownText("*I would expect this text to show*")) }
    )) }
))
.build()
res = slack.send(webhook, payload)
if (res.code != 200) {
  print("slack reported status ${res.code}: ${res.body}")
}

The expected result is:

Either the sdk tells me at compile time what I'm building is incorrect/wont send. Otherwise the api should respond success to the message I'm sending.

The actual result is:

400 invalid_attachments


Requirements (place an x in each of the [ ])

TODO:

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Metadata

Metadata

Assignees

Labels

bugM-T: confirmed bug report. Issues are confirmed when the reproduction steps are documentedproject:slack-api-clientproject:slack-api-clientproject:slack-api-modelproject:slack-api-model

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions