Skip to content

mikedamage/ur-bootbot

Repository files navigation

URBot - Coding Bootcamp Facilitator Chatbot

by Mike Green

Copyright (C) 2018 Trilogy Education Services

Released under the terms of the MIT License

urbot is a chat bot built on the Hubot framework. It was initially generated by generator-hubot, and configured to be deployed on Heroku to get you up and running as quick as possible.

This README is intended to help get you started. Definitely update and improve to talk about your own instance, how to use and deploy, what functionality is available, etc!

Running urbot Locally

You can test your hubot by running the following, however some plugins will not behave as expected unless the environment variables they rely upon have been set.

This bot incorporates hubot-dotenv, which means you can specify environment variables in a .env file in the project root. No such file is included in the repo, however, so as not to expose sensitive information.

You can start urbot locally by running:

npm install # first-run only
npm start

You'll see some start up output and a prompt:

[Sat Feb 28 2015 12:38:27 GMT+0000 (GMT)] INFO Using default redis on localhost:6379
urbot>

Then you can interact with urbot by typing urbot help.

urbot> urbot help
urbot animate me <query> - The same thing as `image me`, except adds [snip]
urbot help - Displays all of the help commands that urbot knows about.
...

Development Mode REPL Console

urbot starts a JavaScript REPL using the replify NPM module. You can connect to this console to run arbitrary JS code and interact with the running bot instance using the repl-client module (installed globally).

On Mac and Linux systems, you'd do the following:

# inside the urbot project directory
npm install -g repl-client # only required once
npm start # start the bot process
rc /tmp/repl/urbot.sock # connect to the REPL socket using repl-client
# The path to the socket might be different than the above on Windows

Once connected, you'll see a JS console. The bot instance is available as the app variable.

urbot> app.name
"urbot"

Configuration

A few scripts (including some installed by default) require environment variables to be set as a simple form of configuration.

Each script should have a commented header which contains a "Configuration" section that explains which values it requires to be placed in which variable. When you have lots of scripts installed this process can be quite labour intensive. The following shell command can be used as a stop gap until an easier way to do this has been implemented.

grep -o 'hubot-[a-z0-9_-]\+' external-scripts.json | \
  xargs -n1 -I {} sh -c 'sed -n "/^# Configuration/,/^#$/ s/^/{} /p" \
      $(find node_modules/{}/ -name "*.coffee")' | \
    awk -F '#' '{ printf "%-25s %s\n", $1, $2 }'

How to set environment variables will be specific to your operating system. Rather than recreate the various methods and best practices in achieving this, it's suggested that you search for a dedicated guide focused on your OS.

Persistence

If you are going to use the hubot-redis-brain package (strongly suggested), you will need to add the Redis to Go addon on Heroku which requires a verified account or you can create an account at Redis to Go and manually set the REDISTOGO_URL variable.

% heroku config:add REDISTOGO_URL="..."

If you don't need any persistence feel free to remove the hubot-redis-brain from external-scripts.json and you don't need to worry about redis at all.

Adapters

Adapters are the interface to the service you want your hubot to run on, such as Campfire or IRC. There are a number of third party adapters that the community have contributed. Check Hubot Adapters for the available ones.

If you would like to run a non-Campfire or shell adapter you will need to add the adapter package as a dependency to the package.json file in the dependencies section.

Once you've added the dependency with npm install --save to install it you can then run hubot with the adapter.

% bin/hubot -a <adapter>

Where <adapter> is the name of your adapter without the hubot- prefix.

Deployment

% heroku create --stack cedar
% git push heroku master

If your Heroku account has been verified you can run the following to enable and add the Redis to Go addon to your app.

% heroku addons:add redistogo:nano

If you run into any problems, checkout Heroku's docs.

You'll need to edit the Procfile to set the name of your hubot.

More detailed documentation can be found on the deploying hubot onto Heroku wiki page.

Deploying to UNIX or Windows

If you would like to deploy to either a UNIX operating system or Windows. Please check out the deploying hubot onto UNIX and deploying hubot onto Windows wiki pages.

Restart the bot

You may want to get comfortable with heroku logs and heroku restart if you're having issues.