1

I have a simple code that's supposed to download images from slack messages.

 var url = message.file.private_url;

 var destination_path = './tmp/uploaded';

  var opts = {
  method: 'GET',
  url: url,
  headers: {
    Authorization: 'Bearer ' + process.env.botToken,
  }
};
request(opts, function(err, res, body) {
      console.log('FILE RETRIEVE STATUS',res.statusCode);
  }).pipe(fs.createWriteStream(destination_path));

The code worked fine for a while, but now I'm getting this error:

An error occured in the receive middleware: TypeError: Cannot read property 'private_url' of undefined

Any help would be appreciated!

N8888
  • 670
  • 2
  • 14
  • 20

1 Answers1

1

Are you using the events API?

Several changes have been made to the API recently (both Events and Web APIs). See here: https://api.slack.com/changelog/2018-05-file-threads-soon-tread

If you describe the API you're using, I might be able to provide more specific help but I suspect the issue (as described in the link above) is that the file attribute attached to messages has been replaced with a new files field (an array). The files in the array are also in a different format.

Check the JSON payload. It probably contains a files array.

Joel
  • 724
  • 5
  • 12
  • I am indeed using the events API – Parker Simpson Aug 02 '18 at 21:22
  • @ParkerSimpson In that case, see the `Discontinued events` section of the link I sent. You may find that you just need to use the new files array instead of file. E.G message.files[0].private_url – Joel Aug 06 '18 at 15:06