Question

Hubot is Github's chatroom robot. It's a great tool, except that no one at our company wants to write in Coffeescript....but it appears that we can't write scripts for Hubot in plain old Javascript.
Is this true? Is there something I'm missing here? Coffeescript is "just javascript" but I can't use Javascript with it?
EDIT
I was making 2 absurdly simple mistakes:
- I copied the CoffeeScript comment syntax into my JS file
- I had the script under the hubot-scripts node_module, instead of just under the /scripts/ directory in the main project.

Works perfectly now.

Was it helpful?

Solution 2

CoffeeScript is compiled into JavaScript, but it's not a superset of JavaScript, so JavaScript code isn't necessarily valid CoffeeScript code.

Nevertheless, after looking at the source, it looks like Hubot can accept both:

  # Public: Loads a file in path.
  #
  # path - A String path on the filesystem.
  # file - A String filename in path on the filesystem.
  #
  # Returns nothing.
  loadFile: (path, file) ->
    ext  = Path.extname file
    full = Path.join path, Path.basename(file, ext)
    if ext is '.coffee' or ext is '.js'
      try
        require(full) @
        @parseHelp "#{path}/#{file}"
      catch error
        @logger.error "Unable to load #{full}: #{error.stack}"
        process.exit(1)

This method is called by loadHubotScripts.

OTHER TIPS

Yes, you can write your hubot scripts in pure JavaScript. Following is a simple hubot script written in pure JavaScript and put under the /scripts/ directory of my customized hubot:

// Description:
//   holiday detector script
//
// Dependencies:
//   None
//
// Configuration:
//   None
//
// Commands:
//   hubot is it weekend ?  - returns whether is it weekend or not
//   hubot is it holiday ?  - returns whether is it holiday or not

module.exports = function(robot) {
    robot.respond(/is it (weekend|holiday)\s?\?/i, function(msg){
        var today = new Date();

        msg.reply(today.getDay() === 0 || today.getDay() === 6 ? "YES" : "NO");
    });
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top