RocketChat / hubot-rocketchat

Rocket.Chat Hubot adapter
MIT License
581 stars 229 forks source link

Cannot "listen" for AttachmentMessages #303

Open humatic opened 6 years ago

humatic commented 6 years ago

I want to create a bot that listens for file uploads so that it can perform an action on them. However, whenever passing an attachment, the following listener causes an error. Best as I can tell, the hubot code is treating the AttachmentMessage as if it were a normal TextMessage.

module.exports = (robot) => {
  robot.listen(
    function(message) {
      if (message && message.attachment && message.attachment.type == 'file') {
        return true;
      }
      return false;
    },
    function(response) {
      response.reply('reply');
    }
  );
}

Error:

ERROR TypeError: Cannot convert object to primitive value
    at executeListener (/home/asdf/Desktop/hubot-rocketchat-boilerplate/node_modules/hubot/src/listener.js:77:77)
    at allDone (/home/asdf/Desktop/hubot-rocketchat-boilerplate/node_modules/hubot/src/middleware.js:56:7)
    at /home/asdf/Desktop/hubot-rocketchat-boilerplate/node_modules/async/lib/async.js:274:13
    at Object.async.eachSeries (/home/asdf/Desktop/hubot-rocketchat-boilerplate/node_modules/async/lib/async.js:142:20)
    at async.reduce (/home/asdf/Desktop/hubot-rocketchat-boilerplate/node_modules/async/lib/async.js:268:15)
    at _combinedTickCallback (internal/process/next_tick.js:73:7)
    at process._tickCallback (internal/process/next_tick.js:104:9)
ith-harvey commented 5 years ago

Yes, this is happening to me as well @humatic

sharebear commented 5 years ago

Stumbled upon this one myself just now, great to see a PR open already :+1: frustrating to have the hubot code die on debug logging...

mayankhardiya commented 2 years ago

@humatic how you resolve "Cannot convert object to primitive value error" ?

mayankhardiya commented 2 years ago

@ith-harvey can you tell me what is solution of this error??