Node-slack-sdk: IncomingWebhooks randomly throws 400 error

Created on 9 Jul 2019  路  3Comments  路  Source: slackapi/node-slack-sdk

Description

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"
            }
          ]
        }
      ]
    }
  ]
}

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

  • [x] bug
  • [ ] enhancement (feature request)
  • [ ] question
  • [ ] documentation related
  • [ ] testing related
  • [ ] discussion

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

  • [x] I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • [x] I've read and agree to the Code of Conduct.
  • [x] 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.

Packages:

Select all that apply:

  • [ ] @slack/web-api
  • [ ] @slack/events-api
  • [ ] @slack/interactive-messages
  • [ ] @slack/rtm-api
  • [x] @slack/webhooks
  • [ ] I don't know

Reproducible in:

package version: 5.0.0

node version: 9.7.1

OS version(s): Windows 10 1904

Attachments:

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

webhook question server-side-issue

All 3 comments

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.

  1. Image requests with a delayed response of up to 10 seconds would display in Slack

  2. Images requests that responded longer than 10 seconds displayed a broken placeholder image in Slack:

image

  1. Broken images would update to display the image, if the image started loading in under 10 seconds
    e.g. For example, CMD+SHIFT+R to force a refresh of the Slack channel

image

  1. All Incoming Webhook requests responded with a 200 OK no matter how long the image request was delayed

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

Was this page helpful?
0 / 5 - 0 ratings