Hubot-slack: TypeError: Cannot read property 'catch' of undefined

Created on 28 Nov 2018  路  2Comments  路  Source: slackapi/hubot-slack

Description

Hey there, first of all, thanks for the great project! It's awesome and really helpful :)
The issue I'm having is this: I'm sending bot responses passing an object and not a simple string, and when I do this, I get this error: ERROR TypeError: Cannot read property 'catch' of undefined at client.coffee:180:7 (see attachments for complete info) and the response is successfully sent.
When I send responses as plain strings, no errors are thrown.

Since I'm reviving an old project that was built using outdated versions of several packages and I updated them all, I'm not sure if this is a deprecated way of passing the bot's response. Also, I've read a few somehow-related issues, like issue 256 but it didn't help much, so any help would be appreciated!

Thanks in advance :)

What type of issue is this?

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

Requirements

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

Reproducible in:

hubot-slack version: 4.5.5

node version: 8.9.4

OS version(s): Ubuntu 18.04.1

Steps to reproduce:

  1. Send a message using response.send() as shown in the attachments sections
  2. Error pops up

Expected result:

Messages being sent without showing any errors.

Actual result:

Messages are sent, but errors are thrown.

Attachments:

Here's how I call the response.send:

response.send(
      {
        room: response.message.user.room
      },
      {
        as_user: true,
        attachments: [
          {
            title: "Information",
            text: message,
            color: "#1e90ff",
            mrkdwn_in: ["text"]
          }
        ]
      },
      () => resolve() //I'm using promises
    );

And that's the error stack I get:

[Wed Nov 28 2018 15:05:52 GMT+0000 (UTC)] ERROR TypeError: Cannot read property 'catch' of undefined
   at SlackClient.send (/home/node/app/node_modules/hubot-slack/src/client.coffee:180:7, <js>:186:91)
   at SlackBot.send (/home/node/app/node_modules/hubot-slack/src/bot.coffee:86:7, <js>:104:37)
   at runAdapterSend (/home/node/app/node_modules/hubot/src/response.js:116:38)
   at allDone (/home/node/app/node_modules/hubot/src/middleware.js:56:7)
   at /home/node/app/node_modules/async/lib/async.js:274:13
   at Object.async.eachSeries (/home/node/app/node_modules/async/lib/async.js:142:20)
   at async.reduce (/home/node/app/node_modules/async/lib/async.js:268:15)
   at _combinedTickCallback (internal/process/next_tick.js:131:7)
   at process._tickDomainCallback (internal/process/next_tick.js:218:9)

 error: Response not OK:  no_text

Most helpful comment

Hey @caio92 馃憢I see two problems here.

When you're calling response.send(), you don't actually need to include the envelope parameter yourself (which is { room: response.message.user.room } in your code). This is automatically added to the function call in bot.coffee. So you can just remove the first parameter you're passing.

Secondly, I'm not sure how you're using promises, but you shouldn't pass the resolve() into the send function. The function is interpreting that as another message you're trying to send.

I got it to work without errors with this call:

res.send(
  {
    as_user: true,
    attachments: [
      {
        title: "Information",
        text: message,
        color: "#1e90ff",
        mrkdwn_in: ["text"]
      }
    ]
  }
);

All 2 comments

Hey @caio92 馃憢I see two problems here.

When you're calling response.send(), you don't actually need to include the envelope parameter yourself (which is { room: response.message.user.room } in your code). This is automatically added to the function call in bot.coffee. So you can just remove the first parameter you're passing.

Secondly, I'm not sure how you're using promises, but you shouldn't pass the resolve() into the send function. The function is interpreting that as another message you're trying to send.

I got it to work without errors with this call:

res.send(
  {
    as_user: true,
    attachments: [
      {
        title: "Information",
        text: message,
        color: "#1e90ff",
        mrkdwn_in: ["text"]
      }
    ]
  }
);

Hey @shanedewael, thanks a lot for the quick and precise response! I fixed the two problems you pointed out and it works like a charm now! :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rb1980 picture rb1980  路  6Comments

nfons picture nfons  路  6Comments

magander3 picture magander3  路  8Comments

rajatguptarg picture rajatguptarg  路  5Comments

Plork picture Plork  路  4Comments