Skip to content

Cannot "listen" for AttachmentMessages #303

@humatic

Description

@humatic

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions