Using @slack/webhooks on AWS Lambda, the function is randomly failing with a 400 code from the Slack API with the error invalid_attachments.
Roughly 50% of messages are posted successfully, and the other 50% fail. If the POST body was malformed, I would expect messages to reliably fail every time, but that's not the case.
This is my POST body (some properties such as image_url and url have been obfuscated):
{
"attachments": [
{
"color": "#CC001E",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*some text here*"
},
"accessory": {
"type": "image",
"image_url": "url here",
"alt_text": "qr code"
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "first button",
"emoji": true
},
"url": "first button url"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "second button",
"emoji": true
},
"url": "second button url"
}
]
}
]
}
]
}
x in one of the [ ])x in each of the [ ])Filling out the following details about bugs will help us solve your issue sooner.
Select all that apply:
@slack/web-api@slack/events-api@slack/interactive-messages@slack/rtm-api@slack/webhookspackage version: 5.0.0
node version: 9.7.1
OS version(s): Windows 10 1904
Error (obfuscated):
{ Error: An HTTP protocol error occurred: statusCode = undefined
at Object.httpErrorWithOriginal (node_modules\@slack\webhook\src\errors.ts:59:5)
at IncomingWebhook.send (node_modules\@slack\webhook\src\IncomingWebhook.ts:68:15)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:118:7)
code: 'slack_webhook_http_error',
original:
{ Error: Request failed with status code 400
at createError (node_modules\axios\lib\core\createError.js:16:15)
at settle (node_modules\axios\lib\core\settle.js:18:12)
at IncomingMessage.handleStreamEnd (node_modules\axios\lib\adapters\http.js:202:11)
at IncomingMessage.emit (events.js:132:15)
at IncomingMessage.emit (domain.js:439:23)
at endReadableNT (_stream_readable.js:1101:12)
at process._tickCallback (internal/process/next_tick.js:114:19)
config:
{ adapter: [Function: httpAdapter],
transformRequest: [Object],
transformResponse: [Object],
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
validateStatus: [Function: validateStatus],
headers: [Object],
method: 'post',
baseURL: '{obfuscated}',
httpAgent: undefined,
httpsAgent: undefined,
maxRedirects: 0,
proxy: false,
url: '{omitted}',
data: '{omitted} see POST body above' },
request:
ClientRequest {
domain: [Domain],
_events: [Object],
_eventsCount: 2,
_maxListeners: undefined,
output: [],
outputEncodings: [],
outputCallbacks: [],
outputSize: 0,
writable: true,
_last: true,
upgrading: false,
chunkedEncoding: false,
shouldKeepAlive: false,
useChunkedEncodingByDefault: true,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: 756,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
socket: [TLSSocket],
connection: [TLSSocket],
_header: 'POST /services/{omitted} HTTP/1.1\r\nAccept: application/json, text/plain, */*\r\nContent-Type: application/json;charset=utf-8\r\nUser-Agent: @slack:webhook/5.0.0 node/9.7.1 win32/10.0.17763\r\nContent-Length: 756\r\nHost: hooks.slack.com\r\nConnection: close\r\n\r\n',
_onPendingData: [Function: noopPendingOutput],
agent: [Agent],
socketPath: undefined,
timeout: undefined,
method: 'POST',
path: '{omitted}',
_ended: true,
res: [IncomingMessage],
aborted: undefined,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
[Symbol(isCorked)]: false,
[Symbol(outHeadersKey)]: [Object] },
response:
{ status: 400,
statusText: 'Bad Request',
headers: [Object],
config: [Object],
request: [ClientRequest],
data: 'invalid_attachments' } } }
Thank you!
Sam
Further information on this: The issue seems to be caused by the image_url property in ImageBlock. If the URL provided doesn't respond quickly enough while the Slack API is processing the POST request, it fails all together with a 400 code.
The issue seems to be fixed using a different third party API that responds much quicker, but I'm still concerned this bug might cause requests to sporadically fail.
Hey @samcaplat, thanks for reporting this issue and your insight on the cause.
I know this issue is a little old, but I'm going to put some time into reproducing it. There's a chance that this has been resolved by the Slack API team. I'll report back once we know whether it's still a bug.
Hey @samcaplat, sorry about the slow turnaround on this issues. Today I put together a sample and it looks like the Slack API team has resolved this issue. Going forward, Incoming Webhooks should respond successfully even when an image URL has a delayed response or times out.
Image requests with a delayed response of up to 10 seconds would display in Slack
Images requests that responded longer than 10 seconds displayed a broken placeholder image in Slack:


200 OK no matter how long the image request was delayedThanks for submitting this issue and following up when you discovered the cause was an image_url not responding quick enough! Looks like this issue has been resolved by the Slack API team.