Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I write scripts for hubot in Javascript?

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.

like image 507
James P. Wright Avatar asked Mar 30 '13 20:03

James P. Wright


People also ask

What can you do with Hubot?

What can Hubot do? We ship Hubot with a small group of core scripts: things like posting images, translating languages, and integrating with Google Maps. We also maintain a repository of community Hubot scripts and an organization of community Hubot packages that you can add to your own robot.

Who uses Hubot?

Who uses Hubot? 66 companies reportedly use Hubot in their tech stacks, including CircleCI, Vinted, and Oscar Health.


2 Answers

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");     }); } 
like image 64
K M Rakibul Islam Avatar answered Sep 21 '22 16:09

K M Rakibul Islam


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.

like image 33
Blender Avatar answered Sep 17 '22 16:09

Blender