An "invalid_attachments" error is thrown when blocks are included within a MessageAttachment object
See original GitHub issueDescription
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:
- 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:
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 optionalblocks
property. - There’s documentation which shows an example of
blocks
being included in an attachments field. - 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:
- Created 3 years ago
- Comments:10 (5 by maintainers)
Yes, removing these fields solved my issue. I was also able to use
action_id
inblocks
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 👍 .
Yo Michael 🤝 @mwbrooks ! That helps indeed! Thank you very much! Broke my head on this ) :happy: