Slack: Build a chat bot with Hubot in JavaScript

Hubot is an scriptable chat bot framework created by GitHub. The newer version supports JavaScript (ES6+), no more CoffeeScript!



$ npm install -g yo generator-hubot

$ mkdir codetengu-bot
$ cd codetengu-bot
$ yo hubot --adapter=slack

You could find all available adapters here:

Slack Token

The next thing you need is a Slack Bot Token (API Token) which looks like xoxb-xxx for your chat bot app. You could create a Hubot app in your Slack workspace to request a token, for instance

Otherwise, you could also create an universal Slack app, install it to your workspace. In your app settings, under "Install App" section, you are able to find OAuth Tokens for your chat bot. See



./bin/hubot --adapter slack

I fork a script named hubot-reload-scripts to help you reload your scripts when developing them.

Hear And Respond Messages

Writing your own script

// scripts/your_script.js
// Description
//   Do your shit
// Author:
//   Vinta Chen
// Commands:
//   * `restart <service>`* - Restart the service
const _ = require('lodash');

module.exports = (robot) => {
  robot.hear(/restart ([a-z0-9_\-]+)/i, (res) => {
    robot.logger.debug(`Received message: ${res.message.rawText}`);
    const [ serviceName ] = res.match.slice(1);
    res.send(`Restarting ${serviceName}`);

Call Slack APIs{'channel':})
  .then(apiRes => {
    const purpose =;
    const topic =;
    res.send(`purpose: ${purpose}`);
    res.send(`topic: ${topic`);
  .catch(apiErr => {
    robot.logger.error('apiErr', apiErr);