DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Installing And Running Hubot - A Bot for Automation and Fun!

Alex Soto user avatar by
Alex Soto
·
Oct. 25, 12 · Interview
Like (2)
Save
Tweet
Share
37.72K Views

Join the DZone community and get the full member experience.

Join For Free

In this post we are going to learn how to install hubot and make it work over XMPP protocol (using an openfire server).  We'll also see how it can help us in our daily work.

GitHub, Inc., wrote the first version of Hubot to automate our company chat room. Hubot knew how to deploy the site, automate a lot of tasks, and be a source of fun in the company.  --Github

Hubot is a robot which belongs to your chat infrastructure as one more user that you can talk to. Hubot can help you automate a lot of tasks, like deploying a site, managing your Pomodoro, or managing an issue tracking system. Hubot is written in CoffeScript on Node.js, so keep in mind that Hubot can be extended with CoffeScript easily.  In fact, the real fun happens when you add your own scripts.

This post is written using Ubuntu, so if you are using any other OS, you only have to modify the way components are installed.

First of all (I assume you have a JVM installed), you must install npm and node.js. For this I have used apt-get.
sudo apt-get install nodejs npm
Next you'l install Hubot dependencies by running the next apt-get command.
apt-get install build-essential libssl-dev git-core redis-server libexpat1-dev
Then we need to install CoffeScript. So we can run the next command:
npm install -g coffee-script
And finally we are going to install Hubot in /opt directory. Obviously, it could be any other one.
cd /opt
git clone git://github.com/github/hubot.git && cd hubot
npm install
Hubot is installed! To see if it works, simply run it from the installation directory:
alex@grumpy:/opt/hubot$ ./bin/hubot
and Hubot shell will start. This shell is really useful for testing purposes but not for production environments.
Hubot> hubot ping
Hubot> PONG
This will produce a Pong message.

Now it is time to install Openfire server so we can communicate with Hubot using the XMPP protocol instead of shell. Of course you could choose any other XMPP server, but for now I'm using Openfire.

To install it, download it from openfire's site, and extract it to /opt directory.
tar -xzvf openfire_<version>.tar.gz
mv openfire /opt
Now it is time to configure the Openfire server. We are going to use an embedded database but of course you can configure an external database such as MySQL or Oracle.

A web-based wizard driven setup and configuration tool is built in Openfire, so let's start Openfire server for the first time and configure typical parameters like administrator username, server name, ...
$OPENFIRE_HOME/bin/openfire start
and access to http://localhost:9090.

Then log in as an admin and then create the first two users, developer and hubot. So go to Users/Groups -> Create New User, and fill in the required information for both users.


Next, you'll create a room where all users that want to interact with Hubot will join. So go to Group Chat -> Create New Room and create a new room. In our case we are going to call it hubot.


and finally we must disable TLS security, there is an issue between Openfire TLS version and node.js XMPP module so if you are using Openfire, you should disable it.


The next step is to check that the developer user has access to the hubot chatroom and check that the account is correctly configured.  We can open our XMPP client (in our case Spark) but it should work with any other one and then verify that we can connect.

If you are using Spark, log in with the developer account and in the Actions menu you will find the Join Conference room option. Now choose the previously created room (hubot) and confirm that you have configured the XMPP part correctly. 

Now it is time for Hubot. First of all we are going to create a bot called my-bot:
alex@grumpy:/opt/hubot$ ./bin/hubot -c ./my-bot
Then enter the my-bot directory and open package.json and add the next dependencies which will configure the adapter so Hubot can use the XMPP protocol for communication:
"dependencies": {
    "hubot": "2.3.2",
    "hubot-scripts": ">= 2.1.0",
    "optparse": "1.0.3",
    "node-xmpp": "0.3.2",
    "hubot-xmpp": "0.1.0",
    "htmlparser": "1.7.6",
    "soupselect": "0.2.0",
    "underscore": "1.3.3",
    "underscore.string": "2.2.0rc"
  }
Then before starting Hubot, you must install the XMPP adapter. Run npm install from the hubot directory, and an XMPP extension will be installed into hubot.
alex@grumpy:/opt/hubot/my-bot$ npm install
And now we are ready to start using Hubot and Openfire.

We are going to start by adding environment variables to configure the XMPP adapter.
export HUBOT_XMPP_USERNAME=hubot@grumpy
export HUBOT_XMPP_PASSWORD=<password>
export HUBOT_XMPP_ROOMS=hubot
Note that a username should accompany yourr server name which in my case is grumpy. And finally it is time to start Hubot.
alex@grumpy:/opt/hubot/my-bot$ ./bin/hubot --adapter xmpp
You will see your new friend in Spark (if you have already added hubot as a friend).


And after you check that we can go to hubot-scripts to download and install the useful ones depending on our environment.

In this video you can see a screencast of Hubot In Action with some scripts that I use.


I hope you like Hubot!

XMPP

Published at DZone with permission of Alex Soto, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Why You Should Automate Code Reviews
  • Agile Scrum and the New Way of Work in 2023
  • Top 12 Technical Skills Every Software Tester Must Have
  • GitOps: Flux vs Argo CD

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: