question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

An "invalid_attachments" error is thrown when blocks are included within a MessageAttachment object

See original GitHub issue

Description

I’m calling client.chat.postMessage and passing in an array of message attachments. Without setting the blocks property for one of the elements of the array, the message posts as expected and includes the attachments.

However, if I set the blocks property in one of these attachment elements, an “invalid_attachments” error is thrown.

The full stack trace can be found at the bottom of this issue.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • example code related
  • testing related
  • discussion

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

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

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

package version: @slack/bolt 2.5.0

node version: 13.10.1

OS version(s): macOS Mojave Version 10.14.6

Steps to reproduce:

  1. Here’s an example code block which uses placeholder values:
const testSectionBlock: SectionBlock = {
    type: "section",
    text: {
        type: "mrkdwn",
        text: "Section block text"
    }
};

const blocks: KnownBlock[] = [testSectionBlock];

const attachments: MessageAttachment[] = [
    {
        text: "Message attachment text",
        callback_id: "test_callback_id",
        color: "#88D8B0",
        blocks // if you don't include this argument, it works
    }
];

const response: any = await client.chat.postMessage({
    text: "Outer text"
    attachments,
    channel,
    token,
});

Expected result:

What you expected to happen

Here’s a screenshot of how the message looks without the blocks included: Screen Shot 2020-12-18 at 1 24 27 PM It should be able to include the blocks within the message attachments.

Actual result:

What actually happened

Error: An API error occurred: invalid_attachments

^ Prevents the message from being posted

Attachments:

Logs, screenshots, screencast, sample project, funny gif, etc.

Notes:

  • In the Slack Node SDK index file, MessageAttachment can include an optional blocks property.
  • There’s documentation which shows an example of blocks being included in an attachments field. Screen Shot 2020-12-18 at 1 32 06 PM
  • In the Slack Java SDK, there are test cases asserting that “invalid_blocks” should be thrown. Although in the linked issue, it’s stated that blocks within attachments should be supported.

Logs:

Error: An API error occurred: invalid_attachments
    at Object.platformErrorFromResult (/<REDACTED>/node_modules/@slack/web-api/dist/errors.js:51:33)
    at WebClient.apiCall (/<REDACTED>/node_modules/@slack/web-api/dist/WebClient.js:156:28)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async /<REDACTED>.js:112:30
    at async Array.<anonymous> (<REDACTED>/node_modules/@slack/bolt/dist/middleware/builtin.js:203:9)
    at async Array.exports.onlyCommands <REDACTED>/node_modules/@slack/bolt/dist/middleware/builtin.js:41:5) {
  code: 'slack_webapi_platform_error',
  data: {
    ok: false,
    error: 'invalid_attachments',
    response_metadata: {
      messages: [ '[ERROR] invalid_keys' ],
      scopes: [
        'channels:history',
        'channels:join',
        'chat:write',
        'commands',
        'users:read',
        'users:read.email',
        'channels:read',
        'im:write',
        'channels:manage',
        'groups:write',
        'mpim:write'
      ],
      acceptedScopes: [ 'chat:write' ]
    }
  }
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
victoria-miltchevacommented, Dec 20, 2020

Does removing text / callback_id solve your issue? You’ll lose access to callback_id (I assume for a legacy button or menu) but you could likely take advantage of action_id in blocks.

Yes, removing these fields solved my issue. I was also able to use action_id in blocks for the button and my action middleware was triggered when it was clicked.

Thanks again for your help and for submitting a color feature request for Block Kit 👍 .

1reaction
alosipovcommented, Jul 1, 2021

Yo Michael 🤝 @mwbrooks ! That helps indeed! Thank you very much! Broke my head on this ) :happy:

Read more comments on GitHub >

github_iconTop Results From Across the Web

Discord.MessageAttachment() not attaching to embed
This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not...
Read more >
Migrate your legacy message compositions to blocks - Slack API
Transforming your legacy message attachments into modern Block Kit layouts.
Read more >
HISTORY.md · master · RocketChat / Rocket.Chat · GitLab
This allows for apps receiving block actions when a user types on a plain text input field or selects an item from the...
Read more >
Untitled
You should start at 0 to insure an error free transfer. ... Only Copy Permissions from Forum (Includes sub-forums) Only Copy Permissions from...
Read more >
NVD DATA - MaxxIT4Hack
... The Forms 2.0 ActiveX control (included with Visual Basic for ... log an event success or failure, e.g. for Logon and Logoff,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found