A tutorial on how to make a Gitter Bot
- First steps
- Configure your bot
- Ready to use
- A GitHub account to post to your Gitter rooms. While you could use your own account, this may be confusing to your users, so a new, separate account may be better
- Once you have created your new GitHub account, log into the Gitter Developer Page, and then access this page and take a note of the accounts Personal Access Token
- You are going to need a cloud infrastructure somewhere to host your hubot instance. For example, you can host on Heroku or on Azure, or on your own
- Have node.js installed (which includes npm)
To get hubot, these are the steps that should be followed.
NOTE: Although there are two hubot adapter's for Gitter, we found that only one of them works reliably. Namely, this one. The other one seems older, and has been replaced by the one that we ended up using.
- Login into Gitter with the GitHub account that you are going to use as your bot
- Join the room(s) that you want the bot to be activated on
Configure your bot
You can follow the installation process from hubot-gitter2 here.
Or you can follow these steps :
npm install -g hubot coffee-script yo generator-hubot
mkdir -p <yourbotname>where
<yourbotname>is the name of your bot
yo hubot(when prompted, enter
gitter2as adapter name, and
npm install --save hubot-gitter2
- Create git repository (
git add .,
git commit -m "Initial commit")
NOTE: Ideally, you would then want to push the repository that you just created to "somewhere" for storage, perhaps GitHub or BitBucket.
You can then test your bot with the following command line where
<your token> is the token provided by Gitter.
HUBOT_GITTER2_TOKEN=<your token> ./bin/hubot -a gitter2
Host on Heroku
- You will need a Heroku account in order to continue
- Install Heroku Toolbelt
NOTE: The steps regarding Keep alive, sleep and wake up are ONLY required if you are running on a Hobby Heroku instance. If you are using a paid for plan, then you can ignore these steps. When running on a Hobby Plan, the Heroku Dyno is only allowed to run for 18 hours a day. This keepalive routine allows the bot to continue running without any interaction, and still remain within the rules of the free account.
Navigate to the directory where you created your bot above
heroku config:set HUBOT_GITTER2_TOKEN=****(here the token is the Personal Access Token for Github Account that will be running as the bot.
heroku config:set HEROKU_URL=https://<URL>(this is to keep the heroku application alive. The URL is generated from the
heroku createcommand above
heroku config:set HUBOT_ADAPTER="gitter2"(this ensures we use the gitter2 adapter)
heroku config:set HUBOT_HEROKU_KEEPALIVE_INTERVAL=5(this is the interval that the heroku instance will be polled to keep it active. Value is in minutes)
heroku config:set HUBOT_HEROKU_KEEPALIVE_URL=https://<URL>/(this is URL that will be pinged each keep alive attempt. Should be the same as the URL above. Notice the trailing slash, which is very important!)
heroku config:set HUBOT_HEROKU_SLEEP_TIME=22:00(this is UTC time at which the hubot instance will go to sleep. 22:00 is the default, but you can change this to whatever suits you.)
heroku config:set HUBOT_HEROKU_WAKEUP_TIME=06:00(this it the UTC time at which the hubot instance will wake up. 06:00 is the default, but you can change this to whatever suits you.)
heroku addons:create scheduler:standard(this adds the free heroku scheduler to your account)
git push heroku master
heroku logs(if all goes well here, you should see something simalar to the following)
Host on Azure
- You will need an Azure account in order to continue.
- Install Azure Command Line Interface -
npm install -g azure-cli
HOTFIX: Due to the fact that there has been a fix on the
develop branch of the
hubot-gitter2 repository to make it work on Azure, you will need to make the following adjustment to the
package.json file. Change this line :
Once a new release of the
hubot-gitter2 is available, you will not need to do this change. You can subscribe to this issue to know when a new release is available.
azure site deploymentscript --node
external-scripts.jsonfile and remove these lines
- Create a new file
server.jsin the root directory that contains these 2 lines
module.exports = require('bin/hubot.coffee');
npm install coffee-script --save
deploy.cmdand add a new line under
Deploymentsection (after the 3rd step)
:: 4. Create Hubot file with a coffee extension
copy /Y "%DEPLOYMENT_TARGET%\bin\hubot" "%DEPLOYMENT_TARGET%\bin\hubot.coffee"
- Commit this change on your repo (
git commit -m "Add Azure deployment configuration")
- Publish your code to your favorite source control (see below in Steps.3)
- Login into Azure dashboard
- Create a new App Services with the name, for example
- Under the Publishing settings, click on Continuous deployment section and then choose the source of your code among these options :
- Visual Studio Team Services
- Local Git Repository
- An external repository
- Under the General settings, click on Application settings and fill with key/value pairs
- add gitter token (key:
- add hubot adapter (key:
- add hubot name (key:
- add gitter token (key:
If you use the free version of Azure websites, you could be suprised that your bot stop to after around 20 minutes. That's because the application pool sleep after a period of inactivity. To keep your service awake, you can use the service uptimerobot.com.
- Sign-up or login to the service
- Add new monitor
- Configure your monitor like this
- Monitor type :
- Friendly Name :
- IP (or host) :
- Monitoring interval : every 15 minutes
- Monitor type :
Ready to use
If all of the above has worked, go to your Gitter Chat Room, and try issuing a hubot command like
hubot ping and hopefully you will see the following: