A tutorial on how to make a Gitter Bot
A tutorial on how to make a Gitter Bot
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.
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 botyo hubot
(when prompted, enter gitter2
as adapter name, and <yourbotname>
as namenpm install --save hubot-gitter2
git init
, 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
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 login
heroku create
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 create
command 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)
Sign into your heroku account, and click on the newly created scheduler
Edit the settings of the job to look like the following:
NOTE: The next due time you be set as the same as the HUBOT_HEROKU_WAKEUP_TIME
above.
git push heroku master
heroku logs
(if all goes well here, you should see something simalar to the following)
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 :
"hubot-gitter2": "git://github.com/huafu/hubot-gitter2.git#develop",
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.json
file and remove these lines
"hubot-heroku-keepalive",
"hubot-redis-brain,
server.js
in the root directory that contains these 2 lines
require('coffee-script/register');
module.exports = require('bin/hubot.coffee');
npm install coffee-script --save
deploy.cmd
and add a new line under Deployment
section (after the 3rd step)
:: 4. Create Hubot file with a coffee extension
copy /Y "%DEPLOYMENT_TARGET%\bin\hubot" "%DEPLOYMENT_TARGET%\bin\hubot.coffee"
git commit -m "Add Azure deployment configuration"
)<yourbotname>
HUBOT_GITTER2_TOKEN
, value: <your token>
)HUBOT_ADAPTER
, value: gitter2
)HUBOT_NAME
, value: <yourbotname>
)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.
Ping
<yourbotname>
http://<yourbotname>.azurewebsites.net/<yourbotname>/help
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: