Search code examples
javascriptnode.jscoffeescripthubotslack

Hubot script only works in Slack when I directly message the robot


Right now, my Hubot robot is techinically working. If I direct message this message to the robot in Slack:

qbot !npm bower

It will reply with this link:

https://www.npmjs.com/package/bower

It also works if I just do:

!npm bower

However, if I say either of those messages in the general channel, the robot doesn't do anything. Any help would be appreciated! Here is the script if it helps at all:

# Description:
#   Get a link to an npm module
#
# Dependencies:
#   request
#
# Configuration:
#   None
#
# Commands:
#   qbot !npm <module>

request = require "request"

module.exports = (robot) ->
  robot.hear /\!npm (.*)/i, (res) ->
    module = res.match[1]
    query = "https://www.npmjs.com/package/#{module}"

    request query, (error, response, body) ->
      unless error or response.statusCode is 404
        res.send query

Solution

  • It's been a long time since I've done it myself, but I believe you want to /invite your hubot by name from the channel you want to use it in. See the docs here: https://github.com/slackhq/hubot-slack#configuration