gep13 / gitter-bot-how-to

A tutorial on how to make a Gitter Bot

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

gitter-bot-how-to Join the chat at https://gitter.im/Odonno/gitter-bot-how-to

A tutorial on how to make a Gitter Bot

Prerequisites

  • 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)

First steps

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.

  1. Login into Gitter with the GitHub account that you are going to use as your bot
  2. 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 :

  1. npm install -g hubot coffee-script yo generator-hubot
  2. mkdir -p <yourbotname> where <yourbotname> is the name of your bot
  3. yo hubot (when prompted, enter gitter2 as adapter name, and <yourbotname> as name
  4. npm install --save hubot-gitter2
  5. Create git repository (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

Publish

Host on Heroku

Prerequisites

Steps

  1. Navigate to the directory where you created your bot above
  2. heroku login
  3. heroku create
  4. heroku config:set HUBOT_GITTER2_TOKEN=**** (here the token is the Personal Access Token for Github Account that will be running as the bot.
  5. 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
  6. heroku config:set HUBOT_ADAPTER="gitter2" (this ensures we use the gitter2 adapter)
  7. git push heroku master
  8. heroku logs (if all goes well here, you should see something simalar to the following)

image

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:

image

Host on Azure

Prerequisites

You'll need an Azure account to continue.

HOTFIX: Because there was fix on develop branch to make hubot-gitter2 works on Windows, you should update your package.json to get the last change. Change this line :

"hubot-gitter2": "git://github.com/huafu/hubot-gitter2.git#develop",

Running Hubot in an Azure website ?

  1. npm install -g azure-cli
  2. azure site deploymentscript --node
  3. Edit external-scripts.json file and remove these lines
    • "hubot-heroku-keepalive",
    • "hubot-redis-brain,
  4. Create a new file server.js in the root directory that contains these 2 lines
    • require('coffee-script/register');
      module.exports = require('bin/hubot.coffee');
  5. npm install coffee-script --save
  6. Open 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"
  7. Commit this change on your repo (git commit -m "Add Azure deployment configuration")
  8. Publish your code to your favorite source control (see below in Steps.3)

Steps

  1. Login into Azure dashboard
  2. Create a new App Services with the name, for example <yourbotname>
  3. Under the Publishing settings, click on Continuous deployment section and then choose the source of your code among these options :
    • Visual Studio Team Services
    • OneDrive
    • Local Git Repository
    • GitHub
    • Bitbucket
    • Dropbox
    • An external repository
  4. Under the General settings, click on Application settings and fill with key/value pairs
    • add gitter token (key: HUBOT_GITTER2_TOKEN, value: <your token>)
    • add hubot adapter (key: HUBOT_ADAPTER, value: gitter2)

Credits

About

A tutorial on how to make a Gitter Bot

License:MIT License